Skip to content

Commit 605ab0b

Browse files
author
Yui T
committed
Fix rename for class expression
1 parent 514d054 commit 605ab0b

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

src/services/services.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5117,10 +5117,10 @@ namespace ts {
51175117
* a reference to a symbol can occur anywhere.
51185118
*/
51195119
function getSymbolScope(symbol: Symbol): Node {
5120-
// If this is the symbol of a function expression, then named references
5121-
// are limited to its own scope.
5120+
// If this is the symbol of a named function expression or named class expression,
5121+
// then named references are limited to its own scope.
51225122
let valueDeclaration = symbol.valueDeclaration;
5123-
if (valueDeclaration && valueDeclaration.kind === SyntaxKind.FunctionExpression) {
5123+
if (valueDeclaration && (valueDeclaration.kind === SyntaxKind.FunctionExpression || valueDeclaration.kind === SyntaxKind.ClassExpression)) {
51245124
return valueDeclaration;
51255125
}
51265126

tests/cases/fourslash/renameLocationsForClassExpression01.ts

+10-16
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
////class Foo {
44
////}
55
////
6-
////var x = class /**/Foo {
6+
//////The class expression Foo
7+
////var x = class [|Foo|] {
78
//// doIt() {
8-
//// return Foo;
9+
//// return [|Foo|];
910
//// }
1011
////
1112
//// static doItStatically() {
12-
//// return Foo;
13+
//// return [|Foo|].y;
1314
//// }
1415
////}
1516
////
@@ -18,17 +19,10 @@
1819
//// return Foo
1920
//// }
2021
////}
22+
////var z = class Foo {}
2123

22-
23-
// TODO (yuit): Fix up this test when class expressions are supported.
24-
// Just uncomment the below, remove the marker, and add the
25-
// appropriate ranges in the test itself.
26-
goTo.marker();
27-
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
28-
29-
////let ranges = test.ranges()
30-
////for (let range of ranges) {
31-
//// goTo.position(range.start);
32-
////
33-
//// verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
34-
////}
24+
let ranges = test.ranges()
25+
for (let range of ranges) {
26+
goTo.position(range.start);
27+
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
28+
}

0 commit comments

Comments
 (0)