yaml 2.0.0-4 → 2.0.0-8

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 (220) 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 +27 -17
  5. package/browser/dist/compose/compose-scalar.js +21 -23
  6. package/browser/dist/compose/composer.js +108 -78
  7. package/browser/dist/compose/resolve-block-map.js +41 -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 +7 -8
  11. package/browser/dist/compose/resolve-flow-collection.js +158 -199
  12. package/browser/dist/compose/resolve-flow-scalar.js +62 -26
  13. package/browser/dist/compose/resolve-props.js +72 -37
  14. package/browser/dist/compose/util-contains-newline.js +15 -12
  15. package/browser/dist/compose/util-map-includes.js +17 -0
  16. package/browser/dist/doc/Document.js +74 -99
  17. package/browser/dist/doc/anchors.js +72 -0
  18. package/browser/dist/doc/createNode.js +35 -19
  19. package/browser/dist/doc/directives.js +5 -0
  20. package/browser/dist/errors.js +16 -12
  21. package/browser/dist/index.js +3 -3
  22. package/browser/dist/nodes/Alias.js +51 -28
  23. package/browser/dist/nodes/Collection.js +23 -92
  24. package/browser/dist/nodes/Node.js +9 -1
  25. package/browser/dist/nodes/Pair.js +16 -231
  26. package/browser/dist/nodes/YAMLMap.js +8 -4
  27. package/browser/dist/nodes/YAMLSeq.js +7 -4
  28. package/browser/dist/nodes/addPairToJSMap.js +103 -0
  29. package/browser/dist/nodes/toJS.js +12 -10
  30. package/browser/dist/options.js +1 -2
  31. package/browser/dist/parse/cst-scalar.js +219 -0
  32. package/browser/dist/parse/cst-stringify.js +61 -0
  33. package/browser/dist/parse/cst-visit.js +97 -0
  34. package/{dist/parse/tokens.js → browser/dist/parse/cst.js} +12 -7
  35. package/browser/dist/parse/lexer.js +149 -125
  36. package/browser/dist/parse/parser.js +272 -196
  37. package/browser/dist/public-api.js +11 -14
  38. package/browser/dist/schema/Schema.js +28 -0
  39. package/browser/dist/{tags/failsafe → schema/common}/map.js +0 -0
  40. package/browser/dist/schema/common/null.js +13 -0
  41. package/browser/dist/{tags/failsafe → schema/common}/seq.js +1 -1
  42. package/browser/dist/{tags/failsafe → schema/common}/string.js +0 -0
  43. package/browser/dist/schema/core/bool.js +19 -0
  44. package/browser/dist/schema/core/float.js +40 -0
  45. package/browser/dist/schema/core/int.js +38 -0
  46. package/browser/dist/schema/core/schema.js +23 -0
  47. package/browser/dist/{tags/json.js → schema/json/schema.js} +5 -6
  48. package/browser/dist/schema/tags.js +79 -0
  49. package/browser/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
  50. package/browser/dist/schema/yaml-1.1/bool.js +26 -0
  51. package/browser/dist/schema/yaml-1.1/float.js +43 -0
  52. package/browser/dist/schema/yaml-1.1/int.js +71 -0
  53. package/browser/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
  54. package/browser/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
  55. package/browser/dist/schema/yaml-1.1/schema.js +37 -0
  56. package/browser/dist/{tags → schema}/yaml-1.1/set.js +0 -0
  57. package/browser/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
  58. package/browser/dist/stringify/stringify.js +8 -6
  59. package/browser/dist/stringify/stringifyCollection.js +122 -0
  60. package/browser/dist/stringify/stringifyComment.js +14 -0
  61. package/browser/dist/stringify/stringifyDocument.js +64 -0
  62. package/browser/dist/stringify/stringifyPair.js +111 -0
  63. package/browser/dist/stringify/stringifyString.js +53 -52
  64. package/browser/dist/visit.js +20 -1
  65. package/dist/compose/compose-collection.d.ts +4 -4
  66. package/dist/compose/compose-collection.js +12 -9
  67. package/dist/compose/compose-doc.d.ts +4 -3
  68. package/dist/compose/compose-doc.js +23 -6
  69. package/dist/compose/compose-node.d.ts +15 -7
  70. package/dist/compose/compose-node.js +27 -17
  71. package/dist/compose/compose-scalar.d.ts +4 -3
  72. package/dist/compose/compose-scalar.js +20 -22
  73. package/dist/compose/composer.d.ts +28 -23
  74. package/dist/compose/composer.js +109 -79
  75. package/dist/compose/resolve-block-map.d.ts +5 -4
  76. package/dist/compose/resolve-block-map.js +41 -29
  77. package/dist/compose/resolve-block-scalar.d.ts +5 -3
  78. package/dist/compose/resolve-block-scalar.js +14 -17
  79. package/dist/compose/resolve-block-seq.d.ts +4 -4
  80. package/dist/compose/resolve-block-seq.js +21 -17
  81. package/dist/compose/resolve-end.d.ts +3 -2
  82. package/dist/compose/resolve-end.js +7 -8
  83. package/dist/compose/resolve-flow-collection.d.ts +4 -5
  84. package/dist/compose/resolve-flow-collection.js +157 -198
  85. package/dist/compose/resolve-flow-scalar.d.ts +5 -3
  86. package/dist/compose/resolve-flow-scalar.js +62 -26
  87. package/dist/compose/resolve-props.d.ts +16 -10
  88. package/dist/compose/resolve-props.js +72 -37
  89. package/dist/compose/util-contains-newline.d.ts +1 -1
  90. package/dist/compose/util-contains-newline.js +15 -12
  91. package/dist/compose/util-empty-scalar-position.d.ts +1 -1
  92. package/dist/compose/util-map-includes.d.ts +4 -0
  93. package/dist/compose/util-map-includes.js +19 -0
  94. package/dist/doc/Document.d.ts +35 -15
  95. package/dist/doc/Document.js +72 -97
  96. package/dist/doc/anchors.d.ts +24 -0
  97. package/dist/doc/anchors.js +77 -0
  98. package/dist/doc/createNode.d.ts +10 -11
  99. package/dist/doc/createNode.js +34 -18
  100. package/dist/doc/directives.d.ts +1 -0
  101. package/dist/doc/directives.js +5 -0
  102. package/dist/errors.d.ts +11 -8
  103. package/dist/errors.js +16 -12
  104. package/dist/index.d.ts +5 -3
  105. package/dist/index.js +3 -3
  106. package/dist/nodes/Alias.d.ts +19 -9
  107. package/dist/nodes/Alias.js +51 -28
  108. package/dist/nodes/Collection.d.ts +9 -17
  109. package/dist/nodes/Collection.js +22 -91
  110. package/dist/nodes/Node.d.ts +10 -4
  111. package/dist/nodes/Node.js +9 -0
  112. package/dist/nodes/Pair.d.ts +10 -13
  113. package/dist/nodes/Pair.js +15 -230
  114. package/dist/nodes/Scalar.d.ts +6 -3
  115. package/dist/nodes/YAMLMap.d.ts +3 -3
  116. package/dist/nodes/YAMLMap.js +8 -4
  117. package/dist/nodes/YAMLSeq.d.ts +3 -3
  118. package/dist/nodes/YAMLSeq.js +7 -4
  119. package/dist/nodes/addPairToJSMap.d.ts +3 -0
  120. package/dist/nodes/addPairToJSMap.js +105 -0
  121. package/dist/nodes/toJS.d.ts +4 -5
  122. package/dist/nodes/toJS.js +12 -10
  123. package/dist/options.d.ts +41 -25
  124. package/dist/options.js +1 -2
  125. package/dist/parse/cst-scalar.d.ts +58 -0
  126. package/dist/parse/cst-scalar.js +223 -0
  127. package/dist/parse/cst-stringify.d.ts +8 -0
  128. package/dist/parse/cst-stringify.js +63 -0
  129. package/dist/parse/cst-visit.d.ts +39 -0
  130. package/dist/parse/cst-visit.js +99 -0
  131. package/dist/parse/{tokens.d.ts → cst.d.ts} +23 -7
  132. package/{browser/dist/parse/tokens.js → dist/parse/cst.js} +27 -1
  133. package/dist/parse/lexer.d.ts +7 -14
  134. package/dist/parse/lexer.js +150 -126
  135. package/dist/parse/parser.d.ts +31 -24
  136. package/dist/parse/parser.js +274 -198
  137. package/dist/public-api.d.ts +7 -7
  138. package/dist/public-api.js +11 -14
  139. package/dist/{doc → schema}/Schema.d.ts +6 -3
  140. package/dist/schema/Schema.js +30 -0
  141. package/dist/{tags/failsafe → schema/common}/map.d.ts +0 -0
  142. package/dist/{tags/failsafe → schema/common}/map.js +0 -0
  143. package/dist/schema/common/null.d.ts +4 -0
  144. package/dist/schema/common/null.js +15 -0
  145. package/dist/{tags/failsafe → schema/common}/seq.d.ts +0 -0
  146. package/dist/{tags/failsafe → schema/common}/seq.js +1 -1
  147. package/dist/{tags/failsafe → schema/common}/string.d.ts +0 -0
  148. package/dist/{tags/failsafe → schema/common}/string.js +0 -0
  149. package/dist/schema/core/bool.d.ts +4 -0
  150. package/dist/schema/core/bool.js +21 -0
  151. package/dist/schema/core/float.d.ts +4 -0
  152. package/dist/schema/core/float.js +44 -0
  153. package/dist/schema/core/int.d.ts +4 -0
  154. package/dist/schema/core/int.js +42 -0
  155. package/dist/schema/core/schema.d.ts +1 -0
  156. package/dist/schema/core/schema.js +25 -0
  157. package/dist/schema/json/schema.d.ts +2 -0
  158. package/dist/{tags/json.js → schema/json/schema.js} +5 -6
  159. package/dist/schema/tags.d.ts +41 -0
  160. package/dist/schema/tags.js +82 -0
  161. package/dist/{tags → schema}/types.d.ts +3 -7
  162. package/dist/{tags → schema}/yaml-1.1/binary.d.ts +0 -0
  163. package/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
  164. package/dist/schema/yaml-1.1/bool.d.ts +7 -0
  165. package/dist/schema/yaml-1.1/bool.js +29 -0
  166. package/dist/schema/yaml-1.1/float.d.ts +4 -0
  167. package/dist/schema/yaml-1.1/float.js +47 -0
  168. package/dist/schema/yaml-1.1/int.d.ts +5 -0
  169. package/dist/schema/yaml-1.1/int.js +76 -0
  170. package/dist/{tags → schema}/yaml-1.1/omap.d.ts +0 -0
  171. package/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
  172. package/dist/{tags → schema}/yaml-1.1/pairs.d.ts +3 -2
  173. package/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
  174. package/dist/schema/yaml-1.1/schema.d.ts +1 -0
  175. package/dist/schema/yaml-1.1/schema.js +39 -0
  176. package/dist/{tags → schema}/yaml-1.1/set.d.ts +1 -1
  177. package/dist/{tags → schema}/yaml-1.1/set.js +0 -0
  178. package/dist/{tags → schema}/yaml-1.1/timestamp.d.ts +0 -0
  179. package/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
  180. package/dist/stringify/stringify.d.ts +1 -2
  181. package/dist/stringify/stringify.js +8 -6
  182. package/dist/stringify/stringifyCollection.d.ts +21 -0
  183. package/dist/stringify/stringifyCollection.js +124 -0
  184. package/dist/stringify/stringifyComment.d.ts +2 -0
  185. package/dist/stringify/stringifyComment.js +17 -0
  186. package/dist/stringify/stringifyDocument.d.ts +3 -0
  187. package/dist/stringify/stringifyDocument.js +66 -0
  188. package/dist/stringify/stringifyPair.d.ts +3 -0
  189. package/dist/stringify/stringifyPair.js +113 -0
  190. package/dist/stringify/stringifyString.js +53 -52
  191. package/dist/test-events.d.ts +1 -2
  192. package/dist/test-events.js +25 -12
  193. package/dist/util.d.ts +1 -1
  194. package/dist/visit.d.ts +10 -1
  195. package/dist/visit.js +20 -1
  196. package/package.json +9 -8
  197. package/browser/dist/doc/Anchors.js +0 -102
  198. package/browser/dist/doc/Schema.js +0 -27
  199. package/browser/dist/doc/getSchemaTags.js +0 -30
  200. package/browser/dist/stringify/addComment.js +0 -17
  201. package/browser/dist/tags/core.js +0 -109
  202. package/browser/dist/tags/failsafe/index.js +0 -7
  203. package/browser/dist/tags/index.js +0 -34
  204. package/browser/dist/tags/yaml-1.1/index.js +0 -152
  205. package/dist/doc/Anchors.d.ts +0 -36
  206. package/dist/doc/Anchors.js +0 -104
  207. package/dist/doc/Schema.js +0 -29
  208. package/dist/doc/getSchemaTags.d.ts +0 -3
  209. package/dist/doc/getSchemaTags.js +0 -32
  210. package/dist/stringify/addComment.d.ts +0 -2
  211. package/dist/stringify/addComment.js +0 -20
  212. package/dist/tags/core.d.ts +0 -14
  213. package/dist/tags/core.js +0 -119
  214. package/dist/tags/failsafe/index.d.ts +0 -1
  215. package/dist/tags/failsafe/index.js +0 -9
  216. package/dist/tags/index.d.ts +0 -31
  217. package/dist/tags/index.js +0 -37
  218. package/dist/tags/json.d.ts +0 -2
  219. package/dist/tags/yaml-1.1/index.d.ts +0 -2
  220. package/dist/tags/yaml-1.1/index.js +0 -154
