yaml 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/browser/dist/compose/resolve-block-map.js +5 -4
- package/browser/dist/compose/resolve-props.js +4 -0
- package/browser/dist/parse/parser.js +14 -12
- package/dist/compose/resolve-block-map.js +5 -4
- package/dist/compose/resolve-props.d.ts +1 -0
- package/dist/compose/resolve-props.js +4 -0
- package/dist/parse/parser.js +14 -12
- package/package.json +1 -1
|
@@ -40,12 +40,13 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
|
40
40
|
}
|
|
41
41
|
continue;
|
|
42
42
|
}
|
|
43
|
+
if (keyProps.hasNewlineAfterProp || containsNewline(key)) {
|
|
44
|
+
onError(key !== null && key !== void 0 ? key : start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
|
|
45
|
+
}
|
|
43
46
|
}
|
|
44
|
-
else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent)
|
|
47
|
+
else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent) {
|
|
45
48
|
onError(offset, 'BAD_INDENT', startColMsg);
|
|
46
|
-
|
|
47
|
-
onError(key, // checked by containsNewline()
|
|
48
|
-
'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
|
|
49
|
+
}
|
|
49
50
|
// key value
|
|
50
51
|
const keyStart = keyProps.end;
|
|
51
52
|
const keyNode = key
|
|
@@ -5,6 +5,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
5
5
|
let comment = '';
|
|
6
6
|
let commentSep = '';
|
|
7
7
|
let hasNewline = false;
|
|
8
|
+
let hasNewlineAfterProp = false;
|
|
8
9
|
let reqSpace = false;
|
|
9
10
|
let anchor = null;
|
|
10
11
|
let tag = null;
|
|
@@ -54,6 +55,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
54
55
|
commentSep += token.source;
|
|
55
56
|
atNewline = true;
|
|
56
57
|
hasNewline = true;
|
|
58
|
+
if (anchor || tag)
|
|
59
|
+
hasNewlineAfterProp = true;
|
|
57
60
|
hasSpace = true;
|
|
58
61
|
break;
|
|
59
62
|
case 'anchor':
|
|
@@ -120,6 +123,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
120
123
|
spaceBefore,
|
|
121
124
|
comment,
|
|
122
125
|
hasNewline,
|
|
126
|
+
hasNewlineAfterProp,
|
|
123
127
|
anchor,
|
|
124
128
|
tag,
|
|
125
129
|
end,
|
|
@@ -7,7 +7,7 @@ function includesToken(list, type) {
|
|
|
7
7
|
return true;
|
|
8
8
|
return false;
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function findNonEmptyIndex(list) {
|
|
11
11
|
for (let i = 0; i < list.length; ++i) {
|
|
12
12
|
switch (list[i].type) {
|
|
13
13
|
case 'space':
|
|
@@ -15,10 +15,10 @@ function includesNonEmpty(list) {
|
|
|
15
15
|
case 'newline':
|
|
16
16
|
break;
|
|
17
17
|
default:
|
|
18
|
-
return
|
|
18
|
+
return i;
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
return
|
|
21
|
+
return -1;
|
|
22
22
|
}
|
|
23
23
|
function isFlowToken(token) {
|
|
24
24
|
switch (token === null || token === void 0 ? void 0 : token.type) {
|
|
@@ -343,7 +343,7 @@ class Parser {
|
|
|
343
343
|
!last.sep &&
|
|
344
344
|
!last.value &&
|
|
345
345
|
last.start.length > 0 &&
|
|
346
|
-
|
|
346
|
+
findNonEmptyIndex(last.start) === -1 &&
|
|
347
347
|
(token.indent === 0 ||
|
|
348
348
|
last.start.every(st => st.type !== 'comment' || st.indent < token.indent))) {
|
|
349
349
|
if (top.type === 'document')
|
|
@@ -391,7 +391,7 @@ class Parser {
|
|
|
391
391
|
return yield* this.lineEnd(doc);
|
|
392
392
|
switch (this.type) {
|
|
393
393
|
case 'doc-start': {
|
|
394
|
-
if (
|
|
394
|
+
if (findNonEmptyIndex(doc.start) !== -1) {
|
|
395
395
|
yield* this.pop();
|
|
396
396
|
yield* this.step();
|
|
397
397
|
}
|
|
@@ -485,17 +485,21 @@ class Parser {
|
|
|
485
485
|
else
|
|
486
486
|
map.items.push({ start: [this.sourceToken] });
|
|
487
487
|
}
|
|
488
|
-
else if (it.sep)
|
|
488
|
+
else if (it.sep) {
|
|
489
489
|
it.sep.push(this.sourceToken);
|
|
490
|
-
|
|
490
|
+
}
|
|
491
|
+
else {
|
|
491
492
|
it.start.push(this.sourceToken);
|
|
493
|
+
}
|
|
492
494
|
return;
|
|
493
495
|
case 'space':
|
|
494
496
|
case 'comment':
|
|
495
|
-
if (it.value)
|
|
497
|
+
if (it.value) {
|
|
496
498
|
map.items.push({ start: [this.sourceToken] });
|
|
497
|
-
|
|
499
|
+
}
|
|
500
|
+
else if (it.sep) {
|
|
498
501
|
it.sep.push(this.sourceToken);
|
|
502
|
+
}
|
|
499
503
|
else {
|
|
500
504
|
if (this.atIndentedComment(it.start, map.indent)) {
|
|
501
505
|
const prev = map.items[map.items.length - 2];
|
|
@@ -512,9 +516,7 @@ class Parser {
|
|
|
512
516
|
return;
|
|
513
517
|
}
|
|
514
518
|
if (this.indent >= map.indent) {
|
|
515
|
-
const atNextItem = !this.onKeyLine &&
|
|
516
|
-
this.indent === map.indent &&
|
|
517
|
-
(it.sep || includesNonEmpty(it.start));
|
|
519
|
+
const atNextItem = !this.onKeyLine && this.indent === map.indent && it.sep;
|
|
518
520
|
// For empty nodes, assign newline-separated not indented empty tokens to following node
|
|
519
521
|
let start = [];
|
|
520
522
|
if (atNextItem && it.sep && !it.value) {
|
|
@@ -42,12 +42,13 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError) {
|
|
|
42
42
|
}
|
|
43
43
|
continue;
|
|
44
44
|
}
|
|
45
|
+
if (keyProps.hasNewlineAfterProp || utilContainsNewline.containsNewline(key)) {
|
|
46
|
+
onError(key !== null && key !== void 0 ? key : start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
|
-
else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent)
|
|
49
|
+
else if (((_a = keyProps.found) === null || _a === void 0 ? void 0 : _a.indent) !== bm.indent) {
|
|
47
50
|
onError(offset, 'BAD_INDENT', startColMsg);
|
|
48
|
-
|
|
49
|
-
onError(key, // checked by containsNewline()
|
|
50
|
-
'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
|
|
51
|
+
}
|
|
51
52
|
// key value
|
|
52
53
|
const keyStart = keyProps.end;
|
|
53
54
|
const keyNode = key
|
|
@@ -7,6 +7,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
7
7
|
let comment = '';
|
|
8
8
|
let commentSep = '';
|
|
9
9
|
let hasNewline = false;
|
|
10
|
+
let hasNewlineAfterProp = false;
|
|
10
11
|
let reqSpace = false;
|
|
11
12
|
let anchor = null;
|
|
12
13
|
let tag = null;
|
|
@@ -56,6 +57,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
56
57
|
commentSep += token.source;
|
|
57
58
|
atNewline = true;
|
|
58
59
|
hasNewline = true;
|
|
60
|
+
if (anchor || tag)
|
|
61
|
+
hasNewlineAfterProp = true;
|
|
59
62
|
hasSpace = true;
|
|
60
63
|
break;
|
|
61
64
|
case 'anchor':
|
|
@@ -122,6 +125,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
|
|
|
122
125
|
spaceBefore,
|
|
123
126
|
comment,
|
|
124
127
|
hasNewline,
|
|
128
|
+
hasNewlineAfterProp,
|
|
125
129
|
anchor,
|
|
126
130
|
tag,
|
|
127
131
|
end,
|
package/dist/parse/parser.js
CHANGED
|
@@ -9,7 +9,7 @@ function includesToken(list, type) {
|
|
|
9
9
|
return true;
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
|
-
function
|
|
12
|
+
function findNonEmptyIndex(list) {
|
|
13
13
|
for (let i = 0; i < list.length; ++i) {
|
|
14
14
|
switch (list[i].type) {
|
|
15
15
|
case 'space':
|
|
@@ -17,10 +17,10 @@ function includesNonEmpty(list) {
|
|
|
17
17
|
case 'newline':
|
|
18
18
|
break;
|
|
19
19
|
default:
|
|
20
|
-
return
|
|
20
|
+
return i;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
return
|
|
23
|
+
return -1;
|
|
24
24
|
}
|
|
25
25
|
function isFlowToken(token) {
|
|
26
26
|
switch (token === null || token === void 0 ? void 0 : token.type) {
|
|
@@ -347,7 +347,7 @@ class Parser {
|
|
|
347
347
|
!last.sep &&
|
|
348
348
|
!last.value &&
|
|
349
349
|
last.start.length > 0 &&
|
|
350
|
-
|
|
350
|
+
findNonEmptyIndex(last.start) === -1 &&
|
|
351
351
|
(token.indent === 0 ||
|
|
352
352
|
last.start.every(st => st.type !== 'comment' || st.indent < token.indent))) {
|
|
353
353
|
if (top.type === 'document')
|
|
@@ -395,7 +395,7 @@ class Parser {
|
|
|
395
395
|
return yield* this.lineEnd(doc);
|
|
396
396
|
switch (this.type) {
|
|
397
397
|
case 'doc-start': {
|
|
398
|
-
if (
|
|
398
|
+
if (findNonEmptyIndex(doc.start) !== -1) {
|
|
399
399
|
yield* this.pop();
|
|
400
400
|
yield* this.step();
|
|
401
401
|
}
|
|
@@ -489,17 +489,21 @@ class Parser {
|
|
|
489
489
|
else
|
|
490
490
|
map.items.push({ start: [this.sourceToken] });
|
|
491
491
|
}
|
|
492
|
-
else if (it.sep)
|
|
492
|
+
else if (it.sep) {
|
|
493
493
|
it.sep.push(this.sourceToken);
|
|
494
|
-
|
|
494
|
+
}
|
|
495
|
+
else {
|
|
495
496
|
it.start.push(this.sourceToken);
|
|
497
|
+
}
|
|
496
498
|
return;
|
|
497
499
|
case 'space':
|
|
498
500
|
case 'comment':
|
|
499
|
-
if (it.value)
|
|
501
|
+
if (it.value) {
|
|
500
502
|
map.items.push({ start: [this.sourceToken] });
|
|
501
|
-
|
|
503
|
+
}
|
|
504
|
+
else if (it.sep) {
|
|
502
505
|
it.sep.push(this.sourceToken);
|
|
506
|
+
}
|
|
503
507
|
else {
|
|
504
508
|
if (this.atIndentedComment(it.start, map.indent)) {
|
|
505
509
|
const prev = map.items[map.items.length - 2];
|
|
@@ -516,9 +520,7 @@ class Parser {
|
|
|
516
520
|
return;
|
|
517
521
|
}
|
|
518
522
|
if (this.indent >= map.indent) {
|
|
519
|
-
const atNextItem = !this.onKeyLine &&
|
|
520
|
-
this.indent === map.indent &&
|
|
521
|
-
(it.sep || includesNonEmpty(it.start));
|
|
523
|
+
const atNextItem = !this.onKeyLine && this.indent === map.indent && it.sep;
|
|
522
524
|
// For empty nodes, assign newline-separated not indented empty tokens to following node
|
|
523
525
|
let start = [];
|
|
524
526
|
if (atNextItem && it.sep && !it.value) {
|