MCPcopy Index your code
hub / github.com/nodejs/node / checkUnusedLocalsAndParameters

Function checkUnusedLocalsAndParameters

test/fixtures/snapshot/typescript.js:82111–82214  ·  view source on GitHub ↗
(nodeWithLocals, addDiagnostic)

Source from the content-addressed store, hash-verified

82109 (ts.isVariableDeclaration(declaration) && ts.isForInOrOfStatement(declaration.parent.parent) || isImportedDeclaration(declaration)) && isIdentifierThatStartsWithUnderscore(declaration.name);
82110 }
82111 function checkUnusedLocalsAndParameters(nodeWithLocals, addDiagnostic) {
82112 // Ideally we could use the ImportClause directly as a key, but must wait until we have full ES6 maps. So must store key along with value.
82113 var unusedImports = new ts.Map();
82114 var unusedDestructures = new ts.Map();
82115 var unusedVariables = new ts.Map();
82116 nodeWithLocals.locals.forEach(function (local) {
82117 // If it's purely a type parameter, ignore, will be checked in `checkUnusedTypeParameters`.
82118 // If it's a type parameter merged with a parameter, check if the parameter-side is used.
82119 if (local.flags & 262144 /* SymbolFlags.TypeParameter */ ? !(local.flags & 3 /* SymbolFlags.Variable */ && !(local.isReferenced & 3 /* SymbolFlags.Variable */)) : local.isReferenced || local.exportSymbol) {
82120 return;
82121 }
82122 if (local.declarations) {
82123 for (var _i = 0, _a = local.declarations; _i < _a.length; _i++) {
82124 var declaration = _a[_i];
82125 if (isValidUnusedLocalDeclaration(declaration)) {
82126 continue;
82127 }
82128 if (isImportedDeclaration(declaration)) {
82129 addToGroup(unusedImports, importClauseFromImported(declaration), declaration, getNodeId);
82130 }
82131 else if (ts.isBindingElement(declaration) && ts.isObjectBindingPattern(declaration.parent)) {
82132 // In `{ a, ...b }, `a` is considered used since it removes a property from `b`. `b` may still be unused though.
82133 var lastElement = ts.last(declaration.parent.elements);
82134 if (declaration === lastElement || !ts.last(declaration.parent.elements).dotDotDotToken) {
82135 addToGroup(unusedDestructures, declaration.parent, declaration, getNodeId);
82136 }
82137 }
82138 else if (ts.isVariableDeclaration(declaration)) {
82139 addToGroup(unusedVariables, declaration.parent, declaration, getNodeId);
82140 }
82141 else {
82142 var parameter = local.valueDeclaration && tryGetRootParameterDeclaration(local.valueDeclaration);
82143 var name = local.valueDeclaration && ts.getNameOfDeclaration(local.valueDeclaration);
82144 if (parameter && name) {
82145 if (!ts.isParameterPropertyDeclaration(parameter, parameter.parent) && !ts.parameterIsThisKeyword(parameter) && !isIdentifierThatStartsWithUnderscore(name)) {
82146 if (ts.isBindingElement(declaration) && ts.isArrayBindingPattern(declaration.parent)) {
82147 addToGroup(unusedDestructures, declaration.parent, declaration, getNodeId);
82148 }
82149 else {
82150 addDiagnostic(parameter, 1 /* UnusedKind.Parameter */, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local)));
82151 }
82152 }
82153 }
82154 else {
82155 errorUnusedLocal(declaration, ts.symbolName(local), addDiagnostic);
82156 }
82157 }
82158 }
82159 }
82160 });
82161 unusedImports.forEach(function (_a) {
82162 var importClause = _a[0], unuseds = _a[1];
82163 var importDecl = importClause.parent;
82164 var nDeclarations = (importClause.name ? 1 : 0) +
82165 (importClause.namedBindings ?
82166 (importClause.namedBindings.kind === 268 /* SyntaxKind.NamespaceImport */ ? 1 : importClause.namedBindings.elements.length)
82167 : 0);
82168 if (nDeclarations === unuseds.length) {

Callers 1

checkUnusedIdentifiersFunction · 0.85

Calls 11

isImportedDeclarationFunction · 0.85
addToGroupFunction · 0.85
importClauseFromImportedFunction · 0.85
errorUnusedLocalFunction · 0.85
bindingNameTextFunction · 0.85
forEachMethod · 0.65
lastMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected