yaml 2.0.0-4 → 2.0.0-5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (210) hide show
  1. package/README.md +5 -5
  2. package/browser/dist/compose/compose-collection.js +12 -9
  3. package/browser/dist/compose/compose-doc.js +23 -6
  4. package/browser/dist/compose/compose-node.js +20 -17
  5. package/browser/dist/compose/compose-scalar.js +20 -23
  6. package/browser/dist/compose/composer.js +105 -76
  7. package/browser/dist/compose/resolve-block-map.js +38 -29
  8. package/browser/dist/compose/resolve-block-scalar.js +14 -17
  9. package/browser/dist/compose/resolve-block-seq.js +21 -17
  10. package/browser/dist/compose/resolve-end.js +6 -7
  11. package/browser/dist/compose/resolve-flow-collection.js +153 -199
  12. package/browser/dist/compose/resolve-flow-scalar.js +49 -25
  13. package/browser/dist/compose/resolve-props.js +47 -35
  14. package/browser/dist/compose/util-contains-newline.js +15 -12
  15. package/browser/dist/doc/Document.js +50 -99
  16. package/browser/dist/doc/anchors.js +72 -0
  17. package/browser/dist/doc/createNode.js +27 -17
  18. package/browser/dist/errors.js +16 -12
  19. package/browser/dist/index.js +3 -3
  20. package/browser/dist/nodes/Alias.js +51 -28
  21. package/browser/dist/nodes/Collection.js +5 -83
  22. package/browser/dist/nodes/Node.js +2 -1
  23. package/browser/dist/nodes/Pair.js +9 -232
  24. package/browser/dist/nodes/YAMLMap.js +8 -4
  25. package/browser/dist/nodes/YAMLSeq.js +7 -4
  26. package/browser/dist/nodes/addPairToJSMap.js +103 -0
  27. package/browser/dist/nodes/toJS.js +12 -10
  28. package/browser/dist/options.js +0 -2
  29. package/browser/dist/parse/cst-scalar.js +219 -0
  30. package/browser/dist/parse/cst-stringify.js +61 -0
  31. package/browser/dist/parse/cst-visit.js +97 -0
  32. package/{dist/parse/tokens.js → browser/dist/parse/cst.js} +12 -7
  33. package/browser/dist/parse/lexer.js +99 -105
  34. package/browser/dist/parse/parser.js +219 -144
  35. package/browser/dist/public-api.js +11 -14
  36. package/browser/dist/schema/Schema.js +23 -0
  37. package/browser/dist/{tags/failsafe → schema/common}/map.js +0 -0
  38. package/browser/dist/schema/common/null.js +13 -0
  39. package/browser/dist/{tags/failsafe → schema/common}/seq.js +1 -1
  40. package/browser/dist/{tags/failsafe → schema/common}/string.js +0 -0
  41. package/browser/dist/schema/core/bool.js +19 -0
  42. package/browser/dist/schema/core/float.js +40 -0
  43. package/browser/dist/schema/core/int.js +38 -0
  44. package/browser/dist/schema/core/schema.js +23 -0
  45. package/browser/dist/{tags/json.js → schema/json/schema.js} +5 -6
  46. package/browser/dist/schema/tags.js +79 -0
  47. package/browser/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
  48. package/browser/dist/schema/yaml-1.1/bool.js +26 -0
  49. package/browser/dist/schema/yaml-1.1/float.js +43 -0
  50. package/browser/dist/schema/yaml-1.1/int.js +71 -0
  51. package/browser/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
  52. package/browser/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
  53. package/browser/dist/schema/yaml-1.1/schema.js +37 -0
  54. package/browser/dist/{tags → schema}/yaml-1.1/set.js +0 -0
  55. package/browser/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
  56. package/browser/dist/stringify/addComment.js +1 -7
  57. package/browser/dist/stringify/stringify.js +8 -6
  58. package/browser/dist/stringify/stringifyCollection.js +108 -0
  59. package/browser/dist/stringify/stringifyDocument.js +61 -0
  60. package/browser/dist/stringify/stringifyPair.js +113 -0
  61. package/browser/dist/stringify/stringifyString.js +53 -52
  62. package/browser/dist/visit.js +20 -1
  63. package/dist/compose/compose-collection.d.ts +4 -4
  64. package/dist/compose/compose-collection.js +12 -9
  65. package/dist/compose/compose-doc.d.ts +4 -3
  66. package/dist/compose/compose-doc.js +23 -6
  67. package/dist/compose/compose-node.d.ts +15 -7
  68. package/dist/compose/compose-node.js +20 -17
  69. package/dist/compose/compose-scalar.d.ts +4 -3
  70. package/dist/compose/compose-scalar.js +19 -22
  71. package/dist/compose/composer.d.ts +28 -23
  72. package/dist/compose/composer.js +106 -77
  73. package/dist/compose/resolve-block-map.d.ts +4 -4
  74. package/dist/compose/resolve-block-map.js +38 -29
  75. package/dist/compose/resolve-block-scalar.d.ts +5 -3
  76. package/dist/compose/resolve-block-scalar.js +14 -17
  77. package/dist/compose/resolve-block-seq.d.ts +4 -4
  78. package/dist/compose/resolve-block-seq.js +21 -17
  79. package/dist/compose/resolve-end.d.ts +3 -2
  80. package/dist/compose/resolve-end.js +6 -7
  81. package/dist/compose/resolve-flow-collection.d.ts +4 -5
  82. package/dist/compose/resolve-flow-collection.js +152 -198
  83. package/dist/compose/resolve-flow-scalar.d.ts +5 -3
  84. package/dist/compose/resolve-flow-scalar.js +49 -25
  85. package/dist/compose/resolve-props.d.ts +17 -10
  86. package/dist/compose/resolve-props.js +47 -35
  87. package/dist/compose/util-contains-newline.d.ts +1 -1
  88. package/dist/compose/util-contains-newline.js +15 -12
  89. package/dist/compose/util-empty-scalar-position.d.ts +1 -1
  90. package/dist/doc/Document.d.ts +27 -15
  91. package/dist/doc/Document.js +48 -97
  92. package/dist/doc/anchors.d.ts +24 -0
  93. package/dist/doc/anchors.js +77 -0
  94. package/dist/doc/createNode.d.ts +8 -10
  95. package/dist/doc/createNode.js +26 -16
  96. package/dist/errors.d.ts +11 -8
  97. package/dist/errors.js +16 -12
  98. package/dist/index.d.ts +5 -3
  99. package/dist/index.js +3 -3
  100. package/dist/nodes/Alias.d.ts +19 -9
  101. package/dist/nodes/Alias.js +51 -28
  102. package/dist/nodes/Collection.d.ts +3 -17
  103. package/dist/nodes/Collection.js +4 -82
  104. package/dist/nodes/Node.d.ts +6 -4
  105. package/dist/nodes/Node.js +2 -0
  106. package/dist/nodes/Pair.d.ts +6 -11
  107. package/dist/nodes/Pair.js +8 -231
  108. package/dist/nodes/Scalar.d.ts +6 -3
  109. package/dist/nodes/YAMLMap.d.ts +3 -3
  110. package/dist/nodes/YAMLMap.js +8 -4
  111. package/dist/nodes/YAMLSeq.d.ts +3 -3
  112. package/dist/nodes/YAMLSeq.js +7 -4
  113. package/dist/nodes/addPairToJSMap.d.ts +3 -0
  114. package/dist/nodes/addPairToJSMap.js +105 -0
  115. package/dist/nodes/toJS.d.ts +4 -5
  116. package/dist/nodes/toJS.js +12 -10
  117. package/dist/options.d.ts +20 -26
  118. package/dist/options.js +0 -2
  119. package/dist/parse/cst-scalar.d.ts +58 -0
  120. package/dist/parse/cst-scalar.js +223 -0
  121. package/dist/parse/cst-stringify.d.ts +8 -0
  122. package/dist/parse/cst-stringify.js +63 -0
  123. package/dist/parse/cst-visit.d.ts +39 -0
  124. package/dist/parse/cst-visit.js +99 -0
  125. package/dist/parse/{tokens.d.ts → cst.d.ts} +23 -7
  126. package/{browser/dist/parse/tokens.js → dist/parse/cst.js} +27 -1
  127. package/dist/parse/lexer.d.ts +4 -13
  128. package/dist/parse/lexer.js +100 -106
  129. package/dist/parse/parser.d.ts +30 -24
  130. package/dist/parse/parser.js +221 -146
  131. package/dist/public-api.d.ts +7 -7
  132. package/dist/public-api.js +11 -14
  133. package/dist/{doc → schema}/Schema.d.ts +5 -3
  134. package/dist/schema/Schema.js +25 -0
  135. package/dist/{tags/failsafe → schema/common}/map.d.ts +0 -0
  136. package/dist/{tags/failsafe → schema/common}/map.js +0 -0
  137. package/dist/schema/common/null.d.ts +4 -0
  138. package/dist/schema/common/null.js +15 -0
  139. package/dist/{tags/failsafe → schema/common}/seq.d.ts +0 -0
  140. package/dist/{tags/failsafe → schema/common}/seq.js +1 -1
  141. package/dist/{tags/failsafe → schema/common}/string.d.ts +0 -0
  142. package/dist/{tags/failsafe → schema/common}/string.js +0 -0
  143. package/dist/schema/core/bool.d.ts +4 -0
  144. package/dist/schema/core/bool.js +21 -0
  145. package/dist/schema/core/float.d.ts +4 -0
  146. package/dist/schema/core/float.js +44 -0
  147. package/dist/schema/core/int.d.ts +4 -0
  148. package/dist/schema/core/int.js +42 -0
  149. package/dist/schema/core/schema.d.ts +1 -0
  150. package/dist/schema/core/schema.js +25 -0
  151. package/dist/schema/json/schema.d.ts +2 -0
  152. package/dist/{tags/json.js → schema/json/schema.js} +5 -6
  153. package/dist/schema/tags.d.ts +41 -0
  154. package/dist/schema/tags.js +82 -0
  155. package/dist/{tags → schema}/types.d.ts +3 -7
  156. package/dist/{tags → schema}/yaml-1.1/binary.d.ts +0 -0
  157. package/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
  158. package/dist/schema/yaml-1.1/bool.d.ts +7 -0
  159. package/dist/schema/yaml-1.1/bool.js +29 -0
  160. package/dist/schema/yaml-1.1/float.d.ts +4 -0
  161. package/dist/schema/yaml-1.1/float.js +47 -0
  162. package/dist/schema/yaml-1.1/int.d.ts +5 -0
  163. package/dist/schema/yaml-1.1/int.js +76 -0
  164. package/dist/{tags → schema}/yaml-1.1/omap.d.ts +0 -0
  165. package/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
  166. package/dist/{tags → schema}/yaml-1.1/pairs.d.ts +3 -2
  167. package/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
  168. package/dist/schema/yaml-1.1/schema.d.ts +1 -0
  169. package/dist/schema/yaml-1.1/schema.js +39 -0
  170. package/dist/{tags → schema}/yaml-1.1/set.d.ts +1 -1
  171. package/dist/{tags → schema}/yaml-1.1/set.js +0 -0
  172. package/dist/{tags → schema}/yaml-1.1/timestamp.d.ts +0 -0
  173. package/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
  174. package/dist/stringify/addComment.js +0 -7
  175. package/dist/stringify/stringify.d.ts +1 -2
  176. package/dist/stringify/stringify.js +8 -6
  177. package/dist/stringify/stringifyCollection.d.ts +21 -0
  178. package/dist/stringify/stringifyCollection.js +110 -0
  179. package/dist/stringify/stringifyDocument.d.ts +3 -0
  180. package/dist/stringify/stringifyDocument.js +63 -0
  181. package/dist/stringify/stringifyPair.d.ts +3 -0
  182. package/dist/stringify/stringifyPair.js +115 -0
  183. package/dist/stringify/stringifyString.js +53 -52
  184. package/dist/test-events.d.ts +1 -2
  185. package/dist/test-events.js +25 -12
  186. package/dist/util.d.ts +1 -1
  187. package/dist/visit.d.ts +10 -1
  188. package/dist/visit.js +20 -1
  189. package/package.json +4 -3
  190. package/browser/dist/doc/Anchors.js +0 -102
  191. package/browser/dist/doc/Schema.js +0 -27
  192. package/browser/dist/doc/getSchemaTags.js +0 -30
  193. package/browser/dist/tags/core.js +0 -109
  194. package/browser/dist/tags/failsafe/index.js +0 -7
  195. package/browser/dist/tags/index.js +0 -34
  196. package/browser/dist/tags/yaml-1.1/index.js +0 -152
  197. package/dist/doc/Anchors.d.ts +0 -36
  198. package/dist/doc/Anchors.js +0 -104
  199. package/dist/doc/Schema.js +0 -29
  200. package/dist/doc/getSchemaTags.d.ts +0 -3
  201. package/dist/doc/getSchemaTags.js +0 -32
  202. package/dist/tags/core.d.ts +0 -14
  203. package/dist/tags/core.js +0 -119
  204. package/dist/tags/failsafe/index.d.ts +0 -1
  205. package/dist/tags/failsafe/index.js +0 -9
  206. package/dist/tags/index.d.ts +0 -31
  207. package/dist/tags/index.js +0 -37
  208. package/dist/tags/json.d.ts +0 -2
  209. package/dist/tags/yaml-1.1/index.d.ts +0 -2
  210. package/dist/tags/yaml-1.1/index.js +0 -154
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ var cst = require('./cst.js');
3
4
  var lexer = require('./lexer.js');
