mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Merge pull request #1792 from Microsoft/getScriptLexicalStructureWithbindingPatterns
handle binding patterns correctly when getting script lexical structure
This commit is contained in:
commit
a5ce3e126d
@ -50,8 +50,9 @@ module ts.NavigationBar {
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
forEach((<BindingPattern>node).elements, visit);
|
||||
break;
|
||||
case SyntaxKind.BindingElement:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
if (isBindingPattern(node)) {
|
||||
if (isBindingPattern((<VariableDeclaration>node).name)) {
|
||||
visit((<VariableDeclaration>node).name);
|
||||
break;
|
||||
}
|
||||
@ -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:
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
////'use strict'
|
||||
////var foo, {}
|
||||
////var bar, []
|
||||
////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…
x
Reference in New Issue
Block a user