yaml 2.0.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/browser/dist/compose/compose-collection.js +1 -1
  2. package/browser/dist/compose/compose-doc.js +2 -2
  3. package/browser/dist/compose/compose-scalar.js +6 -7
  4. package/browser/dist/compose/composer.js +2 -3
  5. package/browser/dist/compose/resolve-block-map.js +8 -8
  6. package/browser/dist/compose/resolve-block-scalar.js +1 -1
  7. package/browser/dist/compose/resolve-flow-collection.js +3 -4
  8. package/browser/dist/compose/resolve-flow-scalar.js +1 -2
  9. package/browser/dist/compose/resolve-props.js +6 -2
  10. package/browser/dist/compose/util-empty-scalar-position.js +1 -1
  11. package/browser/dist/compose/util-flow-indent-check.js +1 -1
  12. package/browser/dist/doc/Document.js +6 -6
  13. package/browser/dist/doc/createNode.js +5 -7
  14. package/browser/dist/nodes/Collection.js +2 -1
  15. package/browser/dist/nodes/Pair.js +2 -2
  16. package/browser/dist/nodes/Scalar.js +1 -1
  17. package/browser/dist/nodes/YAMLMap.js +6 -7
  18. package/browser/dist/nodes/YAMLSeq.js +1 -9
  19. package/browser/dist/nodes/addPairToJSMap.js +1 -1
  20. package/browser/dist/nodes/toJS.js +1 -1
  21. package/browser/dist/parse/cst-scalar.js +1 -2
  22. package/browser/dist/parse/cst-visit.js +2 -2
  23. package/browser/dist/parse/lexer.js +1 -2
  24. package/browser/dist/parse/parser.js +24 -26
  25. package/browser/dist/public-api.js +3 -4
  26. package/browser/dist/schema/Schema.js +1 -1
  27. package/browser/dist/schema/yaml-1.1/omap.js +1 -1
  28. package/browser/dist/schema/yaml-1.1/pairs.js +1 -2
  29. package/browser/dist/schema/yaml-1.1/set.js +4 -0
  30. package/browser/dist/stringify/stringify.js +6 -8
  31. package/browser/dist/stringify/stringifyCollection.js +1 -2
  32. package/browser/dist/stringify/stringifyDocument.js +1 -2
  33. package/browser/dist/stringify/stringifyString.js +2 -2
  34. package/browser/dist/visit.js +5 -6
  35. package/dist/compose/compose-collection.js +1 -1
  36. package/dist/compose/compose-doc.js +2 -2
  37. package/dist/compose/compose-scalar.js +6 -7
  38. package/dist/compose/composer.js +2 -3
  39. package/dist/compose/resolve-block-map.js +8 -8
  40. package/dist/compose/resolve-block-scalar.js +1 -1
  41. package/dist/compose/resolve-flow-collection.js +3 -4
  42. package/dist/compose/resolve-flow-scalar.js +1 -2
  43. package/dist/compose/resolve-props.d.ts +1 -0
  44. package/dist/compose/resolve-props.js +6 -2
  45. package/dist/compose/util-empty-scalar-position.js +1 -1
  46. package/dist/compose/util-flow-indent-check.js +1 -1
  47. package/dist/doc/Document.d.ts +10 -10
  48. package/dist/doc/Document.js +6 -6
  49. package/dist/doc/anchors.d.ts +1 -1
  50. package/dist/doc/createNode.js +5 -7
  51. package/dist/index.d.ts +2 -0
  52. package/dist/nodes/Collection.d.ts +2 -2
  53. package/dist/nodes/Collection.js +2 -1
  54. package/dist/nodes/Node.d.ts +15 -9
  55. package/dist/nodes/Pair.d.ts +1 -1
  56. package/dist/nodes/Pair.js +2 -2
  57. package/dist/nodes/Scalar.js +1 -1
  58. package/dist/nodes/YAMLMap.d.ts +6 -3
  59. package/dist/nodes/YAMLMap.js +6 -7
  60. package/dist/nodes/YAMLSeq.d.ts +4 -1
  61. package/dist/nodes/YAMLSeq.js +1 -9
  62. package/dist/nodes/addPairToJSMap.js +1 -1
  63. package/dist/nodes/toJS.js +1 -1
  64. package/dist/options.d.ts +2 -1
  65. package/dist/parse/cst-scalar.js +1 -2
  66. package/dist/parse/cst-visit.js +2 -2
  67. package/dist/parse/lexer.js +1 -2
  68. package/dist/parse/parser.js +24 -26
  69. package/dist/public-api.js +3 -4
  70. package/dist/schema/Schema.d.ts +3 -3
  71. package/dist/schema/Schema.js +1 -1
  72. package/dist/schema/json-schema.d.ts +69 -0
  73. package/dist/schema/yaml-1.1/omap.d.ts +7 -3
  74. package/dist/schema/yaml-1.1/omap.js +1 -1
  75. package/dist/schema/yaml-1.1/pairs.js +1 -2
  76. package/dist/schema/yaml-1.1/set.d.ts +6 -2
  77. package/dist/schema/yaml-1.1/set.js +4 -0
  78. package/dist/stringify/stringify.js +6 -8
  79. package/dist/stringify/stringifyCollection.js +1 -2
  80. package/dist/stringify/stringifyDocument.js +1 -2
  81. package/dist/stringify/stringifyString.js +2 -2
  82. package/dist/test-events.js +2 -3
  83. package/dist/visit.js +5 -6
  84. package/package.json +3 -3
  85. package/dist/node_modules/tslib/tslib.es6.js +0 -76
