summaryrefslogtreecommitdiff
path: root/node_modules/yaml/dist/compose/resolve-props.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/yaml/dist/compose/resolve-props.js')
-rw-r--r--node_modules/yaml/dist/compose/resolve-props.js34
1 files changed, 24 insertions, 10 deletions
diff --git a/node_modules/yaml/dist/compose/resolve-props.js b/node_modules/yaml/dist/compose/resolve-props.js
index bc2ef22d..9b63cfd2 100644
--- a/node_modules/yaml/dist/compose/resolve-props.js
+++ b/node_modules/yaml/dist/compose/resolve-props.js
@@ -1,16 +1,17 @@
'use strict';
-function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnNewline }) {
+function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIndent, startOnNewline }) {
let spaceBefore = false;
let atNewline = startOnNewline;
let hasSpace = startOnNewline;
let comment = '';
let commentSep = '';
let hasNewline = false;
- let hasNewlineAfterProp = false;
let reqSpace = false;
+ let tab = null;
let anchor = null;
let tag = null;
+ let newlineAfterProp = null;
let comma = null;
let found = null;
let start = null;
@@ -22,16 +23,22 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
onError(token.offset, 'MISSING_CHAR', 'Tags and anchors must be separated from the next token by white space');
reqSpace = false;
}
+ if (tab) {
+ if (atNewline && token.type !== 'comment' && token.type !== 'newline') {
+ onError(tab, 'TAB_AS_INDENT', 'Tabs are not allowed as indentation');
+ }
+ tab = null;
+ }
switch (token.type) {
case 'space':
// At the doc level, tabs at line start may be parsed
// as leading white space rather than indentation.
// In a flow collection, only the parser handles indent.
if (!flow &&
- atNewline &&
- indicator !== 'doc-start' &&
- token.source[0] === '\t')
- onError(token, 'TAB_AS_INDENT', 'Tabs are not allowed as indentation');
+ (indicator !== 'doc-start' || next?.type !== 'flow-collection') &&
+ token.source.includes('\t')) {
+ tab = token;
+ }
hasSpace = true;
break;
case 'comment': {
@@ -58,7 +65,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
atNewline = true;
hasNewline = true;
if (anchor || tag)
- hasNewlineAfterProp = true;
+ newlineAfterProp = token;
hasSpace = true;
break;
case 'anchor':
@@ -91,7 +98,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
if (found)
onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow ?? 'collection'}`);
found = token;
- atNewline = false;
+ atNewline =
+ indicator === 'seq-item-ind' || indicator === 'explicit-key-ind';
hasSpace = false;
break;
case 'comma':
@@ -117,17 +125,23 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN
next.type !== 'space' &&
next.type !== 'newline' &&
next.type !== 'comma' &&
- (next.type !== 'scalar' || next.source !== ''))
+ (next.type !== 'scalar' || next.source !== '')) {
onError(next.offset, 'MISSING_CHAR', 'Tags and anchors must be separated from the next token by white space');
+ }
+ if (tab &&
+ ((atNewline && tab.indent <= parentIndent) ||
+ next?.type === 'block-map' ||
+ next?.type === 'block-seq'))
+ onError(tab, 'TAB_AS_INDENT', 'Tabs are not allowed as indentation');
return {
comma,
found,
spaceBefore,
comment,
hasNewline,
- hasNewlineAfterProp,
anchor,
tag,
+ newlineAfterProp,
end,
start: start ?? end
};