@@ -66,7 +66,7 @@ namespace ts.formatting {
6666 }
6767 }
6868
69- const containerList = getListByPosition ( position , precedingToken . parent ) ;
69+ const containerList = getListByPosition ( position , precedingToken . parent , sourceFile ) ;
7070 // use list position if the preceding token is before any list items
7171 if ( containerList && ! rangeContainsRange ( containerList , precedingToken ) ) {
7272 return getActualIndentationForListStartLine ( containerList , sourceFile , options ) + options . indentSize ! ; // TODO: GH#18217
@@ -322,15 +322,15 @@ namespace ts.formatting {
322322 return false ;
323323 }
324324
325- function getListIfVisualStartEndIsInListRange ( list : NodeArray < Node > | undefined , start : number , end : number , node : Node ) {
325+ function getListIfVisualStartEndIsInListRange ( list : NodeArray < Node > | undefined , start : number , end : number , node : Node , sourceFile : SourceFile ) {
326326 return list && rangeContainsVisualStartEnd ( list ) ? list : undefined ;
327327
328328 // Assumes a list is wrapped by list tokens
329329 function rangeContainsVisualStartEnd ( textRange : TextRange ) : boolean {
330330 const children = node . getChildren ( ) ;
331331 for ( let i = 1 ; i < children . length - 1 ; i ++ ) {
332332 if ( children [ i ] . pos === textRange . pos && children [ i ] . end === textRange . end ) {
333- return rangeContainsStartEnd ( { pos : children [ i - 1 ] . end , end : children [ i + 1 ] . end - children [ i + 1 ] . getWidth ( ) } , start , end ) ;
333+ return rangeContainsStartEnd ( { pos : children [ i - 1 ] . end , end : children [ i + 1 ] . getStart ( sourceFile ) } , start , end ) ;
334334 }
335335 }
336336 return rangeContainsStartEnd ( textRange , start , end ) ;
@@ -343,28 +343,28 @@ namespace ts.formatting {
343343
344344 export function getContainingList ( node : Node , sourceFile : SourceFile ) : NodeArray < Node > | undefined {
345345 if ( node . parent ) {
346- return getListByRange ( node . getStart ( sourceFile ) , node . getEnd ( ) , node . parent ) ;
346+ return getListByRange ( node . getStart ( sourceFile ) , node . getEnd ( ) , node . parent , sourceFile ) ;
347347 }
348348 return undefined ;
349349 }
350350
351- function getListByPosition ( pos : number , node : Node ) : NodeArray < Node > | undefined {
351+ function getListByPosition ( pos : number , node : Node , sourceFile : SourceFile ) : NodeArray < Node > | undefined {
352352 if ( ! node ) {
353353 return ;
354354 }
355- return getListByRange ( pos , pos , node ) ;
355+ return getListByRange ( pos , pos , node , sourceFile ) ;
356356 }
357357
358- function getListByRange ( start : number , end : number , node : Node ) : NodeArray < Node > | undefined {
358+ function getListByRange ( start : number , end : number , node : Node , sourceFile : SourceFile ) : NodeArray < Node > | undefined {
359359 switch ( node . kind ) {
360360 case SyntaxKind . TypeReference :
361- return getListIfVisualStartEndIsInListRange ( ( < TypeReferenceNode > node ) . typeArguments , start , end , node ) ;
361+ return getListIfVisualStartEndIsInListRange ( ( < TypeReferenceNode > node ) . typeArguments , start , end , node , sourceFile ) ;
362362 case SyntaxKind . ObjectLiteralExpression :
363- return getListIfVisualStartEndIsInListRange ( ( < ObjectLiteralExpression > node ) . properties , start , end , node ) ;
363+ return getListIfVisualStartEndIsInListRange ( ( < ObjectLiteralExpression > node ) . properties , start , end , node , sourceFile ) ;
364364 case SyntaxKind . ArrayLiteralExpression :
365- return getListIfVisualStartEndIsInListRange ( ( < ArrayLiteralExpression > node ) . elements , start , end , node ) ;
365+ return getListIfVisualStartEndIsInListRange ( ( < ArrayLiteralExpression > node ) . elements , start , end , node , sourceFile ) ;
366366 case SyntaxKind . TypeLiteral :
367- return getListIfVisualStartEndIsInListRange ( ( < TypeLiteralNode > node ) . members , start , end , node ) ;
367+ return getListIfVisualStartEndIsInListRange ( ( < TypeLiteralNode > node ) . members , start , end , node , sourceFile ) ;
368368 case SyntaxKind . FunctionDeclaration :
369369 case SyntaxKind . FunctionExpression :
370370 case SyntaxKind . ArrowFunction :
@@ -374,30 +374,30 @@ namespace ts.formatting {
374374 case SyntaxKind . Constructor :
375375 case SyntaxKind . ConstructorType :
376376 case SyntaxKind . ConstructSignature : {
377- return getListIfVisualStartEndIsInListRange ( ( < SignatureDeclaration > node ) . typeParameters , start , end , node ) ||
378- getListIfVisualStartEndIsInListRange ( ( < SignatureDeclaration > node ) . parameters , start , end , node ) ;
377+ return getListIfVisualStartEndIsInListRange ( ( < SignatureDeclaration > node ) . typeParameters , start , end , node , sourceFile ) ||
378+ getListIfVisualStartEndIsInListRange ( ( < SignatureDeclaration > node ) . parameters , start , end , node , sourceFile ) ;
379379 }
380380 case SyntaxKind . ClassDeclaration :
381381 case SyntaxKind . ClassExpression :
382382 case SyntaxKind . InterfaceDeclaration :
383383 case SyntaxKind . TypeAliasDeclaration :
384384 case SyntaxKind . JSDocTemplateTag : {
385385 const { typeParameters } = < ClassDeclaration | ClassExpression | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag > node ;
386- return getListIfStartEndIsInListRange ( typeParameters , start , end ) ;
386+ return getListIfVisualStartEndIsInListRange ( typeParameters , start , end , node , sourceFile ) ;
387387 }
388388 case SyntaxKind . NewExpression :
389389 case SyntaxKind . CallExpression : {
390- return getListIfVisualStartEndIsInListRange ( ( < CallExpression > node ) . typeArguments , start , end , node ) ||
391- getListIfVisualStartEndIsInListRange ( ( < CallExpression > node ) . arguments , start , end , node ) ;
390+ return getListIfVisualStartEndIsInListRange ( ( < CallExpression > node ) . typeArguments , start , end , node , sourceFile ) ||
391+ getListIfVisualStartEndIsInListRange ( ( < CallExpression > node ) . arguments , start , end , node , sourceFile ) ;
392392 }
393393 case SyntaxKind . VariableDeclarationList :
394394 return getListIfStartEndIsInListRange ( ( < VariableDeclarationList > node ) . declarations , start , end ) ;
395395 case SyntaxKind . NamedImports :
396396 case SyntaxKind . NamedExports :
397- return getListIfVisualStartEndIsInListRange ( ( < NamedImportsOrExports > node ) . elements , start , end , node ) ;
397+ return getListIfVisualStartEndIsInListRange ( ( < NamedImportsOrExports > node ) . elements , start , end , node , sourceFile ) ;
398398 case SyntaxKind . ObjectBindingPattern :
399399 case SyntaxKind . ArrayBindingPattern :
400- return getListIfVisualStartEndIsInListRange ( ( < ObjectBindingPattern | ArrayBindingPattern > node ) . elements , start , end , node ) ;
400+ return getListIfVisualStartEndIsInListRange ( ( < ObjectBindingPattern | ArrayBindingPattern > node ) . elements , start , end , node , sourceFile ) ;
401401 }
402402 }
403403
0 commit comments