@@ -51,7 +51,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
51
51
  : new Scalar(res);
52
52
  node.range = coll.range;
53
53
  node.tag = tagName;
54
- if (tag === null || tag === void 0 ? void 0 : tag.format)
54
+ if (tag?.format)
55
55
  node.format = tag.format;
56
56
  return node;
57
57
  }
@@ -4,7 +4,7 @@ import { resolveEnd } from './resolve-end.js';
4
4
  import { resolveProps } from './resolve-props.js';
5
5
 
6
6
  function composeDoc(options, directives, { offset, start, value, end }, onError) {
7
- const opts = Object.assign({ directives }, options);
7
+ const opts = Object.assign({ _directives: directives }, options);
8
8
  const doc = new Document(undefined, opts);
9
9
  const ctx = {
10
10
  atRoot: true,
@@ -14,7 +14,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError)
14
14
  };
15
15
  const props = resolveProps(start, {
16
16
  indicator: 'doc-start',
17
- next: value !== null && value !== void 0 ? value : end === null || end === void 0 ? void 0 : end[0],
17
+ next: value ?? end?.[0],
18
18
  offset,
19
19
  onError,
20
20
  startOnNewline: true
@@ -17,12 +17,12 @@ function composeScalar(ctx, token, tagToken, onError) {
17
17
  : ctx.schema[SCALAR];
18
18
  let scalar;
19
19
  try {
20
- const res = tag.resolve(value, msg => onError(tagToken !== null && tagToken !== void 0 ? tagToken : token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
20
+ const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
21
21
  scalar = isScalar(res) ? res : new Scalar(res);
22
22
  }
23
23
  catch (error) {
24
24
  const msg = error instanceof Error ? error.message : String(error);
25
- onError(tagToken !== null && tagToken !== void 0 ? tagToken : token, 'TAG_RESOLVE_FAILED', msg);
25
+ onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg);
26
26
  scalar = new Scalar(value);
27
27
  }
28
28
  scalar.range = range;
@@ -38,7 +38,6 @@ function composeScalar(ctx, token, tagToken, onError) {
38
38
  return scalar;
39
39
  }
40
40
  function findScalarTagByName(schema, value, tagName, tagToken, onError) {
41
- var _a;
42
41
  if (tagName === '!')
43
42
  return schema[SCALAR]; // non-specific tag
44
43
  const matchWithTest = [];
@@ -51,7 +50,7 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
51
50
  }
52
51
  }
53
52
  for (const tag of matchWithTest)
54
- if ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value))
53
+ if (tag.test?.test(value))
55
54
  return tag;
56
55
  const kt = schema.knownTags[tagName];
57
56
  if (kt && !kt.collection) {
@@ -64,10 +63,10 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
64
63
  return schema[SCALAR];
65
64
  }
66
65
  function findScalarTagByTest({ directives, schema }, value, token, onError) {
67
- var _a;
68
- const tag = schema.tags.find(tag => { var _a; return tag.default && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value)); }) || schema[SCALAR];
66
+ const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[SCALAR];
69
67
  if (schema.compat) {
70
- const compat = (_a = schema.compat.find(tag => { var _a; return tag.default && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value)); })) !== null && _a !== void 0 ? _a : schema[SCALAR];
68
+ const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
69
+ schema[SCALAR];
71
70
  if (tag.tag !== compat.tag) {
72
71
  const ts = directives.tagString(tag.tag);
73
72
  const cs = directives.tagString(compat.tag);
@@ -14,7 +14,6 @@ function getErrorPos(src) {
14
14
  return [offset, offset + (typeof source === 'string' ? source.length : 1)];
15
15
  }
16
16
  function parsePrelude(prelude) {
17
- var _a;
18
17
  let comment = '';
19
18
  let atComment = false;
20
19
  let afterEmptyLine = false;
@@ -29,7 +28,7 @@ function parsePrelude(prelude) {
29
28
  afterEmptyLine = false;
30
29
  break;
31
30
  case '%':
32
- if (((_a = prelude[i + 1]) === null || _a === void 0 ? void 0 : _a[0]) !== '#')
31
+ if (prelude[i + 1]?.[0] !== '#')
33
32
  i += 1;
34
33
  atComment = false;
35
34
  break;
@@ -204,7 +203,7 @@ class Composer {
204
203
  this.doc = null;
205
204
  }
206
205
  else if (forceDoc) {
207
- const opts = Object.assign({ directives: this.directives }, this.options);
206
+ const opts = Object.assign({ _directives: this.directives }, this.options);
208
207
  const doc = new Document(undefined, opts);
209
208
  if (this.atDirectives)
210
209
  this.onError(endOffset, 'MISSING_CHAR', 'Missing directives-end indicator line');
@@ -7,7 +7,6 @@ import { mapIncludes } from './util-map-includes.js';
7
7
 
8
8
  const startColMsg = 'All mapping items must start at the same column';
9
9
  function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
10
- var _a;
11
10
  const map = new YAMLMap(ctx.schema);
12
11
  if (ctx.atRoot)
13
12
  ctx.atRoot = false;
@@ -17,7 +16,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
17
16
  // key properties
18
17
  const keyProps = resolveProps(start, {
19
18
  indicator: 'explicit-key-ind',
20
- next: key !== null && key !== void 0 ? key : sep === null || sep === void 0 ? void 0 : sep[0],
19
+ next: key ?? sep?.[0],
21
20
  offset,
22
21
  onError,
23
22
  startOnNewline: true
@@ -40,12 +39,13 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
40
39
  }
41
40
  continue;
42
41
  }
42
+ if (keyProps.hasNewlineAfterProp || containsNewline(key)) {
43
+ onError(key ?? start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
44
+ }
43
45
  }
44
- else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent)
46
+ else if (keyProps.found?.indent !== bm.indent) {
45
47
  onError(offset, 'BAD_INDENT', startColMsg);
46
- if (implicitKey && containsNewline(key))
47
- onError(key, // checked by containsNewline()
48
- 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
48
+ }
49
49
  // key value
50
50
  const keyStart = keyProps.end;
51
51
  const keyNode = key
@@ -56,7 +56,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
56
56
  if (mapIncludes(ctx, map.items, keyNode))
57
57
  onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
58
58
  // value properties
59
- const valueProps = resolveProps(sep !== null && sep !== void 0 ? sep : [], {
59
+ const valueProps = resolveProps(sep ?? [], {
60
60
  indicator: 'map-value-ind',
61
61
  next: value,
62
62
  offset: keyNode.range[2],
@@ -66,7 +66,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
66
66
  offset = valueProps.end;
67
67
  if (valueProps.found) {
68
68
  if (implicitKey) {
69
- if ((value === null || value === void 0 ? void 0 : value.type) === 'block-map' && !valueProps.hasNewline)
69
+ if (value?.type === 'block-map' && !valueProps.hasNewline)
70
70
  onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'Nested mappings are not allowed in compact mappings');
71
71
  if (ctx.options.strict &&
72
72
  keyProps.start < valueProps.found.offset - 1024)
@@ -182,7 +182,7 @@ function splitLines(source) {
182
182
  const split = source.split(/\n( *)/);
183
183
  const first = split[0];
184
184
  const m = first.match(/^( *)/);
185
- const line0 = (m === null || m === void 0 ? void 0 : m[1])
185
+ const line0 = m?.[1]
186
186
  ? [m[1], first.slice(m[1].length)]
187
187
  : ['', first];
188
188
  const lines = [line0];
@@ -10,7 +10,6 @@ import { mapIncludes } from './util-map-includes.js';
10
10
  const blockMsg = 'Block collections are not allowed within flow collections';
11
11
  const isBlock = (token) => token && (token.type === 'block-map' || token.type === 'block-seq');
12
12
  function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError) {
13
- var _a;
14
13
  const isMap = fc.start.source === '{';
15
14
  const fcName = isMap ? 'flow map' : 'flow sequence';
16
15
  const coll = isMap
@@ -27,7 +26,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
27
26
  const props = resolveProps(start, {
28
27
  flow: fcName,
29
28
  indicator: 'explicit-key-ind',
30
- next: key !== null && key !== void 0 ? key : sep === null || sep === void 0 ? void 0 : sep[0],
29
+ next: key ?? sep?.[0],
31
30
  offset,
32
31
  onError,
33
32
  startOnNewline: false
@@ -75,7 +74,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
75
74
  if (prevItemComment) {
76
75
  let prev = coll.items[coll.items.length - 1];
77
76
  if (isPair(prev))
78
- prev = (_a = prev.value) !== null && _a !== void 0 ? _a : prev.key;
77
+ prev = prev.value ?? prev.key;
79
78
  if (prev.comment)
80
79
  prev.comment += '\n' + prevItemComment;
81
80
  else
@@ -105,7 +104,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
105
104
  if (isBlock(key))
106
105
  onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
107
106
  // value properties
108
- const valueProps = resolveProps(sep !== null && sep !== void 0 ? sep : [], {
107
+ const valueProps = resolveProps(sep ?? [], {
109
108
  flow: fcName,
110
109
  indicator: 'map-value-ind',
111
110
  next: value,
@@ -72,7 +72,6 @@ function singleQuotedValue(source, onError) {
72
72
  return foldLines(source.slice(1, -1)).replace(/''/g, "'");
73
73
  }
74
74
  function foldLines(source) {
75
- var _a;
76
75
  /**
77
76
  * The negative lookbehind here and in the `re` RegExp is to
78
77
  * prevent causing a polynomial search time in certain cases.
@@ -112,7 +111,7 @@ function foldLines(source) {
112
111
  const last = /[ \t]*(.*)/sy;
113
112
  last.lastIndex = pos;
114
113
  match = last.exec(source);
115
- return res + sep + ((_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : '');
114
+ return res + sep + (match?.[1] ?? '');
116
115
  }
117
116
  function doubleQuotedValue(source, onError) {
118
117
  let res = '';
@@ -5,6 +5,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
5
5
  let comment = '';
6
6
  let commentSep = '';
7
7
  let hasNewline = false;
8
+ let hasNewlineAfterProp = false;
8
9
  let reqSpace = false;
9
10
  let anchor = null;
10
11
  let tag = null;
@@ -54,6 +55,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
54
55
  commentSep += token.source;
55
56
  atNewline = true;
56
57
  hasNewline = true;
58
+ if (anchor || tag)
59
+ hasNewlineAfterProp = true;
57
60
  hasSpace = true;
58
61
  break;
59
62
  case 'anchor':
@@ -84,7 +87,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
84
87
  if (anchor || tag)
85
88
  onError(token, 'BAD_PROP_ORDER', `Anchors and tags must be after the ${token.source} indicator`);
86
89
  if (found)
87
- onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow !== null && flow !== void 0 ? flow : 'collection'}`);
90
+ onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow ?? 'collection'}`);
88
91
  found = token;
89
92
  atNewline = false;
90
93
  hasSpace = false;
@@ -120,10 +123,11 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
120
123
  spaceBefore,
121
124
  comment,
122
125
  hasNewline,
126
+ hasNewlineAfterProp,
123
127
  anchor,
124
128
  tag,
125
129
  end,
126
- start: start !== null && start !== void 0 ? start : end
130
+ start: start ?? end
127
131
  };
128
132
  }
129
133
 
@@ -14,7 +14,7 @@ function emptyScalarPosition(offset, before, pos) {
14
14
  // Technically, an empty scalar is immediately after the last non-empty
15
15
  // node, but it's more useful to place it after any whitespace.
16
16
  st = before[++i];
17
- while ((st === null || st === void 0 ? void 0 : st.type) === 'space') {
17
+ while (st?.type === 'space') {
18
18
  offset += st.source.length;
19
19
  st = before[++i];
20
20
  }
@@ -1,7 +1,7 @@
1
1
  import { containsNewline } from './util-contains-newline.js';
2
2
 
3
3
  function flowIndentCheck(indent, fc, onError) {
4
- if ((fc === null || fc === void 0 ? void 0 : fc.type) === 'flow-collection') {
4
+ if (fc?.type === 'flow-collection') {
5
5
  const end = fc.end[0];
6
6
  if (end.indent === indent &&
7
7
  (end.source === ']' || end.source === '}') &&
@@ -41,8 +41,8 @@ class Document {
41
41
  }, options);
42
42
  this.options = opt;
43
43
  let { version } = opt;
44
- if (options === null || options === void 0 ? void 0 : options.directives) {
45
- this.directives = options.directives.atDocument();
44
+ if (options?._directives) {
45
+ this.directives = options._directives.atDocument();
46
46
  if (this.directives.yaml.explicit)
47
47
  version = this.directives.yaml.version;
48
48
  }
@@ -124,13 +124,13 @@ class Document {
124
124
  options = replacer;
125
125
  replacer = undefined;
126
126
  }
127
- const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options !== null && options !== void 0 ? options : {};
127
+ const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options ?? {};
128
128
  const { onAnchor, setAnchors, sourceObjects } = createNodeAnchors(this,
129
129
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
130
130
  anchorPrefix || 'a');
131
131
  const ctx = {
132
- aliasDuplicateObjects: aliasDuplicateObjects !== null && aliasDuplicateObjects !== void 0 ? aliasDuplicateObjects : true,
133
- keepUndefined: keepUndefined !== null && keepUndefined !== void 0 ? keepUndefined : false,
132
+ aliasDuplicateObjects: aliasDuplicateObjects ?? true,
133
+ keepUndefined: keepUndefined ?? false,
134
134
  onAnchor,
135
135
  onTagObj,
136
136
  replacer: _replacer,
@@ -294,7 +294,7 @@ class Document {
294
294
  maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100,
295
295
  stringify
296
296
  };
297
- const res = toJS(this.contents, jsonArg !== null && jsonArg !== void 0 ? jsonArg : '', ctx);
297
+ const res = toJS(this.contents, jsonArg ?? '', ctx);
298
298
  if (typeof onAnchor === 'function')
299
299
  for (const { count, res } of ctx.anchors.values())
300
300
  onAnchor(res, count);
@@ -4,24 +4,22 @@ import { Scalar } from '../nodes/Scalar.js';
4
4
 
5
5
  const defaultTagPrefix = 'tag:yaml.org,2002:';
6
6
  function findTagObject(value, tagName, tags) {
7
- var _a;
8
7
  if (tagName) {
9
8
  const match = tags.filter(t => t.tag === tagName);
10
- const tagObj = (_a = match.find(t => !t.format)) !== null && _a !== void 0 ? _a : match[0];
9
+ const tagObj = match.find(t => !t.format) ?? match[0];
11
10
  if (!tagObj)
12
11
  throw new Error(`Tag ${tagName} not found`);
13
12
  return tagObj;
14
13
  }
15
- return tags.find(t => { var _a; return ((_a = t.identify) === null || _a === void 0 ? void 0 : _a.call(t, value)) && !t.format; });
14
+ return tags.find(t => t.identify?.(value) && !t.format);
16
15
  }
17
16
  function createNode(value, tagName, ctx) {
18
- var _a, _b;
19
17
  if (isDocument(value))
20
18
  value = value.contents;
21
19
  if (isNode(value))
22
20
  return value;
23
21
  if (isPair(value)) {
24
- const map = (_b = (_a = ctx.schema[MAP]).createNode) === null || _b === void 0 ? void 0 : _b.call(_a, ctx.schema, null, ctx);
22
+ const map = ctx.schema[MAP].createNode?.(ctx.schema, null, ctx);
25
23
  map.items.push(value);
26
24
  return map;
27
25
  }
@@ -49,7 +47,7 @@ function createNode(value, tagName, ctx) {
49
47
  sourceObjects.set(value, ref);
50
48
  }
51
49
  }
52
- if (tagName === null || tagName === void 0 ? void 0 : tagName.startsWith('!!'))
50
+ if (tagName?.startsWith('!!'))
53
51
  tagName = defaultTagPrefix + tagName.slice(2);
54
52
  let tagObj = findTagObject(value, tagName, schema.tags);
55
53
  if (!tagObj) {
@@ -74,7 +72,7 @@ function createNode(value, tagName, ctx) {
74
72
  onTagObj(tagObj);
75
73
  delete ctx.onTagObj;
76
74
  }
77
- const node = (tagObj === null || tagObj === void 0 ? void 0 : tagObj.createNode)
75
+ const node = tagObj?.createNode
78
76
  ? tagObj.createNode(ctx.schema, value, ctx)
79
77
  : new Scalar(value);
80
78
  if (tagName)
@@ -24,7 +24,8 @@ function collectionFromPath(schema, path, value) {
24
24
  sourceObjects: new Map()
25
25
  });
26
26
  }
27
- // null, undefined, or an empty non-string iterable (e.g. [])
27
+ // Type guard is intentionally a little wrong so as to be more useful,
28
+ // as it does not cover untypable empty non-string iterables (e.g. []).
28
29
  const isEmptyPath = (path) => path == null ||
29
30
  (typeof path === 'object' && !!path[Symbol.iterator]().next().done);
30
31
  class Collection extends NodeBase {
@@ -23,11 +23,11 @@ class Pair {
23
23
  return new Pair(key, value);
24
24
  }
25
25
  toJSON(_, ctx) {
26
- const pair = (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
26
+ const pair = ctx?.mapAsMap ? new Map() : {};
27
27
  return addPairToJSMap(ctx, pair, this);
28
28
  }
29
29
  toString(ctx, onComment, onChompKeep) {
30
- return (ctx === null || ctx === void 0 ? void 0 : ctx.doc)
30
+ return ctx?.doc
31
31
  ? stringifyPair(this, ctx, onComment, onChompKeep)
32
32
  : JSON.stringify(this);
33
33
  }
@@ -8,7 +8,7 @@ class Scalar extends NodeBase {
8
8
  this.value = value;
9
9
  }
10
10
  toJSON(arg, ctx) {
11
- return (ctx === null || ctx === void 0 ? void 0 : ctx.keep) ? this.value : toJS(this.value, arg, ctx);
11
+ return ctx?.keep ? this.value : toJS(this.value, arg, ctx);
12
12
  }
13
13
  toString() {
14
14
  return String(this.value);
@@ -32,18 +32,17 @@ class YAMLMap extends Collection {
32
32
  * collection will throw. Otherwise, overwrites the previous value.
33
33
  */
34
34
  add(pair, overwrite) {
35
- var _a;
36
35
  let _pair;
37
36
  if (isPair(pair))
38
37
  _pair = pair;
39
38
  else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
40
39
  // In TypeScript, this never happens.
41
- _pair = new Pair(pair, pair.value);
40
+ _pair = new Pair(pair, pair?.value);
42
41
  }
43
42
  else
44
43
  _pair = new Pair(pair.key, pair.value);
45
44
  const prev = findPair(this.items, _pair.key);
46
- const sortEntries = (_a = this.schema) === null || _a === void 0 ? void 0 : _a.sortMapEntries;
45
+ const sortEntries = this.schema?.sortMapEntries;
47
46
  if (prev) {
48
47
  if (!overwrite)
49
48
  throw new Error(`Key ${_pair.key} already set`);
@@ -73,8 +72,8 @@ class YAMLMap extends Collection {
73
72
  }
74
73
  get(key, keepScalar) {
75
74
  const it = findPair(this.items, key);
76
- const node = it === null || it === void 0 ? void 0 : it.value;
77
- return !keepScalar && isScalar(node) ? node.value : node;
75
+ const node = it?.value;
76
+ return (!keepScalar && isScalar(node) ? node.value : node) ?? undefined;
78
77
  }
79
78
  has(key) {
80
79
  return !!findPair(this.items, key);
@@ -88,8 +87,8 @@ class YAMLMap extends Collection {
88
87
  * @returns Instance of Type, Map, or Object
89
88
  */
90
89
  toJSON(_, ctx, Type) {
91
- const map = Type ? new Type() : (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
92
- if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
90
+ const map = Type ? new Type() : ctx?.mapAsMap ? new Map() : {};
91
+ if (ctx?.onCreate)
93
92
  ctx.onCreate(map);
94
93
  for (const item of this.items)
95
94
  addPairToJSMap(ctx, map, item);
@@ -30,14 +30,6 @@ class YAMLSeq extends Collection {
30
30
  const del = this.items.splice(idx, 1);
31
31
  return del.length > 0;
32
32
  }
33
- /**
34
- * Returns item at `key`, or `undefined` if not found. By default unwraps
35
- * scalar values from their surrounding node; to disable set `keepScalar` to
36
- * `true` (collections are always returned intact).
37
- *
38
- * `key` must contain a representation of an integer for this to succeed.
39
- * It may be wrapped in a `Scalar`.
40
- */
41
33
  get(key, keepScalar) {
42
34
  const idx = asItemIndex(key);
43
35
  if (typeof idx !== 'number')
@@ -74,7 +66,7 @@ class YAMLSeq extends Collection {
74
66
  }
75
67
  toJSON(_, ctx) {
76
68
  const seq = [];
77
- if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
69
+ if (ctx?.onCreate)
78
70
  ctx.onCreate(seq);
79
71
  let i = 0;
80
72
  for (const item of this.items)
@@ -6,7 +6,7 @@ import { toJS } from './toJS.js';
6
6
 
7
7
  const MERGE_KEY = '<<';
8
8
  function addPairToJSMap(ctx, map, { key, value }) {
9
- if ((ctx === null || ctx === void 0 ? void 0 : ctx.doc.schema.merge) && isMergeKey(key)) {
9
+ if (ctx?.doc.schema.merge && isMergeKey(key)) {
10
10
  value = isAlias(value) ? value.resolve(ctx.doc) : value;
11
11
  if (isSeq(value))
12
12
  for (const it of value.items)
@@ -29,7 +29,7 @@ function toJS(value, arg, ctx) {
29
29
  ctx.onCreate(res);
30
30
  return res;
31
31
  }
32
- if (typeof value === 'bigint' && !(ctx === null || ctx === void 0 ? void 0 : ctx.keep))
32
+ if (typeof value === 'bigint' && !ctx?.keep)
33
33
  return Number(value);
34
34
  return value;
35
35
  }
@@ -38,7 +38,6 @@ function resolveAsScalar(token, strict = true, onError) {
38
38
  * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
39
39
  */
40
40
  function createScalarToken(value, context) {
41
- var _a;
42
41
  const { implicitKey = false, indent, inFlow = false, offset = -1, type = 'PLAIN' } = context;
43
42
  const source = stringifyString({ type, value }, {
44
43
  implicitKey,
@@ -46,7 +45,7 @@ function createScalarToken(value, context) {
46
45
  inFlow,
47
46
  options: { blockQuote: true, lineWidth: -1 }
48
47
  });
49
- const end = (_a = context.end) !== null && _a !== void 0 ? _a : [
48
+ const end = context.end ?? [
50
49
  { type: 'newline', offset: -1, indent, source: '\n' }
51
50
  ];
52
51
  switch (source[0]) {
@@ -47,7 +47,7 @@ visit.REMOVE = REMOVE;
47
47
  visit.itemAtPath = (cst, path) => {
48
48
  let item = cst;
49
49
  for (const [field, index] of path) {
50
- const tok = item === null || item === void 0 ? void 0 : item[field];
50
+ const tok = item?.[field];
51
51
  if (tok && 'items' in tok) {
52
52
  item = tok.items[index];
53
53
  }
@@ -64,7 +64,7 @@ visit.itemAtPath = (cst, path) => {
64
64
  visit.parentCollection = (cst, path) => {
65
65
  const parent = visit.itemAtPath(cst, path.slice(0, -1));
66
66
  const field = path[path.length - 1][0];
67
- const coll = parent === null || parent === void 0 ? void 0 : parent[field];
67
+ const coll = parent?.[field];
68
68
  if (coll && 'items' in coll)
69
69
  return coll;
70
70
  throw new Error('Parent collection not found');
@@ -148,13 +148,12 @@ class Lexer {
148
148
  * @returns A generator of lexical tokens
149
149
  */
150
150
  *lex(source, incomplete = false) {
151
- var _a;
152
151
  if (source) {
153
152
  this.buffer = this.buffer ? this.buffer + source : source;
154
153
  this.lineEndPos = null;
155
154
  }
156
155
  this.atEnd = !incomplete;
157
- let next = (_a = this.next) !== null && _a !== void 0 ? _a : 'stream';
156
+ let next = this.next ?? 'stream';
158
157
  while (next && (incomplete || this.hasChars(1)))
159
158
  next = yield* this.parseNext(next);
160
159
  }