File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,11 @@ class TypescriptAdapter implements Adapter<Node> {
72
72
childNodeRange ( node : Node , childName : string ) : { start : number , end : number } {
73
73
if ( [ "arguments" , "parameters" ] . includes ( childName ) ) {
74
74
const elements = ( node as any ) [ childName ] ;
75
- return { start : this . getStart ( elements [ 0 ] as Node ) - 1 , end : this . getEnd ( elements [ elements . length - 1 ] as Node ) + 1 } ;
75
+ if ( Array . isArray ( elements ) && elements . hasOwnProperty ( '0' ) ) {
76
+ return { start : this . getStart ( elements [ 0 ] as Node ) - 1 , end : this . getEnd ( elements [ elements . length - 1 ] as Node ) + 1 } ;
77
+ } else {
78
+ return { start : elements [ 'pos' ] - 1 , end : elements [ 'pos' ] + 1 } ;
79
+ }
76
80
} else if ( node . kind === SyntaxKind . PropertyAssignment && childName === "semicolon" ) {
77
81
return { start : this . getEnd ( ( node as PropertyAssignment ) . name ) , end : this . getEnd ( ( node as PropertyAssignment ) . name ) + 1 } ;
78
82
} else if ( node . kind === SyntaxKind . PropertyAccessExpression && childName === "dot" ) {
Original file line number Diff line number Diff line change @@ -100,6 +100,11 @@ describe("TypescriptAdapter", () => {
100
100
} ) ;
101
101
102
102
describe ( "#childNodeRange" , ( ) => {
103
+ test ( "ArrowFunction parameters" , ( ) => {
104
+ const node = ( parseCode ( "const foobar = () => {}" ) as any ) [ 'declarationList' ] [ 'declarations' ] [ 0 ] [ 'initializer' ] ;
105
+ expect ( adapter . childNodeRange ( node , "parameters" ) ) . toEqual ( { start : 15 , end : 17 } ) ;
106
+ } ) ;
107
+
103
108
test ( "FunctionDeclaration parameters" , ( ) => {
104
109
const node = parseCode ( "function foobar(foo, bar) {}" ) ;
105
110
expect ( adapter . childNodeRange ( node , "parameters" ) ) . toEqual ( { start : 15 , end : 25 } ) ;
You can’t perform that action at this time.
0 commit comments