@@ -198,6 +198,47 @@ function isBeginningOfLine (node, index, nodes) {
198198 return false
199199}
200200
201+ /**
202+ * Check whether a given token is the first token of:
203+ *
204+ * - ExpressionStatement
205+ * - VExpressionContainer
206+ * - A parameter of CallExpression/NewExpression
207+ * - An element of ArrayExpression
208+ * - An expression of SequenceExpression
209+ *
210+ * @param {Token } token The token to check.
211+ * @param {Node } belongingNode The node that the token is belonging to.
212+ * @returns {boolean } `true` if the token is the first token of an element.
213+ */
214+ function isBeginningOfElement ( token , belongingNode ) {
215+ let node = belongingNode
216+
217+ while ( node != null ) {
218+ const parent = node . parent
219+ const t = parent && parent . type
220+ if ( t != null && ( t . endsWith ( 'Statement' ) || t . endsWith ( 'Declaration' ) ) ) {
221+ return parent . range [ 0 ] === token . range [ 0 ]
222+ }
223+ if ( t === 'VExpressionContainer' ) {
224+ return node . range [ 0 ] === token . range [ 0 ]
225+ }
226+ if ( t === 'CallExpression' || t === 'NewExpression' ) {
227+ return parent . arguments . some ( param => param . range [ 0 ] === token . range [ 0 ] )
228+ }
229+ if ( t === 'ArrayExpression' ) {
230+ return parent . elements . some ( element => element != null && element . range [ 0 ] === token . range [ 0 ] )
231+ }
232+ if ( t === 'SequenceExpression' ) {
233+ return parent . expressions . some ( expr => expr . range [ 0 ] === token . range [ 0 ] )
234+ }
235+
236+ node = parent
237+ }
238+
239+ return false
240+ }
241+
201242/**
202243 * Creates AST event handlers for html-indent.
203244 *
@@ -387,31 +428,6 @@ function create (context) {
387428 return template . getFirstToken ( node )
388429 }
389430
390- /**
391- * Check whether a given token is the first token of a statement.
392- * @param {Token } token The token to check.
393- * @param {Node } belongingNode The node that the token is belonging to.
394- * @returns {boolean } `true` if the token is the first token of a statement.
395- */
396- function isFirstOfStatement ( token , belongingNode ) {
397- let node = belongingNode
398-
399- while ( node != null ) {
400- const parent = node . parent
401- const t = parent && parent . type
402- if ( t != null && ( t . endsWith ( 'Statement' ) || t . endsWith ( 'Declaration' ) ) ) {
403- return parent . range [ 0 ] === token . range [ 0 ]
404- }
405- if ( t === 'VExpressionContainer' ) {
406- return node . range [ 0 ] === token . range [ 0 ]
407- }
408-
409- node = parent
410- }
411-
412- return false
413- }
414-
415431 /**
416432 * Ignore all tokens of the given node.
417433 * @param {Node } node The node to ignore.
@@ -751,7 +767,7 @@ function create (context) {
751767 const shouldIndent = (
752768 prevToken == null ||
753769 prevToken . loc . end . line === leftToken . loc . start . line ||
754- isFirstOfStatement ( leftToken , node )
770+ isBeginningOfElement ( leftToken , node )
755771 )
756772
757773 setOffset ( [ opToken , rightToken ] , shouldIndent ? 1 : 0 , leftToken )
0 commit comments