Skip to content

Commit 22856de

Browse files
Merge pull request #6140 from Microsoft/noUnused
Apply the 'no-unused-variable' tslint rule to our codebase
2 parents bb1e5ab + 75678de commit 22856de

18 files changed

+47
-356
lines changed

src/compiler/checker.ts

Lines changed: 16 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -840,15 +840,6 @@ namespace ts {
840840
return resolveESModuleSymbol(resolveExternalModuleName(node, moduleSpecifier), moduleSpecifier);
841841
}
842842

843-
function getMemberOfModuleVariable(moduleSymbol: Symbol, name: string): Symbol {
844-
if (moduleSymbol.flags & SymbolFlags.Variable) {
845-
const typeAnnotation = (<VariableDeclaration>moduleSymbol.valueDeclaration).type;
846-
if (typeAnnotation) {
847-
return getPropertyOfType(getTypeFromTypeNode(typeAnnotation), name);
848-
}
849-
}
850-
}
851-
852843
// This function creates a synthetic symbol that combines the value side of one symbol with the
853844
// type/namespace side of another symbol. Consider this example:
854845
//
@@ -1084,7 +1075,6 @@ namespace ts {
10841075
}
10851076

10861077
const moduleReferenceLiteral = <LiteralExpression>moduleReferenceExpression;
1087-
const searchPath = getDirectoryPath(getSourceFile(location).fileName);
10881078

10891079
// Module names are escaped in our symbol table. However, string literal values aren't.
10901080
// Escape the name in the "require(...)" clause to ensure we find the right symbol.
@@ -2204,65 +2194,15 @@ namespace ts {
22042194
}
22052195

