diff --git a/docs/06_custom_tags.md b/docs/06_custom_tags.md index 9b0d81ca..0ca17d2c 100644 --- a/docs/06_custom_tags.md +++ b/docs/06_custom_tags.md @@ -73,12 +73,13 @@ const regexp = { tag: '!re', resolve(str) { const match = str.match(/^\/([\s\S]+)\/([gimuy]*)$/) + if (!match) throw new Error('Invalid !re value') return new RegExp(match[1], match[2]) } } const sharedSymbol = { - identify: value => value.constructor === Symbol, + identify: value => value?.constructor === Symbol, tag: '!symbol/shared', resolve: str => Symbol.for(str), stringify(item, ctx, onComment, onChompKeep) { diff --git a/src/schema/types.ts b/src/schema/types.ts index 9ee2368a..b20be459 100644 --- a/src/schema/types.ts +++ b/src/schema/types.ts @@ -18,7 +18,7 @@ interface TagBase { * an explicit tag. For most cases, it's unlikely that you'll actually want to * use this, even if you first think you do. */ - default: boolean + default?: boolean /** * If a tag has multiple forms that should be parsed and/or stringified diff --git a/src/stringify/stringifyString.ts b/src/stringify/stringifyString.ts index c425a8b9..c71a848d 100644 --- a/src/stringify/stringifyString.ts +++ b/src/stringify/stringifyString.ts @@ -318,7 +318,7 @@ function plainString( } export function stringifyString( - item: Scalar, + item: Scalar | StringifyScalar, ctx: StringifyContext, onComment?: () => void, onChompKeep?: () => void @@ -336,7 +336,7 @@ export function stringifyString( type = Scalar.QUOTE_DOUBLE } - const _stringify = (_type: Scalar.Type | undefined) => { + const _stringify = (_type: string | undefined) => { switch (_type) { case Scalar.BLOCK_FOLDED: case Scalar.BLOCK_LITERAL: