mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-20 22:51:17 -05:00
Include declaration expressions (class expressions and function expressions) in named declarations
This commit is contained in:
@@ -904,6 +904,7 @@ namespace ts {
|
||||
function visit(node: Node): void {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
const functionDeclaration = <FunctionLikeDeclaration>node;
|
||||
@@ -930,6 +931,7 @@ namespace ts {
|
||||
break;
|
||||
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
@@ -967,11 +969,15 @@ namespace ts {
|
||||
}
|
||||
// fall through
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.BindingElement:
|
||||
if (isBindingPattern((<VariableDeclaration>node).name)) {
|
||||
forEachChild((<VariableDeclaration>node).name, visit);
|
||||
case SyntaxKind.BindingElement: {
|
||||
const decl = <VariableDeclaration> node;
|
||||
if (isBindingPattern(decl.name)) {
|
||||
forEachChild(decl.name, visit);
|
||||
break;
|
||||
}
|
||||
if (decl.initializer)
|
||||
visit(decl.initializer);
|
||||
}
|
||||
case SyntaxKind.EnumMember:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.PropertySignature:
|
||||
@@ -2770,7 +2776,9 @@ namespace ts {
|
||||
/* @internal */ export function getNodeKind(node: Node): string {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ModuleDeclaration: return ScriptElementKind.moduleElement;
|
||||
case SyntaxKind.ClassDeclaration: return ScriptElementKind.classElement;
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
return ScriptElementKind.classElement;
|
||||
case SyntaxKind.InterfaceDeclaration: return ScriptElementKind.interfaceElement;
|
||||
case SyntaxKind.TypeAliasDeclaration: return ScriptElementKind.typeElement;
|
||||
case SyntaxKind.EnumDeclaration: return ScriptElementKind.enumElement;
|
||||
@@ -2780,7 +2788,9 @@ namespace ts {
|
||||
: isLet(node)
|
||||
? ScriptElementKind.letElement
|
||||
: ScriptElementKind.variableElement;
|
||||
case SyntaxKind.FunctionDeclaration: return ScriptElementKind.functionElement;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return ScriptElementKind.functionElement;
|
||||
case SyntaxKind.GetAccessor: return ScriptElementKind.memberGetAccessorElement;
|
||||
case SyntaxKind.SetAccessor: return ScriptElementKind.memberSetAccessorElement;
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
|
||||
19
tests/cases/fourslash/declarationExpressions.ts
Normal file
19
tests/cases/fourslash/declarationExpressions.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/// <reference path="fourslash.ts"/>
|
||||
|
||||
////class A {}
|
||||
////const B = class C {
|
||||
//// public x;
|
||||
////};
|
||||
////function D() {}
|
||||
////const E = function F() {}
|
||||
|
||||
// Search for properties defined in the constructor, but not other constructor paramters
|
||||
var searchValue = "search";
|
||||
verify.navigationItemsListContains("A", "class", "A", "exact");
|
||||
verify.navigationItemsListContains("B", "const", "B", "exact");
|
||||
verify.navigationItemsListContains("C", "class", "C", "exact");
|
||||
verify.navigationItemsListContains("x", "property", "x", "exact");
|
||||
|
||||
verify.navigationItemsListContains("D", "function", "D", "exact");
|
||||
verify.navigationItemsListContains("E", "const", "E", "exact");
|
||||
verify.navigationItemsListContains("F", "function", "F", "exact")
|
||||
Reference in New Issue
Block a user