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.
- package/browser/dist/compose/compose-doc.js +1 -2
- package/browser/dist/compose/compose-node.js +1 -10
- package/browser/dist/compose/compose-scalar.js +10 -17
- package/browser/dist/compose/composer.js +2 -3
- package/browser/dist/compose/resolve-block-map.js +5 -22
- package/browser/dist/compose/resolve-block-scalar.js +2 -2
- package/browser/dist/compose/resolve-block-seq.js +1 -6
- package/browser/dist/compose/resolve-end.js +2 -2
- package/browser/dist/compose/resolve-flow-collection.js +8 -24
- package/browser/dist/compose/resolve-flow-scalar.js +7 -19
- package/browser/dist/compose/resolve-props.js +7 -32
- package/browser/dist/doc/Document.js +12 -58
- package/browser/dist/doc/createNode.js +5 -11
- package/browser/dist/doc/directives.js +0 -5
- package/browser/dist/nodes/Collection.js +15 -28
- package/browser/dist/nodes/Node.js +0 -7
- package/browser/dist/nodes/Pair.js +1 -9
- package/browser/dist/nodes/YAMLMap.js +1 -1
- package/browser/dist/nodes/YAMLSeq.js +1 -1
- package/browser/dist/nodes/addPairToJSMap.js +3 -4
- package/browser/dist/options.js +0 -2
- package/browser/dist/parse/cst-scalar.js +6 -2
- package/browser/dist/parse/lexer.js +31 -67
- package/browser/dist/parse/parser.js +55 -62
- package/browser/dist/public-api.js +4 -2
- package/browser/dist/schema/Schema.js +3 -14
- package/browser/dist/schema/core/float.js +1 -4
- package/browser/dist/schema/tags.js +13 -17
- package/browser/dist/schema/yaml-1.1/float.js +1 -4
- package/browser/dist/stringify/addComment.js +11 -0
- package/browser/dist/stringify/stringify.js +17 -47
- package/browser/dist/stringify/stringifyCollection.js +72 -116
- package/browser/dist/stringify/stringifyDocument.js +9 -16
- package/browser/dist/stringify/stringifyPair.js +20 -29
- package/browser/dist/stringify/stringifyString.js +41 -39
- package/browser/dist/util.js +0 -3
- package/dist/compose/compose-doc.js +1 -2
- package/dist/compose/compose-node.d.ts +0 -1
- package/dist/compose/compose-node.js +1 -10
- package/dist/compose/compose-scalar.js +9 -16
- package/dist/compose/composer.js +2 -3
- package/dist/compose/resolve-block-map.d.ts +1 -2
- package/dist/compose/resolve-block-map.js +5 -22
- package/dist/compose/resolve-block-scalar.js +2 -2
- package/dist/compose/resolve-block-seq.js +1 -6
- package/dist/compose/resolve-end.js +2 -2
- package/dist/compose/resolve-flow-collection.js +8 -24
- package/dist/compose/resolve-flow-scalar.js +7 -19
- package/dist/compose/resolve-props.d.ts +4 -3
- package/dist/compose/resolve-props.js +7 -32
- package/dist/doc/Document.d.ts +5 -16
- package/dist/doc/Document.js +11 -57
- package/dist/doc/createNode.d.ts +1 -2
- package/dist/doc/createNode.js +4 -10
- package/dist/doc/directives.d.ts +0 -1
- package/dist/doc/directives.js +0 -5
- package/dist/errors.d.ts +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/nodes/Alias.d.ts +3 -7
- package/dist/nodes/Collection.d.ts +4 -10
- package/dist/nodes/Collection.js +14 -27
- package/dist/nodes/Node.d.ts +3 -10
- package/dist/nodes/Node.js +0 -7
- package/dist/nodes/Pair.d.ts +2 -7
- package/dist/nodes/Pair.js +0 -8
- package/dist/nodes/Scalar.d.ts +0 -2
- package/dist/nodes/YAMLMap.d.ts +0 -2
- package/dist/nodes/YAMLMap.js +1 -1
- package/dist/nodes/YAMLSeq.d.ts +0 -2
- package/dist/nodes/YAMLSeq.js +1 -1
- package/dist/nodes/addPairToJSMap.js +2 -3
- package/dist/options.d.ts +6 -81
- package/dist/options.js +0 -2
- package/dist/parse/cst-scalar.d.ts +0 -6
- package/dist/parse/cst-scalar.js +6 -2
- package/dist/parse/lexer.d.ts +1 -3
- package/dist/parse/lexer.js +31 -67
- package/dist/parse/parser.d.ts +0 -1
- package/dist/parse/parser.js +55 -62
- package/dist/public-api.js +4 -2
- package/dist/schema/Schema.d.ts +4 -6
- package/dist/schema/Schema.js +2 -13
- package/dist/schema/core/float.js +1 -4
- package/dist/schema/tags.d.ts +2 -1
- package/dist/schema/tags.js +13 -17
- package/dist/schema/yaml-1.1/float.js +1 -4
- package/dist/stringify/addComment.d.ts +2 -0
- package/dist/stringify/addComment.js +13 -0
- package/dist/stringify/stringify.d.ts +3 -5
- package/dist/stringify/stringify.js +17 -47
- package/dist/stringify/stringifyCollection.d.ts +7 -3
- package/dist/stringify/stringifyCollection.js +72 -116
- package/dist/stringify/stringifyDocument.js +9 -16
- package/dist/stringify/stringifyPair.js +20 -29
- package/dist/stringify/stringifyString.js +41 -39
- package/dist/test-events.d.ts +1 -1
- package/dist/test-events.js +2 -4
- package/dist/util.d.ts +0 -3
- package/dist/util.js +0 -6
- package/package.json +12 -14
- package/browser/dist/compose/util-flow-indent-check.js +0 -15
- package/browser/dist/compose/util-map-includes.js +0 -17
- package/browser/dist/node_modules/tslib/tslib.es6.js +0 -164
- package/browser/dist/stringify/stringifyComment.js +0 -18
- package/dist/compose/util-flow-indent-check.d.ts +0 -3
- package/dist/compose/util-flow-indent-check.js +0 -17
- package/dist/compose/util-map-includes.d.ts +0 -4
- package/dist/compose/util-map-includes.js +0 -19
- package/dist/node_modules/tslib/tslib.es6.js +0 -76
- package/dist/stringify/stringifyComment.d.ts +0 -10
- package/dist/stringify/stringifyComment.js +0 -22
- 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.
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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 (
|
|
154
|
-
return
|
|
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 =
|
|
159
|
-
?
|
|
160
|
-
:
|
|
161
|
-
?
|
|
162
|
-
:
|
|
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 += ' ' +
|
|
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
|
|
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
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
?
|
|
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);
|
package/browser/dist/util.js
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
69
|
-
|
|
70
|
-
if (
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
|
73
|
+
return schema[Node.SCALAR];
|
|
81
74
|
}
|
|
82
75
|
|
|
83
76
|
exports.composeScalar = composeScalar;
|
package/dist/compose/composer.js
CHANGED
|
@@ -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
|
-
|
|
29
|
+
source.substring(1);
|
|
31
30
|
atComment = true;
|
|
32
31
|
afterEmptyLine = false;
|
|
33
32
|
break;
|
|
34
33
|
case '%':
|
|
35
|
-
if (
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 === '+' ?
|
|
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, '
|
|
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, '
|
|
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
|
-
|
|
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
|
|
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 (
|
|
156
|
-
pair
|
|
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
|
|
164
|
+
cePos += ce.source.length;
|
|
177
165
|
else {
|
|
178
|
-
|
|
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
|
|
44
|
+
let message = '';
|
|
45
45
|
switch (source[0]) {
|
|
46
46
|
/* istanbul ignore next should not happen */
|
|
47
47
|
case '\t':
|
|
48
|
-
|
|
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
|
-
|
|
52
|
+
message = `Plain value cannot start with block scalar indicator ${source[0]}`;
|
|
59
53
|
break;
|
|
60
54
|
}
|
|
61
55
|
case '@':
|
|
62
56
|
case '`': {
|
|
63
|
-
|
|
57
|
+
message = `Plain value cannot start with reserved character ${source[0]}`;
|
|
64
58
|
break;
|
|
65
59
|
}
|
|
66
60
|
}
|
|
67
|
-
if (
|
|
68
|
-
onError(0, 'BAD_SCALAR_START',
|
|
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'
|
|
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
|
|
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,
|
|
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;
|