Skip to content

Commit db0ee4f

Browse files
author
Andy
authored
Merge pull request microsoft#11715 from Microsoft/unused
Forbid unused locals/parameters in compiler
2 parents 14e5de3 + f11dbc1 commit db0ee4f

24 files changed

+141
-165
lines changed

src/compiler/checker.ts

+23-26
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ namespace ts {
10541054
if (node.moduleReference.kind === SyntaxKind.ExternalModuleReference) {
10551055
return resolveExternalModuleSymbol(resolveExternalModuleName(node, getExternalModuleImportEqualsDeclarationExpression(node)));
10561056
}
1057-
return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>node.moduleReference, node);
1057+
return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>node.moduleReference);
10581058
}
10591059

10601060
function getTargetOfImportClause(node: ImportClause): Symbol {
@@ -1267,7 +1267,7 @@ namespace ts {
12671267
}
12681268

12691269
// This function is only for imports with entity names
1270-
function getSymbolOfPartOfRightHandSideOfImportEquals(entityName: EntityName, importDeclaration: ImportEqualsDeclaration, dontResolveAlias?: boolean): Symbol {
1270+
function getSymbolOfPartOfRightHandSideOfImportEquals(entityName: EntityName, dontResolveAlias?: boolean): Symbol {
12711271
// There are three things we might try to look for. In the following examples,
12721272
// the search term is enclosed in |...|:
12731273
//
@@ -2583,7 +2583,7 @@ namespace ts {
25832583
}
25842584
}
25852585

2586-
function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) {
2586+
function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node) {
25872587
if (typeParameters && typeParameters.length) {
25882588
writePunctuation(writer, SyntaxKind.LessThanToken);
25892589
let flags = TypeFormatFlags.InFirstTypeArgument;
@@ -4795,7 +4795,7 @@ namespace ts {
47954795
const typeParameters = classType ? classType.localTypeParameters :
47964796
declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) :
47974797
getTypeParametersFromJSDocTemplate(declaration);
4798-
const returnType = getSignatureReturnTypeFromDeclaration(declaration, minArgumentCount, isJSConstructSignature, classType);
4798+
const returnType = getSignatureReturnTypeFromDeclaration(declaration, isJSConstructSignature, classType);
47994799
const typePredicate = declaration.type && declaration.type.kind === SyntaxKind.TypePredicate ?
48004800
createTypePredicateFromTypePredicateNode(declaration.type as TypePredicateNode) :
48014801
undefined;
@@ -4805,7 +4805,7 @@ namespace ts {
48054805
return links.resolvedSignature;
48064806
}
48074807

4808-
function getSignatureReturnTypeFromDeclaration(declaration: SignatureDeclaration, minArgumentCount: number, isJSConstructSignature: boolean, classType: Type) {
4808+
function getSignatureReturnTypeFromDeclaration(declaration: SignatureDeclaration, isJSConstructSignature: boolean, classType: Type) {
48094809
if (isJSConstructSignature) {
48104810
return getTypeFromTypeNode(declaration.parameters[0].type);
48114811
}
@@ -5170,10 +5170,7 @@ namespace ts {
51705170
return undefined;
51715171
}
51725172

5173-
function resolveTypeReferenceName(
5174-
node: TypeReferenceNode | ExpressionWithTypeArguments | JSDocTypeReference,
5175-
typeReferenceName: EntityNameExpression | EntityName) {
5176-
5173+
function resolveTypeReferenceName(typeReferenceName: EntityNameExpression | EntityName) {
51775174
if (!typeReferenceName) {
51785175
return unknownSymbol;
51795176
}
@@ -5211,7 +5208,7 @@ namespace ts {
52115208
let type: Type;
52125209
if (node.kind === SyntaxKind.JSDocTypeReference) {
52135210
const typeReferenceName = getTypeReferenceName(node);
5214-
symbol = resolveTypeReferenceName(node, typeReferenceName);
5211+
symbol = resolveTypeReferenceName(typeReferenceName);
52155212
type = getTypeReferenceType(node, symbol);
52165213
}
52175214
else {
@@ -6673,8 +6670,8 @@ namespace ts {
66736670
}
66746671
if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union ||
66756672
source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) {
6676-
if (result = eachTypeRelatedToSomeType(<UnionOrIntersectionType>source, <UnionOrIntersectionType>target, /*reportErrors*/ false)) {
6677-
if (result &= eachTypeRelatedToSomeType(<UnionOrIntersectionType>target, <UnionOrIntersectionType>source, /*reportErrors*/ false)) {
6673+
if (result = eachTypeRelatedToSomeType(<UnionOrIntersectionType>source, <UnionOrIntersectionType>target)) {
6674+
if (result &= eachTypeRelatedToSomeType(<UnionOrIntersectionType>target, <UnionOrIntersectionType>source)) {
66786675
return result;
66796676
}
66806677
}
@@ -6735,7 +6732,7 @@ namespace ts {
67356732
return false;
67366733
}
67376734

6738-
function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType, reportErrors: boolean): Ternary {
6735+
function eachTypeRelatedToSomeType(source: UnionOrIntersectionType, target: UnionOrIntersectionType): Ternary {
67396736
let result = Ternary.True;
67406737
const sourceTypes = source.types;
67416738
for (const sourceType of sourceTypes) {
@@ -11772,7 +11769,7 @@ namespace ts {
1177211769
// If the effective argument is 'undefined', then it is an argument that is present but is synthetic.
1177311770
if (arg === undefined || arg.kind !== SyntaxKind.OmittedExpression) {
1177411771
const paramType = getTypeAtPosition(signature, i);
11775-
let argType = getEffectiveArgumentType(node, i, arg);
11772+
let argType = getEffectiveArgumentType(node, i);
1177611773

1177711774
// If the effective argument type is 'undefined', there is no synthetic type
1177811775
// for the argument. In that case, we should check the argument.
@@ -11858,7 +11855,7 @@ namespace ts {
1185811855
if (arg === undefined || arg.kind !== SyntaxKind.OmittedExpression) {
1185911856
// Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter)
1186011857
const paramType = getTypeAtPosition(signature, i);
11861-
let argType = getEffectiveArgumentType(node, i, arg);
11858+
let argType = getEffectiveArgumentType(node, i);
1186211859

1186311860
// If the effective argument type is 'undefined', there is no synthetic type
1186411861
// for the argument. In that case, we should check the argument.
@@ -12151,7 +12148,7 @@ namespace ts {
1215112148
/**
1215212149
* Gets the effective argument type for an argument in a call expression.
1215312150
*/
12154-
function getEffectiveArgumentType(node: CallLikeExpression, argIndex: number, arg: Expression): Type {
12151+
function getEffectiveArgumentType(node: CallLikeExpression, argIndex: number): Type {
1215512152
// Decorators provide special arguments, a tagged template expression provides
1215612153
// a special first argument, and string literals get string literal types
1215712154
// unless we're reporting errors
@@ -13556,15 +13553,15 @@ namespace ts {
1355613553
return booleanType;
1355713554
}
1355813555

13559-
function checkObjectLiteralAssignment(node: ObjectLiteralExpression, sourceType: Type, contextualMapper?: TypeMapper): Type {
13556+
function checkObjectLiteralAssignment(node: ObjectLiteralExpression, sourceType: Type): Type {
1356013557
const properties = node.properties;
1356113558
for (const p of properties) {
13562-
checkObjectLiteralDestructuringPropertyAssignment(sourceType, p, contextualMapper);
13559+
checkObjectLiteralDestructuringPropertyAssignment(sourceType, p);
1356313560
}
1356413561
return sourceType;
1356513562
}
1356613563

13567-
function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike, contextualMapper?: TypeMapper) {
13564+
function checkObjectLiteralDestructuringPropertyAssignment(objectLiteralType: Type, property: ObjectLiteralElementLike) {
1356813565
if (property.kind === SyntaxKind.PropertyAssignment || property.kind === SyntaxKind.ShorthandPropertyAssignment) {
1356913566
const name = <PropertyName>(<PropertyAssignment>property).name;
1357013567
if (name.kind === SyntaxKind.ComputedPropertyName) {
@@ -13679,7 +13676,7 @@ namespace ts {
1367913676
target = (<BinaryExpression>target).left;
1368013677
}
1368113678
if (target.kind === SyntaxKind.ObjectLiteralExpression) {
13682-
return checkObjectLiteralAssignment(<ObjectLiteralExpression>target, sourceType, contextualMapper);
13679+
return checkObjectLiteralAssignment(<ObjectLiteralExpression>target, sourceType);
1368313680
}
1368413681
if (target.kind === SyntaxKind.ArrayLiteralExpression) {
1368513682
return checkArrayLiteralAssignment(<ArrayLiteralExpression>target, sourceType, contextualMapper);
@@ -18588,7 +18585,7 @@ namespace ts {
1858818585
// Since we already checked for ExportAssignment, this really could only be an Import
1858918586
const importEqualsDeclaration = <ImportEqualsDeclaration>getAncestor(entityName, SyntaxKind.ImportEqualsDeclaration);
1859018587
Debug.assert(importEqualsDeclaration !== undefined);
18591-
return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>entityName, importEqualsDeclaration, /*dontResolveAlias*/ true);
18588+
return getSymbolOfPartOfRightHandSideOfImportEquals(<EntityName>entityName, /*dontResolveAlias*/ true);
1859218589
}
1859318590

1859418591
if (isRightSideOfQualifiedNameOrPropertyAccess(entityName)) {
@@ -19971,7 +19968,7 @@ namespace ts {
1997119968
}
1997219969
}
1997319970

19974-
function checkGrammarTypeParameterList(node: FunctionLikeDeclaration, typeParameters: NodeArray<TypeParameterDeclaration>, file: SourceFile): boolean {
19971+
function checkGrammarTypeParameterList(typeParameters: NodeArray<TypeParameterDeclaration>, file: SourceFile): boolean {
1997519972
if (checkGrammarForDisallowedTrailingComma(typeParameters)) {
1997619973
return true;
1997719974
}
@@ -20022,7 +20019,7 @@ namespace ts {
2002220019
function checkGrammarFunctionLikeDeclaration(node: FunctionLikeDeclaration): boolean {
2002320020
// Prevent cascading error by short-circuit
2002420021
const file = getSourceFileOfNode(node);
20025-
return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarTypeParameterList(node, node.typeParameters, file) ||
20022+
return checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarTypeParameterList(node.typeParameters, file) ||
2002620023
checkGrammarParameterList(node.parameters) || checkGrammarArrowFunction(node, file);
2002720024
}
2002820025

@@ -20208,7 +20205,7 @@ namespace ts {
2020820205
}
2020920206
}
2021020207

20211-
function checkGrammarForInvalidQuestionMark(node: Declaration, questionToken: Node, message: DiagnosticMessage): boolean {
20208+
function checkGrammarForInvalidQuestionMark(questionToken: Node, message: DiagnosticMessage): boolean {
2021220209
if (questionToken) {
2021320210
return grammarErrorOnNode(questionToken, message);
2021420211
}
@@ -20254,7 +20251,7 @@ namespace ts {
2025420251
let currentKind: number;
2025520252
if (prop.kind === SyntaxKind.PropertyAssignment || prop.kind === SyntaxKind.ShorthandPropertyAssignment) {
2025620253
// Grammar checking for computedPropertyName and shorthandPropertyAssignment
20257-
checkGrammarForInvalidQuestionMark(prop, (<PropertyAssignment>prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
20254+
checkGrammarForInvalidQuestionMark((<PropertyAssignment>prop).questionToken, Diagnostics.An_object_member_cannot_be_declared_optional);
2025820255
if (name.kind === SyntaxKind.NumericLiteral) {
2025920256
checkGrammarNumericLiteral(<NumericLiteral>name);
2026020257
}
@@ -20438,7 +20435,7 @@ namespace ts {
2043820435
}
2043920436

2044020437
if (node.parent.kind === SyntaxKind.ObjectLiteralExpression) {
20441-
if (checkGrammarForInvalidQuestionMark(node, node.questionToken, Diagnostics.An_object_member_cannot_be_declared_optional)) {
20438+
if (checkGrammarForInvalidQuestionMark(node.questionToken, Diagnostics.An_object_member_cannot_be_declared_optional)) {
2044220439
return true;
2044320440
}
2044420441
else if (node.body === undefined) {

src/compiler/comments.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ namespace ts {
188188
}
189189
}
190190

191-
function emitLeadingComment(commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean, rangePos: number) {
191+
function emitLeadingComment(commentPos: number, commentEnd: number, _kind: SyntaxKind, hasTrailingNewLine: boolean, rangePos: number) {
192192
if (!hasWrittenComment) {
193193
emitNewLineBeforeLeadingCommentOfPosition(currentLineMap, writer, rangePos, commentPos);
194194
hasWrittenComment = true;
@@ -211,7 +211,7 @@ namespace ts {
211211
forEachTrailingCommentToEmit(pos, emitTrailingComment);
212212
}
213213

214-
function emitTrailingComment(commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean) {
214+
function emitTrailingComment(commentPos: number, commentEnd: number, _kind: SyntaxKind, hasTrailingNewLine: boolean) {
215215
// trailing comments are emitted at space/*trailing comment1 */space/*trailing comment2*/
216216
if (!writer.isAtStartOfLine()) {
217217
writer.write(" ");
@@ -242,7 +242,7 @@ namespace ts {
242242
}
243243
}
244244

245-
function emitTrailingCommentOfPosition(commentPos: number, commentEnd: number, kind: SyntaxKind, hasTrailingNewLine: boolean) {
245+
function emitTrailingCommentOfPosition(commentPos: number, commentEnd: number, _kind: SyntaxKind, hasTrailingNewLine: boolean) {
246246
// trailing comments of a position are emitted at /*trailing comment1 */space/*trailing comment*/space
247247

248248
emitPos(commentPos);

src/compiler/core.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ namespace ts {
903903
return t => compose(a(t));
904904
}
905905
else {
906-
return t => u => u;
906+
return _ => u => u;
907907
}
908908
}
909909

@@ -943,7 +943,7 @@ namespace ts {
943943
function formatStringFromArgs(text: string, args: { [index: number]: string; }, baseIndex?: number): string {
944944
baseIndex = baseIndex || 0;
945945

946-
return text.replace(/{(\d+)}/g, (match, index?) => args[+index + baseIndex]);
946+
return text.replace(/{(\d+)}/g, (_match, index?) => args[+index + baseIndex]);
947947
}
948948

949949
export let localizedDiagnosticMessages: Map<string> = undefined;
@@ -982,7 +982,7 @@ namespace ts {
982982
}
983983

984984
/* internal */
985-
export function formatMessage(dummy: any, message: DiagnosticMessage): string {
985+
export function formatMessage(_dummy: any, message: DiagnosticMessage): string {
986986
let text = getLocaleSpecificMessage(message);
987987

988988
if (arguments.length > 2) {
@@ -1623,7 +1623,7 @@ namespace ts {
16231623
basePaths: string[];
16241624
}
16251625

1626-
export function getFileMatcherPatterns(path: string, extensions: string[], excludes: string[], includes: string[], useCaseSensitiveFileNames: boolean, currentDirectory: string): FileMatcherPatterns {
1626+
export function getFileMatcherPatterns(path: string, excludes: string[], includes: string[], useCaseSensitiveFileNames: boolean, currentDirectory: string): FileMatcherPatterns {
16271627
path = normalizePath(path);
16281628
currentDirectory = normalizePath(currentDirectory);
16291629
const absolutePath = combinePaths(currentDirectory, path);
@@ -1640,7 +1640,7 @@ namespace ts {
16401640
path = normalizePath(path);
16411641
currentDirectory = normalizePath(currentDirectory);
16421642

1643-
const patterns = getFileMatcherPatterns(path, extensions, excludes, includes, useCaseSensitiveFileNames, currentDirectory);
1643+
const patterns = getFileMatcherPatterns(path, excludes, includes, useCaseSensitiveFileNames, currentDirectory);
16441644

16451645
const regexFlag = useCaseSensitiveFileNames ? "" : "i";
16461646
const includeFileRegex = patterns.includeFilePattern && new RegExp(patterns.includeFilePattern, regexFlag);
@@ -1874,11 +1874,11 @@ namespace ts {
18741874
this.declarations = undefined;
18751875
}
18761876

1877-
function Type(this: Type, checker: TypeChecker, flags: TypeFlags) {
1877+
function Type(this: Type, _checker: TypeChecker, flags: TypeFlags) {
18781878
this.flags = flags;
18791879
}
18801880

1881-
function Signature(checker: TypeChecker) {
1881+
function Signature() {
18821882
}
18831883

18841884
function Node(this: Node, kind: SyntaxKind, pos: number, end: number) {
@@ -1911,9 +1911,6 @@ namespace ts {
19111911
}
19121912

19131913
export namespace Debug {
1914-
declare var process: any;
1915-
declare var require: any;
1916-
19171914
export let currentAssertionLevel = AssertionLevel.None;
19181915

19191916
export function shouldAssert(level: AssertionLevel): boolean {

0 commit comments

Comments
 (0)