File tree Expand file tree Collapse file tree 3 files changed +86
-1
lines changed Expand file tree Collapse file tree 3 files changed +86
-1
lines changed Original file line number Diff line number Diff line change @@ -648,6 +648,25 @@ function M3() { }`);
648
648
}
649
649
M3() { }
650
650
constructor() { }
651
+ }` ) ;
652
+ // Shorthand property names
653
+ testExtractMethod ( "extractMethod29" ,
654
+ `interface UnaryExpression {
655
+ kind: "Unary";
656
+ operator: string;
657
+ operand: any;
658
+ }
659
+
660
+ function parseUnaryExpression(operator: string): UnaryExpression {
661
+ [#|return {
662
+ kind: "Unary",
663
+ operator,
664
+ operand: parsePrimaryExpression(),
665
+ };|]
666
+ }
667
+
668
+ function parsePrimaryExpression(): any {
669
+ throw "Not implemented";
651
670
}` ) ;
652
671
} ) ;
653
672
Original file line number Diff line number Diff line change @@ -1022,7 +1022,11 @@ namespace ts.refactor.extractMethod {
1022
1022
}
1023
1023
1024
1024
function recordUsagebySymbol ( identifier : Identifier , usage : Usage , isTypeName : boolean ) {
1025
- const symbol = checker . getSymbolAtLocation ( identifier ) ;
1025
+ // If the identifier is both a property name and its value, we're only interested in its value
1026
+ // (since the name is a declaration and will be included in the extracted range).
1027
+ const symbol = identifier . parent && isShorthandPropertyAssignment ( identifier . parent ) && identifier . parent . name === identifier
1028
+ ? checker . getShorthandAssignmentValueSymbol ( identifier . parent )
1029
+ : checker . getSymbolAtLocation ( identifier ) ;
1026
1030
if ( ! symbol ) {
1027
1031
// cannot find symbol - do nothing
1028
1032
return undefined ;
Original file line number Diff line number Diff line change
1
+ // ==ORIGINAL==
2
+ interface UnaryExpression {
3
+ kind : "Unary" ;
4
+ operator : string ;
5
+ operand : any ;
6
+ }
7
+
8
+ function parseUnaryExpression ( operator : string ) : UnaryExpression {
9
+ return {
10
+ kind : "Unary" ,
11
+ operator,
12
+ operand : parsePrimaryExpression ( ) ,
13
+ } ;
14
+ }
15
+
16
+ function parsePrimaryExpression ( ) : any {
17
+ throw "Not implemented" ;
18
+ }
19
+ // ==SCOPE::function 'parseUnaryExpression'==
20
+ interface UnaryExpression {
21
+ kind : "Unary" ;
22
+ operator : string ;
23
+ operand : any ;
24
+ }
25
+
26
+ function parseUnaryExpression ( operator : string ) : UnaryExpression {
27
+ return /*RENAME*/ newFunction ( ) ;
28
+
29
+ function newFunction ( ) {
30
+ return {
31
+ kind : "Unary" ,
32
+ operator,
33
+ operand : parsePrimaryExpression ( ) ,
34
+ } ;
35
+ }
36
+ }
37
+
38
+ function parsePrimaryExpression ( ) : any {
39
+ throw "Not implemented" ;
40
+ }
41
+ // ==SCOPE::global scope==
42
+ interface UnaryExpression {
43
+ kind : "Unary" ;
44
+ operator : string ;
45
+ operand : any ;
46
+ }
47
+
48
+ function parseUnaryExpression ( operator : string ) : UnaryExpression {
49
+ return /*RENAME*/ newFunction ( operator ) ;
50
+ }
51
+
52
+ function newFunction ( operator : string ) {
53
+ return {
54
+ kind : "Unary" ,
55
+ operator,
56
+ operand : parsePrimaryExpression ( ) ,
57
+ } ;
58
+ }
59
+
60
+ function parsePrimaryExpression ( ) : any {
61
+ throw "Not implemented" ;
62
+ }
You can’t perform that action at this time.
0 commit comments