yaml 2.0.0-8 → 2.0.1

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 (120) 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 +14 -3
  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 +24 -9
  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 +18 -6
  10. package/browser/dist/compose/resolve-flow-scalar.js +2 -1
  11. package/browser/dist/compose/resolve-props.js +8 -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/node_modules/tslib/tslib.es6.js +164 -0
  19. package/browser/dist/nodes/Collection.js +8 -4
  20. package/browser/dist/nodes/Pair.js +2 -2
  21. package/browser/dist/nodes/Scalar.js +1 -1
  22. package/browser/dist/nodes/YAMLMap.js +6 -5
  23. package/browser/dist/nodes/YAMLSeq.js +2 -2
  24. package/browser/dist/nodes/addPairToJSMap.js +3 -2
  25. package/browser/dist/nodes/toJS.js +3 -1
  26. package/browser/dist/parse/cst-scalar.js +2 -6
  27. package/browser/dist/parse/cst-visit.js +2 -2
  28. package/browser/dist/parse/lexer.js +27 -11
  29. package/browser/dist/parse/parser.js +135 -57
  30. package/browser/dist/public-api.js +4 -5
  31. package/browser/dist/schema/Schema.js +14 -4
  32. package/browser/dist/schema/common/null.js +3 -1
  33. package/browser/dist/schema/core/float.js +4 -1
  34. package/browser/dist/schema/tags.js +17 -13
  35. package/browser/dist/schema/yaml-1.1/float.js +4 -1
  36. package/browser/dist/schema/yaml-1.1/omap.js +1 -1
  37. package/browser/dist/schema/yaml-1.1/pairs.js +2 -1
  38. package/browser/dist/stringify/stringify.js +53 -23
  39. package/browser/dist/stringify/stringifyCollection.js +115 -85
  40. package/browser/dist/stringify/stringifyComment.js +18 -12
  41. package/browser/dist/stringify/stringifyDocument.js +37 -15
  42. package/browser/dist/stringify/stringifyPair.js +35 -21
  43. package/browser/dist/stringify/stringifyString.js +41 -43
  44. package/browser/dist/util.js +3 -0
  45. package/browser/dist/visit.js +150 -62
  46. package/dist/compose/compose-doc.js +3 -2
  47. package/dist/compose/compose-node.d.ts +1 -0
  48. package/dist/compose/compose-node.js +14 -3
  49. package/dist/compose/compose-scalar.js +15 -9
  50. package/dist/compose/composer.d.ts +1 -1
  51. package/dist/compose/composer.js +8 -9
  52. package/dist/compose/resolve-block-map.js +24 -9
  53. package/dist/compose/resolve-block-scalar.js +12 -3
  54. package/dist/compose/resolve-block-seq.js +5 -0
  55. package/dist/compose/resolve-flow-collection.js +18 -6
  56. package/dist/compose/resolve-flow-scalar.js +2 -1
  57. package/dist/compose/resolve-props.d.ts +2 -1
  58. package/dist/compose/resolve-props.js +8 -0
  59. package/dist/compose/util-flow-indent-check.d.ts +3 -0
  60. package/dist/compose/util-flow-indent-check.js +17 -0
  61. package/dist/doc/Document.d.ts +7 -4
  62. package/dist/doc/Document.js +56 -23
  63. package/dist/doc/anchors.d.ts +2 -2
  64. package/dist/doc/anchors.js +2 -2
  65. package/dist/doc/createNode.d.ts +1 -1
  66. package/dist/doc/createNode.js +7 -4
  67. package/dist/doc/directives.d.ts +4 -2
  68. package/dist/doc/directives.js +7 -4
  69. package/dist/index.d.ts +4 -4
  70. package/dist/index.js +1 -2
  71. package/dist/node_modules/tslib/tslib.es6.js +76 -0
  72. package/dist/nodes/Alias.d.ts +7 -3
  73. package/dist/nodes/Collection.d.ts +4 -4
  74. package/dist/nodes/Collection.js +8 -4
  75. package/dist/nodes/Node.d.ts +3 -0
  76. package/dist/nodes/Pair.d.ts +3 -0
  77. package/dist/nodes/Pair.js +2 -2
  78. package/dist/nodes/Scalar.d.ts +2 -0
  79. package/dist/nodes/Scalar.js +1 -1
  80. package/dist/nodes/YAMLMap.d.ts +5 -1
  81. package/dist/nodes/YAMLMap.js +6 -5
  82. package/dist/nodes/YAMLSeq.d.ts +2 -0
  83. package/dist/nodes/YAMLSeq.js +2 -2
  84. package/dist/nodes/addPairToJSMap.js +2 -1
  85. package/dist/nodes/toJS.js +3 -1
  86. package/dist/options.d.ts +60 -15
  87. package/dist/parse/cst-scalar.d.ts +6 -0
  88. package/dist/parse/cst-scalar.js +2 -6
  89. package/dist/parse/cst-visit.js +2 -2
  90. package/dist/parse/lexer.js +27 -11
  91. package/dist/parse/parser.js +135 -57
  92. package/dist/public-api.js +4 -5
  93. package/dist/schema/Schema.d.ts +5 -4
  94. package/dist/schema/Schema.js +13 -3
  95. package/dist/schema/common/null.js +3 -1
  96. package/dist/schema/core/float.js +4 -1
  97. package/dist/schema/tags.d.ts +1 -2
  98. package/dist/schema/tags.js +17 -13
  99. package/dist/schema/yaml-1.1/float.js +4 -1
  100. package/dist/schema/yaml-1.1/omap.js +1 -1
  101. package/dist/schema/yaml-1.1/pairs.js +2 -1
  102. package/dist/stringify/stringify.d.ts +5 -3
  103. package/dist/stringify/stringify.js +53 -23
  104. package/dist/stringify/stringifyCollection.d.ts +2 -6
  105. package/dist/stringify/stringifyCollection.js +114 -84
  106. package/dist/stringify/stringifyComment.d.ts +10 -2
  107. package/dist/stringify/stringifyComment.js +19 -12
  108. package/dist/stringify/stringifyDocument.js +36 -14
  109. package/dist/stringify/stringifyPair.js +34 -20
  110. package/dist/stringify/stringifyString.js +41 -43
  111. package/dist/test-events.d.ts +1 -1
  112. package/dist/test-events.js +13 -12
  113. package/dist/util.d.ts +3 -0
  114. package/dist/util.js +6 -0
  115. package/dist/visit.d.ts +49 -10
  116. package/dist/visit.js +149 -60
  117. package/package.json +10 -8
  118. package/util.d.ts +3 -0
  119. package/browser/dist/options.js +0 -17
  120. package/dist/options.js +0 -19