@@ -2,26 +2,31 @@ import { Pair } from '../nodes/Pair.js';
2
2
  import { YAMLMap } from '../nodes/YAMLMap.js';
3
3
  import { resolveProps } from './resolve-props.js';
4
4
  import { containsNewline } from './util-contains-newline.js';
5
+ import { mapIncludes } from './util-map-includes.js';
5
6
 
6
7
  const startColMsg = 'All mapping items must start at the same column';
7
- function resolveBlockMap({ composeNode, composeEmptyNode }, doc, { indent, items, offset }, anchor, onError) {
8
+ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
8
9
  var _a;
9
- const start = offset;
10
- const map = new YAMLMap(doc.schema);
11
- if (anchor)
12
- doc.anchors.setAnchor(map, anchor);
13
- for (const { start, key, sep, value } of items) {
10
+ const map = new YAMLMap(ctx.schema);
11
+ let offset = bm.offset;
12
+ for (const { start, key, sep, value } of bm.items) {
14
13
  // key properties
15
- const keyProps = resolveProps(doc, start, true, 'explicit-key-ind', offset, onError);
14
+ const keyProps = resolveProps(start, {
15
+ indicator: 'explicit-key-ind',
16
+ next: key || (sep === null || sep === void 0 ? void 0 : sep[0]),
17
+ offset,
18
+ onError,
19
+ startOnNewline: true
20
+ });
16
21
  const implicitKey = !keyProps.found;
17
22
  if (implicitKey) {
18
23
  if (key) {
19
24
  if (key.type === 'block-seq')
20
- onError(offset, 'A block sequence may not be used as an implicit map key');
21
- else if ('indent' in key && key.indent !== indent)
22
- onError(offset, startColMsg);
25
+ onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'A block sequence may not be used as an implicit map key');
26
+ else if ('indent' in key && key.indent !== bm.indent)
27
+ onError(offset, 'BAD_INDENT', startColMsg);
23
28
  }
24
- if (!keyProps.anchor && !keyProps.tagName && !sep) {
29
+ if (!keyProps.anchor && !keyProps.tag && !sep) {
25
30
  // TODO: assert being at last item?
26
31
  if (keyProps.comment) {
27
32
  if (map.comment)
@@ -32,39 +37,46 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, doc, { indent, items
32
37
  continue;
33
38
  }
34
39
  }
35
- else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== indent)
36
- onError(offset, startColMsg);
37
- offset += keyProps.length;
40
+ else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent)
41
+ onError(offset, 'BAD_INDENT', startColMsg);
38
42
  if (implicitKey && containsNewline(key))
39
- onError(offset, 'Implicit keys need to be on a single line');
43
+ onError(key, // checked by containsNewline()
44
+ 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
40
45
  // key value
41
- const keyStart = offset;
46
+ const keyStart = keyProps.end;
42
47
  const keyNode = key
43
- ? composeNode(doc, key, keyProps, onError)
44
- : composeEmptyNode(doc, offset, start, null, keyProps, onError);
45
- offset = keyNode.range[1];
48
+ ? composeNode(ctx, key, keyProps, onError)
49
+ : composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
50
+ if (mapIncludes(ctx, map.items, keyNode))
51
+ onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
46
52
  // value properties
47
- const valueProps = resolveProps(doc, sep || [], !key || key.type === 'block-scalar', 'map-value-ind', offset, onError);
48
- offset += valueProps.length;
53
+ const valueProps = resolveProps(sep || [], {
54
+ indicator: 'map-value-ind',
55
+ next: value,
56
+ offset: keyNode.range[2],
57
+ onError,
58
+ startOnNewline: !key || key.type === 'block-scalar'
59
+ });
60
+ offset = valueProps.end;
49
61
  if (valueProps.found) {
50
62
  if (implicitKey) {
51
63
  if ((value === null || value === void 0 ? void 0 : value.type) === 'block-map' && !valueProps.hasNewline)
52
- onError(offset, 'Nested mappings are not allowed in compact mappings');
53
- if (doc.options.strict &&
64
+ onError(offset, 'BLOCK_AS_IMPLICIT_KEY', 'Nested mappings are not allowed in compact mappings');
65
+ if (ctx.options.strict &&
54
66
  keyProps.start < valueProps.found.offset - 1024)
55
- onError(offset, 'The : indicator must be at most 1024 chars after the start of an implicit block mapping key');
67
+ onError(keyNode.range, 'KEY_OVER_1024_CHARS', 'The : indicator must be at most 1024 chars after the start of an implicit block mapping key');
56
68
  }
57
69
  // value value
58
70
  const valueNode = value
59
- ? composeNode(doc, value, valueProps, onError)
60
- : composeEmptyNode(doc, offset, sep, null, valueProps, onError);
61
- offset = valueNode.range[1];
71
+ ? composeNode(ctx, value, valueProps, onError)
72
+ : composeEmptyNode(ctx, offset, sep, null, valueProps, onError);
73
+ offset = valueNode.range[2];
62
74
  map.items.push(new Pair(keyNode, valueNode));
63
75
  }
64
76
  else {
65
77
  // key with no value
66
78
  if (implicitKey)
67
- onError(keyStart, 'Implicit map keys need to be followed by map values');
79
+ onError(keyNode.range, 'MISSING_CHAR', 'Implicit map keys need to be followed by map values');
68
80
  if (valueProps.comment) {
69
81
  if (keyNode.comment)
70
82
  keyNode.comment += '\n' + valueProps.comment;
@@ -74,7 +86,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, doc, { indent, items
74
86
  map.items.push(new Pair(keyNode));
75
87
  }
76
88
  }
77
- map.range = [start, offset];
89
+ map.range = [bm.offset, offset, offset];
78
90
  return map;
79
91
  }
80
92
 
@@ -1,9 +1,10 @@
1
1
  import { Scalar } from '../nodes/Scalar.js';
2
2
 
3
3
  function resolveBlockScalar(scalar, strict, onError) {
4
+ const start = scalar.offset;
4
5
  const header = parseBlockScalarHeader(scalar, strict, onError);
5
6
  if (!header)
6
- return { value: '', type: null, comment: '', length: 0 };
7
+ return { value: '', type: null, comment: '', range: [start, start, start] };
7
8
  const type = header.mode === '>' ? Scalar.BLOCK_FOLDED : Scalar.BLOCK_LITERAL;
8
9
  const lines = scalar.source ? splitLines(scalar.source) : [];
9
10
  // determine the end of content & start of chomping
@@ -18,10 +19,10 @@ function resolveBlockScalar(scalar, strict, onError) {
18
19
  // shortcut for empty contents
19
20
  if (!scalar.source || chompStart === 0) {
20
21
  const value = header.chomp === '+' ? lines.map(line => line[0]).join('\n') : '';
21
- let length = header.length;
22
+ let end = start + header.length;
22
23
  if (scalar.source)
23
- length += scalar.source.length;
24
- return { value, type, comment: header.comment, length };
24
+ end += scalar.source.length;
25
+ return { value, type, comment: header.comment, range: [start, end, end] };
25
26
  }
26
27
  // find the indentation level to trim from start
27
28
  let trimIndent = scalar.indent + header.indent;
@@ -36,7 +37,7 @@ function resolveBlockScalar(scalar, strict, onError) {
36
37
  else {
37
38
  if (indent.length < trimIndent) {
38
39
  const message = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator';
39
- onError(offset + indent.length, message);
40
+ onError(offset + indent.length, 'MISSING_CHAR', message);
40
41
  }
41
42
  if (header.indent === 0)
42
43
  trimIndent = indent.length;
@@ -63,7 +64,7 @@ function resolveBlockScalar(scalar, strict, onError) {
63
64
  ? 'explicit indentation indicator'
64
65
  : 'first line';
65
66
  const message = `Block scalar lines must not be less indented than their ${src}`;
66
- onError(offset - content.length - (crlf ? 2 : 1), message);
67
+ onError(offset - content.length - (crlf ? 2 : 1), 'BAD_INDENT', message);
67
68
  indent = '';
68
69
  }
69
70
  if (type === Scalar.BLOCK_LITERAL) {
@@ -105,17 +106,13 @@ function resolveBlockScalar(scalar, strict, onError) {
105
106
  default:
106
107
  value += '\n';
107
108
  }
108
- return {
109
- value,
110
- type,
111
- comment: header.comment,
112
- length: header.length + scalar.source.length
113
- };
109
+ const end = start + header.length + scalar.source.length;
110
+ return { value, type, comment: header.comment, range: [start, end, end] };
114
111
  }
115
112
  function parseBlockScalarHeader({ offset, props }, strict, onError) {
116
113
  /* istanbul ignore if should not happen */
117
114
  if (props[0].type !== 'block-scalar-header') {
118
- onError(offset, 'Block scalar header not found');
115
+ onError(props[0], 'IMPOSSIBLE', 'Block scalar header not found');
119
116
  return null;
120
117
  }
121
118
  const { source } = props[0];
@@ -136,7 +133,7 @@ function parseBlockScalarHeader({ offset, props }, strict, onError) {
136
133
  }
137
134
  }
138
135
  if (error !== -1)
139
- onError(error, `Block scalar header includes extra characters: ${source}`);
136
+ onError(error, 'UNEXPECTED_TOKEN', `Block scalar header includes extra characters: ${source}`);
140
137
  let hasSpace = false;
141
138
  let comment = '';
142
139
  let length = source.length;
@@ -152,19 +149,19 @@ function parseBlockScalarHeader({ offset, props }, strict, onError) {
152
149
  case 'comment':
153
150
  if (strict && !hasSpace) {
154
151
  const message = 'Comments must be separated from other tokens by white space characters';
155
- onError(offset + length, message);
152
+ onError(token, 'MISSING_CHAR', message);
156
153
  }
157
154
  length += token.source.length;
158
155
  comment = token.source.substring(1);
159
156
  break;
160
157
  case 'error':
161
- onError(offset + length, token.message);
158
+ onError(token, 'UNEXPECTED_TOKEN', token.message);
162
159
  length += token.source.length;
163
160
  break;
164
161
  /* istanbul ignore next should not happen */
165
162
  default: {
166
163
  const message = `Unexpected token in block scalar header: ${token.type}`;
167
- onError(offset + length, message);
164
+ onError(token, 'UNEXPECTED_TOKEN', message);
168
165
  const ts = token.source;
169
166
  if (ts && typeof ts === 'string')
170
167
  length += ts.length;
@@ -1,20 +1,24 @@
1
1
  import { YAMLSeq } from '../nodes/YAMLSeq.js';
2
2
  import { resolveProps } from './resolve-props.js';
3
3
 
4
- function resolveBlockSeq({ composeNode, composeEmptyNode }, doc, { items, offset }, anchor, onError) {
5
- const start = offset;
6
- const seq = new YAMLSeq(doc.schema);
7
- if (anchor)
8
- doc.anchors.setAnchor(seq, anchor);
9
- for (const { start, value } of items) {
10
- const props = resolveProps(doc, start, true, 'seq-item-ind', offset, onError);
11
- offset += props.length;
4
+ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
5
+ const seq = new YAMLSeq(ctx.schema);
6
+ let offset = bs.offset;
7
+ for (const { start, value } of bs.items) {
8
+ const props = resolveProps(start, {
9
+ indicator: 'seq-item-ind',
10
+ next: value,
11
+ offset,
12
+ onError,
13
+ startOnNewline: true
14
+ });
15
+ offset = props.end;
12
16
  if (!props.found) {
13
- if (props.anchor || props.tagName || value) {
14
- const msg = value && value.type === 'block-seq'
15
- ? 'All sequence items must start at the same column'
16
- : 'Sequence item without - indicator';
17
- onError(offset, msg);
17
+ if (props.anchor || props.tag || value) {
18
+ if (value && value.type === 'block-seq')
19
+ onError(offset, 'BAD_INDENT', 'All sequence items must start at the same column');
20
+ else
21
+ onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
18
22
  }
19
23
  else {
20
24
  // TODO: assert being at last item?
@@ -24,12 +28,12 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, doc, { items, offset
24
28
  }
25
29
  }
26
30
  const node = value
27
- ? composeNode(doc, value, props, onError)
28
- : composeEmptyNode(doc, offset, start, null, props, onError);
29
- offset = node.range[1];
31
+ ? composeNode(ctx, value, props, onError)
32
+ : composeEmptyNode(ctx, offset, start, null, props, onError);
33
+ offset = node.range[2];
30
34
  seq.items.push(node);
31
35
  }
32
- seq.range = [start, offset];
36
+ seq.range = [bs.offset, offset, offset];
33
37
  return seq;
34
38
  }
35
39
 
@@ -2,32 +2,31 @@ function resolveEnd(end, offset, reqSpace, onError) {
2
2
  let comment = '';
3
3
  if (end) {
4
4
  let hasSpace = false;
5
- let hasComment = false;
6
5
  let sep = '';
7
- for (const { source, type } of end) {
6
+ for (const token of end) {
7
+ const { source, type } = token;
8
8
  switch (type) {
9
9
  case 'space':
10
10
  hasSpace = true;
11
11
  break;
12
12
  case 'comment': {
13
13
  if (reqSpace && !hasSpace)
14
- onError(offset, 'Comments must be separated from other tokens by white space characters');
15
- const cb = source.substring(1);
16
- if (!hasComment)
14
+ onError(token, 'MISSING_CHAR', 'Comments must be separated from other tokens by white space characters');
15
+ const cb = source.substring(1) || ' ';
16
+ if (!comment)
17
17
  comment = cb;
18
18
  else
19
19
  comment += sep + cb;
20
- hasComment = true;
21
20
  sep = '';
22
21
  break;
23
22
  }
24
23
  case 'newline':
25
- if (hasComment)
24
+ if (comment)
26
25
  sep += source;
27
26
  hasSpace = true;
28
27
  break;
29
28
  default:
30
- onError(offset, `Unexpected ${type} at node end`);
29
+ onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${type} at node end`);
31
30
  }
32
31
  offset += source.length;
33
32
  }