yaml 1.9.2 → 1.10.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/README.md +4 -4
- package/browser/dist/PlainValue-ff5147c6.js +1277 -0
- package/browser/dist/Schema-2bf2c74e.js +679 -0
- package/browser/dist/index.js +869 -34
- package/browser/dist/legacy-exports.js +3 -0
- package/browser/dist/parse-cst.js +1904 -0
- package/browser/dist/resolveSeq-04825f30.js +2373 -0
- package/browser/dist/types.js +4 -0
- package/browser/dist/util.js +2 -0
- package/browser/dist/warnings-0e4b70d3.js +499 -0
- package/browser/index.js +1 -1
- package/browser/map.js +2 -4
- package/browser/pair.js +2 -4
- package/browser/parse-cst.js +1 -1
- package/browser/scalar.js +2 -4
- package/browser/schema.js +7 -10
- package/browser/seq.js +2 -4
- package/browser/types/binary.js +7 -5
- package/browser/types/omap.js +3 -4
- package/browser/types/pairs.js +3 -4
- package/browser/types/set.js +3 -4
- package/browser/types/timestamp.js +9 -5
- package/browser/types.js +1 -13
- package/browser/util.js +1 -18
- package/dist/Document-2cf6b08c.js +757 -0
- package/dist/PlainValue-ec8e588e.js +876 -0
- package/dist/Schema-42e9705c.js +522 -0
- package/dist/index.js +20 -84
- package/dist/legacy-exports.js +16 -0
- package/dist/parse-cst.js +1747 -0
- package/dist/resolveSeq-4a68b39b.js +2115 -0
- package/dist/test-events.js +11 -9
- package/dist/types.js +23 -0
- package/dist/util.js +19 -0
- package/dist/warnings-39684f17.js +416 -0
- package/index.d.ts +22 -8
- package/map.js +2 -2
- package/package.json +22 -39
- package/pair.js +2 -2
- package/parse-cst.js +1 -1
- package/scalar.js +2 -2
- package/schema.js +8 -6
- package/seq.js +2 -2
- package/types/binary.js +3 -2
- package/types/omap.js +3 -2
- package/types/pairs.js +3 -2
- package/types/set.js +3 -2
- package/types/timestamp.js +6 -6
- package/types.d.ts +113 -99
- package/types.js +16 -11
- package/types.mjs +15 -19
- package/util.js +14 -14
- package/util.mjs +13 -20
- package/browser/dist/Anchors.js +0 -130
- package/browser/dist/Document.js +0 -824
- package/browser/dist/addComment.js +0 -8
- package/browser/dist/constants.js +0 -26
- package/browser/dist/cst/Alias.js +0 -46
- package/browser/dist/cst/BlankLine.js +0 -52
- package/browser/dist/cst/BlockValue.js +0 -251
- package/browser/dist/cst/Collection.js +0 -278
- package/browser/dist/cst/CollectionItem.js +0 -140
- package/browser/dist/cst/Comment.js +0 -44
- package/browser/dist/cst/Directive.js +0 -76
- package/browser/dist/cst/Document.js +0 -286
- package/browser/dist/cst/FlowCollection.js +0 -220
- package/browser/dist/cst/Node.js +0 -386
- package/browser/dist/cst/ParseContext.js +0 -246
- package/browser/dist/cst/PlainValue.js +0 -170
- package/browser/dist/cst/QuoteDouble.js +0 -245
- package/browser/dist/cst/QuoteSingle.js +0 -120
- package/browser/dist/cst/Range.js +0 -64
- package/browser/dist/cst/parse.js +0 -48
- package/browser/dist/cst/source-utils.js +0 -168
- package/browser/dist/errors.js +0 -127
- package/browser/dist/foldFlowLines.js +0 -138
- package/browser/dist/listTagNames.js +0 -28
- package/browser/dist/schema/Alias.js +0 -135
- package/browser/dist/schema/Collection.js +0 -260
- package/browser/dist/schema/Map.js +0 -161
- package/browser/dist/schema/Merge.js +0 -118
- package/browser/dist/schema/Node.js +0 -4
- package/browser/dist/schema/Pair.js +0 -194
- package/browser/dist/schema/Scalar.js +0 -42
- package/browser/dist/schema/Seq.js +0 -116
- package/browser/dist/schema/index.js +0 -368
- package/browser/dist/schema/parseMap.js +0 -312
- package/browser/dist/schema/parseSeq.js +0 -168
- package/browser/dist/schema/parseUtils.js +0 -106
- package/browser/dist/stringify.js +0 -332
- package/browser/dist/tags/core.js +0 -141
- package/browser/dist/tags/failsafe/index.js +0 -4
- package/browser/dist/tags/failsafe/map.js +0 -53
- package/browser/dist/tags/failsafe/seq.js +0 -39
- package/browser/dist/tags/failsafe/string.js +0 -28
- package/browser/dist/tags/index.js +0 -36
- package/browser/dist/tags/json.js +0 -77
- package/browser/dist/tags/options.js +0 -26
- package/browser/dist/tags/yaml-1.1/binary.js +0 -87
- package/browser/dist/tags/yaml-1.1/index.js +0 -189
- package/browser/dist/tags/yaml-1.1/omap.js +0 -137
- package/browser/dist/tags/yaml-1.1/pairs.js +0 -78
- package/browser/dist/tags/yaml-1.1/set.js +0 -118
- package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
- package/browser/dist/test-events.js +0 -163
- package/browser/dist/toJSON.js +0 -19
- package/browser/dist/warnings.js +0 -39
- package/dist/Anchors.js +0 -120
- package/dist/Document.js +0 -714
- package/dist/addComment.js +0 -14
- package/dist/constants.js +0 -31
- package/dist/cst/Alias.js +0 -33
- package/dist/cst/BlankLine.js +0 -40
- package/dist/cst/BlockValue.js +0 -243
- package/dist/cst/Collection.js +0 -266
- package/dist/cst/CollectionItem.js +0 -135
- package/dist/cst/Comment.js +0 -33
- package/dist/cst/Directive.js +0 -59
- package/dist/cst/Document.js +0 -276
- package/dist/cst/FlowCollection.js +0 -213
- package/dist/cst/Node.js +0 -360
- package/dist/cst/ParseContext.js +0 -253
- package/dist/cst/PlainValue.js +0 -156
- package/dist/cst/QuoteDouble.js +0 -232
- package/dist/cst/QuoteSingle.js +0 -108
- package/dist/cst/Range.js +0 -60
- package/dist/cst/parse.js +0 -50
- package/dist/cst/source-utils.js +0 -175
- package/dist/errors.js +0 -97
- package/dist/foldFlowLines.js +0 -143
- package/dist/listTagNames.js +0 -33
- package/dist/schema/Alias.js +0 -105
- package/dist/schema/Collection.js +0 -184
- package/dist/schema/Map.js +0 -98
- package/dist/schema/Merge.js +0 -75
- package/dist/schema/Node.js +0 -7
- package/dist/schema/Pair.js +0 -174
- package/dist/schema/Scalar.js +0 -26
- package/dist/schema/Seq.js +0 -73
- package/dist/schema/index.js +0 -310
- package/dist/schema/parseMap.js +0 -334
- package/dist/schema/parseSeq.js +0 -175
- package/dist/schema/parseUtils.js +0 -101
- package/dist/stringify.js +0 -352
- package/dist/tags/core.js +0 -121
- package/dist/tags/failsafe/index.js +0 -12
- package/dist/tags/failsafe/map.js +0 -32
- package/dist/tags/failsafe/seq.js +0 -29
- package/dist/tags/failsafe/string.js +0 -37
- package/dist/tags/index.js +0 -53
- package/dist/tags/json.js +0 -64
- package/dist/tags/options.js +0 -36
- package/dist/tags/yaml-1.1/binary.js +0 -94
- package/dist/tags/yaml-1.1/index.js +0 -162
- package/dist/tags/yaml-1.1/omap.js +0 -100
- package/dist/tags/yaml-1.1/pairs.js +0 -75
- package/dist/tags/yaml-1.1/set.js +0 -82
- package/dist/tags/yaml-1.1/timestamp.js +0 -90
- package/dist/toJSON.js +0 -21
- package/dist/warnings.js +0 -48
package/dist/cst/Node.js
DELETED
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.Node = void 0;
|
|
4
|
-
|
|
5
|
-
var _constants = require("../constants");
|
|
6
|
-
|
|
7
|
-
var _sourceUtils = require("./source-utils");
|
|
8
|
-
|
|
9
|
-
var _Range = require("./Range");
|
|
10
|
-
|
|
11
|
-
/** Root class of all nodes */
|
|
12
|
-
class Node {
|
|
13
|
-
static addStringTerminator(src, offset, str) {
|
|
14
|
-
if (str[str.length - 1] === '\n') return str;
|
|
15
|
-
const next = Node.endOfWhiteSpace(src, offset);
|
|
16
|
-
return next >= src.length || src[next] === '\n' ? str + '\n' : str;
|
|
17
|
-
} // ^(---|...)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
static atDocumentBoundary(src, offset, sep) {
|
|
21
|
-
const ch0 = src[offset];
|
|
22
|
-
if (!ch0) return true;
|
|
23
|
-
const prev = src[offset - 1];
|
|
24
|
-
if (prev && prev !== '\n') return false;
|
|
25
|
-
|
|
26
|
-
if (sep) {
|
|
27
|
-
if (ch0 !== sep) return false;
|
|
28
|
-
} else {
|
|
29
|
-
if (ch0 !== _constants.Char.DIRECTIVES_END && ch0 !== _constants.Char.DOCUMENT_END) return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const ch1 = src[offset + 1];
|
|
33
|
-
const ch2 = src[offset + 2];
|
|
34
|
-
if (ch1 !== ch0 || ch2 !== ch0) return false;
|
|
35
|
-
const ch3 = src[offset + 3];
|
|
36
|
-
return !ch3 || ch3 === '\n' || ch3 === '\t' || ch3 === ' ';
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
static endOfIdentifier(src, offset) {
|
|
40
|
-
let ch = src[offset];
|
|
41
|
-
const isVerbatim = ch === '<';
|
|
42
|
-
const notOk = isVerbatim ? ['\n', '\t', ' ', '>'] : ['\n', '\t', ' ', '[', ']', '{', '}', ','];
|
|
43
|
-
|
|
44
|
-
while (ch && notOk.indexOf(ch) === -1) ch = src[offset += 1];
|
|
45
|
-
|
|
46
|
-
if (isVerbatim && ch === '>') offset += 1;
|
|
47
|
-
return offset;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static endOfIndent(src, offset) {
|
|
51
|
-
let ch = src[offset];
|
|
52
|
-
|
|
53
|
-
while (ch === ' ') ch = src[offset += 1];
|
|
54
|
-
|
|
55
|
-
return offset;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
static endOfLine(src, offset) {
|
|
59
|
-
let ch = src[offset];
|
|
60
|
-
|
|
61
|
-
while (ch && ch !== '\n') ch = src[offset += 1];
|
|
62
|
-
|
|
63
|
-
return offset;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static endOfWhiteSpace(src, offset) {
|
|
67
|
-
let ch = src[offset];
|
|
68
|
-
|
|
69
|
-
while (ch === '\t' || ch === ' ') ch = src[offset += 1];
|
|
70
|
-
|
|
71
|
-
return offset;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
static startOfLine(src, offset) {
|
|
75
|
-
let ch = src[offset - 1];
|
|
76
|
-
if (ch === '\n') return offset;
|
|
77
|
-
|
|
78
|
-
while (ch && ch !== '\n') ch = src[offset -= 1];
|
|
79
|
-
|
|
80
|
-
return offset + 1;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* End of indentation, or null if the line's indent level is not more
|
|
84
|
-
* than `indent`
|
|
85
|
-
*
|
|
86
|
-
* @param {string} src
|
|
87
|
-
* @param {number} indent
|
|
88
|
-
* @param {number} lineStart
|
|
89
|
-
* @returns {?number}
|
|
90
|
-
*/
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
static endOfBlockIndent(src, indent, lineStart) {
|
|
94
|
-
const inEnd = Node.endOfIndent(src, lineStart);
|
|
95
|
-
|
|
96
|
-
if (inEnd > lineStart + indent) {
|
|
97
|
-
return inEnd;
|
|
98
|
-
} else {
|
|
99
|
-
const wsEnd = Node.endOfWhiteSpace(src, inEnd);
|
|
100
|
-
const ch = src[wsEnd];
|
|
101
|
-
if (!ch || ch === '\n') return wsEnd;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return null;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
static atBlank(src, offset, endAsBlank) {
|
|
108
|
-
const ch = src[offset];
|
|
109
|
-
return ch === '\n' || ch === '\t' || ch === ' ' || endAsBlank && !ch;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
static nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) {
|
|
113
|
-
if (!ch || indentDiff < 0) return false;
|
|
114
|
-
if (indentDiff > 0) return true;
|
|
115
|
-
return indicatorAsIndent && ch === '-';
|
|
116
|
-
} // should be at line or string end, or at next non-whitespace char
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
static normalizeOffset(src, offset) {
|
|
120
|
-
const ch = src[offset];
|
|
121
|
-
return !ch ? offset : ch !== '\n' && src[offset - 1] === '\n' ? offset - 1 : Node.endOfWhiteSpace(src, offset);
|
|
122
|
-
} // fold single newline into space, multiple newlines to N - 1 newlines
|
|
123
|
-
// presumes src[offset] === '\n'
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
static foldNewline(src, offset, indent) {
|
|
127
|
-
let inCount = 0;
|
|
128
|
-
let error = false;
|
|
129
|
-
let fold = '';
|
|
130
|
-
let ch = src[offset + 1];
|
|
131
|
-
|
|
132
|
-
while (ch === ' ' || ch === '\t' || ch === '\n') {
|
|
133
|
-
switch (ch) {
|
|
134
|
-
case '\n':
|
|
135
|
-
inCount = 0;
|
|
136
|
-
offset += 1;
|
|
137
|
-
fold += '\n';
|
|
138
|
-
break;
|
|
139
|
-
|
|
140
|
-
case '\t':
|
|
141
|
-
if (inCount <= indent) error = true;
|
|
142
|
-
offset = Node.endOfWhiteSpace(src, offset + 2) - 1;
|
|
143
|
-
break;
|
|
144
|
-
|
|
145
|
-
case ' ':
|
|
146
|
-
inCount += 1;
|
|
147
|
-
offset += 1;
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
ch = src[offset + 1];
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (!fold) fold = ' ';
|
|
155
|
-
if (ch && inCount <= indent) error = true;
|
|
156
|
-
return {
|
|
157
|
-
fold,
|
|
158
|
-
offset,
|
|
159
|
-
error
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
constructor(type, props, context) {
|
|
164
|
-
Object.defineProperty(this, 'context', {
|
|
165
|
-
value: context || null,
|
|
166
|
-
writable: true
|
|
167
|
-
});
|
|
168
|
-
this.error = null;
|
|
169
|
-
this.range = null;
|
|
170
|
-
this.valueRange = null;
|
|
171
|
-
this.props = props || [];
|
|
172
|
-
this.type = type;
|
|
173
|
-
this.value = null;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
getPropValue(idx, key, skipKey) {
|
|
177
|
-
if (!this.context) return null;
|
|
178
|
-
const {
|
|
179
|
-
src
|
|
180
|
-
} = this.context;
|
|
181
|
-
const prop = this.props[idx];
|
|
182
|
-
return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
get anchor() {
|
|
186
|
-
for (let i = 0; i < this.props.length; ++i) {
|
|
187
|
-
const anchor = this.getPropValue(i, _constants.Char.ANCHOR, true);
|
|
188
|
-
if (anchor != null) return anchor;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
get comment() {
|
|
195
|
-
const comments = [];
|
|
196
|
-
|
|
197
|
-
for (let i = 0; i < this.props.length; ++i) {
|
|
198
|
-
const comment = this.getPropValue(i, _constants.Char.COMMENT, true);
|
|
199
|
-
if (comment != null) comments.push(comment);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return comments.length > 0 ? comments.join('\n') : null;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
commentHasRequiredWhitespace(start) {
|
|
206
|
-
const {
|
|
207
|
-
src
|
|
208
|
-
} = this.context;
|
|
209
|
-
if (this.header && start === this.header.end) return false;
|
|
210
|
-
if (!this.valueRange) return false;
|
|
211
|
-
const {
|
|
212
|
-
end
|
|
213
|
-
} = this.valueRange;
|
|
214
|
-
return start !== end || Node.atBlank(src, end - 1);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
get hasComment() {
|
|
218
|
-
if (this.context) {
|
|
219
|
-
const {
|
|
220
|
-
src
|
|
221
|
-
} = this.context;
|
|
222
|
-
|
|
223
|
-
for (let i = 0; i < this.props.length; ++i) {
|
|
224
|
-
if (src[this.props[i].start] === _constants.Char.COMMENT) return true;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
return false;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
get hasProps() {
|
|
232
|
-
if (this.context) {
|
|
233
|
-
const {
|
|
234
|
-
src
|
|
235
|
-
} = this.context;
|
|
236
|
-
|
|
237
|
-
for (let i = 0; i < this.props.length; ++i) {
|
|
238
|
-
if (src[this.props[i].start] !== _constants.Char.COMMENT) return true;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
get includesTrailingLines() {
|
|
246
|
-
return false;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
get jsonLike() {
|
|
250
|
-
const jsonLikeTypes = [_constants.Type.FLOW_MAP, _constants.Type.FLOW_SEQ, _constants.Type.QUOTE_DOUBLE, _constants.Type.QUOTE_SINGLE];
|
|
251
|
-
return jsonLikeTypes.indexOf(this.type) !== -1;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
get rangeAsLinePos() {
|
|
255
|
-
if (!this.range || !this.context) return undefined;
|
|
256
|
-
const start = (0, _sourceUtils.getLinePos)(this.range.start, this.context.root);
|
|
257
|
-
if (!start) return undefined;
|
|
258
|
-
const end = (0, _sourceUtils.getLinePos)(this.range.end, this.context.root);
|
|
259
|
-
return {
|
|
260
|
-
start,
|
|
261
|
-
end
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
get rawValue() {
|
|
266
|
-
if (!this.valueRange || !this.context) return null;
|
|
267
|
-
const {
|
|
268
|
-
start,
|
|
269
|
-
end
|
|
270
|
-
} = this.valueRange;
|
|
271
|
-
return this.context.src.slice(start, end);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
get tag() {
|
|
275
|
-
for (let i = 0; i < this.props.length; ++i) {
|
|
276
|
-
const tag = this.getPropValue(i, _constants.Char.TAG, false);
|
|
277
|
-
|
|
278
|
-
if (tag != null) {
|
|
279
|
-
if (tag[1] === '<') {
|
|
280
|
-
return {
|
|
281
|
-
verbatim: tag.slice(2, -1)
|
|
282
|
-
};
|
|
283
|
-
} else {
|
|
284
|
-
// eslint-disable-next-line no-unused-vars
|
|
285
|
-
const [_, handle, suffix] = tag.match(/^(.*!)([^!]*)$/);
|
|
286
|
-
return {
|
|
287
|
-
handle,
|
|
288
|
-
suffix
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
get valueRangeContainsNewline() {
|
|
298
|
-
if (!this.valueRange || !this.context) return false;
|
|
299
|
-
const {
|
|
300
|
-
start,
|
|
301
|
-
end
|
|
302
|
-
} = this.valueRange;
|
|
303
|
-
const {
|
|
304
|
-
src
|
|
305
|
-
} = this.context;
|
|
306
|
-
|
|
307
|
-
for (let i = start; i < end; ++i) {
|
|
308
|
-
if (src[i] === '\n') return true;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
return false;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
parseComment(start) {
|
|
315
|
-
const {
|
|
316
|
-
src
|
|
317
|
-
} = this.context;
|
|
318
|
-
|
|
319
|
-
if (src[start] === _constants.Char.COMMENT) {
|
|
320
|
-
const end = Node.endOfLine(src, start + 1);
|
|
321
|
-
const commentRange = new _Range.Range(start, end);
|
|
322
|
-
this.props.push(commentRange);
|
|
323
|
-
return end;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return start;
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* Populates the `origStart` and `origEnd` values of all ranges for this
|
|
330
|
-
* node. Extended by child classes to handle descendant nodes.
|
|
331
|
-
*
|
|
332
|
-
* @param {number[]} cr - Positions of dropped CR characters
|
|
333
|
-
* @param {number} offset - Starting index of `cr` from the last call
|
|
334
|
-
* @returns {number} - The next offset, matching the one found for `origStart`
|
|
335
|
-
*/
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
setOrigRanges(cr, offset) {
|
|
339
|
-
if (this.range) offset = this.range.setOrigRange(cr, offset);
|
|
340
|
-
if (this.valueRange) this.valueRange.setOrigRange(cr, offset);
|
|
341
|
-
this.props.forEach(prop => prop.setOrigRange(cr, offset));
|
|
342
|
-
return offset;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
toString() {
|
|
346
|
-
const {
|
|
347
|
-
context: {
|
|
348
|
-
src
|
|
349
|
-
},
|
|
350
|
-
range,
|
|
351
|
-
value
|
|
352
|
-
} = this;
|
|
353
|
-
if (value != null) return value;
|
|
354
|
-
const str = src.slice(range.start, range.end);
|
|
355
|
-
return Node.addStringTerminator(src, range.end, str);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
exports.Node = Node;
|
package/dist/cst/ParseContext.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.ParseContext = void 0;
|
|
4
|
-
|
|
5
|
-
var _constants = require("../constants");
|
|
6
|
-
|
|
7
|
-
var _errors = require("../errors");
|
|
8
|
-
|
|
9
|
-
var _Alias = require("./Alias");
|
|
10
|
-
|
|
11
|
-
var _BlockValue = require("./BlockValue");
|
|
12
|
-
|
|
13
|
-
var _Collection = require("./Collection");
|
|
14
|
-
|
|
15
|
-
var _CollectionItem = require("./CollectionItem");
|
|
16
|
-
|
|
17
|
-
var _FlowCollection = require("./FlowCollection");
|
|
18
|
-
|
|
19
|
-
var _Node = require("./Node");
|
|
20
|
-
|
|
21
|
-
var _PlainValue = require("./PlainValue");
|
|
22
|
-
|
|
23
|
-
var _QuoteDouble = require("./QuoteDouble");
|
|
24
|
-
|
|
25
|
-
var _QuoteSingle = require("./QuoteSingle");
|
|
26
|
-
|
|
27
|
-
var _Range = require("./Range");
|
|
28
|
-
|
|
29
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
30
|
-
|
|
31
|
-
function createNewNode(type, props) {
|
|
32
|
-
switch (type) {
|
|
33
|
-
case _constants.Type.ALIAS:
|
|
34
|
-
return new _Alias.Alias(type, props);
|
|
35
|
-
|
|
36
|
-
case _constants.Type.BLOCK_FOLDED:
|
|
37
|
-
case _constants.Type.BLOCK_LITERAL:
|
|
38
|
-
return new _BlockValue.BlockValue(type, props);
|
|
39
|
-
|
|
40
|
-
case _constants.Type.FLOW_MAP:
|
|
41
|
-
case _constants.Type.FLOW_SEQ:
|
|
42
|
-
return new _FlowCollection.FlowCollection(type, props);
|
|
43
|
-
|
|
44
|
-
case _constants.Type.MAP_KEY:
|
|
45
|
-
case _constants.Type.MAP_VALUE:
|
|
46
|
-
case _constants.Type.SEQ_ITEM:
|
|
47
|
-
return new _CollectionItem.CollectionItem(type, props);
|
|
48
|
-
|
|
49
|
-
case _constants.Type.COMMENT:
|
|
50
|
-
case _constants.Type.PLAIN:
|
|
51
|
-
return new _PlainValue.PlainValue(type, props);
|
|
52
|
-
|
|
53
|
-
case _constants.Type.QUOTE_DOUBLE:
|
|
54
|
-
return new _QuoteDouble.QuoteDouble(type, props);
|
|
55
|
-
|
|
56
|
-
case _constants.Type.QUOTE_SINGLE:
|
|
57
|
-
return new _QuoteSingle.QuoteSingle(type, props);
|
|
58
|
-
|
|
59
|
-
/* istanbul ignore next */
|
|
60
|
-
|
|
61
|
-
default:
|
|
62
|
-
return null;
|
|
63
|
-
// should never happen
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* @param {boolean} atLineStart - Node starts at beginning of line
|
|
68
|
-
* @param {boolean} inFlow - true if currently in a flow context
|
|
69
|
-
* @param {boolean} inCollection - true if currently in a collection context
|
|
70
|
-
* @param {number} indent - Current level of indentation
|
|
71
|
-
* @param {number} lineStart - Start of the current line
|
|
72
|
-
* @param {Node} parent - The parent of the node
|
|
73
|
-
* @param {string} src - Source of the YAML document
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
class ParseContext {
|
|
78
|
-
static parseType(src, offset, inFlow) {
|
|
79
|
-
switch (src[offset]) {
|
|
80
|
-
case '*':
|
|
81
|
-
return _constants.Type.ALIAS;
|
|
82
|
-
|
|
83
|
-
case '>':
|
|
84
|
-
return _constants.Type.BLOCK_FOLDED;
|
|
85
|
-
|
|
86
|
-
case '|':
|
|
87
|
-
return _constants.Type.BLOCK_LITERAL;
|
|
88
|
-
|
|
89
|
-
case '{':
|
|
90
|
-
return _constants.Type.FLOW_MAP;
|
|
91
|
-
|
|
92
|
-
case '[':
|
|
93
|
-
return _constants.Type.FLOW_SEQ;
|
|
94
|
-
|
|
95
|
-
case '?':
|
|
96
|
-
return !inFlow && _Node.Node.atBlank(src, offset + 1, true) ? _constants.Type.MAP_KEY : _constants.Type.PLAIN;
|
|
97
|
-
|
|
98
|
-
case ':':
|
|
99
|
-
return !inFlow && _Node.Node.atBlank(src, offset + 1, true) ? _constants.Type.MAP_VALUE : _constants.Type.PLAIN;
|
|
100
|
-
|
|
101
|
-
case '-':
|
|
102
|
-
return !inFlow && _Node.Node.atBlank(src, offset + 1, true) ? _constants.Type.SEQ_ITEM : _constants.Type.PLAIN;
|
|
103
|
-
|
|
104
|
-
case '"':
|
|
105
|
-
return _constants.Type.QUOTE_DOUBLE;
|
|
106
|
-
|
|
107
|
-
case "'":
|
|
108
|
-
return _constants.Type.QUOTE_SINGLE;
|
|
109
|
-
|
|
110
|
-
default:
|
|
111
|
-
return _constants.Type.PLAIN;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
constructor(orig = {}, {
|
|
116
|
-
atLineStart,
|
|
117
|
-
inCollection,
|
|
118
|
-
inFlow,
|
|
119
|
-
indent,
|
|
120
|
-
lineStart,
|
|
121
|
-
parent
|
|
122
|
-
} = {}) {
|
|
123
|
-
_defineProperty(this, "parseNode", (overlay, start) => {
|
|
124
|
-
if (_Node.Node.atDocumentBoundary(this.src, start)) return null;
|
|
125
|
-
const context = new ParseContext(this, overlay);
|
|
126
|
-
const {
|
|
127
|
-
props,
|
|
128
|
-
type,
|
|
129
|
-
valueStart
|
|
130
|
-
} = context.parseProps(start);
|
|
131
|
-
const node = createNewNode(type, props);
|
|
132
|
-
let offset = node.parse(context, valueStart);
|
|
133
|
-
node.range = new _Range.Range(start, offset);
|
|
134
|
-
/* istanbul ignore if */
|
|
135
|
-
|
|
136
|
-
if (offset <= start) {
|
|
137
|
-
// This should never happen, but if it does, let's make sure to at least
|
|
138
|
-
// step one character forward to avoid a busy loop.
|
|
139
|
-
node.error = new Error(`Node#parse consumed no characters`);
|
|
140
|
-
node.error.parseEnd = offset;
|
|
141
|
-
node.error.source = node;
|
|
142
|
-
node.range.end = start + 1;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (context.nodeStartsCollection(node)) {
|
|
146
|
-
if (!node.error && !context.atLineStart && context.parent.type === _constants.Type.DOCUMENT) {
|
|
147
|
-
node.error = new _errors.YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)');
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const collection = new _Collection.Collection(node);
|
|
151
|
-
offset = collection.parse(new ParseContext(context), offset);
|
|
152
|
-
collection.range = new _Range.Range(start, offset);
|
|
153
|
-
return collection;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return node;
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
this.atLineStart = atLineStart != null ? atLineStart : orig.atLineStart || false;
|
|
160
|
-
this.inCollection = inCollection != null ? inCollection : orig.inCollection || false;
|
|
161
|
-
this.inFlow = inFlow != null ? inFlow : orig.inFlow || false;
|
|
162
|
-
this.indent = indent != null ? indent : orig.indent;
|
|
163
|
-
this.lineStart = lineStart != null ? lineStart : orig.lineStart;
|
|
164
|
-
this.parent = parent != null ? parent : orig.parent || {};
|
|
165
|
-
this.root = orig.root;
|
|
166
|
-
this.src = orig.src;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
nodeStartsCollection(node) {
|
|
170
|
-
const {
|
|
171
|
-
inCollection,
|
|
172
|
-
inFlow,
|
|
173
|
-
src
|
|
174
|
-
} = this;
|
|
175
|
-
if (inCollection || inFlow) return false;
|
|
176
|
-
if (node instanceof _CollectionItem.CollectionItem) return true; // check for implicit key
|
|
177
|
-
|
|
178
|
-
let offset = node.range.end;
|
|
179
|
-
if (src[offset] === '\n' || src[offset - 1] === '\n') return false;
|
|
180
|
-
offset = _Node.Node.endOfWhiteSpace(src, offset);
|
|
181
|
-
return src[offset] === ':';
|
|
182
|
-
} // Anchor and tag are before type, which determines the node implementation
|
|
183
|
-
// class; hence this intermediate step.
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
parseProps(offset) {
|
|
187
|
-
const {
|
|
188
|
-
inFlow,
|
|
189
|
-
parent,
|
|
190
|
-
src
|
|
191
|
-
} = this;
|
|
192
|
-
const props = [];
|
|
193
|
-
let lineHasProps = false;
|
|
194
|
-
offset = _Node.Node.endOfWhiteSpace(src, offset);
|
|
195
|
-
let ch = src[offset];
|
|
196
|
-
|
|
197
|
-
while (ch === _constants.Char.ANCHOR || ch === _constants.Char.COMMENT || ch === _constants.Char.TAG || ch === '\n') {
|
|
198
|
-
if (ch === '\n') {
|
|
199
|
-
const lineStart = offset + 1;
|
|
200
|
-
|
|
201
|
-
const inEnd = _Node.Node.endOfIndent(src, lineStart);
|
|
202
|
-
|
|
203
|
-
const indentDiff = inEnd - (lineStart + this.indent);
|
|
204
|
-
const noIndicatorAsIndent = parent.type === _constants.Type.SEQ_ITEM && parent.context.atLineStart;
|
|
205
|
-
if (!_Node.Node.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break;
|
|
206
|
-
this.atLineStart = true;
|
|
207
|
-
this.lineStart = lineStart;
|
|
208
|
-
lineHasProps = false;
|
|
209
|
-
offset = inEnd;
|
|
210
|
-
} else if (ch === _constants.Char.COMMENT) {
|
|
211
|
-
const end = _Node.Node.endOfLine(src, offset + 1);
|
|
212
|
-
|
|
213
|
-
props.push(new _Range.Range(offset, end));
|
|
214
|
-
offset = end;
|
|
215
|
-
} else {
|
|
216
|
-
let end = _Node.Node.endOfIdentifier(src, offset + 1);
|
|
217
|
-
|
|
218
|
-
if (ch === _constants.Char.TAG && src[end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, end + 13))) {
|
|
219
|
-
// Let's presume we're dealing with a YAML 1.0 domain tag here, rather
|
|
220
|
-
// than an empty but 'foo.bar' private-tagged node in a flow collection
|
|
221
|
-
// followed without whitespace by a plain string starting with a year
|
|
222
|
-
// or date divided by something.
|
|
223
|
-
end = _Node.Node.endOfIdentifier(src, end + 5);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
props.push(new _Range.Range(offset, end));
|
|
227
|
-
lineHasProps = true;
|
|
228
|
-
offset = _Node.Node.endOfWhiteSpace(src, end);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
ch = src[offset];
|
|
232
|
-
} // '- &a : b' has an anchor on an empty node
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
if (lineHasProps && ch === ':' && _Node.Node.atBlank(src, offset + 1, true)) offset -= 1;
|
|
236
|
-
const type = ParseContext.parseType(src, offset, inFlow);
|
|
237
|
-
return {
|
|
238
|
-
props,
|
|
239
|
-
type,
|
|
240
|
-
valueStart: offset
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Parses a node from the source
|
|
245
|
-
* @param {ParseContext} overlay
|
|
246
|
-
* @param {number} start - Index of first non-whitespace character for the node
|
|
247
|
-
* @returns {?Node} - null if at a document boundary
|
|
248
|
-
*/
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
exports.ParseContext = ParseContext;
|