@@ -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,10 +17,10 @@ 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
26
  switch (token === null || token === void 0 ? void 0 : token.type) {
@@ -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) {
@@ -340,7 +347,7 @@ class Parser {
340
347
  !last.sep &&
341
348
  !last.value &&
342
349
  last.start.length > 0 &&
343
- !includesNonEmpty(last.start) &&
350
+ findNonEmptyIndex(last.start) === -1 &&
344
351
  (token.indent === 0 ||
345
352
  last.start.every(st => st.type !== 'comment' || st.indent < token.indent))) {
346
353
  if (top.type === 'document')
@@ -388,7 +395,7 @@ class Parser {
388
395
  return yield* this.lineEnd(doc);
389
396
  switch (this.type) {
390
397
  case 'doc-start': {
391
- if (includesNonEmpty(doc.start)) {
398
+ if (findNonEmptyIndex(doc.start) !== -1) {
392
399
  yield* this.pop();
393
400
  yield* this.step();
394
401
  }
@@ -482,17 +489,21 @@ class Parser {
482
489
  else
483
490
  map.items.push({ start: [this.sourceToken] });
484
491
  }
485
- else if (it.sep)
492
+ else if (it.sep) {
486
493
  it.sep.push(this.sourceToken);
487
- else
494
+ }
495
+ else {
488
496
  it.start.push(this.sourceToken);
497
+ }
489
498
  return;
490
499
  case 'space':
491
500
  case 'comment':
492
- if (it.value)
501
+ if (it.value) {
493
502
  map.items.push({ start: [this.sourceToken] });
494
- else if (it.sep)
503
+ }
504
+ else if (it.sep) {
495
505
  it.sep.push(this.sourceToken);
506
+ }
496
507
  else {
497
508
  if (this.atIndentedComment(it.start, map.indent)) {
498
509
  const prev = map.items[map.items.length - 2];
@@ -509,66 +520,132 @@ class Parser {
509
520
  return;
510
521
  }
511
522
  if (this.indent >= map.indent) {
512
- const atNextItem = !this.onKeyLine &&
513
- this.indent === map.indent &&
514
- (it.sep || includesNonEmpty(it.start));
523
+ const atNextItem = !this.onKeyLine && this.indent === map.indent && it.sep;
524
+ // For empty nodes, assign newline-separated not indented empty tokens to following node
525
+ let start = [];
526
+ if (atNextItem && it.sep && !it.value) {
527
+ const nl = [];
528
+ for (let i = 0; i < it.sep.length; ++i) {
529
+ const st = it.sep[i];
530
+ switch (st.type) {
531
+ case 'newline':
532
+ nl.push(i);
533
+ break;
534
+ case 'space':
535
+ break;
536
+ case 'comment':
537
+ if (st.indent > map.indent)
538
+ nl.length = 0;
539
+ break;
540
+ default:
541
+ nl.length = 0;
542
+ }
543
+ }
544
+ if (nl.length >= 2)
545
+ start = it.sep.splice(nl[1]);
546
+ }
515
547
  switch (this.type) {
516
548
  case 'anchor':
517
549
  case 'tag':
518
550
  if (atNextItem || it.value) {
519
- map.items.push({ start: [this.sourceToken] });
551
+ start.push(this.sourceToken);
552
+ map.items.push({ start });
520
553
  this.onKeyLine = true;
521
554
  }
522
- else if (it.sep)
555
+ else if (it.sep) {
523
556
  it.sep.push(this.sourceToken);
524
- else
557
+ }
558
+ else {
525
559
  it.start.push(this.sourceToken);
560
+ }
526
561
  return;
527
562
  case 'explicit-key-ind':
528
- if (!it.sep && !includesToken(it.start, 'explicit-key-ind'))
563
+ if (!it.sep && !includesToken(it.start, 'explicit-key-ind')) {
529
564
  it.start.push(this.sourceToken);
530
- else if (atNextItem || it.value)
531
- map.items.push({ start: [this.sourceToken] });
532
- else
565
+ }
566
+ else if (atNextItem || it.value) {
567
+ start.push(this.sourceToken);
568
+ map.items.push({ start });
569
+ }
570
+ else {
533
571
  this.stack.push({
534
572
  type: 'block-map',
535
573
  offset: this.offset,
536
574
  indent: this.indent,
537
575
  items: [{ start: [this.sourceToken] }]
538
576
  });
577
+ }
539
578
  this.onKeyLine = true;
540
579
  return;
541
580
  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
- });
581
+ if (includesToken(it.start, 'explicit-key-ind')) {
582
+ if (!it.sep) {
583
+ if (includesToken(it.start, 'newline')) {
584
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
585
+ }
586
+ else {
587
+ const start = getFirstKeyStartProps(it.start);
588
+ this.stack.push({
589
+ type: 'block-map',
590
+ offset: this.offset,
591
+ indent: this.indent,
592
+ items: [{ start, key: null, sep: [this.sourceToken] }]
593
+ });
594
+ }
595
+ }
596
+ else if (it.value) {
597
+ map.items.push({ start: [], key: null, sep: [this.sourceToken] });
598
+ }
599
+ else if (includesToken(it.sep, 'map-value-ind')) {
600
+ this.stack.push({
601
+ type: 'block-map',
602
+ offset: this.offset,
603
+ indent: this.indent,
604
+ items: [{ start, key: null, sep: [this.sourceToken] }]
605
+ });
606
+ }
607
+ else if (isFlowToken(it.key) &&
608
+ !includesToken(it.sep, 'newline')) {
609
+ const start = getFirstKeyStartProps(it.start);
610
+ const key = it.key;
611
+ const sep = it.sep;
612
+ sep.push(this.sourceToken);
613
+ // @ts-expect-error type guard is wrong here
614
+ delete it.key, delete it.sep;
615
+ this.stack.push({
616
+ type: 'block-map',
617
+ offset: this.offset,
618
+ indent: this.indent,
619
+ items: [{ start, key, sep }]
620
+ });
621
+ }
622
+ else if (start.length > 0) {
623
+ // Not actually at next item
624
+ it.sep = it.sep.concat(start, this.sourceToken);
625
+ }
626
+ else {
627
+ it.sep.push(this.sourceToken);
628
+ }
629
+ }
630
+ else {
631
+ if (!it.sep) {
632
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
633
+ }
634
+ else if (it.value || atNextItem) {
635
+ map.items.push({ start, key: null, sep: [this.sourceToken] });
636
+ }
637
+ else if (includesToken(it.sep, 'map-value-ind')) {
638
+ this.stack.push({
639
+ type: 'block-map',
640
+ offset: this.offset,
641
+ indent: this.indent,
642
+ items: [{ start: [], key: null, sep: [this.sourceToken] }]
643
+ });
644
+ }
645
+ else {
646
+ it.sep.push(this.sourceToken);
647
+ }
569
648
  }
570
- else
571
- it.sep.push(this.sourceToken);
572
649
  this.onKeyLine = true;
573
650
  return;
574
651
  case 'alias':
@@ -577,7 +654,7 @@ class Parser {
577
654
  case 'double-quoted-scalar': {
578
655
  const fs = this.flowScalar(this.type);
579
656
  if (atNextItem || it.value) {
580
- map.items.push({ start: [], key: fs, sep: [] });
657
+ map.items.push({ start, key: fs, sep: [] });
581
658
  this.onKeyLine = true;
582
659
  }
583
660
  else if (it.sep) {
@@ -594,8 +671,9 @@ class Parser {
594
671
  if (bv) {
595
672
  if (atNextItem &&
596
673
  bv.type !== 'block-seq' &&
597
- includesToken(it.start, 'explicit-key-ind'))
598
- map.items.push({ start: [] });
674
+ includesToken(it.start, 'explicit-key-ind')) {
675
+ map.items.push({ start });
676
+ }
599
677
  this.stack.push(bv);
600
678
  return;
601
679
  }
@@ -732,7 +810,7 @@ class Parser {
732
810
  else {
733
811
  const parent = this.peek(2);
734
812
  if (parent.type === 'block-map' &&
735
- (this.type === 'map-value-ind' ||
813
+ ((this.type === 'map-value-ind' && parent.indent === fc.indent) ||
736
814
  (this.type === 'newline' &&
737
815
  !parent.items[parent.items.length - 1].sep))) {
738
816
  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,13 +50,17 @@ 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
- const keys = Object.keys(schemas)
56
- .filter(key => key !== 'yaml11')
57
- .map(key => JSON.stringify(key))
58
- .join(', ');
59
- throw new Error(`Unknown schema "${schemaName}"; use one of ${keys}`);
55
+ if (Array.isArray(customTags))
56
+ tags = [];
57
+ else {
58
+ const keys = Array.from(schemas.keys())
59
+ .filter(key => key !== 'yaml11')
60
+ .map(key => JSON.stringify(key))
61
+ .join(', ');
62
+ throw new Error(`Unknown schema "${schemaName}"; use one of ${keys} or define customTags array`);
63
+ }
60
64
  }
61
65
  if (Array.isArray(customTags)) {
62
66
  for (const tag of customTags)
@@ -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;