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
@@ -6,6 +6,12 @@ import type { BlockScalar, FlowScalar, SourceToken, Token } from './cst.js';
6
6
  * If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
7
7
  * Otherwise, return `null`.
8
8
  */
9
+ export declare function resolveAsScalar(token: FlowScalar | BlockScalar, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): {
10
+ value: string;
11
+ type: Scalar.Type | null;
12
+ comment: string;
13
+ range: Range;
14
+ };
9
15
  export declare function resolveAsScalar(token: Token | null | undefined, strict?: boolean, onError?: (offset: number, code: ErrorCode, message: string) => void): {
10
16
  value: string;
11
17
  type: Scalar.Type | null;
@@ -5,10 +5,6 @@ var resolveFlowScalar = require('../compose/resolve-flow-scalar.js');
5
5
  var errors = require('../errors.js');
6
6
  var stringifyString = require('../stringify/stringifyString.js');
7
7
 
8
- /**
9
- * If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
10
- * Otherwise, return `null`.
11
- */
12
8
  function resolveAsScalar(token, strict = true, onError) {
13
9
  if (token) {
14
10
  const _onError = (pos, code, message) => {
@@ -44,15 +40,14 @@ function resolveAsScalar(token, strict = true, onError) {
44
40
  * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
45
41
  */
46
42
  function createScalarToken(value, context) {
47
- var _a;
48
43
  const { implicitKey = false, indent, inFlow = false, offset = -1, type = 'PLAIN' } = context;
49
44
  const source = stringifyString.stringifyString({ type, value }, {
50
45
  implicitKey,
51
46
  indent: indent > 0 ? ' '.repeat(indent) : '',
52
47
  inFlow,
53
- options: { lineWidth: -1 }
48
+ options: { blockQuote: true, lineWidth: -1 }
54
49
  });
55
- const end = (_a = context.end) !== null && _a !== void 0 ? _a : [
50
+ const end = context.end ?? [
56
51
  { type: 'newline', offset: -1, indent, source: '\n' }
57
52
  ];
58
53
  switch (source[0]) {
@@ -119,7 +114,7 @@ function setScalarValue(token, value, context = {}) {
119
114
  implicitKey: implicitKey || indent === null,
120
115
  indent: indent !== null && indent > 0 ? ' '.repeat(indent) : '',
121
116
  inFlow,
122
- options: { lineWidth: -1 }
117
+ options: { blockQuote: true, lineWidth: -1 }
123
118
  });
124
119
  switch (source[0]) {
125
120
  case '|':
@@ -1,6 +1,6 @@
1
1
  import type { CollectionItem, Document } from './cst.js';
2
- export declare type VisitPath = readonly ['key' | 'value', number][];
3
- export declare type Visitor = (item: CollectionItem, path: VisitPath) => number | symbol | Visitor | void;
2
+ export type VisitPath = readonly ['key' | 'value', number][];
3
+ export type Visitor = (item: CollectionItem, path: VisitPath) => number | symbol | Visitor | void;
4
4
  /**
5
5
  * Apply a visitor to a CST document or item.
6
6
  *
@@ -49,7 +49,7 @@ visit.REMOVE = REMOVE;
49
49
  visit.itemAtPath = (cst, path) => {
50
50
  let item = cst;
51
51
  for (const [field, index] of path) {
52
- const tok = item && item[field];
52
+ const tok = item?.[field];
53
53
  if (tok && 'items' in tok) {
54
54
  item = tok.items[index];
55
55
  }
@@ -66,7 +66,7 @@ visit.itemAtPath = (cst, path) => {
66
66
  visit.parentCollection = (cst, path) => {
67
67
  const parent = visit.itemAtPath(cst, path.slice(0, -1));
68
68
  const field = path[path.length - 1][0];
69
- const coll = parent && parent[field];
69
+ const coll = parent?.[field];
70
70
  if (coll && 'items' in coll)
71
71
  return coll;
72
72
  throw new Error('Parent collection not found');
@@ -72,7 +72,7 @@ export interface BlockSequence {
72
72
  value?: Token;
73
73
  }>;
74
74
  }
75
- export declare type CollectionItem = {
75
+ export type CollectionItem = {
76
76
  start: SourceToken[];
77
77
  key?: Token | null;
78
78
  sep?: SourceToken[];
@@ -86,8 +86,8 @@ export interface FlowCollection {
86
86
  items: CollectionItem[];
87
87
  end: SourceToken[];
88
88
  }
89
- export declare type Token = SourceToken | ErrorToken | Directive | Document | DocumentEnd | FlowScalar | BlockScalar | BlockMap | BlockSequence | FlowCollection;
90
- export declare type TokenType = SourceToken['type'] | DocumentEnd['type'] | FlowScalar['type'];
89
+ export type Token = SourceToken | ErrorToken | Directive | Document | DocumentEnd | FlowScalar | BlockScalar | BlockMap | BlockSequence | FlowCollection;
90
+ export type TokenType = SourceToken['type'] | DocumentEnd['type'] | FlowScalar['type'];
91
91
  /** The byte order mark */
92
92
  export declare const BOM = "\uFEFF";
93
93
  /** Start of doc-mode */
@@ -47,6 +47,8 @@ export declare class Lexer {
47
47
  private indentNext;
48
48
  /** Indentation level of the current line. */
49
49
  private indentValue;
50
+ /** Position of the next \n character. */
51
+ private lineEndPos;
50
52
  /** Stores the state of the lexer if reaching the end of incpomplete input */
51
53
  private next;
52
54
  /** A pointer to `buffer`; the current position of the lexer. */
@@ -136,6 +136,8 @@ class Lexer {
136
136
  this.indentNext = 0;
137
137
  /** Indentation level of the current line. */
138
138
  this.indentValue = 0;
139
+ /** Position of the next \n character. */
140
+ this.lineEndPos = null;
139
141
  /** Stores the state of the lexer if reaching the end of incpomplete input */
140
142
  this.next = null;
141
143
  /** A pointer to `buffer`; the current position of the lexer. */
@@ -148,10 +150,12 @@ class Lexer {
148
150
  * @returns A generator of lexical tokens
149
151
  */
150
152
  *lex(source, incomplete = false) {
151
- if (source)
153
+ if (source) {
152
154
  this.buffer = this.buffer ? this.buffer + source : source;
155
+ this.lineEndPos = null;
156
+ }
153
157
  this.atEnd = !incomplete;
154
- let next = this.next || 'stream';
158
+ let next = this.next ?? 'stream';
155
159
  while (next && (incomplete || this.hasChars(1)))
156
160
  next = yield* this.parseNext(next);
157
161
  }
@@ -192,7 +196,11 @@ class Lexer {
192
196
  return offset;
193
197
  }
194
198
  getLine() {
195
- let end = this.buffer.indexOf('\n', this.pos);
199
+ let end = this.lineEndPos;
200
+ if (typeof end !== 'number' || (end !== -1 && end < this.pos)) {
201
+ end = this.buffer.indexOf('\n', this.pos);
202
+ this.lineEndPos = end;
203
+ }
196
204
  if (end === -1)
197
205
  return this.atEnd ? this.buffer.substring(this.pos) : null;
198
206
  if (this.buffer[end - 1] === '\r')
@@ -205,6 +213,7 @@ class Lexer {
205
213
  setNext(state) {
206
214
  this.buffer = this.buffer.substring(this.pos);
207
215
  this.pos = 0;
216
+ this.lineEndPos = null;
208
217
  this.next = state;
209
218
  return null;
210
219
  }
@@ -350,14 +359,19 @@ class Lexer {
350
359
  let indent = -1;
351
360
  do {
352
361
  nl = yield* this.pushNewline();
353
- sp = yield* this.pushSpaces(true);
354
- if (nl > 0)
362
+ if (nl > 0) {
363
+ sp = yield* this.pushSpaces(false);
355
364
  this.indentValue = indent = sp;
365
+ }
366
+ else {
367
+ sp = 0;
368
+ }
369
+ sp += yield* this.pushSpaces(true);
356
370
  } while (nl + sp > 0);
357
371
  const line = this.getLine();
358
372
  if (line === null)
359
373
  return this.setNext('flow');
360
- if ((indent !== -1 && indent < this.indentNext) ||
374
+ if ((indent !== -1 && indent < this.indentNext && line[0] !== '#') ||
361
375
  (indent === 0 &&
362
376
  (line.startsWith('---') || line.startsWith('...')) &&
363
377
  isEmpty(line[3]))) {
@@ -375,8 +389,11 @@ class Lexer {
375
389
  }
376
390
  }
377
391
  let n = 0;
378
- while (line[n] === ',')
379
- n += (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
392
+ while (line[n] === ',') {
393
+ n += yield* this.pushCount(1);
394
+ n += yield* this.pushSpaces(true);
395
+ this.flowKey = false;
396
+ }
380
397
  n += yield* this.pushIndicators();
381
398
  switch (line[n]) {
382
399
  case undefined:
@@ -406,6 +423,7 @@ class Lexer {
406
423
  case ':': {
407
424
  const next = this.charAt(1);
408
425
  if (this.flowKey || isEmpty(next) || next === ',') {
426
+ this.flowKey = false;
409
427
  yield* this.pushCount(1);
410
428
  yield* this.pushSpaces(true);
411
429
  return 'flow';
@@ -435,17 +453,19 @@ class Lexer {
435
453
  end = this.buffer.indexOf('"', end + 1);
436
454
  }
437
455
  }
438
- let nl = this.buffer.indexOf('\n', this.pos);
439
- if (nl !== -1 && nl < end) {
440
- while (nl !== -1 && nl < end) {
456
+ // Only looking for newlines within the quotes
457
+ const qb = this.buffer.substring(0, end);
458
+ let nl = qb.indexOf('\n', this.pos);
459
+ if (nl !== -1) {
460
+ while (nl !== -1) {
441
461
  const cs = this.continueScalar(nl + 1);
442
462
  if (cs === -1)
443
463
  break;
444
- nl = this.buffer.indexOf('\n', cs);
464
+ nl = qb.indexOf('\n', cs);
445
465
  }
446
- if (nl !== -1 && nl < end) {
466
+ if (nl !== -1) {
447
467
  // this is an error caused by an unexpected unindent
448
- end = nl - 1;
468
+ end = nl - (qb[nl - 1] === '\r' ? 2 : 1);
449
469
  }
450
470
  }
451
471
  if (end === -1) {
@@ -520,9 +540,10 @@ class Lexer {
520
540
  let ch = this.buffer[i];
521
541
  if (ch === '\r')
522
542
  ch = this.buffer[--i];
543
+ const lastChar = i; // Drop the line if last char not more indented
523
544
  while (ch === ' ' || ch === '\t')
524
545
  ch = this.buffer[--i];
525
- if (ch === '\n' && i >= this.pos)
546
+ if (ch === '\n' && i >= this.pos && i + 1 + indent > lastChar)
526
547
  nl = i;
527
548
  else
528
549
  break;
@@ -545,17 +566,18 @@ class Lexer {
545
566
  end = i;
546
567
  }
547
568
  else if (isEmpty(ch)) {
548
- const next = this.buffer[i + 1];
549
- if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
550
- break;
569
+ let next = this.buffer[i + 1];
551
570
  if (ch === '\r') {
552
571
  if (next === '\n') {
553
572
  i += 1;
554
573
  ch = '\n';
574
+ next = this.buffer[i + 1];
555
575
  }
556
576
  else
557
577
  end = i;
558
578
  }
579
+ if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
580
+ break;
559
581
  if (ch === '\n') {
560
582
  const cs = this.continueScalar(i + 1);
561
583
  if (cs === -1)
@@ -604,16 +626,21 @@ class Lexer {
604
626
  return ((yield* this.pushUntil(isNotAnchorChar)) +
605
627
  (yield* this.pushSpaces(true)) +
606
628
  (yield* this.pushIndicators()));
607
- case ':':
608
- case '?': // this is an error outside flow collections
609
629
  case '-': // this is an error
610
- if (isEmpty(this.charAt(1))) {
611
- if (this.flowLevel === 0)
630
+ case '?': // this is an error outside flow collections
631
+ case ':': {
632
+ const inFlow = this.flowLevel > 0;
633
+ const ch1 = this.charAt(1);
634
+ if (isEmpty(ch1) || (inFlow && invalidFlowScalarChars.includes(ch1))) {
635
+ if (!inFlow)
612
636
  this.indentNext = this.indentValue + 1;
637
+ else if (this.flowKey)
638
+ this.flowKey = false;
613
639
  return ((yield* this.pushCount(1)) +
614
640
  (yield* this.pushSpaces(true)) +
615
641
  (yield* this.pushIndicators()));
616
642
  }
643
+ }
617
644
  }
618
645
  return 0;
619
646
  }
@@ -9,7 +9,7 @@ function includesToken(list, type) {
9
9
  return true;
10
10
  return false;
11
11
  }
12
- function includesNonEmpty(list) {
12
+ function findNonEmptyIndex(list) {
13
13
  for (let i = 0; i < list.length; ++i) {
14
14
  switch (list[i].type) {
15
15
  case 'space':
@@ -17,13 +17,13 @@ function includesNonEmpty(list) {
17
17
  case 'newline':
18
18
  break;
19
19
  default:
20
- return true;
20
+ return i;
21
21
  }
22
22
  }
23
- return false;
23
+ return -1;
24
24
  }
25
25
  function isFlowToken(token) {
26
- switch (token === null || token === void 0 ? void 0 : token.type) {
26
+ switch (token?.type) {
27
27
  case 'alias':
28
28
  case 'scalar':
29
29
  case 'single-quoted-scalar':
@@ -40,7 +40,7 @@ function getPrevProps(parent) {
40
40
  return parent.start;
41
41
  case 'block-map': {
42
42
  const it = parent.items[parent.items.length - 1];
43
- return it.sep || it.start;
43
+ return it.sep ?? it.start;
44
44
  }
45
45
  case 'block-seq':
46
46
  return parent.items[parent.items.length - 1].start;
@@ -51,7 +51,6 @@ function getPrevProps(parent) {
51
51
  }
52
52
  /** Note: May modify input array */
53
53
  function getFirstKeyStartProps(prev) {
54
- var _a;
55
54
  if (prev.length === 0)
56
55
  return [];
57
56
  let i = prev.length;
@@ -65,7 +64,7 @@ function getFirstKeyStartProps(prev) {
65
64
  break loop;
66
65
  }
67
66
  }
68
- while (((_a = prev[++i]) === null || _a === void 0 ? void 0 : _a.type) === 'space') {
67
+ while (prev[++i]?.type === 'space') {
69
68
  /* loop */
70
69
  }
71
70
  return prev.splice(i, prev.length);
@@ -207,6 +206,7 @@ class Parser {
207
206
  this.indent += source.length;
208
207
  break;
209
208
  case 'doc-mode':
209
+ case 'flow-error-end':
210
210
  return;
211
211
  default:
212
212
  this.atNewLine = false;
@@ -268,7 +268,7 @@ class Parser {
268
268
  return this.stack[this.stack.length - n];
269
269
  }
270
270
  *pop(error) {
271
- const token = error || this.stack.pop();
271
+ const token = error ?? this.stack.pop();
272
272
  /* istanbul ignore if should not happen */
273
273
  if (!token) {
274
274
  const message = 'Tried to pop an empty stack';
@@ -279,9 +279,14 @@ class Parser {
279
279
  }
280
280
  else {
281
281
  const top = this.peek(1);
282
- // For these, parent indent is needed instead of own
283
- if (token.type === 'block-scalar' || token.type === 'flow-collection')
284
- token.indent = 'indent' in top ? top.indent : -1;
282
+ if (token.type === 'block-scalar') {
283
+ // Block scalars use their parent rather than header indent
284
+ token.indent = 'indent' in top ? top.indent : 0;
285
+ }
286
+ else if (token.type === 'flow-collection' && top.type === 'document') {
287
+ // Ignore all indent for top-level flow collections
288
+ token.indent = 0;
289
+ }
285
290
  if (token.type === 'flow-collection')
286
291
  fixFlowSeqItems(token);
287
292
  switch (top.type) {
@@ -340,7 +345,7 @@ class Parser {
340
345
  !last.sep &&
341
346
  !last.value &&
342
347
  last.start.length > 0 &&
343
- !includesNonEmpty(last.start) &&
348
+ findNonEmptyIndex(last.start) === -1 &&
344
349
  (token.indent === 0 ||
345
350
  last.start.every(st => st.type !== 'comment' || st.indent < token.indent))) {
346
351
  if (top.type === 'document')
@@ -388,7 +393,7 @@ class Parser {
388
393
  return yield* this.lineEnd(doc);
389
394
  switch (this.type) {
390
395
  case 'doc-start': {
391
- if (includesNonEmpty(doc.start)) {
396
+ if (findNonEmptyIndex(doc.start) !== -1) {
392
397
  yield* this.pop();
393
398
  yield* this.step();
394
399
  }
@@ -468,7 +473,6 @@ class Parser {
468
473
  }
469
474
  }
470
475
  *blockMap(map) {
471
- var _a;
472
476
  const it = map.items[map.items.length - 1];
473
477
  // it.sep is true-ish if pair already has key or : separator
474
478
  switch (this.type) {
@@ -477,26 +481,30 @@ class Parser {
477
481
  if (it.value) {
478
482
  const end = 'end' in it.value ? it.value.end : undefined;
479
483
  const last = Array.isArray(end) ? end[end.length - 1] : undefined;
480
- if ((last === null || last === void 0 ? void 0 : last.type) === 'comment')
481
- end === null || end === void 0 ? void 0 : end.push(this.sourceToken);
484
+ if (last?.type === 'comment')
485
+ end?.push(this.sourceToken);
482
486
  else
483
487
  map.items.push({ start: [this.sourceToken] });
484
488
  }
485
- else if (it.sep)
489
+ else if (it.sep) {
486
490
  it.sep.push(this.sourceToken);
487
- else
491
+ }
492
+ else {
488
493
  it.start.push(this.sourceToken);
494
+ }
489
495
  return;
490
496
  case 'space':
491
497
  case 'comment':
492
- if (it.value)
498
+ if (it.value) {
493
499
  map.items.push({ start: [this.sourceToken] });
494
- else if (it.sep)
500
+ }
501
+ else if (it.sep) {
495
502
  it.sep.push(this.sourceToken);
503
+ }
496
504
  else {
497
505
  if (this.atIndentedComment(it.start, map.indent)) {
498
506
  const prev = map.items[map.items.length - 2];
499
- const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
507
+ const end = prev?.value?.end;
500
508
  if (Array.isArray(end)) {
501
509
  Array.prototype.push.apply(end, it.start);
502
510
  end.push(this.sourceToken);
@@ -509,66 +517,132 @@ class Parser {
509
517
  return;
510
518
  }
511
519
  if (this.indent >= map.indent) {
512
- const atNextItem = !this.onKeyLine &&
513
- this.indent === map.indent &&
514
- (it.sep || includesNonEmpty(it.start));
520
+ const atNextItem = !this.onKeyLine && this.indent === map.indent && it.sep;
521
+ // For empty nodes, assign newline-separated not indented empty tokens to following node
522
+ let start = [];
523
+ if (atNextItem && it.sep && !it.value) {
524
+ const nl = [];
525
+ for (let i = 0; i < it.sep.length; ++i) {
526
+ const st = it.sep[i];
527
+ switch (st.type) {
528
+ case 'newline':
529
+ nl.push(i);
530
+ break;
531
+ case 'space':
532
+ break;
533
+ case 'comment':
534
+ if (st.indent > map.indent)
535
+ nl.length = 0;
536
+ break;
537
+ default:
538
+ nl.length = 0;
539
+ }
540
+ }
541
+ if (nl.length >= 2)
542
+ start = it.sep.splice(nl[1]);
543
+ }
515
544
  switch (this.type) {
516
545
  case 'anchor':
517
546
  case 'tag':
518
547
  if (atNextItem || it.value) {
519
- map.items.push({ start: [this.sourceToken] });
548
+ start.push(this.sourceToken);
549
+ map.items.push({ start });
520
550
  this.onKeyLine = true;
521
551
  }
522
- else if (it.sep)
552
+ else if (it.sep) {
523
553
  it.sep.push(this.sourceToken);
524
- else
554
+ }
555
+ else {
525
556
  it.start.push(this.sourceToken);
557
+ }
526
558
  return;
527
559
  case 'explicit-key-ind':
528
- if (!it.sep && !includesToken(it.start, 'explicit-key-ind'))
560
+ if (!it.sep && !includesToken(it.start, 'explicit-key-ind')) {
529
561
  it.start.push(this.sourceToken);
530
- else if (atNextItem || it.value)
531
- map.items.push({ start: [this.sourceToken] });
532
- else
562
+ }
563
+ else if (atNextItem || it.value) {
564
+ start.push(this.sourceToken);
565
+ map.items.push({ start });
566
+ }
567
+ else {
533
568
  this.stack.push({
534
569
  type: 'block-map',
535
570
  offset: this.offset,
536
571
  indent: this.indent,
537
572
  items: [{ start: [this.sourceToken] }]
538
573
  });
574
+ }
539
575
  this.onKeyLine = true;
540
576
  return;
541
577
  case 'map-value-ind':
542
- if (!it.sep)
543
- Object.assign(it, { key: null, sep: [this.sourceToken] });
544
- else if (it.value ||
545
- (atNextItem && !includesToken(it.start, 'explicit-key-ind')))
546
- map.items.push({ start: [], key: null, sep: [this.sourceToken] });
547
- else if (includesToken(it.sep, 'map-value-ind'))
548
- this.stack.push({
549
- type: 'block-map',
550
- offset: this.offset,
551
- indent: this.indent,
552
- items: [{ start: [], key: null, sep: [this.sourceToken] }]
553
- });
554
- else if (includesToken(it.start, 'explicit-key-ind') &&
555
- isFlowToken(it.key) &&
556
- !includesToken(it.sep, 'newline')) {
557
- const start = getFirstKeyStartProps(it.start);
558
- const key = it.key;
559
- const sep = it.sep;
560
- sep.push(this.sourceToken);
561
- // @ts-ignore type guard is wrong here
562
- delete it.key, delete it.sep;
563
- this.stack.push({
564
- type: 'block-map',
565
- offset: this.offset,
566
- indent: this.indent,
567
- items: [{ start, key, sep }]
568
- });
578
+ if (includesToken(it.start, 'explicit-key-ind')) {
579
+ if (!it.sep) {
580
+ if (includesToken(it.start, 'newline')) {
581
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
582
+ }
583
+ else {
584
+ const start = getFirstKeyStartProps(it.start);
585
+ this.stack.push({
586
+ type: 'block-map',
587
+ offset: this.offset,
588
+ indent: this.indent,
589
+ items: [{ start, key: null, sep: [this.sourceToken] }]
590
+ });
591
+ }
592
+ }
593
+ else if (it.value) {
594
+ map.items.push({ start: [], key: null, sep: [this.sourceToken] });
595
+ }
596
+ else if (includesToken(it.sep, 'map-value-ind')) {
597
+ this.stack.push({
598
+ type: 'block-map',
599
+ offset: this.offset,
600
+ indent: this.indent,
601
+ items: [{ start, key: null, sep: [this.sourceToken] }]
602
+ });
603
+ }
604
+ else if (isFlowToken(it.key) &&
605
+ !includesToken(it.sep, 'newline')) {
606
+ const start = getFirstKeyStartProps(it.start);
607
+ const key = it.key;
608
+ const sep = it.sep;
609
+ sep.push(this.sourceToken);
610
+ // @ts-expect-error type guard is wrong here
611
+ delete it.key, delete it.sep;
612
+ this.stack.push({
613
+ type: 'block-map',
614
+ offset: this.offset,
615
+ indent: this.indent,
616
+ items: [{ start, key, sep }]
617
+ });
618
+ }
619
+ else if (start.length > 0) {
620
+ // Not actually at next item
621
+ it.sep = it.sep.concat(start, this.sourceToken);
622
+ }
623
+ else {
624
+ it.sep.push(this.sourceToken);
625
+ }
626
+ }
627
+ else {
628
+ if (!it.sep) {
629
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
630
+ }
631
+ else if (it.value || atNextItem) {
632
+ map.items.push({ start, key: null, sep: [this.sourceToken] });
633
+ }
634
+ else if (includesToken(it.sep, 'map-value-ind')) {
635
+ this.stack.push({
636
+ type: 'block-map',
637
+ offset: this.offset,
638
+ indent: this.indent,
639
+ items: [{ start: [], key: null, sep: [this.sourceToken] }]
640
+ });
641
+ }
642
+ else {
643
+ it.sep.push(this.sourceToken);
644
+ }
569
645
  }
570
- else
571
- it.sep.push(this.sourceToken);
572
646
  this.onKeyLine = true;
573
647
  return;
574
648
  case 'alias':
@@ -577,7 +651,7 @@ class Parser {
577
651
  case 'double-quoted-scalar': {
578
652
  const fs = this.flowScalar(this.type);
579
653
  if (atNextItem || it.value) {
580
- map.items.push({ start: [], key: fs, sep: [] });
654
+ map.items.push({ start, key: fs, sep: [] });
581
655
  this.onKeyLine = true;
582
656
  }
583
657
  else if (it.sep) {
@@ -594,8 +668,9 @@ class Parser {
594
668
  if (bv) {
595
669
  if (atNextItem &&
596
670
  bv.type !== 'block-seq' &&
597
- includesToken(it.start, 'explicit-key-ind'))
598
- map.items.push({ start: [] });
671
+ includesToken(it.start, 'explicit-key-ind')) {
672
+ map.items.push({ start });
673
+ }
599
674
  this.stack.push(bv);
600
675
  return;
601
676
  }
@@ -606,15 +681,14 @@ class Parser {
606
681
  yield* this.step();
607
682
  }
608
683
  *blockSequence(seq) {
609
- var _a;
610
684
  const it = seq.items[seq.items.length - 1];
611
685
  switch (this.type) {
612
686
  case 'newline':
613
687
  if (it.value) {
614
688
  const end = 'end' in it.value ? it.value.end : undefined;
615
689
  const last = Array.isArray(end) ? end[end.length - 1] : undefined;
616
- if ((last === null || last === void 0 ? void 0 : last.type) === 'comment')
617
- end === null || end === void 0 ? void 0 : end.push(this.sourceToken);
690
+ if (last?.type === 'comment')
691
+ end?.push(this.sourceToken);
618
692
  else
619
693
  seq.items.push({ start: [this.sourceToken] });
620
694
  }
@@ -628,7 +702,7 @@ class Parser {
628
702
  else {
629
703
  if (this.atIndentedComment(it.start, seq.indent)) {
630
704
  const prev = seq.items[seq.items.length - 2];
631
- const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
705
+ const end = prev?.value?.end;
632
706
  if (Array.isArray(end)) {
633
707
  Array.prototype.push.apply(end, it.start);
634
708
  end.push(this.sourceToken);
@@ -732,7 +806,7 @@ class Parser {
732
806
  else {
733
807
  const parent = this.peek(2);
734
808
  if (parent.type === 'block-map' &&
735
- (this.type === 'map-value-ind' ||
809
+ ((this.type === 'map-value-ind' && parent.indent === fc.indent) ||
736
810
  (this.type === 'newline' &&
737
811
  !parent.items[parent.items.length - 1].sep))) {
738
812
  yield* this.pop();