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
@@ -74,6 +74,7 @@ function singleQuotedValue(source, onError) {
74
74
  return foldLines(source.slice(1, -1)).replace(/''/g, "'");
75
75
  }
76
76
  function foldLines(source) {
77
+ var _a;
77
78
  /**
78
79
  * The negative lookbehind here and in the `re` RegExp is to
79
80
  * prevent causing a polynomial search time in certain cases.
@@ -113,7 +114,7 @@ function foldLines(source) {
113
114
  const last = /[ \t]*(.*)/sy;
114
115
  last.lastIndex = pos;
115
116
  match = last.exec(source);
116
- return res + sep + ((match && match[1]) || '');
117
+ return res + sep + ((_a = match === null || match === void 0 ? void 0 : match[1]) !== null && _a !== void 0 ? _a : '');
117
118
  }
118
119
  function doubleQuotedValue(source, onError) {
119
120
  let res = '';
@@ -1,7 +1,7 @@
1
1
  import type { SourceToken, Token } from '../parse/cst.js';
2
2
  import type { ComposeErrorHandler } from './composer.js';
3
3
  export interface ResolvePropsArg {
4
- flow?: string;
4
+ flow?: 'flow map' | 'flow sequence';
5
5
  indicator: 'doc-start' | 'explicit-key-ind' | 'map-value-ind' | 'seq-item-ind';
6
6
  next: Token | null | undefined;
7
7
  offset: number;
@@ -14,6 +14,7 @@ export declare function resolveProps(tokens: SourceToken[], { flow, indicator, n
14
14
  spaceBefore: boolean;
15
15
  comment: string;
16
16
  hasNewline: boolean;
17
+ hasNewlineAfterProp: boolean;
17
18
  anchor: SourceToken | null;
18
19
  tag: SourceToken | null;
19
20
  end: number;
@@ -7,6 +7,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
7
7
  let comment = '';
8
8
  let commentSep = '';
9
9
  let hasNewline = false;
10
+ let hasNewlineAfterProp = false;
10
11
  let reqSpace = false;
11
12
  let anchor = null;
12
13
  let tag = null;
@@ -56,11 +57,15 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
56
57
  commentSep += token.source;
57
58
  atNewline = true;
58
59
  hasNewline = true;
60
+ if (anchor || tag)
61
+ hasNewlineAfterProp = true;
59
62
  hasSpace = true;
60
63
  break;
61
64
  case 'anchor':
62
65
  if (anchor)
63
66
  onError(token, 'MULTIPLE_ANCHORS', 'A node can have at most one anchor');
67
+ if (token.source.endsWith(':'))
68
+ onError(token.offset + token.source.length - 1, 'BAD_ALIAS', 'Anchor ending in : is ambiguous', true);
64
69
  anchor = token;
65
70
  if (start === null)
66
71
  start = token.offset;
@@ -83,6 +88,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
83
88
  // Could here handle preceding comments differently
84
89
  if (anchor || tag)
85
90
  onError(token, 'BAD_PROP_ORDER', `Anchors and tags must be after the ${token.source} indicator`);
91
+ if (found)
92
+ onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow !== null && flow !== void 0 ? flow : 'collection'}`);
86
93
  found = token;
87
94
  atNewline = false;
88
95
  hasSpace = false;
@@ -118,6 +125,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
118
125
  spaceBefore,
119
126
  comment,
120
127
  hasNewline,
128
+ hasNewlineAfterProp,
121
129
  anchor,
122
130
  tag,
123
131
  end,
@@ -0,0 +1,3 @@
1
+ import { Token } from '../parse/cst';
2
+ import { ComposeErrorHandler } from './composer';
3
+ export declare function flowIndentCheck(indent: number, fc: Token | null | undefined, onError: ComposeErrorHandler): void;
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ var utilContainsNewline = require('./util-contains-newline.js');
4
+
5
+ function flowIndentCheck(indent, fc, onError) {
6
+ if ((fc === null || fc === void 0 ? void 0 : fc.type) === 'flow-collection') {
7
+ const end = fc.end[0];
8
+ if (end.indent === indent &&
9
+ (end.source === ']' || end.source === '}') &&
10
+ utilContainsNewline.containsNewline(fc)) {
11
+ const msg = 'Flow end indicator should be more indented than parent';
12
+ onError(end, 'BAD_INDENT', msg, true);
13
+ }
14
+ }
15
+ }
16
+
17
+ exports.flowIndentCheck = flowIndentCheck;
@@ -5,12 +5,13 @@ import { Pair } from '../nodes/Pair.js';
5
5
  import type { Scalar } from '../nodes/Scalar.js';
6
6
  import type { YAMLMap } from '../nodes/YAMLMap.js';
7
7
  import type { YAMLSeq } from '../nodes/YAMLSeq.js';
8
- import { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from '../options.js';
8
+ import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from '../options.js';
9
9
  import { Schema } from '../schema/Schema.js';
10
10
  import { Directives } from './directives.js';
11
11
  export declare type Replacer = any[] | ((key: any, value: any) => unknown);
12
12
  export declare namespace Document {
13
13
  interface Parsed<T extends ParsedNode = ParsedNode> extends Document<T> {
14
+ directives: Directives;
14
15
  range: Range;
15
16
  }
16
17
  }
@@ -22,7 +23,7 @@ export declare class Document<T = unknown> {
22
23
  comment: string | null;
23
24
  /** The document contents. */
24
25
  contents: T | null;
25
- directives: Directives;
26
+ directives?: Directives;
26
27
  /** Errors encountered during parsing. */
27
28
  errors: YAMLError[];
28
29
  options: Required<Omit<ParseOptions & DocumentOptions, 'lineCounter' | 'directives' | 'version'>>;
@@ -116,10 +117,12 @@ export declare class Document<T = unknown> {
116
117
  setIn(path: Iterable<unknown>, value: unknown): void;
117
118
  /**
118
119
  * Change the YAML version and schema used by the document.
120
+ * A `null` version disables support for directives, explicit tags, anchors, and aliases.
121
+ * It also requires the `schema` option to be given as a `Schema` instance value.
119
122
  *
120
- * Overrides all previously set schema options
123
+ * Overrides all previously set schema options.
121
124
  */
122
- setSchema(version: '1.1' | '1.2', options?: SchemaOptions): void;
125
+ setSchema(version: '1.1' | '1.2' | 'next' | null, options?: SchemaOptions): void;
123
126
  /** A plain JavaScript representation of the document `contents`. */
124
127
  toJS(opt?: ToJSOptions & {
125
128
  [ignored: string]: unknown;
@@ -5,7 +5,6 @@ var Collection = require('../nodes/Collection.js');
5
5
  var Node = require('../nodes/Node.js');
6
6
  var Pair = require('../nodes/Pair.js');
7
7
  var toJS = require('../nodes/toJS.js');
8
- var options = require('../options.js');
9
8
  var Schema = require('../schema/Schema.js');
10
9
  var stringify = require('../stringify/stringify.js');
11
10
  var stringifyDocument = require('../stringify/stringifyDocument.js');
@@ -15,7 +14,7 @@ var createNode = require('./createNode.js');
15
14
  var directives = require('./directives.js');
16
15
 
17
16
  class Document {
18
- constructor(value, replacer, options$1) {
17
+ constructor(value, replacer, options) {
19
18
  /** A comment before this Document */
20
19
  this.commentBefore = null;
21
20
  /** A comment immediately after this Document */
@@ -29,25 +28,33 @@ class Document {
29
28
  if (typeof replacer === 'function' || Array.isArray(replacer)) {
30
29
  _replacer = replacer;
31
30
  }
32
- else if (options$1 === undefined && replacer) {
33
- options$1 = replacer;
31
+ else if (options === undefined && replacer) {
32
+ options = replacer;
34
33
  replacer = undefined;
35
34
  }
36
- const opt = Object.assign({}, options.defaultOptions, options$1);
35
+ const opt = Object.assign({
36
+ intAsBigInt: false,
37
+ keepSourceTokens: false,
38
+ logLevel: 'warn',
39
+ prettyErrors: true,
40
+ strict: true,
41
+ uniqueKeys: true,
42
+ version: '1.2'
43
+ }, options);
37
44
  this.options = opt;
38
45
  let { version } = opt;
39
- if (options$1 === null || options$1 === void 0 ? void 0 : options$1.directives) {
40
- this.directives = options$1.directives.atDocument();
46
+ if (options === null || options === void 0 ? void 0 : options.directives) {
47
+ this.directives = options.directives.atDocument();
41
48
  if (this.directives.yaml.explicit)
42
49
  version = this.directives.yaml.version;
43
50
  }
44
51
  else
45
52
  this.directives = new directives.Directives({ version });
46
- this.setSchema(version, options$1);
53
+ this.setSchema(version, options);
47
54
  if (value === undefined)
48
55
  this.contents = null;
49
56
  else {
50
- this.contents = this.createNode(value, _replacer, options$1);
57
+ this.contents = this.createNode(value, _replacer, options);
51
58
  }
52
59
  }
53
60
  /**
@@ -64,7 +71,8 @@ class Document {
64
71
  copy.errors = this.errors.slice();
65
72
  copy.warnings = this.warnings.slice();
66
73
  copy.options = Object.assign({}, this.options);
67
- copy.directives = this.directives.clone();
74
+ if (this.directives)
75
+ copy.directives = this.directives.clone();
68
76
  copy.schema = this.schema.clone();
69
77
  copy.contents = Node.isNode(this.contents)
70
78
  ? this.contents.clone(copy.schema)
@@ -96,6 +104,7 @@ class Document {
96
104
  if (!node.anchor) {
97
105
  const prev = anchors.anchorNames(this);
98
106
  node.anchor =
107
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
99
108
  !name || prev.has(name) ? anchors.findNewAnchor(name || 'a', prev) : name;
100
109
  }
101
110
  return new Alias.Alias(node.anchor);
@@ -117,8 +126,10 @@ class Document {
117
126
  options = replacer;
118
127
  replacer = undefined;
119
128
  }
120
- const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options || {};
121
- const { onAnchor, setAnchors, sourceObjects } = anchors.createNodeAnchors(this, anchorPrefix || 'a');
129
+ const { aliasDuplicateObjects, anchorPrefix, flow, keepUndefined, onTagObj, tag } = options !== null && options !== void 0 ? options : {};
130
+ const { onAnchor, setAnchors, sourceObjects } = anchors.createNodeAnchors(this,
131
+ // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
132
+ anchorPrefix || 'a');
122
133
  const ctx = {
123
134
  aliasDuplicateObjects: aliasDuplicateObjects !== null && aliasDuplicateObjects !== void 0 ? aliasDuplicateObjects : true,
124
135
  keepUndefined: keepUndefined !== null && keepUndefined !== void 0 ? keepUndefined : false,
@@ -231,26 +242,48 @@ class Document {
231
242
  }
232
243
  /**
233
244
  * Change the YAML version and schema used by the document.
245
+ * A `null` version disables support for directives, explicit tags, anchors, and aliases.
246
+ * It also requires the `schema` option to be given as a `Schema` instance value.
234
247
  *
235
- * Overrides all previously set schema options
248
+ * Overrides all previously set schema options.
236
249
  */
237
- setSchema(version, options) {
238
- let _options;
239
- switch (String(version)) {
250
+ setSchema(version, options = {}) {
251
+ if (typeof version === 'number')
252
+ version = String(version);
253
+ let opt;
254
+ switch (version) {
240
255
  case '1.1':
241
- this.directives.yaml.version = '1.1';
242
- _options = Object.assign({ merge: true, resolveKnownTags: false, schema: 'yaml-1.1' }, options);
256
+ if (this.directives)
257
+ this.directives.yaml.version = '1.1';
258
+ else
259
+ this.directives = new directives.Directives({ version: '1.1' });
260
+ opt = { merge: true, resolveKnownTags: false, schema: 'yaml-1.1' };
243
261
  break;
244
262
  case '1.2':
245
- this.directives.yaml.version = '1.2';
246
- _options = Object.assign({ merge: false, resolveKnownTags: true, schema: 'core' }, options);
263
+ case 'next':
264
+ if (this.directives)
265
+ this.directives.yaml.version = version;
266
+ else
267
+ this.directives = new directives.Directives({ version });
268
+ opt = { merge: false, resolveKnownTags: true, schema: 'core' };
269
+ break;
270
+ case null:
271
+ if (this.directives)
272
+ delete this.directives;
273
+ opt = null;
247
274
  break;
248
275
  default: {
249
276
  const sv = JSON.stringify(version);
250
- throw new Error(`Expected '1.1' or '1.2' as version, but found: ${sv}`);
277
+ throw new Error(`Expected '1.1', '1.2' or null as first argument, but found: ${sv}`);
251
278
  }
252
279
  }
253
- this.schema = new Schema.Schema(_options);
280
+ // Not using `instanceof Schema` to allow for duck typing
281
+ if (options.schema instanceof Object)
282
+ this.schema = options.schema;
283
+ else if (opt)
284
+ this.schema = new Schema.Schema(Object.assign(opt, options));
285
+ else
286
+ throw new Error(`With a null YAML version, the { schema: Schema } option is required`);
254
287
  }
255
288
  // json & jsonArg are only used from toJSON()
256
289
  toJS({ json, jsonArg, mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
@@ -263,7 +296,7 @@ class Document {
263
296
  maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100,
264
297
  stringify: stringify.stringify
265
298
  };
266
- const res = toJS.toJS(this.contents, jsonArg || '', ctx);
299
+ const res = toJS.toJS(this.contents, jsonArg !== null && jsonArg !== void 0 ? jsonArg : '', ctx);
267
300
  if (typeof onAnchor === 'function')
268
301
  for (const { count, res } of ctx.anchors.values())
269
302
  onAnchor(res, count);
@@ -10,13 +10,13 @@ export declare function anchorNames(root: Document | Node): Set<string>;
10
10
  /** Find a new anchor name with the given `prefix` and a one-indexed suffix. */
11
11
  export declare function findNewAnchor(prefix: string, exclude: Set<string>): string;
12
12
  export declare function createNodeAnchors(doc: Document, prefix: string): {
13
- onAnchor(source: unknown): string;
13
+ onAnchor: (source: unknown) => string;
14
14
  /**
15
15
  * With circular references, the source node is only resolved after all
16
16
  * of its child nodes are. This is why anchors are set only after all of
17
17
  * the nodes have been created.
18
18
  */
19
- setAnchors(): void;
19
+ setAnchors: () => void;
20
20
  sourceObjects: Map<unknown, {
21
21
  anchor: string | null;
22
22
  node: Node | null;
@@ -39,7 +39,7 @@ function createNodeAnchors(doc, prefix) {
39
39
  const sourceObjects = new Map();
40
40
  let prevAnchors = null;
41
41
  return {
42
- onAnchor(source) {
42
+ onAnchor: (source) => {
43
43
  aliasObjects.push(source);
44
44
  if (!prevAnchors)
45
45
  prevAnchors = anchorNames(doc);
@@ -52,7 +52,7 @@ function createNodeAnchors(doc, prefix) {
52
52
  * of its child nodes are. This is why anchors are set only after all of
53
53
  * the nodes have been created.
54
54
  */
55
- setAnchors() {
55
+ setAnchors: () => {
56
56
  for (const source of aliasObjects) {
57
57
  const ref = sourceObjects.get(source);
58
58
  if (typeof ref === 'object' &&
@@ -5,7 +5,7 @@ import type { Replacer } from './Document.js';
5
5
  export interface CreateNodeContext {
6
6
  aliasDuplicateObjects: boolean;
7
7
  keepUndefined: boolean;
8
- onAnchor(source: unknown): string;
8
+ onAnchor: (source: unknown) => string;
9
9
  onTagObj?: (tagObj: ScalarTag | CollectionTag) => void;
10
10
  sourceObjects: Map<unknown, {
11
11
  anchor: string | null;
@@ -6,14 +6,15 @@ var Scalar = require('../nodes/Scalar.js');
6
6
 
7
7
  const defaultTagPrefix = 'tag:yaml.org,2002:';
8
8
  function findTagObject(value, tagName, tags) {
9
+ var _a;
9
10
  if (tagName) {
10
11
  const match = tags.filter(t => t.tag === tagName);
11
- const tagObj = match.find(t => !t.format) || match[0];
12
+ const tagObj = (_a = match.find(t => !t.format)) !== null && _a !== void 0 ? _a : match[0];
12
13
  if (!tagObj)
13
14
  throw new Error(`Tag ${tagName} not found`);
14
15
  return tagObj;
15
16
  }
16
- return tags.find(t => t.identify && t.identify(value) && !t.format);
17
+ return tags.find(t => { var _a; return ((_a = t.identify) === null || _a === void 0 ? void 0 : _a.call(t, value)) && !t.format; });
17
18
  }
18
19
  function createNode(value, tagName, ctx) {
19
20
  var _a, _b;
@@ -50,12 +51,14 @@ function createNode(value, tagName, ctx) {
50
51
  sourceObjects.set(value, ref);
51
52
  }
52
53
  }
53
- if (tagName && tagName.startsWith('!!'))
54
+ if (tagName === null || tagName === void 0 ? void 0 : tagName.startsWith('!!'))
54
55
  tagName = defaultTagPrefix + tagName.slice(2);
55
56
  let tagObj = findTagObject(value, tagName, schema.tags);
56
57
  if (!tagObj) {
57
- if (value && typeof value.toJSON === 'function')
58
+ if (value && typeof value.toJSON === 'function') {
59
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
58
60
  value = value.toJSON();
61
+ }
59
62
  if (!value || typeof value !== 'object') {
60
63
  const node = new Scalar.Scalar(value);
61
64
  if (ref)
@@ -3,7 +3,7 @@ export declare class Directives {
3
3
  static defaultYaml: Directives['yaml'];
4
4
  static defaultTags: Directives['tags'];
5
5
  yaml: {
6
- version: '1.1' | '1.2';
6
+ version: '1.1' | '1.2' | 'next';
7
7
  explicit?: boolean;
8
8
  };
9
9
  tags: Record<string, string>;
@@ -11,7 +11,9 @@ export declare class Directives {
11
11
  * The directives-end/doc-start marker `---`. If `null`, a marker may still be
12
12
  * included in the document's stringified representation.
13
13
  */
14
- marker: true | null;
14
+ docStart: true | null;
15
+ /** The doc-end marker `...`. */
16
+ docEnd: boolean;
15
17
  /**
16
18
  * Used when parsing YAML 1.1, where:
17
19
  * > If the document specifies no directives, it is parsed using the same
@@ -18,13 +18,15 @@ class Directives {
18
18
  * The directives-end/doc-start marker `---`. If `null`, a marker may still be
19
19
  * included in the document's stringified representation.
20
20
  */
21
- this.marker = null;
21
+ this.docStart = null;
22
+ /** The doc-end marker `...`. */
23
+ this.docEnd = false;
22
24
  this.yaml = Object.assign({}, Directives.defaultYaml, yaml);
23
25
  this.tags = Object.assign({}, Directives.defaultTags, tags);
24
26
  }
25
27
  clone() {
26
28
  const copy = new Directives(this.yaml, this.tags);
27
- copy.marker = this.marker;
29
+ copy.docStart = this.docStart;
28
30
  return copy;
29
31
  }
30
32
  /**
@@ -73,7 +75,7 @@ class Directives {
73
75
  }
74
76
  case '%YAML': {
75
77
  this.yaml.explicit = true;
76
- if (parts.length < 1) {
78
+ if (parts.length !== 1) {
77
79
  onError(0, '%YAML directive should contain exactly one part');
78
80
  return false;
79
81
  }
@@ -83,7 +85,8 @@ class Directives {
83
85
  return true;
84
86
  }
85
87
  else {
86
- onError(6, `Unsupported YAML version ${version}`, true);
88
+ const isValid = /^\d+\.\d+$/.test(version);
89
+ onError(6, `Unsupported YAML version ${version}`, isValid);
87
90
  return false;
88
91
  }
89
92
  }
package/dist/index.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  export { Composer } from './compose/composer.js';
2
2
  export { Document } from './doc/Document.js';
3
3
  export { Schema } from './schema/Schema.js';
4
- export { YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
4
+ export { ErrorCode, YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
5
5
  export { Alias } from './nodes/Alias.js';
6
- export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq, Node, ParsedNode } from './nodes/Node.js';
6
+ export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq, Node, ParsedNode, Range } from './nodes/Node.js';
7
7
  export { Pair } from './nodes/Pair.js';
8
8
  export { Scalar } from './nodes/Scalar.js';
9
9
  export { YAMLMap } from './nodes/YAMLMap.js';
10
10
  export { YAMLSeq } from './nodes/YAMLSeq.js';
11
- export { CreateNodeOptions, defaultOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options.js';
11
+ export type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options.js';
12
12
  export * as CST from './parse/cst.js';
13
13
  export { Lexer } from './parse/lexer.js';
14
14
  export { LineCounter } from './parse/line-counter.js';
@@ -16,4 +16,4 @@ export { Parser } from './parse/parser.js';
16
16
  export { EmptyStream, parse, parseAllDocuments, parseDocument, stringify } from './public-api.js';
17
17
  export type { TagId, Tags } from './schema/tags';
18
18
  export type { CollectionTag, ScalarTag } from './schema/types';
19
- export { visit, visitor, visitorFn } from './visit.js';
19
+ export { asyncVisitor, asyncVisitorFn, visit, visitAsync, visitor, visitorFn } from './visit.js';
package/dist/index.js CHANGED
@@ -10,7 +10,6 @@ var Pair = require('./nodes/Pair.js');
10
10
  var Scalar = require('./nodes/Scalar.js');
11
11
  var YAMLMap = require('./nodes/YAMLMap.js');
12
12
  var YAMLSeq = require('./nodes/YAMLSeq.js');
13
- var options = require('./options.js');
14
13
  var cst = require('./parse/cst.js');
15
14
  var lexer = require('./parse/lexer.js');
16
15
  var lineCounter = require('./parse/line-counter.js');
@@ -39,7 +38,6 @@ exports.Pair = Pair.Pair;
39
38
  exports.Scalar = Scalar.Scalar;
40
39
  exports.YAMLMap = YAMLMap.YAMLMap;
41
40
  exports.YAMLSeq = YAMLSeq.YAMLSeq;
42
- exports.defaultOptions = options.defaultOptions;
43
41
  exports.CST = cst;
44
42
  exports.Lexer = lexer.Lexer;
45
43
  exports.LineCounter = lineCounter.LineCounter;
@@ -49,3 +47,4 @@ exports.parseAllDocuments = publicApi.parseAllDocuments;
49
47
  exports.parseDocument = publicApi.parseDocument;
50
48
  exports.stringify = publicApi.stringify;
51
49
  exports.visit = visit.visit;
50
+ exports.visitAsync = visit.visitAsync;
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ /*! *****************************************************************************
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission to use, copy, modify, and/or distribute this software for any
7
+ purpose with or without fee is hereby granted.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
16
+ ***************************************************************************** */
17
+ /* global Reflect, Promise */
18
+
19
+ var extendStatics = function(d, b) {
20
+ extendStatics = Object.setPrototypeOf ||
21
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
22
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
23
+ return extendStatics(d, b);
24
+ };
25
+
26
+ function __extends(d, b) {
27
+ if (typeof b !== "function" && b !== null)
28
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29
+ extendStatics(d, b);
30
+ function __() { this.constructor = d; }
31
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32
+ }
33
+
34
+ function __generator(thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (_) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ }
61
+
62
+ function __values(o) {
63
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
64
+ if (m) return m.call(o);
65
+ if (o && typeof o.length === "number") return {
66
+ next: function () {
67
+ if (o && i >= o.length) o = void 0;
68
+ return { value: o && o[i++], done: !o };
69
+ }
70
+ };
71
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
72
+ }
73
+
74
+ exports.__extends = __extends;
75
+ exports.__generator = __generator;
76
+ exports.__values = __values;
@@ -1,13 +1,17 @@
1
- import type { Document } from '../doc/Document';
1
+ import type { Document } from '../doc/Document.js';
2
+ import type { FlowScalar } from '../parse/cst.js';
2
3
  import type { StringifyContext } from '../stringify/stringify.js';
3
4
  import { NodeBase, Range } from './Node.js';
4
5
  import type { Scalar } from './Scalar';
5
6
  import type { ToJSContext } from './toJS.js';
6
- import type { YAMLMap } from './YAMLMap';
7
- import type { YAMLSeq } from './YAMLSeq';
7
+ import type { YAMLMap } from './YAMLMap.js';
8
+ import type { YAMLSeq } from './YAMLSeq.js';
8
9
  export declare namespace Alias {
9
10
  interface Parsed extends Alias {
10
11
  range: Range;
12
+ srcToken?: FlowScalar & {
13
+ type: 'alias';
14
+ };
11
15
  }
12
16
  }
13
17
  export declare class Alias extends NodeBase {
@@ -53,21 +53,21 @@ export declare abstract class Collection extends NodeBase {
53
53
  * Removes a value from the collection.
54
54
  * @returns `true` if the item was found and removed.
55
55
  */
56
- deleteIn([key, ...rest]: Iterable<unknown>): boolean;
56
+ deleteIn(path: Iterable<unknown>): boolean;
57
57
  /**
58
58
  * Returns item at `key`, or `undefined` if not found. By default unwraps
59
59
  * scalar values from their surrounding node; to disable set `keepScalar` to
60
60
  * `true` (collections are always returned intact).
61
61
  */
62
- getIn([key, ...rest]: Iterable<unknown>, keepScalar?: boolean): unknown;
62
+ getIn(path: Iterable<unknown>, keepScalar?: boolean): unknown;
63
63
  hasAllNullValues(allowScalar?: boolean): boolean;
64
64
  /**
65
65
  * Checks if the collection includes a value with the key `key`.
66
66
  */
67
- hasIn([key, ...rest]: Iterable<unknown>): boolean;
67
+ hasIn(path: Iterable<unknown>): boolean;
68
68
  /**
69
69
  * Sets a value in this collection. For `!!set`, `value` needs to be a
70
70
  * boolean to add/remove the item from the set.
71
71
  */
72
- setIn([key, ...rest]: Iterable<unknown>, value: unknown): void;
72
+ setIn(path: Iterable<unknown>, value: unknown): void;
73
73
  }
@@ -76,7 +76,8 @@ class Collection extends Node.NodeBase {
76
76
  * Removes a value from the collection.
77
77
  * @returns `true` if the item was found and removed.
78
78
  */
79
- deleteIn([key, ...rest]) {
79
+ deleteIn(path) {
80
+ const [key, ...rest] = path;
80
81
  if (rest.length === 0)
81
82
  return this.delete(key);
82
83
  const node = this.get(key, true);
@@ -90,7 +91,8 @@ class Collection extends Node.NodeBase {
90
91
  * scalar values from their surrounding node; to disable set `keepScalar` to
91
92
  * `true` (collections are always returned intact).
92
93
  */
93
- getIn([key, ...rest], keepScalar) {
94
+ getIn(path, keepScalar) {
95
+ const [key, ...rest] = path;
94
96
  const node = this.get(key, true);
95
97
  if (rest.length === 0)
96
98
  return !keepScalar && Node.isScalar(node) ? node.value : node;
@@ -114,7 +116,8 @@ class Collection extends Node.NodeBase {
114
116
  /**
115
117
  * Checks if the collection includes a value with the key `key`.
116
118
  */
117
- hasIn([key, ...rest]) {
119
+ hasIn(path) {
120
+ const [key, ...rest] = path;
118
121
  if (rest.length === 0)
119
122
  return this.has(key);
120
123
  const node = this.get(key, true);
@@ -124,7 +127,8 @@ class Collection extends Node.NodeBase {
124
127
  * Sets a value in this collection. For `!!set`, `value` needs to be a
125
128
  * boolean to add/remove the item from the set.
126
129
  */
127
- setIn([key, ...rest], value) {
130
+ setIn(path, value) {
131
+ const [key, ...rest] = path;
128
132
  if (rest.length === 0) {
129
133
  this.set(key, value);
130
134
  }