diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index eddd0c3178c..b66497fc40d 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -441,6 +441,9 @@ module ts { bindBlockScopedVariableDeclaration(node); } else if (isParameterDeclaration(node)) { + // It is safe to walk up parent chain to find whether the node is a destructing parameter declaration + // because its parent chain has already been set up, since parents are set before descending into children. + // // If node is a binding element in parameter declaration, we need to use ParameterExcludes. // Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration // For example: diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0e56b53b13f..e69a30e1289 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2048,13 +2048,6 @@ module ts { return resolutionResults.pop(); } - function getRootDeclaration(node: Node): Node { - while (node.kind === SyntaxKind.BindingElement) { - node = node.parent.parent; - } - return node; - } - function getDeclarationContainer(node: Node): Node { node = getRootDeclaration(node); diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 5dc84d9bcd6..d4d20e5040f 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1151,10 +1151,15 @@ module ts { } export function isParameterDeclaration(node: VariableLikeDeclaration) { + let root = getRootDeclaration(node); + return root.kind === SyntaxKind.Parameter; + } + + export function getRootDeclaration(node: Node): Node { while (node.kind === SyntaxKind.BindingElement) { - node = node.parent.parent; + node = node.parent.parent; } - return node.kind === SyntaxKind.Parameter; + return node; } export function nodeStartsNewLexicalEnvironment(n: Node): boolean {