yaml 2.0.0-10 → 2.0.0-5

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 (112) hide show
  1. package/browser/dist/compose/compose-doc.js +1 -2
  2. package/browser/dist/compose/compose-node.js +1 -10
  3. package/browser/dist/compose/compose-scalar.js +10 -17
  4. package/browser/dist/compose/composer.js +2 -3
  5. package/browser/dist/compose/resolve-block-map.js +5 -22
  6. package/browser/dist/compose/resolve-block-scalar.js +2 -2
  7. package/browser/dist/compose/resolve-block-seq.js +1 -6
  8. package/browser/dist/compose/resolve-end.js +2 -2
  9. package/browser/dist/compose/resolve-flow-collection.js +8 -24
  10. package/browser/dist/compose/resolve-flow-scalar.js +7 -19
  11. package/browser/dist/compose/resolve-props.js +7 -32
  12. package/browser/dist/doc/Document.js +12 -58
  13. package/browser/dist/doc/createNode.js +5 -11
  14. package/browser/dist/doc/directives.js +0 -5
  15. package/browser/dist/nodes/Collection.js +15 -28
  16. package/browser/dist/nodes/Node.js +0 -7
  17. package/browser/dist/nodes/Pair.js +1 -9
  18. package/browser/dist/nodes/YAMLMap.js +1 -1
  19. package/browser/dist/nodes/YAMLSeq.js +1 -1
  20. package/browser/dist/nodes/addPairToJSMap.js +3 -4
  21. package/browser/dist/options.js +0 -2
  22. package/browser/dist/parse/cst-scalar.js +6 -2
  23. package/browser/dist/parse/lexer.js +31 -67
  24. package/browser/dist/parse/parser.js +55 -62
  25. package/browser/dist/public-api.js +4 -2
  26. package/browser/dist/schema/Schema.js +3 -14
  27. package/browser/dist/schema/core/float.js +1 -4
  28. package/browser/dist/schema/tags.js +13 -17
  29. package/browser/dist/schema/yaml-1.1/float.js +1 -4
  30. package/browser/dist/stringify/addComment.js +11 -0
  31. package/browser/dist/stringify/stringify.js +17 -47
  32. package/browser/dist/stringify/stringifyCollection.js +72 -116
  33. package/browser/dist/stringify/stringifyDocument.js +9 -16
  34. package/browser/dist/stringify/stringifyPair.js +20 -29
  35. package/browser/dist/stringify/stringifyString.js +41 -39
  36. package/browser/dist/util.js +0 -3
  37. package/dist/compose/compose-doc.js +1 -2
  38. package/dist/compose/compose-node.d.ts +0 -1
  39. package/dist/compose/compose-node.js +1 -10
  40. package/dist/compose/compose-scalar.js +9 -16
  41. package/dist/compose/composer.js +2 -3
  42. package/dist/compose/resolve-block-map.d.ts +1 -2
  43. package/dist/compose/resolve-block-map.js +5 -22
  44. package/dist/compose/resolve-block-scalar.js +2 -2
  45. package/dist/compose/resolve-block-seq.js +1 -6
  46. package/dist/compose/resolve-end.js +2 -2
  47. package/dist/compose/resolve-flow-collection.js +8 -24
  48. package/dist/compose/resolve-flow-scalar.js +7 -19
  49. package/dist/compose/resolve-props.d.ts +4 -3
  50. package/dist/compose/resolve-props.js +7 -32
  51. package/dist/doc/Document.d.ts +5 -16
  52. package/dist/doc/Document.js +11 -57
  53. package/dist/doc/createNode.d.ts +1 -2
  54. package/dist/doc/createNode.js +4 -10
  55. package/dist/doc/directives.d.ts +0 -1
  56. package/dist/doc/directives.js +0 -5
  57. package/dist/errors.d.ts +1 -1
  58. package/dist/index.d.ts +2 -2
  59. package/dist/nodes/Alias.d.ts +3 -7
  60. package/dist/nodes/Collection.d.ts +4 -10
  61. package/dist/nodes/Collection.js +14 -27
  62. package/dist/nodes/Node.d.ts +3 -10
  63. package/dist/nodes/Node.js +0 -7
  64. package/dist/nodes/Pair.d.ts +2 -7
  65. package/dist/nodes/Pair.js +0 -8
  66. package/dist/nodes/Scalar.d.ts +0 -2
  67. package/dist/nodes/YAMLMap.d.ts +0 -2
  68. package/dist/nodes/YAMLMap.js +1 -1
  69. package/dist/nodes/YAMLSeq.d.ts +0 -2
  70. package/dist/nodes/YAMLSeq.js +1 -1
  71. package/dist/nodes/addPairToJSMap.js +2 -3
  72. package/dist/options.d.ts +6 -81
  73. package/dist/options.js +0 -2
  74. package/dist/parse/cst-scalar.d.ts +0 -6
  75. package/dist/parse/cst-scalar.js +6 -2
  76. package/dist/parse/lexer.d.ts +1 -3
  77. package/dist/parse/lexer.js +31 -67
  78. package/dist/parse/parser.d.ts +0 -1
  79. package/dist/parse/parser.js +55 -62
  80. package/dist/public-api.js +4 -2
  81. package/dist/schema/Schema.d.ts +4 -6
  82. package/dist/schema/Schema.js +2 -13
  83. package/dist/schema/core/float.js +1 -4
  84. package/dist/schema/tags.d.ts +2 -1
  85. package/dist/schema/tags.js +13 -17
  86. package/dist/schema/yaml-1.1/float.js +1 -4
  87. package/dist/stringify/addComment.d.ts +2 -0
  88. package/dist/stringify/addComment.js +13 -0
  89. package/dist/stringify/stringify.d.ts +3 -5
  90. package/dist/stringify/stringify.js +17 -47
  91. package/dist/stringify/stringifyCollection.d.ts +7 -3
  92. package/dist/stringify/stringifyCollection.js +72 -116
  93. package/dist/stringify/stringifyDocument.js +9 -16
  94. package/dist/stringify/stringifyPair.js +20 -29
  95. package/dist/stringify/stringifyString.js +41 -39
  96. package/dist/test-events.d.ts +1 -1
  97. package/dist/test-events.js +2 -4
  98. package/dist/util.d.ts +0 -3
  99. package/dist/util.js +0 -6
  100. package/package.json +12 -14
  101. package/browser/dist/compose/util-flow-indent-check.js +0 -15
  102. package/browser/dist/compose/util-map-includes.js +0 -17
  103. package/browser/dist/node_modules/tslib/tslib.es6.js +0 -164
  104. package/browser/dist/stringify/stringifyComment.js +0 -18
  105. package/dist/compose/util-flow-indent-check.d.ts +0 -3
  106. package/dist/compose/util-flow-indent-check.js +0 -17
  107. package/dist/compose/util-map-includes.d.ts +0 -4
  108. package/dist/compose/util-map-includes.js +0 -19
  109. package/dist/node_modules/tslib/tslib.es6.js +0 -76
  110. package/dist/stringify/stringifyComment.d.ts +0 -10
  111. package/dist/stringify/stringifyComment.js +0 -22
  112. package/util.d.ts +0 -3
