@@ -7,12 +7,21 @@ export interface ResolvePropsArg {
77 next : Token | null | undefined
88 offset : number
99 onError : ComposeErrorHandler
10+ parentIndent : number
1011 startOnNewline : boolean
1112}
1213
1314export function resolveProps (
1415 tokens : SourceToken [ ] ,
15- { flow, indicator, next, offset, onError, startOnNewline } : ResolvePropsArg
16+ {
17+ flow,
18+ indicator,
19+ next,
20+ offset,
21+ onError,
22+ parentIndent,
23+ startOnNewline
24+ } : ResolvePropsArg
1625) {
1726 let spaceBefore = false
1827 let atNewline = startOnNewline
@@ -43,7 +52,7 @@ export function resolveProps(
4352 reqSpace = false
4453 }
4554 if ( tab ) {
46- if ( token . type !== 'comment' ) {
55+ if ( atNewline && token . type !== 'comment' && token . type !== 'newline ') {
4756 onError ( tab , 'TAB_AS_INDENT' , 'Tabs are not allowed as indentation' )
4857 }
4958 tab = null
@@ -55,9 +64,8 @@ export function resolveProps(
5564 // In a flow collection, only the parser handles indent.
5665 if (
5766 ! flow &&
58- atNewline &&
5967 ( indicator !== 'doc-start' || next ?. type !== 'flow-collection' ) &&
60- token . source [ 0 ] === '\t'
68+ token . source . includes ( '\t' )
6169 ) {
6270 tab = token
6371 }
@@ -132,7 +140,8 @@ export function resolveProps(
132140 `Unexpected ${ token . source } in ${ flow ?? 'collection' } `
133141 )
134142 found = token
135- atNewline = false
143+ atNewline =
144+ indicator === 'seq-item-ind' || indicator === 'explicit-key-ind'
136145 hasSpace = false
137146 break
138147 case 'comma' :
@@ -167,7 +176,13 @@ export function resolveProps(
167176 'Tags and anchors must be separated from the next token by white space'
168177 )
169178 }
170- if ( tab ) onError ( tab , 'TAB_AS_INDENT' , 'Tabs are not allowed as indentation' )
179+ if (
180+ tab &&
181+ ( ( atNewline && tab . indent <= parentIndent ) ||
182+ next ?. type === 'block-map' ||
183+ next ?. type === 'block-seq' )
184+ )
185+ onError ( tab , 'TAB_AS_INDENT' , 'Tabs are not allowed as indentation' )
171186 return {
172187 comma,
173188 found,
0 commit comments