Skip to content

Commit 97ec3e6

Browse files
committedDec 21, 2022
fix: Minor relaxation of types for custom tags (fixes #429)
1 parent 5e5470a commit 97ec3e6

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed
 

‎docs/06_custom_tags.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,13 @@ const regexp = {
7373
tag: '!re',
7474
resolve(str) {
7575
const match = str.match(/^\/([\s\S]+)\/([gimuy]*)$/)
76+
if (!match) throw new Error('Invalid !re value')
7677
return new RegExp(match[1], match[2])
7778
}
7879
}
7980

8081
const sharedSymbol = {
81-
identify: value => value.constructor === Symbol,
82+
identify: value => value?.constructor === Symbol,
8283
tag: '!symbol/shared',
8384
resolve: str => Symbol.for(str),
8485
stringify(item, ctx, onComment, onChompKeep) {

‎src/schema/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface TagBase {
1818
* an explicit tag. For most cases, it's unlikely that you'll actually want to
1919
* use this, even if you first think you do.
2020
*/
21-
default: boolean
21+
default?: boolean
2222

2323
/**
2424
* If a tag has multiple forms that should be parsed and/or stringified

‎src/stringify/stringifyString.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ function plainString(
318318
}
319319

320320
export function stringifyString(
321-
item: Scalar,
321+
item: Scalar | StringifyScalar,
322322
ctx: StringifyContext,
323323
onComment?: () => void,
324324
onChompKeep?: () => void
@@ -336,7 +336,7 @@ export function stringifyString(
336336
type = Scalar.QUOTE_DOUBLE
337337
}
338338

339-
const _stringify = (_type: Scalar.Type | undefined) => {
339+
const _stringify = (_type: string | undefined) => {
340340
switch (_type) {
341341
case Scalar.BLOCK_FOLDED:
342342
case Scalar.BLOCK_LITERAL:

0 commit comments

Comments
 (0)
Please sign in to comment.