mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
Merge pull request #9984 from Microsoft/node_kind
Unify nodeKind implementations for navigationBar and navigateTo
This commit is contained in:
@@ -506,7 +506,7 @@ namespace ts.NavigationBar {
|
||||
function convertToTopLevelItem(n: NavigationBarNode): NavigationBarItem {
|
||||
return {
|
||||
text: getItemName(n.node),
|
||||
kind: nodeKind(n.node),
|
||||
kind: getNodeKind(n.node),
|
||||
kindModifiers: getNodeModifiers(n.node),
|
||||
spans: getSpans(n),
|
||||
childItems: map(n.children, convertToChildItem) || emptyChildItemArray,
|
||||
@@ -518,7 +518,7 @@ namespace ts.NavigationBar {
|
||||
function convertToChildItem(n: NavigationBarNode): NavigationBarItem {
|
||||
return {
|
||||
text: getItemName(n.node),
|
||||
kind: nodeKind(n.node),
|
||||
kind: getNodeKind(n.node),
|
||||
kindModifiers: getNodeModifiers(n.node),
|
||||
spans: getSpans(n),
|
||||
childItems: emptyChildItemArray,
|
||||
@@ -539,57 +539,6 @@ namespace ts.NavigationBar {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: GH#9145: We should just use getNodeKind. No reason why navigationBar and navigateTo should have different behaviors.
|
||||
function nodeKind(node: Node): string {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.SourceFile:
|
||||
return ScriptElementKind.moduleElement;
|
||||
|
||||
case SyntaxKind.EnumMember:
|
||||
return ScriptElementKind.memberVariableElement;
|
||||
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
case SyntaxKind.BindingElement:
|
||||
let variableDeclarationNode: Node;
|
||||
let name: Node;
|
||||
|
||||
if (node.kind === SyntaxKind.BindingElement) {
|
||||
name = (<BindingElement>node).name;
|
||||
variableDeclarationNode = node;
|
||||
// binding elements are added only for variable declarations
|
||||
// bubble up to the containing variable declaration
|
||||
while (variableDeclarationNode && variableDeclarationNode.kind !== SyntaxKind.VariableDeclaration) {
|
||||
variableDeclarationNode = variableDeclarationNode.parent;
|
||||
}
|
||||
Debug.assert(!!variableDeclarationNode);
|
||||
}
|
||||
else {
|
||||
Debug.assert(!isBindingPattern((<VariableDeclaration>node).name));
|
||||
variableDeclarationNode = node;
|
||||
name = (<VariableDeclaration>node).name;
|
||||
}
|
||||
|
||||
if (isConst(variableDeclarationNode)) {
|
||||
return ts.ScriptElementKind.constElement;
|
||||
}
|
||||
else if (isLet(variableDeclarationNode)) {
|
||||
return ts.ScriptElementKind.letElement;
|
||||
}
|
||||
else {
|
||||
return ts.ScriptElementKind.variableElement;
|
||||
}
|
||||
|
||||
case SyntaxKind.ArrowFunction:
|
||||
return ts.ScriptElementKind.functionElement;
|
||||
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
return ScriptElementKind.typeElement;
|
||||
|
||||
default:
|
||||
return getNodeKind(node);
|
||||
}
|
||||
}
|
||||
|
||||
function getModuleName(moduleDeclaration: ModuleDeclaration): string {
|
||||
// We want to maintain quotation marks.
|
||||
if (isAmbientModule(moduleDeclaration)) {
|
||||
|
||||
@@ -1690,6 +1690,8 @@ namespace ts {
|
||||
|
||||
/** enum E */
|
||||
export const enumElement = "enum";
|
||||
// TODO: GH#9983
|
||||
export const enumMemberElement = "const";
|
||||
|
||||
/**
|
||||
* Inside module and script only
|
||||
@@ -2947,7 +2949,10 @@ namespace ts {
|
||||
|
||||
/* @internal */ export function getNodeKind(node: Node): string {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ModuleDeclaration: return ScriptElementKind.moduleElement;
|
||||
case SyntaxKind.SourceFile:
|
||||
return isExternalModule(<SourceFile>node) ? ScriptElementKind.moduleElement : ScriptElementKind.scriptElement;
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
return ScriptElementKind.moduleElement;
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
return ScriptElementKind.classElement;
|
||||
@@ -2955,11 +2960,10 @@ namespace ts {
|
||||
case SyntaxKind.TypeAliasDeclaration: return ScriptElementKind.typeElement;
|
||||
case SyntaxKind.EnumDeclaration: return ScriptElementKind.enumElement;
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return isConst(node)
|
||||
? ScriptElementKind.constElement
|
||||
: isLet(node)
|
||||
? ScriptElementKind.letElement
|
||||
: ScriptElementKind.variableElement;
|
||||
return getKindOfVariableDeclaration(<VariableDeclaration>node);
|
||||
case SyntaxKind.BindingElement:
|
||||
return getKindOfVariableDeclaration(<VariableDeclaration>getRootDeclaration(node));
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return ScriptElementKind.functionElement;
|
||||
@@ -2976,7 +2980,7 @@ namespace ts {
|
||||
case SyntaxKind.CallSignature: return ScriptElementKind.callSignatureElement;
|
||||
case SyntaxKind.Constructor: return ScriptElementKind.constructorImplementationElement;
|
||||
case SyntaxKind.TypeParameter: return ScriptElementKind.typeParameterElement;
|
||||
case SyntaxKind.EnumMember: return ScriptElementKind.variableElement;
|
||||
case SyntaxKind.EnumMember: return ScriptElementKind.enumMemberElement;
|
||||
case SyntaxKind.Parameter: return (node.flags & NodeFlags.ParameterPropertyModifier) ? ScriptElementKind.memberVariableElement : ScriptElementKind.parameterElement;
|
||||
case SyntaxKind.ImportEqualsDeclaration:
|
||||
case SyntaxKind.ImportSpecifier:
|
||||
@@ -2984,8 +2988,19 @@ namespace ts {
|
||||
case SyntaxKind.ExportSpecifier:
|
||||
case SyntaxKind.NamespaceImport:
|
||||
return ScriptElementKind.alias;
|
||||
case SyntaxKind.JSDocTypedefTag:
|
||||
return ScriptElementKind.typeElement;
|
||||
default:
|
||||
return ScriptElementKind.unknown;
|
||||
}
|
||||
|
||||
function getKindOfVariableDeclaration(v: VariableDeclaration): string {
|
||||
return isConst(v)
|
||||
? ScriptElementKind.constElement
|
||||
: isLet(v)
|
||||
? ScriptElementKind.letElement
|
||||
: ScriptElementKind.variableElement;
|
||||
}
|
||||
return ScriptElementKind.unknown;
|
||||
}
|
||||
|
||||
class CancellationTokenObject implements CancellationToken {
|
||||
|
||||
Reference in New Issue
Block a user