cdk8s 2.7.62 → 2.7.64

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 (160) hide show
  1. package/.backportrc.json +0 -1
  2. package/.jsii +3 -3
  3. package/lib/api-object.js +1 -1
  4. package/lib/app.js +1 -1
  5. package/lib/chart.js +1 -1
  6. package/lib/cron.js +1 -1
  7. package/lib/dependency.js +2 -2
  8. package/lib/duration.js +1 -1
  9. package/lib/helm.js +1 -1
  10. package/lib/include.js +1 -1
  11. package/lib/json-patch.js +1 -1
  12. package/lib/lazy.js +1 -1
  13. package/lib/metadata.js +1 -1
  14. package/lib/names.js +1 -1
  15. package/lib/size.js +1 -1
  16. package/lib/testing.js +1 -1
  17. package/lib/yaml.js +6 -4
  18. package/node_modules/yaml/README.md +2 -2
  19. package/node_modules/yaml/browser/dist/compose/compose-collection.js +1 -1
  20. package/node_modules/yaml/browser/dist/compose/compose-doc.js +4 -3
  21. package/node_modules/yaml/browser/dist/compose/compose-node.js +18 -5
  22. package/node_modules/yaml/browser/dist/compose/compose-scalar.js +19 -13
  23. package/node_modules/yaml/browser/dist/compose/composer.js +8 -10
  24. package/node_modules/yaml/browser/dist/compose/resolve-block-map.js +30 -13
  25. package/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +12 -3
  26. package/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +10 -5
  27. package/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +17 -6
  28. package/node_modules/yaml/browser/dist/compose/resolve-flow-scalar.js +8 -2
  29. package/node_modules/yaml/browser/dist/compose/resolve-props.js +9 -1
  30. package/node_modules/yaml/browser/dist/compose/util-empty-scalar-position.js +1 -1
  31. package/node_modules/yaml/browser/dist/compose/util-flow-indent-check.js +15 -0
  32. package/node_modules/yaml/browser/dist/doc/Document.js +76 -19
  33. package/node_modules/yaml/browser/dist/doc/anchors.js +2 -2
  34. package/node_modules/yaml/browser/dist/doc/createNode.js +14 -11
  35. package/node_modules/yaml/browser/dist/doc/directives.js +11 -3
  36. package/node_modules/yaml/browser/dist/errors.js +1 -1
  37. package/node_modules/yaml/browser/dist/index.js +1 -2
  38. package/node_modules/yaml/browser/dist/node_modules/tslib/tslib.es6.js +164 -0
  39. package/node_modules/yaml/browser/dist/nodes/Collection.js +30 -16
  40. package/node_modules/yaml/browser/dist/nodes/Node.js +7 -0
  41. package/node_modules/yaml/browser/dist/nodes/Pair.js +11 -3
  42. package/node_modules/yaml/browser/dist/nodes/Scalar.js +1 -1
  43. package/node_modules/yaml/browser/dist/nodes/YAMLMap.js +10 -10
  44. package/node_modules/yaml/browser/dist/nodes/YAMLSeq.js +5 -13
  45. package/node_modules/yaml/browser/dist/nodes/addPairToJSMap.js +3 -2
  46. package/node_modules/yaml/browser/dist/nodes/toJS.js +3 -1
  47. package/node_modules/yaml/browser/dist/parse/cst-scalar.js +3 -8
  48. package/node_modules/yaml/browser/dist/parse/cst-visit.js +2 -2
  49. package/node_modules/yaml/browser/dist/parse/lexer.js +49 -22
  50. package/node_modules/yaml/browser/dist/parse/parser.js +142 -68
  51. package/node_modules/yaml/browser/dist/public-api.js +5 -7
  52. package/node_modules/yaml/browser/dist/schema/Schema.js +19 -4
  53. package/node_modules/yaml/browser/dist/schema/common/null.js +3 -1
  54. package/node_modules/yaml/browser/dist/schema/core/float.js +4 -1
  55. package/node_modules/yaml/browser/dist/schema/tags.js +17 -13
  56. package/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +4 -1
  57. package/node_modules/yaml/browser/dist/schema/yaml-1.1/omap.js +1 -1
  58. package/node_modules/yaml/browser/dist/schema/yaml-1.1/pairs.js +1 -1
  59. package/node_modules/yaml/browser/dist/schema/yaml-1.1/set.js +6 -1
  60. package/node_modules/yaml/browser/dist/stringify/stringify.js +53 -23
  61. package/node_modules/yaml/browser/dist/stringify/stringifyCollection.js +114 -85
  62. package/node_modules/yaml/browser/dist/stringify/stringifyComment.js +18 -12
  63. package/node_modules/yaml/browser/dist/stringify/stringifyDocument.js +36 -15
  64. package/node_modules/yaml/browser/dist/stringify/stringifyPair.js +71 -32
  65. package/node_modules/yaml/browser/dist/stringify/stringifyString.js +56 -53
  66. package/node_modules/yaml/browser/dist/util.js +3 -0
  67. package/node_modules/yaml/browser/dist/visit.js +149 -62
  68. package/node_modules/yaml/dist/compose/compose-collection.js +1 -1
  69. package/node_modules/yaml/dist/compose/compose-doc.js +4 -3
  70. package/node_modules/yaml/dist/compose/compose-node.d.ts +4 -2
  71. package/node_modules/yaml/dist/compose/compose-node.js +18 -5
  72. package/node_modules/yaml/dist/compose/compose-scalar.js +18 -12
  73. package/node_modules/yaml/dist/compose/composer.d.ts +3 -3
  74. package/node_modules/yaml/dist/compose/composer.js +10 -12
  75. package/node_modules/yaml/dist/compose/resolve-block-map.js +30 -13
  76. package/node_modules/yaml/dist/compose/resolve-block-scalar.js +12 -3
  77. package/node_modules/yaml/dist/compose/resolve-block-seq.js +10 -5
  78. package/node_modules/yaml/dist/compose/resolve-flow-collection.js +17 -6
  79. package/node_modules/yaml/dist/compose/resolve-flow-scalar.js +8 -2
  80. package/node_modules/yaml/dist/compose/resolve-props.d.ts +2 -1
  81. package/node_modules/yaml/dist/compose/resolve-props.js +9 -1
  82. package/node_modules/yaml/dist/compose/util-empty-scalar-position.js +1 -1
  83. package/node_modules/yaml/dist/compose/util-flow-indent-check.d.ts +3 -0
  84. package/node_modules/yaml/dist/compose/util-flow-indent-check.js +17 -0
  85. package/node_modules/yaml/dist/doc/Document.d.ts +24 -15
  86. package/node_modules/yaml/dist/doc/Document.js +80 -23
  87. package/node_modules/yaml/dist/doc/anchors.d.ts +3 -3
  88. package/node_modules/yaml/dist/doc/anchors.js +2 -2
  89. package/node_modules/yaml/dist/doc/applyReviver.d.ts +1 -1
  90. package/node_modules/yaml/dist/doc/createNode.d.ts +3 -2
  91. package/node_modules/yaml/dist/doc/createNode.js +13 -10
  92. package/node_modules/yaml/dist/doc/directives.d.ts +5 -2
  93. package/node_modules/yaml/dist/doc/directives.js +11 -3
  94. package/node_modules/yaml/dist/errors.d.ts +2 -2
  95. package/node_modules/yaml/dist/errors.js +1 -1
  96. package/node_modules/yaml/dist/index.d.ts +6 -4
  97. package/node_modules/yaml/dist/index.js +1 -2
  98. package/node_modules/yaml/dist/log.d.ts +1 -1
  99. package/node_modules/yaml/dist/nodes/Alias.d.ts +8 -4
  100. package/node_modules/yaml/dist/nodes/Collection.d.ts +12 -6
  101. package/node_modules/yaml/dist/nodes/Collection.js +29 -15
  102. package/node_modules/yaml/dist/nodes/Node.d.ts +22 -11
  103. package/node_modules/yaml/dist/nodes/Node.js +7 -0
  104. package/node_modules/yaml/dist/nodes/Pair.d.ts +8 -3
  105. package/node_modules/yaml/dist/nodes/Pair.js +10 -2
  106. package/node_modules/yaml/dist/nodes/Scalar.d.ts +2 -0
  107. package/node_modules/yaml/dist/nodes/Scalar.js +1 -1
  108. package/node_modules/yaml/dist/nodes/YAMLMap.d.ts +12 -4
  109. package/node_modules/yaml/dist/nodes/YAMLMap.js +10 -10
  110. package/node_modules/yaml/dist/nodes/YAMLSeq.d.ts +6 -1
  111. package/node_modules/yaml/dist/nodes/YAMLSeq.js +5 -13
  112. package/node_modules/yaml/dist/nodes/addPairToJSMap.d.ts +2 -1
  113. package/node_modules/yaml/dist/nodes/addPairToJSMap.js +2 -1
  114. package/node_modules/yaml/dist/nodes/toJS.js +3 -1
  115. package/node_modules/yaml/dist/options.d.ts +82 -22
  116. package/node_modules/yaml/dist/parse/cst-scalar.d.ts +6 -0
  117. package/node_modules/yaml/dist/parse/cst-scalar.js +3 -8
  118. package/node_modules/yaml/dist/parse/cst-visit.d.ts +2 -2
  119. package/node_modules/yaml/dist/parse/cst-visit.js +2 -2
  120. package/node_modules/yaml/dist/parse/cst.d.ts +3 -3
  121. package/node_modules/yaml/dist/parse/lexer.d.ts +2 -0
  122. package/node_modules/yaml/dist/parse/lexer.js +49 -22
  123. package/node_modules/yaml/dist/parse/parser.js +142 -68
  124. package/node_modules/yaml/dist/public-api.js +5 -7
  125. package/node_modules/yaml/dist/schema/Schema.d.ts +9 -7
  126. package/node_modules/yaml/dist/schema/Schema.js +18 -3
  127. package/node_modules/yaml/dist/schema/common/null.js +3 -1
  128. package/node_modules/yaml/dist/schema/core/float.js +4 -1
  129. package/node_modules/yaml/dist/schema/json-schema.d.ts +69 -0
  130. package/node_modules/yaml/dist/schema/tags.d.ts +3 -4
  131. package/node_modules/yaml/dist/schema/tags.js +17 -13
  132. package/node_modules/yaml/dist/schema/types.d.ts +1 -1
  133. package/node_modules/yaml/dist/schema/yaml-1.1/float.js +4 -1
  134. package/node_modules/yaml/dist/schema/yaml-1.1/omap.d.ts +7 -3
  135. package/node_modules/yaml/dist/schema/yaml-1.1/omap.js +1 -1
  136. package/node_modules/yaml/dist/schema/yaml-1.1/pairs.js +1 -1
  137. package/node_modules/yaml/dist/schema/yaml-1.1/set.d.ts +6 -2
  138. package/node_modules/yaml/dist/schema/yaml-1.1/set.js +6 -1
  139. package/node_modules/yaml/dist/stringify/foldFlowLines.d.ts +1 -1
  140. package/node_modules/yaml/dist/stringify/stringify.d.ts +7 -4
  141. package/node_modules/yaml/dist/stringify/stringify.js +53 -23
  142. package/node_modules/yaml/dist/stringify/stringifyCollection.d.ts +2 -6
  143. package/node_modules/yaml/dist/stringify/stringifyCollection.js +113 -84
  144. package/node_modules/yaml/dist/stringify/stringifyComment.d.ts +10 -2
  145. package/node_modules/yaml/dist/stringify/stringifyComment.js +19 -12
  146. package/node_modules/yaml/dist/stringify/stringifyDocument.js +35 -14
  147. package/node_modules/yaml/dist/stringify/stringifyPair.js +70 -31
  148. package/node_modules/yaml/dist/stringify/stringifyString.d.ts +7 -1
  149. package/node_modules/yaml/dist/stringify/stringifyString.js +56 -53
  150. package/node_modules/yaml/dist/test-events.d.ts +1 -1
  151. package/node_modules/yaml/dist/test-events.js +14 -14
  152. package/node_modules/yaml/dist/util.d.ts +3 -0
  153. package/node_modules/yaml/dist/util.js +6 -0
  154. package/node_modules/yaml/dist/visit.d.ts +51 -12
  155. package/node_modules/yaml/dist/visit.js +148 -60
  156. package/node_modules/yaml/package.json +19 -17
  157. package/node_modules/yaml/util.d.ts +3 -0
  158. package/package.json +5 -3
  159. package/node_modules/yaml/browser/dist/options.js +0 -17
  160. package/node_modules/yaml/dist/options.js +0 -19
