mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-16 15:45:27 -05:00
Merge pull request #11790 from Microsoft/allowUnderScoreForIn
Allow unused locals in for in or for of that start with _
This commit is contained in:
@@ -15836,15 +15836,31 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else if (compilerOptions.noUnusedLocals) {
|
||||
forEach(local.declarations, d => error(d.name || d, Diagnostics._0_is_declared_but_never_used, local.name));
|
||||
forEach(local.declarations, d => errorUnusedLocal(d.name || d, local.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function errorUnusedLocal(node: Node, name: string) {
|
||||
if (isIdentifierThatStartsWithUnderScore(node)) {
|
||||
const declaration = getRootDeclaration(node.parent);
|
||||
if (declaration.kind === SyntaxKind.VariableDeclaration &&
|
||||
(declaration.parent.parent.kind === SyntaxKind.ForInStatement ||
|
||||
declaration.parent.parent.kind === SyntaxKind.ForOfStatement)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
error(node, Diagnostics._0_is_declared_but_never_used, name);
|
||||
}
|
||||
|
||||
function parameterNameStartsWithUnderscore(parameter: ParameterDeclaration) {
|
||||
return parameter.name && parameter.name.kind === SyntaxKind.Identifier && (<Identifier>parameter.name).text.charCodeAt(0) === CharacterCodes._;
|
||||
return parameter.name && isIdentifierThatStartsWithUnderScore(parameter.name);
|
||||
}
|
||||
|
||||
function isIdentifierThatStartsWithUnderScore(node: Node) {
|
||||
return node.kind === SyntaxKind.Identifier && (<Identifier>node).text.charCodeAt(0) === CharacterCodes._;
|
||||
}
|
||||
|
||||
function checkUnusedClassMembers(node: ClassDeclaration | ClassExpression): void {
|
||||
|
||||
Reference in New Issue
Block a user