yaml 2.0.0-9 → 2.1.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 +1 -1
- package/browser/dist/compose/compose-collection.js +1 -1
- package/browser/dist/compose/compose-doc.js +4 -3
- package/browser/dist/compose/compose-node.js +13 -4
- package/browser/dist/compose/compose-scalar.js +18 -13
- package/browser/dist/compose/composer.js +8 -10
- package/browser/dist/compose/resolve-block-map.js +15 -8
- package/browser/dist/compose/resolve-block-scalar.js +12 -3
- package/browser/dist/compose/resolve-block-seq.js +5 -0
- package/browser/dist/compose/resolve-flow-collection.js +13 -5
- package/browser/dist/compose/resolve-flow-scalar.js +1 -1
- package/browser/dist/compose/resolve-props.js +9 -1
- package/browser/dist/compose/util-empty-scalar-position.js +1 -1
- package/browser/dist/compose/util-flow-indent-check.js +15 -0
- package/browser/dist/doc/Document.js +53 -20
- package/browser/dist/doc/anchors.js +2 -2
- package/browser/dist/doc/createNode.js +8 -7
- package/browser/dist/doc/directives.js +7 -4
- package/browser/dist/index.js +1 -2
- package/browser/dist/nodes/Collection.js +2 -1
- package/browser/dist/nodes/Pair.js +2 -2
- package/browser/dist/nodes/Scalar.js +1 -1
- package/browser/dist/nodes/YAMLMap.js +7 -7
- package/browser/dist/nodes/YAMLSeq.js +2 -10
- package/browser/dist/nodes/addPairToJSMap.js +1 -1
- package/browser/dist/nodes/toJS.js +3 -1
- package/browser/dist/parse/cst-scalar.js +1 -2
- package/browser/dist/parse/cst-visit.js +2 -2
- package/browser/dist/parse/lexer.js +20 -8
- package/browser/dist/parse/parser.js +142 -68
- package/browser/dist/public-api.js +5 -7
- package/browser/dist/schema/Schema.js +14 -4
- package/browser/dist/schema/common/null.js +3 -1
- package/browser/dist/schema/core/float.js +4 -1
- package/browser/dist/schema/tags.js +9 -9
- package/browser/dist/schema/yaml-1.1/float.js +4 -1
- package/browser/dist/schema/yaml-1.1/omap.js +1 -1
- package/browser/dist/schema/yaml-1.1/pairs.js +1 -1
- package/browser/dist/schema/yaml-1.1/set.js +4 -0
- package/browser/dist/stringify/stringify.js +49 -22
- package/browser/dist/stringify/stringifyCollection.js +114 -85
- package/browser/dist/stringify/stringifyComment.js +18 -12
- package/browser/dist/stringify/stringifyDocument.js +36 -15
- package/browser/dist/stringify/stringifyPair.js +34 -20
- package/browser/dist/stringify/stringifyString.js +8 -11
- package/browser/dist/visit.js +149 -62
- package/dist/compose/compose-collection.js +1 -1
- package/dist/compose/compose-doc.js +4 -3
- package/dist/compose/compose-node.d.ts +1 -0
- package/dist/compose/compose-node.js +13 -4
- package/dist/compose/compose-scalar.js +17 -12
- package/dist/compose/composer.d.ts +1 -1
- package/dist/compose/composer.js +10 -12
- package/dist/compose/resolve-block-map.js +15 -8
- package/dist/compose/resolve-block-scalar.js +12 -3
- package/dist/compose/resolve-block-seq.js +5 -0
- package/dist/compose/resolve-flow-collection.js +13 -5
- package/dist/compose/resolve-flow-scalar.js +1 -1
- package/dist/compose/resolve-props.d.ts +2 -1
- package/dist/compose/resolve-props.js +9 -1
- package/dist/compose/util-empty-scalar-position.js +1 -1
- package/dist/compose/util-flow-indent-check.d.ts +3 -0
- package/dist/compose/util-flow-indent-check.js +17 -0
- package/dist/doc/Document.d.ts +17 -14
- package/dist/doc/Document.js +58 -25
- package/dist/doc/anchors.d.ts +3 -3
- package/dist/doc/anchors.js +2 -2
- package/dist/doc/createNode.d.ts +1 -1
- package/dist/doc/createNode.js +8 -7
- package/dist/doc/directives.d.ts +4 -2
- package/dist/doc/directives.js +7 -4
- package/dist/index.d.ts +4 -2
- package/dist/index.js +1 -2
- package/dist/nodes/Collection.d.ts +2 -2
- package/dist/nodes/Collection.js +2 -1
- package/dist/nodes/Node.d.ts +14 -10
- package/dist/nodes/Pair.d.ts +1 -1
- package/dist/nodes/Pair.js +2 -2
- package/dist/nodes/Scalar.js +1 -1
- package/dist/nodes/YAMLMap.d.ts +9 -4
- package/dist/nodes/YAMLMap.js +7 -7
- package/dist/nodes/YAMLSeq.d.ts +4 -1
- package/dist/nodes/YAMLSeq.js +2 -10
- package/dist/nodes/addPairToJSMap.js +1 -1
- package/dist/nodes/toJS.js +3 -1
- package/dist/options.d.ts +44 -13
- package/dist/parse/cst-scalar.js +1 -2
- package/dist/parse/cst-visit.js +2 -2
- package/dist/parse/lexer.js +20 -8
- package/dist/parse/parser.js +142 -68
- package/dist/public-api.js +5 -7
- package/dist/schema/Schema.d.ts +5 -4
- package/dist/schema/Schema.js +13 -3
- package/dist/schema/common/null.js +3 -1
- package/dist/schema/core/float.js +4 -1
- package/dist/schema/json-schema.d.ts +69 -0
- package/dist/schema/tags.d.ts +1 -2
- package/dist/schema/tags.js +9 -9
- package/dist/schema/yaml-1.1/float.js +4 -1
- package/dist/schema/yaml-1.1/omap.d.ts +7 -3
- package/dist/schema/yaml-1.1/omap.js +1 -1
- package/dist/schema/yaml-1.1/pairs.js +1 -1
- package/dist/schema/yaml-1.1/set.d.ts +6 -2
- package/dist/schema/yaml-1.1/set.js +4 -0
- package/dist/stringify/stringify.d.ts +5 -3
- package/dist/stringify/stringify.js +49 -22
- package/dist/stringify/stringifyCollection.d.ts +2 -6
- package/dist/stringify/stringifyCollection.js +113 -84
- package/dist/stringify/stringifyComment.d.ts +10 -2
- package/dist/stringify/stringifyComment.js +19 -12
- package/dist/stringify/stringifyDocument.js +35 -14
- package/dist/stringify/stringifyPair.js +33 -19
- package/dist/stringify/stringifyString.js +8 -11
- package/dist/test-events.js +14 -14
- package/dist/visit.d.ts +49 -10
- package/dist/visit.js +148 -60
- package/package.json +11 -10
- package/browser/dist/options.js +0 -18
- package/dist/node_modules/tslib/tslib.es6.js +0 -76
- package/dist/options.js +0 -20
|
@@ -6,21 +6,20 @@ const defaultTagPrefix = 'tag:yaml.org,2002:';
|
|
|
6
6
|
function findTagObject(value, tagName, tags) {
|
|
7
7
|
if (tagName) {
|
|
8
8
|
const match = tags.filter(t => t.tag === tagName);
|
|
9
|
-
const tagObj = match.find(t => !t.format)
|
|
9
|
+
const tagObj = match.find(t => !t.format) ?? match[0];
|
|
10
10
|
if (!tagObj)
|
|
11
11
|
throw new Error(`Tag ${tagName} not found`);
|
|
12
12
|
return tagObj;
|
|
13
13
|
}
|
|
14
|
-
return tags.find(t => t.identify
|
|
14
|
+
return tags.find(t => t.identify?.(value) && !t.format);
|
|
15
15
|
}
|
|
16
16
|
function createNode(value, tagName, ctx) {
|
|
17
|
-
var _a, _b;
|
|
18
17
|
if (isDocument(value))
|
|
19
18
|
value = value.contents;
|
|
20
19
|
if (isNode(value))
|
|
21
20
|
return value;
|
|
22
21
|
if (isPair(value)) {
|
|
23
|
-
const map =
|
|
22
|
+
const map = ctx.schema[MAP].createNode?.(ctx.schema, null, ctx);
|
|
24
23
|
map.items.push(value);
|
|
25
24
|
return map;
|
|
26
25
|
}
|
|
@@ -48,12 +47,14 @@ function createNode(value, tagName, ctx) {
|
|
|
48
47
|
sourceObjects.set(value, ref);
|
|
49
48
|
}
|
|
50
49
|
}
|
|
51
|
-
if (tagName
|
|
50
|
+
if (tagName?.startsWith('!!'))
|
|
52
51
|
tagName = defaultTagPrefix + tagName.slice(2);
|
|
53
52
|
let tagObj = findTagObject(value, tagName, schema.tags);
|
|
54
53
|
if (!tagObj) {
|
|
55
|
-
if (value && typeof value.toJSON === 'function')
|
|
54
|
+
if (value && typeof value.toJSON === 'function') {
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
56
56
|
value = value.toJSON();
|
|
57
|
+
}
|
|
57
58
|
if (!value || typeof value !== 'object') {
|
|
58
59
|
const node = new Scalar(value);
|
|
59
60
|
if (ref)
|
|
@@ -71,7 +72,7 @@ function createNode(value, tagName, ctx) {
|
|
|
71
72
|
onTagObj(tagObj);
|
|
72
73
|
delete ctx.onTagObj;
|
|
73
74
|
}
|
|
74
|
-
const node =
|
|
75
|
+
const node = tagObj?.createNode
|
|
75
76
|
? tagObj.createNode(ctx.schema, value, ctx)
|
|
76
77
|
: new Scalar(value);
|
|
77
78
|
if (tagName)
|
|
@@ -16,13 +16,15 @@ class Directives {
|
|
|
16
16
|
* The directives-end/doc-start marker `---`. If `null`, a marker may still be
|
|
17
17
|
* included in the document's stringified representation.
|
|
18
18
|
*/
|
|
19
|
-
this.
|
|
19
|
+
this.docStart = null;
|
|
20
|
+
/** The doc-end marker `...`. */
|
|
21
|
+
this.docEnd = false;
|
|
20
22
|
this.yaml = Object.assign({}, Directives.defaultYaml, yaml);
|
|
21
23
|
this.tags = Object.assign({}, Directives.defaultTags, tags);
|
|
22
24
|
}
|
|
23
25
|
clone() {
|
|
24
26
|
const copy = new Directives(this.yaml, this.tags);
|
|
25
|
-
copy.
|
|
27
|
+
copy.docStart = this.docStart;
|
|
26
28
|
return copy;
|
|
27
29
|
}
|
|
28
30
|
/**
|
|
@@ -71,7 +73,7 @@ class Directives {
|
|
|
71
73
|
}
|
|
72
74
|
case '%YAML': {
|
|
73
75
|
this.yaml.explicit = true;
|
|
74
|
-
if (parts.length
|
|
76
|
+
if (parts.length !== 1) {
|
|
75
77
|
onError(0, '%YAML directive should contain exactly one part');
|
|
76
78
|
return false;
|
|
77
79
|
}
|
|
@@ -81,7 +83,8 @@ class Directives {
|
|
|
81
83
|
return true;
|
|
82
84
|
}
|
|
83
85
|
else {
|
|
84
|
-
|
|
86
|
+
const isValid = /^\d+\.\d+$/.test(version);
|
|
87
|
+
onError(6, `Unsupported YAML version ${version}`, isValid);
|
|
85
88
|
return false;
|
|
86
89
|
}
|
|
87
90
|
}
|
package/browser/dist/index.js
CHANGED
|
@@ -8,11 +8,10 @@ export { Pair } from './nodes/Pair.js';
|
|
|
8
8
|
export { Scalar } from './nodes/Scalar.js';
|
|
9
9
|
export { YAMLMap } from './nodes/YAMLMap.js';
|
|
10
10
|
export { YAMLSeq } from './nodes/YAMLSeq.js';
|
|
11
|
-
export { defaultOptions } from './options.js';
|
|
12
11
|
import * as cst from './parse/cst.js';
|
|
13
12
|
export { cst as CST };
|
|
14
13
|
export { Lexer } from './parse/lexer.js';
|
|
15
14
|
export { LineCounter } from './parse/line-counter.js';
|
|
16
15
|
export { Parser } from './parse/parser.js';
|
|
17
16
|
export { parse, parseAllDocuments, parseDocument, stringify } from './public-api.js';
|
|
18
|
-
export { visit } from './visit.js';
|
|
17
|
+
export { visit, visitAsync } from './visit.js';
|
|
@@ -24,7 +24,8 @@ function collectionFromPath(schema, path, value) {
|
|
|
24
24
|
sourceObjects: new Map()
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
|
-
//
|
|
27
|
+
// Type guard is intentionally a little wrong so as to be more useful,
|
|
28
|
+
// as it does not cover untypable empty non-string iterables (e.g. []).
|
|
28
29
|
const isEmptyPath = (path) => path == null ||
|
|
29
30
|
(typeof path === 'object' && !!path[Symbol.iterator]().next().done);
|
|
30
31
|
class Collection extends NodeBase {
|
|
@@ -23,11 +23,11 @@ class Pair {
|
|
|
23
23
|
return new Pair(key, value);
|
|
24
24
|
}
|
|
25
25
|
toJSON(_, ctx) {
|
|
26
|
-
const pair = ctx
|
|
26
|
+
const pair = ctx?.mapAsMap ? new Map() : {};
|
|
27
27
|
return addPairToJSMap(ctx, pair, this);
|
|
28
28
|
}
|
|
29
29
|
toString(ctx, onComment, onChompKeep) {
|
|
30
|
-
return ctx
|
|
30
|
+
return ctx?.doc
|
|
31
31
|
? stringifyPair(this, ctx, onComment, onChompKeep)
|
|
32
32
|
: JSON.stringify(this);
|
|
33
33
|
}
|
|
@@ -37,12 +37,12 @@ class YAMLMap extends Collection {
|
|
|
37
37
|
_pair = pair;
|
|
38
38
|
else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
|
|
39
39
|
// In TypeScript, this never happens.
|
|
40
|
-
_pair = new Pair(pair, pair
|
|
40
|
+
_pair = new Pair(pair, pair?.value);
|
|
41
41
|
}
|
|
42
42
|
else
|
|
43
43
|
_pair = new Pair(pair.key, pair.value);
|
|
44
44
|
const prev = findPair(this.items, _pair.key);
|
|
45
|
-
const sortEntries = this.schema
|
|
45
|
+
const sortEntries = this.schema?.sortMapEntries;
|
|
46
46
|
if (prev) {
|
|
47
47
|
if (!overwrite)
|
|
48
48
|
throw new Error(`Key ${_pair.key} already set`);
|
|
@@ -72,8 +72,8 @@ class YAMLMap extends Collection {
|
|
|
72
72
|
}
|
|
73
73
|
get(key, keepScalar) {
|
|
74
74
|
const it = findPair(this.items, key);
|
|
75
|
-
const node = it
|
|
76
|
-
return !keepScalar && isScalar(node) ? node.value : node;
|
|
75
|
+
const node = it?.value;
|
|
76
|
+
return (!keepScalar && isScalar(node) ? node.value : node) ?? undefined;
|
|
77
77
|
}
|
|
78
78
|
has(key) {
|
|
79
79
|
return !!findPair(this.items, key);
|
|
@@ -87,8 +87,8 @@ class YAMLMap extends Collection {
|
|
|
87
87
|
* @returns Instance of Type, Map, or Object
|
|
88
88
|
*/
|
|
89
89
|
toJSON(_, ctx, Type) {
|
|
90
|
-
const map = Type ? new Type() : ctx
|
|
91
|
-
if (ctx
|
|
90
|
+
const map = Type ? new Type() : ctx?.mapAsMap ? new Map() : {};
|
|
91
|
+
if (ctx?.onCreate)
|
|
92
92
|
ctx.onCreate(map);
|
|
93
93
|
for (const item of this.items)
|
|
94
94
|
addPairToJSMap(ctx, map, item);
|
|
@@ -104,7 +104,7 @@ class YAMLMap extends Collection {
|
|
|
104
104
|
if (!ctx.allNullValues && this.hasAllNullValues(false))
|
|
105
105
|
ctx = Object.assign({}, ctx, { allNullValues: true });
|
|
106
106
|
return stringifyCollection(this, ctx, {
|
|
107
|
-
|
|
107
|
+
blockItemPrefix: '',
|
|
108
108
|
flowChars: { start: '{', end: '}' },
|
|
109
109
|
itemIndent: ctx.indent || '',
|
|
110
110
|
onChompKeep,
|
|
@@ -30,14 +30,6 @@ class YAMLSeq extends Collection {
|
|
|
30
30
|
const del = this.items.splice(idx, 1);
|
|
31
31
|
return del.length > 0;
|
|
32
32
|
}
|
|
33
|
-
/**
|
|
34
|
-
* Returns item at `key`, or `undefined` if not found. By default unwraps
|
|
35
|
-
* scalar values from their surrounding node; to disable set `keepScalar` to
|
|
36
|
-
* `true` (collections are always returned intact).
|
|
37
|
-
*
|
|
38
|
-
* `key` must contain a representation of an integer for this to succeed.
|
|
39
|
-
* It may be wrapped in a `Scalar`.
|
|
40
|
-
*/
|
|
41
33
|
get(key, keepScalar) {
|
|
42
34
|
const idx = asItemIndex(key);
|
|
43
35
|
if (typeof idx !== 'number')
|
|
@@ -74,7 +66,7 @@ class YAMLSeq extends Collection {
|
|
|
74
66
|
}
|
|
75
67
|
toJSON(_, ctx) {
|
|
76
68
|
const seq = [];
|
|
77
|
-
if (ctx
|
|
69
|
+
if (ctx?.onCreate)
|
|
78
70
|
ctx.onCreate(seq);
|
|
79
71
|
let i = 0;
|
|
80
72
|
for (const item of this.items)
|
|
@@ -85,7 +77,7 @@ class YAMLSeq extends Collection {
|
|
|
85
77
|
if (!ctx)
|
|
86
78
|
return JSON.stringify(this);
|
|
87
79
|
return stringifyCollection(this, ctx, {
|
|
88
|
-
|
|
80
|
+
blockItemPrefix: '- ',
|
|
89
81
|
flowChars: { start: '[', end: ']' },
|
|
90
82
|
itemIndent: (ctx.indent || '') + ' ',
|
|
91
83
|
onChompKeep,
|
|
@@ -6,7 +6,7 @@ import { toJS } from './toJS.js';
|
|
|
6
6
|
|
|
7
7
|
const MERGE_KEY = '<<';
|
|
8
8
|
function addPairToJSMap(ctx, map, { key, value }) {
|
|
9
|
-
if (ctx
|
|
9
|
+
if (ctx?.doc.schema.merge && isMergeKey(key)) {
|
|
10
10
|
value = isAlias(value) ? value.resolve(ctx.doc) : value;
|
|
11
11
|
if (isSeq(value))
|
|
12
12
|
for (const it of value.items)
|
|
@@ -11,9 +11,11 @@ import { hasAnchor } from './Node.js';
|
|
|
11
11
|
* stringification.
|
|
12
12
|
*/
|
|
13
13
|
function toJS(value, arg, ctx) {
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
14
15
|
if (Array.isArray(value))
|
|
15
16
|
return value.map((v, i) => toJS(v, String(i), ctx));
|
|
16
17
|
if (value && typeof value.toJSON === 'function') {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
17
19
|
if (!ctx || !hasAnchor(value))
|
|
18
20
|
return value.toJSON(arg, ctx);
|
|
19
21
|
const data = { aliasCount: 0, count: 1, res: undefined };
|
|
@@ -27,7 +29,7 @@ function toJS(value, arg, ctx) {
|
|
|
27
29
|
ctx.onCreate(res);
|
|
28
30
|
return res;
|
|
29
31
|
}
|
|
30
|
-
if (typeof value === 'bigint' && !
|
|
32
|
+
if (typeof value === 'bigint' && !ctx?.keep)
|
|
31
33
|
return Number(value);
|
|
32
34
|
return value;
|
|
33
35
|
}
|
|
@@ -38,7 +38,6 @@ function resolveAsScalar(token, strict = true, onError) {
|
|
|
38
38
|
* @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
|
|
39
39
|
*/
|
|
40
40
|
function createScalarToken(value, context) {
|
|
41
|
-
var _a;
|
|
42
41
|
const { implicitKey = false, indent, inFlow = false, offset = -1, type = 'PLAIN' } = context;
|
|
43
42
|
const source = stringifyString({ type, value }, {
|
|
44
43
|
implicitKey,
|
|
@@ -46,7 +45,7 @@ function createScalarToken(value, context) {
|
|
|
46
45
|
inFlow,
|
|
47
46
|
options: { blockQuote: true, lineWidth: -1 }
|
|
48
47
|
});
|
|
49
|
-
const end =
|
|
48
|
+
const end = context.end ?? [
|
|
50
49
|
{ type: 'newline', offset: -1, indent, source: '\n' }
|
|
51
50
|
];
|
|
52
51
|
switch (source[0]) {
|
|
@@ -47,7 +47,7 @@ visit.REMOVE = REMOVE;
|
|
|
47
47
|
visit.itemAtPath = (cst, path) => {
|
|
48
48
|
let item = cst;
|
|
49
49
|
for (const [field, index] of path) {
|
|
50
|
-
const tok = item
|
|
50
|
+
const tok = item?.[field];
|
|
51
51
|
if (tok && 'items' in tok) {
|
|
52
52
|
item = tok.items[index];
|
|
53
53
|
}
|
|
@@ -64,7 +64,7 @@ visit.itemAtPath = (cst, path) => {
|
|
|
64
64
|
visit.parentCollection = (cst, path) => {
|
|
65
65
|
const parent = visit.itemAtPath(cst, path.slice(0, -1));
|
|
66
66
|
const field = path[path.length - 1][0];
|
|
67
|
-
const coll = parent
|
|
67
|
+
const coll = parent?.[field];
|
|
68
68
|
if (coll && 'items' in coll)
|
|
69
69
|
return coll;
|
|
70
70
|
throw new Error('Parent collection not found');
|
|
@@ -153,7 +153,7 @@ class Lexer {
|
|
|
153
153
|
this.lineEndPos = null;
|
|
154
154
|
}
|
|
155
155
|
this.atEnd = !incomplete;
|
|
156
|
-
let next = this.next
|
|
156
|
+
let next = this.next ?? 'stream';
|
|
157
157
|
while (next && (incomplete || this.hasChars(1)))
|
|
158
158
|
next = yield* this.parseNext(next);
|
|
159
159
|
}
|
|
@@ -357,9 +357,14 @@ class Lexer {
|
|
|
357
357
|
let indent = -1;
|
|
358
358
|
do {
|
|
359
359
|
nl = yield* this.pushNewline();
|
|
360
|
-
|
|
361
|
-
|
|
360
|
+
if (nl > 0) {
|
|
361
|
+
sp = yield* this.pushSpaces(false);
|
|
362
362
|
this.indentValue = indent = sp;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
sp = 0;
|
|
366
|
+
}
|
|
367
|
+
sp += yield* this.pushSpaces(true);
|
|
363
368
|
} while (nl + sp > 0);
|
|
364
369
|
const line = this.getLine();
|
|
365
370
|
if (line === null)
|
|
@@ -416,6 +421,7 @@ class Lexer {
|
|
|
416
421
|
case ':': {
|
|
417
422
|
const next = this.charAt(1);
|
|
418
423
|
if (this.flowKey || isEmpty(next) || next === ',') {
|
|
424
|
+
this.flowKey = false;
|
|
419
425
|
yield* this.pushCount(1);
|
|
420
426
|
yield* this.pushSpaces(true);
|
|
421
427
|
return 'flow';
|
|
@@ -532,9 +538,10 @@ class Lexer {
|
|
|
532
538
|
let ch = this.buffer[i];
|
|
533
539
|
if (ch === '\r')
|
|
534
540
|
ch = this.buffer[--i];
|
|
541
|
+
const lastChar = i; // Drop the line if last char not more indented
|
|
535
542
|
while (ch === ' ' || ch === '\t')
|
|
536
543
|
ch = this.buffer[--i];
|
|
537
|
-
if (ch === '\n' && i >= this.pos)
|
|
544
|
+
if (ch === '\n' && i >= this.pos && i + 1 + indent > lastChar)
|
|
538
545
|
nl = i;
|
|
539
546
|
else
|
|
540
547
|
break;
|
|
@@ -617,16 +624,21 @@ class Lexer {
|
|
|
617
624
|
return ((yield* this.pushUntil(isNotAnchorChar)) +
|
|
618
625
|
(yield* this.pushSpaces(true)) +
|
|
619
626
|
(yield* this.pushIndicators()));
|
|
620
|
-
case ':':
|
|
621
|
-
case '?': // this is an error outside flow collections
|
|
622
627
|
case '-': // this is an error
|
|
623
|
-
|
|
624
|
-
|
|
628
|
+
case '?': // this is an error outside flow collections
|
|
629
|
+
case ':': {
|
|
630
|
+
const inFlow = this.flowLevel > 0;
|
|
631
|
+
const ch1 = this.charAt(1);
|
|
632
|
+
if (isEmpty(ch1) || (inFlow && invalidFlowScalarChars.includes(ch1))) {
|
|
633
|
+
if (!inFlow)
|
|
625
634
|
this.indentNext = this.indentValue + 1;
|
|
635
|
+
else if (this.flowKey)
|
|
636
|
+
this.flowKey = false;
|
|
626
637
|
return ((yield* this.pushCount(1)) +
|
|
627
638
|
(yield* this.pushSpaces(true)) +
|
|
628
639
|
(yield* this.pushIndicators()));
|
|
629
640
|
}
|
|
641
|
+
}
|
|
630
642
|
}
|
|
631
643
|
return 0;
|
|
632
644
|
}
|