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
@@ -16,13 +16,15 @@ class Directives {
16
16
  * The directives-end/doc-start marker `---`. If `null`, a marker may still be
17
17
  * included in the document's stringified representation.
18
18
  */
19
- this.marker = null;
19
+ this.docStart = null;
20
+ /** The doc-end marker `...`. */
21
+ this.docEnd = false;
20
22
  this.yaml = Object.assign({}, Directives.defaultYaml, yaml);
21
23
  this.tags = Object.assign({}, Directives.defaultTags, tags);
22
24
  }
23
25
  clone() {
24
26
  const copy = new Directives(this.yaml, this.tags);
25
- copy.marker = this.marker;
27
+ copy.docStart = this.docStart;
26
28
  return copy;
27
29
  }
28
30
  /**
@@ -71,7 +73,7 @@ class Directives {
71
73
  }
72
74
  case '%YAML': {
73
75
  this.yaml.explicit = true;
74
- if (parts.length < 1) {
76
+ if (parts.length !== 1) {
75
77
  onError(0, '%YAML directive should contain exactly one part');
76
78
  return false;
77
79
  }
@@ -81,7 +83,8 @@ class Directives {
81
83
  return true;
82
84
  }
83
85
  else {
84
- onError(6, `Unsupported YAML version ${version}`, true);
86
+ const isValid = /^\d+\.\d+$/.test(version);
87
+ onError(6, `Unsupported YAML version ${version}`, isValid);
85
88
  return false;
86
89
  }
87
90
  }
@@ -8,11 +8,10 @@ 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 { defaultOptions } from './options.js';
12
11
  import * as cst from './parse/cst.js';
13
12
  export { cst as CST };
14
13
  export { Lexer } from './parse/lexer.js';
15
14
  export { LineCounter } from './parse/line-counter.js';
16
15
  export { Parser } from './parse/parser.js';
17
16
  export { parse, parseAllDocuments, parseDocument, stringify } from './public-api.js';
18
- export { visit } from './visit.js';
17
+ export { visit, visitAsync } from './visit.js';
@@ -0,0 +1,164 @@
1
+ /*! *****************************************************************************
2
+ Copyright (c) Microsoft Corporation.
3
+
4
+ Permission to use, copy, modify, and/or distribute this software for any
5
+ purpose with or without fee is hereby granted.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
+ PERFORMANCE OF THIS SOFTWARE.
14
+ ***************************************************************************** */
15
+
16
+ /* global Reflect, Promise */
17
+ var extendStatics = function (d, b) {
18
+ extendStatics = Object.setPrototypeOf || {
19
+ __proto__: []
20
+ } instanceof Array && function (d, b) {
21
+ d.__proto__ = b;
22
+ } || function (d, b) {
23
+ for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p];
24
+ };
25
+
26
+ return extendStatics(d, b);
27
+ };
28
+
29
+ function __extends(d, b) {
30
+ if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
31
+ extendStatics(d, b);
32
+
33
+ function __() {
34
+ this.constructor = d;
35
+ }
36
+
37
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
38
+ }
39
+ function __generator(thisArg, body) {
40
+ var _ = {
41
+ label: 0,
42
+ sent: function () {
43
+ if (t[0] & 1) throw t[1];
44
+ return t[1];
45
+ },
46
+ trys: [],
47
+ ops: []
48
+ },
49
+ f,
50
+ y,
51
+ t,
52
+ g;
53
+ return g = {
54
+ next: verb(0),
55
+ "throw": verb(1),
56
+ "return": verb(2)
57
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
58
+ return this;
59
+ }), g;
60
+
61
+ function verb(n) {
62
+ return function (v) {
63
+ return step([n, v]);
64
+ };
65
+ }
66
+
67
+ function step(op) {
68
+ if (f) throw new TypeError("Generator is already executing.");
69
+
70
+ while (_) try {
71
+ 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;
72
+ if (y = 0, t) op = [op[0] & 2, t.value];
73
+
74
+ switch (op[0]) {
75
+ case 0:
76
+ case 1:
77
+ t = op;
78
+ break;
79
+
80
+ case 4:
81
+ _.label++;
82
+ return {
83
+ value: op[1],
84
+ done: false
85
+ };
86
+
87
+ case 5:
88
+ _.label++;
89
+ y = op[1];
90
+ op = [0];
91
+ continue;
92
+
93
+ case 7:
94
+ op = _.ops.pop();
95
+
96
+ _.trys.pop();
97
+
98
+ continue;
99
+
100
+ default:
101
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
102
+ _ = 0;
103
+ continue;
104
+ }
105
+
106
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
107
+ _.label = op[1];
108
+ break;
109
+ }
110
+
111
+ if (op[0] === 6 && _.label < t[1]) {
112
+ _.label = t[1];
113
+ t = op;
114
+ break;
115
+ }
116
+
117
+ if (t && _.label < t[2]) {
118
+ _.label = t[2];
119
+
120
+ _.ops.push(op);
121
+
122
+ break;
123
+ }
124
+
125
+ if (t[2]) _.ops.pop();
126
+
127
+ _.trys.pop();
128
+
129
+ continue;
130
+ }
131
+
132
+ op = body.call(thisArg, _);
133
+ } catch (e) {
134
+ op = [6, e];
135
+ y = 0;
136
+ } finally {
137
+ f = t = 0;
138
+ }
139
+
140
+ if (op[0] & 5) throw op[1];
141
+ return {
142
+ value: op[0] ? op[1] : void 0,
143
+ done: true
144
+ };
145
+ }
146
+ }
147
+ function __values(o) {
148
+ var s = typeof Symbol === "function" && Symbol.iterator,
149
+ m = s && o[s],
150
+ i = 0;
151
+ if (m) return m.call(o);
152
+ if (o && typeof o.length === "number") return {
153
+ next: function () {
154
+ if (o && i >= o.length) o = void 0;
155
+ return {
156
+ value: o && o[i++],
157
+ done: !o
158
+ };
159
+ }
160
+ };
161
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
162
+ }
163
+
164
+ export { __extends, __generator, __values };
@@ -74,7 +74,8 @@ class Collection extends NodeBase {
74
74
  * Removes a value from the collection.
75
75
  * @returns `true` if the item was found and removed.
76
76
  */
77
- deleteIn([key, ...rest]) {
77
+ deleteIn(path) {
78
+ const [key, ...rest] = path;
78
79
  if (rest.length === 0)
79
80
  return this.delete(key);
80
81
  const node = this.get(key, true);
@@ -88,7 +89,8 @@ class Collection extends NodeBase {
88
89
  * scalar values from their surrounding node; to disable set `keepScalar` to
89
90
  * `true` (collections are always returned intact).
90
91
  */
91
- getIn([key, ...rest], keepScalar) {
92
+ getIn(path, keepScalar) {
93
+ const [key, ...rest] = path;
92
94
  const node = this.get(key, true);
93
95
  if (rest.length === 0)
94
96
  return !keepScalar && isScalar(node) ? node.value : node;
@@ -112,7 +114,8 @@ class Collection extends NodeBase {
112
114
  /**
113
115
  * Checks if the collection includes a value with the key `key`.
114
116
  */
115
- hasIn([key, ...rest]) {
117
+ hasIn(path) {
118
+ const [key, ...rest] = path;
116
119
  if (rest.length === 0)
117
120
  return this.has(key);
118
121
  const node = this.get(key, true);
@@ -122,7 +125,8 @@ class Collection extends NodeBase {
122
125
  * Sets a value in this collection. For `!!set`, `value` needs to be a
123
126
  * boolean to add/remove the item from the set.
124
127
  */
125
- setIn([key, ...rest], value) {
128
+ setIn(path, value) {
129
+ const [key, ...rest] = path;
126
130
  if (rest.length === 0) {
127
131
  this.set(key, value);
128
132
  }
@@ -23,11 +23,11 @@ class Pair {
23
23
  return new Pair(key, value);
24
24
  }
25
25
  toJSON(_, ctx) {
26
- const pair = ctx && ctx.mapAsMap ? new Map() : {};
26
+ const pair = (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
27
27
  return addPairToJSMap(ctx, pair, this);
28
28
  }
29
29
  toString(ctx, onComment, onChompKeep) {
30
- return ctx && ctx.doc
30
+ return (ctx === null || ctx === void 0 ? void 0 : ctx.doc)
31
31
  ? stringifyPair(this, ctx, onComment, onChompKeep)
32
32
  : JSON.stringify(this);
33
33
  }
@@ -8,7 +8,7 @@ class Scalar extends NodeBase {
8
8
  this.value = value;
9
9
  }
10
10
  toJSON(arg, ctx) {
11
- return ctx && ctx.keep ? this.value : toJS(this.value, arg, ctx);
11
+ return (ctx === null || ctx === void 0 ? void 0 : ctx.keep) ? this.value : toJS(this.value, arg, ctx);
12
12
  }
13
13
  toString() {
14
14
  return String(this.value);
@@ -32,6 +32,7 @@ class YAMLMap extends Collection {
32
32
  * collection will throw. Otherwise, overwrites the previous value.
33
33
  */
34
34
  add(pair, overwrite) {
35
+ var _a;
35
36
  let _pair;
36
37
  if (isPair(pair))
37
38
  _pair = pair;
@@ -42,7 +43,7 @@ class YAMLMap extends Collection {
42
43
  else
43
44
  _pair = new Pair(pair.key, pair.value);
44
45
  const prev = findPair(this.items, _pair.key);
45
- const sortEntries = this.schema && this.schema.sortMapEntries;
46
+ const sortEntries = (_a = this.schema) === null || _a === void 0 ? void 0 : _a.sortMapEntries;
46
47
  if (prev) {
47
48
  if (!overwrite)
48
49
  throw new Error(`Key ${_pair.key} already set`);
@@ -72,7 +73,7 @@ class YAMLMap extends Collection {
72
73
  }
73
74
  get(key, keepScalar) {
74
75
  const it = findPair(this.items, key);
75
- const node = it && it.value;
76
+ const node = it === null || it === void 0 ? void 0 : it.value;
76
77
  return !keepScalar && isScalar(node) ? node.value : node;
77
78
  }
78
79
  has(key) {
@@ -87,8 +88,8 @@ class YAMLMap extends Collection {
87
88
  * @returns Instance of Type, Map, or Object
88
89
  */
89
90
  toJSON(_, ctx, Type) {
90
- const map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
91
- if (ctx && ctx.onCreate)
91
+ const map = Type ? new Type() : (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
92
+ if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
92
93
  ctx.onCreate(map);
93
94
  for (const item of this.items)
94
95
  addPairToJSMap(ctx, map, item);
@@ -104,7 +105,7 @@ class YAMLMap extends Collection {
104
105
  if (!ctx.allNullValues && this.hasAllNullValues(false))
105
106
  ctx = Object.assign({}, ctx, { allNullValues: true });
106
107
  return stringifyCollection(this, ctx, {
107
- blockItem: n => n.str,
108
+ blockItemPrefix: '',
108
109
  flowChars: { start: '{', end: '}' },
109
110
  itemIndent: ctx.indent || '',
110
111
  onChompKeep,
@@ -74,7 +74,7 @@ class YAMLSeq extends Collection {
74
74
  }
75
75
  toJSON(_, ctx) {
76
76
  const seq = [];
77
- if (ctx && ctx.onCreate)
77
+ if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
78
78
  ctx.onCreate(seq);
79
79
  let i = 0;
80
80
  for (const item of this.items)
@@ -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
- blockItem: n => (n.comment ? n.str : `- ${n.str}`),
88
+ blockItemPrefix: '- ',
89
89
  flowChars: { start: '[', end: ']' },
90
90
  itemIndent: (ctx.indent || '') + ' ',
91
91
  onChompKeep,
@@ -1,12 +1,13 @@
1
1
  import { warn } from '../log.js';
2
2
  import { createStringifyContext } from '../stringify/stringify.js';
3
- import { isSeq, isScalar, isAlias, isMap, isNode } from './Node.js';
3
+ import { isAlias, isSeq, isScalar, 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
- if (ctx && ctx.doc.schema.merge && isMergeKey(key)) {
9
+ if ((ctx === null || ctx === void 0 ? void 0 : ctx.doc.schema.merge) && isMergeKey(key)) {
10
+ value = isAlias(value) ? value.resolve(ctx.doc) : value;
10
11
  if (isSeq(value))
11
12
  for (const it of value.items)
12
13
  mergeToJSMap(ctx, map, it);
@@ -11,9 +11,11 @@ import { hasAnchor } from './Node.js';
11
11
  * stringification.
12
12
  */
13
13
  function toJS(value, arg, ctx) {
14
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
14
15
  if (Array.isArray(value))
15
16
  return value.map((v, i) => toJS(v, String(i), ctx));
16
17
  if (value && typeof value.toJSON === 'function') {
18
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
17
19
  if (!ctx || !hasAnchor(value))
18
20
  return value.toJSON(arg, ctx);
19
21
  const data = { aliasCount: 0, count: 1, res: undefined };
@@ -27,7 +29,7 @@ function toJS(value, arg, ctx) {
27
29
  ctx.onCreate(res);
28
30
  return res;
29
31
  }
30
- if (typeof value === 'bigint' && !(ctx && ctx.keep))
32
+ if (typeof value === 'bigint' && !(ctx === null || ctx === void 0 ? void 0 : ctx.keep))
31
33
  return Number(value);
32
34
  return value;
33
35
  }
@@ -3,10 +3,6 @@ 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
- */
10
6
  function resolveAsScalar(token, strict = true, onError) {
11
7
  if (token) {
12
8
  const _onError = (pos, code, message) => {
@@ -48,7 +44,7 @@ function createScalarToken(value, context) {
48
44
  implicitKey,
49
45
  indent: indent > 0 ? ' '.repeat(indent) : '',
50
46
  inFlow,
51
- options: { lineWidth: -1 }
47
+ options: { blockQuote: true, lineWidth: -1 }
52
48
  });
53
49
  const end = (_a = context.end) !== null && _a !== void 0 ? _a : [
54
50
  { type: 'newline', offset: -1, indent, source: '\n' }
@@ -117,7 +113,7 @@ function setScalarValue(token, value, context = {}) {
117
113
  implicitKey: implicitKey || indent === null,
118
114
  indent: indent !== null && indent > 0 ? ' '.repeat(indent) : '',
119
115
  inFlow,
120
- options: { lineWidth: -1 }
116
+ options: { blockQuote: true, lineWidth: -1 }
121
117
  });
122
118
  switch (source[0]) {
123
119
  case '|':
@@ -47,7 +47,7 @@ visit.REMOVE = REMOVE;
47
47
  visit.itemAtPath = (cst, path) => {
48
48
  let item = cst;
49
49
  for (const [field, index] of path) {
50
- const tok = item && item[field];
50
+ const tok = item === null || item === void 0 ? void 0 : item[field];
51
51
  if (tok && 'items' in tok) {
52
52
  item = tok.items[index];
53
53
  }
@@ -64,7 +64,7 @@ visit.itemAtPath = (cst, path) => {
64
64
  visit.parentCollection = (cst, path) => {
65
65
  const parent = visit.itemAtPath(cst, path.slice(0, -1));
66
66
  const field = path[path.length - 1][0];
67
- const coll = parent && parent[field];
67
+ const coll = parent === null || parent === void 0 ? void 0 : parent[field];
68
68
  if (coll && 'items' in coll)
69
69
  return coll;
70
70
  throw new Error('Parent collection not found');
@@ -148,12 +148,13 @@ class Lexer {
148
148
  * @returns A generator of lexical tokens
149
149
  */
150
150
  *lex(source, incomplete = false) {
151
+ var _a;
151
152
  if (source) {
152
153
  this.buffer = this.buffer ? this.buffer + source : source;
153
154
  this.lineEndPos = null;
154
155
  }
155
156
  this.atEnd = !incomplete;
156
- let next = this.next || 'stream';
157
+ let next = (_a = this.next) !== null && _a !== void 0 ? _a : 'stream';
157
158
  while (next && (incomplete || this.hasChars(1)))
158
159
  next = yield* this.parseNext(next);
159
160
  }
@@ -357,14 +358,19 @@ class Lexer {
357
358
  let indent = -1;
358
359
  do {
359
360
  nl = yield* this.pushNewline();
360
- sp = yield* this.pushSpaces(true);
361
- if (nl > 0)
361
+ if (nl > 0) {
362
+ sp = yield* this.pushSpaces(false);
362
363
  this.indentValue = indent = sp;
364
+ }
365
+ else {
366
+ sp = 0;
367
+ }
368
+ sp += yield* this.pushSpaces(true);
363
369
  } while (nl + sp > 0);
364
370
  const line = this.getLine();
365
371
  if (line === null)
366
372
  return this.setNext('flow');
367
- if ((indent !== -1 && indent < this.indentNext) ||
373
+ if ((indent !== -1 && indent < this.indentNext && line[0] !== '#') ||
368
374
  (indent === 0 &&
369
375
  (line.startsWith('---') || line.startsWith('...')) &&
370
376
  isEmpty(line[3]))) {
@@ -382,8 +388,11 @@ class Lexer {
382
388
  }
383
389
  }
384
390
  let n = 0;
385
- while (line[n] === ',')
386
- n += (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
391
+ while (line[n] === ',') {
392
+ n += yield* this.pushCount(1);
393
+ n += yield* this.pushSpaces(true);
394
+ this.flowKey = false;
395
+ }
387
396
  n += yield* this.pushIndicators();
388
397
  switch (line[n]) {
389
398
  case undefined:
@@ -413,6 +422,7 @@ class Lexer {
413
422
  case ':': {
414
423
  const next = this.charAt(1);
415
424
  if (this.flowKey || isEmpty(next) || next === ',') {
425
+ this.flowKey = false;
416
426
  yield* this.pushCount(1);
417
427
  yield* this.pushSpaces(true);
418
428
  return 'flow';
@@ -529,9 +539,10 @@ class Lexer {
529
539
  let ch = this.buffer[i];
530
540
  if (ch === '\r')
531
541
  ch = this.buffer[--i];
542
+ const lastChar = i; // Drop the line if last char not more indented
532
543
  while (ch === ' ' || ch === '\t')
533
544
  ch = this.buffer[--i];
534
- if (ch === '\n' && i >= this.pos)
545
+ if (ch === '\n' && i >= this.pos && i + 1 + indent > lastChar)
535
546
  nl = i;
536
547
  else
537
548
  break;
@@ -614,16 +625,21 @@ class Lexer {
614
625
  return ((yield* this.pushUntil(isNotAnchorChar)) +
615
626
  (yield* this.pushSpaces(true)) +
616
627
  (yield* this.pushIndicators()));
617
- case ':':
618
- case '?': // this is an error outside flow collections
619
628
  case '-': // this is an error
620
- if (isEmpty(this.charAt(1))) {
621
- if (this.flowLevel === 0)
629
+ case '?': // this is an error outside flow collections
630
+ case ':': {
631
+ const inFlow = this.flowLevel > 0;
632
+ const ch1 = this.charAt(1);
633
+ if (isEmpty(ch1) || (inFlow && invalidFlowScalarChars.includes(ch1))) {
634
+ if (!inFlow)
622
635
  this.indentNext = this.indentValue + 1;
636
+ else if (this.flowKey)
637
+ this.flowKey = false;
623
638
  return ((yield* this.pushCount(1)) +
624
639
  (yield* this.pushSpaces(true)) +
625
640
  (yield* this.pushIndicators()));
626
641
  }
642
+ }
627
643
  }
628
644
  return 0;
629
645
  }