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
@@ -10,6 +10,7 @@ const CN = { composeNode, composeEmptyNode };
10
10
  function composeNode(ctx, token, props, onError) {
11
11
  const { spaceBefore, comment, anchor, tag } = props;
12
12
  let node;
13
+ let isSrcToken = true;
13
14
  switch (token.type) {
14
15
  case 'alias':
15
16
  node = composeAlias(ctx, token, onError);
@@ -31,9 +32,14 @@ function composeNode(ctx, token, props, onError) {
31
32
  if (anchor)
32
33
  node.anchor = anchor.source.substring(1);
33
34
  break;
34
- default:
35
- console.log(token);
36
- throw new Error(`Unsupporten token type: ${token.type}`);
35
+ default: {
36
+ const message = token.type === 'error'
37
+ ? token.message
38
+ : `Unsupported token (type: ${token.type})`;
39
+ onError(token, 'UNEXPECTED_TOKEN', message);
40
+ node = composeEmptyNode(ctx, token.offset, undefined, null, props, onError);
41
+ isSrcToken = false;
42
+ }
37
43
  }
38
44
  if (anchor && node.anchor === '')
39
45
  onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
@@ -45,9 +51,12 @@ function composeNode(ctx, token, props, onError) {
45
51
  else
46
52
  node.commentBefore = comment;
47
53
  }
54
+ // @ts-expect-error Type checking misses meaning of isSrcToken
55
+ if (ctx.options.keepSourceTokens && isSrcToken)
56
+ node.srcToken = token;
48
57
  return node;
49
58
  }
50
- function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anchor, tag }, onError) {
59
+ function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anchor, tag, end }, onError) {
51
60
  const token = {
52
61
  type: 'scalar',
53
62
  offset: utilEmptyScalarPosition.emptyScalarPosition(offset, before, pos),
@@ -62,14 +71,18 @@ function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anch
62
71
  }
63
72
  if (spaceBefore)
64
73
  node.spaceBefore = true;
65
- if (comment)
74
+ if (comment) {
66
75
  node.comment = comment;
76
+ node.range[2] = end;
77
+ }
67
78
  return node;
68
79
  }
69
80
  function composeAlias({ options }, { offset, source, end }, onError) {
70
81
  const alias = new Alias.Alias(source.substring(1));
71
82
  if (alias.source === '')
72
83
  onError(offset, 'BAD_ALIAS', 'Alias cannot be an empty string');
84
+ if (alias.source.endsWith(':'))
85
+ onError(offset + source.length - 1, 'BAD_ALIAS', 'Alias ending in : is ambiguous', true);
73
86
  const valueEnd = offset + source.length;
74
87
  const re = resolveEnd.resolveEnd(end, valueEnd, options.strict, onError);
75
88
  alias.range = [offset, valueEnd, re.offset];
@@ -14,14 +14,17 @@ function composeScalar(ctx, token, tagToken, onError) {
14
14
  : null;
15
15
  const tag = tagToken && tagName
16
16
  ? findScalarTagByName(ctx.schema, value, tagName, tagToken, onError)
17
- : findScalarTagByTest(ctx.schema, value, token.type === 'scalar');
17
+ : token.type === 'scalar'
18
+ ? findScalarTagByTest(ctx, value, token, onError)
19
+ : ctx.schema[Node.SCALAR];
18
20
  let scalar;
19
21
  try {
20
- const res = tag.resolve(value, msg => onError(tagToken || token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
22
+ const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
21
23
  scalar = Node.isScalar(res) ? res : new Scalar.Scalar(res);
22
24
  }
23
25
  catch (error) {
24
- onError(tagToken || token, 'TAG_RESOLVE_FAILED', error.message);
26
+ const msg = error instanceof Error ? error.message : String(error);
27
+ onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg);
25
28
  scalar = new Scalar.Scalar(value);
26
29
  }
27
30
  scalar.range = range;
@@ -37,7 +40,6 @@ function composeScalar(ctx, token, tagToken, onError) {
37
40
  return scalar;
38
41
  }
39
42
  function findScalarTagByName(schema, value, tagName, tagToken, onError) {
40
- var _a;
41
43
  if (tagName === '!')
42
44
  return schema[Node.SCALAR]; // non-specific tag
43
45
  const matchWithTest = [];
@@ -50,7 +52,7 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
50
52
  }
51
53
  }
52
54
  for (const tag of matchWithTest)
53
- if ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value))
55
+ if (tag.test?.test(value))
54
56
  return tag;
