yaml 2.0.0-10 → 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 (112) hide show
  1. package/browser/dist/compose/compose-doc.js +1 -2
  2. package/browser/dist/compose/compose-node.js +1 -10
  3. package/browser/dist/compose/compose-scalar.js +10 -17
  4. package/browser/dist/compose/composer.js +2 -3
  5. package/browser/dist/compose/resolve-block-map.js +5 -22
  6. package/browser/dist/compose/resolve-block-scalar.js +2 -2
  7. package/browser/dist/compose/resolve-block-seq.js +1 -6
  8. package/browser/dist/compose/resolve-end.js +2 -2
  9. package/browser/dist/compose/resolve-flow-collection.js +8 -24
  10. package/browser/dist/compose/resolve-flow-scalar.js +7 -19
  11. package/browser/dist/compose/resolve-props.js +7 -32
  12. package/browser/dist/doc/Document.js +12 -58
  13. package/browser/dist/doc/createNode.js +5 -11
  14. package/browser/dist/doc/directives.js +0 -5
  15. package/browser/dist/nodes/Collection.js +15 -28
  16. package/browser/dist/nodes/Node.js +0 -7
  17. package/browser/dist/nodes/Pair.js +1 -9
  18. package/browser/dist/nodes/YAMLMap.js +1 -1
  19. package/browser/dist/nodes/YAMLSeq.js +1 -1
  20. package/browser/dist/nodes/addPairToJSMap.js +3 -4
  21. package/browser/dist/options.js +0 -2
  22. package/browser/dist/parse/cst-scalar.js +6 -2
  23. package/browser/dist/parse/lexer.js +31 -67
  24. package/browser/dist/parse/parser.js +55 -62
  25. package/browser/dist/public-api.js +4 -2
  26. package/browser/dist/schema/Schema.js +3 -14
  27. package/browser/dist/schema/core/float.js +1 -4
  28. package/browser/dist/schema/tags.js +13 -17
  29. package/browser/dist/schema/yaml-1.1/float.js +1 -4
  30. package/browser/dist/stringify/addComment.js +11 -0
  31. package/browser/dist/stringify/stringify.js +17 -47
  32. package/browser/dist/stringify/stringifyCollection.js +72 -116
  33. package/browser/dist/stringify/stringifyDocument.js +9 -16
  34. package/browser/dist/stringify/stringifyPair.js +20 -29
  35. package/browser/dist/stringify/stringifyString.js +41 -39
  36. package/browser/dist/util.js +0 -3
  37. package/dist/compose/compose-doc.js +1 -2
  38. package/dist/compose/compose-node.d.ts +0 -1
  39. package/dist/compose/compose-node.js +1 -10
  40. package/dist/compose/compose-scalar.js +9 -16
  41. package/dist/compose/composer.js +2 -3
  42. package/dist/compose/resolve-block-map.d.ts +1 -2
  43. package/dist/compose/resolve-block-map.js +5 -22
  44. package/dist/compose/resolve-block-scalar.js +2 -2
  45. package/dist/compose/resolve-block-seq.js +1 -6
  46. package/dist/compose/resolve-end.js +2 -2
  47. package/dist/compose/resolve-flow-collection.js +8 -24
  48. package/dist/compose/resolve-flow-scalar.js +7 -19
  49. package/dist/compose/resolve-props.d.ts +4 -3
  50. package/dist/compose/resolve-props.js +7 -32
  51. package/dist/doc/Document.d.ts +5 -16
  52. package/dist/doc/Document.js +11 -57
  53. package/dist/doc/createNode.d.ts +1 -2
  54. package/dist/doc/createNode.js +4 -10
  55. package/dist/doc/directives.d.ts +0 -1
  56. package/dist/doc/directives.js +0 -5
  57. package/dist/errors.d.ts +1 -1
  58. package/dist/index.d.ts +2 -2
  59. package/dist/nodes/Alias.d.ts +3 -7
  60. package/dist/nodes/Collection.d.ts +4 -10
  61. package/dist/nodes/Collection.js +14 -27
  62. package/dist/nodes/Node.d.ts +3 -10
  63. package/dist/nodes/Node.js +0 -7
  64. package/dist/nodes/Pair.d.ts +2 -7
  65. package/dist/nodes/Pair.js +0 -8
  66. package/dist/nodes/Scalar.d.ts +0 -2
  67. package/dist/nodes/YAMLMap.d.ts +0 -2
  68. package/dist/nodes/YAMLMap.js +1 -1
  69. package/dist/nodes/YAMLSeq.d.ts +0 -2
  70. package/dist/nodes/YAMLSeq.js +1 -1
  71. package/dist/nodes/addPairToJSMap.js +2 -3
  72. package/dist/options.d.ts +6 -81
  73. package/dist/options.js +0 -2
  74. package/dist/parse/cst-scalar.d.ts +0 -6
  75. package/dist/parse/cst-scalar.js +6 -2
  76. package/dist/parse/lexer.d.ts +1 -3
  77. package/dist/parse/lexer.js +31 -67
  78. package/dist/parse/parser.d.ts +0 -1
  79. package/dist/parse/parser.js +55 -62
  80. package/dist/public-api.js +4 -2
  81. package/dist/schema/Schema.d.ts +4 -6
  82. package/dist/schema/Schema.js +2 -13
  83. package/dist/schema/core/float.js +1 -4
  84. package/dist/schema/tags.d.ts +2 -1
  85. package/dist/schema/tags.js +13 -17
  86. package/dist/schema/yaml-1.1/float.js +1 -4
  87. package/dist/stringify/addComment.d.ts +2 -0
  88. package/dist/stringify/addComment.js +13 -0
  89. package/dist/stringify/stringify.d.ts +3 -5
  90. package/dist/stringify/stringify.js +17 -47
  91. package/dist/stringify/stringifyCollection.d.ts +7 -3
  92. package/dist/stringify/stringifyCollection.js +72 -116
  93. package/dist/stringify/stringifyDocument.js +9 -16
  94. package/dist/stringify/stringifyPair.js +20 -29
  95. package/dist/stringify/stringifyString.js +41 -39
  96. package/dist/test-events.d.ts +1 -1
  97. package/dist/test-events.js +2 -4
  98. package/dist/util.d.ts +0 -3
  99. package/dist/util.js +0 -6
  100. package/package.json +12 -14
  101. package/browser/dist/compose/util-flow-indent-check.js +0 -15
  102. package/browser/dist/compose/util-map-includes.js +0 -17
  103. package/browser/dist/node_modules/tslib/tslib.es6.js +0 -164
  104. package/browser/dist/stringify/stringifyComment.js +0 -18
  105. package/dist/compose/util-flow-indent-check.d.ts +0 -3
  106. package/dist/compose/util-flow-indent-check.js +0 -17
  107. package/dist/compose/util-map-includes.d.ts +0 -4
  108. package/dist/compose/util-map-includes.js +0 -19
  109. package/dist/node_modules/tslib/tslib.es6.js +0 -76
  110. package/dist/stringify/stringifyComment.d.ts +0 -10
  111. package/dist/stringify/stringifyComment.js +0 -22
  112. package/util.d.ts +0 -3
