File tree 4 files changed +57
-2
lines changed 4 files changed +57
-2
lines changed Original file line number Diff line number Diff line change @@ -552,6 +552,11 @@ export default class {
552
552
M() {
553
553
[#|1 + 1|];
554
554
}
555
+ }` ) ;
556
+
557
+ testExtractFunction ( "extractFunction_NoDeclarations" , `
558
+ function F() {
559
+ [#|arguments.length|]; // arguments has no declaration
555
560
}` ) ;
556
561
} ) ;
557
562
Original file line number Diff line number Diff line change @@ -1689,7 +1689,8 @@ namespace ts.refactor.extractSymbol {
1689
1689
return symbolId ;
1690
1690
}
1691
1691
// find first declaration in this file
1692
- const declInFile = find ( symbol . getDeclarations ( ) , d => d . getSourceFile ( ) === sourceFile ) ;
1692
+ const decls = symbol . getDeclarations ( ) ;
1693
+ const declInFile = decls && find ( decls , d => d . getSourceFile ( ) === sourceFile ) ;
1693
1694
if ( ! declInFile ) {
1694
1695
return undefined ;
1695
1696
}
@@ -1782,7 +1783,8 @@ namespace ts.refactor.extractSymbol {
1782
1783
if ( ! symbol ) {
1783
1784
return undefined ;
1784
1785
}
1785
- if ( symbol . getDeclarations ( ) . some ( d => d . parent === scopeDecl ) ) {
1786
+ const decls = symbol . getDeclarations ( ) ;
1787
+ if ( decls && decls . some ( d => d . parent === scopeDecl ) ) {
1786
1788
return createIdentifier ( symbol . name ) ;
1787
1789
}
1788
1790
const prefix = tryReplaceWithQualifiedNameOrPropertyAccess ( symbol . parent , scopeDecl , isTypeNode ) ;
Original file line number Diff line number Diff line change
1
+ // ==ORIGINAL==
2
+
3
+ function F ( ) {
4
+ /*[#|*/ arguments . length /*|]*/ ; // arguments has no declaration
5
+ }
6
+ // ==SCOPE::Extract to inner function in function 'F'==
7
+
8
+ function F ( ) {
9
+ /*RENAME*/ newFunction ( ) ; // arguments has no declaration
10
+
11
+
12
+ function newFunction ( ) {
13
+ arguments . length ;
14
+ }
15
+ }
16
+ // ==SCOPE::Extract to function in global scope==
17
+
18
+ function F ( ) {
19
+ /*RENAME*/ newFunction ( ) ; // arguments has no declaration
20
+ }
21
+
22
+ function newFunction ( ) {
23
+ arguments . length ;
24
+ }
Original file line number Diff line number Diff line change
1
+ // ==ORIGINAL==
2
+
3
+ function F ( ) {
4
+ /*[#|*/ arguments . length /*|]*/ ; // arguments has no declaration
5
+ }
6
+ // ==SCOPE::Extract to inner function in function 'F'==
7
+
8
+ function F ( ) {
9
+ /*RENAME*/ newFunction ( ) ; // arguments has no declaration
10
+
11
+
12
+ function newFunction ( ) {
13
+ arguments . length ;
14
+ }
15
+ }
16
+ // ==SCOPE::Extract to function in global scope==
17
+
18
+ function F ( ) {
19
+ /*RENAME*/ newFunction ( ) ; // arguments has no declaration
20
+ }
21
+
22
+ function newFunction ( ) {
23
+ arguments . length ;
24
+ }
You can’t perform that action at this time.
0 commit comments