Skip to content

Commit 16378e3

Browse files
committed
do not treat property names in binding elements as block scoped variables
1 parent 4ff22a0 commit 16378e3

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5091,13 +5091,20 @@ module ts {
50915091
return;
50925092
}
50935093

5094-
// - check if binding is used in some function
5094+
// - check if binding is used in some function
50955095
// (stop the walk when reaching container of binding declaration)
50965096
// - if first check succeeded - check if variable is declared inside the loop
50975097

5098-
// var decl -> var decl list -> parent
5099-
var container = (<VariableDeclaration>symbol.valueDeclaration).parent.parent;
5098+
// nesting structure:
5099+
// (variable declaration or binding element) -> variable declaration list -> container
5100+
var container: Node = symbol.valueDeclaration;
5101+
while (container.kind !== SyntaxKind.VariableDeclarationList) {
5102+
container = container.parent;
5103+
}
5104+
// get the parent of variable declaration list
5105+
container = container.parent;
51005106
if (container.kind === SyntaxKind.VariableStatement) {
5107+
// if parent is variable statement - get its parent
51015108
container = container.parent;
51025109
}
51035110

@@ -10722,6 +10729,12 @@ module ts {
1072210729
return undefined;
1072310730
}
1072410731

10732+
// ignore property names in object binding patterns
10733+
if (n.parent.kind === SyntaxKind.BindingElement &&
10734+
(<BindingElement>n.parent).propertyName === n) {
10735+
return undefined;
10736+
}
10737+
1072510738
// for names in variable declarations and binding elements try to short circuit and fetch symbol from the node
1072610739
var declarationSymbol: Symbol =
1072710740
(n.parent.kind === SyntaxKind.VariableDeclaration && (<VariableDeclaration>n.parent).name === n) ||

0 commit comments

Comments
 (0)