yaml 2.8.3 → 2.9.0
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/composer.js +4 -2
- package/browser/dist/compose/resolve-flow-scalar.js +5 -3
- package/browser/dist/nodes/Alias.js +2 -0
- package/browser/dist/parse/lexer.js +28 -24
- package/browser/dist/parse/parser.js +12 -4
- package/browser/dist/schema/yaml-1.1/merge.js +11 -8
- package/browser/dist/stringify/stringifyNumber.js +2 -1
- package/dist/compose/composer.js +4 -2
- package/dist/compose/resolve-flow-scalar.js +5 -3
- package/dist/nodes/Alias.js +2 -0
- package/dist/nodes/Scalar.d.ts +5 -1
- package/dist/parse/lexer.js +28 -24
- package/dist/parse/parser.js +12 -4
- package/dist/schema/yaml-1.1/merge.js +10 -7
- package/dist/stringify/stringifyNumber.js +2 -1
- package/package.json +1 -1
|
@@ -94,8 +94,10 @@ class Composer {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
if (afterDoc) {
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
for (let i = 0; i < this.errors.length; ++i)
|
|
98
|
+
doc.errors.push(this.errors[i]);
|
|
99
|
+
for (let i = 0; i < this.warnings.length; ++i)
|
|
100
|
+
doc.warnings.push(this.warnings[i]);
|
|
99
101
|
}
|
|
100
102
|
else {
|
|
101
103
|
doc.errors = this.errors;
|
|
@@ -142,7 +142,7 @@ function doubleQuotedValue(source, onError) {
|
|
|
142
142
|
next = source[++i + 1];
|
|
143
143
|
}
|
|
144
144
|
else if (next === 'x' || next === 'u' || next === 'U') {
|
|
145
|
-
const length =
|
|
145
|
+
const length = next === 'x' ? 2 : next === 'u' ? 4 : 8;
|
|
146
146
|
res += parseCharCode(source, i + 1, length, onError);
|
|
147
147
|
i += length;
|
|
148
148
|
}
|
|
@@ -212,12 +212,14 @@ function parseCharCode(source, offset, length, onError) {
|
|
|
212
212
|
const cc = source.substr(offset, length);
|
|
213
213
|
const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
|
|
214
214
|
const code = ok ? parseInt(cc, 16) : NaN;
|
|
215
|
-
|
|
215
|
+
try {
|
|
216
|
+
return String.fromCodePoint(code);
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
216
219
|
const raw = source.substr(offset - 2, length + 2);
|
|
217
220
|
onError(offset - 2, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
|
|
218
221
|
return raw;
|
|
219
222
|
}
|
|
220
|
-
return String.fromCodePoint(code);
|
|
221
223
|
}
|
|
222
224
|
|
|
223
225
|
export { resolveFlowScalar };
|
|
@@ -19,6 +19,8 @@ class Alias extends NodeBase {
|
|
|
19
19
|
* instance of the `source` anchor before this node.
|
|
20
20
|
*/
|
|
21
21
|
resolve(doc, ctx) {
|
|
22
|
+
if (ctx?.maxAliasCount === 0)
|
|
23
|
+
throw new ReferenceError('Alias resolution is disabled');
|
|
22
24
|
let nodes;
|
|
23
25
|
if (ctx?.aliasResolveCache) {
|
|
24
26
|
nodes = ctx.aliasResolveCache;
|
|
@@ -310,7 +310,7 @@ class Lexer {
|
|
|
310
310
|
const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
|
|
311
311
|
this.indentNext = this.indentValue + 1;
|
|
312
312
|
this.indentValue += n;
|
|
313
|
-
return
|
|
313
|
+
return 'block-start';
|
|
314
314
|
}
|
|
315
315
|
return 'doc';
|
|
316
316
|
}
|
|
@@ -631,32 +631,36 @@ class Lexer {
|
|
|
631
631
|
return 0;
|
|
632
632
|
}
|
|
633
633
|
*pushIndicators() {
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
634
|
+
let n = 0;
|
|
635
|
+
loop: while (true) {
|
|
636
|
+
switch (this.charAt(0)) {
|
|
637
|
+
case '!':
|
|
638
|
+
n += yield* this.pushTag();
|
|
639
|
+
n += yield* this.pushSpaces(true);
|
|
640
|
+
continue loop;
|
|
641
|
+
case '&':
|
|
642
|
+
n += yield* this.pushUntil(isNotAnchorChar);
|
|
643
|
+
n += yield* this.pushSpaces(true);
|
|
644
|
+
continue loop;
|
|
645
|
+
case '-': // this is an error
|
|
646
|
+
case '?': // this is an error outside flow collections
|
|
647
|
+
case ':': {
|
|
648
|
+
const inFlow = this.flowLevel > 0;
|
|
649
|
+
const ch1 = this.charAt(1);
|
|
650
|
+
if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) {
|
|
651
|
+
if (!inFlow)
|
|
652
|
+
this.indentNext = this.indentValue + 1;
|
|
653
|
+
else if (this.flowKey)
|
|
654
|
+
this.flowKey = false;
|
|
655
|
+
n += yield* this.pushCount(1);
|
|
656
|
+
n += yield* this.pushSpaces(true);
|
|
657
|
+
continue loop;
|
|
658
|
+
}
|
|
656
659
|
}
|
|
657
660
|
}
|
|
661
|
+
break loop;
|
|
658
662
|
}
|
|
659
|
-
return
|
|
663
|
+
return n;
|
|
660
664
|
}
|
|
661
665
|
*pushTag() {
|
|
662
666
|
if (this.charAt(1) === '<') {
|
|
@@ -67,6 +67,14 @@ function getFirstKeyStartProps(prev) {
|
|
|
67
67
|
}
|
|
68
68
|
return prev.splice(i, prev.length);
|
|
69
69
|
}
|
|
70
|
+
function arrayPushArray(target, source) {
|
|
71
|
+
// May exhaust call stack with large `source` array
|
|
72
|
+
if (source.length < 1e5)
|
|
73
|
+
Array.prototype.push.apply(target, source);
|
|
74
|
+
else
|
|
75
|
+
for (let i = 0; i < source.length; ++i)
|
|
76
|
+
target.push(source[i]);
|
|
77
|
+
}
|
|
70
78
|
function fixFlowSeqItems(fc) {
|
|
71
79
|
if (fc.start.type === 'flow-seq-start') {
|
|
72
80
|
for (const it of fc.items) {
|
|
@@ -79,12 +87,12 @@ function fixFlowSeqItems(fc) {
|
|
|
79
87
|
delete it.key;
|
|
80
88
|
if (isFlowToken(it.value)) {
|
|
81
89
|
if (it.value.end)
|
|
82
|
-
|
|
90
|
+
arrayPushArray(it.value.end, it.sep);
|
|
83
91
|
else
|
|
84
92
|
it.value.end = it.sep;
|
|
85
93
|
}
|
|
86
94
|
else
|
|
87
|
-
|
|
95
|
+
arrayPushArray(it.start, it.sep);
|
|
88
96
|
delete it.sep;
|
|
89
97
|
}
|
|
90
98
|
}
|
|
@@ -502,7 +510,7 @@ class Parser {
|
|
|
502
510
|
const prev = map.items[map.items.length - 2];
|
|
503
511
|
const end = prev?.value?.end;
|
|
504
512
|
if (Array.isArray(end)) {
|
|
505
|
-
|
|
513
|
+
arrayPushArray(end, it.start);
|
|
506
514
|
end.push(this.sourceToken);
|
|
507
515
|
map.items.pop();
|
|
508
516
|
return;
|
|
@@ -717,7 +725,7 @@ class Parser {
|
|
|
717
725
|
const prev = seq.items[seq.items.length - 2];
|
|
718
726
|
const end = prev?.value?.end;
|
|
719
727
|
if (Array.isArray(end)) {
|
|
720
|
-
|
|
728
|
+
arrayPushArray(end, it.start);
|
|
721
729
|
end.push(this.sourceToken);
|
|
722
730
|
seq.items.pop();
|
|
723
731
|
return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isScalar,
|
|
1
|
+
import { isScalar, isSeq, isAlias, isMap } from '../../nodes/identity.js';
|
|
2
2
|
import { Scalar } from '../../nodes/Scalar.js';
|
|
3
3
|
|
|
4
4
|
// If the value associated with a merge key is a single mapping node, each of
|
|
@@ -26,18 +26,18 @@ const isMergeKey = (ctx, key) => (merge.identify(key) ||
|
|
|
26
26
|
merge.identify(key.value))) &&
|
|
27
27
|
ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default);
|
|
28
28
|
function addMergeToJSMap(ctx, map, value) {
|
|
29
|
-
|
|
30
|
-
if (isSeq(
|
|
31
|
-
for (const it of
|
|
29
|
+
const source = resolveAliasValue(ctx, value);
|
|
30
|
+
if (isSeq(source))
|
|
31
|
+
for (const it of source.items)
|
|
32
32
|
mergeValue(ctx, map, it);
|
|
33
|
-
else if (Array.isArray(
|
|
34
|
-
for (const it of
|
|
33
|
+
else if (Array.isArray(source))
|
|
34
|
+
for (const it of source)
|
|
35
35
|
mergeValue(ctx, map, it);
|
|
36
36
|
else
|
|
37
|
-
mergeValue(ctx, map,
|
|
37
|
+
mergeValue(ctx, map, source);
|
|
38
38
|
}
|
|
39
39
|
function mergeValue(ctx, map, value) {
|
|
40
|
-
const source = ctx
|
|
40
|
+
const source = resolveAliasValue(ctx, value);
|
|
41
41
|
if (!isMap(source))
|
|
42
42
|
throw new Error('Merge sources must be maps or map aliases');
|
|
43
43
|
const srcMap = source.toJSON(null, ctx, Map);
|
|
@@ -60,5 +60,8 @@ function mergeValue(ctx, map, value) {
|
|
|
60
60
|
}
|
|
61
61
|
return map;
|
|
62
62
|
}
|
|
63
|
+
function resolveAliasValue(ctx, value) {
|
|
64
|
+
return ctx && isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
|
|
65
|
+
}
|
|
63
66
|
|
|
64
67
|
export { addMergeToJSMap, isMergeKey, merge };
|
|
@@ -8,7 +8,8 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) {
|
|
|
8
8
|
if (!format &&
|
|
9
9
|
minFractionDigits &&
|
|
10
10
|
(!tag || tag === 'tag:yaml.org,2002:float') &&
|
|
11
|
-
|
|
11
|
+
/^-?\d/.test(n) &&
|
|
12
|
+
!n.includes('e')) {
|
|
12
13
|
let i = n.indexOf('.');
|
|
13
14
|
if (i < 0) {
|
|
14
15
|
i = n.length;
|
package/dist/compose/composer.js
CHANGED
|
@@ -97,8 +97,10 @@ class Composer {
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
if (afterDoc) {
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
for (let i = 0; i < this.errors.length; ++i)
|
|
101
|
+
doc.errors.push(this.errors[i]);
|
|
102
|
+
for (let i = 0; i < this.warnings.length; ++i)
|
|
103
|
+
doc.warnings.push(this.warnings[i]);
|
|
102
104
|
}
|
|
103
105
|
else {
|
|
104
106
|
doc.errors = this.errors;
|
|
@@ -144,7 +144,7 @@ function doubleQuotedValue(source, onError) {
|
|
|
144
144
|
next = source[++i + 1];
|
|
145
145
|
}
|
|
146
146
|
else if (next === 'x' || next === 'u' || next === 'U') {
|
|
147
|
-
const length =
|
|
147
|
+
const length = next === 'x' ? 2 : next === 'u' ? 4 : 8;
|
|
148
148
|
res += parseCharCode(source, i + 1, length, onError);
|
|
149
149
|
i += length;
|
|
150
150
|
}
|
|
@@ -214,12 +214,14 @@ function parseCharCode(source, offset, length, onError) {
|
|
|
214
214
|
const cc = source.substr(offset, length);
|
|
215
215
|
const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
|
|
216
216
|
const code = ok ? parseInt(cc, 16) : NaN;
|
|
217
|
-
|
|
217
|
+
try {
|
|
218
|
+
return String.fromCodePoint(code);
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
218
221
|
const raw = source.substr(offset - 2, length + 2);
|
|
219
222
|
onError(offset - 2, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
|
|
220
223
|
return raw;
|
|
221
224
|
}
|
|
222
|
-
return String.fromCodePoint(code);
|
|
223
225
|
}
|
|
224
226
|
|
|
225
227
|
exports.resolveFlowScalar = resolveFlowScalar;
|
package/dist/nodes/Alias.js
CHANGED
|
@@ -21,6 +21,8 @@ class Alias extends Node.NodeBase {
|
|
|
21
21
|
* instance of the `source` anchor before this node.
|
|
22
22
|
*/
|
|
23
23
|
resolve(doc, ctx) {
|
|
24
|
+
if (ctx?.maxAliasCount === 0)
|
|
25
|
+
throw new ReferenceError('Alias resolution is disabled');
|
|
24
26
|
let nodes;
|
|
25
27
|
if (ctx?.aliasResolveCache) {
|
|
26
28
|
nodes = ctx.aliasResolveCache;
|
package/dist/nodes/Scalar.d.ts
CHANGED
|
@@ -31,7 +31,11 @@ export declare class Scalar<T = unknown> extends NodeBase {
|
|
|
31
31
|
* The YAML 1.1 schema also supports 'BIN' and 'TIME'
|
|
32
32
|
*/
|
|
33
33
|
format?: string;
|
|
34
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* If `value` is a number that is serialized as a decimal string
|
|
36
|
+
* (i.e. not using exponential notation),
|
|
37
|
+
* use this value when stringifying this node.
|
|
38
|
+
*/
|
|
35
39
|
minFractionDigits?: number;
|
|
36
40
|
/** Set during parsing to the source string value */
|
|
37
41
|
source?: string;
|
package/dist/parse/lexer.js
CHANGED
|
@@ -312,7 +312,7 @@ class Lexer {
|
|
|
312
312
|
const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true));
|
|
313
313
|
this.indentNext = this.indentValue + 1;
|
|
314
314
|
this.indentValue += n;
|
|
315
|
-
return
|
|
315
|
+
return 'block-start';
|
|
316
316
|
}
|
|
317
317
|
return 'doc';
|
|
318
318
|
}
|
|
@@ -633,32 +633,36 @@ class Lexer {
|
|
|
633
633
|
return 0;
|
|
634
634
|
}
|
|
635
635
|
*pushIndicators() {
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
636
|
+
let n = 0;
|
|
637
|
+
loop: while (true) {
|
|
638
|
+
switch (this.charAt(0)) {
|
|
639
|
+
case '!':
|
|
640
|
+
n += yield* this.pushTag();
|
|
641
|
+
n += yield* this.pushSpaces(true);
|
|
642
|
+
continue loop;
|
|
643
|
+
case '&':
|
|
644
|
+
n += yield* this.pushUntil(isNotAnchorChar);
|
|
645
|
+
n += yield* this.pushSpaces(true);
|
|
646
|
+
continue loop;
|
|
647
|
+
case '-': // this is an error
|
|
648
|
+
case '?': // this is an error outside flow collections
|
|
649
|
+
case ':': {
|
|
650
|
+
const inFlow = this.flowLevel > 0;
|
|
651
|
+
const ch1 = this.charAt(1);
|
|
652
|
+
if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) {
|
|
653
|
+
if (!inFlow)
|
|
654
|
+
this.indentNext = this.indentValue + 1;
|
|
655
|
+
else if (this.flowKey)
|
|
656
|
+
this.flowKey = false;
|
|
657
|
+
n += yield* this.pushCount(1);
|
|
658
|
+
n += yield* this.pushSpaces(true);
|
|
659
|
+
continue loop;
|
|
660
|
+
}
|
|
658
661
|
}
|
|
659
662
|
}
|
|
663
|
+
break loop;
|
|
660
664
|
}
|
|
661
|
-
return
|
|
665
|
+
return n;
|
|
662
666
|
}
|
|
663
667
|
*pushTag() {
|
|
664
668
|
if (this.charAt(1) === '<') {
|
package/dist/parse/parser.js
CHANGED
|
@@ -70,6 +70,14 @@ function getFirstKeyStartProps(prev) {
|
|
|
70
70
|
}
|
|
71
71
|
return prev.splice(i, prev.length);
|
|
72
72
|
}
|
|
73
|
+
function arrayPushArray(target, source) {
|
|
74
|
+
// May exhaust call stack with large `source` array
|
|
75
|
+
if (source.length < 1e5)
|
|
76
|
+
Array.prototype.push.apply(target, source);
|
|
77
|
+
else
|
|
78
|
+
for (let i = 0; i < source.length; ++i)
|
|
79
|
+
target.push(source[i]);
|
|
80
|
+
}
|
|
73
81
|
function fixFlowSeqItems(fc) {
|
|
74
82
|
if (fc.start.type === 'flow-seq-start') {
|
|
75
83
|
for (const it of fc.items) {
|
|
@@ -82,12 +90,12 @@ function fixFlowSeqItems(fc) {
|
|
|
82
90
|
delete it.key;
|
|
83
91
|
if (isFlowToken(it.value)) {
|
|
84
92
|
if (it.value.end)
|
|
85
|
-
|
|
93
|
+
arrayPushArray(it.value.end, it.sep);
|
|
86
94
|
else
|
|
87
95
|
it.value.end = it.sep;
|
|
88
96
|
}
|
|
89
97
|
else
|
|
90
|
-
|
|
98
|
+
arrayPushArray(it.start, it.sep);
|
|
91
99
|
delete it.sep;
|
|
92
100
|
}
|
|
93
101
|
}
|
|
@@ -507,7 +515,7 @@ class Parser {
|
|
|
507
515
|
const prev = map.items[map.items.length - 2];
|
|
508
516
|
const end = prev?.value?.end;
|
|
509
517
|
if (Array.isArray(end)) {
|
|
510
|
-
|
|
518
|
+
arrayPushArray(end, it.start);
|
|
511
519
|
end.push(this.sourceToken);
|
|
512
520
|
map.items.pop();
|
|
513
521
|
return;
|
|
@@ -722,7 +730,7 @@ class Parser {
|
|
|
722
730
|
const prev = seq.items[seq.items.length - 2];
|
|
723
731
|
const end = prev?.value?.end;
|
|
724
732
|
if (Array.isArray(end)) {
|
|
725
|
-
|
|
733
|
+
arrayPushArray(end, it.start);
|
|
726
734
|
end.push(this.sourceToken);
|
|
727
735
|
seq.items.pop();
|
|
728
736
|
return;
|
|
@@ -28,18 +28,18 @@ const isMergeKey = (ctx, key) => (merge.identify(key) ||
|
|
|
28
28
|
merge.identify(key.value))) &&
|
|
29
29
|
ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default);
|
|
30
30
|
function addMergeToJSMap(ctx, map, value) {
|
|
31
|
-
|
|
32
|
-
if (identity.isSeq(
|
|
33
|
-
for (const it of
|
|
31
|
+
const source = resolveAliasValue(ctx, value);
|
|
32
|
+
if (identity.isSeq(source))
|
|
33
|
+
for (const it of source.items)
|
|
34
34
|
mergeValue(ctx, map, it);
|
|
35
|
-
else if (Array.isArray(
|
|
36
|
-
for (const it of
|
|
35
|
+
else if (Array.isArray(source))
|
|
36
|
+
for (const it of source)
|
|
37
37
|
mergeValue(ctx, map, it);
|
|
38
38
|
else
|
|
39
|
-
mergeValue(ctx, map,
|
|
39
|
+
mergeValue(ctx, map, source);
|
|
40
40
|
}
|
|
41
41
|
function mergeValue(ctx, map, value) {
|
|
42
|
-
const source = ctx
|
|
42
|
+
const source = resolveAliasValue(ctx, value);
|
|
43
43
|
if (!identity.isMap(source))
|
|
44
44
|
throw new Error('Merge sources must be maps or map aliases');
|
|
45
45
|
const srcMap = source.toJSON(null, ctx, Map);
|
|
@@ -62,6 +62,9 @@ function mergeValue(ctx, map, value) {
|
|
|
62
62
|
}
|
|
63
63
|
return map;
|
|
64
64
|
}
|
|
65
|
+
function resolveAliasValue(ctx, value) {
|
|
66
|
+
return ctx && identity.isAlias(value) ? value.resolve(ctx.doc, ctx) : value;
|
|
67
|
+
}
|
|
65
68
|
|
|
66
69
|
exports.addMergeToJSMap = addMergeToJSMap;
|
|
67
70
|
exports.isMergeKey = isMergeKey;
|
|
@@ -10,7 +10,8 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) {
|
|
|
10
10
|
if (!format &&
|
|
11
11
|
minFractionDigits &&
|
|
12
12
|
(!tag || tag === 'tag:yaml.org,2002:float') &&
|
|
13
|
-
|
|
13
|
+
/^-?\d/.test(n) &&
|
|
14
|
+
!n.includes('e')) {
|
|
14
15
|
let i = n.indexOf('.');
|
|
15
16
|
if (i < 0) {
|
|
16
17
|
i = n.length;
|