@@ -1,5 +1,5 @@
1
1
  import { createNode } from '../doc/createNode.js';
2
- import { NodeBase, isNode, isPair, isCollection, isScalar } from './Node.js';
2
+ import { NodeBase, isCollection, isScalar, isPair } from './Node.js';
3
3
 
4
4
  function collectionFromPath(schema, path, value) {
5
5
  let v = value;
@@ -11,14 +11,19 @@ function collectionFromPath(schema, path, value) {
11
11
  v = a;
12
12
  }
13
13
  else {
14
- v = new Map([[k, v]]);
14
+ const o = {};
15
+ Object.defineProperty(o, typeof k === 'symbol' ? k : String(k), {
16
+ value: v,
17
+ writable: true,
18
+ enumerable: true,
19
+ configurable: true
20
+ });
21
+ v = o;
15
22
  }
16
23
  }
17
24
  return createNode(v, undefined, {
18
- aliasDuplicateObjects: false,
19
- keepUndefined: false,
20
- onAnchor: () => {
21
- throw new Error('This should not happen, please report a bug.');
25
+ onAnchor() {
26
+ throw new Error('Repeated objects are not supported here');
22
27
  },
23
28
  schema,
24
29
  sourceObjects: new Map()
@@ -37,20 +42,6 @@ class Collection extends NodeBase {
37
42
  writable: true
38
43
  });
39
44
  }
40
- /**
41
- * Create a copy of this collection.
42
- *
43
- * @param schema - If defined, overwrites the original's schema
44
- */
45
- clone(schema) {
46
- const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
47
- if (schema)
48
- copy.schema = schema;
49
- copy.items = copy.items.map(it => isNode(it) || isPair(it) ? it.clone(schema) : it);
50
- if (this.range)
51
- copy.range = this.range.slice();
52
- return copy;
53
- }
54
45
  /**
55
46
  * Adds a value to the collection. For `!!map` and `!!omap` the value must
56
47
  * be a Pair instance or a `{ key, value }` object, which may not have a key
@@ -74,8 +65,7 @@ class Collection extends NodeBase {
74
65
  * Removes a value from the collection.
75
66
  * @returns `true` if the item was found and removed.
76
67
  */
77
- deleteIn(path) {
78
- const [key, ...rest] = path;
68
+ deleteIn([key, ...rest]) {
79
69
  if (rest.length === 0)
80
70
  return this.delete(key);
81
71
  const node = this.get(key, true);
@@ -89,8 +79,7 @@ class Collection extends NodeBase {
89
79
  * scalar values from their surrounding node; to disable set `keepScalar` to
90
80
  * `true` (collections are always returned intact).
91
81
  */
92
- getIn(path, keepScalar) {
93
- const [key, ...rest] = path;
82
+ getIn([key, ...rest], keepScalar) {
94
83
  const node = this.get(key, true);
95
84
  if (rest.length === 0)
96
85
  return !keepScalar && isScalar(node) ? node.value : node;
@@ -114,8 +103,7 @@ class Collection extends NodeBase {
114
103
  /**
115
104
  * Checks if the collection includes a value with the key `key`.
116
105
  */
117
- hasIn(path) {
118
- const [key, ...rest] = path;
106
+ hasIn([key, ...rest]) {
119
107
  if (rest.length === 0)
120
108
  return this.has(key);
121
109
  const node = this.get(key, true);
@@ -125,8 +113,7 @@ class Collection extends NodeBase {
125
113
  * Sets a value in this collection. For `!!set`, `value` needs to be a
126
114
  * boolean to add/remove the item from the set.
127
115
  */
128
- setIn(path, value) {
129
- const [key, ...rest] = path;
116
+ setIn([key, ...rest], value) {
130
117
  if (rest.length === 0) {
131
118
  this.set(key, value);
132
119
  }
@@ -36,13 +36,6 @@ class NodeBase {
36
36
  constructor(type) {
37
37
  Object.defineProperty(this, NODE_TYPE, { value: type });
38
38
  }
39
- /** Create a copy of this node. */
40
- clone() {
41
- const copy = Object.create(Object.getPrototypeOf(this), Object.getOwnPropertyDescriptors(this));
42
- if (this.range)
43
- copy.range = this.range.slice();
44
- return copy;
45
- }
46
39
  }
47
40
 
48
41
  export { ALIAS, DOC, MAP, NODE_TYPE, NodeBase, PAIR, SCALAR, SEQ, hasAnchor, isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq };
@@ -1,7 +1,7 @@
1
1
  import { createNode } from '../doc/createNode.js';
2
2
  import { stringifyPair } from '../stringify/stringifyPair.js';
3
3
  import { addPairToJSMap } from './addPairToJSMap.js';
4
- import { NODE_TYPE, PAIR, isNode } from './Node.js';
4
+ import { NODE_TYPE, PAIR } from './Node.js';
5
5
 
6
6
  function createPair(key, value, ctx) {
7
7
  const k = createNode(key, undefined, ctx);
@@ -14,14 +14,6 @@ class Pair {
14
14
  this.key = key;
15
15
  this.value = value;
16
16
  }
17
- clone(schema) {
18
- let { key, value } = this;
19
- if (isNode(key))
20
- key = key.clone(schema);
21
- if (isNode(value))
22
- value = value.clone(schema);
23
- return new Pair(key, value);
24
- }
25
17
  toJSON(_, ctx) {
26
18
  const pair = ctx && ctx.mapAsMap ? new Map() : {};
27
19
  return addPairToJSMap(ctx, pair, this);
@@ -104,7 +104,7 @@ class YAMLMap extends Collection {
104
104
  if (!ctx.allNullValues && this.hasAllNullValues(false))
105
105
  ctx = Object.assign({}, ctx, { allNullValues: true });
106
106
  return stringifyCollection(this, ctx, {
107
- blockItemPrefix: '',
107
+ blockItem: n => n.str,
108
108
  flowChars: { start: '{', end: '}' },
109
109
  itemIndent: ctx.indent || '',
110
110
  onChompKeep,
@@ -85,7 +85,7 @@ class YAMLSeq extends Collection {
85
85
  if (!ctx)
86
86
  return JSON.stringify(this);
87
87
  return stringifyCollection(this, ctx, {
88
- blockItemPrefix: '- ',
88
+ blockItem: n => (n.comment ? n.str : `- ${n.str}`),
89
89
  flowChars: { start: '[', end: ']' },
90
90
  itemIndent: (ctx.indent || '') + ' ',
91
91
  onChompKeep,
@@ -1,13 +1,12 @@
1
1
  import { warn } from '../log.js';
2
2
  import { createStringifyContext } from '../stringify/stringify.js';
3
- import { isAlias, isSeq, isScalar, isMap, isNode } from './Node.js';
3
+ import { isScalar, isSeq, isAlias, isMap, isNode } from './Node.js';
4
4
  import { Scalar } from './Scalar.js';
5
5
  import { toJS } from './toJS.js';
6
6
 
7
7
  const MERGE_KEY = '<<';
8
8
  function addPairToJSMap(ctx, map, { key, value }) {
9
9
  if (ctx && ctx.doc.schema.merge && isMergeKey(key)) {
10
- value = isAlias(value) ? value.resolve(ctx.doc) : value;
11
10
  if (isSeq(value))
12
11
  for (const it of value.items)
13
12
  mergeToJSMap(ctx, map, it);
@@ -53,9 +52,9 @@ const isMergeKey = (key) => key === MERGE_KEY ||
53
52
  // Keys in mapping nodes earlier in the sequence override keys specified in
54
53
  // later mapping nodes. -- http://yaml.org/type/merge.html
55
54
  function mergeToJSMap(ctx, map, value) {
56
- const source = ctx && isAlias(value) ? value.resolve(ctx.doc) : value;
55
+ const source = ctx && isAlias(value) ? value.resolve(ctx.doc) : null;
57
56
  if (!isMap(source))
58
- throw new Error('Merge sources must be maps or map aliases');
57
+ throw new Error('Merge sources must be map aliases');
59
58
  const srcMap = source.toJSON(null, ctx, Map);
60
59
  for (const [key, value] of srcMap) {
61
60
  if (map instanceof Map) {
@@ -7,11 +7,9 @@
7
7
  */
8
8
  const defaultOptions = {
9
9
  intAsBigInt: false,
10
- keepSourceTokens: false,
11
10
  logLevel: 'warn',
12
11
  prettyErrors: true,
13
12
  strict: true,
14
- uniqueKeys: true,
15
13
  version: '1.2'
16
14
  };
17
15
 
@@ -3,6 +3,10 @@ import { resolveFlowScalar } from '../compose/resolve-flow-scalar.js';
3
3
  import { YAMLParseError } from '../errors.js';
4
4
  import { stringifyString } from '../stringify/stringifyString.js';
5
5
 
6
+ /**
7
+ * If `token` is a CST flow or block scalar, determine its string value and a few other attributes.
8
+ * Otherwise, return `null`.
9
+ */
6
10
  function resolveAsScalar(token, strict = true, onError) {
7
11
  if (token) {
8
12
  const _onError = (pos, code, message) => {
@@ -44,7 +48,7 @@ function createScalarToken(value, context) {
44
48
  implicitKey,
45
49
  indent: indent > 0 ? ' '.repeat(indent) : '',
46
50
  inFlow,
47
- options: { blockQuote: true, lineWidth: -1 }
51
+ options: { lineWidth: -1 }
48
52
  });
49
53
  const end = (_a = context.end) !== null && _a !== void 0 ? _a : [
50
54
  { type: 'newline', offset: -1, indent, source: '\n' }
@@ -113,7 +117,7 @@ function setScalarValue(token, value, context = {}) {
113
117
  implicitKey: implicitKey || indent === null,
114
118
  indent: indent !== null && indent > 0 ? ' '.repeat(indent) : '',
115
119
  inFlow,
116
- options: { blockQuote: true, lineWidth: -1 }
120
+ options: { lineWidth: -1 }
117
121
  });
118
122
  switch (source[0]) {
119
123
  case '|':
@@ -79,11 +79,9 @@ function isEmpty(ch) {
79
79
  return false;
80
80
  }
81
81
  }
82
- const hexDigits = '0123456789ABCDEFabcdef'.split('');
83
- const tagChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()".split('');
84
- const invalidFlowScalarChars = ',[]{}'.split('');
85
- const invalidAnchorChars = ' ,[]{}\n\r\t'.split('');
86
- const isNotAnchorChar = (ch) => !ch || invalidAnchorChars.includes(ch);
82
+ const invalidFlowScalarChars = [',', '[', ']', '{', '}'];
83
+ const invalidIdentifierChars = [' ', ',', '[', ']', '{', '}', '\n', '\r', '\t'];
84
+ const isNotIdentifierChar = (ch) => !ch || invalidIdentifierChars.includes(ch);
87
85
  /**
88
86
  * Splits an input string into lexical tokens, i.e. smaller strings that are
89
87
  * easily identifiable by `tokens.tokenType()`.
@@ -134,8 +132,6 @@ class Lexer {
134
132
  this.indentNext = 0;
135
133
  /** Indentation level of the current line. */
136
134
  this.indentValue = 0;
137
- /** Position of the next \n character. */
138
- this.lineEndPos = null;
139
135
  /** Stores the state of the lexer if reaching the end of incpomplete input */
140
136
  this.next = null;
141
137
  /** A pointer to `buffer`; the current position of the lexer. */
@@ -148,10 +144,8 @@ class Lexer {
148
144
  * @returns A generator of lexical tokens
149
145
  */
150
146
  *lex(source, incomplete = false) {
151
- if (source) {
147
+ if (source)
152
148
  this.buffer = this.buffer ? this.buffer + source : source;
153
- this.lineEndPos = null;
154
- }
155
149
  this.atEnd = !incomplete;
156
150
  let next = this.next || 'stream';
157
151
  while (next && (incomplete || this.hasChars(1)))
@@ -194,11 +188,7 @@ class Lexer {
194
188
  return offset;
195
189
  }
196
190
  getLine() {
197
- let end = this.lineEndPos;
198
- if (typeof end !== 'number' || (end !== -1 && end < this.pos)) {
199
- end = this.buffer.indexOf('\n', this.pos);
200
- this.lineEndPos = end;
201
- }
191
+ let end = this.buffer.indexOf('\n', this.pos);
202
192
  if (end === -1)
203
193
  return this.atEnd ? this.buffer.substring(this.pos) : null;
204
194
  if (this.buffer[end - 1] === '\r')
@@ -211,7 +201,6 @@ class Lexer {
211
201
  setNext(state) {
212
202
  this.buffer = this.buffer.substring(this.pos);
213
203
  this.pos = 0;
214
- this.lineEndPos = null;
215
204
  this.next = state;
216
205
  return null;
217
206
  }
@@ -336,7 +325,7 @@ class Lexer {
336
325
  yield* this.pushCount(1);
337
326
  return 'doc';
338
327
  case '*':
339
- yield* this.pushUntil(isNotAnchorChar);
328
+ yield* this.pushUntil(isNotIdentifierChar);
340
329
  return 'doc';
341
330
  case '"':
342
331
  case "'":
@@ -364,7 +353,7 @@ class Lexer {
364
353
  const line = this.getLine();
365
354
  if (line === null)
366
355
  return this.setNext('flow');
367
- if ((indent !== -1 && indent < this.indentNext && line[0] !== '#') ||
356
+ if ((indent !== -1 && indent < this.indentNext) ||
368
357
  (indent === 0 &&
369
358
  (line.startsWith('---') || line.startsWith('...')) &&
370
359
  isEmpty(line[3]))) {
@@ -382,11 +371,8 @@ class Lexer {
382
371
  }
383
372
  }
384
373
  let n = 0;
385
- while (line[n] === ',') {
386
- n += yield* this.pushCount(1);
387
- n += yield* this.pushSpaces(true);
388
- this.flowKey = false;
389
- }
374
+ while (line[n] === ',')
375
+ n += (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
390
376
  n += yield* this.pushIndicators();
391
377
  switch (line[n]) {
392
378
  case undefined:
@@ -407,7 +393,7 @@ class Lexer {
407
393
  this.flowLevel -= 1;
408
394
  return this.flowLevel ? 'flow' : 'doc';
409
395
  case '*':
410
- yield* this.pushUntil(isNotAnchorChar);
396
+ yield* this.pushUntil(isNotIdentifierChar);
411
397
  return 'flow';
412
398
  case '"':
413
399
  case "'":
@@ -416,7 +402,6 @@ class Lexer {
416
402
  case ':': {
417
403
  const next = this.charAt(1);
418
404
  if (this.flowKey || isEmpty(next) || next === ',') {
419
- this.flowKey = false;
420
405
  yield* this.pushCount(1);
421
406
  yield* this.pushSpaces(true);
422
407
  return 'flow';
@@ -446,19 +431,17 @@ class Lexer {
446
431
  end = this.buffer.indexOf('"', end + 1);
447
432
  }
448
433
  }
449
- // Only looking for newlines within the quotes
450
- const qb = this.buffer.substring(0, end);
451
- let nl = qb.indexOf('\n', this.pos);
452
- if (nl !== -1) {
453
- while (nl !== -1) {
434
+ let nl = this.buffer.indexOf('\n', this.pos);
435
+ if (nl !== -1 && nl < end) {
436
+ while (nl !== -1 && nl < end) {
454
437
  const cs = this.continueScalar(nl + 1);
455
438
  if (cs === -1)
456
439
  break;
457
- nl = qb.indexOf('\n', cs);
440
+ nl = this.buffer.indexOf('\n', cs);
458
441
  }
459
- if (nl !== -1) {
442
+ if (nl !== -1 && nl < end) {
460
443
  // this is an error caused by an unexpected unindent
461
- end = nl - (qb[nl - 1] === '\r' ? 2 : 1);
444
+ end = nl - 1;
462
445
  }
463
446
  }
464
447
  if (end === -1) {
@@ -558,18 +541,17 @@ class Lexer {
558
541
  end = i;
559
542
  }
560
543
  else if (isEmpty(ch)) {
561
- let next = this.buffer[i + 1];
544
+ const next = this.buffer[i + 1];
545
+ if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
546
+ break;
562
547
  if (ch === '\r') {
563
548
  if (next === '\n') {
564
549
  i += 1;
565
550
  ch = '\n';
566
- next = this.buffer[i + 1];
567
551
  }
568
552
  else
569
553
  end = i;
570
554
  }
571
- if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next)))
572
- break;
573
555
  if (ch === '\n') {
574
556
  const cs = this.continueScalar(i + 1);
575
557
  if (cs === -1)
@@ -611,11 +593,13 @@ class Lexer {
611
593
  *pushIndicators() {
612
594
  switch (this.charAt(0)) {
613
595
  case '!':
614
- return ((yield* this.pushTag()) +
615
- (yield* this.pushSpaces(true)) +
616
- (yield* this.pushIndicators()));
596
+ if (this.charAt(1) === '<')
597
+ return ((yield* this.pushVerbatimTag()) +
598
+ (yield* this.pushSpaces(true)) +
599
+ (yield* this.pushIndicators()));
600
+ // fallthrough
617
601
  case '&':
618
- return ((yield* this.pushUntil(isNotAnchorChar)) +
602
+ return ((yield* this.pushUntil(isNotIdentifierChar)) +
619
603
  (yield* this.pushSpaces(true)) +
620
604
  (yield* this.pushIndicators()));
621
605
  case ':':
@@ -624,8 +608,6 @@ class Lexer {
624
608
  if (isEmpty(this.charAt(1))) {
625
609
  if (this.flowLevel === 0)
626
610
  this.indentNext = this.indentValue + 1;
627
- else if (this.flowKey)
628
- this.flowKey = false;
629
611
  return ((yield* this.pushCount(1)) +
630
612
  (yield* this.pushSpaces(true)) +
631
613
  (yield* this.pushIndicators()));
@@ -633,30 +615,12 @@ class Lexer {
633
615
  }
634
616
  return 0;
635
617
  }
636
- *pushTag() {
637
- if (this.charAt(1) === '<') {
638
- let i = this.pos + 2;
639
- let ch = this.buffer[i];
640
- while (!isEmpty(ch) && ch !== '>')
641
- ch = this.buffer[++i];
642
- return yield* this.pushToIndex(ch === '>' ? i + 1 : i, false);
643
- }
644
- else {
645
- let i = this.pos + 1;
646
- let ch = this.buffer[i];
647
- while (ch) {
648
- if (tagChars.includes(ch))
649
- ch = this.buffer[++i];
650
- else if (ch === '%' &&
651
- hexDigits.includes(this.buffer[i + 1]) &&
652
- hexDigits.includes(this.buffer[i + 2])) {
653
- ch = this.buffer[(i += 3)];
654
- }
655
- else
656
- break;
657
- }
658
- return yield* this.pushToIndex(i, false);
659
- }
618
+ *pushVerbatimTag() {
619
+ let i = this.pos + 2;
620
+ let ch = this.buffer[i];
621
+ while (!isEmpty(ch) && ch !== '>')
622
+ ch = this.buffer[++i];
623
+ return yield* this.pushToIndex(ch === '>' ? i + 1 : i, false);
660
624
  }
661
625
  *pushNewline() {
662
626
  const ch = this.buffer[this.pos];
@@ -20,6 +20,38 @@ function includesNonEmpty(list) {
20
20
  }
21
21
  return false;
22
22
  }
23
+ function atFirstEmptyLineAfterComments(start) {
24
+ let hasComment = false;
25
+ for (let i = 0; i < start.length; ++i) {
26
+ switch (start[i].type) {
27
+ case 'space':
28
+ break;
29
+ case 'comment':
30
+ hasComment = true;
31
+ break;
32
+ case 'newline':
33
+ if (!hasComment)
34
+ return false;
35
+ break;
36
+ default:
37
+ return false;
38
+ }
39
+ }
40
+ if (hasComment) {
41
+ for (let i = start.length - 1; i >= 0; --i) {
42
+ switch (start[i].type) {
43
+ /* istanbul ignore next */
44
+ case 'space':
45
+ break;
46
+ case 'newline':
47
+ return true;
48
+ default:
49
+ return false;
50
+ }
51
+ }
52
+ }
53
+ return false;
54
+ }
23
55
  function isFlowToken(token) {
24
56
  switch (token === null || token === void 0 ? void 0 : token.type) {
25
57
  case 'alias':
@@ -203,7 +235,6 @@ class Parser {
203
235
  this.indent += source.length;
204
236
  break;
205
237
  case 'doc-mode':
206
- case 'flow-error-end':
207
238
  return;
208
239
  default:
209
240
  this.atNewLine = false;
@@ -276,14 +307,9 @@ class Parser {
276
307
  }
277
308
  else {
278
309
  const top = this.peek(1);
279
- if (token.type === 'block-scalar') {
280
- // Block scalars use their parent rather than header indent
281
- token.indent = 'indent' in top ? top.indent : 0;
282
- }
283
- else if (token.type === 'flow-collection' && top.type === 'document') {
284
- // Ignore all indent for top-level flow collections
285
- token.indent = 0;
286
- }
310
+ // For these, parent indent is needed instead of own
311
+ if (token.type === 'block-scalar' || token.type === 'flow-collection')
312
+ token.indent = 'indent' in top ? top.indent : -1;
287
313
  if (token.type === 'flow-collection')
288
314
  fixFlowSeqItems(token);
289
315
  switch (top.type) {
@@ -476,38 +502,24 @@ class Parser {
476
502
  switch (this.type) {
477
503
  case 'newline':
478
504
  this.onKeyLine = false;
479
- if (it.value) {
480
- const end = 'end' in it.value ? it.value.end : undefined;
481
- const last = Array.isArray(end) ? end[end.length - 1] : undefined;
482
- if ((last === null || last === void 0 ? void 0 : last.type) === 'comment')
483
- end === null || end === void 0 ? void 0 : end.push(this.sourceToken);
484
- else
485
- map.items.push({ start: [this.sourceToken] });
505
+ if (!it.sep && atFirstEmptyLineAfterComments(it.start)) {
506
+ const prev = map.items[map.items.length - 2];
507
+ const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
508
+ if (Array.isArray(end)) {
509
+ Array.prototype.push.apply(end, it.start);
510
+ it.start = [this.sourceToken];
511
+ return;
512
+ }
486
513
  }
487
- else if (it.sep)
488
- it.sep.push(this.sourceToken);
489
- else
490
- it.start.push(this.sourceToken);
491
- return;
514
+ // fallthrough
492
515
  case 'space':
493
516
  case 'comment':
494
517
  if (it.value)
495
518
  map.items.push({ start: [this.sourceToken] });
496
519
  else if (it.sep)
497
520
  it.sep.push(this.sourceToken);
498
- else {
499
- if (this.atIndentedComment(it.start, map.indent)) {
500
- const prev = map.items[map.items.length - 2];
501
- const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
502
- if (Array.isArray(end)) {
503
- Array.prototype.push.apply(end, it.start);
504
- end.push(this.sourceToken);
505
- map.items.pop();
506
- return;
507
- }
508
- }
521
+ else
509
522
  it.start.push(this.sourceToken);
510
- }
511
523
  return;
512
524
  }
513
525
  if (this.indent >= map.indent) {
@@ -612,34 +624,22 @@ class Parser {
612
624
  const it = seq.items[seq.items.length - 1];
613
625
  switch (this.type) {
614
626
  case 'newline':
615
- if (it.value) {
616
- const end = 'end' in it.value ? it.value.end : undefined;
617
- const last = Array.isArray(end) ? end[end.length - 1] : undefined;
618
- if ((last === null || last === void 0 ? void 0 : last.type) === 'comment')
619
- end === null || end === void 0 ? void 0 : end.push(this.sourceToken);
620
- else
621
- seq.items.push({ start: [this.sourceToken] });
627
+ if (!it.value && atFirstEmptyLineAfterComments(it.start)) {
628
+ const prev = seq.items[seq.items.length - 2];
629
+ const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
630
+ if (Array.isArray(end)) {
631
+ Array.prototype.push.apply(end, it.start);
632
+ it.start = [this.sourceToken];
633
+ return;
634
+ }
622
635
  }
623
- else
624
- it.start.push(this.sourceToken);
625
- return;
636
+ // fallthrough
626
637
  case 'space':
627
638
  case 'comment':
628
639
  if (it.value)
629
640
  seq.items.push({ start: [this.sourceToken] });
630
- else {
631
- if (this.atIndentedComment(it.start, seq.indent)) {
632
- const prev = seq.items[seq.items.length - 2];
633
- const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
634
- if (Array.isArray(end)) {
635
- Array.prototype.push.apply(end, it.start);
636
- end.push(this.sourceToken);
637
- seq.items.pop();
638
- return;
639
- }
640
- }
641
+ else
641
642
  it.start.push(this.sourceToken);
642
- }
643
643
  return;
644
644
  case 'anchor':
645
645
  case 'tag':
@@ -834,13 +834,6 @@ class Parser {
834
834
  }
835
835
  return null;
836
836
  }
837
- atIndentedComment(start, indent) {
838
- if (this.type !== 'comment')
839
- return false;
840
- if (this.indent <= indent)
841
- return false;
842
- return start.every(st => st.type === 'newline' || st.type === 'space');
843
- }
844
837
  *documentEnd(docEnd) {
845
838
  if (this.type !== 'doc-mode') {
846
839
  if (docEnd.end)
@@ -6,8 +6,10 @@ import { LineCounter } from './parse/line-counter.js';
6
6
  import { Parser } from './parse/parser.js';
7
7
 
8
8
  function parseOptions(options) {
9
- const prettyErrors = options.prettyErrors !== false;
10
- const lineCounter = options.lineCounter || (prettyErrors && new LineCounter()) || null;
9
+ const prettyErrors = !options || options.prettyErrors !== false;
10
+ const lineCounter = (options && options.lineCounter) ||
11
+ (prettyErrors && new LineCounter()) ||
12
+ null;
11
13
  return { lineCounter, prettyErrors };
12
14
  }
13
15
  /**
@@ -2,21 +2,15 @@ import { MAP, SCALAR, SEQ } from '../nodes/Node.js';
2
2
  import { map } from './common/map.js';
3
3
  import { seq } from './common/seq.js';
4
4
  import { string } from './common/string.js';
5
- import { getTags, coreKnownTags } from './tags.js';
5
+ import { coreKnownTags, getTags } from './tags.js';
6
6
 
7
7
  const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
8
8
  class Schema {
9
- constructor({ compat, customTags, merge, resolveKnownTags, schema, sortMapEntries, toStringDefaults }) {
10
- this.compat = Array.isArray(compat)
11
- ? getTags(compat, 'compat')
12
- : compat
13
- ? getTags(null, compat)
14
- : null;
9
+ constructor({ customTags, merge, resolveKnownTags, schema, sortMapEntries }) {
15
10
  this.merge = !!merge;
16
- this.name = (typeof schema === 'string' && schema) || 'core';
11
+ this.name = schema || 'core';
17
12
  this.knownTags = resolveKnownTags ? coreKnownTags : {};
18
13
  this.tags = getTags(customTags, this.name);
19
- this.toStringOptions = toStringDefaults || null;
20
14
  Object.defineProperty(this, MAP, { value: map });
21
15
  Object.defineProperty(this, SCALAR, { value: string });
22
16
  Object.defineProperty(this, SEQ, { value: seq });
@@ -24,11 +18,6 @@ class Schema {
24
18
  this.sortMapEntries =
25
19
  sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null;
26
20
  }
27
- clone() {
28
- const copy = Object.create(Schema.prototype, Object.getOwnPropertyDescriptors(this));
29
- copy.tags = this.tags.slice();
30
- return copy;
31
- }
32
21
  }
33
22
 
34
23
  export { Schema };