yaml 1.5.1 → 1.7.2
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/Document.js +25 -5
- package/browser/dist/cst/CollectionItem.js +27 -6
- package/browser/dist/cst/Document.js +9 -1
- package/browser/dist/cst/FlowCollection.js +9 -1
- package/browser/dist/cst/Node.js +7 -4
- package/browser/dist/cst/PlainValue.js +1 -1
- package/browser/dist/cst/source-utils.js +179 -0
- package/browser/dist/errors.js +36 -3
- package/browser/dist/index.js +5 -4
- package/browser/dist/schema/Alias.js +1 -1
- package/browser/dist/schema/Merge.js +1 -1
- package/browser/dist/schema/Pair.js +17 -2
- package/browser/dist/schema/index.js +4 -3
- package/browser/dist/schema/parseMap.js +17 -4
- package/browser/dist/schema/parseSeq.js +22 -6
- package/browser/dist/schema/parseUtils.js +49 -0
- package/browser/dist/stringify.js +4 -3
- package/browser/dist/tags/failsafe/map.js +2 -2
- package/browser/dist/{deprecation.js → warnings.js} +13 -7
- package/browser/map.js +1 -1
- package/browser/pair.js +1 -1
- package/browser/scalar.js +1 -1
- package/browser/schema.js +1 -1
- package/browser/seq.js +1 -1
- package/browser/types/binary.js +1 -1
- package/browser/types/omap.js +1 -1
- package/browser/types/pairs.js +1 -1
- package/browser/types/set.js +1 -1
- package/browser/types/timestamp.js +1 -1
- package/dist/Document.js +32 -12
- package/dist/cst/CollectionItem.js +27 -6
- package/dist/cst/Document.js +9 -1
- package/dist/cst/FlowCollection.js +9 -1
- package/dist/cst/Node.js +7 -4
- package/dist/cst/PlainValue.js +1 -1
- package/dist/cst/source-utils.js +178 -0
- package/dist/errors.js +37 -3
- package/dist/index.js +5 -4
- package/dist/schema/Alias.js +1 -1
- package/dist/schema/Merge.js +4 -5
- package/dist/schema/Pair.js +19 -2
- package/dist/schema/index.js +4 -3
- package/dist/schema/parseMap.js +20 -5
- package/dist/schema/parseSeq.js +19 -6
- package/dist/schema/parseUtils.js +54 -6
- package/dist/stringify.js +7 -4
- package/dist/tags/yaml-1.1/omap.js +3 -5
- package/dist/tags/yaml-1.1/set.js +3 -1
- package/dist/{deprecation.js → warnings.js} +12 -7
- package/map.js +1 -1
- package/package.json +18 -16
- package/pair.js +1 -1
- package/scalar.js +1 -1
- package/schema.js +1 -1
- package/seq.js +1 -1
- package/types/binary.js +1 -1
- package/types/omap.js +1 -1
- package/types/pairs.js +1 -1
- package/types/set.js +1 -1
- package/types/timestamp.js +1 -1
- package/browser/dist/cst/getLinePos.js +0 -79
- package/dist/cst/getLinePos.js +0 -79
|
@@ -17,6 +17,8 @@ var _parseUtils = require("./parseUtils");
|
|
|
17
17
|
|
|
18
18
|
var _Seq = _interopRequireDefault(require("./Seq"));
|
|
19
19
|
|
|
20
|
+
var _Collection = _interopRequireDefault(require("./Collection"));
|
|
21
|
+
|
|
20
22
|
function parseSeq(doc, cst) {
|
|
21
23
|
if (cst.type !== _constants.Type.SEQ && cst.type !== _constants.Type.FLOW_SEQ) {
|
|
22
24
|
var msg = "A ".concat(cst.type, " node cannot be resolved as a sequence");
|
|
@@ -31,6 +33,14 @@ function parseSeq(doc, cst) {
|
|
|
31
33
|
var seq = new _Seq.default();
|
|
32
34
|
seq.items = items;
|
|
33
35
|
(0, _parseUtils.resolveComments)(seq, comments);
|
|
36
|
+
|
|
37
|
+
if (!doc.options.mapAsMap && items.some(function (it) {
|
|
38
|
+
return it instanceof _Pair.default && it.key instanceof _Collection.default;
|
|
39
|
+
})) {
|
|
40
|
+
var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
|
|
41
|
+
doc.warnings.push(new _errors.YAMLWarning(cst, warn));
|
|
42
|
+
}
|
|
43
|
+
|
|
34
44
|
cst.resolved = seq;
|
|
35
45
|
return seq;
|
|
36
46
|
}
|
|
@@ -91,7 +101,8 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
91
101
|
var item = cst.items[i];
|
|
92
102
|
|
|
93
103
|
if (typeof item.char === 'string') {
|
|
94
|
-
var char = item.char
|
|
104
|
+
var char = item.char,
|
|
105
|
+
offset = item.offset;
|
|
95
106
|
|
|
96
107
|
if (char !== ':' && (explicitKey || key !== undefined)) {
|
|
97
108
|
if (explicitKey && key === undefined) key = next ? items.pop() : null;
|
|
@@ -110,8 +121,10 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
110
121
|
key = items.pop();
|
|
111
122
|
|
|
112
123
|
if (key instanceof _Pair.default) {
|
|
113
|
-
var msg = 'Chaining flow sequence pairs is invalid
|
|
114
|
-
|
|
124
|
+
var msg = 'Chaining flow sequence pairs is invalid';
|
|
125
|
+
var err = new _errors.YAMLSemanticError(cst, msg);
|
|
126
|
+
err.offset = offset;
|
|
127
|
+
doc.errors.push(err);
|
|
115
128
|
}
|
|
116
129
|
|
|
117
130
|
if (!explicitKey) (0, _parseUtils.checkKeyLength)(doc.errors, cst, i, key, keyStart);
|
|
@@ -126,7 +139,10 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
126
139
|
} else if (next === '[' || char !== ']' || i < cst.items.length - 1) {
|
|
127
140
|
var _msg = "Flow sequence contains an unexpected ".concat(char);
|
|
128
141
|
|
|
129
|
-
|
|
142
|
+
var _err = new _errors.YAMLSyntaxError(cst, _msg);
|
|
143
|
+
|
|
144
|
+
_err.offset = offset;
|
|
145
|
+
doc.errors.push(_err);
|
|
130
146
|
}
|
|
131
147
|
} else if (item.type === _constants.Type.BLANK_LINE) {
|
|
132
148
|
comments.push({
|
|
@@ -139,7 +155,7 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
139
155
|
});
|
|
140
156
|
} else {
|
|
141
157
|
if (next) {
|
|
142
|
-
var _msg2 = "Expected a ".concat(next, "
|
|
158
|
+
var _msg2 = "Expected a ".concat(next, " in flow sequence");
|
|
143
159
|
|
|
144
160
|
doc.errors.push(new _errors.YAMLSemanticError(item, _msg2));
|
|
145
161
|
}
|
|
@@ -158,7 +174,7 @@ function resolveFlowSeqItems(doc, cst) {
|
|
|
158
174
|
}
|
|
159
175
|
}
|
|
160
176
|
|
|
161
|
-
|
|
177
|
+
(0, _parseUtils.checkFlowCollectionEnd)(doc.errors, cst);
|
|
162
178
|
if (key !== undefined) items.push(new _Pair.default(key));
|
|
163
179
|
return {
|
|
164
180
|
comments: comments,
|
|
@@ -3,11 +3,60 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.checkFlowCollectionEnd = checkFlowCollectionEnd;
|
|
6
7
|
exports.checkKeyLength = checkKeyLength;
|
|
7
8
|
exports.resolveComments = resolveComments;
|
|
8
9
|
|
|
9
10
|
var _errors = require("../errors");
|
|
10
11
|
|
|
12
|
+
var _constants = require("../constants");
|
|
13
|
+
|
|
14
|
+
function checkFlowCollectionEnd(errors, cst) {
|
|
15
|
+
var char, name;
|
|
16
|
+
|
|
17
|
+
switch (cst.type) {
|
|
18
|
+
case _constants.Type.FLOW_MAP:
|
|
19
|
+
char = '}';
|
|
20
|
+
name = 'flow map';
|
|
21
|
+
break;
|
|
22
|
+
|
|
23
|
+
case _constants.Type.FLOW_SEQ:
|
|
24
|
+
char = ']';
|
|
25
|
+
name = 'flow sequence';
|
|
26
|
+
break;
|
|
27
|
+
|
|
28
|
+
default:
|
|
29
|
+
errors.push(new _errors.YAMLSemanticError(cst, 'Not a flow collection!?'));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var lastItem;
|
|
34
|
+
|
|
35
|
+
for (var i = cst.items.length - 1; i >= 0; --i) {
|
|
36
|
+
var item = cst.items[i];
|
|
37
|
+
|
|
38
|
+
if (!item || item.type !== _constants.Type.COMMENT) {
|
|
39
|
+
lastItem = item;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (lastItem && lastItem.char !== char) {
|
|
45
|
+
var msg = "Expected ".concat(name, " to end with ").concat(char);
|
|
46
|
+
var err;
|
|
47
|
+
|
|
48
|
+
if (typeof lastItem.offset === 'number') {
|
|
49
|
+
err = new _errors.YAMLSemanticError(cst, msg);
|
|
50
|
+
err.offset = lastItem.offset + 1;
|
|
51
|
+
} else {
|
|
52
|
+
err = new _errors.YAMLSemanticError(lastItem, msg);
|
|
53
|
+
if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
errors.push(err);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
11
60
|
function checkKeyLength(errors, node, itemIdx, key, keyStart) {
|
|
12
61
|
if (!key || typeof keyStart !== 'number') return;
|
|
13
62
|
var item = node.items[itemIdx];
|
|
@@ -265,10 +265,11 @@ function plainString(item, ctx, onComment, onChompKeep) {
|
|
|
265
265
|
return blockString(item, ctx, onComment, onChompKeep);
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
var str = value.replace(/\n+/g, "$&\n".concat(indent)); //
|
|
269
|
-
//
|
|
268
|
+
var str = value.replace(/\n+/g, "$&\n".concat(indent)); // Verify that output will be parsed as a string, as e.g. plain numbers and
|
|
269
|
+
// booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
|
|
270
|
+
// and others in v1.1.
|
|
270
271
|
|
|
271
|
-
if (actualString &&
|
|
272
|
+
if (actualString && typeof tags.resolveScalar(str).value !== 'string') {
|
|
272
273
|
return doubleQuotedString(value, ctx);
|
|
273
274
|
}
|
|
274
275
|
|
|
@@ -47,8 +47,8 @@ function createMap(schema, obj, ctx) {
|
|
|
47
47
|
}
|
|
48
48
|
} else if (obj && (0, _typeof2.default)(obj) === 'object') {
|
|
49
49
|
for (var _i = 0, _Object$keys = Object.keys(obj); _i < _Object$keys.length; _i++) {
|
|
50
|
-
var
|
|
51
|
-
map.items.push(schema.createPair(
|
|
50
|
+
var _key = _Object$keys[_i];
|
|
51
|
+
map.items.push(schema.createPair(_key, obj[_key], ctx));
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -3,23 +3,29 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.warn = warn;
|
|
6
7
|
exports.warnFileDeprecation = warnFileDeprecation;
|
|
7
8
|
exports.warnOptionDeprecation = warnOptionDeprecation;
|
|
8
9
|
|
|
9
10
|
/* global global, console */
|
|
10
|
-
function warn(
|
|
11
|
-
if (global && global.
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
function warn(warning, type) {
|
|
12
|
+
if (global && global._YAML_SILENCE_WARNINGS) return;
|
|
13
|
+
|
|
14
|
+
var _ref = global && global.process,
|
|
15
|
+
emitWarning = _ref.emitWarning; // This will throw in Jest if `warning` is an Error instance due to
|
|
16
|
+
// https://github.com/facebook/jest/issues/2549
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
if (emitWarning) emitWarning(warning, type);else {
|
|
14
20
|
// eslint-disable-next-line no-console
|
|
15
|
-
console.warn("
|
|
21
|
+
console.warn(type ? "".concat(type, ": ").concat(warning) : warning);
|
|
16
22
|
}
|
|
17
23
|
}
|
|
18
24
|
|
|
19
25
|
function warnFileDeprecation(filename) {
|
|
20
26
|
if (global && global._YAML_SILENCE_DEPRECATION_WARNINGS) return;
|
|
21
27
|
var path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/');
|
|
22
|
-
warn("The endpoint 'yaml/".concat(path, "' will be removed in a future release."));
|
|
28
|
+
warn("The endpoint 'yaml/".concat(path, "' will be removed in a future release."), 'DeprecationWarning');
|
|
23
29
|
}
|
|
24
30
|
|
|
25
31
|
var warned = {};
|
|
@@ -30,5 +36,5 @@ function warnOptionDeprecation(name, alternative) {
|
|
|
30
36
|
warned[name] = true;
|
|
31
37
|
var msg = "The option '".concat(name, "' will be removed in a future release");
|
|
32
38
|
msg += alternative ? ", use '".concat(alternative, "' instead.") : '.';
|
|
33
|
-
warn(msg);
|
|
39
|
+
warn(msg, 'DeprecationWarning');
|
|
34
40
|
}
|
package/browser/map.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
module.exports = require('./dist/schema/Map').default
|
|
2
|
-
require('./dist/
|
|
2
|
+
require('./dist/warnings').warnFileDeprecation(__filename)
|
package/browser/pair.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
module.exports = require('./dist/schema/Pair').default
|
|
2
|
-
require('./dist/
|
|
2
|
+
require('./dist/warnings').warnFileDeprecation(__filename)
|
package/browser/scalar.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
module.exports = require('./dist/schema/Scalar').default
|
|
2
|
-
require('./dist/
|
|
2
|
+
require('./dist/warnings').warnFileDeprecation(__filename)
|
package/browser/schema.js
CHANGED
|
@@ -4,4 +4,4 @@ module.exports.nullOptions = opt.nullOptions
|
|
|
4
4
|
module.exports.strOptions = opt.strOptions
|
|
5
5
|
module.exports.stringify = require('./dist/stringify').stringifyString
|
|
6
6
|
|
|
7
|
-
require('./dist/
|
|
7
|
+
require('./dist/warnings').warnFileDeprecation(__filename)
|
package/browser/seq.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
module.exports = require('./dist/schema/Seq').default
|
|
2
|
-
require('./dist/
|
|
2
|
+
require('./dist/warnings').warnFileDeprecation(__filename)
|
package/browser/types/binary.js
CHANGED
|
@@ -4,4 +4,4 @@ Object.defineProperty(exports, '__esModule', { value: true })
|
|
|
4
4
|
exports.binary = require('../dist/tags/yaml-1.1/binary').default
|
|
5
5
|
exports.default = [exports.binary]
|
|
6
6
|
|
|
7
|
-
require('../dist/
|
|
7
|
+
require('../dist/warnings').warnFileDeprecation(__filename)
|
package/browser/types/omap.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
module.exports = require('../dist/tags/yaml-1.1/omap').default
|
|
2
|
-
require('../dist/
|
|
2
|
+
require('../dist/warnings').warnFileDeprecation(__filename)
|
package/browser/types/pairs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
module.exports = require('../dist/tags/yaml-1.1/pairs').default
|
|
2
|
-
require('../dist/
|
|
2
|
+
require('../dist/warnings').warnFileDeprecation(__filename)
|
package/browser/types/set.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
module.exports = require('../dist/tags/yaml-1.1/set').default
|
|
2
|
-
require('../dist/
|
|
2
|
+
require('../dist/warnings').warnFileDeprecation(__filename)
|
package/dist/Document.js
CHANGED
|
@@ -27,7 +27,9 @@ var _Scalar = _interopRequireDefault(require("./schema/Scalar"));
|
|
|
27
27
|
|
|
28
28
|
var _toJSON = _interopRequireDefault(require("./toJSON"));
|
|
29
29
|
|
|
30
|
-
function
|
|
30
|
+
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
|
|
31
|
+
|
|
32
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
33
|
|
|
32
34
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
35
|
|
|
@@ -41,6 +43,7 @@ class Document {
|
|
|
41
43
|
this.commentBefore = null;
|
|
42
44
|
this.comment = null;
|
|
43
45
|
this.contents = null;
|
|
46
|
+
this.directivesEndMarker = null;
|
|
44
47
|
this.errors = [];
|
|
45
48
|
this.options = options;
|
|
46
49
|
this.schema = null;
|
|
@@ -114,8 +117,20 @@ class Document {
|
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
119
|
|
|
117
|
-
setSchema() {
|
|
118
|
-
if (!
|
|
120
|
+
setSchema(id, customTags) {
|
|
121
|
+
if (!id && !customTags && this.schema) return;
|
|
122
|
+
if (typeof id === 'number') id = id.toFixed(1);
|
|
123
|
+
|
|
124
|
+
if (id === '1.0' || id === '1.1' || id === '1.2') {
|
|
125
|
+
if (this.version) this.version = id;else this.options.version = id;
|
|
126
|
+
delete this.options.schema;
|
|
127
|
+
} else if (id && typeof id === 'string') {
|
|
128
|
+
this.options.schema = id;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
if (Array.isArray(customTags)) this.options.customTags = customTags;
|
|
132
|
+
const opt = Object.assign({}, this.getDefaults(), this.options);
|
|
133
|
+
this.schema = new _schema.default(opt);
|
|
119
134
|
}
|
|
120
135
|
|
|
121
136
|
parse(node, prevDoc) {
|
|
@@ -124,6 +139,7 @@ class Document {
|
|
|
124
139
|
const {
|
|
125
140
|
directives = [],
|
|
126
141
|
contents = [],
|
|
142
|
+
directivesEndMarker,
|
|
127
143
|
error,
|
|
128
144
|
valueRange
|
|
129
145
|
} = node;
|
|
@@ -134,6 +150,7 @@ class Document {
|
|
|
134
150
|
}
|
|
135
151
|
|
|
136
152
|
this.parseDirectives(directives, prevDoc);
|
|
153
|
+
if (directivesEndMarker) this.directivesEndMarker = true;
|
|
137
154
|
this.range = valueRange ? [valueRange.start, valueRange.end] : null;
|
|
138
155
|
this.setSchema();
|
|
139
156
|
this.anchors._cstAliases = [];
|
|
@@ -400,12 +417,10 @@ class Document {
|
|
|
400
417
|
};
|
|
401
418
|
const props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
|
|
402
419
|
|
|
403
|
-
for (const
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
} = _ref;
|
|
408
|
-
|
|
420
|
+
for (const {
|
|
421
|
+
start,
|
|
422
|
+
end
|
|
423
|
+
} of props) {
|
|
409
424
|
switch (node.context.src[start]) {
|
|
410
425
|
case _constants.Char.COMMENT:
|
|
411
426
|
{
|
|
@@ -592,7 +607,6 @@ class Document {
|
|
|
592
607
|
if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
|
|
593
608
|
this.setSchema();
|
|
594
609
|
const lines = [];
|
|
595
|
-
if (this.commentBefore) lines.push(this.commentBefore.replace(/^/gm, '#'), '');
|
|
596
610
|
let hasDirectives = false;
|
|
597
611
|
|
|
598
612
|
if (this.version) {
|
|
@@ -616,7 +630,13 @@ class Document {
|
|
|
616
630
|
hasDirectives = true;
|
|
617
631
|
}
|
|
618
632
|
});
|
|
619
|
-
if (hasDirectives) lines.push('---');
|
|
633
|
+
if (hasDirectives || this.directivesEndMarker) lines.push('---');
|
|
634
|
+
|
|
635
|
+
if (this.commentBefore) {
|
|
636
|
+
if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
|
|
637
|
+
lines.unshift(this.commentBefore.replace(/^/gm, '#'));
|
|
638
|
+
}
|
|
639
|
+
|
|
620
640
|
const ctx = {
|
|
621
641
|
anchors: {},
|
|
622
642
|
doc: this,
|
|
@@ -627,7 +647,7 @@ class Document {
|
|
|
627
647
|
|
|
628
648
|
if (this.contents) {
|
|
629
649
|
if (this.contents instanceof _Node.default) {
|
|
630
|
-
if (this.contents.spaceBefore && hasDirectives) lines.push('');
|
|
650
|
+
if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
|
|
631
651
|
if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
|
|
632
652
|
|
|
633
653
|
ctx.forceBlockIndent = !!this.comment;
|
|
@@ -49,12 +49,15 @@ class CollectionItem extends _Node.default {
|
|
|
49
49
|
let offset = _Node.default.endOfWhiteSpace(src, start + 1);
|
|
50
50
|
|
|
51
51
|
let ch = src[offset];
|
|
52
|
+
const inlineComment = ch === '#';
|
|
53
|
+
const comments = [];
|
|
54
|
+
let blankLine = null;
|
|
52
55
|
|
|
53
56
|
while (ch === '\n' || ch === '#') {
|
|
54
57
|
if (ch === '#') {
|
|
55
58
|
const end = _Node.default.endOfLine(src, offset + 1);
|
|
56
59
|
|
|
57
|
-
|
|
60
|
+
comments.push(new _Range.default(offset, end));
|
|
58
61
|
offset = end;
|
|
59
62
|
} else {
|
|
60
63
|
atLineStart = true;
|
|
@@ -62,13 +65,11 @@ class CollectionItem extends _Node.default {
|
|
|
62
65
|
|
|
63
66
|
const wsEnd = _Node.default.endOfWhiteSpace(src, lineStart);
|
|
64
67
|
|
|
65
|
-
if (src[wsEnd] === '\n') {
|
|
66
|
-
|
|
68
|
+
if (src[wsEnd] === '\n' && comments.length === 0) {
|
|
69
|
+
blankLine = new _BlankLine.default();
|
|
67
70
|
lineStart = blankLine.parse({
|
|
68
71
|
src
|
|
69
72
|
}, lineStart);
|
|
70
|
-
const items = context.parent.items || context.parent.contents;
|
|
71
|
-
items.push(blankLine);
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
offset = _Node.default.endOfIndent(src, lineStart);
|
|
@@ -85,11 +86,31 @@ class CollectionItem extends _Node.default {
|
|
|
85
86
|
lineStart,
|
|
86
87
|
parent: this
|
|
87
88
|
}, offset);
|
|
88
|
-
if (this.node) offset = this.node.range.end;
|
|
89
89
|
} else if (ch && lineStart > start + 1) {
|
|
90
90
|
offset = lineStart - 1;
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
+
if (this.node) {
|
|
94
|
+
if (blankLine) {
|
|
95
|
+
// Only blank lines preceding non-empty nodes are captured. Note that
|
|
96
|
+
// this means that collection item range start indices do not always
|
|
97
|
+
// increase monotonically. -- eemeli/yaml#126
|
|
98
|
+
const items = context.parent.items || context.parent.contents;
|
|
99
|
+
if (items) items.push(blankLine);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (comments.length) Array.prototype.push.apply(this.props, comments);
|
|
103
|
+
offset = this.node.range.end;
|
|
104
|
+
} else {
|
|
105
|
+
if (inlineComment) {
|
|
106
|
+
const c = comments[0];
|
|
107
|
+
this.props.push(c);
|
|
108
|
+
offset = c.end;
|
|
109
|
+
} else {
|
|
110
|
+
offset = _Node.default.endOfLine(src, start + 1);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
93
114
|
const end = this.node ? this.node.valueRange.end : offset;
|
|
94
115
|
this.valueRange = new _Range.default(start, end);
|
|
95
116
|
return offset;
|
package/dist/cst/Document.js
CHANGED
|
@@ -35,6 +35,8 @@ class Document extends _Node.default {
|
|
|
35
35
|
super(_constants.Type.DOCUMENT);
|
|
36
36
|
this.directives = null;
|
|
37
37
|
this.contents = null;
|
|
38
|
+
this.directivesEndMarker = null;
|
|
39
|
+
this.documentEndMarker = null;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
parseDirectives(start) {
|
|
@@ -103,7 +105,10 @@ class Document extends _Node.default {
|
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
|
|
106
|
-
if (src[offset])
|
|
108
|
+
if (src[offset]) {
|
|
109
|
+
this.directivesEndMarker = new _Range.default(offset, offset + 3);
|
|
110
|
+
return offset + 3;
|
|
111
|
+
}
|
|
107
112
|
|
|
108
113
|
if (hasDirectives) {
|
|
109
114
|
this.error = new _errors.YAMLSemanticError(this, 'Missing directives-end indicator line');
|
|
@@ -190,6 +195,7 @@ class Document extends _Node.default {
|
|
|
190
195
|
this.valueRange.end = offset;
|
|
191
196
|
|
|
192
197
|
if (src[offset]) {
|
|
198
|
+
this.documentEndMarker = new _Range.default(offset, offset + 3);
|
|
193
199
|
offset += 3;
|
|
194
200
|
|
|
195
201
|
if (src[offset]) {
|
|
@@ -244,9 +250,11 @@ class Document extends _Node.default {
|
|
|
244
250
|
this.directives.forEach(node => {
|
|
245
251
|
offset = node.setOrigRanges(cr, offset);
|
|
246
252
|
});
|
|
253
|
+
if (this.directivesEndMarker) offset = this.directivesEndMarker.setOrigRange(cr, offset);
|
|
247
254
|
this.contents.forEach(node => {
|
|
248
255
|
offset = node.setOrigRanges(cr, offset);
|
|
249
256
|
});
|
|
257
|
+
if (this.documentEndMarker) offset = this.documentEndMarker.setOrigRange(cr, offset);
|
|
250
258
|
return offset;
|
|
251
259
|
}
|
|
252
260
|
|
|
@@ -74,7 +74,15 @@ class FlowCollection extends _Node.default {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
offset = _Node.default.endOfIndent(src, lineStart);
|
|
77
|
-
|
|
77
|
+
|
|
78
|
+
if (offset <= lineStart + indent) {
|
|
79
|
+
char = src[offset];
|
|
80
|
+
|
|
81
|
+
if (offset < lineStart + indent || char !== ']' && char !== '}') {
|
|
82
|
+
const msg = 'Insufficient indentation in flow collection';
|
|
83
|
+
this.error = new _errors.YAMLSemanticError(this, msg);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
78
86
|
}
|
|
79
87
|
break;
|
|
80
88
|
|
package/dist/cst/Node.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _constants = require("../constants");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _sourceUtils = require("./source-utils");
|
|
11
11
|
|
|
12
12
|
var _Range = _interopRequireDefault(require("./Range"));
|
|
13
13
|
|
|
@@ -171,7 +171,10 @@ class Node {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
constructor(type, props, context) {
|
|
174
|
-
this
|
|
174
|
+
Object.defineProperty(this, 'context', {
|
|
175
|
+
value: context || null,
|
|
176
|
+
writable: true
|
|
177
|
+
});
|
|
175
178
|
this.error = null;
|
|
176
179
|
this.range = null;
|
|
177
180
|
this.valueRange = null;
|
|
@@ -260,9 +263,9 @@ class Node {
|
|
|
260
263
|
|
|
261
264
|
get rangeAsLinePos() {
|
|
262
265
|
if (!this.range || !this.context) return undefined;
|
|
263
|
-
const start = (0,
|
|
266
|
+
const start = (0, _sourceUtils.getLinePos)(this.range.start, this.context.root);
|
|
264
267
|
if (!start) return undefined;
|
|
265
|
-
const end = (0,
|
|
268
|
+
const end = (0, _sourceUtils.getLinePos)(this.range.end, this.context.root);
|
|
266
269
|
return {
|
|
267
270
|
start,
|
|
268
271
|
end
|
package/dist/cst/PlainValue.js
CHANGED
|
@@ -19,7 +19,7 @@ class PlainValue extends _Node.default {
|
|
|
19
19
|
while (ch && ch !== '\n') {
|
|
20
20
|
if (inFlow && (ch === '[' || ch === ']' || ch === '{' || ch === '}' || ch === ',')) break;
|
|
21
21
|
const next = src[offset + 1];
|
|
22
|
-
if (ch === ':' && (next === '\n' || next === '\t' || next === ' ' || inFlow && next === ',')) break;
|
|
22
|
+
if (ch === ':' && (!next || next === '\n' || next === '\t' || next === ' ' || inFlow && next === ',')) break;
|
|
23
23
|
if ((ch === ' ' || ch === '\t') && next === '#') break;
|
|
24
24
|
offset += 1;
|
|
25
25
|
ch = next;
|