yaml 2.0.0-9 → 2.0.0

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 (102) hide show
  1. package/README.md +1 -1
  2. package/browser/dist/compose/compose-doc.js +3 -2
  3. package/browser/dist/compose/compose-node.js +13 -4
  4. package/browser/dist/compose/compose-scalar.js +16 -10
  5. package/browser/dist/compose/composer.js +6 -7
  6. package/browser/dist/compose/resolve-block-map.js +9 -2
  7. package/browser/dist/compose/resolve-block-scalar.js +12 -3
  8. package/browser/dist/compose/resolve-block-seq.js +5 -0
  9. package/browser/dist/compose/resolve-flow-collection.js +14 -5
  10. package/browser/dist/compose/resolve-flow-scalar.js +2 -1
  11. package/browser/dist/compose/resolve-props.js +4 -0
  12. package/browser/dist/compose/util-flow-indent-check.js +15 -0
  13. package/browser/dist/doc/Document.js +49 -16
  14. package/browser/dist/doc/anchors.js +2 -2
  15. package/browser/dist/doc/createNode.js +7 -4
  16. package/browser/dist/doc/directives.js +7 -4
  17. package/browser/dist/index.js +1 -2
  18. package/browser/dist/nodes/Pair.js +2 -2
  19. package/browser/dist/nodes/Scalar.js +1 -1
  20. package/browser/dist/nodes/YAMLMap.js +6 -5
  21. package/browser/dist/nodes/YAMLSeq.js +2 -2
  22. package/browser/dist/nodes/addPairToJSMap.js +1 -1
  23. package/browser/dist/nodes/toJS.js +3 -1
  24. package/browser/dist/parse/cst-visit.js +2 -2
  25. package/browser/dist/parse/lexer.js +21 -8
  26. package/browser/dist/parse/parser.js +121 -45
  27. package/browser/dist/public-api.js +4 -5
  28. package/browser/dist/schema/Schema.js +14 -4
  29. package/browser/dist/schema/common/null.js +3 -1
  30. package/browser/dist/schema/core/float.js +4 -1
  31. package/browser/dist/schema/tags.js +9 -9
  32. package/browser/dist/schema/yaml-1.1/float.js +4 -1
  33. package/browser/dist/schema/yaml-1.1/omap.js +1 -1
  34. package/browser/dist/schema/yaml-1.1/pairs.js +2 -1
  35. package/browser/dist/stringify/stringify.js +51 -22
  36. package/browser/dist/stringify/stringifyCollection.js +115 -85
  37. package/browser/dist/stringify/stringifyComment.js +18 -12
  38. package/browser/dist/stringify/stringifyDocument.js +37 -15
  39. package/browser/dist/stringify/stringifyPair.js +34 -20
  40. package/browser/dist/stringify/stringifyString.js +8 -11
  41. package/browser/dist/visit.js +150 -62
  42. package/dist/compose/compose-doc.js +3 -2
  43. package/dist/compose/compose-node.d.ts +1 -0
  44. package/dist/compose/compose-node.js +13 -4
  45. package/dist/compose/compose-scalar.js +15 -9
  46. package/dist/compose/composer.d.ts +1 -1
  47. package/dist/compose/composer.js +8 -9
  48. package/dist/compose/resolve-block-map.js +9 -2
  49. package/dist/compose/resolve-block-scalar.js +12 -3
  50. package/dist/compose/resolve-block-seq.js +5 -0
  51. package/dist/compose/resolve-flow-collection.js +14 -5
  52. package/dist/compose/resolve-flow-scalar.js +2 -1
  53. package/dist/compose/resolve-props.d.ts +1 -1
  54. package/dist/compose/resolve-props.js +4 -0
  55. package/dist/compose/util-flow-indent-check.d.ts +3 -0
  56. package/dist/compose/util-flow-indent-check.js +17 -0
  57. package/dist/doc/Document.d.ts +7 -4
  58. package/dist/doc/Document.js +56 -23
  59. package/dist/doc/anchors.d.ts +2 -2
  60. package/dist/doc/anchors.js +2 -2
  61. package/dist/doc/createNode.d.ts +1 -1
  62. package/dist/doc/createNode.js +7 -4
  63. package/dist/doc/directives.d.ts +4 -2
  64. package/dist/doc/directives.js +7 -4
  65. package/dist/index.d.ts +2 -2
  66. package/dist/index.js +1 -2
  67. package/dist/nodes/Pair.js +2 -2
  68. package/dist/nodes/Scalar.js +1 -1
  69. package/dist/nodes/YAMLMap.d.ts +3 -1
  70. package/dist/nodes/YAMLMap.js +6 -5
  71. package/dist/nodes/YAMLSeq.js +2 -2
  72. package/dist/nodes/addPairToJSMap.js +1 -1
  73. package/dist/nodes/toJS.js +3 -1
  74. package/dist/options.d.ts +42 -12
  75. package/dist/parse/cst-visit.js +2 -2
  76. package/dist/parse/lexer.js +21 -8
  77. package/dist/parse/parser.js +121 -45
  78. package/dist/public-api.js +4 -5
  79. package/dist/schema/Schema.d.ts +5 -4
  80. package/dist/schema/Schema.js +13 -3
  81. package/dist/schema/common/null.js +3 -1
  82. package/dist/schema/core/float.js +4 -1
  83. package/dist/schema/tags.d.ts +1 -2
  84. package/dist/schema/tags.js +9 -9
  85. package/dist/schema/yaml-1.1/float.js +4 -1
  86. package/dist/schema/yaml-1.1/omap.js +1 -1
  87. package/dist/schema/yaml-1.1/pairs.js +2 -1
  88. package/dist/stringify/stringify.d.ts +5 -3
  89. package/dist/stringify/stringify.js +51 -22
  90. package/dist/stringify/stringifyCollection.d.ts +2 -6
  91. package/dist/stringify/stringifyCollection.js +114 -84
  92. package/dist/stringify/stringifyComment.d.ts +10 -2
  93. package/dist/stringify/stringifyComment.js +19 -12
  94. package/dist/stringify/stringifyDocument.js +36 -14
  95. package/dist/stringify/stringifyPair.js +33 -19
  96. package/dist/stringify/stringifyString.js +8 -11
  97. package/dist/test-events.js +13 -12
  98. package/dist/visit.d.ts +49 -10
  99. package/dist/visit.js +149 -60
  100. package/package.json +9 -8
  101. package/browser/dist/options.js +0 -18
  102. package/dist/options.js +0 -20
