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
@@ -3,20 +3,24 @@
3
3
  var YAMLSeq = require('../nodes/YAMLSeq.js');
4
4
  var resolveProps = require('./resolve-props.js');
5
5
 
6
- function resolveBlockSeq({ composeNode, composeEmptyNode }, doc, { items, offset }, anchor, onError) {
7
- const start = offset;
8
- const seq = new YAMLSeq.YAMLSeq(doc.schema);
9
- if (anchor)
10
- doc.anchors.setAnchor(seq, anchor);
11
- for (const { start, value } of items) {
12
- const props = resolveProps.resolveProps(doc, start, true, 'seq-item-ind', offset, onError);
13
- offset += props.length;
6
+ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
7
+ const seq = new YAMLSeq.YAMLSeq(ctx.schema);
8
+ let offset = bs.offset;
9
+ for (const { start, value } of bs.items) {
10
+ const props = resolveProps.resolveProps(start, {
11
+ ctx,
12
+ indicator: 'seq-item-ind',
13
+ offset,
14
+ onError,
15
+ startOnNewline: true
16
+ });
17
+ offset = props.end;
14
18
  if (!props.found) {
15
- if (props.anchor || props.tagName || value) {
16
- const msg = value && value.type === 'block-seq'
17
- ? 'All sequence items must start at the same column'
18
- : 'Sequence item without - indicator';
19
- onError(offset, msg);
19
+ if (props.anchor || props.tag || value) {
20
+ if (value && value.type === 'block-seq')
21
+ onError(offset, 'BAD_INDENT', 'All sequence items must start at the same column');
22
+ else
23
+ onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
20
24
  }
21
25
  else {
22
26
  // TODO: assert being at last item?
@@ -26,12 +30,12 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, doc, { items, offset
26
30
  }
27
31
  }
28
32
  const node = value
29
- ? composeNode(doc, value, props, onError)
30
- : composeEmptyNode(doc, offset, start, null, props, onError);
31
- offset = node.range[1];
33
+ ? composeNode(ctx, value, props, onError)
34
+ : composeEmptyNode(ctx, offset, start, null, props, onError);
35
+ offset = node.range[2];
32
36
  seq.items.push(node);
33
37
  }
34
- seq.range = [start, offset];
38
+ seq.range = [bs.offset, offset, offset];
35
39
  return seq;
36
40
  }
37
41
 
@@ -1,5 +1,6 @@
1
- import type { SourceToken } from '../parse/tokens.js';
2
- export declare function resolveEnd(end: SourceToken[] | undefined, offset: number, reqSpace: boolean, onError: (offset: number, message: string) => void): {
1
+ import type { SourceToken } from '../parse/cst.js';
2
+ import type { ComposeErrorHandler } from './composer.js';
3
+ export declare function resolveEnd(end: SourceToken[] | undefined, offset: number, reqSpace: boolean, onError: ComposeErrorHandler): {
3
4
  comment: string;
4
5
  offset: number;
5
6
  };
@@ -4,32 +4,31 @@ function resolveEnd(end, offset, reqSpace, onError) {
4
4
  let comment = '';
5
5
  if (end) {
6
6
  let hasSpace = false;
7
- let hasComment = false;
8
7
  let sep = '';
9
- for (const { source, type } of end) {
8
+ for (const token of end) {
9
+ const { source, type } = token;
10
10
  switch (type) {
11
11
  case 'space':
12
12
  hasSpace = true;
13
13
  break;
14
14
  case 'comment': {
15
15
  if (reqSpace && !hasSpace)
16
- onError(offset, 'Comments must be separated from other tokens by white space characters');
16
+ onError(token, 'COMMENT_SPACE', 'Comments must be separated from other tokens by white space characters');
17
17
  const cb = source.substring(1);
18
- if (!hasComment)
18
+ if (!comment)
19
19
  comment = cb;
20
20
  else
21
21
  comment += sep + cb;
22
- hasComment = true;
23
22
  sep = '';
24
23
  break;
25
24
  }
26
25
  case 'newline':
27
- if (hasComment)
26
+ if (comment)
28
27
  sep += source;
29
28
  hasSpace = true;
30
29
  break;
31
30
  default:
32
- onError(offset, `Unexpected ${type} at node end`);
31
+ onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${type} at node end`);
33
32
  }
34
33
  offset += source.length;
35
34
  }
@@ -1,7 +1,6 @@
1
- import type { Document } from '../doc/Document.js';
2
- import { ParsedNode } from '../nodes/Node.js';
3
1
  import { YAMLMap } from '../nodes/YAMLMap.js';
4
2
  import { YAMLSeq } from '../nodes/YAMLSeq.js';
5
- import type { FlowCollection } from '../parse/tokens.js';
6
- import type { ComposeNode } from './compose-node.js';
7
- export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, doc: Document.Parsed, fc: FlowCollection, _anchor: string | null, onError: (offset: number, message: string, warning?: boolean) => void): YAMLMap.Parsed<ParsedNode, ParsedNode | null> | YAMLSeq.Parsed<ParsedNode>;
3
+ import type { FlowCollection } from '../parse/cst.js';
4
+ import type { ComposeContext, ComposeNode } from './compose-node.js';
5
+ import type { ComposeErrorHandler } from './composer.js';
6
+ export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler): YAMLMap.Parsed<import("../nodes/Node.js").ParsedNode, import("../nodes/Node.js").ParsedNode | null> | YAMLSeq.Parsed<import("../nodes/Node.js").ParsedNode>;
@@ -5,227 +5,181 @@ var Pair = require('../nodes/Pair.js');
5
5
  var YAMLMap = require('../nodes/YAMLMap.js');
6
6
  var YAMLSeq = require('../nodes/YAMLSeq.js');
7
7
  var resolveEnd = require('./resolve-end.js');
8
+ var resolveProps = require('./resolve-props.js');
8
9
  var utilContainsNewline = require('./util-contains-newline.js');
9
10
 
10
- function resolveFlowCollection({ composeNode, composeEmptyNode }, doc, fc, _anchor, onError) {
11
+ const blockMsg = 'Block collections are not allowed within flow collections';
12
+ const isBlock = (token) => token && (token.type === 'block-map' || token.type === 'block-seq');
13
+ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onError) {
11
14
  const isMap = fc.start.source === '{';
12
- const coll = isMap ? new YAMLMap.YAMLMap(doc.schema) : new YAMLSeq.YAMLSeq(doc.schema);
15
+ const fcName = isMap ? 'flow map' : 'flow sequence';
16
+ const coll = isMap
17
+ ? new YAMLMap.YAMLMap(ctx.schema)
18
+ : new YAMLSeq.YAMLSeq(ctx.schema);
13
19
  coll.flow = true;
14
- if (_anchor)
15
- doc.anchors.setAnchor(coll, _anchor);
16
- let key = null;
17
- let value = null;
18
- let spaceBefore = false;
19
- let comment = '';
20
- let hasSpace = false;
21
- let hasComment = false;
22
- let newlines = '';
23
- let anchor = '';
24
- let tagName = '';
25
- let offset = fc.offset + 1;
26
- let atLineStart = false;
27
- let atExplicitKey = false;
28
- let atValueEnd = false;
29
- let nlAfterValueInSeq = false;
30
- let seqKeyToken = null;
31
- function getProps() {
32
- const props = { spaceBefore, comment, anchor, tagName };
33
- spaceBefore = false;
34
- comment = '';
35
- hasComment = false;
36
- newlines = '';
37
- anchor = '';
38
- tagName = '';
39
- return props;
40
- }
41
- function addItem(pos) {
42
- if (value) {
43
- if (hasComment)
44
- value.comment = comment;
45
- }
46
- else {
47
- value = composeEmptyNode(doc, offset, fc.items, pos, getProps(), onError);
20
+ let offset = fc.offset;
21
+ for (let i = 0; i < fc.items.length; ++i) {
22
+ const { start, key, sep, value } = fc.items[i];
23
+ const props = resolveProps.resolveProps(start, {
24
+ ctx,
25
+ flow: fcName,
26
+ indicator: 'explicit-key-ind',
27
+ offset,
28
+ onError,
29
+ startOnNewline: false
30
+ });
31
+ if (!props.found) {
32
+ if (!props.anchor && !props.tag && !sep && !value) {
33
+ if (i === 0 && props.comma)
34
+ onError(props.comma, 'UNEXPECTED_TOKEN', `Unexpected , in ${fcName}`);
35
+ else if (i < fc.items.length - 1)
36
+ onError(props.start, 'UNEXPECTED_TOKEN', `Unexpected empty item in ${fcName}`);
37
+ if (props.comment) {
38
+ if (coll.comment)
39
+ coll.comment += '\n' + props.comment;
40
+ else
41
+ coll.comment = props.comment;
42
+ }
43
+ continue;
44
+ }
45
+ if (!isMap && ctx.options.strict && utilContainsNewline.containsNewline(key))
46
+ onError(key, // checked by containsNewline()
47
+ 'MULTILINE_IMPLICIT_KEY', 'Implicit keys of flow sequence pairs need to be on a single line');
48
48
  }
49
- if (isMap || atExplicitKey) {
50
- coll.items.push(key ? new Pair.Pair(key, value) : new Pair.Pair(value));
49
+ if (i === 0) {
50
+ if (props.comma)
51
+ onError(props.comma, 'UNEXPECTED_TOKEN', `Unexpected , in ${fcName}`);
51
52
  }
52
53
  else {
53
- const seq = coll;
54
- if (key) {
55
- const map = new YAMLMap.YAMLMap(doc.schema);
56
- map.flow = true;
57
- map.items.push(new Pair.Pair(key, value));
58
- seq.items.push(map);
59
- }
60
- else
61
- seq.items.push(value);
62
- }
63
- }
64
- for (let i = 0; i < fc.items.length; ++i) {
65
- const token = fc.items[i];
66
- let isSourceToken = true;
67
- switch (token.type) {
68
- case 'space':
69
- hasSpace = true;
70
- break;
71
- case 'comment': {
72
- if (doc.options.strict && !hasSpace)
73
- onError(offset, 'Comments must be separated from other tokens by white space characters');
74
- const cb = token.source.substring(1);
75
- if (!hasComment)
76
- comment = cb;
77
- else
78
- comment += newlines + cb;
79
- atLineStart = false;
80
- hasComment = true;
81
- newlines = '';
82
- break;
83
- }
84
- case 'newline':
85
- if (atLineStart && !hasComment)
86
- spaceBefore = true;
87
- if (atValueEnd) {
88
- if (hasComment) {
89
- let node = coll.items[coll.items.length - 1];
90
- if (Node.isPair(node))
91
- node = node.value || node.key;
92
- /* istanbul ignore else should not happen */
93
- if (Node.isNode(node))
94
- node.comment = comment;
95
- else
96
- onError(offset, 'Error adding trailing comment to node');
97
- comment = '';
98
- hasComment = false;
54
+ if (!props.comma)
55
+ onError(props.start, 'MISSING_CHAR', `Missing , between ${fcName} items`);
56
+ if (props.comment) {
57
+ let prevItemComment = '';
58
+ loop: for (const st of start) {
59
+ switch (st.type) {
60
+ case 'comma':
61
+ case 'space':
62
+ break;
63
+ case 'comment':
64
+ prevItemComment = st.source.substring(1);
65
+ break loop;
66
+ default:
67
+ break loop;
99
68
  }
100
- atValueEnd = false;
101
69
  }
102
- else {
103
- newlines += token.source;
104
- if (!isMap && !key && value)
105
- nlAfterValueInSeq = true;
70
+ if (prevItemComment) {
71
+ let prev = coll.items[coll.items.length - 1];
72
+ if (Node.isPair(prev))
73
+ prev = prev.value || prev.key;
74
+ if (prev.comment)
75
+ prev.comment += '\n' + prevItemComment;
76
+ else
77
+ prev.comment = prevItemComment;
78
+ props.comment = props.comment.substring(prevItemComment.length + 1);
106
79
  }
107
- atLineStart = true;
108
- hasSpace = true;
109
- break;
110
- case 'anchor':
111
- if (anchor)
112
- onError(offset, 'A node can have at most one anchor');
113
- anchor = token.source.substring(1);
114
- atLineStart = false;
115
- atValueEnd = false;
116
- hasSpace = false;
117
- break;
118
- case 'tag': {
119
- if (tagName)
120
- onError(offset, 'A node can have at most one tag');
121
- const tn = doc.directives.tagName(token.source, m => onError(offset, m));
122
- if (tn)
123
- tagName = tn;
124
- atLineStart = false;
125
- atValueEnd = false;
126
- hasSpace = false;
127
- break;
128
80
  }
129
- case 'explicit-key-ind':
130
- if (anchor || tagName)
131
- onError(offset, 'Anchors and tags must be after the ? indicator');
132
- atExplicitKey = true;
133
- atLineStart = false;
134
- atValueEnd = false;
135
- hasSpace = false;
136
- break;
137
- case 'map-value-ind': {
138
- if (key) {
139
- if (value) {
140
- onError(offset, 'Missing {} around pair used as mapping key');
141
- const map = new YAMLMap.YAMLMap(doc.schema);
142
- map.flow = true;
143
- map.items.push(new Pair.Pair(key, value));
144
- map.range = [key.range[0], value.range[1]];
145
- key = map;
146
- value = null;
147
- } // else explicit key
148
- }
149
- else if (value) {
150
- if (doc.options.strict) {
151
- const slMsg = 'Implicit keys of flow sequence pairs need to be on a single line';
152
- if (nlAfterValueInSeq)
153
- onError(offset, slMsg);
154
- else if (seqKeyToken) {
155
- if (utilContainsNewline.containsNewline(seqKeyToken))
156
- onError(offset, slMsg);
157
- const start = 'offset' in seqKeyToken && seqKeyToken.offset;
158
- if (typeof start === 'number' && start < offset - 1024)
159
- onError(offset, 'The : indicator must be at most 1024 chars after the start of an implicit flow sequence key');
160
- seqKeyToken = null;
81
+ }
82
+ if (!isMap && !sep && !props.found) {
83
+ // item is a value in a seq
84
+ // → key & sep are empty, start does not include ? or :
85
+ const valueNode = value
86
+ ? composeNode(ctx, value, props, onError)
87
+ : composeEmptyNode(ctx, props.end, sep, null, props, onError);
88
+ coll.items.push(valueNode);
89
+ offset = valueNode.range[2];
90
+ if (isBlock(value))
91
+ onError(valueNode.range, 'BLOCK_IN_FLOW', blockMsg);
92
+ }
93
+ else {
94
+ // item is a key+value pair
95
+ // key value
96
+ const keyStart = props.end;
97
+ const keyNode = key
98
+ ? composeNode(ctx, key, props, onError)
99
+ : composeEmptyNode(ctx, keyStart, start, null, props, onError);
100
+ if (isBlock(key))
101
+ onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
102
+ // value properties
103
+ const valueProps = resolveProps.resolveProps(sep || [], {
104
+ ctx,
105
+ flow: fcName,
106
+ indicator: 'map-value-ind',
107
+ offset: keyNode.range[2],
108
+ onError,
109
+ startOnNewline: false
110
+ });
111
+ if (valueProps.found) {
112
+ if (!isMap && !props.found && ctx.options.strict) {
113
+ if (sep)
114
+ for (const st of sep) {
115
+ if (st === valueProps.found)
116
+ break;
117
+ if (st.type === 'newline') {
118
+ onError(st, 'MULTILINE_IMPLICIT_KEY', 'Implicit keys of flow sequence pairs need to be on a single line');
119
+ break;
120
+ }
161
121
  }
162
- }
163
- key = value;
164
- value = null;
122
+ if (props.start < valueProps.found.offset - 1024)
123
+ onError(valueProps.found, 'KEY_OVER_1024_CHARS', 'The : indicator must be at most 1024 chars after the start of an implicit flow sequence key');
165
124
  }
166
- else {
167
- key = composeEmptyNode(doc, offset, fc.items, i, getProps(), onError);
168
- }
169
- if (hasComment) {
170
- key.comment = comment;
171
- comment = '';
172
- hasComment = false;
173
- }
174
- atExplicitKey = false;
175
- atValueEnd = false;
176
- hasSpace = false;
177
- break;
178
125
  }
179
- case 'comma':
180
- if (key || value || anchor || tagName || atExplicitKey)
181
- addItem(i);
126
+ else if (value) {
127
+ if ('source' in value && value.source && value.source[0] === ':')
128
+ onError(value, 'MISSING_CHAR', `Missing space after : in ${fcName}`);
129
+ else
130
+ onError(valueProps.start, 'MISSING_CHAR', `Missing , or : between ${fcName} items`);
131
+ }
132
+ // value value
133
+ const valueNode = value
134
+ ? composeNode(ctx, value, valueProps, onError)
135
+ : valueProps.found
136
+ ? composeEmptyNode(ctx, valueProps.end, sep, null, valueProps, onError)
137
+ : null;
138
+ if (valueNode) {
139
+ if (isBlock(value))
140
+ onError(valueNode.range, 'BLOCK_IN_FLOW', blockMsg);
141
+ }
142
+ else if (valueProps.comment) {
143
+ if (keyNode.comment)
144
+ keyNode.comment += '\n' + valueProps.comment;
182
145
  else
183
- onError(offset, `Unexpected , in flow ${isMap ? 'map' : 'sequence'}`);
184
- key = null;
185
- value = null;
186
- atExplicitKey = false;
187
- atValueEnd = true;
188
- hasSpace = false;
189
- nlAfterValueInSeq = false;
190
- seqKeyToken = null;
191
- break;
192
- case 'block-map':
193
- case 'block-seq':
194
- onError(offset, 'Block collections are not allowed within flow collections');
195
- // fallthrough
196
- default: {
197
- if (value)
198
- onError(offset, 'Missing , between flow collection items');
199
- if (!isMap && !key && !atExplicitKey)
200
- seqKeyToken = token;
201
- value = composeNode(doc, token, getProps(), onError);
202
- offset = value.range[1];
203
- atLineStart = false;
204
- isSourceToken = false;
205
- atValueEnd = false;
206
- hasSpace = false;
146
+ keyNode.comment = valueProps.comment;
147
+ }
148
+ const pair = new Pair.Pair(keyNode, valueNode);
149
+ if (isMap)
150
+ coll.items.push(pair);
151
+ else {
152
+ const map = new YAMLMap.YAMLMap(ctx.schema);
153
+ map.flow = true;
154
+ map.items.push(pair);
155
+ coll.items.push(map);
207
156
  }
157
+ offset = valueNode ? valueNode.range[2] : valueProps.end;
208
158
  }
209
- if (isSourceToken)
210
- offset += token.source.length;
211
159
  }
212
- if (key || value || anchor || tagName || atExplicitKey)
213
- addItem(fc.items.length);
214
160
  const expectedEnd = isMap ? '}' : ']';
215
161
  const [ce, ...ee] = fc.end;
216
- if (!ce || ce.source !== expectedEnd) {
217
- const cs = isMap ? 'map' : 'sequence';
218
- onError(offset, `Expected flow ${cs} to end with ${expectedEnd}`);
162
+ let cePos = offset;
163
+ if (ce && ce.source === expectedEnd)
164
+ cePos += ce.source.length;
165
+ else {
166
+ onError(offset + 1, 'MISSING_CHAR', `Expected ${fcName} to end with ${expectedEnd}`);
167
+ if (ce && ce.source.length !== 1)
168
+ ee.unshift(ce);
219
169
  }
220
- if (ce)
221
- offset += ce.source.length;
222
170
  if (ee.length > 0) {
223
- const end = resolveEnd.resolveEnd(ee, offset, doc.options.strict, onError);
224
- if (end.comment)
225
- coll.comment = comment;
226
- offset = end.offset;
171
+ const end = resolveEnd.resolveEnd(ee, cePos, ctx.options.strict, onError);
172
+ if (end.comment) {
173
+ if (coll.comment)
174
+ coll.comment += '\n' + end.comment;
175
+ else
176
+ coll.comment = end.comment;
177
+ }
178
+ coll.range = [fc.offset, cePos, end.offset];
179
+ }
180
+ else {
181
+ coll.range = [fc.offset, cePos, cePos];
227
182
  }
228
- coll.range = [fc.offset, offset];
229
183
  return coll;
230
184
  }
231
185
 
@@ -1,8 +1,10 @@
1
+ import { Range } from '../nodes/Node.js';
1
2
  import { Scalar } from '../nodes/Scalar.js';
2
- import type { FlowScalar } from '../parse/tokens.js';
3
- export declare function resolveFlowScalar({ offset, type, source, end }: FlowScalar, strict: boolean, onError: (offset: number, message: string) => void): {
3
+ import type { FlowScalar } from '../parse/cst.js';
4
+ import type { ComposeErrorHandler } from './composer.js';
5
+ export declare function resolveFlowScalar(scalar: FlowScalar, strict: boolean, onError: ComposeErrorHandler): {
4
6
  value: string;
5
7
  type: Scalar.PLAIN | Scalar.QUOTE_DOUBLE | Scalar.QUOTE_SINGLE | null;
6
8
  comment: string;
7
- length: number;
9
+ range: Range;
8
10
  };