add binding elements from variable declaration into script lexical structure
This commit is contained in:
parent
b05f2bf1a3
commit
f4ca318c39
|
@ -50,6 +50,7 @@ module ts.NavigationBar {
|
|||
case SyntaxKind.ArrayBindingPattern:
|
||||
forEach((<BindingPattern>node).elements, visit);
|
||||
break;
|
||||
case SyntaxKind.BindingElement:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
if (isBindingPattern((<VariableDeclaration>node).name)) {
|
||||
visit((<VariableDeclaration>node).name);
|
||||
|
@ -262,17 +263,34 @@ module ts.NavigationBar {
|
|||
return createItem(node, getTextOfNode((<FunctionLikeDeclaration>node).name), ts.ScriptElementKind.functionElement);
|
||||
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
if (isBindingPattern((<VariableDeclaration>node).name)) {
|
||||
break;
|
||||
}
|
||||
if (isConst(node)) {
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.constElement);
|
||||
}
|
||||
else if (isLet(node)) {
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.letElement);
|
||||
case SyntaxKind.BindingElement:
|
||||
var variableDeclarationNode: Node;
|
||||
var 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 !== undefined);
|
||||
}
|
||||
else {
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.variableElement);
|
||||
Debug.assert(!isBindingPattern((<VariableDeclaration>node).name));
|
||||
variableDeclarationNode = node;
|
||||
name = (<VariableDeclaration>node).name;
|
||||
}
|
||||
|
||||
if (isConst(variableDeclarationNode)) {
|
||||
return createItem(node, getTextOfNode(name), ts.ScriptElementKind.constElement);
|
||||
}
|
||||
else if (isLet(variableDeclarationNode)) {
|
||||
return createItem(node, getTextOfNode(name), ts.ScriptElementKind.letElement);
|
||||
}
|
||||
else {
|
||||
return createItem(node, getTextOfNode(name), ts.ScriptElementKind.variableElement);
|
||||
}
|
||||
|
||||
case SyntaxKind.Constructor:
|
||||
|
|
|
@ -1,4 +1,21 @@
|
|||
/// <reference path='fourslash.ts'/>
|
||||
////'use strict'
|
||||
////var foo, {}
|
||||
////var bar, []
|
||||
verify.getScriptLexicalStructureListCount(3); // global (1) + variable declarations (2)
|
||||
////let foo1, {a, b}
|
||||
////const bar1, [c, d]
|
||||
////var {e, x: [f, g]} = {a:1, x:[]};
|
||||
|
||||
verify.getScriptLexicalStructureListCount(12); // global (1) + variable declarations (4) + binding patterns (7)
|
||||
verify.getScriptLexicalStructureListContains("foo", "var");
|
||||
verify.getScriptLexicalStructureListContains("bar", "var");
|
||||
verify.getScriptLexicalStructureListContains("foo1", "let")
|
||||
verify.getScriptLexicalStructureListContains("a", "let");
|
||||
verify.getScriptLexicalStructureListContains("b", "let");
|
||||
verify.getScriptLexicalStructureListContains("bar1", "const");
|
||||
verify.getScriptLexicalStructureListContains("c", "const");
|
||||
verify.getScriptLexicalStructureListContains("d", "const");
|
||||
verify.getScriptLexicalStructureListContains("e", "var");
|
||||
verify.getScriptLexicalStructureListContains("f", "var");
|
||||
verify.getScriptLexicalStructureListContains("g", "var");
|
||||
|
||||
|
|
Loading…
Reference in a new issue