Do not report unused local error on locals that are intended for removing properties with object spread

Fixes #12766
This commit is contained in:
Sheetal Nandi
2016-12-08 15:12:35 -08:00
parent 9505a18894
commit 81452c544a
4 changed files with 69 additions and 7 deletions

View File

@@ -16702,6 +16702,14 @@ namespace ts {
}
}
function isRemovedPropertyFromObjectSpread(node: Node) {
if (isBindingElement(node) && isObjectBindingPattern(node.parent)) {
const lastElement = lastOrUndefined(node.parent.elements);
return lastElement !== node && !!lastElement.dotDotDotToken;
}
return false;
}
function errorUnusedLocal(node: Node, name: string) {
if (isIdentifierThatStartsWithUnderScore(node)) {
const declaration = getRootDeclaration(node.parent);
@@ -16711,7 +16719,10 @@ namespace ts {
return;
}
}
error(node, Diagnostics._0_is_declared_but_never_used, name);
if (!isRemovedPropertyFromObjectSpread(node.kind === SyntaxKind.Identifier ? node.parent : node)) {
error(node, Diagnostics._0_is_declared_but_never_used, name);
}
}
function parameterNameStartsWithUnderscore(parameterName: DeclarationName) {