4
- var tokens = require('./tokens.js');
5
5
 
6
6
  function includesToken(list, type) {
7
7
  for (let i = 0; i < list.length; ++i)
@@ -89,6 +89,7 @@ function getFirstKeyStartProps(prev) {
89
89
  let i = prev.length;
90
90
  loop: while (--i >= 0) {
91
91
  switch (prev[i].type) {
92
+ case 'doc-start':
92
93
  case 'explicit-key-ind':
93
94
  case 'map-value-ind':
94
95
  case 'seq-item-ind':
@@ -101,31 +102,62 @@ function getFirstKeyStartProps(prev) {
101
102
  }
102
103
  return prev.splice(i, prev.length);
103
104
  }
105
+ function fixFlowSeqItems(fc) {
106
+ if (fc.start.type === 'flow-seq-start') {
107
+ for (const it of fc.items) {
108
+ if (it.sep &&
109
+ !it.value &&
110
+ !includesToken(it.start, 'explicit-key-ind') &&
111
+ !includesToken(it.sep, 'map-value-ind')) {
112
+ if (it.key)
113
+ it.value = it.key;
114
+ delete it.key;
115
+ if (isFlowToken(it.value)) {
116
+ if (it.value.end)
117
+ Array.prototype.push.apply(it.value.end, it.sep);
118
+ else
119
+ it.value.end = it.sep;
120
+ }
121
+ else
122
+ Array.prototype.push.apply(it.start, it.sep);
123
+ delete it.sep;
124
+ }
125
+ }
126
+ }
127
+ }
104
128
  /**
105
129
  * A YAML concrete syntax tree (CST) parser
106
130
  *
107
- * While the `parse()` method provides an API for parsing a source string
108
- * directly, the parser may also be used with a user-provided lexer:
109
- *
110
131
  * ```ts
111
- * const cst: Token[] = []
112
- * const parser = new Parser(tok => cst.push(tok))
113
132
  * const src: string = ...
133
+ * for (const token of new Parser().parse(src)) {
134
+ * // token: Token
135
+ * }
136
+ * ```
137
+ *
138
+ * To use the parser with a user-provided lexer:
114
139
  *
115
- * // The following would be equivalent to `parser.parse(src, false)`
116
- * const lexer = new Lexer(parser.next)
117
- * lexer.lex(src, false)
118
- * parser.end()
140
+ * ```ts
141
+ * function* parse(source: string, lexer: Lexer) {
142
+ * const parser = new Parser()
143
+ * for (const lexeme of lexer.lex(source))
144
+ * yield* parser.next(lexeme)
145
+ * yield* parser.end()
146
+ * }
147
+ *
148
+ * const src: string = ...
149
+ * const lexer = new Lexer()
150
+ * for (const token of parse(src, lexer)) {
151
+ * // token: Token
152
+ * }
119
153
  * ```
120
154
  */
121
155
  class Parser {
122
156
  /**
123
- * @param push - Called separately with each parsed token
124
157
  * @param onNewLine - If defined, called separately with the start position of
125
158
  * each new line (in `parse()`, including the start of input).
126
- * @public
127
159
  */
128
- constructor(push, onNewLine) {
160
+ constructor(onNewLine) {
129
161
  /** If true, space and sequence indicators count as indentation */
130
162
  this.atNewLine = true;
131
163
  /** If true, next token is a scalar value */
@@ -142,96 +174,97 @@ class Parser {
142
174
  this.source = '';
143
175
  /** The type of the current token, set in parse() */
144
176
  this.type = '';
145
- /**
146
- * Advance the parser by the `source` of one lexical token. Bound to the
147
- * Parser instance, so may be used directly as a callback function.
148
- */
149
- this.next = (source) => {
150
- this.source = source;
151
- if (process.env.LOG_TOKENS)
152
- console.log('|', tokens.prettyToken(source));
153
- if (this.atScalar) {
154
- this.atScalar = false;
155
- this.step();
156
- this.offset += source.length;
157
- return;
158
- }
159
- const type = tokens.tokenType(source);
160
- if (!type) {
161
- const message = `Not a YAML token: ${source}`;
162
- this.pop({ type: 'error', offset: this.offset, message, source });
163
- this.offset += source.length;
164
- }
165
- else if (type === 'scalar') {
166
- this.atNewLine = false;
167
- this.atScalar = true;
168
- this.type = 'scalar';
169
- }
170
- else {
171
- this.type = type;
172
- this.step();
173
- switch (type) {
174
- case 'newline':
175
- this.atNewLine = true;
176
- this.indent = 0;
177
- if (this.onNewLine)
178
- this.onNewLine(this.offset + source.length);
179
- break;
180
- case 'space':
181
- if (this.atNewLine && source[0] === ' ')
182
- this.indent += source.length;
183
- break;
184
- case 'explicit-key-ind':
185
- case 'map-value-ind':
186
- case 'seq-item-ind':
187
- if (this.atNewLine)
188
- this.indent += source.length;
189
- break;
190
- case 'doc-mode':
191
- return;
192
- default:
193
- this.atNewLine = false;
194
- }
195
- this.offset += source.length;
196
- }
197
- };
198
177
  // Must be defined after `next()`
199
- this.lexer = new lexer.Lexer(this.next);
200
- this.push = push;
178
+ this.lexer = new lexer.Lexer();
201
179
  this.onNewLine = onNewLine;
202
180
  }
203
181
  /**
204
- * Parse `source` as a YAML stream, calling `push` with each directive,
205
- * document and other structure as it is completely parsed. If `incomplete`,
206
- * a part of the last line may be left as a buffer for the next call.
182
+ * Parse `source` as a YAML stream.
183
+ * If `incomplete`, a part of the last line may be left as a buffer for the next call.
207
184
  *
208
- * Errors are not thrown, but pushed out as `{ type: 'error', message }` tokens.
209
- * @public
185
+ * Errors are not thrown, but yielded as `{ type: 'error', message }` tokens.
186
+ *
187
+ * @returns A generator of tokens representing each directive, document, and other structure.
210
188
  */
211
- parse(source, incomplete = false) {
189
+ *parse(source, incomplete = false) {
212
190
  if (this.onNewLine && this.offset === 0)
213
191
  this.onNewLine(0);
214
- this.lexer.lex(source, incomplete);
192
+ for (const lexeme of this.lexer.lex(source, incomplete))
193
+ yield* this.next(lexeme);
215
194
  if (!incomplete)
216
- this.end();
195
+ yield* this.end();
196
+ }
197
+ /**
198
+ * Advance the parser by the `source` of one lexical token.
199
+ */
200
+ *next(source) {
201
+ this.source = source;
202
+ if (process.env.LOG_TOKENS)
203
+ console.log('|', cst.prettyToken(source));
204
+ if (this.atScalar) {
205
+ this.atScalar = false;
206
+ yield* this.step();
207
+ this.offset += source.length;
208
+ return;
209
+ }
210
+ const type = cst.tokenType(source);
211
+ if (!type) {
212
+ const message = `Not a YAML token: ${source}`;
213
+ yield* this.pop({ type: 'error', offset: this.offset, message, source });
214
+ this.offset += source.length;
215
+ }
216
+ else if (type === 'scalar') {
217
+ this.atNewLine = false;
218
+ this.atScalar = true;
219
+ this.type = 'scalar';
220
+ }
221
+ else {
222
+ this.type = type;
223
+ yield* this.step();
224
+ switch (type) {
225
+ case 'newline':
226
+ this.atNewLine = true;
227
+ this.indent = 0;
228
+ if (this.onNewLine)
229
+ this.onNewLine(this.offset + source.length);
230
+ break;
231
+ case 'space':
232
+ if (this.atNewLine && source[0] === ' ')
233
+ this.indent += source.length;
234
+ break;
235
+ case 'explicit-key-ind':
236
+ case 'map-value-ind':
237
+ case 'seq-item-ind':
238
+ if (this.atNewLine)
239
+ this.indent += source.length;
240
+ break;
241
+ case 'doc-mode':
242
+ return;
243
+ default:
244
+ this.atNewLine = false;
245
+ }
246
+ this.offset += source.length;
247
+ }
217
248
  }
218
249
  /** Call at end of input to push out any remaining constructions */
219
- end() {
250
+ *end() {
220
251
  while (this.stack.length > 0)
221
- this.pop();
252
+ yield* this.pop();
222
253
  }
223
254
  get sourceToken() {
224
- return {
255
+ const st = {
225
256
  type: this.type,
257
+ offset: this.offset,
226
258
  indent: this.indent,
227
259
  source: this.source
228
260
  };
261
+ return st;
229
262
  }
230
- step() {
263
+ *step() {
231
264
  const top = this.peek(1);
232
265
  if (this.type === 'doc-end' && (!top || top.type !== 'doc-end')) {
233
266
  while (this.stack.length > 0)
234
- this.pop();
267
+ yield* this.pop();
235
268
  this.stack.push({
236
269
  type: 'doc-end',
237
270
  offset: this.offset,
@@ -240,47 +273,49 @@ class Parser {
240
273
  return;
241
274
  }
242
275
  if (!top)
243
- return this.stream();
276
+ return yield* this.stream();
244
277
  switch (top.type) {
245
278
  case 'document':
246
- return this.document(top);
279
+ return yield* this.document(top);
247
280
  case 'alias':
248
281
  case 'scalar':
249
282
  case 'single-quoted-scalar':
250
283
  case 'double-quoted-scalar':
251
- return this.scalar(top);
284
+ return yield* this.scalar(top);
252
285
  case 'block-scalar':
253
- return this.blockScalar(top);
286
+ return yield* this.blockScalar(top);
254
287
  case 'block-map':
255
- return this.blockMap(top);
288
+ return yield* this.blockMap(top);
256
289
  case 'block-seq':
257
- return this.blockSequence(top);
290
+ return yield* this.blockSequence(top);
258
291
  case 'flow-collection':
259
- return this.flowCollection(top);
292
+ return yield* this.flowCollection(top);
260
293
  case 'doc-end':
261
- return this.documentEnd(top);
294
+ return yield* this.documentEnd(top);
262
295
  }
263
296
  /* istanbul ignore next should not happen */
264
- this.pop();
297
+ yield* this.pop();
265
298
  }
266
299
  peek(n) {
267
300
  return this.stack[this.stack.length - n];
268
301
  }
269
- pop(error) {
302
+ *pop(error) {
270
303
  const token = error || this.stack.pop();
271
304
  /* istanbul ignore if should not happen */
272
305
  if (!token) {
273
306
  const message = 'Tried to pop an empty stack';
274
- this.push({ type: 'error', source: '', message });
307
+ yield { type: 'error', offset: this.offset, source: '', message };
275
308
  }
276
309
  else if (this.stack.length === 0) {
277
- this.push(token);
310
+ yield token;
278
311
  }
279
312
  else {
280
313
  const top = this.peek(1);
281
314
  // For these, parent indent is needed instead of own
282
315
  if (token.type === 'block-scalar' || token.type === 'flow-collection')
283
316
  token.indent = 'indent' in top ? top.indent : -1;
317
+ if (token.type === 'flow-collection')
318
+ fixFlowSeqItems(token);
284
319
  switch (top.type) {
285
320
  case 'document':
286
321
  top.value = token;
@@ -313,13 +348,20 @@ class Parser {
313
348
  it.value = token;
314
349
  break;
315
350
  }
316
- case 'flow-collection':
317
- top.items.push(token);
318
- break;
351
+ case 'flow-collection': {
352
+ const it = top.items[top.items.length - 1];
353
+ if (!it || it.value)
354
+ top.items.push({ start: [], key: token, sep: [] });
355
+ else if (it.sep)
356
+ it.value = token;
357
+ else
358
+ Object.assign(it, { key: token, sep: [] });
359
+ return;
360
+ }
319
361
  /* istanbul ignore next should not happen */
320
362
  default:
321
- this.pop();
322
- this.pop(token);
363
+ yield* this.pop();
364
+ yield* this.pop(token);
323
365
  }
324
366
  if ((top.type === 'document' ||
325
367
  top.type === 'block-map' ||
@@ -342,16 +384,16 @@ class Parser {
342
384
  }
343
385
  }
344
386
  }
345
- stream() {
387
+ *stream() {
346
388
  switch (this.type) {
347
389
  case 'directive-line':
348
- this.push({ type: 'directive', source: this.source });
390
+ yield { type: 'directive', offset: this.offset, source: this.source };
349
391
  return;
350
392
  case 'byte-order-mark':
351
393
  case 'space':
352
394
  case 'comment':
353
395
  case 'newline':
354
- this.push(this.sourceToken);
396
+ yield this.sourceToken;
355
397
  return;
356
398
  case 'doc-mode':
357
399
  case 'doc-start': {
@@ -366,21 +408,21 @@ class Parser {
366
408
  return;
367
409
  }
368
410
  }
369
- this.push({
411
+ yield {
370
412
  type: 'error',
371
413
  offset: this.offset,
372
414
  message: `Unexpected ${this.type} token in YAML stream`,
373
415
  source: this.source
374
- });
416
+ };
375
417
  }
376
- document(doc) {
418
+ *document(doc) {
377
419
  if (doc.value)
378
- return this.lineEnd(doc);
420
+ return yield* this.lineEnd(doc);
379
421
  switch (this.type) {
380
422
  case 'doc-start': {
381
423
  if (includesNonEmpty(doc.start)) {
382
- this.pop();
383
- this.step();
424
+ yield* this.pop();
425
+ yield* this.step();
384
426
  }
385
427
  else
386
428
  doc.start.push(this.sourceToken);
@@ -398,15 +440,15 @@ class Parser {
398
440
  if (bv)
399
441
  this.stack.push(bv);
400
442
  else {
401
- this.push({
443
+ yield {
402
444
  type: 'error',
403
445
  offset: this.offset,
404
446
  message: `Unexpected ${this.type} token in YAML document`,
405
447
  source: this.source
406
- });
448
+ };
407
449
  }
408
450
  }
409
- scalar(scalar) {
451
+ *scalar(scalar) {
410
452
  if (this.type === 'map-value-ind') {
411
453
  const prev = getPrevProps(this.peek(2));
412
454
  const start = getFirstKeyStartProps(prev);
@@ -428,9 +470,9 @@ class Parser {
428
470
  this.stack[this.stack.length - 1] = map;
429
471
  }
430
472
  else
431
- this.lineEnd(scalar);
473
+ yield* this.lineEnd(scalar);
432
474
  }
433
- blockScalar(scalar) {
475
+ *blockScalar(scalar) {
434
476
  switch (this.type) {
435
477
  case 'space':
436
478
  case 'comment':
@@ -449,15 +491,15 @@ class Parser {
449
491
  nl = this.source.indexOf('\n', nl) + 1;
450
492
  }
451
493
  }
452
- this.pop();
494
+ yield* this.pop();
453
495
  break;
454
496
  /* istanbul ignore next should not happen */
455
497
  default:
456
- this.pop();
457
- this.step();
498
+ yield* this.pop();
499
+ yield* this.step();
458
500
  }
459
501
  }
460
- blockMap(map) {
502
+ *blockMap(map) {
461
503
  var _a;
462
504
  const it = map.items[map.items.length - 1];
463
505
  // it.sep is true-ish if pair already has key or : separator
@@ -578,10 +620,10 @@ class Parser {
578
620
  }
579
621
  }
580
622
  }
581
- this.pop();
582
- this.step();
623
+ yield* this.pop();
624
+ yield* this.step();
583
625
  }
584
- blockSequence(seq) {
626
+ *blockSequence(seq) {
585
627
  var _a;
586
628
  const it = seq.items[seq.items.length - 1];
587
629
  switch (this.type) {
@@ -620,38 +662,65 @@ class Parser {
620
662
  }
621
663
  if (this.indent > seq.indent) {
622
664
  const bv = this.startBlockValue(seq);
623
- if (bv)
624
- return this.stack.push(bv);
665
+ if (bv) {
666
+ this.stack.push(bv);
667
+ return;
668
+ }
625
669
  }
626
- this.pop();
627
- this.step();
670
+ yield* this.pop();
671
+ yield* this.step();
628
672
  }
629
- flowCollection(fc) {
673
+ *flowCollection(fc) {
674
+ const it = fc.items[fc.items.length - 1];
630
675
  if (this.type === 'flow-error-end') {
631
676
  let top;
632
677
  do {
633
- this.pop();
678
+ yield* this.pop();
634
679
  top = this.peek(1);
635
680
  } while (top && top.type === 'flow-collection');
636
681
  }
637
682
  else if (fc.end.length === 0) {
638
683
  switch (this.type) {
639
- case 'space':
640
- case 'comment':
641
- case 'newline':
642
684
  case 'comma':
643
685
  case 'explicit-key-ind':
686
+ if (!it || it.sep)
687
+ fc.items.push({ start: [this.sourceToken] });
688
+ else
689
+ it.start.push(this.sourceToken);
690
+ return;
644
691
  case 'map-value-ind':
692
+ if (!it || it.value)
693
+ fc.items.push({ start: [], key: null, sep: [this.sourceToken] });
694
+ else if (it.sep)
695
+ it.sep.push(this.sourceToken);
696
+ else
697
+ Object.assign(it, { key: null, sep: [this.sourceToken] });
698
+ return;
699
+ case 'space':
700
+ case 'comment':
701
+ case 'newline':
645
702
  case 'anchor':
646
703
  case 'tag':
647
- fc.items.push(this.sourceToken);
704
+ if (!it || it.value)
705
+ fc.items.push({ start: [this.sourceToken] });
706
+ else if (it.sep)
707
+ it.sep.push(this.sourceToken);
708
+ else
709
+ it.start.push(this.sourceToken);
648
710
  return;
649
711
  case 'alias':
650
712
  case 'scalar':
651
713
  case 'single-quoted-scalar':
652
- case 'double-quoted-scalar':
653
- fc.items.push(this.flowScalar(this.type));
714
+ case 'double-quoted-scalar': {
715
+ const fs = this.flowScalar(this.type);
716
+ if (!it || it.value)
717
+ fc.items.push({ start: [], key: fs, sep: [] });
718
+ else if (it.sep)
719
+ this.stack.push(fs);
720
+ else
721
+ Object.assign(it, { key: fs, sep: [] });
654
722
  return;
723
+ }
655
724
  case 'flow-map-end':
656
725
  case 'flow-seq-end':
657
726
  fc.end.push(this.sourceToken);
@@ -660,10 +729,10 @@ class Parser {
660
729
  const bv = this.startBlockValue(fc);
661
730
  /* istanbul ignore else should not happen */
662
731
  if (bv)
663
- return this.stack.push(bv);
732
+ this.stack.push(bv);
664
733
  else {
665
- this.pop();
666
- this.step();
734
+ yield* this.pop();
735
+ yield* this.step();
667
736
  }
668
737
  }
669
738
  else {
@@ -672,13 +741,14 @@ class Parser {
672
741
  (this.type === 'map-value-ind' ||
673
742
  (this.type === 'newline' &&
674
743
  !parent.items[parent.items.length - 1].sep))) {
675
- this.pop();
676
- this.step();
744
+ yield* this.pop();
745
+ yield* this.step();
677
746
  }
678
747
  else if (this.type === 'map-value-ind' &&
679
748
  parent.type !== 'flow-collection') {
680
749
  const prev = getPrevProps(parent);
681
750
  const start = getFirstKeyStartProps(prev);
751
+ fixFlowSeqItems(fc);
682
752
  const sep = fc.end.splice(1, fc.end.length);
683
753
  sep.push(this.sourceToken);
684
754
  const map = {
@@ -691,7 +761,7 @@ class Parser {
691
761
  this.stack[this.stack.length - 1] = map;
692
762
  }
693
763
  else {
694
- this.lineEnd(fc);
764
+ yield* this.lineEnd(fc);
695
765
  }
696
766
  }
697
767
  }
@@ -722,7 +792,8 @@ class Parser {
722
792
  type: 'block-scalar',
723
793
  offset: this.offset,
724
794
  indent: this.indent,
725
- props: [this.sourceToken]
795
+ props: [this.sourceToken],
796
+ source: ''
726
797
  };
727
798
  case 'flow-map-start':
728
799
  case 'flow-seq-start':
@@ -741,14 +812,18 @@ class Parser {
741
812
  indent: this.indent,
742
813
  items: [{ start: [this.sourceToken] }]
743
814
  };
744
- case 'explicit-key-ind':
815
+ case 'explicit-key-ind': {
745
816
  this.onKeyLine = true;
817
+ const prev = getPrevProps(parent);
818
+ const start = getFirstKeyStartProps(prev);
819
+ start.push(this.sourceToken);
746
820
  return {
747
821
  type: 'block-map',
748
822
  offset: this.offset,
749
823
  indent: this.indent,
750
- items: [{ start: [this.sourceToken] }]
824
+ items: [{ start }]
751
825
  };
826
+ }
752
827
  case 'map-value-ind': {
753
828
  this.onKeyLine = true;
754
829
  const prev = getPrevProps(parent);
@@ -763,17 +838,17 @@ class Parser {
763
838
  }
764
839
  return null;
765
840
  }
766
- documentEnd(docEnd) {
841
+ *documentEnd(docEnd) {
767
842
  if (this.type !== 'doc-mode') {
768
843
  if (docEnd.end)
769
844
  docEnd.end.push(this.sourceToken);
770
845
  else
771
846
  docEnd.end = [this.sourceToken];
772
847
  if (this.type === 'newline')
773
- this.pop();
848
+ yield* this.pop();
774
849
  }
775
850
  }
776
- lineEnd(token) {
851
+ *lineEnd(token) {
777
852
  switch (this.type) {
778
853
  case 'comma':
779
854
  case 'doc-start':
@@ -781,8 +856,8 @@ class Parser {
781
856
  case 'flow-seq-end':
782
857
  case 'flow-map-end':
783
858
  case 'map-value-ind':
784
- this.pop();
785
- this.step();
859
+ yield* this.pop();
860
+ yield* this.step();
786
861
  break;
787
862
  case 'newline':
788
863
  this.onKeyLine = false;
@@ -796,7 +871,7 @@ class Parser {
796
871
  else
797
872
  token.end = [this.sourceToken];
798
873
  if (this.type === 'newline')
799
- this.pop();
874
+ yield* this.pop();
800
875
  }
801
876
  }
802
877
  }
@@ -2,7 +2,7 @@ import { Composer } from './compose/composer.js';
2
2
  import type { Reviver } from './doc/applyReviver.js';
3
3
  import { Document, Replacer } from './doc/Document.js';
4
4
  import type { ParsedNode } from './nodes/Node.js';
5
- import type { Options, ToJSOptions, ToStringOptions } from './options.js';
5
+ import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options.js';
6
6
  export interface EmptyStream extends Array<Document.Parsed>, ReturnType<Composer['streamInfo']> {
7
7
  empty: true;
8
8
  }
@@ -15,9 +15,9 @@ export interface EmptyStream extends Array<Document.Parsed>, ReturnType<Composer
15
15
  * EmptyStream and contain additional stream information. In
16
16
  * TypeScript, you should use `'empty' in docs` as a type guard for it.
17
17
  */
18
- export declare function parseAllDocuments<T extends ParsedNode = ParsedNode>(source: string, options?: Options): Document.Parsed<T>[] | EmptyStream;
18
+ export declare function parseAllDocuments<T extends ParsedNode = ParsedNode>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<T>[] | EmptyStream;
19
19
  /** Parse an input string into a single YAML.Document */
20
- export declare function parseDocument<T extends ParsedNode = ParsedNode>(source: string, options?: Options): Document.Parsed<T>;
20
+ export declare function parseDocument<T extends ParsedNode = ParsedNode>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<T>;
21
21
  /**
22
22
  * Parse an input string into JavaScript.
23
23
  *
@@ -31,13 +31,13 @@ export declare function parseDocument<T extends ParsedNode = ParsedNode>(source:
31
31
  * document, so Maps become objects, Sequences arrays, and scalars result in
32
32
  * nulls, booleans, numbers and strings.
33
33
  */
34
- export declare function parse(src: string, options?: Options & ToJSOptions): any;
35
- export declare function parse(src: string, reviver: Reviver, options?: Options & ToJSOptions): any;
34
+ export declare function parse(src: string, options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions): any;
35
+ export declare function parse(src: string, reviver: Reviver, options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions): any;
36
36
  /**
37
37
  * Stringify a value as a YAML document.
38
38
  *
39
39
  * @param replacer - A replacer array or function, as in `JSON.stringify()`
40
40
  * @returns Will always include `\n` as the last character, as is expected of YAML documents.
41
41
  */
42
- export declare function stringify(value: any, options?: Options & ToStringOptions): string;
43
- export declare function stringify(value: any, replacer?: Replacer | null, options?: string | number | (Options & ToStringOptions)): string;
42
+ export declare function stringify(value: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions): string;
43
+ export declare function stringify(value: any, replacer?: Replacer | null, options?: string | number | (DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions)): string;