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 @@ -709,6 +709,25 @@ function M3() { }`);
709
709
}
710
710
M3() { }
711
711
constructor() { }
712
+ }` ) ;
713
+ // Shorthand property names
714
+ testExtractMethod ( "extractMethod29" ,
715
+ `interface UnaryExpression {
716
+ kind: "Unary";
717
+ operator: string;
718
+ operand: any;
719
+ }
720
+
721
+ function parseUnaryExpression(operator: string): UnaryExpression {
722
+ [#|return {
723
+ kind: "Unary",
724
+ operator,
725
+ operand: parsePrimaryExpression(),
726
+ };|]
727
+ }
728
+
729
+ function parsePrimaryExpression(): any {
730
+ throw "Not implemented";
712
731
}` ) ;
713
732
} ) ;
714
733
Original file line number Diff line number Diff line change @@ -1161,7 +1161,11 @@ namespace ts.refactor.extractMethod {
1161
1161
}
1162
1162
1163
1163
function recordUsagebySymbol ( identifier : Identifier , usage : Usage , isTypeName : boolean ) {
1164
- const symbol = checker . getSymbolAtLocation ( identifier ) ;
1164
+ // If the identifier is both a property name and its value, we're only interested in its value
1165
+ // (since the name is a declaration and will be included in the extracted range).
1166
+ const symbol = identifier . parent && isShorthandPropertyAssignment ( identifier . parent ) && identifier . parent . name === identifier
1167
+ ? checker . getShorthandAssignmentValueSymbol ( identifier . parent )
1168
+ : checker . getSymbolAtLocation ( identifier ) ;
1165
1169
if ( ! symbol ) {
1166
1170
// cannot find symbol - do nothing
1167
1171
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::inner function in 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::function in 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