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.
- package/README.md +5 -5
- package/browser/dist/compose/compose-collection.js +12 -9
- package/browser/dist/compose/compose-doc.js +23 -6
- package/browser/dist/compose/compose-node.js +20 -17
- package/browser/dist/compose/compose-scalar.js +20 -23
- package/browser/dist/compose/composer.js +105 -76
- package/browser/dist/compose/resolve-block-map.js +38 -29
- package/browser/dist/compose/resolve-block-scalar.js +14 -17
- package/browser/dist/compose/resolve-block-seq.js +21 -17
- package/browser/dist/compose/resolve-end.js +6 -7
- package/browser/dist/compose/resolve-flow-collection.js +153 -199
- package/browser/dist/compose/resolve-flow-scalar.js +49 -25
- package/browser/dist/compose/resolve-props.js +47 -35
- package/browser/dist/compose/util-contains-newline.js +15 -12
- package/browser/dist/doc/Document.js +50 -99
- package/browser/dist/doc/anchors.js +72 -0
- package/browser/dist/doc/createNode.js +27 -17
- package/browser/dist/errors.js +16 -12
- package/browser/dist/index.js +3 -3
- package/browser/dist/nodes/Alias.js +51 -28
- package/browser/dist/nodes/Collection.js +5 -83
- package/browser/dist/nodes/Node.js +2 -1
- package/browser/dist/nodes/Pair.js +9 -232
- package/browser/dist/nodes/YAMLMap.js +8 -4
- package/browser/dist/nodes/YAMLSeq.js +7 -4
- package/browser/dist/nodes/addPairToJSMap.js +103 -0
- package/browser/dist/nodes/toJS.js +12 -10
- package/browser/dist/options.js +0 -2
- package/browser/dist/parse/cst-scalar.js +219 -0
- package/browser/dist/parse/cst-stringify.js +61 -0
- package/browser/dist/parse/cst-visit.js +97 -0
- package/{dist/parse/tokens.js → browser/dist/parse/cst.js} +12 -7
- package/browser/dist/parse/lexer.js +99 -105
- package/browser/dist/parse/parser.js +219 -144
- package/browser/dist/public-api.js +11 -14
- package/browser/dist/schema/Schema.js +23 -0
- package/browser/dist/{tags/failsafe → schema/common}/map.js +0 -0
- package/browser/dist/schema/common/null.js +13 -0
- package/browser/dist/{tags/failsafe → schema/common}/seq.js +1 -1
- package/browser/dist/{tags/failsafe → schema/common}/string.js +0 -0
- package/browser/dist/schema/core/bool.js +19 -0
- package/browser/dist/schema/core/float.js +40 -0
- package/browser/dist/schema/core/int.js +38 -0
- package/browser/dist/schema/core/schema.js +23 -0
- package/browser/dist/{tags/json.js → schema/json/schema.js} +5 -6
- package/browser/dist/schema/tags.js +79 -0
- package/browser/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
- package/browser/dist/schema/yaml-1.1/bool.js +26 -0
- package/browser/dist/schema/yaml-1.1/float.js +43 -0
- package/browser/dist/schema/yaml-1.1/int.js +71 -0
- package/browser/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
- package/browser/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
- package/browser/dist/schema/yaml-1.1/schema.js +37 -0
- package/browser/dist/{tags → schema}/yaml-1.1/set.js +0 -0
- package/browser/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
- package/browser/dist/stringify/addComment.js +1 -7
- package/browser/dist/stringify/stringify.js +8 -6
- package/browser/dist/stringify/stringifyCollection.js +108 -0
- package/browser/dist/stringify/stringifyDocument.js +61 -0
- package/browser/dist/stringify/stringifyPair.js +113 -0
- package/browser/dist/stringify/stringifyString.js +53 -52
- package/browser/dist/visit.js +20 -1
- package/dist/compose/compose-collection.d.ts +4 -4
- package/dist/compose/compose-collection.js +12 -9
- package/dist/compose/compose-doc.d.ts +4 -3
- package/dist/compose/compose-doc.js +23 -6
- package/dist/compose/compose-node.d.ts +15 -7
- package/dist/compose/compose-node.js +20 -17
- package/dist/compose/compose-scalar.d.ts +4 -3
- package/dist/compose/compose-scalar.js +19 -22
- package/dist/compose/composer.d.ts +28 -23
- package/dist/compose/composer.js +106 -77
- package/dist/compose/resolve-block-map.d.ts +4 -4
- package/dist/compose/resolve-block-map.js +38 -29
- package/dist/compose/resolve-block-scalar.d.ts +5 -3
- package/dist/compose/resolve-block-scalar.js +14 -17
- package/dist/compose/resolve-block-seq.d.ts +4 -4
- package/dist/compose/resolve-block-seq.js +21 -17
- package/dist/compose/resolve-end.d.ts +3 -2
- package/dist/compose/resolve-end.js +6 -7
- package/dist/compose/resolve-flow-collection.d.ts +4 -5
- package/dist/compose/resolve-flow-collection.js +152 -198
- package/dist/compose/resolve-flow-scalar.d.ts +5 -3
- package/dist/compose/resolve-flow-scalar.js +49 -25
- package/dist/compose/resolve-props.d.ts +17 -10
- package/dist/compose/resolve-props.js +47 -35
- package/dist/compose/util-contains-newline.d.ts +1 -1
- package/dist/compose/util-contains-newline.js +15 -12
- package/dist/compose/util-empty-scalar-position.d.ts +1 -1
- package/dist/doc/Document.d.ts +27 -15
- package/dist/doc/Document.js +48 -97
- package/dist/doc/anchors.d.ts +24 -0
- package/dist/doc/anchors.js +77 -0
- package/dist/doc/createNode.d.ts +8 -10
- package/dist/doc/createNode.js +26 -16
- package/dist/errors.d.ts +11 -8
- package/dist/errors.js +16 -12
- package/dist/index.d.ts +5 -3
- package/dist/index.js +3 -3
- package/dist/nodes/Alias.d.ts +19 -9
- package/dist/nodes/Alias.js +51 -28
- package/dist/nodes/Collection.d.ts +3 -17
- package/dist/nodes/Collection.js +4 -82
- package/dist/nodes/Node.d.ts +6 -4
- package/dist/nodes/Node.js +2 -0
- package/dist/nodes/Pair.d.ts +6 -11
- package/dist/nodes/Pair.js +8 -231
- package/dist/nodes/Scalar.d.ts +6 -3
- package/dist/nodes/YAMLMap.d.ts +3 -3
- package/dist/nodes/YAMLMap.js +8 -4
- package/dist/nodes/YAMLSeq.d.ts +3 -3
- package/dist/nodes/YAMLSeq.js +7 -4
- package/dist/nodes/addPairToJSMap.d.ts +3 -0
- package/dist/nodes/addPairToJSMap.js +105 -0
- package/dist/nodes/toJS.d.ts +4 -5
- package/dist/nodes/toJS.js +12 -10
- package/dist/options.d.ts +20 -26
- package/dist/options.js +0 -2
- package/dist/parse/cst-scalar.d.ts +58 -0
- package/dist/parse/cst-scalar.js +223 -0
- package/dist/parse/cst-stringify.d.ts +8 -0
- package/dist/parse/cst-stringify.js +63 -0
- package/dist/parse/cst-visit.d.ts +39 -0
- package/dist/parse/cst-visit.js +99 -0
- package/dist/parse/{tokens.d.ts → cst.d.ts} +23 -7
- package/{browser/dist/parse/tokens.js → dist/parse/cst.js} +27 -1
- package/dist/parse/lexer.d.ts +4 -13
- package/dist/parse/lexer.js +100 -106
- package/dist/parse/parser.d.ts +30 -24
- package/dist/parse/parser.js +221 -146
- package/dist/public-api.d.ts +7 -7
- package/dist/public-api.js +11 -14
- package/dist/{doc → schema}/Schema.d.ts +5 -3
- package/dist/schema/Schema.js +25 -0
- package/dist/{tags/failsafe → schema/common}/map.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/map.js +0 -0
- package/dist/schema/common/null.d.ts +4 -0
- package/dist/schema/common/null.js +15 -0
- package/dist/{tags/failsafe → schema/common}/seq.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/seq.js +1 -1
- package/dist/{tags/failsafe → schema/common}/string.d.ts +0 -0
- package/dist/{tags/failsafe → schema/common}/string.js +0 -0
- package/dist/schema/core/bool.d.ts +4 -0
- package/dist/schema/core/bool.js +21 -0
- package/dist/schema/core/float.d.ts +4 -0
- package/dist/schema/core/float.js +44 -0
- package/dist/schema/core/int.d.ts +4 -0
- package/dist/schema/core/int.js +42 -0
- package/dist/schema/core/schema.d.ts +1 -0
- package/dist/schema/core/schema.js +25 -0
- package/dist/schema/json/schema.d.ts +2 -0
- package/dist/{tags/json.js → schema/json/schema.js} +5 -6
- package/dist/schema/tags.d.ts +41 -0
- package/dist/schema/tags.js +82 -0
- package/dist/{tags → schema}/types.d.ts +3 -7
- package/dist/{tags → schema}/yaml-1.1/binary.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/binary.js +0 -0
- package/dist/schema/yaml-1.1/bool.d.ts +7 -0
- package/dist/schema/yaml-1.1/bool.js +29 -0
- package/dist/schema/yaml-1.1/float.d.ts +4 -0
- package/dist/schema/yaml-1.1/float.js +47 -0
- package/dist/schema/yaml-1.1/int.d.ts +5 -0
- package/dist/schema/yaml-1.1/int.js +76 -0
- package/dist/{tags → schema}/yaml-1.1/omap.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/omap.js +0 -0
- package/dist/{tags → schema}/yaml-1.1/pairs.d.ts +3 -2
- package/dist/{tags → schema}/yaml-1.1/pairs.js +9 -6
- package/dist/schema/yaml-1.1/schema.d.ts +1 -0
- package/dist/schema/yaml-1.1/schema.js +39 -0
- package/dist/{tags → schema}/yaml-1.1/set.d.ts +1 -1
- package/dist/{tags → schema}/yaml-1.1/set.js +0 -0
- package/dist/{tags → schema}/yaml-1.1/timestamp.d.ts +0 -0
- package/dist/{tags → schema}/yaml-1.1/timestamp.js +0 -0
- package/dist/stringify/addComment.js +0 -7
- package/dist/stringify/stringify.d.ts +1 -2
- package/dist/stringify/stringify.js +8 -6
- package/dist/stringify/stringifyCollection.d.ts +21 -0
- package/dist/stringify/stringifyCollection.js +110 -0
- package/dist/stringify/stringifyDocument.d.ts +3 -0
- package/dist/stringify/stringifyDocument.js +63 -0
- package/dist/stringify/stringifyPair.d.ts +3 -0
- package/dist/stringify/stringifyPair.js +115 -0
- package/dist/stringify/stringifyString.js +53 -52
- package/dist/test-events.d.ts +1 -2
- package/dist/test-events.js +25 -12
- package/dist/util.d.ts +1 -1
- package/dist/visit.d.ts +10 -1
- package/dist/visit.js +20 -1
- package/package.json +4 -3
- package/browser/dist/doc/Anchors.js +0 -102
- package/browser/dist/doc/Schema.js +0 -27
- package/browser/dist/doc/getSchemaTags.js +0 -30
- package/browser/dist/tags/core.js +0 -109
- package/browser/dist/tags/failsafe/index.js +0 -7
- package/browser/dist/tags/index.js +0 -34
- package/browser/dist/tags/yaml-1.1/index.js +0 -152
- package/dist/doc/Anchors.d.ts +0 -36
- package/dist/doc/Anchors.js +0 -104
- package/dist/doc/Schema.js +0 -29
- package/dist/doc/getSchemaTags.d.ts +0 -3
- package/dist/doc/getSchemaTags.js +0 -32
- package/dist/tags/core.d.ts +0 -14
- package/dist/tags/core.js +0 -119
- package/dist/tags/failsafe/index.d.ts +0 -1
- package/dist/tags/failsafe/index.js +0 -9
- package/dist/tags/index.d.ts +0 -31
- package/dist/tags/index.js +0 -37
- package/dist/tags/json.d.ts +0 -2
- package/dist/tags/yaml-1.1/index.d.ts +0 -2
- package/dist/tags/yaml-1.1/index.js +0 -154
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
var Scalar = require('../nodes/Scalar.js');
|
|
4
4
|
var resolveEnd = require('./resolve-end.js');
|
|
5
5
|
|
|
6
|
-
function resolveFlowScalar(
|
|
6
|
+
function resolveFlowScalar(scalar, strict, onError) {
|
|
7
|
+
const { offset, type, source, end } = scalar;
|
|
7
8
|
let _type;
|
|
8
9
|
let value;
|
|
9
|
-
const _onError = (rel, msg) => onError(offset + rel, msg);
|
|
10
|
+
const _onError = (rel, code, msg) => onError(offset + rel, code, msg);
|
|
10
11
|
switch (type) {
|
|
11
12
|
case 'scalar':
|
|
12
13
|
_type = Scalar.Scalar.PLAIN;
|
|
@@ -22,68 +23,91 @@ function resolveFlowScalar({ offset, type, source, end }, strict, onError) {
|
|
|
22
23
|
break;
|
|
23
24
|
/* istanbul ignore next should not happen */
|
|
24
25
|
default:
|
|
25
|
-
onError(
|
|
26
|
+
onError(scalar, 'UNEXPECTED_TOKEN', `Expected a flow scalar value, but found: ${type}`);
|
|
26
27
|
return {
|
|
27
28
|
value: '',
|
|
28
29
|
type: null,
|
|
29
30
|
comment: '',
|
|
30
|
-
|
|
31
|
+
range: [offset, offset + source.length, offset + source.length]
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
|
-
const
|
|
34
|
+
const valueEnd = offset + source.length;
|
|
35
|
+
const re = resolveEnd.resolveEnd(end, valueEnd, strict, onError);
|
|
34
36
|
return {
|
|
35
37
|
value,
|
|
36
38
|
type: _type,
|
|
37
39
|
comment: re.comment,
|
|
38
|
-
|
|
40
|
+
range: [offset, valueEnd, re.offset]
|
|
39
41
|
};
|
|
40
42
|
}
|
|
41
43
|
function plainValue(source, onError) {
|
|
44
|
+
let message = '';
|
|
42
45
|
switch (source[0]) {
|
|
43
46
|
/* istanbul ignore next should not happen */
|
|
44
47
|
case '\t':
|
|
45
|
-
|
|
48
|
+
message = 'Plain value cannot start with a tab character';
|
|
46
49
|
break;
|
|
47
50
|
case '|':
|
|
48
51
|
case '>': {
|
|
49
|
-
|
|
50
|
-
onError(0, message);
|
|
52
|
+
message = `Plain value cannot start with block scalar indicator ${source[0]}`;
|
|
51
53
|
break;
|
|
52
54
|
}
|
|
53
55
|
case '@':
|
|
54
56
|
case '`': {
|
|
55
|
-
|
|
56
|
-
onError(0, message);
|
|
57
|
+
message = `Plain value cannot start with reserved character ${source[0]}`;
|
|
57
58
|
break;
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
+
if (message)
|
|
62
|
+
onError(0, 'BAD_SCALAR_START', message);
|
|
63
|
+
return foldLines(source);
|
|
61
64
|
}
|
|
62
65
|
function singleQuotedValue(source, onError) {
|
|
63
66
|
if (source[source.length - 1] !== "'" || source.length === 1)
|
|
64
|
-
onError(source.length, "Missing closing 'quote");
|
|
67
|
+
onError(source.length, 'MISSING_CHAR', "Missing closing 'quote");
|
|
65
68
|
return foldLines(source.slice(1, -1)).replace(/''/g, "'");
|
|
66
69
|
}
|
|
67
70
|
function foldLines(source) {
|
|
68
|
-
|
|
69
|
-
|
|
71
|
+
/**
|
|
72
|
+
* The negative lookbehind here and in the `re` RegExp is to
|
|
73
|
+
* prevent causing a polynomial search time in certain cases.
|
|
74
|
+
*
|
|
75
|
+
* The try-catch is for Safari, which doesn't support this yet:
|
|
76
|
+
* https://caniuse.com/js-regexp-lookbehind
|
|
77
|
+
*/
|
|
78
|
+
let first, line;
|
|
79
|
+
try {
|
|
80
|
+
first = new RegExp('(.*?)(?<![ \t])[ \t]*\r?\n', 'sy');
|
|
81
|
+
line = new RegExp('[ \t]*(.*?)(?:(?<![ \t])[ \t]*)?\r?\n', 'sy');
|
|
82
|
+
}
|
|
83
|
+
catch (_) {
|
|
84
|
+
first = /(.*?)[ \t]*\r?\n/sy;
|
|
85
|
+
line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
|
|
86
|
+
}
|
|
87
|
+
let match = first.exec(source);
|
|
88
|
+
if (!match)
|
|
89
|
+
return source;
|
|
90
|
+
let res = match[1];
|
|
70
91
|
let sep = ' ';
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
92
|
+
let pos = first.lastIndex;
|
|
93
|
+
line.lastIndex = pos;
|
|
94
|
+
while ((match = line.exec(source))) {
|
|
95
|
+
if (match[1] === '') {
|
|
74
96
|
if (sep === '\n')
|
|
75
97
|
res += sep;
|
|
76
98
|
else
|
|
77
99
|
sep = '\n';
|
|
78
100
|
}
|
|
79
101
|
else {
|
|
80
|
-
res += sep +
|
|
102
|
+
res += sep + match[1];
|
|
81
103
|
sep = ' ';
|
|
82
104
|
}
|
|
105
|
+
pos = line.lastIndex;
|
|
83
106
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
107
|
+
const last = /[ \t]*(.*)/sy;
|
|
108
|
+
last.lastIndex = pos;
|
|
109
|
+
match = last.exec(source);
|
|
110
|
+
return res + sep + ((match && match[1]) || '');
|
|
87
111
|
}
|
|
88
112
|
function doubleQuotedValue(source, onError) {
|
|
89
113
|
let res = '';
|
|
@@ -114,7 +138,7 @@ function doubleQuotedValue(source, onError) {
|
|
|
114
138
|
}
|
|
115
139
|
else {
|
|
116
140
|
const raw = source.substr(i - 1, 2);
|
|
117
|
-
onError(i - 1, `Invalid escape sequence ${raw}`);
|
|
141
|
+
onError(i - 1, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
|
|
118
142
|
res += raw;
|
|
119
143
|
}
|
|
120
144
|
}
|
|
@@ -132,7 +156,7 @@ function doubleQuotedValue(source, onError) {
|
|
|
132
156
|
}
|
|
133
157
|
}
|
|
134
158
|
if (source[source.length - 1] !== '"' || source.length === 1)
|
|
135
|
-
onError(source.length, 'Missing closing "quote');
|
|
159
|
+
onError(source.length, 'MISSING_CHAR', 'Missing closing "quote');
|
|
136
160
|
return res;
|
|
137
161
|
}
|
|
138
162
|
/**
|
|
@@ -180,7 +204,7 @@ function parseCharCode(source, offset, length, onError) {
|
|
|
180
204
|
const code = ok ? parseInt(cc, 16) : NaN;
|
|
181
205
|
if (isNaN(code)) {
|
|
182
206
|
const raw = source.substr(offset - 2, length + 2);
|
|
183
|
-
onError(offset - 2, `Invalid escape sequence ${raw}`);
|
|
207
|
+
onError(offset - 2, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`);
|
|
184
208
|
return raw;
|
|
185
209
|
}
|
|
186
210
|
return String.fromCodePoint(code);
|
|
@@ -1,15 +1,22 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type { SourceToken } from '../parse/cst.js';
|
|
2
|
+
import type { ComposeContext } from './compose-node.js';
|
|
3
|
+
import type { ComposeErrorHandler } from './composer.js';
|
|
4
|
+
export interface ResolvePropsArg {
|
|
5
|
+
ctx: ComposeContext;
|
|
6
|
+
flow?: string;
|
|
7
|
+
indicator: 'doc-start' | 'explicit-key-ind' | 'map-value-ind' | 'seq-item-ind';
|
|
8
|
+
offset: number;
|
|
9
|
+
onError: ComposeErrorHandler;
|
|
10
|
+
startOnNewline: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function resolveProps(tokens: SourceToken[], { ctx, flow, indicator, offset, onError, startOnNewline }: ResolvePropsArg): {
|
|
13
|
+
comma: SourceToken | null;
|
|
14
|
+
found: SourceToken | null;
|
|
8
15
|
spaceBefore: boolean;
|
|
9
16
|
comment: string;
|
|
10
17
|
hasNewline: boolean;
|
|
11
|
-
anchor:
|
|
12
|
-
|
|
13
|
-
|
|
18
|
+
anchor: SourceToken | null;
|
|
19
|
+
tag: SourceToken | null;
|
|
20
|
+
end: number;
|
|
14
21
|
start: number;
|
|
15
22
|
};
|
|
@@ -1,92 +1,104 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function resolveProps(
|
|
4
|
-
let length = 0;
|
|
3
|
+
function resolveProps(tokens, { ctx, flow, indicator, offset, onError, startOnNewline }) {
|
|
5
4
|
let spaceBefore = false;
|
|
6
5
|
let atNewline = startOnNewline;
|
|
7
6
|
let hasSpace = startOnNewline;
|
|
8
7
|
let comment = '';
|
|
9
|
-
let
|
|
8
|
+
let commentSep = '';
|
|
10
9
|
let hasNewline = false;
|
|
11
|
-
let
|
|
12
|
-
let
|
|
13
|
-
let
|
|
10
|
+
let anchor = null;
|
|
11
|
+
let tag = null;
|
|
12
|
+
let comma = null;
|
|
14
13
|
let found = null;
|
|
15
14
|
let start = null;
|
|
16
15
|
for (const token of tokens) {
|
|
17
16
|
switch (token.type) {
|
|
18
17
|
case 'space':
|
|
19
|
-
// At the doc level, tabs at line start may be parsed
|
|
20
|
-
// white space rather than indentation.
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
// At the doc level, tabs at line start may be parsed
|
|
19
|
+
// as leading white space rather than indentation.
|
|
20
|
+
// In a flow collection, only the parser handles indent.
|
|
21
|
+
if (!flow &&
|
|
22
|
+
atNewline &&
|
|
23
|
+
indicator !== 'doc-start' &&
|
|
24
|
+
token.source[0] === '\t')
|
|
25
|
+
onError(token, 'TAB_AS_INDENT', 'Tabs are not allowed as indentation');
|
|
23
26
|
hasSpace = true;
|
|
24
27
|
break;
|
|
25
28
|
case 'comment': {
|
|
26
|
-
if (
|
|
27
|
-
onError(
|
|
29
|
+
if (ctx.options.strict && !hasSpace)
|
|
30
|
+
onError(token, 'COMMENT_SPACE', 'Comments must be separated from other tokens by white space characters');
|
|
28
31
|
const cb = token.source.substring(1);
|
|
29
|
-
if (!
|
|
32
|
+
if (!comment)
|
|
30
33
|
comment = cb;
|
|
31
34
|
else
|
|
32
|
-
comment +=
|
|
33
|
-
|
|
34
|
-
sep = '';
|
|
35
|
+
comment += commentSep + cb;
|
|
36
|
+
commentSep = '';
|
|
35
37
|
break;
|
|
36
38
|
}
|
|
37
39
|
case 'newline':
|
|
38
|
-
if (atNewline && !
|
|
40
|
+
if (atNewline && !comment)
|
|
39
41
|
spaceBefore = true;
|
|
40
42
|
atNewline = true;
|
|
41
43
|
hasNewline = true;
|
|
42
44
|
hasSpace = true;
|
|
43
|
-
|
|
45
|
+
commentSep += token.source;
|
|
44
46
|
break;
|
|
45
47
|
case 'anchor':
|
|
46
48
|
if (anchor)
|
|
47
|
-
onError(
|
|
48
|
-
anchor = token
|
|
49
|
+
onError(token, 'MULTIPLE_ANCHORS', 'A node can have at most one anchor');
|
|
50
|
+
anchor = token;
|
|
49
51
|
if (start === null)
|
|
50
|
-
start = offset
|
|
52
|
+
start = token.offset;
|
|
51
53
|
atNewline = false;
|
|
52
54
|
hasSpace = false;
|
|
53
55
|
break;
|
|
54
56
|
case 'tag': {
|
|
55
|
-
if (
|
|
56
|
-
onError(
|
|
57
|
-
|
|
58
|
-
if (tn)
|
|
59
|
-
tagName = tn;
|
|
57
|
+
if (tag)
|
|
58
|
+
onError(token, 'MULTIPLE_TAGS', 'A node can have at most one tag');
|
|
59
|
+
tag = token;
|
|
60
60
|
if (start === null)
|
|
61
|
-
start = offset
|
|
61
|
+
start = token.offset;
|
|
62
62
|
atNewline = false;
|
|
63
63
|
hasSpace = false;
|
|
64
64
|
break;
|
|
65
65
|
}
|
|
66
66
|
case indicator:
|
|
67
67
|
// Could here handle preceding comments differently
|
|
68
|
-
|
|
68
|
+
if (anchor || tag)
|
|
69
|
+
onError(token, 'BAD_PROP_ORDER', `Anchors and tags must be after the ${token.source} indicator`);
|
|
70
|
+
found = token;
|
|
69
71
|
atNewline = false;
|
|
70
72
|
hasSpace = false;
|
|
71
73
|
break;
|
|
74
|
+
case 'comma':
|
|
75
|
+
if (flow) {
|
|
76
|
+
if (comma)
|
|
77
|
+
onError(token, 'UNEXPECTED_TOKEN', `Unexpected , in ${flow}`);
|
|
78
|
+
comma = token;
|
|
79
|
+
atNewline = false;
|
|
80
|
+
hasSpace = false;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
// else fallthrough
|
|
72
84
|
default:
|
|
73
|
-
onError(
|
|
85
|
+
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.type} token`);
|
|
74
86
|
atNewline = false;
|
|
75
87
|
hasSpace = false;
|
|
76
88
|
}
|
|
77
|
-
/* istanbul ignore else should not happen */
|
|
78
|
-
if (token.source)
|
|
79
|
-
length += token.source.length;
|
|
80
89
|
}
|
|
90
|
+
const last = tokens[tokens.length - 1];
|
|
91
|
+
const end = last ? last.offset + last.source.length : offset;
|
|
81
92
|
return {
|
|
93
|
+
comma,
|
|
82
94
|
found,
|
|
83
95
|
spaceBefore,
|
|
84
96
|
comment,
|
|
85
97
|
hasNewline,
|
|
86
98
|
anchor,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
start: start !== null && start !== void 0 ? start :
|
|
99
|
+
tag,
|
|
100
|
+
end,
|
|
101
|
+
start: start !== null && start !== void 0 ? start : end
|
|
90
102
|
};
|
|
91
103
|
}
|
|
92
104
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Token } from '../parse/
|
|
1
|
+
import type { Token } from '../parse/cst.js';
|
|
2
2
|
export declare function containsNewline(key: Token | null | undefined): boolean | null;
|
|
@@ -8,21 +8,24 @@ function containsNewline(key) {
|
|
|
8
8
|
case 'scalar':
|
|
9
9
|
case 'double-quoted-scalar':
|
|
10
10
|
case 'single-quoted-scalar':
|
|
11
|
-
|
|
11
|
+
if (key.source.includes('\n'))
|
|
12
|
+
return true;
|
|
13
|
+
if (key.end)
|
|
14
|
+
for (const st of key.end)
|
|
15
|
+
if (st.type === 'newline')
|
|
16
|
+
return true;
|
|
17
|
+
return false;
|
|
12
18
|
case 'flow-collection':
|
|
13
|
-
for (const
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
for (const it of key.items) {
|
|
20
|
+
for (const st of it.start)
|
|
21
|
+
if (st.type === 'newline')
|
|
16
22
|
return true;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
case 'single-quoted-scalar':
|
|
21
|
-
case 'flow-collection':
|
|
22
|
-
if (containsNewline(token))
|
|
23
|
+
if (it.sep)
|
|
24
|
+
for (const st of it.sep)
|
|
25
|
+
if (st.type === 'newline')
|
|
23
26
|
return true;
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
if (containsNewline(it.key) || containsNewline(it.value))
|
|
28
|
+
return true;
|
|
26
29
|
}
|
|
27
30
|
return false;
|
|
28
31
|
default:
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Token } from '../parse/
|
|
1
|
+
import type { Token } from '../parse/cst.js';
|
|
2
2
|
export declare function emptyScalarPosition(offset: number, before: Token[] | undefined, pos: number | null): number;
|
package/dist/doc/Document.d.ts
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
1
|
import type { YAMLError, YAMLWarning } from '../errors.js';
|
|
2
|
-
import {
|
|
2
|
+
import { Alias } from '../nodes/Alias.js';
|
|
3
|
+
import { Node, NODE_TYPE, ParsedNode, Range } from '../nodes/Node.js';
|
|
3
4
|
import { Pair } from '../nodes/Pair.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import type { Scalar } from '../nodes/Scalar.js';
|
|
6
|
+
import type { YAMLMap } from '../nodes/YAMLMap.js';
|
|
7
|
+
import type { YAMLSeq } from '../nodes/YAMLSeq.js';
|
|
8
|
+
import { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from '../options.js';
|
|
9
|
+
import { Schema } from '../schema/Schema.js';
|
|
7
10
|
import { Directives } from './directives.js';
|
|
8
11
|
export declare type Replacer = any[] | ((key: any, value: any) => unknown);
|
|
9
12
|
export declare namespace Document {
|
|
10
13
|
interface Parsed<T extends ParsedNode = ParsedNode> extends Document<T> {
|
|
11
|
-
range:
|
|
12
|
-
/** The schema used with the document. */
|
|
13
|
-
schema: Schema;
|
|
14
|
+
range: Range;
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
export declare class Document<T = unknown> {
|
|
17
18
|
readonly [NODE_TYPE]: symbol;
|
|
18
|
-
/**
|
|
19
|
-
* Anchors associated with the document's nodes;
|
|
20
|
-
* also provides alias & merge node creators.
|
|
21
|
-
*/
|
|
22
|
-
anchors: Anchors;
|
|
23
19
|
/** A comment before this Document */
|
|
24
20
|
commentBefore: string | null;
|
|
25
21
|
/** A comment immediately after this Document */
|
|
@@ -30,6 +26,11 @@ export declare class Document<T = unknown> {
|
|
|
30
26
|
/** Errors encountered during parsing. */
|
|
31
27
|
errors: YAMLError[];
|
|
32
28
|
options: Required<Omit<ParseOptions & DocumentOptions, 'lineCounter' | 'directives' | 'version'>>;
|
|
29
|
+
/**
|
|
30
|
+
* The [start, value-end, node-end] character offsets for the part of the
|
|
31
|
+
* source parsed into this document (undefined if not parsed).
|
|
32
|
+
*/
|
|
33
|
+
range?: Range;
|
|
33
34
|
/** The schema used with the document. Use `setSchema()` to change. */
|
|
34
35
|
schema: Schema;
|
|
35
36
|
/** Warnings encountered during parsing. */
|
|
@@ -38,17 +39,28 @@ export declare class Document<T = unknown> {
|
|
|
38
39
|
* @param value - The initial value for the document, which will be wrapped
|
|
39
40
|
* in a Node container.
|
|
40
41
|
*/
|
|
41
|
-
constructor(value?: any, options?:
|
|
42
|
-
constructor(value: any, replacer: null | Replacer, options?:
|
|
42
|
+
constructor(value?: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions);
|
|
43
|
+
constructor(value: any, replacer: null | Replacer, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions);
|
|
43
44
|
/** Adds a value to the document. */
|
|
44
45
|
add(value: any): void;
|
|
45
46
|
/** Adds a value to the document. */
|
|
46
47
|
addIn(path: Iterable<unknown>, value: unknown): void;
|
|
48
|
+
/**
|
|
49
|
+
* Create a new `Alias` node, ensuring that the target `node` has the required anchor.
|
|
50
|
+
*
|
|
51
|
+
* If `node` already has an anchor, `name` is ignored.
|
|
52
|
+
* Otherwise, the `node.anchor` value will be set to `name`,
|
|
53
|
+
* or if an anchor with that name is already present in the document,
|
|
54
|
+
* `name` will be used as a prefix for a new unique anchor.
|
|
55
|
+
* If `name` is undefined, the generated anchor will use 'a' as a prefix.
|
|
56
|
+
*/
|
|
57
|
+
createAlias(node: Scalar | YAMLMap | YAMLSeq, name?: string): Alias;
|
|
47
58
|
/**
|
|
48
59
|
* Convert any value into a `Node` using the current schema, recursively
|
|
49
60
|
* turning objects into collections.
|
|
50
61
|
*/
|
|
51
|
-
createNode(value: unknown,
|
|
62
|
+
createNode(value: unknown, options?: CreateNodeOptions): Node;
|
|
63
|
+
createNode(value: unknown, replacer: Replacer | CreateNodeOptions | null, options?: CreateNodeOptions): Node;
|
|
52
64
|
/**
|
|
53
65
|
* Convert a key and a value into a `Pair` using the current schema,
|
|
54
66
|
* recursively wrapping all values as `Scalar` or `Collection` nodes.
|