Skip to content

Commit cb6e444

Browse files
author
Andy
committed
Merge pull request #8595 from Microsoft/declaration_expressions
Declaration expressions
2 parents 42f25b3 + b91d14f commit cb6e444

File tree

2 files changed

+48
-18
lines changed

2 files changed

+48
-18
lines changed

src/services/services.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ namespace ts {
904904
function visit(node: Node): void {
905905
switch (node.kind) {
906906
case SyntaxKind.FunctionDeclaration:
907+
case SyntaxKind.FunctionExpression:
907908
case SyntaxKind.MethodDeclaration:
908909
case SyntaxKind.MethodSignature:
909910
const functionDeclaration = <FunctionLikeDeclaration>node;
@@ -930,6 +931,7 @@ namespace ts {
930931
break;
931932

932933
case SyntaxKind.ClassDeclaration:
934+
case SyntaxKind.ClassExpression:
933935
case SyntaxKind.InterfaceDeclaration:
934936
case SyntaxKind.TypeAliasDeclaration:
935937
case SyntaxKind.EnumDeclaration:
@@ -944,34 +946,25 @@ namespace ts {
944946
case SyntaxKind.SetAccessor:
945947
case SyntaxKind.TypeLiteral:
946948
addDeclaration(<Declaration>node);
947-
// fall through
948-
case SyntaxKind.Constructor:
949-
case SyntaxKind.VariableStatement:
950-
case SyntaxKind.VariableDeclarationList:
951-
case SyntaxKind.ObjectBindingPattern:
952-
case SyntaxKind.ArrayBindingPattern:
953-
case SyntaxKind.ModuleBlock:
954949
forEachChild(node, visit);
955950
break;
956951

957-
case SyntaxKind.Block:
958-
if (isFunctionBlock(node)) {
959-
forEachChild(node, visit);
960-
}
961-
break;
962-
963952
case SyntaxKind.Parameter:
964953
// Only consider parameter properties
965954
if (!(node.flags & NodeFlags.ParameterPropertyModifier)) {
966955
break;
967956
}
968957
// fall through
969958
case SyntaxKind.VariableDeclaration:
970-
case SyntaxKind.BindingElement:
971-
if (isBindingPattern((<VariableDeclaration>node).name)) {
972-
forEachChild((<VariableDeclaration>node).name, visit);
959+
case SyntaxKind.BindingElement: {
960+
const decl = <VariableDeclaration> node;
961+
if (isBindingPattern(decl.name)) {
962+
forEachChild(decl.name, visit);
973963
break;
974964
}
965+
if (decl.initializer)
966+
visit(decl.initializer);
967+
}
975968
case SyntaxKind.EnumMember:
976969
case SyntaxKind.PropertyDeclaration:
977970
case SyntaxKind.PropertySignature:
@@ -1008,6 +1001,9 @@ namespace ts {
10081001
}
10091002
}
10101003
break;
1004+
1005+
default:
1006+
forEachChild(node, visit);
10111007
}
10121008
}
10131009
}
@@ -2770,7 +2766,9 @@ namespace ts {
27702766
/* @internal */ export function getNodeKind(node: Node): string {
27712767
switch (node.kind) {
27722768
case SyntaxKind.ModuleDeclaration: return ScriptElementKind.moduleElement;
2773-
case SyntaxKind.ClassDeclaration: return ScriptElementKind.classElement;
2769+
case SyntaxKind.ClassDeclaration:
2770+
case SyntaxKind.ClassExpression:
2771+
return ScriptElementKind.classElement;
27742772
case SyntaxKind.InterfaceDeclaration: return ScriptElementKind.interfaceElement;
27752773
case SyntaxKind.TypeAliasDeclaration: return ScriptElementKind.typeElement;
27762774
case SyntaxKind.EnumDeclaration: return ScriptElementKind.enumElement;
@@ -2780,7 +2778,9 @@ namespace ts {
27802778
: isLet(node)
27812779
? ScriptElementKind.letElement
27822780
: ScriptElementKind.variableElement;
2783-
case SyntaxKind.FunctionDeclaration: return ScriptElementKind.functionElement;
2781+
case SyntaxKind.FunctionDeclaration:
2782+
case SyntaxKind.FunctionExpression:
2783+
return ScriptElementKind.functionElement;
27842784
case SyntaxKind.GetAccessor: return ScriptElementKind.memberGetAccessorElement;
27852785
case SyntaxKind.SetAccessor: return ScriptElementKind.memberSetAccessorElement;
27862786
case SyntaxKind.MethodDeclaration:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
////class A {}
4+
////const B = class C {
5+
//// public x;
6+
////};
7+
////function D() {}
8+
////const E = function F() {}
9+
////console.log(function() {}, class {}); // Expression with no name should have no effect.
10+
////console.log(function inner() {});
11+
////String(function fun() { class cls { public prop; } }));
12+
13+
function navExact(name: string, kind: string) {
14+
verify.navigationItemsListContains(name, kind, name, "exact");
15+
}
16+
17+
navExact("A", "class");
18+
navExact("B", "const");
19+
navExact("C", "class");
20+
navExact("x", "property");
21+
22+
navExact("D", "function");
23+
navExact("E", "const");
24+
navExact("F", "function")
25+
26+
navExact("inner", "function");
27+
28+
navExact("fun", "function");
29+
navExact("cls", "class");
30+
navExact("prop", "property");

0 commit comments

Comments
 (0)