@@ -118,50 +118,34 @@ function doubleQuotedString(value, ctx) {
118
118
  : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
119
119
  }
120
120
  function singleQuotedString(value, ctx) {
121
- if (ctx.options.singleQuote === false ||
122
- (ctx.implicitKey && value.includes('\n')) ||
123
- /[ \t]\n|\n[ \t]/.test(value) // single quoted string can't have leading or trailing whitespace around newline
124
- )
125
- return doubleQuotedString(value, ctx);
121
+ if (ctx.implicitKey) {
122
+ if (/\n/.test(value))
123
+ return doubleQuotedString(value, ctx);
124
+ }
125
+ else {
126
+ // single quoted string can't have leading or trailing whitespace around newline
127
+ if (/[ \t]\n|\n[ \t]/.test(value))
128
+ return doubleQuotedString(value, ctx);
129
+ }
126
130
  const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
127
131
  const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
128
132
  return ctx.implicitKey
129
133
  ? res
130
134
  : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
131
135
  }
132
- function quotedString(value, ctx) {
133
- const { singleQuote } = ctx.options;
134
- let qs;
135
- if (singleQuote === false)
136
- qs = doubleQuotedString;
137
- else {
138
- const hasDouble = value.includes('"');
139
- const hasSingle = value.includes("'");
140
- if (hasDouble && !hasSingle)
141
- qs = singleQuotedString;
142
- else if (hasSingle && !hasDouble)
143
- qs = doubleQuotedString;
144
- else
145
- qs = singleQuote ? singleQuotedString : doubleQuotedString;
146
- }
147
- return qs(value, ctx);
148
- }
149
136
  function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
