Skip to content

Commit 42168e3

Browse files
committed
Merge pull request microsoft#3769 from Microsoft/bindingAnonymouseWithName
Binding anonymous with name for functionExpression and classExpression
2 parents f682980 + 92d2d19 commit 42168e3

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

src/compiler/binder.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,8 @@ namespace ts {
892892
case SyntaxKind.FunctionExpression:
893893
case SyntaxKind.ArrowFunction:
894894
checkStrictModeFunctionName(<FunctionExpression>node);
895-
return bindAnonymousDeclaration(<FunctionExpression>node, SymbolFlags.Function, "__function");
895+
let bindingName = (<FunctionExpression>node).name ? (<FunctionExpression>node).name.text : "__function";
896+
return bindAnonymousDeclaration(<FunctionExpression>node, SymbolFlags.Function, bindingName);
896897
case SyntaxKind.ClassExpression:
897898
case SyntaxKind.ClassDeclaration:
898899
return bindClassLikeDeclaration(<ClassLikeDeclaration>node);
@@ -964,7 +965,8 @@ namespace ts {
964965
bindBlockScopedDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes);
965966
}
966967
else {
967-
bindAnonymousDeclaration(node, SymbolFlags.Class, "__class");
968+
let bindingName = node.name ? node.name.text : "__class";
969+
bindAnonymousDeclaration(node, SymbolFlags.Class, bindingName);
968970
}
969971

970972
let symbol = node.symbol;

tests/baselines/reference/classExpressionTest2.types

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ function M() {
2828
}
2929

3030
var v = new m<number>();
31-
>v : <number>
32-
>new m<number>() : <number>
31+
>v : C<number>
32+
>new m<number>() : C<number>
3333
>m : typeof C
3434

3535
return v.f<string>();
3636
>v.f<string>() : { t: string; x: number; }
3737
>v.f : <T>() => { t: T; x: number; }
38-
>v : <number>
38+
>v : C<number>
3939
>f : <T>() => { t: T; x: number; }
4040
}

tests/cases/fourslash/renameLocationsForClassExpression01.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
////class Foo {
44
////}
55
////
6-
////var x = class /**/Foo {
6+
////var x = class [|Foo|] {
77
//// doIt() {
8-
//// return Foo;
8+
//// return [|Foo|];
99
//// }
1010
////
1111
//// static doItStatically() {
12-
//// return Foo;
12+
//// return [|Foo|];
1313
//// }
1414
////}
1515
////
@@ -23,12 +23,10 @@
2323
// TODO (yuit): Fix up this test when class expressions are supported.
2424
// Just uncomment the below, remove the marker, and add the
2525
// appropriate ranges in the test itself.
26-
goTo.marker();
27-
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
2826

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-
////}
27+
let ranges = test.ranges()
28+
for (let range of ranges) {
29+
goTo.position(range.start);
30+
31+
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);
32+
}

0 commit comments

Comments
 (0)