@@ -2,18 +2,22 @@ import { Pair } from '../nodes/Pair.js';
2
2
  import { YAMLMap } from '../nodes/YAMLMap.js';
3
3
  import { resolveProps } from './resolve-props.js';
4
4
  import { containsNewline } from './util-contains-newline.js';
5
+ import { flowIndentCheck } from './util-flow-indent-check.js';
5
6
  import { mapIncludes } from './util-map-includes.js';
6
7
 
7
8
  const startColMsg = 'All mapping items must start at the same column';
8
9
  function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
9
- var _a;
10
10
  const map = new YAMLMap(ctx.schema);
11
+ if (ctx.atRoot)
12
+ ctx.atRoot = false;
11
13
  let offset = bm.offset;
12
- for (const { start, key, sep, value } of bm.items) {
14
+ let commentEnd = null;
15
+ for (const collItem of bm.items) {
16
+ const { start, key, sep, value } = collItem;
13
17
  // key properties
14
18
  const keyProps = resolveProps(start, {
15
19
  indicator: 'explicit-key-ind',
16
- next: key || (sep === null || sep === void 0 ? void 0 : sep[0]),
20
+ next: key ?? sep?.[0],
17
21
  offset,
18
22
  onError,
19
23
  startOnNewline: true
@@ -27,7 +31,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
27
31
  onError(offset, 'BAD_INDENT', startColMsg);
28
32
  }
29
33
  if (!keyProps.anchor && !keyProps.tag && !sep) {
30
- // TODO: assert being at last item?
34
+ commentEnd = keyProps.end;
31
35
  if (keyProps.comment) {
32
36
  if (map.comment)
33
37
  map.comment += '\n' + keyProps.comment;
@@ -36,21 +40,24 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
36
40
  }
37
41
  continue;
38
42
  }
43
+ if (keyProps.hasNewlineAfterProp || containsNewline(key)) {
44
+ onError(key ?? start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
45
+ }
39
46
  }
40
- else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent)
47
+ else if (keyProps.found?.indent !== bm.indent) {
41
48
  onError(offset, 'BAD_INDENT', startColMsg);
42
- if (implicitKey && containsNewline(key))
43
- onError(key, // checked by containsNewline()
44
- 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
49
+ }
45
50
  // key value
46
51
  const keyStart = keyProps.end;
47
52
  const keyNode = key
48
53
  ? composeNode(ctx, key, keyProps, onError)
49
54
  : composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
55
+ if (ctx.schema.compat)
56
+ flowIndentCheck(bm.indent, key, onError);
50
57
  if (mapIncludes(ctx, map.items, keyNode))
51
58
  onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
52
59
  // value properties
53
- const valueProps = resolveProps(sep || [], {
60
+ const valueProps = resolveProps(sep ?? [], {
54
61
  indicator: 'map-value-ind',
55
62
  next: value,
56
63
  offset: keyNode.range[2],
@@ -60,7 +67,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
60
67
  offset = valueProps.end;
61
68
  if (valueProps.found) {
62
69
  if (implicitKey) {
63
- if ((value === null || value === void 0 ? void 0 : value.type) === 'block-map' && !valueProps.hasNewline)
70
+ if (value?.type === 'block-map' && !valueProps.hasNewline)
64
71
  onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'Nested mappings are not allowed in compact mappings');
65
72
  if (ctx.options.strict &&
66
73
  keyProps.start < valueProps.found.offset - 1024)
@@ -70,8 +77,13 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
70
77
  const valueNode = value
71
78
  ? composeNode(ctx, value, valueProps, onError)
72
79
  : composeEmptyNode(ctx, offset, sep, null, valueProps, onError);
80
+ if (ctx.schema.compat)
81
+ flowIndentCheck(bm.indent, value, onError);
73
82
  offset = valueNode.range[2];
74
- map.items.push(new Pair(keyNode, valueNode));
83
+ const pair = new Pair(keyNode, valueNode);
84
+ if (ctx.options.keepSourceTokens)
85
+ pair.srcToken = collItem;
86
+ map.items.push(pair);
75
87
  }
76
88
  else {
77
89
  // key with no value
@@ -83,10 +95,15 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
83
95
  else
84
96
  keyNode.comment = valueProps.comment;
85
97
  }
86
- map.items.push(new Pair(keyNode));
98
+ const pair = new Pair(keyNode);
99
+ if (ctx.options.keepSourceTokens)
100
+ pair.srcToken = collItem;
101
+ map.items.push(pair);
87
102
  }
88
103
  }
89
- map.range = [bm.offset, offset, offset];
104
+ if (commentEnd && commentEnd < offset)
105
+ onError(commentEnd, 'IMPOSSIBLE', 'Map comment with trailing content');
106
+ map.range = [bm.offset, offset, commentEnd ?? offset];
90
107
  return map;
91
108
  }
92
109
 
@@ -17,8 +17,10 @@ function resolveBlockScalar(scalar, strict, onError) {
17
17
  break;
18
18
  }
19
19
  // shortcut for empty contents
20
- if (!scalar.source || chompStart === 0) {
21
- const value = header.chomp === '+' ? lines.map(line => line[0]).join('\n') : '';
20
+ if (chompStart === 0) {
21
+ const value = header.chomp === '+' && lines.length > 0
22
+ ? '\n'.repeat(Math.max(1, lines.length - 1))
23
+ : '';
22
24
  let end = start + header.length;
23
25
  if (scalar.source)
24
26
  end += scalar.source.length;
@@ -46,6 +48,11 @@ function resolveBlockScalar(scalar, strict, onError) {
46
48
  }
47
49
  offset += indent.length + content.length + 1;
48
50
  }
51
+ // include trailing more-indented empty lines in content
52
+ for (let i = lines.length - 1; i >= chompStart; --i) {
53
+ if (lines[i][0].length > trimIndent)
54
+ chompStart = i + 1;
55
+ }
49
56
  let value = '';
50
57
  let sep = '';
51
58
  let prevMoreIndented = false;
@@ -175,7 +182,9 @@ function splitLines(source) {
175
182
  const split = source.split(/\n( *)/);
176
183
  const first = split[0];
177
184
  const m = first.match(/^( *)/);
178
- const line0 = m && m[1] ? [m[1], first.slice(m[1].length)] : ['', first];
185
+ const line0 = m?.[1]
186
+ ? [m[1], first.slice(m[1].length)]
187
+ : ['', first];
179
188
  const lines = [line0];
180
189
  for (let i = 1; i < split.length; i += 2)
181
190
  lines.push([split[i], split[i + 1]]);
@@ -1,9 +1,13 @@
1
1
  import { YAMLSeq } from '../nodes/YAMLSeq.js';
2
2
  import { resolveProps } from './resolve-props.js';
3
+ import { flowIndentCheck } from './util-flow-indent-check.js';
3
4
 
4
5
  function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
5
6
  const seq = new YAMLSeq(ctx.schema);
7
+ if (ctx.atRoot)
8
+ ctx.atRoot = false;
6
9
  let offset = bs.offset;
10
+ let commentEnd = null;
7
11
  for (const { start, value } of bs.items) {
8
12
  const props = resolveProps(start, {
9
13
  indicator: 'seq-item-ind',
@@ -12,16 +16,15 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
12
16
  onError,
13
17
  startOnNewline: true
14
18
  });
15
- offset = props.end;
16
19
  if (!props.found) {
17
20
  if (props.anchor || props.tag || value) {
18
21
  if (value && value.type === 'block-seq')
19
- onError(offset, 'BAD_INDENT', 'All sequence items must start at the same column');
22
+ onError(props.end, 'BAD_INDENT', 'All sequence items must start at the same column');
20
23
  else
21
24
  onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
22
25
  }
23
26
  else {
24
- // TODO: assert being at last item?
27
+ commentEnd = props.end;
25
28
  if (props.comment)
26
29
  seq.comment = props.comment;
27
30
  continue;
@@ -29,11 +32,13 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
29
32
  }
30
33
  const node = value
31
34
  ? composeNode(ctx, value, props, onError)
32
- : composeEmptyNode(ctx, offset, start, null, props, onError);
35
+ : composeEmptyNode(ctx, props.end, start, null, props, onError);
36
+ if (ctx.schema.compat)
37
+ flowIndentCheck(bs.indent, value, onError);
33
38
  offset = node.range[2];
34
39
  seq.items.push(node);
35
40
  }
36
- seq.range = [bs.offset, offset, offset];
41
+ seq.range = [bs.offset, offset, commentEnd ?? offset];
37
42
  return seq;
38
43
  }
39
44
 
@@ -16,13 +16,17 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
16
16
  ? new YAMLMap(ctx.schema)
17
17
  : new YAMLSeq(ctx.schema);
18
18
  coll.flow = true;
19
- let offset = fc.offset;
19
+ const atRoot = ctx.atRoot;
20
+ if (atRoot)
21
+ ctx.atRoot = false;
22
+ let offset = fc.offset + fc.start.source.length;
20
23
  for (let i = 0; i < fc.items.length; ++i) {
21
- const { start, key, sep, value } = fc.items[i];
24
+ const collItem = fc.items[i];
25
+ const { start, key, sep, value } = collItem;
22
26
  const props = resolveProps(start, {
23
27
  flow: fcName,
24
28
  indicator: 'explicit-key-ind',
25
- next: key || (sep === null || sep === void 0 ? void 0 : sep[0]),
29
+ next: key ?? sep?.[0],
26
30
  offset,
27
31
  onError,
28
32
  startOnNewline: false
@@ -39,6 +43,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
39
43
  else
40
44
  coll.comment = props.comment;
41
45
  }
46
+ offset = props.end;
42
47
  continue;
43
48
  }
44
49
  if (!isMap && ctx.options.strict && containsNewline(key))
@@ -69,7 +74,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
69
74
  if (prevItemComment) {
70
75
  let prev = coll.items[coll.items.length - 1];
71
76
  if (isPair(prev))
72
- prev = prev.value || prev.key;
77
+ prev = prev.value ?? prev.key;
73
78
  if (prev.comment)
74
79
  prev.comment += '\n' + prevItemComment;
75
80
  else
@@ -99,7 +104,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
99
104
  if (isBlock(key))
100
105
  onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
101
106
  // value properties
102
- const valueProps = resolveProps(sep || [], {
107
+ const valueProps = resolveProps(sep ?? [], {
103
108
  flow: fcName,
104
109
  indicator: 'map-value-ind',
105
110
  next: value,
@@ -145,6 +150,8 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
145
150
  keyNode.comment = valueProps.comment;
146
151
  }
147
152
  const pair = new Pair(keyNode, valueNode);
153
+ if (ctx.options.keepSourceTokens)
154
+ pair.srcToken = collItem;
148
155
  if (isMap) {
149
156
  const map = coll;
150
157
  if (mapIncludes(ctx, map.items, keyNode))
@@ -166,7 +173,11 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
166
173
  if (ce && ce.source === expectedEnd)
167
174
  cePos = ce.offset + ce.source.length;
168
175
  else {
169
- onError(offset + 1, 'MISSING_CHAR', `Expected ${fcName} to end with ${expectedEnd}`);
176
+ const name = fcName[0].toUpperCase() + fcName.substring(1);
177
+ const msg = atRoot
178
+ ? `${name} must end with a ${expectedEnd}`
179
+ : `${name} in block collection must be sufficiently indented and end with a ${expectedEnd}`;
180
+ onError(offset, atRoot ? 'MISSING_CHAR' : 'BAD_INDENT', msg);
170
181
  if (ce && ce.source.length !== 1)
171
182
  ee.unshift(ce);
172
183
  }
@@ -111,7 +111,7 @@ function foldLines(source) {
111
111
  const last = /[ \t]*(.*)/sy;
112
112
  last.lastIndex = pos;
113
113
  match = last.exec(source);
114
- return res + sep + ((match && match[1]) || '');
114
+ return res + sep + (match?.[1] ?? '');
115
115
  }
116
116
  function doubleQuotedValue(source, onError) {
117
117
  let res = '';
@@ -135,6 +135,12 @@ function doubleQuotedValue(source, onError) {
135
135
  while (next === ' ' || next === '\t')
136
136
  next = source[++i + 1];
137
137
  }
138
+ else if (next === '\r' && source[i + 1] === '\n') {
139
+ // skip escaped CRLF newlines, but still trim the following line
140
+ next = source[++i + 1];
141
+ while (next === ' ' || next === '\t')
142
+ next = source[++i + 1];
143
+ }
138
144
  else if (next === 'x' || next === 'u' || next === 'U') {
139
145
  const length = { x: 2, u: 4, U: 8 }[next];
140
146
  res += parseCharCode(source, i + 1, length, onError);
@@ -152,7 +158,7 @@ function doubleQuotedValue(source, onError) {
152
158
  let next = source[i + 1];
153
159
  while (next === ' ' || next === '\t')
154
160
  next = source[++i + 1];
155
- if (next !== '\n')
161
+ if (next !== '\n' && !(next === '\r' && source[i + 2] === '\n'))
156
162
  res += i > wsStart ? source.slice(wsStart, i + 1) : ch;
157
163
  }
158
164
  else {
@@ -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,11 +55,15 @@ 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':
60
63
  if (anchor)
61
64
  onError(token, 'MULTIPLE_ANCHORS', 'A node can have at most one anchor');
65
+ if (token.source.endsWith(':'))
66
+ onError(token.offset + token.source.length - 1, 'BAD_ALIAS', 'Anchor ending in : is ambiguous', true);
62
67
  anchor = token;
63
68
  if (start === null)
64
69
  start = token.offset;
@@ -81,6 +86,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
81
86
  // Could here handle preceding comments differently
82
87
  if (anchor || tag)
83
88
  onError(token, 'BAD_PROP_ORDER', `Anchors and tags must be after the ${token.source} indicator`);
89
+ if (found)
90
+ onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow ?? 'collection'}`);
84
91
  found = token;
85
92
  atNewline = false;
86
93
  hasSpace = false;
@@ -116,10 +123,11 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
116
123
  spaceBefore,
117
124
  comment,
118
125
  hasNewline,
126
+ hasNewlineAfterProp,
119
127
  anchor,
120
128
  tag,
121
129
  end,
122
- start: start !== null && start !== void 0 ? start : end
130
+ start: start ?? end
123
131
  };
124
132
  }
125
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
  }
@@ -0,0 +1,15 @@
1
+ import { containsNewline } from './util-contains-newline.js';
2
+
3
+ function flowIndentCheck(indent, fc, onError) {
4
+ if (fc?.type === 'flow-collection') {
5
+ const end = fc.end[0];
6
+ if (end.indent === indent &&
7
+ (end.source === ']' || end.source === '}') &&
8
+ containsNewline(fc)) {
9
+ const msg = 'Flow end indicator should be more indented than parent';
10
+ onError(end, 'BAD_INDENT', msg, true);
11
+ }
12
+ }
13
+ }
14
+
15
+ export { flowIndentCheck };
@@ -1,9 +1,8 @@
1
1
  import { Alias } from '../nodes/Alias.js';
2
2
  import { isEmptyPath, collectionFromPath } from '../nodes/Collection.js';
3
- import { NODE_TYPE, DOC, isCollection, isScalar } from '../nodes/Node.js';
3
+ import { NODE_TYPE, DOC, isNode, isCollection, isScalar } from '../nodes/Node.js';
4
4
  import { Pair } from '../nodes/Pair.js';
5
5
  import { toJS } from '../nodes/toJS.js';
6
- import { defaultOptions } from '../options.js';
7
6
  import { Schema } from '../schema/Schema.js';
8
7
  import { stringify } from '../stringify/stringify.js';
9
8
  import { stringifyDocument } from '../stringify/stringifyDocument.js';
@@ -31,11 +30,19 @@ class Document {
31
30
  options = replacer;
32
31
  replacer = undefined;
33
32
  }
34
- const opt = Object.assign({}, defaultOptions, options);
33
+ const opt = Object.assign({
34
+ intAsBigInt: false,
35
+ keepSourceTokens: false,
36
+ logLevel: 'warn',
37
+ prettyErrors: true,
38
+ strict: true,
39
+ uniqueKeys: true,
40
+ version: '1.2'
41
+ }, options);
35
42
  this.options = opt;
36
43
  let { version } = opt;
37
- if (options === null || options === void 0 ? void 0 : options.directives) {
38
- this.directives = options.directives.atDocument();
44
+ if (options?._directives) {
45
+ this.directives = options._directives.atDocument();
39
46
  if (this.directives.yaml.explicit)
40
47
  version = this.directives.yaml.version;
41
48
  }
@@ -48,6 +55,30 @@ class Document {
48
55
  this.contents = this.createNode(value, _replacer, options);
49
56
  }
50
57
  }
58
+ /**
59
+ * Create a deep copy of this Document and its contents.
60
+ *
61
+ * Custom Node values that inherit from `Object` still refer to their original instances.
62
+ */
63
+ clone() {
64
+ const copy = Object.create(Document.prototype, {
65
+ [NODE_TYPE]: { value: DOC }
66
+ });
67
+ copy.commentBefore = this.commentBefore;
68
+ copy.comment = this.comment;
69
+ copy.errors = this.errors.slice();
70
+ copy.warnings = this.warnings.slice();
71
+ copy.options = Object.assign({}, this.options);
72
+ if (this.directives)
73
+ copy.directives = this.directives.clone();
74
+ copy.schema = this.schema.clone();
75
+ copy.contents = isNode(this.contents)
76
+ ? this.contents.clone(copy.schema)
77
+ : this.contents;
78
+ if (this.range)
79
+ copy.range = this.range.slice();
80
+ return copy;
81
+ }
51
82
  /** Adds a value to the document. */
52
83
  add(value) {
53
84
  if (assertCollection(this.contents))
@@ -71,6 +102,7 @@ class Document {
71
102
  if (!node.anchor) {
72
103
  const prev = anchorNames(this);
73
104
  node.anchor =
105
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
74
106
  !name || prev.has(name) ? findNewAnchor(name || 'a', prev) : name;
75
107
  }
76
108
  return new Alias(node.anchor);
@@ -92,10 +124,13 @@ class Document {
92
124
  options = replacer;
93
125
  replacer = undefined;
94
126
  }
95
- const { anchorPrefix, flow, keepUndefined, onTagObj, tag } = options || {};
96
- const { onAnchor, setAnchors, sourceObjects } = createNodeAnchors(this, anchorPrefix || 'a');
127
+ const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options ?? {};
128
+ const { onAnchor, setAnchors, sourceObjects } = createNodeAnchors(this,
129
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
130
+ anchorPrefix || 'a');
97
131
  const ctx = {
98
- keepUndefined: keepUndefined !== null && keepUndefined !== void 0 ? keepUndefined : false,
132
+ aliasDuplicateObjects: aliasDuplicateObjects ?? true,
133
+ keepUndefined: keepUndefined ?? false,
99
134
  onAnchor,
100
135
  onTagObj,
101
136
  replacer: _replacer,
@@ -205,26 +240,48 @@ class Document {
205
240
  }
206
241
  /**
207
242
  * Change the YAML version and schema used by the document.
243
+ * A `null` version disables support for directives, explicit tags, anchors, and aliases.
244
+ * It also requires the `schema` option to be given as a `Schema` instance value.
208
245
  *
209
- * Overrides all previously set schema options
246
+ * Overrides all previously set schema options.
210
247
  */
211
- setSchema(version, options) {
212
- let _options;
213
- switch (String(version)) {
248
+ setSchema(version, options = {}) {
249
+ if (typeof version === 'number')
250
+ version = String(version);
251
+ let opt;
252
+ switch (version) {
214
253
  case '1.1':
215
- this.directives.yaml.version = '1.1';
216
- _options = Object.assign({ merge: true, resolveKnownTags: false, schema: 'yaml-1.1' }, options);
254
+ if (this.directives)
255
+ this.directives.yaml.version = '1.1';
256
+ else
257
+ this.directives = new Directives({ version: '1.1' });
258
+ opt = { merge: true, resolveKnownTags: false, schema: 'yaml-1.1' };
217
259
  break;
218
260
  case '1.2':
219
- this.directives.yaml.version = '1.2';
220
- _options = Object.assign({ merge: false, resolveKnownTags: true, schema: 'core' }, options);
261
+ case 'next':
262
+ if (this.directives)
263
+ this.directives.yaml.version = version;
264
+ else
265
+ this.directives = new Directives({ version });
266
+ opt = { merge: false, resolveKnownTags: true, schema: 'core' };
267
+ break;
268
+ case null:
269
+ if (this.directives)
270
+ delete this.directives;
271
+ opt = null;
221
272
  break;
222
273
  default: {
223
274
  const sv = JSON.stringify(version);
224
- throw new Error(`Expected '1.1' or '1.2' as version, but found: ${sv}`);
275
+ throw new Error(`Expected '1.1', '1.2' or null as first argument, but found: ${sv}`);
225
276
  }
226
277
  }
227
- this.schema = new Schema(_options);
278
+ // Not using `instanceof Schema` to allow for duck typing
279
+ if (options.schema instanceof Object)
280
+ this.schema = options.schema;
281
+ else if (opt)
282
+ this.schema = new Schema(Object.assign(opt, options));
283
+ else
284
+ throw new Error(`With a null YAML version, the { schema: Schema } option is required`);
228
285
  }
229
286
  // json & jsonArg are only used from toJSON()
230
287
  toJS({ json, jsonArg, mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
@@ -237,7 +294,7 @@ class Document {
237
294
  maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100,
238
295
  stringify
239
296
  };
240
- const res = toJS(this.contents, jsonArg || '', ctx);
297
+ const res = toJS(this.contents, jsonArg ?? '', ctx);
241
298
  if (typeof onAnchor === 'function')
242
299
  for (const { count, res } of ctx.anchors.values())
243
300
  onAnchor(res, count);
@@ -37,7 +37,7 @@ function createNodeAnchors(doc, prefix) {
37
37
  const sourceObjects = new Map();
38
38
  let prevAnchors = null;
39
39
  return {
40
- onAnchor(source) {
40
+ onAnchor: (source) => {
41
41
  aliasObjects.push(source);
42
42
  if (!prevAnchors)
43
43
  prevAnchors = anchorNames(doc);
@@ -50,7 +50,7 @@ function createNodeAnchors(doc, prefix) {
50
50
  * of its child nodes are. This is why anchors are set only after all of
51
51
  * the nodes have been created.
52
52
  */
53
- setAnchors() {
53
+ setAnchors: () => {
54
54
  for (const source of aliasObjects) {
55
55
  const ref = sourceObjects.get(source);
56
56
  if (typeof ref === 'object' &&
@@ -1,40 +1,41 @@
1
1
  import { Alias } from '../nodes/Alias.js';
2
- import { isNode, isPair, MAP, SEQ } from '../nodes/Node.js';
2
+ import { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/Node.js';
3
3
  import { Scalar } from '../nodes/Scalar.js';
4
4
 
5
5
  const defaultTagPrefix = 'tag:yaml.org,2002:';
6
6
  function findTagObject(value, tagName, tags) {
7
7
  if (tagName) {
8
8
  const match = tags.filter(t => t.tag === tagName);
9
- const tagObj = match.find(t => !t.format) || match[0];
9
+ const tagObj = match.find(t => !t.format) ?? match[0];
10
10
  if (!tagObj)
11
11
  throw new Error(`Tag ${tagName} not found`);
12
12
  return tagObj;
13
13
  }
14
- return tags.find(t => t.identify && t.identify(value) && !t.format);
14
+ return tags.find(t => t.identify?.(value) && !t.format);
15
15
  }
16
16
  function createNode(value, tagName, ctx) {
17
- var _a, _b;
17
+ if (isDocument(value))
18
+ value = value.contents;
18
19
  if (isNode(value))
19
20
  return value;
20
21
  if (isPair(value)) {
21
- 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);
22
23
  map.items.push(value);
23
24
  return map;
24
25
  }
25
26
  if (value instanceof String ||
26
27
  value instanceof Number ||
27
28
  value instanceof Boolean ||
28
- (typeof BigInt === 'function' && value instanceof BigInt) // not supported everywhere
29
+ (typeof BigInt !== 'undefined' && value instanceof BigInt) // not supported everywhere
29
30
  ) {
30
31
  // https://tc39.es/ecma262/#sec-serializejsonproperty
31
32
  value = value.valueOf();
32
33
  }
33
- const { onAnchor, onTagObj, schema, sourceObjects } = ctx;
34
+ const { aliasDuplicateObjects, onAnchor, onTagObj, schema, sourceObjects } = ctx;
34
35
  // Detect duplicate references to the same object & use Alias nodes for all
35
36
  // after first. The `ref` wrapper allows for circular references to resolve.
36
37
  let ref = undefined;
37
- if (value && typeof value === 'object') {
38
+ if (aliasDuplicateObjects && value && typeof value === 'object') {
38
39
  ref = sourceObjects.get(value);
39
40
  if (ref) {
40
41
  if (!ref.anchor)
@@ -46,12 +47,14 @@ function createNode(value, tagName, ctx) {
46
47
  sourceObjects.set(value, ref);
47
48
  }
48
49
  }
49
- if (tagName && tagName.startsWith('!!'))
50
+ if (tagName?.startsWith('!!'))
50
51
  tagName = defaultTagPrefix + tagName.slice(2);
51
52
  let tagObj = findTagObject(value, tagName, schema.tags);
52
53
  if (!tagObj) {
53
- if (value && typeof value.toJSON === 'function')
54
+ if (value && typeof value.toJSON === 'function') {
55
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
54
56
  value = value.toJSON();
57
+ }
55
58
  if (!value || typeof value !== 'object') {
56
59
  const node = new Scalar(value);
57
60
  if (ref)
@@ -69,7 +72,7 @@ function createNode(value, tagName, ctx) {
69
72
  onTagObj(tagObj);
70
73
  delete ctx.onTagObj;
71
74
  }
72
- const node = (tagObj === null || tagObj === void 0 ? void 0 : tagObj.createNode)
75
+ const node = tagObj?.createNode
73
76
  ? tagObj.createNode(ctx.schema, value, ctx)
74
77
  : new Scalar(value);
75
78
  if (tagName)
@@ -16,10 +16,17 @@ class Directives {
16
16
  * The directives-end/doc-start marker `---`. If `null`, a marker may still be
17
17
  * included in the document's stringified representation.
18
18
  */
19
- this.marker = null;
19
+ this.docStart = null;
20
+ /** The doc-end marker `...`. */
21
+ this.docEnd = false;
20
22
  this.yaml = Object.assign({}, Directives.defaultYaml, yaml);
21
23
  this.tags = Object.assign({}, Directives.defaultTags, tags);
22
24
  }
25
+ clone() {
26
+ const copy = new Directives(this.yaml, this.tags);
27
+ copy.docStart = this.docStart;
28
+ return copy;
29
+ }
23
30
  /**
24
31
  * During parsing, get a Directives instance for the current document and
25
32
  * update the stream state according to the current version's spec.
@@ -66,7 +73,7 @@ class Directives {
66
73
  }
67
74
  case '%YAML': {
68
75
  this.yaml.explicit = true;
69
- if (parts.length < 1) {
76
+ if (parts.length !== 1) {
70
77
  onError(0, '%YAML directive should contain exactly one part');
71
78
  return false;
72
79
  }
@@ -76,7 +83,8 @@ class Directives {
76
83
  return true;
77
84
  }
78
85
  else {
79
- onError(6, `Unsupported YAML version ${version}`, true);
86
+ const isValid = /^\d+\.\d+$/.test(version);
87
+ onError(6, `Unsupported YAML version ${version}`, isValid);
80
88
  return false;
81
89
  }
82
90
  }
@@ -47,7 +47,7 @@ const prettifyError = (src, lc) => (error) => {
47
47
  let count = 1;
48
48
  const end = error.linePos[1];
49
49
  if (end && end.line === line && end.col > col) {
50
- count = Math.min(end.col - col, 80 - ci);
50
+ count = Math.max(1, Math.min(end.col - col, 80 - ci));
51
51
  }
52
52
  const pointer = ' '.repeat(ci) + '^'.repeat(count);
53
53
  error.message += `:\n\n${lineStr}\n${pointer}\n`;