150
- const { blockQuote, commentString, lineWidth } = ctx.options;
151
137
  // 1. Block can't end in whitespace unless the last line is non-empty.
152
138
  // 2. Strings consisting of only whitespace are best rendered explicitly.
153
- if (!blockQuote || /\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
154
- return quotedString(value, ctx);
139
+ if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
140
+ return doubleQuotedString(value, ctx);
155
141
  }
156
142
  const indent = ctx.indent ||
157
143
  (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');
158
- const literal = blockQuote === 'literal'
159
- ? true
160
- : blockQuote === 'folded' || type === Scalar.BLOCK_FOLDED
161
- ? false
162
- : type === Scalar.BLOCK_LITERAL
163
- ? true
164
- : !lineLengthOverLimit(value, lineWidth, indent.length);
144
+ const literal = type === Scalar.BLOCK_FOLDED
145
+ ? false
146
+ : type === Scalar.BLOCK_LITERAL
147
+ ? true
148
+ : !lineLengthOverLimit(value, ctx.options.lineWidth, indent.length);
165
149
  if (!value)
166
150
  return literal ? '|\n' : '>\n';
167
151
  // determine chomping from whitespace at value end
@@ -212,7 +196,7 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
212
196
  const indentSize = indent ? '2' : '1'; // root is at -1
213
197
  let header = (literal ? '|' : '>') + (startWithSpace ? indentSize : '') + chomp;
214
198
  if (comment) {
215
- header += ' ' + commentString(comment.replace(/ ?[\r\n]+/g, ' '));
199
+ header += ' #' + comment.replace(/ ?[\r\n]+/g, ' ');
216
200
  if (onComment)
217
201
  onComment();
218
202
  }
@@ -229,14 +213,30 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
229
213
  return `${header}\n${indent}${body}`;
230
214
  }
