Skip to content

Commit

Permalink
fix: Minor relaxation of types for custom tags (fixes #429)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Dec 21, 2022
1 parent 5e5470a commit 97ec3e6
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/06_custom_tags.md
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/schema/types.ts
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/stringify/stringifyString.ts
Expand Up @@ -318,7 +318,7 @@ function plainString(
}

export function stringifyString(
item: Scalar,
item: Scalar | StringifyScalar,
ctx: StringifyContext,
onComment?: () => void,
onChompKeep?: () => void
Expand All @@ -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:
Expand Down

0 comments on commit 97ec3e6

Please sign in to comment.