@@ -66,7 +66,7 @@ namespace ts.formatting {
66
66
}
67
67
}
68
68
69
- const containerList = getListByPosition ( position , precedingToken . parent ) ;
69
+ const containerList = getListByPosition ( position , precedingToken . parent , sourceFile ) ;
70
70
// use list position if the preceding token is before any list items
71
71
if ( containerList && ! rangeContainsRange ( containerList , precedingToken ) ) {
72
72
return getActualIndentationForListStartLine ( containerList , sourceFile , options ) + options . indentSize ! ; // TODO: GH#18217
@@ -322,15 +322,15 @@ namespace ts.formatting {
322
322
return false ;
323
323
}
324
324
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 ) {
326
326
return list && rangeContainsVisualStartEnd ( list ) ? list : undefined ;
327
327
328
328
// Assumes a list is wrapped by list tokens
329
329
function rangeContainsVisualStartEnd ( textRange : TextRange ) : boolean {
330
330
const children = node . getChildren ( ) ;
331
331
for ( let i = 1 ; i < children . length - 1 ; i ++ ) {
332
332
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 ) ;
334
334
}
335
335
}
336
336
return rangeContainsStartEnd ( textRange , start , end ) ;
@@ -343,28 +343,28 @@ namespace ts.formatting {
343
343
344
344
export function getContainingList ( node : Node , sourceFile : SourceFile ) : NodeArray < Node > | undefined {
345
345
if ( node . parent ) {
346
- return getListByRange ( node . getStart ( sourceFile ) , node . getEnd ( ) , node . parent ) ;
346
+ return getListByRange ( node . getStart ( sourceFile ) , node . getEnd ( ) , node . parent , sourceFile ) ;
347
347
}
348
348
return undefined ;
349
349
}
350
350
351
- function getListByPosition ( pos : number , node : Node ) : NodeArray < Node > | undefined {
351
+ function getListByPosition ( pos : number , node : Node , sourceFile : SourceFile ) : NodeArray < Node > | undefined {
352
352
if ( ! node ) {
353
353
return ;
354
354
}
355
- return getListByRange ( pos , pos , node ) ;
355
+ return getListByRange ( pos , pos , node , sourceFile ) ;
356
356
}
357
357
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 {
359
359
switch ( node . kind ) {
360
360
case SyntaxKind . TypeReference :
361
- return getListIfVisualStartEndIsInListRange ( ( < TypeReferenceNode > node ) . typeArguments , start , end , node ) ;
361
+ return getListIfVisualStartEndIsInListRange ( ( < TypeReferenceNode > node ) . typeArguments , start , end , node , sourceFile ) ;
362
362
case SyntaxKind . ObjectLiteralExpression :
363
- return getListIfVisualStartEndIsInListRange ( ( < ObjectLiteralExpression > node ) . properties , start , end , node ) ;
363
+ return getListIfVisualStartEndIsInListRange ( ( < ObjectLiteralExpression > node ) . properties , start , end , node , sourceFile ) ;
364
364
case SyntaxKind . ArrayLiteralExpression :
365
- return getListIfVisualStartEndIsInListRange ( ( < ArrayLiteralExpression > node ) . elements , start , end , node ) ;
365
+ return getListIfVisualStartEndIsInListRange ( ( < ArrayLiteralExpression > node ) . elements , start , end , node , sourceFile ) ;
366
366
case SyntaxKind . TypeLiteral :
367
- return getListIfVisualStartEndIsInListRange ( ( < TypeLiteralNode > node ) . members , start , end , node ) ;
367
+ return getListIfVisualStartEndIsInListRange ( ( < TypeLiteralNode > node ) . members , start , end , node , sourceFile ) ;
368
368
case SyntaxKind . FunctionDeclaration :
369
369
case SyntaxKind . FunctionExpression :
370
370
case SyntaxKind . ArrowFunction :
@@ -374,30 +374,30 @@ namespace ts.formatting {
374
374
case SyntaxKind . Constructor :
375
375
case SyntaxKind . ConstructorType :
376
376
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 ) ;
379
379
}
380
380
case SyntaxKind . ClassDeclaration :
381
381
case SyntaxKind . ClassExpression :
382
382
case SyntaxKind . InterfaceDeclaration :
383
383
case SyntaxKind . TypeAliasDeclaration :
384
384
case SyntaxKind . JSDocTemplateTag : {
385
385
const { typeParameters } = < ClassDeclaration | ClassExpression | InterfaceDeclaration | TypeAliasDeclaration | JSDocTemplateTag > node ;
386
- return getListIfStartEndIsInListRange ( typeParameters , start , end ) ;
386
+ return getListIfVisualStartEndIsInListRange ( typeParameters , start , end , node , sourceFile ) ;
387
387
}
388
388
case SyntaxKind . NewExpression :
389
389
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 ) ;
392
392
}
393
393
case SyntaxKind . VariableDeclarationList :
394
394
return getListIfStartEndIsInListRange ( ( < VariableDeclarationList > node ) . declarations , start , end ) ;
395
395
case SyntaxKind . NamedImports :
396
396
case SyntaxKind . NamedExports :
397
- return getListIfVisualStartEndIsInListRange ( ( < NamedImportsOrExports > node ) . elements , start , end , node ) ;
397
+ return getListIfVisualStartEndIsInListRange ( ( < NamedImportsOrExports > node ) . elements , start , end , node , sourceFile ) ;
398
398
case SyntaxKind . ObjectBindingPattern :
399
399
case SyntaxKind . ArrayBindingPattern :
400
- return getListIfVisualStartEndIsInListRange ( ( < ObjectBindingPattern | ArrayBindingPattern > node ) . elements , start , end , node ) ;
400
+ return getListIfVisualStartEndIsInListRange ( ( < ObjectBindingPattern | ArrayBindingPattern > node ) . elements , start , end , node , sourceFile ) ;
401
401
}
402
402
}
403
403
0 commit comments