22062196
function isDeclarationVisible(node: Declaration): boolean {
2207-
function getContainingExternalModule(node: Node) {
2208-
for (; node; node = node.parent) {
2209-
if (node.kind === SyntaxKind.ModuleDeclaration) {
2210-
if ((<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral) {
2211-
return node;
2212-
}
2213-
}
2214-
else if (node.kind === SyntaxKind.SourceFile) {
2215-
return isExternalOrCommonJsModule(<SourceFile>node) ? node : undefined;
2216-
}
2197+
if (node) {
2198+
const links = getNodeLinks(node);
2199+
if (links.isVisible === undefined) {
2200+
links.isVisible = !!determineIfDeclarationIsVisible();
22172201
}
2218-
Debug.fail("getContainingModule cant reach here");
2202+
return links.isVisible;
22192203
}
22202204

2221-
function isUsedInExportAssignment(node: Node) {
2222-
// Get source File and see if it is external module and has export assigned symbol
2223-
const externalModule = getContainingExternalModule(node);
2224-
let exportAssignmentSymbol: Symbol;
2225-
let resolvedExportSymbol: Symbol;
2226-
if (externalModule) {
2227-
// This is export assigned symbol node
2228-
const externalModuleSymbol = getSymbolOfNode(externalModule);
2229-
exportAssignmentSymbol = getExportAssignmentSymbol(externalModuleSymbol);
2230-
const symbolOfNode = getSymbolOfNode(node);
2231-
if (isSymbolUsedInExportAssignment(symbolOfNode)) {
2232-
return true;
2233-
}
2234-
2235-
// if symbolOfNode is alias declaration, resolve the symbol declaration and check
2236-
if (symbolOfNode.flags & SymbolFlags.Alias) {
2237-
return isSymbolUsedInExportAssignment(resolveAlias(symbolOfNode));
2238-
}
2239-
}
2240-
2241-
// Check if the symbol is used in export assignment
2242-
function isSymbolUsedInExportAssignment(symbol: Symbol) {
2243-
if (exportAssignmentSymbol === symbol) {
2244-
return true;
2245-
}
2246-
2247-
if (exportAssignmentSymbol && !!(exportAssignmentSymbol.flags & SymbolFlags.Alias)) {
2248-
// if export assigned symbol is alias declaration, resolve the alias
2249-
resolvedExportSymbol = resolvedExportSymbol || resolveAlias(exportAssignmentSymbol);
2250-
if (resolvedExportSymbol === symbol) {
2251-
return true;
2252-
}
2253-
2254-
// Container of resolvedExportSymbol is visible
2255-
return forEach(resolvedExportSymbol.declarations, (current: Node) => {
2256-
while (current) {
2257-
if (current === node) {
2258-
return true;
2259-
}
2260-
current = current.parent;
2261-
}
2262-
});
2263-
}
2264-
}
2265-
}
2205+
return false;
22662206

22672207
function determineIfDeclarationIsVisible() {
22682208
switch (node.kind) {
@@ -2341,14 +2281,6 @@ namespace ts {
23412281
Debug.fail("isDeclarationVisible unknown: SyntaxKind: " + node.kind);
23422282
}
23432283
}
2344-
2345-
if (node) {
2346-
const links = getNodeLinks(node);
2347-
if (links.isVisible === undefined) {
2348-
links.isVisible = !!determineIfDeclarationIsVisible();
2349-
}
2350-
return links.isVisible;
2351-
}
23522284
}
23532285

23542286
function collectLinkedAliases(node: Identifier): Node[] {
@@ -3394,14 +3326,6 @@ namespace ts {
33943326
}
33953327
}
33963328

3397-
function addInheritedSignatures(signatures: Signature[], baseSignatures: Signature[]) {
3398-
if (baseSignatures) {
3399-
for (const signature of baseSignatures) {
3400-
signatures.push(signature);
3401-
}
3402-
}
3403-
}
3404-
34053329
function resolveDeclaredMembers(type: InterfaceType): InterfaceTypeWithDeclaredMembers {
34063330
if (!(<InterfaceTypeWithDeclaredMembers>type).declaredProperties) {
34073331
const symbol = type.symbol;
@@ -3890,25 +3814,6 @@ namespace ts {
38903814
function getSignaturesOfType(type: Type, kind: SignatureKind): Signature[] {
38913815
return getSignaturesOfStructuredType(getApparentType(type), kind);
38923816
}
3893-
3894-
function typeHasConstructSignatures(type: Type): boolean {
3895-
const apparentType = getApparentType(type);
3896-
if (apparentType.flags & (TypeFlags.ObjectType | TypeFlags.Union)) {
3897-
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
3898-
return resolved.constructSignatures.length > 0;
3899-
}
3900-
return false;
3901-
}
3902-
3903-
function typeHasCallOrConstructSignatures(type: Type): boolean {
3904-
const apparentType = getApparentType(type);
3905-
if (apparentType.flags & TypeFlags.StructuredType) {
3906-
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
3907-
return resolved.callSignatures.length > 0 || resolved.constructSignatures.length > 0;
3908-
}
3909-
return false;
3910-
}
3911-
39123817
function getIndexTypeOfStructuredType(type: Type, kind: IndexKind): Type {
39133818
if (type.flags & TypeFlags.StructuredType) {
39143819
const resolved = resolveStructuredTypeMembers(<ObjectType>type);
@@ -4410,10 +4315,6 @@ namespace ts {
44104315
return getTypeOfGlobalSymbol(getGlobalTypeSymbol(name), arity);
44114316
}
44124317

4413-
function tryGetGlobalType(name: string, arity = 0): ObjectType {
4414-
return getTypeOfGlobalSymbol(getGlobalSymbol(name, SymbolFlags.Type, /*diagnostic*/ undefined), arity);
4415-
}
4416-
44174318
/**
44184319
* Returns a type that is inside a namespace at the global scope, e.g.
44194320
* getExportedTypeFromNamespace('JSX', 'Element') returns the JSX.Element type
@@ -6299,12 +6200,8 @@ namespace ts {
62996200
}
63006201

63016202
function createInferenceContext(typeParameters: TypeParameter[], inferUnionTypes: boolean): InferenceContext {
6302-
const inferences: TypeInferences[] = [];
6303-
for (const unused of typeParameters) {
6304-
inferences.push({
6305-
primary: undefined, secondary: undefined, isFixed: false
6306-
});
6307-
}
6203+
const inferences = map(typeParameters, createTypeInferencesObject);
6204+
63086205
return {
63096206
typeParameters,
63106207
inferUnionTypes,
@@ -6313,6 +6210,14 @@ namespace ts {
63136210
};
63146211
}
63156212

6213+
function createTypeInferencesObject(): TypeInferences {
6214+
return {
6215+
primary: undefined,
6216+
secondary: undefined,
6217+
isFixed: false,
6218+
};
6219+
}
6220+
63166221
function inferTypes(context: InferenceContext, source: Type, target: Type) {
63176222
let sourceStack: Type[];
63186223
let targetStack: Type[];
@@ -6583,10 +6488,6 @@ namespace ts {
65836488
return context.inferredTypes;
65846489
}
65856490

6586-
function hasAncestor(node: Node, kind: SyntaxKind): boolean {
6587-
return getAncestor(node, kind) !== undefined;
6588-
}
6589-
65906491
// EXPRESSION TYPE CHECKING
65916492

65926493
function getResolvedSymbol(node: Identifier): Symbol {
@@ -8206,7 +8107,6 @@ namespace ts {
82068107
/// type or factory function.
82078108
/// Otherwise, returns unknownSymbol.
82088109
function getJsxElementTagSymbol(node: JsxOpeningLikeElement | JsxClosingElement): Symbol {
8209-
const flags: JsxFlags = JsxFlags.UnknownElement;
82108110
const links = getNodeLinks(node);
82118111
if (!links.resolvedSymbol) {
82128112
if (isJsxIntrinsicIdentifier(node.tagName)) {
@@ -14479,16 +14379,6 @@ namespace ts {
1447914379
}
1448014380
}
1448114381

14482-
function getModuleStatements(node: Declaration): Statement[] {
14483-
if (node.kind === SyntaxKind.SourceFile) {
14484-
return (<SourceFile>node).statements;
14485-
}
14486-
if (node.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>node).body.kind === SyntaxKind.ModuleBlock) {
14487-
return (<ModuleBlock>(<ModuleDeclaration>node).body).statements;
14488-
}
14489-
return emptyArray;
14490-
}
14491-
1449214382
function hasExportedMembers(moduleSymbol: Symbol) {
1449314383
for (var id in moduleSymbol.exports) {
1449414384
if (id !== "export=") {
@@ -15567,20 +15457,6 @@ namespace ts {
1556715457
return symbol && getExportSymbolOfValueSymbolIfExported(symbol).valueDeclaration;
1556815458
}
1556915459

15570-
function instantiateSingleCallFunctionType(functionType: Type, typeArguments: Type[]): Type {
15571-
if (functionType === unknownType) {
15572-
return unknownType;
15573-
}
15574-
15575-
const signature = getSingleCallSignature(functionType);
15576-
if (!signature) {
15577-
return unknownType;
15578-
}
15579-
15580-
const instantiatedSignature = getSignatureInstantiation(signature, typeArguments);
15581-
return getOrCreateTypeFromSignature(instantiatedSignature);
15582-
}
15583-
1558415460
function createResolver(): EmitResolver {
1558515461
return {
1558615462
getReferencedExportContainer,
@@ -16629,25 +16505,6 @@ namespace ts {
1662916505
}
1663016506
}
1663116507

16632-
function isIntegerLiteral(expression: Expression): boolean {
16633-
if (expression.kind === SyntaxKind.PrefixUnaryExpression) {
16634-
const unaryExpression = <PrefixUnaryExpression>expression;
16635-
if (unaryExpression.operator === SyntaxKind.PlusToken || unaryExpression.operator === SyntaxKind.MinusToken) {
16636-
expression = unaryExpression.operand;
16637-
}
16638-
}
16639-
if (expression.kind === SyntaxKind.NumericLiteral) {
16640-
// Allows for scientific notation since literalExpression.text was formed by
16641-
// coercing a number to a string. Sometimes this coercion can yield a string
16642-
// in scientific notation.
16643-
// We also don't need special logic for hex because a hex integer is converted
16644-
// to decimal when it is coerced.
16645-
return /^[0-9]+([eE]\+?[0-9]+)?$/.test((<LiteralExpression>expression).text);
16646-
}
16647-
16648-
return false;
16649-
}
16650-
1665116508
function hasParseDiagnostics(sourceFile: SourceFile): boolean {
1665216509
return sourceFile.parseDiagnostics.length > 0;
1665316510
}
@@ -16676,11 +16533,6 @@ namespace ts {
1667616533
}
1667716534
}
1667816535

16679-
function isEvalOrArgumentsIdentifier(node: Node): boolean {
16680-
return node.kind === SyntaxKind.Identifier &&
16681-
((<Identifier>node).text === "eval" || (<Identifier>node).text === "arguments");
16682-
}
16683-
1668416536
function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
1668516537
if (node.typeParameters) {
1668616538
return grammarErrorAtPos(getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);

src/compiler/core.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -794,23 +794,6 @@ namespace ts {
794794
return path;
795795
}
796796

797-
const backslashOrDoubleQuote = /[\"\\]/g;
798-
const escapedCharsRegExp = /[\u0000-\u001f\t\v\f\b\r\n\u2028\u2029\u0085]/g;
799-
const escapedCharsMap: Map<string> = {
800-
"\0": "\\0",
801-
"\t": "\\t",
802-
"\v": "\\v",
803-
"\f": "\\f",
804-
"\b": "\\b",
805-
"\r": "\\r",
806-
"\n": "\\n",
807-
"\\": "\\\\",
808-
"\"": "\\\"",
809-
"\u2028": "\\u2028", // lineSeparator
810-
"\u2029": "\\u2029", // paragraphSeparator
811-
"\u0085": "\\u0085" // nextLine
812-
};
813-
814797
export interface ObjectAllocator {
815798
getNodeConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => Node;
816799
getSourceFileConstructor(): new (kind: SyntaxKind, pos?: number, end?: number) => SourceFile;

src/compiler/declarationEmitter.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,14 +1534,6 @@ namespace ts {
15341534
}
15351535

15361536
function emitBindingElement(bindingElement: BindingElement) {
1537-
function getBindingElementTypeVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult): SymbolAccessibilityDiagnostic {
1538-
const diagnosticMessage = getParameterDeclarationTypeVisibilityDiagnosticMessage(symbolAccesibilityResult);
1539-
return diagnosticMessage !== undefined ? {
1540-
diagnosticMessage,
1541-
errorNode: bindingElement,
1542-
typeName: bindingElement.name
1543-
} : undefined;
1544-
}
15451537

15461538
if (bindingElement.kind === SyntaxKind.OmittedExpression) {
15471539
// If bindingElement is an omittedExpression (i.e. containing elision),

src/compiler/emitter.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -779,12 +779,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
779779
}
780780
}
781781

782-
function emitTrailingCommaIfPresent(nodeList: NodeArray<Node>): void {
783-
if (nodeList.hasTrailingComma) {
784-
write(",");
785-
}
786-
}
787-
788782
function emitLinePreservingList(parent: Node, nodes: NodeArray<Node>, allowTrailingComma: boolean, spacesBetweenBraces: boolean) {
789783
Debug.assert(nodes.length > 0);
790784

@@ -3248,10 +3242,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
32483242
}
32493243
}
32503244

3251-
function emitDownLevelForOfStatement(node: ForOfStatement) {
3252-
emitLoop(node, emitDownLevelForOfStatementWorker);
3253-
}
3254-
32553245
function emitDownLevelForOfStatementWorker(node: ForOfStatement, loop: ConvertedLoop) {
32563246
// The following ES6 code:
32573247
//

0 commit comments

Comments
 (0)