diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 6888a6fc25d..fd3d2141dc0 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5091,13 +5091,20 @@ module ts { return; } - // - check if binding is used in some function + // - check if binding is used in some function // (stop the walk when reaching container of binding declaration) // - if first check succeeded - check if variable is declared inside the loop - // var decl -> var decl list -> parent - var container = (symbol.valueDeclaration).parent.parent; + // nesting structure: + // (variable declaration or binding element) -> variable declaration list -> container + var container: Node = symbol.valueDeclaration; + while (container.kind !== SyntaxKind.VariableDeclarationList) { + container = container.parent; + } + // get the parent of variable declaration list + container = container.parent; if (container.kind === SyntaxKind.VariableStatement) { + // if parent is variable statement - get its parent container = container.parent; } @@ -10722,6 +10729,12 @@ module ts { return undefined; } + // ignore property names in object binding patterns + if (n.parent.kind === SyntaxKind.BindingElement && + (n.parent).propertyName === n) { + return undefined; + } + // for names in variable declarations and binding elements try to short circuit and fetch symbol from the node var declarationSymbol: Symbol = (n.parent.kind === SyntaxKind.VariableDeclaration && (n.parent).name === n) ||