55
57
  const kt = schema.knownTags[tagName];
56
58
  if (kt && !kt.collection) {
@@ -62,15 +64,19 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
62
64
  onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, tagName !== 'tag:yaml.org,2002:str');
63
65
  return schema[Node.SCALAR];
64
66
  }
65
- function findScalarTagByTest(schema, value, apply) {
66
- var _a;
67
- if (apply) {
68
- for (const tag of schema.tags) {
69
- if (tag.default && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value)))
70
- return tag;
67
+ function findScalarTagByTest({ directives, schema }, value, token, onError) {
68
+ const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[Node.SCALAR];
69
+ if (schema.compat) {
70
+ const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
71
+ schema[Node.SCALAR];
72
+ if (tag.tag !== compat.tag) {
73
+ const ts = directives.tagString(tag.tag);
74
+ const cs = directives.tagString(compat.tag);
75
+ const msg = `Value may be parsed as either ${ts} or ${cs}`;
76
+ onError(token, 'TAG_RESOLVE_FAILED', msg, true);
71
77
  }
72
78
  }
73
- return schema[Node.SCALAR];
79
+ return tag;
74
80
  }
75
81
 
76
82
  exports.composeScalar = composeScalar;
@@ -2,13 +2,13 @@ import { Directives } from '../doc/directives.js';
2
2
  import { Document } from '../doc/Document.js';
3
3
  import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.js';
4
4
  import { Range } from '../nodes/Node.js';
5
- import { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
5
+ import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
6
6
  import type { Token } from '../parse/cst.js';
7
- declare type ErrorSource = number | [number, number] | Range | {
7
+ type ErrorSource = number | [number, number] | Range | {
8
8
  offset: number;
9
9
  source?: string;
10
10
  };
11
- export declare type ComposeErrorHandler = (source: ErrorSource, code: ErrorCode, message: string, warning?: boolean) => void;
11
+ export type ComposeErrorHandler = (source: ErrorSource, code: ErrorCode, message: string, warning?: boolean) => void;
12
12
  /**
13
13
  * Compose a stream of CST nodes into a stream of YAML Documents.
14
14
  *
@@ -4,7 +4,6 @@ var directives = require('../doc/directives.js');
4
4
  var Document = require('../doc/Document.js');
5
5
  var errors = require('../errors.js');
6
6
  var Node = require('../nodes/Node.js');
7
- var options = require('../options.js');
8
7
  var composeDoc = require('./compose-doc.js');
9
8
  var resolveEnd = require('./resolve-end.js');
10
9
 
@@ -17,7 +16,6 @@ function getErrorPos(src) {
17
16
  return [offset, offset + (typeof source === 'string' ? source.length : 1)];
18
17
  }
19
18
  function parsePrelude(prelude) {
20
- var _a;
21
19
  let comment = '';
22
20
  let atComment = false;
23
21
  let afterEmptyLine = false;
@@ -32,7 +30,7 @@ function parsePrelude(prelude) {
32
30
  afterEmptyLine = false;
33
31
  break;
34
32
  case '%':
35
- if (((_a = prelude[i + 1]) === null || _a === void 0 ? void 0 : _a[0]) !== '#')
33
+ if (prelude[i + 1]?.[0] !== '#')
36
34
  i += 1;
37
35
  atComment = false;
38
36
  break;
@@ -57,7 +55,7 @@ function parsePrelude(prelude) {
57
55
  * ```
58
56
  */
59
57
  class Composer {
60
- constructor(options$1 = {}) {
58
+ constructor(options = {}) {
61
59
  this.doc = null;
62
60
  this.atDirectives = false;
63
61
  this.prelude = [];
@@ -70,10 +68,9 @@ class Composer {
70
68
  else
71
69
  this.errors.push(new errors.YAMLParseError(pos, code, message));
72
70
  };
73
- this.directives = new directives.Directives({
74
- version: options$1.version || options.defaultOptions.version
75
- });
76
- this.options = options$1;
71
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
72
+ this.directives = new directives.Directives({ version: options.version || '1.2' });
73
+ this.options = options;
77
74
  }
78
75
  decorate(doc, afterDoc) {
79
76
  const { comment, afterEmptyLine } = parsePrelude(this.prelude);
@@ -83,7 +80,7 @@ class Composer {
83
80
  if (afterDoc) {
84
81
  doc.comment = doc.comment ? `${doc.comment}\n${comment}` : comment;
85
82
  }
86
- else if (afterEmptyLine || doc.directives.marker || !dc) {
83
+ else if (afterEmptyLine || doc.directives.docStart || !dc) {
87
84
  doc.commentBefore = comment;
88
85
  }
89
86
  else if (Node.isCollection(dc) && !dc.flow && dc.items.length > 0) {
@@ -150,8 +147,8 @@ class Composer {
150
147
  break;
151
148
  case 'document': {
152
149
  const doc = composeDoc.composeDoc(this.options, this.directives, token, this.onError);
153
- if (this.atDirectives && !doc.directives.marker)
154
- this.onError(token, 'MISSING_CHAR', 'Missing directives-end indicator line');
150
+ if (this.atDirectives && !doc.directives.docStart)
151
+ this.onError(token, 'MISSING_CHAR', 'Missing directives-end/doc-start indicator line');
155
152
  this.decorate(doc, false);
156
153
  if (this.doc)
157
154
  yield this.doc;
@@ -183,6 +180,7 @@ class Composer {
183
180
  this.errors.push(new errors.YAMLParseError(getErrorPos(token), 'UNEXPECTED_TOKEN', msg));
184
181
  break;
185
182
  }
183
+ this.doc.directives.docEnd = true;
186
184
  const end = resolveEnd.resolveEnd(token.end, token.offset + token.source.length, this.doc.options.strict, this.onError);
187
185
  this.decorate(this.doc, true);
188
186
  if (end.comment) {
@@ -209,7 +207,7 @@ class Composer {
209
207
  this.doc = null;
210
208
  }
211
209
  else if (forceDoc) {
212
- const opts = Object.assign({ directives: this.directives }, this.options);
210
+ const opts = Object.assign({ _directives: this.directives }, this.options);
213
211
  const doc = new Document.Document(undefined, opts);
214
212
  if (this.atDirectives)
215
213
  this.onError(endOffset, 'MISSING_CHAR', 'Missing directives-end indicator line');
@@ -4,18 +4,22 @@ var Pair = require('../nodes/Pair.js');
4
4
  var YAMLMap = require('../nodes/YAMLMap.js');
5
5
  var resolveProps = require('./resolve-props.js');
6
6
  var utilContainsNewline = require('./util-contains-newline.js');
7
+ var utilFlowIndentCheck = require('./util-flow-indent-check.js');
7
8
  var utilMapIncludes = require('./util-map-includes.js');
8
9
 
9
10
  const startColMsg = 'All mapping items must start at the same column';
10
11
  function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
11
- var _a;
12
12
  const map = new YAMLMap.YAMLMap(ctx.schema);
13
+ if (ctx.atRoot)
14
+ ctx.atRoot = false;
13
15
  let offset = bm.offset;
14
- for (const { start, key, sep, value } of bm.items) {
16
+ let commentEnd = null;
17
+ for (const collItem of bm.items) {
18
+ const { start, key, sep, value } = collItem;
15
19
  // key properties
16
20
  const keyProps = resolveProps.resolveProps(start, {
17
21
  indicator: 'explicit-key-ind',
18
- next: key || (sep === null || sep === void 0 ? void 0 : sep[0]),
22
+ next: key ?? sep?.[0],
19
23
  offset,
20
24
  onError,
21
25
  startOnNewline: true
@@ -29,7 +33,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
29
33
  onError(offset, 'BAD_INDENT', startColMsg);
30
34
  }
31
35
  if (!keyProps.anchor && !keyProps.tag && !sep) {
32
- // TODO: assert being at last item?
36
+ commentEnd = keyProps.end;
33
37
  if (keyProps.comment) {
34
38
  if (map.comment)
35
39
  map.comment += '\n' + keyProps.comment;
@@ -38,21 +42,24 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
38
42
  }
39
43
  continue;
40
44
  }
45
+ if (keyProps.hasNewlineAfterProp || utilContainsNewline.containsNewline(key)) {
46
+ onError(key ?? start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
47
+ }
41
48
  }
42
- else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent)
49
+ else if (keyProps.found?.indent !== bm.indent) {
43
50
  onError(offset, 'BAD_INDENT', startColMsg);
44
- if (implicitKey && utilContainsNewline.containsNewline(key))
45
- onError(key, // checked by containsNewline()
46
- 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
51
+ }
47
52
  // key value
48
53
  const keyStart = keyProps.end;
49
54
  const keyNode = key
50
55
  ? composeNode(ctx, key, keyProps, onError)
51
56
  : composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
57
+ if (ctx.schema.compat)
58
+ utilFlowIndentCheck.flowIndentCheck(bm.indent, key, onError);
52
59
  if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
53
60
  onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
54
61
  // value properties
55
- const valueProps = resolveProps.resolveProps(sep || [], {
62
+ const valueProps = resolveProps.resolveProps(sep ?? [], {
56
63
  indicator: 'map-value-ind',
57
64
  next: value,
58
65
  offset: keyNode.range[2],
@@ -62,7 +69,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
62
69
  offset = valueProps.end;
63
70
  if (valueProps.found) {
64
71
  if (implicitKey) {
65
- if ((value === null || value === void 0 ? void 0 : value.type) === 'block-map' && !valueProps.hasNewline)
72
+ if (value?.type === 'block-map' && !valueProps.hasNewline)
66
73
  onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'Nested mappings are not allowed in compact mappings');
67
74
  if (ctx.options.strict &&
68
75
  keyProps.start < valueProps.found.offset - 1024)
@@ -72,8 +79,13 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
72
79
  const valueNode = value
73
80
  ? composeNode(ctx, value, valueProps, onError)
74
81
  : composeEmptyNode(ctx, offset, sep, null, valueProps, onError);
82
+ if (ctx.schema.compat)
83
+ utilFlowIndentCheck.flowIndentCheck(bm.indent, value, onError);
75
84
  offset = valueNode.range[2];
76
- map.items.push(new Pair.Pair(keyNode, valueNode));
85
+ const pair = new Pair.Pair(keyNode, valueNode);
86
+ if (ctx.options.keepSourceTokens)
87
+ pair.srcToken = collItem;
88
+ map.items.push(pair);
77
89
  }
78
90
  else {
79
91
  // key with no value
@@ -85,10 +97,15 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
85
97
  else
86
98
  keyNode.comment = valueProps.comment;
87
99
  }
88
- map.items.push(new Pair.Pair(keyNode));
100
+ const pair = new Pair.Pair(keyNode);
101
+ if (ctx.options.keepSourceTokens)
102
+ pair.srcToken = collItem;
103
+ map.items.push(pair);
89
104
  }
90
105
  }
91
- map.range = [bm.offset, offset, offset];
106
+ if (commentEnd && commentEnd < offset)
107
+ onError(commentEnd, 'IMPOSSIBLE', 'Map comment with trailing content');
108
+ map.range = [bm.offset, offset, commentEnd ?? offset];
92
109
  return map;
93
110
  }
94
111
 
@@ -19,8 +19,10 @@ function resolveBlockScalar(scalar, strict, onError) {
19
19
  break;
20
20
  }
21
21
  // shortcut for empty contents
22
- if (!scalar.source || chompStart === 0) {
23
- const value = header.chomp === '+' ? lines.map(line => line[0]).join('\n') : '';
22
+ if (chompStart === 0) {
23
+ const value = header.chomp === '+' && lines.length > 0
24
+ ? '\n'.repeat(Math.max(1, lines.length - 1))
25
+ : '';
24
26
  let end = start + header.length;
25
27
  if (scalar.source)
26
28
  end += scalar.source.length;
@@ -48,6 +50,11 @@ function resolveBlockScalar(scalar, strict, onError) {
48
50
  }
49
51
  offset += indent.length + content.length + 1;
50
52
  }
53
+ // include trailing more-indented empty lines in content
54
+ for (let i = lines.length - 1; i >= chompStart; --i) {
55
+ if (lines[i][0].length > trimIndent)
56
+ chompStart = i + 1;
57
+ }
51
58
  let value = '';
52
59
  let sep = '';
53
60
  let prevMoreIndented = false;
@@ -177,7 +184,9 @@ function splitLines(source) {
177
184
  const split = source.split(/\n( *)/);
178
185
  const first = split[0];
179
186
  const m = first.match(/^( *)/);
180
- const line0 = m && m[1] ? [m[1], first.slice(m[1].length)] : ['', first];
187
+ const line0 = m?.[1]
188
+ ? [m[1], first.slice(m[1].length)]
189
+ : ['', first];
181
190
  const lines = [line0];
182
191
  for (let i = 1; i < split.length; i += 2)
183
192
  lines.push([split[i], split[i + 1]]);
@@ -2,10 +2,14 @@
2
2
 
3
3
  var YAMLSeq = require('../nodes/YAMLSeq.js');
4
4
  var resolveProps = require('./resolve-props.js');
5
+ var utilFlowIndentCheck = require('./util-flow-indent-check.js');
5
6
 
6
7
  function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
7
8
  const seq = new YAMLSeq.YAMLSeq(ctx.schema);
9
+ if (ctx.atRoot)
10
+ ctx.atRoot = false;
8
11
  let offset = bs.offset;
12
+ let commentEnd = null;
9
13
  for (const { start, value } of bs.items) {
10
14
  const props = resolveProps.resolveProps(start, {
11
15
  indicator: 'seq-item-ind',
@@ -14,16 +18,15 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
14
18
  onError,
15
19
  startOnNewline: true
16
20
  });
17
- offset = props.end;
18
21
  if (!props.found) {
19
22
  if (props.anchor || props.tag || value) {
20
23
  if (value && value.type === 'block-seq')
21
- onError(offset, 'BAD_INDENT', 'All sequence items must start at the same column');
24
+ onError(props.end, 'BAD_INDENT', 'All sequence items must start at the same column');
22
25
  else
23
26
  onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
24
27
  }
25
28
  else {
26
- // TODO: assert being at last item?
29
+ commentEnd = props.end;
27
30
  if (props.comment)
28
31
  seq.comment = props.comment;
29
32
  continue;
@@ -31,11 +34,13 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
31
34
  }
32
35
  const node = value
33
36
  ? composeNode(ctx, value, props, onError)
34
- : composeEmptyNode(ctx, offset, start, null, props, onError);
37
+ : composeEmptyNode(ctx, props.end, start, null, props, onError);
38
+ if (ctx.schema.compat)
39
+ utilFlowIndentCheck.flowIndentCheck(bs.indent, value, onError);
35
40
  offset = node.range[2];
36
41
  seq.items.push(node);
37
42
  }
38
- seq.range = [bs.offset, offset, offset];
43
+ seq.range = [bs.offset, offset, commentEnd ?? offset];
39
44
  return seq;
40
45
  }
41
46
 
@@ -18,13 +18,17 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
18
18
  ? new YAMLMap.YAMLMap(ctx.schema)
19
19
  : new YAMLSeq.YAMLSeq(ctx.schema);
20
20
  coll.flow = true;
21
- let offset = fc.offset;
21
+ const atRoot = ctx.atRoot;
22
+ if (atRoot)
23
+ ctx.atRoot = false;
24
+ let offset = fc.offset + fc.start.source.length;
22
25
  for (let i = 0; i < fc.items.length; ++i) {
23
- const { start, key, sep, value } = fc.items[i];
26
+ const collItem = fc.items[i];
27
+ const { start, key, sep, value } = collItem;
24
28
  const props = resolveProps.resolveProps(start, {
25
29
  flow: fcName,
26
30
  indicator: 'explicit-key-ind',
27
- next: key || (sep === null || sep === void 0 ? void 0 : sep[0]),
31
+ next: key ?? sep?.[0],
28
32
  offset,
29
33
  onError,
30
34
  startOnNewline: false
@@ -41,6 +45,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
41
45
  else
42
46
  coll.comment = props.comment;
43
47
  }
48
+ offset = props.end;
44
49
  continue;
45
50
  }
46
51
  if (!isMap && ctx.options.strict && utilContainsNewline.containsNewline(key))
@@ -71,7 +76,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
71
76
  if (prevItemComment) {
72
77
  let prev = coll.items[coll.items.length - 1];
73
78
  if (Node.isPair(prev))
74
- prev = prev.value || prev.key;
79
+ prev = prev.value ?? prev.key;
75
80
  if (prev.comment)
76
81
  prev.comment += '\n' + prevItemComment;
77
82
  else
@@ -101,7 +106,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
101
106
  if (isBlock(key))
102
107
  onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
103
108
  // value properties
104
- const valueProps = resolveProps.resolveProps(sep || [], {
109
+ const valueProps = resolveProps.resolveProps(sep ?? [], {
105
110
  flow: fcName,
106
111
  indicator: 'map-value-ind',
107
112
  next: value,
@@ -147,6 +152,8 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
147
152
  keyNode.comment = valueProps.comment;
148
153
  }
149
154
  const pair = new Pair.Pair(keyNode, valueNode);
155
+ if (ctx.options.keepSourceTokens)
156
+ pair.srcToken = collItem;
150
157
  if (isMap) {
151
158
  const map = coll;
152
159
  if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
@@ -168,7 +175,11 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
168
175
  if (ce && ce.source === expectedEnd)
169
176
  cePos = ce.offset + ce.source.length;
170
177
  else {
171
- onError(offset + 1, 'MISSING_CHAR', `Expected ${fcName} to end with ${expectedEnd}`);
178
+ const name = fcName[0].toUpperCase() + fcName.substring(1);
179
+ const msg = atRoot
180
+ ? `${name} must end with a ${expectedEnd}`
181
+ : `${name} in block collection must be sufficiently indented and end with a ${expectedEnd}`;
182
+ onError(offset, atRoot ? 'MISSING_CHAR' : 'BAD_INDENT', msg);
172
183
  if (ce && ce.source.length !== 1)
173
184
  ee.unshift(ce);
174
185
  }
@@ -113,7 +113,7 @@ function foldLines(source) {
113
113
  const last = /[ \t]*(.*)/sy;
114
114
  last.lastIndex = pos;
115
115
  match = last.exec(source);
116
- return res + sep + ((match && match[1]) || '');
116
+ return res + sep + (match?.[1] ?? '');
117
117
  }
118
118
  function doubleQuotedValue(source, onError) {
119
119
  let res = '';
@@ -137,6 +137,12 @@ function doubleQuotedValue(source, onError) {
137
137
  while (next === ' ' || next === '\t')
138
138
  next = source[++i + 1];
139
139
  }
140
+ else if (next === '\r' && source[i + 1] === '\n') {
141
+ // skip escaped CRLF newlines, but still trim the following line
142
+ next = source[++i + 1];
143
+ while (next === ' ' || next === '\t')
144
+ next = source[++i + 1];
145
+ }
140
146
  else if (next === 'x' || next === 'u' || next === 'U') {
141
147
  const length = { x: 2, u: 4, U: 8 }[next];
142
148
  res += parseCharCode(source, i + 1, length, onError);
@@ -154,7 +160,7 @@ function doubleQuotedValue(source, onError) {
154
160
  let next = source[i + 1];
155
161
  while (next === ' ' || next === '\t')
156
162
  next = source[++i + 1];
157
- if (next !== '\n')
163
+ if (next !== '\n' && !(next === '\r' && source[i + 2] === '\n'))
158
164
  res += i > wsStart ? source.slice(wsStart, i + 1) : ch;
159
165
  }
160
166
  else {
@@ -1,7 +1,7 @@
1
1
  import type { SourceToken, Token } from '../parse/cst.js';
2
2
  import type { ComposeErrorHandler } from './composer.js';
3
3
  export interface ResolvePropsArg {
4
- flow?: string;
4
+ flow?: 'flow map' | 'flow sequence';
5
5
  indicator: 'doc-start' | 'explicit-key-ind' | 'map-value-ind' | 'seq-item-ind';
6
6
  next: Token | null | undefined;
7
7
  offset: number;
@@ -14,6 +14,7 @@ export declare function resolveProps(tokens: SourceToken[], { flow, indicator, n
14
14
  spaceBefore: boolean;
15
15
  comment: string;
16
16
  hasNewline: boolean;
17
+ hasNewlineAfterProp: boolean;
17
18
  anchor: SourceToken | null;
18
19
  tag: SourceToken | null;
19
20
  end: number;
@@ -7,6 +7,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
7
7
  let comment = '';
8
8
  let commentSep = '';
9
9
  let hasNewline = false;
10
+ let hasNewlineAfterProp = false;
10
11
  let reqSpace = false;
11
12
  let anchor = null;
12
13
  let tag = null;
@@ -56,11 +57,15 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
56
57
  commentSep += token.source;
57
58
  atNewline = true;
58
59
  hasNewline = true;
60
+ if (anchor || tag)
61
+ hasNewlineAfterProp = true;
59
62
  hasSpace = true;
60
63
  break;
61
64
  case 'anchor':
62
65
  if (anchor)
63
66
  onError(token, 'MULTIPLE_ANCHORS', 'A node can have at most one anchor');
67
+ if (token.source.endsWith(':'))
68
+ onError(token.offset + token.source.length - 1, 'BAD_ALIAS', 'Anchor ending in : is ambiguous', true);
64
69
  anchor = token;
65
70
  if (start === null)
66
71
  start = token.offset;
@@ -83,6 +88,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
83
88
  // Could here handle preceding comments differently
84
89
  if (anchor || tag)
85
90
  onError(token, 'BAD_PROP_ORDER', `Anchors and tags must be after the ${token.source} indicator`);
91
+ if (found)
92
+ onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow ?? 'collection'}`);
86
93
  found = token;
87
94
  atNewline = false;
88
95
  hasSpace = false;
@@ -118,10 +125,11 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
118
125
  spaceBefore,
119
126
  comment,
120
127
  hasNewline,
128
+ hasNewlineAfterProp,
121
129
  anchor,
122
130
  tag,
123
131
  end,
124
- start: start !== null && start !== void 0 ? start : end
132
+ start: start ?? end
125
133
  };
126
134
  }
127
135
 
@@ -16,7 +16,7 @@ function emptyScalarPosition(offset, before, pos) {
16
16
  // Technically, an empty scalar is immediately after the last non-empty
17
17
  // node, but it's more useful to place it after any whitespace.
18
18
  st = before[++i];
19
- while ((st === null || st === void 0 ? void 0 : st.type) === 'space') {
19
+ while (st?.type === 'space') {
20
20
  offset += st.source.length;
21
21
  st = before[++i];
22
22
  }
@@ -0,0 +1,3 @@
1
+ import { Token } from '../parse/cst';
2
+ import { ComposeErrorHandler } from './composer';
3
+ export declare function flowIndentCheck(indent: number, fc: Token | null | undefined, onError: ComposeErrorHandler): void;
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ var utilContainsNewline = require('./util-contains-newline.js');
4
+
5
+ function flowIndentCheck(indent, fc, onError) {
6
+ if (fc?.type === 'flow-collection') {
7
+ const end = fc.end[0];
8
+ if (end.indent === indent &&
9
+ (end.source === ']' || end.source === '}') &&
10
+ utilContainsNewline.containsNewline(fc)) {
11
+ const msg = 'Flow end indicator should be more indented than parent';
12
+ onError(end, 'BAD_INDENT', msg, true);
13
+ }
14
+ }
15
+ }
16
+
17
+ exports.flowIndentCheck = flowIndentCheck;