@@ -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 === null || item === void 0 ? void 0 : 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 === null || parent === void 0 ? void 0 : parent[field];
70
70
  if (coll && 'items' in coll)
71
71
  return coll;
72
72
  throw new Error('Parent collection not found');
@@ -150,12 +150,13 @@ class Lexer {
150
150
  * @returns A generator of lexical tokens
151
151
  */
152
152
  *lex(source, incomplete = false) {
153
+ var _a;
153
154
  if (source) {
154
155
  this.buffer = this.buffer ? this.buffer + source : source;
155
156
  this.lineEndPos = null;
156
157
  }
157
158
  this.atEnd = !incomplete;
158
- let next = this.next || 'stream';
159
+ let next = (_a = this.next) !== null && _a !== void 0 ? _a : 'stream';
159
160
  while (next && (incomplete || this.hasChars(1)))
160
161
  next = yield* this.parseNext(next);
161
162
  }
@@ -359,9 +360,14 @@ class Lexer {
359
360
  let indent = -1;
360
361
  do {
361
362
  nl = yield* this.pushNewline();
362
- sp = yield* this.pushSpaces(true);
363
- if (nl > 0)
363
+ if (nl > 0) {
364
+ sp = yield* this.pushSpaces(false);
364
365
  this.indentValue = indent = sp;
366
+ }
367
+ else {
368
+ sp = 0;
369
+ }
370
+ sp += yield* this.pushSpaces(true);
365
371
  } while (nl + sp > 0);
366
372
  const line = this.getLine();
367
373
  if (line === null)
@@ -418,6 +424,7 @@ class Lexer {
418
424
  case ':': {
419
425
  const next = this.charAt(1);
420
426
  if (this.flowKey || isEmpty(next) || next === ',') {
427
+ this.flowKey = false;
421
428
  yield* this.pushCount(1);
422
429
  yield* this.pushSpaces(true);
423
430
  return 'flow';
@@ -534,9 +541,10 @@ class Lexer {
534
541
  let ch = this.buffer[i];
535
542
  if (ch === '\r')
536
543
  ch = this.buffer[--i];
544
+ const lastChar = i; // Drop the line if last char not more indented
537
545
  while (ch === ' ' || ch === '\t')
538
546
  ch = this.buffer[--i];
539
- if (ch === '\n' && i >= this.pos)
547
+ if (ch === '\n' && i >= this.pos && i + 1 + indent > lastChar)
540
548
  nl = i;
541
549
  else
542
550
  break;
@@ -619,16 +627,21 @@ class Lexer {
619
627
  return ((yield* this.pushUntil(isNotAnchorChar)) +
620
628
  (yield* this.pushSpaces(true)) +
621
629
  (yield* this.pushIndicators()));
622
- case ':':
623
- case '?': // this is an error outside flow collections
624
630
  case '-': // this is an error
625
- if (isEmpty(this.charAt(1))) {
626
- if (this.flowLevel === 0)
631
+ case '?': // this is an error outside flow collections
632
+ case ':': {
633
+ const inFlow = this.flowLevel > 0;
634
+ const ch1 = this.charAt(1);
635
+ if (isEmpty(ch1) || (inFlow && invalidFlowScalarChars.includes(ch1))) {
636
+ if (!inFlow)
627
637
  this.indentNext = this.indentValue + 1;
638
+ else if (this.flowKey)
639
+ this.flowKey = false;
628
640
  return ((yield* this.pushCount(1)) +
629
641
  (yield* this.pushSpaces(true)) +
630
642
  (yield* this.pushIndicators()));
631
643
  }
644
+ }
632
645
  }
633
646
  return 0;
634
647
  }
@@ -35,12 +35,13 @@ function isFlowToken(token) {
35
35
  }
36
36
  }
37
37
  function getPrevProps(parent) {
38
+ var _a;
38
39
  switch (parent.type) {
39
40
  case 'document':
40
41
  return parent.start;
41
42
  case 'block-map': {
42
43
  const it = parent.items[parent.items.length - 1];
43
- return it.sep || it.start;
44
+ return (_a = it.sep) !== null && _a !== void 0 ? _a : it.start;
44
45
  }
45
46
  case 'block-seq':
46
47
  return parent.items[parent.items.length - 1].start;
@@ -207,6 +208,7 @@ class Parser {
207
208
  this.indent += source.length;
208
209
  break;
209
210
  case 'doc-mode':
211
+ case 'flow-error-end':
210
212
  return;
211
213
  default:
212
214
  this.atNewLine = false;
@@ -268,7 +270,7 @@ class Parser {
268
270
  return this.stack[this.stack.length - n];
269
271
  }
270
272
  *pop(error) {
271
- const token = error || this.stack.pop();
273
+ const token = error !== null && error !== void 0 ? error : this.stack.pop();
272
274
  /* istanbul ignore if should not happen */
273
275
  if (!token) {
274
276
  const message = 'Tried to pop an empty stack';
@@ -279,9 +281,14 @@ class Parser {
279
281
  }
280
282
  else {
281
283
  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;
284
+ if (token.type === 'block-scalar') {
285
+ // Block scalars use their parent rather than header indent
286
+ token.indent = 'indent' in top ? top.indent : 0;
287
+ }
288
+ else if (token.type === 'flow-collection' && top.type === 'document') {
289
+ // Ignore all indent for top-level flow collections
290
+ token.indent = 0;
291
+ }
285
292
  if (token.type === 'flow-collection')
286
293
  fixFlowSeqItems(token);
287
294
  switch (top.type) {
@@ -512,63 +519,131 @@ class Parser {
512
519
  const atNextItem = !this.onKeyLine &&
513
520
  this.indent === map.indent &&
514
521
  (it.sep || includesNonEmpty(it.start));
522
+ // For empty nodes, assign newline-separated not indented empty tokens to following node
523
+ let start = [];
524
+ if (atNextItem && it.sep && !it.value) {
525
+ const nl = [];
526
+ for (let i = 0; i < it.sep.length; ++i) {
527
+ const st = it.sep[i];
528
+ switch (st.type) {
529
+ case 'newline':
530
+ nl.push(i);
531
+ break;
532
+ case 'space':
533
+ break;
534
+ case 'comment':
535
+ if (st.indent > map.indent)
536
+ nl.length = 0;
537
+ break;
538
+ default:
539
+ nl.length = 0;
540
+ }
541
+ }
542
+ if (nl.length >= 2)
543
+ start = it.sep.splice(nl[1]);
544
+ }
515
545
  switch (this.type) {
516
546
  case 'anchor':
517
547
  case 'tag':
518
548
  if (atNextItem || it.value) {
519
- map.items.push({ start: [this.sourceToken] });
549
+ start.push(this.sourceToken);
550
+ map.items.push({ start });
520
551
  this.onKeyLine = true;
521
552
  }
522
- else if (it.sep)
553
+ else if (it.sep) {
523
554
  it.sep.push(this.sourceToken);
524
- else
555
+ }
556
+ else {
525
557
  it.start.push(this.sourceToken);
558
+ }
526
559
  return;
527
560
  case 'explicit-key-ind':
528
- if (!it.sep && !includesToken(it.start, 'explicit-key-ind'))
561
+ if (!it.sep && !includesToken(it.start, 'explicit-key-ind')) {
529
562
  it.start.push(this.sourceToken);
530
- else if (atNextItem || it.value)
531
- map.items.push({ start: [this.sourceToken] });
532
- else
563
+ }
564
+ else if (atNextItem || it.value) {
565
+ start.push(this.sourceToken);
566
+ map.items.push({ start });
567
+ }
568
+ else {
533
569
  this.stack.push({
534
570
  type: 'block-map',
535
571
  offset: this.offset,
536
572
  indent: this.indent,
537
573
  items: [{ start: [this.sourceToken] }]
538
574
  });
575
+ }
539
576
  this.onKeyLine = true;
540
577
  return;
541
578
  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
- });
579
+ if (includesToken(it.start, 'explicit-key-ind')) {
580
+ if (!it.sep) {
581
+ if (includesToken(it.start, 'newline')) {
582
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
583
+ }
584
+ else {
585
+ const start = getFirstKeyStartProps(it.start);
586
+ this.stack.push({
587
+ type: 'block-map',
588
+ offset: this.offset,
589
+ indent: this.indent,
590
+ items: [{ start, key: null, sep: [this.sourceToken] }]
591
+ });
592
+ }
593
+ }
594
+ else if (it.value) {
595
+ map.items.push({ start: [], key: null, sep: [this.sourceToken] });
596
+ }
597
+ else if (includesToken(it.sep, 'map-value-ind')) {
598
+ this.stack.push({
599
+ type: 'block-map',
600
+ offset: this.offset,
601
+ indent: this.indent,
602
+ items: [{ start, key: null, sep: [this.sourceToken] }]
603
+ });
604
+ }
605
+ else if (isFlowToken(it.key) &&
606
+ !includesToken(it.sep, 'newline')) {
607
+ const start = getFirstKeyStartProps(it.start);
608
+ const key = it.key;
609
+ const sep = it.sep;
610
+ sep.push(this.sourceToken);
611
+ // @ts-expect-error type guard is wrong here
612
+ delete it.key, delete it.sep;
613
+ this.stack.push({
614
+ type: 'block-map',
615
+ offset: this.offset,
616
+ indent: this.indent,
617
+ items: [{ start, key, sep }]
618
+ });
619
+ }
620
+ else if (start.length > 0) {
621
+ // Not actually at next item
622
+ it.sep = it.sep.concat(start, this.sourceToken);
623
+ }
624
+ else {
625
+ it.sep.push(this.sourceToken);
626
+ }
627
+ }
628
+ else {
629
+ if (!it.sep) {
630
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
631
+ }
632
+ else if (it.value || atNextItem) {
633
+ map.items.push({ start, key: null, sep: [this.sourceToken] });
634
+ }
635
+ else if (includesToken(it.sep, 'map-value-ind')) {
636
+ this.stack.push({
637
+ type: 'block-map',
638
+ offset: this.offset,
639
+ indent: this.indent,
640
+ items: [{ start: [], key: null, sep: [this.sourceToken] }]
641
+ });
642
+ }
643
+ else {
644
+ it.sep.push(this.sourceToken);
645
+ }
569
646
  }
570
- else
571
- it.sep.push(this.sourceToken);
572
647
  this.onKeyLine = true;
573
648
  return;
574
649
  case 'alias':
@@ -577,7 +652,7 @@ class Parser {
577
652
  case 'double-quoted-scalar': {
578
653
  const fs = this.flowScalar(this.type);
579
654
  if (atNextItem || it.value) {
580
- map.items.push({ start: [], key: fs, sep: [] });
655
+ map.items.push({ start, key: fs, sep: [] });
581
656
  this.onKeyLine = true;
582
657
  }
583
658
  else if (it.sep) {
@@ -594,8 +669,9 @@ class Parser {
594
669
  if (bv) {
595
670
  if (atNextItem &&
596
671
  bv.type !== 'block-seq' &&
597
- includesToken(it.start, 'explicit-key-ind'))
598
- map.items.push({ start: [] });
672
+ includesToken(it.start, 'explicit-key-ind')) {
673
+ map.items.push({ start });
674
+ }
599
675
  this.stack.push(bv);
600
676
  return;
601
677
  }
@@ -732,7 +808,7 @@ class Parser {
732
808
  else {
733
809
  const parent = this.peek(2);
734
810
  if (parent.type === 'block-map' &&
735
- (this.type === 'map-value-ind' ||
811
+ ((this.type === 'map-value-ind' && parent.indent === fc.indent) ||
736
812
  (this.type === 'newline' &&
737
813
  !parent.items[parent.items.length - 1].sep))) {
738
814
  yield* this.pop();
@@ -8,10 +8,8 @@ var lineCounter = require('./parse/line-counter.js');
8
8
  var parser = require('./parse/parser.js');
9
9
 
10
10
  function parseOptions(options) {
11
- const prettyErrors = !options || options.prettyErrors !== false;
12
- const lineCounter$1 = (options && options.lineCounter) ||
13
- (prettyErrors && new lineCounter.LineCounter()) ||
14
- null;
11
+ const prettyErrors = options.prettyErrors !== false;
12
+ const lineCounter$1 = options.lineCounter || (prettyErrors && new lineCounter.LineCounter()) || null;
15
13
  return { lineCounter: lineCounter$1, prettyErrors };
16
14
  }
17
15
  /**
@@ -79,6 +77,7 @@ function parse(src, reviver, options) {
79
77
  return doc.toJS(Object.assign({ reviver: _reviver }, options));
80
78
  }
81
79
  function stringify(value, replacer, options) {
80
+ var _a;
82
81
  let _replacer = null;
83
82
  if (typeof replacer === 'function' || Array.isArray(replacer)) {
84
83
  _replacer = replacer;
@@ -93,7 +92,7 @@ function stringify(value, replacer, options) {
93
92
  options = indent < 1 ? undefined : indent > 8 ? { indent: 8 } : { indent };
94
93
  }
95
94
  if (value === undefined) {
96
- const { keepUndefined } = options || replacer || {};
95
+ const { keepUndefined } = (_a = options !== null && options !== void 0 ? options : replacer) !== null && _a !== void 0 ? _a : {};
97
96
  if (!keepUndefined)
98
97
  return undefined;
99
98
  }
@@ -1,17 +1,18 @@
1
1
  import { MAP, SCALAR, SEQ } from '../nodes/Node.js';
2
2
  import type { Pair } from '../nodes/Pair.js';
3
- import type { SchemaOptions } from '../options.js';
3
+ import type { SchemaOptions, ToStringOptions } from '../options.js';
4
4
  import type { CollectionTag, ScalarTag } from './types.js';
5
- export declare type SchemaName = 'core' | 'failsafe' | 'json' | 'yaml-1.1';
6
5
  export declare class Schema {
6
+ compat: Array<CollectionTag | ScalarTag> | null;
7
7
  knownTags: Record<string, CollectionTag | ScalarTag>;
8
8
  merge: boolean;
9
- name: SchemaName;
9
+ name: string;
10
10
  sortMapEntries: ((a: Pair, b: Pair) => number) | null;
11
11
  tags: Array<CollectionTag | ScalarTag>;
12
+ toStringOptions: Readonly<ToStringOptions> | null;
12
13
  [MAP]: CollectionTag;
13
14
  [SCALAR]: ScalarTag;
14
15
  [SEQ]: CollectionTag;
15
- constructor({ customTags, merge, resolveKnownTags, schema, sortMapEntries }: SchemaOptions);
16
+ constructor({ compat, customTags, merge, resolveKnownTags, schema, sortMapEntries, toStringDefaults }: SchemaOptions);
16
17
  clone(): Schema;
17
18
  }
@@ -8,17 +8,27 @@ var tags = require('./tags.js');
8
8
 
9
9
  const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
10
10
  class Schema {
11
- constructor({ customTags, merge, resolveKnownTags, schema, sortMapEntries }) {
11
+ constructor({ compat, customTags, merge, resolveKnownTags, schema, sortMapEntries, toStringDefaults }) {
12
+ this.compat = Array.isArray(compat)
13
+ ? tags.getTags(compat, 'compat')
14
+ : compat
15
+ ? tags.getTags(null, compat)
16
+ : null;
12
17
  this.merge = !!merge;
13
- this.name = schema || 'core';
18
+ this.name = (typeof schema === 'string' && schema) || 'core';
14
19
  this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
15
20
  this.tags = tags.getTags(customTags, this.name);
21
+ this.toStringOptions = toStringDefaults !== null && toStringDefaults !== void 0 ? toStringDefaults : null;
16
22
  Object.defineProperty(this, Node.MAP, { value: map.map });
17
23
  Object.defineProperty(this, Node.SCALAR, { value: string.string });
18
24
  Object.defineProperty(this, Node.SEQ, { value: seq.seq });
19
25
  // Used by createMap()
20
26
  this.sortMapEntries =
21
- sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null;
27
+ typeof sortMapEntries === 'function'
28
+ ? sortMapEntries
29
+ : sortMapEntries === true
30
+ ? sortMapEntriesByKey
31
+ : null;
22
32
  }
23
33
  clone() {
24
34
  const copy = Object.create(Schema.prototype, Object.getOwnPropertyDescriptors(this));
@@ -9,7 +9,9 @@ const nullTag = {
9
9
  tag: 'tag:yaml.org,2002:null',
10
10
  test: /^(?:~|[Nn]ull|NULL)?$/,
11
11
  resolve: () => new Scalar.Scalar(null),
12
- stringify: ({ source }, ctx) => source && nullTag.test.test(source) ? source : ctx.options.nullStr
12
+ stringify: ({ source }, ctx) => typeof source === 'string' && nullTag.test.test(source)
13
+ ? source
14
+ : ctx.options.nullStr
13
15
  };
14
16
 
15
17
  exports.nullTag = nullTag;
@@ -22,7 +22,10 @@ const floatExp = {
22
22
  format: 'EXP',
23
23
  test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
24
24
  resolve: str => parseFloat(str),
25
- stringify: ({ value }) => Number(value).toExponential()
25
+ stringify(node) {
26
+ const num = Number(node.value);
27
+ return isFinite(num) ? num.toExponential() : stringifyNumber.stringifyNumber(node);
28
+ }
26
29
  };
27
30
  const float = {
28
31
  identify: value => typeof value === 'number',
@@ -1,5 +1,4 @@
1
1
  import { SchemaOptions } from '../options.js';
2
- import type { SchemaName } from './Schema.js';
3
2
  import type { CollectionTag, ScalarTag } from './types.js';
4
3
  declare const tagsByName: {
5
4
  binary: ScalarTag;
@@ -37,5 +36,5 @@ export declare const coreKnownTags: {
37
36
  test: RegExp;
38
37
  };
39
38
  };
40
- export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: SchemaName): (ScalarTag | CollectionTag)[];
39
+ export declare function getTags(customTags: SchemaOptions['customTags'] | undefined, schemaName: string): (ScalarTag | CollectionTag)[];
41
40
  export {};
@@ -16,13 +16,13 @@ var schema$2 = require('./yaml-1.1/schema.js');
16
16
  var set = require('./yaml-1.1/set.js');
17
17
  var timestamp = require('./yaml-1.1/timestamp.js');
18
18
 
19
- const schemas = {
20
- core: schema.schema,
21
- failsafe: [map.map, seq.seq, string.string],
22
- json: schema$1.schema,
23
- yaml11: schema$2.schema,
24
- 'yaml-1.1': schema$2.schema
25
- };
19
+ const schemas = new Map([
20
+ ['core', schema.schema],
21
+ ['failsafe', [map.map, seq.seq, string.string]],
22
+ ['json', schema$1.schema],
23
+ ['yaml11', schema$2.schema],
24
+ ['yaml-1.1', schema$2.schema]
25
+ ]);
26
26
  const tagsByName = {
27
27
  binary: binary.binary,
28
28
  bool: bool.boolTag,
@@ -50,12 +50,12 @@ const coreKnownTags = {
50
50
  'tag:yaml.org,2002:timestamp': timestamp.timestamp
51
51
  };
52
52
  function getTags(customTags, schemaName) {
53
- let tags = schemas[schemaName];
53
+ let tags = schemas.get(schemaName);
54
54
  if (!tags) {
55
55
  if (Array.isArray(customTags))
56
56
  tags = [];
57
57
  else {
58
- const keys = Object.keys(schemas)
58
+ const keys = Array.from(schemas.keys())
59
59
  .filter(key => key !== 'yaml11')
60
60
  .map(key => JSON.stringify(key))
61
61
  .join(', ');
@@ -22,7 +22,10 @@ const floatExp = {
22
22
  format: 'EXP',
23
23
  test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
24
24
  resolve: (str) => parseFloat(str.replace(/_/g, '')),
25
- stringify: ({ value }) => Number(value).toExponential()
25
+ stringify(node) {
26
+ const num = Number(node.value);
27
+ return isFinite(num) ? num.toExponential() : stringifyNumber.stringifyNumber(node);
28
+ }
26
29
  };
27
30
  const float = {
28
31
  identify: value => typeof value === 'number',
@@ -24,7 +24,7 @@ class YAMLOMap extends YAMLSeq.YAMLSeq {
24
24
  if (!ctx)
25
25
  return super.toJSON(_);
26
26
  const map = new Map();
27
- if (ctx && ctx.onCreate)
27
+ if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
28
28
  ctx.onCreate(map);
29
29
  for (const pair of this.items) {
30
30
  let key, value;
@@ -6,6 +6,7 @@ var Scalar = require('../../nodes/Scalar.js');
6
6
  var YAMLSeq = require('../../nodes/YAMLSeq.js');
7
7
 
8
8
  function resolvePairs(seq, onError) {
9
+ var _a;
9
10
  if (Node.isSeq(seq)) {
10
11
  for (let i = 0; i < seq.items.length; ++i) {
11
12
  let item = seq.items[i];
@@ -20,7 +21,7 @@ function resolvePairs(seq, onError) {
20
21
  ? `${item.commentBefore}\n${pair.key.commentBefore}`
21
22
  : item.commentBefore;
22
23
  if (item.comment) {
23
- const cn = pair.value || pair.key;
24
+ const cn = (_a = pair.value) !== null && _a !== void 0 ? _a : pair.key;
24
25
  cn.comment = cn.comment
25
26
  ? `${item.comment}\n${cn.comment}`
26
27
  : item.comment;
@@ -1,4 +1,5 @@
1
1
  import type { Document } from '../doc/Document.js';
2
+ import type { Alias } from '../nodes/Alias.js';
2
3
  import type { ToStringOptions } from '../options.js';
3
4
  export declare type StringifyContext = {
4
5
  actualString?: boolean;
@@ -10,9 +11,10 @@ export declare type StringifyContext = {
10
11
  indent: string;
11
12
  indentStep: string;
12
13
  indentAtStart?: number;
13
- inFlow?: boolean;
14
+ inFlow: boolean | null;
14
15
  inStringifyKey?: boolean;
15
- options: Readonly<Required<Omit<ToStringOptions, 'indent'>>>;
16
+ options: Readonly<Required<Omit<ToStringOptions, 'collectionStyle' | 'indent'>>>;
17
+ resolvedAliases?: Set<Alias>;
16
18
  };
17
- export declare const createStringifyContext: (doc: Document, options: ToStringOptions) => StringifyContext;
19
+ export declare function createStringifyContext(doc: Document, options: ToStringOptions): StringifyContext;
18
20
  export declare function stringify(item: unknown, ctx: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;