231
215
  function plainString(item, ctx, onComment, onChompKeep) {
216
+ var _a;
232
217
  const { type, value } = item;
233
218
  const { actualString, implicitKey, indent, inFlow } = ctx;
234
219
  if ((implicitKey && /[\n[\]{},]/.test(value)) ||
235
220
  (inFlow && /[[\]{},]/.test(value))) {
236
- return quotedString(value, ctx);
221
+ return doubleQuotedString(value, ctx);
237
222
  }
238
223
  if (!value ||
239
224
  /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
225
+ const hasDouble = value.indexOf('"') !== -1;
226
+ const hasSingle = value.indexOf("'") !== -1;
227
+ let quotedString;
228
+ if (hasDouble && !hasSingle) {
229
+ quotedString = singleQuotedString;
230
+ }
231
+ else if (hasSingle && !hasDouble) {
232
+ quotedString = doubleQuotedString;
233
+ }
234
+ else if (ctx.options.singleQuote) {
235
+ quotedString = singleQuotedString;
236
+ }
237
+ else {
238
+ quotedString = doubleQuotedString;
239
+ }
240
240
  // not allowed:
241
241
  // - empty string, '-' or '?'
242
242
  // - start with an indicator character (except [?:-]) or /[?-] /
@@ -263,10 +263,12 @@ function plainString(item, ctx, onComment, onChompKeep) {
263
263
  // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
264
264
  // and others in v1.1.
265
265
  if (actualString) {
266
- const test = (tag) => { var _a; return tag.default && tag.tag !== 'tag:yaml.org,2002:str' && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(str)); };
267
- const { compat, tags } = ctx.doc.schema;
268
- if (tags.some(test) || (compat === null || compat === void 0 ? void 0 : compat.some(test)))
269
- return quotedString(value, ctx);
266
+ for (const tag of ctx.doc.schema.tags) {
267
+ if (tag.default &&
268
+ tag.tag !== 'tag:yaml.org,2002:str' &&
269
+ ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(str)))
270
+ return doubleQuotedString(value, ctx);
271
+ }
270
272
  }
271
273
  return implicitKey
272
274
  ? str
@@ -288,7 +290,7 @@ function stringifyString(item, ctx, onComment, onChompKeep) {
288
290
  case Scalar.BLOCK_FOLDED:
289
291
  case Scalar.BLOCK_LITERAL:
290
292
  return implicitKey || inFlow
291
- ? quotedString(ss.value, ctx) // blocks are not valid inside flow containers
293
+ ? doubleQuotedString(ss.value, ctx) // blocks are not valid inside flow containers
292
294
  : blockString(ss, ctx, onComment, onChompKeep);
293
295
  case Scalar.QUOTE_DOUBLE:
294
296
  return doubleQuotedString(ss.value, ctx);
@@ -1,9 +1,6 @@
1
1
  export { debug, warn } from './log.js';
2
2
  export { findPair } from './nodes/YAMLMap.js';
3
3
  export { toJS } from './nodes/toJS.js';
4
- export { map as mapTag } from './schema/common/map.js';
5
- export { seq as seqTag } from './schema/common/seq.js';
6
- export { string as stringTag } from './schema/common/string.js';
7
4
  export { foldFlowLines } from './stringify/foldFlowLines.js';
8
5
  export { stringifyNumber } from './stringify/stringifyNumber.js';
9
6
  export { stringifyString } from './stringify/stringifyString.js';
@@ -9,14 +9,13 @@ function composeDoc(options, directives, { offset, start, value, end }, onError)
9
9
  const opts = Object.assign({ directives }, options);
10
10
  const doc = new Document.Document(undefined, opts);
11
11
  const ctx = {
12
- atRoot: true,
13
12
  directives: doc.directives,
14
13
  options: doc.options,
15
14
  schema: doc.schema
16
15
  };
17
16
  const props = resolveProps.resolveProps(start, {
17
+ ctx,
18
18
  indicator: 'doc-start',
19
- next: value || (end === null || end === void 0 ? void 0 : end[0]),
20
19
  offset,
21
20
  onError,
22
21
  startOnNewline: true
@@ -5,7 +5,6 @@ import type { SourceToken, Token } from '../parse/cst.js';
5
5
  import type { Schema } from '../schema/Schema.js';
6
6
  import type { ComposeErrorHandler } from './composer.js';
7
7
  export interface ComposeContext {
8
- atRoot: boolean;
9
8
  directives: Directives;
10
9
  options: Readonly<Required<Omit<ParseOptions, 'lineCounter'>>>;
11
10
  schema: Readonly<Schema>;
@@ -35,8 +35,6 @@ function composeNode(ctx, token, props, onError) {
35
35
  console.log(token);
36
36
  throw new Error(`Unsupporten token type: ${token.type}`);
37
37
  }
38
- if (anchor && node.anchor === '')
39
- onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
40
38
  if (spaceBefore)
41
39
  node.spaceBefore = true;
42
40
  if (comment) {
@@ -45,8 +43,6 @@ function composeNode(ctx, token, props, onError) {
45
43
  else
46
44
  node.commentBefore = comment;
47
45
  }
48
- if (ctx.options.keepSourceTokens)
49
- node.srcToken = token;
50
46
  return node;
51
47
  }
52
48
  function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anchor, tag }, onError) {
@@ -57,11 +53,8 @@ function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anch
57
53
  source: ''
58
54
  };
59
55
  const node = composeScalar.composeScalar(ctx, token, tag, onError);
60
- if (anchor) {
56
+ if (anchor)
61
57
  node.anchor = anchor.source.substring(1);
62
- if (node.anchor === '')
63
- onError(anchor, 'BAD_ALIAS', 'Anchor cannot be an empty string');
64
- }
65
58
  if (spaceBefore)
66
59
  node.spaceBefore = true;
67
60
  if (comment)
@@ -70,8 +63,6 @@ function composeEmptyNode(ctx, offset, before, pos, { spaceBefore, comment, anch
70
63
  }
71
64
  function composeAlias({ options }, { offset, source, end }, onError) {
72
65
  const alias = new Alias.Alias(source.substring(1));
73
- if (alias.source === '')
74
- onError(offset, 'BAD_ALIAS', 'Alias cannot be an empty string');
75
66
  const valueEnd = offset + source.length;
76
67
  const re = resolveEnd.resolveEnd(end, valueEnd, options.strict, onError);
77
68
  alias.range = [offset, valueEnd, re.offset];
@@ -14,17 +14,14 @@ function composeScalar(ctx, token, tagToken, onError) {
14
14
  : null;
15
15
  const tag = tagToken && tagName
16
16
  ? findScalarTagByName(ctx.schema, value, tagName, tagToken, onError)
17
- : token.type === 'scalar'
18
- ? findScalarTagByTest(ctx, value, token, onError)
19
- : ctx.schema[Node.SCALAR];
17
+ : findScalarTagByTest(ctx.schema, value, token.type === 'scalar');
20
18
  let scalar;
21
19
  try {
22
20
  const res = tag.resolve(value, msg => onError(tagToken || token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
23
21
  scalar = Node.isScalar(res) ? res : new Scalar.Scalar(res);
24
22
  }
25
23
  catch (error) {
26
- const msg = error instanceof Error ? error.message : String(error);
27
- onError(tagToken || token, 'TAG_RESOLVE_FAILED', msg);
24
+ onError(tagToken || token, 'TAG_RESOLVE_FAILED', error.message);
28
25
  scalar = new Scalar.Scalar(value);
29
26
  }
30
27
  scalar.range = range;
@@ -65,19 +62,15 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
65
62
  onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, tagName !== 'tag:yaml.org,2002:str');
66
63
  return schema[Node.SCALAR];
67
64
  }
68
- function findScalarTagByTest({ directives, schema }, value, token, onError) {
69
- const tag = schema.tags.find(tag => { var _a; return tag.default && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value)); }) || schema[Node.SCALAR];
70
- if (schema.compat) {
71
- const compat = schema.compat.find(tag => { var _a; return tag.default && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value)); }) ||
72
- schema[Node.SCALAR];
73
- if (tag.tag !== compat.tag) {
74
- const ts = directives.tagString(tag.tag);
75
- const cs = directives.tagString(compat.tag);
76
- const msg = `Value may be parsed as either ${ts} or ${cs}`;
77
- onError(token, 'TAG_RESOLVE_FAILED', msg, true);
65
+ function findScalarTagByTest(schema, value, apply) {
66
+ var _a;
67
+ if (apply) {
68
+ for (const tag of schema.tags) {
69
+ if (tag.default && ((_a = tag.test) === null || _a === void 0 ? void 0 : _a.test(value)))
70
+ return tag;
78
71
  }
79
72
  }
80
- return tag;
73
+ return schema[Node.SCALAR];
81
74
  }
82
75
 
83
76
  exports.composeScalar = composeScalar;
@@ -17,7 +17,6 @@ function getErrorPos(src) {
17
17
  return [offset, offset + (typeof source === 'string' ? source.length : 1)];
18
18
  }
19
19
  function parsePrelude(prelude) {
20
- var _a;
21
20
  let comment = '';
22
21
  let atComment = false;
23
22
  let afterEmptyLine = false;
@@ -27,12 +26,12 @@ function parsePrelude(prelude) {
27
26
  case '#':
28
27
  comment +=
29
28
  (comment === '' ? '' : afterEmptyLine ? '\n\n' : '\n') +
30
- (source.substring(1) || ' ');
29
+ source.substring(1);
31
30
  atComment = true;
32
31
  afterEmptyLine = false;
33
32
  break;
34
33
  case '%':
35
- if (((_a = prelude[i + 1]) === null || _a === void 0 ? void 0 : _a[0]) !== '#')
34
+ if (prelude[i + 1][0] !== '#')
36
35
  i += 1;
37
36
  atComment = false;
38
37
  break;
@@ -1,6 +1,5 @@
1
- import type { ParsedNode } from '../nodes/Node.js';
2
1
  import { YAMLMap } from '../nodes/YAMLMap.js';
3
2
  import type { BlockMap } from '../parse/cst.js';
4
3
  import type { ComposeContext, ComposeNode } from './compose-node.js';
5
4
  import type { ComposeErrorHandler } from './composer.js';
6
- export declare function resolveBlockMap({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bm: BlockMap, onError: ComposeErrorHandler): YAMLMap.Parsed<ParsedNode, ParsedNode | null>;
5
+ export declare function resolveBlockMap({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bm: BlockMap, onError: ComposeErrorHandler): YAMLMap.Parsed<import("../index.js").ParsedNode, import("../index.js").ParsedNode | null>;
@@ -4,22 +4,17 @@ var Pair = require('../nodes/Pair.js');
4
4
  var YAMLMap = require('../nodes/YAMLMap.js');
5
5
  var resolveProps = require('./resolve-props.js');
6
6
  var utilContainsNewline = require('./util-contains-newline.js');
7
- var utilFlowIndentCheck = require('./util-flow-indent-check.js');
8
- var utilMapIncludes = require('./util-map-includes.js');
9
7
 
10
8
  const startColMsg = 'All mapping items must start at the same column';
11
9
  function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
12
10
  var _a;
13
11
  const map = new YAMLMap.YAMLMap(ctx.schema);
14
- if (ctx.atRoot)
15
- ctx.atRoot = false;
16
12
  let offset = bm.offset;
17
- for (const collItem of bm.items) {
18
- const { start, key, sep, value } = collItem;
13
+ for (const { start, key, sep, value } of bm.items) {
19
14
  // key properties
20
15
  const keyProps = resolveProps.resolveProps(start, {
16
+ ctx,
21
17
  indicator: 'explicit-key-ind',
22
- next: key || (sep === null || sep === void 0 ? void 0 : sep[0]),
23
18
  offset,
24
19
  onError,
25
20
  startOnNewline: true
@@ -53,14 +48,10 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
53
48
  const keyNode = key
54
49
  ? composeNode(ctx, key, keyProps, onError)
55
50
  : composeEmptyNode(ctx, keyStart, start, null, keyProps, onError);
56
- if (ctx.schema.compat)
57
- utilFlowIndentCheck.flowIndentCheck(bm.indent, key, onError);
58
- if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
59
- onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
60
51
  // value properties
61
52
  const valueProps = resolveProps.resolveProps(sep || [], {
53
+ ctx,
62
54
  indicator: 'map-value-ind',
63
- next: value,
64
55
  offset: keyNode.range[2],
65
56
  onError,
66
57
  startOnNewline: !key || key.type === 'block-scalar'
@@ -78,13 +69,8 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
78
69
  const valueNode = value
79
70
  ? composeNode(ctx, value, valueProps, onError)
80
71
  : composeEmptyNode(ctx, offset, sep, null, valueProps, onError);
81
- if (ctx.schema.compat)
82
- utilFlowIndentCheck.flowIndentCheck(bm.indent, value, onError);
83
72
  offset = valueNode.range[2];
84
- const pair = new Pair.Pair(keyNode, valueNode);
85
- if (ctx.options.keepSourceTokens)
86
- pair.srcToken = collItem;
87
- map.items.push(pair);
73
+ map.items.push(new Pair.Pair(keyNode, valueNode));
88
74
  }
89
75
  else {
90
76
  // key with no value
@@ -96,10 +82,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
96
82
  else
97
83
  keyNode.comment = valueProps.comment;
98
84
  }
99
- const pair = new Pair.Pair(keyNode);
100
- if (ctx.options.keepSourceTokens)
101
- pair.srcToken = collItem;
102
- map.items.push(pair);
85
+ map.items.push(new Pair.Pair(keyNode));
103
86
  }
104
87
  }
105
88
  map.range = [bm.offset, offset, offset];
@@ -20,7 +20,7 @@ function resolveBlockScalar(scalar, strict, onError) {
20
20
  }
21
21
  // shortcut for empty contents
22
22
  if (!scalar.source || chompStart === 0) {
23
- const value = header.chomp === '+' ? '\n'.repeat(Math.max(0, lines.length - 1)) : '';
23
+ const value = header.chomp === '+' ? lines.map(line => line[0]).join('\n') : '';
24
24
  let end = start + header.length;
25
25
  if (scalar.source)
26
26
  end += scalar.source.length;
@@ -151,7 +151,7 @@ function parseBlockScalarHeader({ offset, props }, strict, onError) {
151
151
  case 'comment':
152
152
  if (strict && !hasSpace) {
153
153
  const message = 'Comments must be separated from other tokens by white space characters';
154
- onError(token, 'MISSING_CHAR', message);
154
+ onError(token, 'COMMENT_SPACE', message);
155
155
  }
156
156
  length += token.source.length;
157
157
  comment = token.source.substring(1);
@@ -2,17 +2,14 @@
2
2
 
3
3
  var YAMLSeq = require('../nodes/YAMLSeq.js');
4
4
  var resolveProps = require('./resolve-props.js');
5
- var utilFlowIndentCheck = require('./util-flow-indent-check.js');
6
5
 
7
6
  function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
8
7
  const seq = new YAMLSeq.YAMLSeq(ctx.schema);
9
- if (ctx.atRoot)
10
- ctx.atRoot = false;
11
8
  let offset = bs.offset;
12
9
  for (const { start, value } of bs.items) {
13
10
  const props = resolveProps.resolveProps(start, {
11
+ ctx,
14
12
  indicator: 'seq-item-ind',
15
- next: value,
16
13
  offset,
17
14
  onError,
18
15
  startOnNewline: true
@@ -35,8 +32,6 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError) {
35
32
  const node = value
36
33
  ? composeNode(ctx, value, props, onError)
37
34
  : composeEmptyNode(ctx, offset, start, null, props, onError);
38
- if (ctx.schema.compat)
39
- utilFlowIndentCheck.flowIndentCheck(bs.indent, value, onError);
40
35
  offset = node.range[2];
41
36
  seq.items.push(node);
42
37
  }
@@ -13,8 +13,8 @@ function resolveEnd(end, offset, reqSpace, onError) {
13
13
  break;
14
14
  case 'comment': {
15
15
  if (reqSpace && !hasSpace)
16
- onError(token, 'MISSING_CHAR', 'Comments must be separated from other tokens by white space characters');
17
- const cb = source.substring(1) || ' ';
16
+ onError(token, 'COMMENT_SPACE', 'Comments must be separated from other tokens by white space characters');
17
+ const cb = source.substring(1);
18
18
  if (!comment)
19
19
  comment = cb;
20
20
  else
@@ -7,7 +7,6 @@ var YAMLSeq = require('../nodes/YAMLSeq.js');
7
7
  var resolveEnd = require('./resolve-end.js');
8
8
  var resolveProps = require('./resolve-props.js');
9
9
  var utilContainsNewline = require('./util-contains-newline.js');
10
- var utilMapIncludes = require('./util-map-includes.js');
11
10
 
12
11
  const blockMsg = 'Block collections are not allowed within flow collections';
13
12
  const isBlock = (token) => token && (token.type === 'block-map' || token.type === 'block-seq');
@@ -18,17 +17,13 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
18
17
  ? new YAMLMap.YAMLMap(ctx.schema)
19
18
  : new YAMLSeq.YAMLSeq(ctx.schema);
20
19
  coll.flow = true;
21
- const atRoot = ctx.atRoot;
22
- if (atRoot)
23
- ctx.atRoot = false;
24
- let offset = fc.offset + fc.start.source.length;
20
+ let offset = fc.offset;
25
21
  for (let i = 0; i < fc.items.length; ++i) {
26
- const collItem = fc.items[i];
27
- const { start, key, sep, value } = collItem;
22
+ const { start, key, sep, value } = fc.items[i];
28
23
  const props = resolveProps.resolveProps(start, {
24
+ ctx,
29
25
  flow: fcName,
30
26
  indicator: 'explicit-key-ind',
31
- next: key || (sep === null || sep === void 0 ? void 0 : sep[0]),
32
27
  offset,
33
28
  onError,
34
29
  startOnNewline: false
@@ -45,7 +40,6 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
45
40
  else
46
41
  coll.comment = props.comment;
47
42
  }
48
- offset = props.end;
49
43
  continue;
50
44
  }
51
45
  if (!isMap && ctx.options.strict && utilContainsNewline.containsNewline(key))
@@ -107,9 +101,9 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
107
101
  onError(keyNode.range, 'BLOCK_IN_FLOW', blockMsg);
108
102
  // value properties
109
103
  const valueProps = resolveProps.resolveProps(sep || [], {
104
+ ctx,
110
105
  flow: fcName,
111
106
  indicator: 'map-value-ind',
112
- next: value,
113
107
  offset: keyNode.range[2],
114
108
  onError,
115
109
  startOnNewline: false
@@ -152,14 +146,8 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
152
146
  keyNode.comment = valueProps.comment;
153
147
  }
154
148
  const pair = new Pair.Pair(keyNode, valueNode);
155
- if (ctx.options.keepSourceTokens)
156
- pair.srcToken = collItem;
157
- if (isMap) {
158
- const map = coll;
159
- if (utilMapIncludes.mapIncludes(ctx, map.items, keyNode))
160
- onError(keyStart, 'DUPLICATE_KEY', 'Map keys must be unique');
161
- map.items.push(pair);
162
- }
149
+ if (isMap)
150
+ coll.items.push(pair);
163
151
  else {
164
152
  const map = new YAMLMap.YAMLMap(ctx.schema);
165
153
  map.flow = true;
@@ -173,13 +161,9 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
173
161
  const [ce, ...ee] = fc.end;
174
162
  let cePos = offset;
175
163
  if (ce && ce.source === expectedEnd)
176
- cePos = ce.offset + ce.source.length;
164
+ cePos += ce.source.length;
177
165
  else {
178
- const name = fcName[0].toUpperCase() + fcName.substring(1);
179
- const msg = atRoot
180
- ? `${name} must end with a ${expectedEnd}`
181
- : `${name} in block collection must be sufficiently indented and end with a ${expectedEnd}`;
182
- onError(offset, atRoot ? 'MISSING_CHAR' : 'BAD_INDENT', msg);
166
+ onError(offset + 1, 'MISSING_CHAR', `Expected ${fcName} to end with ${expectedEnd}`);
183
167
  if (ce && ce.source.length !== 1)
184
168
  ee.unshift(ce);
185
169
  }
@@ -41,31 +41,25 @@ function resolveFlowScalar(scalar, strict, onError) {
41
41
  };
42
42
  }
43
43
  function plainValue(source, onError) {
44
- let badChar = '';
44
+ let message = '';
45
45
  switch (source[0]) {
46
46
  /* istanbul ignore next should not happen */
47
47
  case '\t':
48
- badChar = 'a tab character';
49
- break;
50
- case ',':
51
- badChar = 'flow indicator character ,';
52
- break;
53
- case '%':
54
- badChar = 'directive indicator character %';
48
+ message = 'Plain value cannot start with a tab character';
55
49
  break;
56
50
  case '|':
57
51
  case '>': {
58
- badChar = `block scalar indicator ${source[0]}`;
52
+ message = `Plain value cannot start with block scalar indicator ${source[0]}`;
59
53
  break;
60
54
  }
61
55
  case '@':
62
56
  case '`': {
63
- badChar = `reserved character ${source[0]}`;
57
+ message = `Plain value cannot start with reserved character ${source[0]}`;
64
58
  break;
65
59
  }
66
60
  }
67
- if (badChar)
68
- onError(0, 'BAD_SCALAR_START', `Plain value cannot start with ${badChar}`);
61
+ if (message)
62
+ onError(0, 'BAD_SCALAR_START', message);
69
63
  return foldLines(source);
70
64
  }
71
65
  function singleQuotedValue(source, onError) {
@@ -137,12 +131,6 @@ function doubleQuotedValue(source, onError) {
137
131
  while (next === ' ' || next === '\t')
138
132
  next = source[++i + 1];
139
133
  }
140
- else if (next === '\r' && source[i + 1] === '\n') {
141
- // skip escaped CRLF newlines, but still trim the following line
142
- next = source[++i + 1];
143
- while (next === ' ' || next === '\t')
144
- next = source[++i + 1];
145
- }
146
134
  else if (next === 'x' || next === 'u' || next === 'U') {
147
135
  const length = { x: 2, u: 4, U: 8 }[next];
148
136
  res += parseCharCode(source, i + 1, length, onError);
@@ -160,7 +148,7 @@ function doubleQuotedValue(source, onError) {
160
148
  let next = source[i + 1];
161
149
  while (next === ' ' || next === '\t')
162
150
  next = source[++i + 1];
163
- if (next !== '\n' && !(next === '\r' && source[i + 2] === '\n'))
151
+ if (next !== '\n')
164
152
  res += i > wsStart ? source.slice(wsStart, i + 1) : ch;
165
153
  }
166
154
  else {
@@ -1,14 +1,15 @@
1
- import type { SourceToken, Token } from '../parse/cst.js';
1
+ import type { SourceToken } from '../parse/cst.js';
2
+ import type { ComposeContext } from './compose-node.js';
2
3
  import type { ComposeErrorHandler } from './composer.js';
3
4
  export interface ResolvePropsArg {
5
+ ctx: ComposeContext;
4
6
  flow?: string;
5
7
  indicator: 'doc-start' | 'explicit-key-ind' | 'map-value-ind' | 'seq-item-ind';
6
- next: Token | null | undefined;
7
8
  offset: number;
8
9
  onError: ComposeErrorHandler;
9
10
  startOnNewline: boolean;
10
11
  }
11
- export declare function resolveProps(tokens: SourceToken[], { flow, indicator, next, offset, onError, startOnNewline }: ResolvePropsArg): {
12
+ export declare function resolveProps(tokens: SourceToken[], { ctx, flow, indicator, offset, onError, startOnNewline }: ResolvePropsArg): {
12
13
  comma: SourceToken | null;
13
14
  found: SourceToken | null;
14
15
  spaceBefore: boolean;