Merge remote-tracking branch 'origin/master' into tsserverVS-WIP-projectsystem

This commit is contained in:
Vladimir Matveev
2016-06-30 20:26:00 -07:00
69 changed files with 2679 additions and 149 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ Third Party Code Components
--------------------------------------------
------------------- DefinitelyTyped --------------------
This file is based on or incorporates material from the projects listed below (collectively ?Third Party Code?). Microsoft is not the original author of the Third Party Code. The original copyright notice and the license, under which Microsoft received such Third Party Code, are set forth below. Such licenses and notices are provided for informational purposes only. Microsoft, not the third party, licenses the Third Party Code to you under the terms set forth in the EULA for the Microsoft Product. Microsoft reserves all other rights not expressly granted under this agreement, whether by implication, estoppel or otherwise.
This file is based on or incorporates material from the projects listed below (collectively "Third Party Code"). Microsoft is not the original author of the Third Party Code. The original copyright notice and the license, under which Microsoft received such Third Party Code, are set forth below. Such licenses and notices are provided for informational purposes only. Microsoft, not the third party, licenses the Third Party Code to you under the terms set forth in the EULA for the Microsoft Product. Microsoft reserves all other rights not expressly granted under this agreement, whether by implication, estoppel or otherwise.
DefinitelyTyped
This project is licensed under the MIT license.
Copyrights are respective of each contributor listed at the beginning of each definition file.
+173 -94
View File
@@ -51,6 +51,7 @@ namespace ts {
const compilerOptions = host.getCompilerOptions();
const languageVersion = compilerOptions.target || ScriptTarget.ES3;
const modulekind = getEmitModuleKind(compilerOptions);
const noUnusedIdentifiers = !!compilerOptions.noUnusedLocals || !!compilerOptions.noUnusedParameters;
const allowSyntheticDefaultImports = typeof compilerOptions.allowSyntheticDefaultImports !== "undefined" ? compilerOptions.allowSyntheticDefaultImports : modulekind === ModuleKind.System;
const strictNullChecks = compilerOptions.strictNullChecks;
@@ -187,6 +188,7 @@ namespace ts {
let jsxElementClassType: Type;
let deferredNodes: Node[];
let deferredUnusedIdentifierNodes: Node[];
let flowLoopStart = 0;
let flowLoopCount = 0;
@@ -394,7 +396,7 @@ namespace ts {
target.flags |= source.flags;
if (source.valueDeclaration &&
(!target.valueDeclaration ||
(target.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && source.valueDeclaration.kind !== SyntaxKind.ModuleDeclaration))) {
(target.valueDeclaration.kind === SyntaxKind.ModuleDeclaration && source.valueDeclaration.kind !== SyntaxKind.ModuleDeclaration))) {
// other kinds of value declarations take precedence over modules
target.valueDeclaration = source.valueDeclaration;
}
@@ -664,8 +666,8 @@ namespace ts {
useResult = result.flags & SymbolFlags.TypeParameter
// type parameters are visible in parameter list, return type and type parameter list
? lastLocation === (<FunctionLikeDeclaration>location).type ||
lastLocation.kind === SyntaxKind.Parameter ||
lastLocation.kind === SyntaxKind.TypeParameter
lastLocation.kind === SyntaxKind.Parameter ||
lastLocation.kind === SyntaxKind.TypeParameter
// local types not visible outside the function body
: false;
}
@@ -847,6 +849,10 @@ namespace ts {
location = location.parent;
}
if (result && nameNotFoundMessage && noUnusedIdentifiers) {
result.isReferenced = true;
}
if (!result) {
result = getSymbol(globals, name, meaning);
}
@@ -854,7 +860,7 @@ namespace ts {
if (!result) {
if (nameNotFoundMessage) {
if (!checkAndReportErrorForMissingPrefix(errorLocation, name, nameArg) &&
!checkAndReportErrorForExtendingInterface(errorLocation)) {
!checkAndReportErrorForExtendingInterface(errorLocation)) {
error(errorLocation, nameNotFoundMessage, typeof nameArg === "string" ? nameArg : declarationNameToString(nameArg));
}
}
@@ -961,7 +967,7 @@ namespace ts {
return true;
}
return false;
}
}
function checkResolvedBlockScopedVariable(result: Symbol, errorLocation: Node): void {
Debug.assert((result.flags & SymbolFlags.BlockScopedVariable) !== 0);
@@ -1022,8 +1028,8 @@ namespace ts {
const exportDefaultSymbol = isShorthandAmbientModule(moduleSymbol.valueDeclaration) ?
moduleSymbol :
moduleSymbol.exports["export="] ?
getPropertyOfType(getTypeOfSymbol(moduleSymbol.exports["export="]), "default") :
resolveSymbol(moduleSymbol.exports["default"]);
getPropertyOfType(getTypeOfSymbol(moduleSymbol.exports["export="]), "default") :
resolveSymbol(moduleSymbol.exports["default"]);
if (!exportDefaultSymbol && !allowSyntheticDefaultImports) {
error(node.name, Diagnostics.Module_0_has_no_default_export, symbolToString(moduleSymbol));
@@ -4536,7 +4542,7 @@ namespace ts {
: undefined;
const typeParameters = classType ? classType.localTypeParameters :
declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) :
getTypeParametersFromJSDocTemplate(declaration);
getTypeParametersFromJSDocTemplate(declaration);
const returnType = getSignatureReturnTypeFromDeclaration(declaration, minArgumentCount, isJSConstructSignature, classType);
const typePredicate = declaration.type && declaration.type.kind === SyntaxKind.TypePredicate ?
createTypePredicateFromTypePredicateNode(declaration.type as TypePredicateNode) :
@@ -5165,7 +5171,7 @@ namespace ts {
if (typeSet.length === 0) {
return typeSet.containsNull ? typeSet.containsNonWideningType ? nullType : nullWideningType :
typeSet.containsUndefined ? typeSet.containsNonWideningType ? undefinedType : undefinedWideningType :
neverType;
neverType;
}
else if (typeSet.length === 1) {
return typeSet[0];
@@ -5401,8 +5407,8 @@ namespace ts {
const count = sources.length;
const mapper: TypeMapper =
count == 1 ? createUnaryTypeMapper(sources[0], targets ? targets[0] : anyType) :
count == 2 ? createBinaryTypeMapper(sources[0], targets ? targets[0] : anyType, sources[1], targets ? targets[1] : anyType) :
createArrayTypeMapper(sources, targets);
count == 2 ? createBinaryTypeMapper(sources[0], targets ? targets[0] : anyType, sources[1], targets ? targets[1] : anyType) :
createArrayTypeMapper(sources, targets);
mapper.mappedTypes = sources;
return mapper;
}
@@ -5725,8 +5731,8 @@ namespace ts {
}
function isSignatureAssignableTo(source: Signature,
target: Signature,
ignoreReturnTypes: boolean): boolean {
target: Signature,
ignoreReturnTypes: boolean): boolean {
return compareSignaturesRelated(source, target, ignoreReturnTypes, /*reportErrors*/ false, /*errorReporter*/ undefined, compareTypesAssignable) !== Ternary.False;
}
@@ -5734,11 +5740,11 @@ namespace ts {
* See signatureRelatedTo, compareSignaturesIdentical
*/
function compareSignaturesRelated(source: Signature,
target: Signature,
ignoreReturnTypes: boolean,
reportErrors: boolean,
errorReporter: (d: DiagnosticMessage, arg0?: string, arg1?: string) => void,
compareTypes: (s: Type, t: Type, reportErrors?: boolean) => Ternary): Ternary {
target: Signature,
ignoreReturnTypes: boolean,
reportErrors: boolean,
errorReporter: (d: DiagnosticMessage, arg0?: string, arg1?: string) => void,
compareTypes: (s: Type, t: Type, reportErrors?: boolean) => Ternary): Ternary {
// TODO (drosen): De-duplicate code between related functions.
if (source === target) {
return Ternary.True;
@@ -5820,10 +5826,10 @@ namespace ts {
}
function compareTypePredicateRelatedTo(source: TypePredicate,
target: TypePredicate,
reportErrors: boolean,
errorReporter: (d: DiagnosticMessage, arg0?: string, arg1?: string) => void,
compareTypes: (s: Type, t: Type, reportErrors?: boolean) => Ternary): Ternary {
target: TypePredicate,
reportErrors: boolean,
errorReporter: (d: DiagnosticMessage, arg0?: string, arg1?: string) => void,
compareTypes: (s: Type, t: Type, reportErrors?: boolean) => Ternary): Ternary {
if (source.kind !== target.kind) {
if (reportErrors) {
errorReporter(Diagnostics.A_this_based_type_guard_is_not_compatible_with_a_parameter_based_type_guard);
@@ -6904,7 +6910,7 @@ namespace ts {
function isStringLiteralUnionType(type: Type): boolean {
return type.flags & TypeFlags.StringLiteral ? true :
type.flags & TypeFlags.Union ? forEach((<UnionType>type).types, isStringLiteralUnionType) :
false;
false;
}
/**
@@ -6986,11 +6992,11 @@ namespace ts {
const resolved = <ResolvedType>type;
const members = transformTypeOfMembers(type, getRegularTypeOfObjectLiteral);
const regularNew = createAnonymousType(resolved.symbol,
members,
resolved.callSignatures,
resolved.constructSignatures,
resolved.stringIndexInfo,
resolved.numberIndexInfo);
members,
resolved.callSignatures,
resolved.constructSignatures,
resolved.stringIndexInfo,
resolved.numberIndexInfo);
regularNew.flags = resolved.flags & ~TypeFlags.FreshObjectLiteral;
(<FreshObjectLiteralType>type).regularType = regularNew;
return regularNew;
@@ -7818,7 +7824,7 @@ namespace ts {
// We cache results of flow type resolution for shared nodes that were previously visited in
// the same getFlowTypeOfReference invocation. A node is considered shared when it is the
// antecedent of more than one node.
for (let i = visitedFlowStart; i < visitedFlowCount; i++) {
for (let i = visitedFlowStart; i < visitedFlowCount; i++) {
if (visitedFlowNodes[i] === flow) {
return visitedFlowTypes[i];
}
@@ -8205,7 +8211,7 @@ namespace ts {
const targetType = type.flags & TypeFlags.TypeParameter ? getApparentType(type) : type;
return isTypeAssignableTo(candidate, targetType) ? candidate :
isTypeAssignableTo(type, candidate) ? type :
getIntersectionType([type, candidate]);
getIntersectionType([type, candidate]);
}
function narrowTypeByTypePredicate(type: Type, callExpression: CallExpression, assumeTrue: boolean): Type {
@@ -8319,21 +8325,8 @@ namespace ts {
return container === declarationContainer;
}
function updateReferencesForInterfaceHeritiageClauseTargets(node: InterfaceDeclaration): void {
const extendedTypeNode = getClassExtendsHeritageClauseElement(node);
if (extendedTypeNode) {
const t = getTypeFromTypeNode(extendedTypeNode);
if (t !== unknownType && t.symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !isInAmbientContext(node)) {
t.symbol.hasReference = true;
}
}
}
function checkIdentifier(node: Identifier): Type {
const symbol = getResolvedSymbol(node);
if (symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !isInAmbientContext(node)) {
symbol.hasReference = true;
}
// As noted in ECMAScript 6 language spec, arrow functions never have an arguments objects.
// Although in down-level emit of arrow function, we emit it using function expression which means that
@@ -8624,9 +8617,9 @@ namespace ts {
getSpecialPropertyAssignmentKind(container.parent) === SpecialPropertyAssignmentKind.PrototypeProperty) {
// Get the 'x' of 'x.prototype.y = f' (here, 'f' is 'container')
const className = (((container.parent as BinaryExpression) // x.prototype.y = f
.left as PropertyAccessExpression) // x.prototype.y
.expression as PropertyAccessExpression) // x.prototype
.expression; // x
.left as PropertyAccessExpression) // x.prototype.y
.expression as PropertyAccessExpression) // x.prototype
.expression; // x
const classSymbol = checkExpression(className).symbol;
if (classSymbol && classSymbol.members && (classSymbol.flags & SymbolFlags.Function)) {
return getInferredClassType(classSymbol);
@@ -9871,7 +9864,7 @@ namespace ts {
elemType = checkExpression(node.tagName);
}
if (elemType.flags & TypeFlags.Union) {
const types = (<UnionOrIntersectionType> elemType).types;
const types = (<UnionOrIntersectionType>elemType).types;
return getUnionType(types.map(type => {
return getResolvedJsxType(node, type, elemClassType);
}));
@@ -10248,8 +10241,16 @@ namespace ts {
return unknownType;
}
if ((compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !isInAmbientContext(node)) {
prop.hasReference = true;
if (noUnusedIdentifiers &&
(prop.flags & SymbolFlags.ClassMember) &&
prop.valueDeclaration && (prop.valueDeclaration.flags & NodeFlags.Private)) {
if (prop.flags & SymbolFlags.Instantiated) {
getSymbolLinks(prop).target.isReferenced = true;
}
else {
prop.isReferenced = true;
}
}
getNodeLinks(node).resolvedSymbol = prop;
@@ -11803,7 +11804,7 @@ namespace ts {
// if inference didn't come up with anything but {}, fall back to the binding pattern if present.
if (links.type === emptyObjectType &&
(parameter.valueDeclaration.name.kind === SyntaxKind.ObjectBindingPattern ||
parameter.valueDeclaration.name.kind === SyntaxKind.ArrayBindingPattern)) {
parameter.valueDeclaration.name.kind === SyntaxKind.ArrayBindingPattern)) {
links.type = getTypeFromBindingPattern(<BindingPattern>parameter.valueDeclaration.name);
}
assignBindingElementTypes(<ParameterDeclaration>parameter.valueDeclaration);
@@ -12194,8 +12195,7 @@ namespace ts {
}
}
}
checkUnusedIdentifiers(node);
checkUnusedTypeParameters(node);
registerForUnusedIdentifiersCheck(node);
}
}
@@ -12544,6 +12544,12 @@ namespace ts {
if (exprOrAssignment.kind === SyntaxKind.ShorthandPropertyAssignment) {
const prop = <ShorthandPropertyAssignment>exprOrAssignment;
if (prop.objectAssignmentInitializer) {
// In strict null checking mode, if a default value of a non-undefined type is specified, remove
// undefined from the final type.
if (strictNullChecks &&
!(getCombinedTypeFlags(checkExpression(prop.objectAssignmentInitializer)) & TypeFlags.Undefined)) {
sourceType = getTypeWithFacts(sourceType, TypeFacts.NEUndefined);
}
checkBinaryLikeExpression(prop.name, prop.equalsToken, prop.objectAssignmentInitializer, contextualMapper);
}
target = (<ShorthandPropertyAssignment>exprOrAssignment).name;
@@ -13423,8 +13429,7 @@ namespace ts {
checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node);
checkSourceElement(node.body);
checkUnusedIdentifiers(node);
checkUnusedTypeParameters(node);
registerForUnusedIdentifiersCheck(node);
const symbol = getSymbolOfNode(node);
const firstDeclaration = getDeclarationOfKind(symbol, node.kind);
@@ -13570,6 +13575,7 @@ namespace ts {
}
if (node.parent.kind !== SyntaxKind.ObjectLiteralExpression) {
checkSourceElement(node.body);
registerForUnusedIdentifiersCheck(node);
}
else {
checkNodeDeferred(node);
@@ -13586,6 +13592,7 @@ namespace ts {
function checkAccessorDeferred(node: AccessorDeclaration) {
checkSourceElement(node.body);
registerForUnusedIdentifiersCheck(node);
}
function checkMissingDeclaration(node: Node) {
@@ -13618,9 +13625,6 @@ namespace ts {
checkGrammarTypeArguments(node, node.typeArguments);
const type = getTypeFromTypeReference(node);
if (type !== unknownType) {
if (type.symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !isInAmbientContext(node)) {
type.symbol.hasReference = true;
}
if (node.typeArguments) {
// Do type argument local checks only if referenced type is successfully resolved
forEach(node.typeArguments, checkSourceElement);
@@ -14471,8 +14475,7 @@ namespace ts {
}
checkSourceElement(node.body);
checkUnusedIdentifiers(node);
checkUnusedTypeParameters(node);
if (!node.asteriskToken) {
const returnOrPromisedType = node.type && (isAsync ? checkAsyncFunctionReturnType(node) : getTypeFromTypeNode(node.type));
checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnOrPromisedType);
@@ -14492,40 +14495,96 @@ namespace ts {
getReturnTypeOfSignature(getSignatureFromDeclaration(node));
}
}
registerForUnusedIdentifiersCheck(node);
}
function checkUnusedIdentifiers(node: FunctionDeclaration | MethodDeclaration | ConstructorDeclaration | FunctionExpression | ArrowFunction | ForInStatement | Block | CatchClause): void {
if (node.parent.kind !== SyntaxKind.InterfaceDeclaration && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !isInAmbientContext(node)) {
function registerForUnusedIdentifiersCheck(node: Node) {
if (deferredUnusedIdentifierNodes) {
deferredUnusedIdentifierNodes.push(node);
}
}
function checkUnusedIdentifiers() {
if (deferredUnusedIdentifierNodes) {
for (const node of deferredUnusedIdentifierNodes) {
switch (node.kind) {
case SyntaxKind.SourceFile:
case SyntaxKind.ModuleDeclaration:
checkUnusedModuleMembers(<ModuleDeclaration | SourceFile>node);
break;
case SyntaxKind.ClassDeclaration:
case SyntaxKind.ClassExpression:
checkUnusedClassMembers(<ClassDeclaration | ClassExpression>node);
checkUnusedTypeParameters(<ClassDeclaration | ClassExpression>node);
break;
case SyntaxKind.InterfaceDeclaration:
checkUnusedTypeParameters(<InterfaceDeclaration>node);
break;
case SyntaxKind.Block:
case SyntaxKind.CaseBlock:
case SyntaxKind.ForStatement:
case SyntaxKind.ForInStatement:
case SyntaxKind.ForOfStatement:
checkUnusedLocalsAndParameters(node);
break;
case SyntaxKind.Constructor:
case SyntaxKind.FunctionExpression:
case SyntaxKind.FunctionDeclaration:
case SyntaxKind.ArrowFunction:
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
if ((<FunctionLikeDeclaration>node).body) {
checkUnusedLocalsAndParameters(<FunctionLikeDeclaration>node);
}
checkUnusedTypeParameters(<FunctionLikeDeclaration>node);
break;
case SyntaxKind.MethodSignature:
case SyntaxKind.CallSignature:
case SyntaxKind.ConstructSignature:
case SyntaxKind.IndexSignature:
case SyntaxKind.FunctionType:
case SyntaxKind.ConstructorType:
checkUnusedTypeParameters(<FunctionLikeDeclaration>node);
break;
};
}
}
}
function checkUnusedLocalsAndParameters(node: Node): void {
if (node.parent.kind !== SyntaxKind.InterfaceDeclaration && noUnusedIdentifiers && !isInAmbientContext(node)) {
for (const key in node.locals) {
if (hasProperty(node.locals, key)) {
const local = node.locals[key];
if (!local.hasReference && local.valueDeclaration) {
if (local.valueDeclaration.kind !== SyntaxKind.Parameter && compilerOptions.noUnusedLocals) {
error(local.valueDeclaration.name, Diagnostics._0_is_declared_but_never_used, local.name);
}
else if (local.valueDeclaration.kind === SyntaxKind.Parameter && compilerOptions.noUnusedParameters) {
if (local.valueDeclaration.flags === 0) {
if (!local.isReferenced) {
if (local.valueDeclaration && local.valueDeclaration.kind === SyntaxKind.Parameter) {
if (compilerOptions.noUnusedParameters && !isParameterPropertyDeclaration(<ParameterDeclaration>local.valueDeclaration)) {
error(local.valueDeclaration.name, Diagnostics._0_is_declared_but_never_used, local.name);
}
}
else if (compilerOptions.noUnusedLocals) {
forEach(local.declarations, d => error(d.name || d, Diagnostics._0_is_declared_but_never_used, local.name));
}
}
}
}
}
}
function checkUnusedClassLocals(node: ClassDeclaration): void {
function checkUnusedClassMembers(node: ClassDeclaration | ClassExpression): void {
if (compilerOptions.noUnusedLocals && !isInAmbientContext(node)) {
if (node.members) {
for (const member of node.members) {
if (member.kind === SyntaxKind.MethodDeclaration || member.kind === SyntaxKind.PropertyDeclaration) {
if (isPrivateNode(member) && !member.symbol.hasReference) {
if (!member.symbol.isReferenced && member.flags & NodeFlags.Private) {
error(member.name, Diagnostics._0_is_declared_but_never_used, member.symbol.name);
}
}
else if (member.kind === SyntaxKind.Constructor) {
for (const parameter of (<ConstructorDeclaration>member).parameters) {
if (isPrivateNode(parameter) && !parameter.symbol.hasReference) {
if (!parameter.symbol.isReferenced && parameter.flags & NodeFlags.Private) {
error(parameter.name, Diagnostics._0_is_declared_but_never_used, parameter.symbol.name);
}
}
@@ -14535,11 +14594,11 @@ namespace ts {
}
}
function checkUnusedTypeParameters(node: ClassDeclaration | FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction | ConstructorDeclaration | SignatureDeclaration | InterfaceDeclaration) {
function checkUnusedTypeParameters(node: ClassDeclaration | ClassExpression | FunctionDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction | ConstructorDeclaration | SignatureDeclaration | InterfaceDeclaration) {
if (compilerOptions.noUnusedLocals && !isInAmbientContext(node)) {
if (node.typeParameters) {
for (const typeParameter of node.typeParameters) {
if (!typeParameter.symbol.hasReference) {
if (!typeParameter.symbol.isReferenced) {
error(typeParameter.name, Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name);
}
}
@@ -14547,17 +14606,17 @@ namespace ts {
}
}
function isPrivateNode(node: Node): boolean {
return (node.flags & NodeFlags.Private) !== 0;
}
function checkUnusedModuleLocals(node: ModuleDeclaration | SourceFile): void {
function checkUnusedModuleMembers(node: ModuleDeclaration | SourceFile): void {
if (compilerOptions.noUnusedLocals && !isInAmbientContext(node)) {
for (const key in node.locals) {
if (hasProperty(node.locals, key)) {
const local = node.locals[key];
if (!local.hasReference && !local.exportSymbol) {
forEach(local.declarations, d => error(d.name, Diagnostics._0_is_declared_but_never_used, local.name));
if (!local.isReferenced && !local.exportSymbol) {
for (const declaration of local.declarations) {
if (!isAmbientModule(declaration)) {
error(declaration.name, Diagnostics._0_is_declared_but_never_used, local.name);
}
}
}
}
}
@@ -14570,7 +14629,9 @@ namespace ts {
checkGrammarStatementInAmbientContext(node);
}
forEach(node.statements, checkSourceElement);
checkUnusedIdentifiers(node);
if (node.locals) {
registerForUnusedIdentifiersCheck(node);
}
}
function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) {
@@ -15035,6 +15096,9 @@ namespace ts {
if (node.condition) checkExpression(node.condition);
if (node.incrementor) checkExpression(node.incrementor);
checkSourceElement(node.statement);
if (node.locals) {
registerForUnusedIdentifiersCheck(node);
}
}
function checkForOfStatement(node: ForOfStatement): void {
@@ -15075,7 +15139,9 @@ namespace ts {
}
checkSourceElement(node.statement);
checkUnusedIdentifiers(node);
if (node.locals) {
registerForUnusedIdentifiersCheck(node);
}
}
function checkForInStatement(node: ForInStatement) {
@@ -15123,7 +15189,9 @@ namespace ts {
}
checkSourceElement(node.statement);
checkUnusedIdentifiers(node);
if (node.locals) {
registerForUnusedIdentifiersCheck(node);
}
}
function checkForInOrForOfVariableDeclaration(iterationStatement: ForInStatement | ForOfStatement): void {
@@ -15388,7 +15456,7 @@ namespace ts {
function isUnwrappedReturnTypeVoidOrAny(func: FunctionLikeDeclaration, returnType: Type): boolean {
const unwrappedReturnType = isAsyncFunctionLike(func) ? getPromisedType(returnType) : returnType;
return maybeTypeOfKind(unwrappedReturnType, TypeFlags.Void | TypeFlags.Any);
return unwrappedReturnType && maybeTypeOfKind(unwrappedReturnType, TypeFlags.Void | TypeFlags.Any);
}
function checkReturnStatement(node: ReturnStatement) {
@@ -15496,6 +15564,9 @@ namespace ts {
}
forEach(clause.statements, checkSourceElement);
});
if (node.caseBlock.locals) {
registerForUnusedIdentifiersCheck(node.caseBlock);
}
}
function checkLabeledStatement(node: LabeledStatement) {
@@ -15563,7 +15634,6 @@ namespace ts {
}
checkBlock(catchClause.block);
checkUnusedIdentifiers(catchClause);
}
if (node.finallyBlock) {
@@ -15717,6 +15787,7 @@ namespace ts {
function checkClassExpressionDeferred(node: ClassExpression) {
forEach(node.members, checkSourceElement);
registerForUnusedIdentifiersCheck(node);
}
function checkClassDeclaration(node: ClassDeclaration) {
@@ -15725,8 +15796,8 @@ namespace ts {
}
checkClassLikeDeclaration(node);
forEach(node.members, checkSourceElement);
checkUnusedClassLocals(node);
checkUnusedTypeParameters(node);
registerForUnusedIdentifiersCheck(node);
}
function checkClassLikeDeclaration(node: ClassLikeDeclaration) {
@@ -16036,7 +16107,6 @@ namespace ts {
if (produceDiagnostics) {
checkTypeForDuplicateIndexSignatures(node);
updateReferencesForInterfaceHeritiageClauseTargets(node);
checkUnusedTypeParameters(node);
}
}
@@ -16434,7 +16504,9 @@ namespace ts {
if (node.body) {
checkSourceElement(node.body);
checkUnusedModuleLocals(node);
if (!isGlobalScopeAugmentation(node)) {
registerForUnusedIdentifiersCheck(node);
}
}
}
@@ -16615,9 +16687,6 @@ namespace ts {
if (target.flags & SymbolFlags.Type) {
checkTypeNameIsReserved(node.name, Diagnostics.Import_name_cannot_be_0);
}
if ((compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !isInAmbientContext(node)) {
target.hasReference = true;
}
}
}
else {
@@ -16959,12 +17028,22 @@ namespace ts {
potentialThisCollisions.length = 0;
deferredNodes = [];
deferredUnusedIdentifierNodes = produceDiagnostics && noUnusedIdentifiers ? [] : undefined;
forEach(node.statements, checkSourceElement);
if (isExternalModule(node)) {
checkUnusedModuleLocals(node);
}
checkDeferredNodes();
if (isExternalModule(node)) {
registerForUnusedIdentifiersCheck(node);
}
if (!node.isDeclarationFile) {
checkUnusedIdentifiers();
}
deferredNodes = undefined;
deferredUnusedIdentifierNodes = undefined;
if (isExternalOrCommonJsModule(node)) {
checkExternalModuleExports(node);
+5 -5
View File
@@ -1156,12 +1156,12 @@ namespace ts {
if (token === SyntaxKind.ExportKeyword) {
nextToken();
if (token === SyntaxKind.DefaultKeyword) {
return lookAhead(nextTokenIsClassOrFunction);
return lookAhead(nextTokenIsClassOrFunctionOrAsync);
}
return token !== SyntaxKind.AsteriskToken && token !== SyntaxKind.AsKeyword && token !== SyntaxKind.OpenBraceToken && canFollowModifier();
}
if (token === SyntaxKind.DefaultKeyword) {
return nextTokenIsClassOrFunction();
return nextTokenIsClassOrFunctionOrAsync();
}
if (token === SyntaxKind.StaticKeyword) {
nextToken();
@@ -1183,9 +1183,9 @@ namespace ts {
|| isLiteralPropertyName();
}
function nextTokenIsClassOrFunction(): boolean {
function nextTokenIsClassOrFunctionOrAsync(): boolean {
nextToken();
return token === SyntaxKind.ClassKeyword || token === SyntaxKind.FunctionKeyword;
return token === SyntaxKind.ClassKeyword || token === SyntaxKind.FunctionKeyword || token === SyntaxKind.AsyncKeyword;
}
// True if positioned at the start of a list element
@@ -5071,7 +5071,7 @@ namespace ts {
* In such situations, 'permitInvalidConstAsModifier' should be set to true.
*/
function parseModifiers(permitInvalidConstAsModifier?: boolean): ModifiersArray {
let flags = 0;
let flags: NodeFlags = 0;
let modifiers: ModifiersArray;
while (true) {
const modifierStart = scanner.getStartPos();
+22 -15
View File
@@ -779,13 +779,18 @@ namespace ts {
while (true) {
const baseName = getBaseFileName(directory);
if (baseName !== "node_modules") {
const result =
// first: try to load module as-is
loadModuleFromNodeModulesFolder(moduleName, directory, failedLookupLocations, state) ||
// second: try to load module from the scope '@types'
loadModuleFromNodeModulesFolder(combinePaths("@types", moduleName), directory, failedLookupLocations, state);
if (result) {
return result;
// Try to load source from the package
const packageResult = loadModuleFromNodeModulesFolder(moduleName, directory, failedLookupLocations, state);
if (packageResult && hasTypeScriptFileExtension(packageResult)) {
// Always prefer a TypeScript (.ts, .tsx, .d.ts) file shipped with the package
return packageResult;
}
else {
// Else prefer a types package over non-TypeScript results (e.g. JavaScript files)
const typesResult = loadModuleFromNodeModulesFolder(combinePaths("@types", moduleName), directory, failedLookupLocations, state);
if (typesResult || packageResult) {
return typesResult || packageResult;
}
}
}
@@ -1097,7 +1102,7 @@ namespace ts {
const modulesWithElidedImports: Map<boolean> = {};
// Track source files that are JavaScript files found by searching under node_modules, as these shouldn't be compiled.
const jsFilesFoundSearchingNodeModules: Map<boolean> = {};
const sourceFilesFoundSearchingNodeModules: Map<boolean> = {};
const start = new Date().getTime();
@@ -1379,7 +1384,7 @@ namespace ts {
getSourceFile: program.getSourceFile,
getSourceFileByPath: program.getSourceFileByPath,
getSourceFiles: program.getSourceFiles,
getFilesFromNodeModules: () => jsFilesFoundSearchingNodeModules,
isSourceFileFromExternalLibrary: (file: SourceFile) => !!lookUp(sourceFilesFoundSearchingNodeModules, file.path),
writeFile: writeFileCallback || (
(fileName, data, writeByteOrderMark, onError, sourceFiles) => host.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles)),
isEmitBlocked,
@@ -2071,15 +2076,17 @@ namespace ts {
// - noResolve is falsy
// - module name comes from the list of imports
// - it's not a top level JavaScript module that exceeded the search max
const isJsFileUnderNodeModules = resolution && resolution.isExternalLibraryImport &&
hasJavaScriptFileExtension(resolution.resolvedFileName);
const isFromNodeModulesSearch = resolution && resolution.isExternalLibraryImport;
const isJsFileFromNodeModules = isFromNodeModulesSearch && hasJavaScriptFileExtension(resolution.resolvedFileName);
if (isJsFileUnderNodeModules) {
jsFilesFoundSearchingNodeModules[resolvedPath] = true;
if (isFromNodeModulesSearch) {
sourceFilesFoundSearchingNodeModules[resolvedPath] = true;
}
if (isJsFileFromNodeModules) {
currentNodeModulesJsDepth++;
}
const elideImport = isJsFileUnderNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth;
const elideImport = isJsFileFromNodeModules && currentNodeModulesJsDepth > maxNodeModulesJsDepth;
const shouldAddFile = resolution && !options.noResolve && i < file.imports.length && !elideImport;
if (elideImport) {
@@ -2094,7 +2101,7 @@ namespace ts {
file.imports[i].end);
}
if (isJsFileUnderNodeModules) {
if (isJsFileFromNodeModules) {
currentNodeModulesJsDepth--;
}
}
+4 -2
View File
@@ -469,7 +469,7 @@ namespace ts {
}
export interface ModifiersArray extends NodeArray<Modifier> {
flags: number;
flags: NodeFlags;
}
// @kind(SyntaxKind.AbstractKeyword)
@@ -2108,6 +2108,8 @@ namespace ts {
PropertyOrAccessor = Property | Accessor,
Export = ExportNamespace | ExportType | ExportValue,
ClassMember = Method | Accessor | Property,
/* @internal */
// The set of things we consider semantically classifiable. Used to speed up the LS during
// classification.
@@ -2129,7 +2131,7 @@ namespace ts {
/* @internal */ parent?: Symbol; // Parent symbol
/* @internal */ exportSymbol?: Symbol; // Exported symbol associated with this symbol
/* @internal */ constEnumOnlyModule?: boolean; // True if module contains only const enums or other modules with only const enums
/* @internal */ hasReference?: boolean; // True if the symbol is referenced elsewhere
/* @internal */ isReferenced?: boolean; // True if the symbol is referenced elsewhere
}
/* @internal */
+3 -5
View File
@@ -36,7 +36,7 @@ namespace ts {
getSourceFiles(): SourceFile[];
/* @internal */
getFilesFromNodeModules(): Map<boolean>;
isSourceFileFromExternalLibrary(file: SourceFile): boolean;
getCommonSourceDirectory(): string;
getCanonicalFileName(fileName: string): string;
@@ -2277,10 +2277,9 @@ namespace ts {
}
else {
const sourceFiles = targetSourceFile === undefined ? host.getSourceFiles() : [targetSourceFile];
const nodeModulesFiles = host.getFilesFromNodeModules();
for (const sourceFile of sourceFiles) {
// Don't emit if source file is a declaration file, or was located under node_modules
if (!isDeclarationFile(sourceFile) && !lookUp(nodeModulesFiles, sourceFile.path)) {
if (!isDeclarationFile(sourceFile) && !host.isSourceFileFromExternalLibrary(sourceFile)) {
onSingleFileEmit(host, sourceFile);
}
}
@@ -2314,10 +2313,9 @@ namespace ts {
function onBundledEmit(host: EmitHost) {
// Can emit only sources that are not declaration file and are either non module code or module with
// --module or --target es6 specified. Files included by searching under node_modules are also not emitted.
const nodeModulesFiles = host.getFilesFromNodeModules();
const bundledSources = filter(host.getSourceFiles(),
sourceFile => !isDeclarationFile(sourceFile) &&
!lookUp(nodeModulesFiles, sourceFile.path) &&
!host.isSourceFileFromExternalLibrary(sourceFile) &&
(!isExternalModule(sourceFile) ||
!!getEmitModuleKind(options)));
if (bundledSources.length) {
+4 -1
View File
@@ -284,5 +284,8 @@ interface VarDate { }
interface DateConstructor {
new (vd: VarDate): Date;
}
interface Date {
getVarDate: () => VarDate;
}
}
+1 -1
View File
@@ -497,7 +497,7 @@ namespace ts.formatting {
return childKind !== SyntaxKind.NamedExports;
case SyntaxKind.ImportDeclaration:
return childKind !== SyntaxKind.ImportClause ||
(<ImportClause>child).namedBindings.kind !== SyntaxKind.NamedImports;
((<ImportClause>child).namedBindings && (<ImportClause>child).namedBindings.kind !== SyntaxKind.NamedImports);
case SyntaxKind.JsxElement:
return childKind !== SyntaxKind.JsxClosingElement;
}
+1 -2
View File
@@ -412,8 +412,7 @@ namespace ts.NavigationBar {
case SyntaxKind.JSDocTypedefTag:
return getJSDocTypedefTagName(<JSDocTypedefTag>node);
default:
Debug.fail();
return "";
return "<unknown>";
}
}
@@ -0,0 +1,25 @@
error TS2318: Cannot find global type 'Promise'.
tests/cases/compiler/asyncFunctionNoReturnType.ts(1,1): error TS1311: Async functions are only available when targeting ECMAScript 2015 or higher.
tests/cases/compiler/asyncFunctionNoReturnType.ts(1,1): error TS1057: An async function or method must have a valid awaitable return type.
tests/cases/compiler/asyncFunctionNoReturnType.ts(1,1): error TS7030: Not all code paths return a value.
tests/cases/compiler/asyncFunctionNoReturnType.ts(2,9): error TS2304: Cannot find name 'window'.
tests/cases/compiler/asyncFunctionNoReturnType.ts(3,9): error TS7030: Not all code paths return a value.
!!! error TS2318: Cannot find global type 'Promise'.
==== tests/cases/compiler/asyncFunctionNoReturnType.ts (5 errors) ====
async () => {
~~~~~
!!! error TS1311: Async functions are only available when targeting ECMAScript 2015 or higher.
~~~~~~~~~~~~~
!!! error TS1057: An async function or method must have a valid awaitable return type.
~~~~~~~~~~~~~
!!! error TS7030: Not all code paths return a value.
if (window)
~~~~~~
!!! error TS2304: Cannot find name 'window'.
return;
~~~~~~~
!!! error TS7030: Not all code paths return a value.
}
@@ -0,0 +1,20 @@
//// [asyncFunctionNoReturnType.ts]
async () => {
if (window)
return;
}
//// [asyncFunctionNoReturnType.js]
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
(function () __awaiter(this, void 0, void 0, function* () {
if (window)
return;
}));
@@ -0,0 +1,11 @@
//// [destructuringAssignmentWithDefault.ts]
const a: { x?: number } = { };
let x = 0;
({x = 1} = a);
//// [destructuringAssignmentWithDefault.js]
var a = {};
var x = 0;
(_a = a.x, x = _a === void 0 ? 1 : _a, a);
var _a;
@@ -0,0 +1,12 @@
=== tests/cases/compiler/destructuringAssignmentWithDefault.ts ===
const a: { x?: number } = { };
>a : Symbol(a, Decl(destructuringAssignmentWithDefault.ts, 0, 5))
>x : Symbol(x, Decl(destructuringAssignmentWithDefault.ts, 0, 10))
let x = 0;
>x : Symbol(x, Decl(destructuringAssignmentWithDefault.ts, 1, 3))
({x = 1} = a);
>x : Symbol(x, Decl(destructuringAssignmentWithDefault.ts, 2, 2))
>a : Symbol(a, Decl(destructuringAssignmentWithDefault.ts, 0, 5))
@@ -0,0 +1,17 @@
=== tests/cases/compiler/destructuringAssignmentWithDefault.ts ===
const a: { x?: number } = { };
>a : { x?: number | undefined; }
>x : number | undefined
>{ } : {}
let x = 0;
>x : number
>0 : number
({x = 1} = a);
>({x = 1} = a) : { x?: number | undefined; }
>{x = 1} = a : { x?: number | undefined; }
>{x = 1} : { x?: number; }
>x : number
>a : { x?: number | undefined; }
@@ -0,0 +1,18 @@
//// [exportDefaultAsyncFunction.ts]
export default async function foo(): Promise<void> {}
foo();
//// [exportDefaultAsyncFunction.js]
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
export default function foo() {
return __awaiter(this, void 0, void 0, function* () { });
}
foo();
@@ -0,0 +1,8 @@
=== tests/cases/compiler/exportDefaultAsyncFunction.ts ===
export default async function foo(): Promise<void> {}
>foo : Symbol(foo, Decl(exportDefaultAsyncFunction.ts, 0, 0))
>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --))
foo();
>foo : Symbol(foo, Decl(exportDefaultAsyncFunction.ts, 0, 0))
@@ -0,0 +1,9 @@
=== tests/cases/compiler/exportDefaultAsyncFunction.ts ===
export default async function foo(): Promise<void> {}
>foo : () => Promise<void>
>Promise : Promise<T>
foo();
>foo() : Promise<void>
>foo : () => Promise<void>
@@ -8,8 +8,6 @@ export {};
//// [app.ts]
import "A"
//// [index.js]
"use strict";
//// [app.js]
"use strict";
require("A");
@@ -31,9 +31,6 @@ exports.x = 1;
//// [file2.js]
"use strict";
exports.y = 1;
//// [file4.js]
"use strict";
exports.z1 = 1;
//// [file1.js]
"use strict";
var file1_1 = require("folder2/file1");
@@ -1,6 +1,7 @@
define(["require", "exports", "m1"], function (require, exports, m1) {
define(["require", "exports", "m1", "m4"], function (require, exports, m1, m4) {
"use strict";
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number
m1.f2.person.age = "10"; // Should error if loaded the .js files correctly
var r2 = 3 + m4.foo; // Should be OK if correctly using the @types .d.ts file
});
@@ -1,4 +1,4 @@
maxDepthIncreased/root.ts(4,1): error TS2322: Type 'string' is not assignable to type 'number'.
maxDepthIncreased/root.ts(7,1): error TS2322: Type 'string' is not assignable to type 'number'.
==== index.js (0 errors) ====
@@ -28,11 +28,19 @@ maxDepthIncreased/root.ts(4,1): error TS2322: Type 'string' is not assignable to
exports.f2 = m2;
==== entry.d.ts (0 errors) ====
export declare var foo: number;
==== maxDepthIncreased/root.ts (1 errors) ====
import * as m1 from "m1";
import * as m4 from "m4";
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number
m1.f2.person.age = "10"; // Should error if loaded the .js files correctly
~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
let r2 = 3 + m4.foo; // Should be OK if correctly using the @types .d.ts file
@@ -10,6 +10,7 @@
"maxDepthIncreased/node_modules/m2/node_modules/m3/index.js",
"maxDepthIncreased/node_modules/m2/entry.js",
"maxDepthIncreased/node_modules/m1/index.js",
"maxDepthIncreased/node_modules/@types/m4/entry.d.ts",
"maxDepthIncreased/root.ts"
],
"emittedFiles": [
@@ -1,5 +1,7 @@
"use strict";
var m1 = require("m1");
var m4 = require("m4");
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number
m1.f2.person.age = "10"; // Should error if loaded the .js files correctly
var r2 = 3 + m4.foo; // Should be OK if correctly using the @types .d.ts file
@@ -1,4 +1,4 @@
maxDepthIncreased/root.ts(4,1): error TS2322: Type 'string' is not assignable to type 'number'.
maxDepthIncreased/root.ts(7,1): error TS2322: Type 'string' is not assignable to type 'number'.
==== index.js (0 errors) ====
@@ -28,11 +28,19 @@ maxDepthIncreased/root.ts(4,1): error TS2322: Type 'string' is not assignable to
exports.f2 = m2;
==== entry.d.ts (0 errors) ====
export declare var foo: number;
==== maxDepthIncreased/root.ts (1 errors) ====
import * as m1 from "m1";
import * as m4 from "m4";
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number
m1.f2.person.age = "10"; // Should error if loaded the .js files correctly
~~~~~~~~~~~~~~~~
!!! error TS2322: Type 'string' is not assignable to type 'number'.
let r2 = 3 + m4.foo; // Should be OK if correctly using the @types .d.ts file
@@ -10,6 +10,7 @@
"maxDepthIncreased/node_modules/m2/node_modules/m3/index.js",
"maxDepthIncreased/node_modules/m2/entry.js",
"maxDepthIncreased/node_modules/m1/index.js",
"maxDepthIncreased/node_modules/@types/m4/entry.d.ts",
"maxDepthIncreased/root.ts"
],
"emittedFiles": [
@@ -0,0 +1,41 @@
//// [tests/cases/compiler/unusedImports11.ts] ////
//// [b.ts]
export class Member {}
export default Member;
//// [a.ts]
import { Member } from './b';
import d, { Member as M } from './b';
import * as ns from './b';
import r = require("./b");
new Member();
new d();
new M();
new ns.Member();
new r.Member();
//// [b.js]
"use strict";
var Member = (function () {
function Member() {
}
return Member;
}());
exports.Member = Member;
exports.__esModule = true;
exports["default"] = Member;
//// [a.js]
"use strict";
var b_1 = require('./b');
var b_2 = require('./b');
var ns = require('./b');
var r = require("./b");
new b_1.Member();
new b_2["default"]();
new b_2.Member();
new ns.Member();
new r.Member();
@@ -0,0 +1,43 @@
=== tests/cases/compiler/a.ts ===
import { Member } from './b';
>Member : Symbol(Member, Decl(a.ts, 0, 8))
import d, { Member as M } from './b';
>d : Symbol(d, Decl(a.ts, 1, 6))
>Member : Symbol(M, Decl(a.ts, 1, 11))
>M : Symbol(M, Decl(a.ts, 1, 11))
import * as ns from './b';
>ns : Symbol(ns, Decl(a.ts, 2, 6))
import r = require("./b");
>r : Symbol(r, Decl(a.ts, 2, 26))
new Member();
>Member : Symbol(Member, Decl(a.ts, 0, 8))
new d();
>d : Symbol(d, Decl(a.ts, 1, 6))
new M();
>M : Symbol(M, Decl(a.ts, 1, 11))
new ns.Member();
>ns.Member : Symbol(Member, Decl(b.ts, 0, 0))
>ns : Symbol(ns, Decl(a.ts, 2, 6))
>Member : Symbol(Member, Decl(b.ts, 0, 0))
new r.Member();
>r.Member : Symbol(Member, Decl(b.ts, 0, 0))
>r : Symbol(r, Decl(a.ts, 2, 26))
>Member : Symbol(Member, Decl(b.ts, 0, 0))
=== tests/cases/compiler/b.ts ===
export class Member {}
>Member : Symbol(Member, Decl(b.ts, 0, 0))
export default Member;
>Member : Symbol(Member, Decl(b.ts, 0, 0))
@@ -0,0 +1,48 @@
=== tests/cases/compiler/a.ts ===
import { Member } from './b';
>Member : typeof Member
import d, { Member as M } from './b';
>d : typeof Member
>Member : typeof Member
>M : typeof Member
import * as ns from './b';
>ns : typeof ns
import r = require("./b");
>r : typeof ns
new Member();
>new Member() : Member
>Member : typeof Member
new d();
>new d() : Member
>d : typeof Member
new M();
>new M() : Member
>M : typeof Member
new ns.Member();
>new ns.Member() : Member
>ns.Member : typeof Member
>ns : typeof ns
>Member : typeof Member
new r.Member();
>new r.Member() : Member
>r.Member : typeof Member
>r : typeof ns
>Member : typeof Member
=== tests/cases/compiler/b.ts ===
export class Member {}
>Member : Member
export default Member;
>Member : Member
@@ -0,0 +1,29 @@
tests/cases/compiler/a.ts(1,10): error TS6133: 'Member' is declared but never used.
tests/cases/compiler/a.ts(2,8): error TS6133: 'd' is declared but never used.
tests/cases/compiler/a.ts(2,23): error TS6133: 'M' is declared but never used.
tests/cases/compiler/a.ts(3,13): error TS6133: 'ns' is declared but never used.
tests/cases/compiler/a.ts(4,8): error TS6133: 'r' is declared but never used.
==== tests/cases/compiler/a.ts (5 errors) ====
import { Member } from './b';
~~~~~~
!!! error TS6133: 'Member' is declared but never used.
import d, { Member as M } from './b';
~
!!! error TS6133: 'd' is declared but never used.
~
!!! error TS6133: 'M' is declared but never used.
import * as ns from './b';
~~
!!! error TS6133: 'ns' is declared but never used.
import r = require("./b");
~
!!! error TS6133: 'r' is declared but never used.
==== tests/cases/compiler/b.ts (0 errors) ====
export class Member {}
export default Member;
@@ -0,0 +1,27 @@
//// [tests/cases/compiler/unusedImports12.ts] ////
//// [b.ts]
export class Member {}
export default Member;
//// [a.ts]
import { Member } from './b';
import d, { Member as M } from './b';
import * as ns from './b';
import r = require("./b");
//// [b.js]
"use strict";
var Member = (function () {
function Member() {
}
return Member;
}());
exports.Member = Member;
exports.__esModule = true;
exports["default"] = Member;
//// [a.js]
"use strict";
@@ -0,0 +1,159 @@
tests/cases/compiler/unusedLocalsAndParameters.ts(5,12): error TS6133: 'a' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(10,22): error TS6133: 'a' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(16,5): error TS6133: 'farrow' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(16,15): error TS6133: 'a' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(19,7): error TS6133: 'C' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(21,12): error TS6133: 'a' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(24,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/unusedLocalsAndParameters.ts(24,11): error TS6133: 'v' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(28,5): error TS6133: 'E' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(30,12): error TS6133: 'a' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(33,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/unusedLocalsAndParameters.ts(33,11): error TS6133: 'v' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(39,12): error TS6133: 'a' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(42,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/unusedLocalsAndParameters.ts(42,11): error TS6133: 'v' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(49,10): error TS6133: 'i' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(53,10): error TS6133: 'i' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(57,17): error TS6133: 'n' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(64,11): error TS6133: 'c' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(69,11): error TS6133: 'a' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(72,11): error TS6133: 'c' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(75,11): error TS6133: 'c' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(80,11): error TS6133: 'N' is declared but never used.
tests/cases/compiler/unusedLocalsAndParameters.ts(81,9): error TS6133: 'x' is declared but never used.
==== tests/cases/compiler/unusedLocalsAndParameters.ts (24 errors) ====
export { };
// function declaration paramter
function f(a) {
~
!!! error TS6133: 'a' is declared but never used.
}
f(0);
// function expression paramter
var fexp = function (a) {
~
!!! error TS6133: 'a' is declared but never used.
};
fexp(0);
// arrow function paramter
var farrow = (a) => {
~~~~~~
!!! error TS6133: 'farrow' is declared but never used.
~
!!! error TS6133: 'a' is declared but never used.
};
class C {
~
!!! error TS6133: 'C' is declared but never used.
// Method declaration paramter
method(a) {
~
!!! error TS6133: 'a' is declared but never used.
}
// Accessor declaration paramter
set x(v: number) {
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
~
!!! error TS6133: 'v' is declared but never used.
}
}
var E = class {
~
!!! error TS6133: 'E' is declared but never used.
// Method declaration paramter
method(a) {
~
!!! error TS6133: 'a' is declared but never used.
}
// Accessor declaration paramter
set x(v: number) {
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
~
!!! error TS6133: 'v' is declared but never used.
}
}
var o = {
// Object literal method declaration paramter
method(a) {
~
!!! error TS6133: 'a' is declared but never used.
},
// Accessor declaration paramter
set x(v: number) {
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
~
!!! error TS6133: 'v' is declared but never used.
}
};
o;
// in a for..in statment
for (let i in o) {
~
!!! error TS6133: 'i' is declared but never used.
}
// in a for..of statment
for (let i of [1, 2, 3]) {
~
!!! error TS6133: 'i' is declared but never used.
}
// in a for. statment
for (let i = 0, n; i < 10; i++) {
~
!!! error TS6133: 'n' is declared but never used.
}
// in a block
const condition = false;
if (condition) {
const c = 0;
~
!!! error TS6133: 'c' is declared but never used.
}
// in try/catch/finally
try {
const a = 0;
~
!!! error TS6133: 'a' is declared but never used.
}
catch (e) {
const c = 1;
~
!!! error TS6133: 'c' is declared but never used.
}
finally {
const c = 0;
~
!!! error TS6133: 'c' is declared but never used.
}
// in a namespace
namespace N {
~
!!! error TS6133: 'N' is declared but never used.
var x;
~
!!! error TS6133: 'x' is declared but never used.
}
@@ -0,0 +1,168 @@
//// [unusedLocalsAndParameters.ts]
export { };
// function declaration paramter
function f(a) {
}
f(0);
// function expression paramter
var fexp = function (a) {
};
fexp(0);
// arrow function paramter
var farrow = (a) => {
};
class C {
// Method declaration paramter
method(a) {
}
// Accessor declaration paramter
set x(v: number) {
}
}
var E = class {
// Method declaration paramter
method(a) {
}
// Accessor declaration paramter
set x(v: number) {
}
}
var o = {
// Object literal method declaration paramter
method(a) {
},
// Accessor declaration paramter
set x(v: number) {
}
};
o;
// in a for..in statment
for (let i in o) {
}
// in a for..of statment
for (let i of [1, 2, 3]) {
}
// in a for. statment
for (let i = 0, n; i < 10; i++) {
}
// in a block
const condition = false;
if (condition) {
const c = 0;
}
// in try/catch/finally
try {
const a = 0;
}
catch (e) {
const c = 1;
}
finally {
const c = 0;
}
// in a namespace
namespace N {
var x;
}
//// [unusedLocalsAndParameters.js]
"use strict";
// function declaration paramter
function f(a) {
}
f(0);
// function expression paramter
var fexp = function (a) {
};
fexp(0);
// arrow function paramter
var farrow = function (a) {
};
var C = (function () {
function C() {
}
// Method declaration paramter
C.prototype.method = function (a) {
};
Object.defineProperty(C.prototype, "x", {
// Accessor declaration paramter
set: function (v) {
},
enumerable: true,
configurable: true
});
return C;
}());
var E = (function () {
function class_1() {
}
// Method declaration paramter
class_1.prototype.method = function (a) {
};
Object.defineProperty(class_1.prototype, "x", {
// Accessor declaration paramter
set: function (v) {
},
enumerable: true,
configurable: true
});
return class_1;
}());
var o = {
// Object literal method declaration paramter
method: function (a) {
},
// Accessor declaration paramter
set x(v) {
}
};
o;
// in a for..in statment
for (var i in o) {
}
// in a for..of statment
for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) {
var i = _a[_i];
}
// in a for. statment
for (var i = 0, n = void 0; i < 10; i++) {
}
// in a block
var condition = false;
if (condition) {
var c = 0;
}
// in try/catch/finally
try {
var a = 0;
}
catch (e) {
var c = 1;
}
finally {
var c = 0;
}
// in a namespace
var N;
(function (N) {
var x;
})(N || (N = {}));
@@ -0,0 +1,172 @@
tests/cases/compiler/unusedLocalsAndParametersDeferred.ts(42,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/unusedLocalsAndParametersDeferred.ts(65,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/unusedLocalsAndParametersDeferred.ts(87,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
==== tests/cases/compiler/unusedLocalsAndParametersDeferred.ts (3 errors) ====
export { };
function defered<T>(a: () => T): T {
return a();
}
// function declaration paramter
function f(a) {
defered(() => {
a;
});
}
f(0);
// function expression paramter
var fexp = function (a) {
defered(() => {
a;
});
};
fexp(1);
// arrow function paramter
var farrow = (a) => {
defered(() => {
a;
});
};
farrow(2);
let prop1;
class C {
// Method declaration paramter
method(a) {
defered(() => {
a;
});
}
// Accessor declaration paramter
set x(v: number) {
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
defered(() => {
v;
});
}
// in a property initalizer
p = defered(() => {
prop1;
});
}
new C();
let prop2;
var E = class {
// Method declaration paramter
method(a) {
defered(() => {
a;
});
}
// Accessor declaration paramter
set x(v: number) {
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
defered(() => {
v;
});
}
// in a property initalizer
p = defered(() => {
prop2;
});
}
new E();
var o = {
// Object literal method declaration paramter
method(a) {
defered(() => {
a;
});
},
// Accessor declaration paramter
set x(v: number) {
~
!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
defered(() => {
v;
});
},
// in a property initalizer
p: defered(() => {
prop1;
})
};
o;
// in a for..in statment
for (let i in o) {
defered(() => {
i;
});
}
// in a for..of statment
for (let i of [1,2,3]) {
defered(() => {
i;
});
}
// in a for. statment
for (let i = 0; i < 10; i++) {
defered(() => {
i;
});
}
// in a block
const condition = false;
if (condition) {
const c = 0;
defered(() => {
c;
});
}
// in try/catch/finally
try {
const a = 0;
defered(() => {
a;
});
}
catch (e) {
const c = 1;
defered(() => {
c;
});
}
finally {
const c = 0;
defered(() => {
c;
});
}
// in a namespace
namespace N {
var x;
defered(() => {
x;
});
}
N;
@@ -0,0 +1,325 @@
//// [unusedLocalsAndParametersDeferred.ts]
export { };
function defered<T>(a: () => T): T {
return a();
}
// function declaration paramter
function f(a) {
defered(() => {
a;
});
}
f(0);
// function expression paramter
var fexp = function (a) {
defered(() => {
a;
});
};
fexp(1);
// arrow function paramter
var farrow = (a) => {
defered(() => {
a;
});
};
farrow(2);
let prop1;
class C {
// Method declaration paramter
method(a) {
defered(() => {
a;
});
}
// Accessor declaration paramter
set x(v: number) {
defered(() => {
v;
});
}
// in a property initalizer
p = defered(() => {
prop1;
});
}
new C();
let prop2;
var E = class {
// Method declaration paramter
method(a) {
defered(() => {
a;
});
}
// Accessor declaration paramter
set x(v: number) {
defered(() => {
v;
});
}
// in a property initalizer
p = defered(() => {
prop2;
});
}
new E();
var o = {
// Object literal method declaration paramter
method(a) {
defered(() => {
a;
});
},
// Accessor declaration paramter
set x(v: number) {
defered(() => {
v;
});
},
// in a property initalizer
p: defered(() => {
prop1;
})
};
o;
// in a for..in statment
for (let i in o) {
defered(() => {
i;
});
}
// in a for..of statment
for (let i of [1,2,3]) {
defered(() => {
i;
});
}
// in a for. statment
for (let i = 0; i < 10; i++) {
defered(() => {
i;
});
}
// in a block
const condition = false;
if (condition) {
const c = 0;
defered(() => {
c;
});
}
// in try/catch/finally
try {
const a = 0;
defered(() => {
a;
});
}
catch (e) {
const c = 1;
defered(() => {
c;
});
}
finally {
const c = 0;
defered(() => {
c;
});
}
// in a namespace
namespace N {
var x;
defered(() => {
x;
});
}
N;
//// [unusedLocalsAndParametersDeferred.js]
"use strict";
function defered(a) {
return a();
}
// function declaration paramter
function f(a) {
defered(function () {
a;
});
}
f(0);
// function expression paramter
var fexp = function (a) {
defered(function () {
a;
});
};
fexp(1);
// arrow function paramter
var farrow = function (a) {
defered(function () {
a;
});
};
farrow(2);
var prop1;
var C = (function () {
function C() {
// in a property initalizer
this.p = defered(function () {
prop1;
});
}
// Method declaration paramter
C.prototype.method = function (a) {
defered(function () {
a;
});
};
Object.defineProperty(C.prototype, "x", {
// Accessor declaration paramter
set: function (v) {
defered(function () {
v;
});
},
enumerable: true,
configurable: true
});
return C;
}());
new C();
var prop2;
var E = (function () {
function class_1() {
// in a property initalizer
this.p = defered(function () {
prop2;
});
}
// Method declaration paramter
class_1.prototype.method = function (a) {
defered(function () {
a;
});
};
Object.defineProperty(class_1.prototype, "x", {
// Accessor declaration paramter
set: function (v) {
defered(function () {
v;
});
},
enumerable: true,
configurable: true
});
return class_1;
}());
new E();
var o = {
// Object literal method declaration paramter
method: function (a) {
defered(function () {
a;
});
},
// Accessor declaration paramter
set x(v) {
defered(function () {
v;
});
},
// in a property initalizer
p: defered(function () {
prop1;
})
};
o;
// in a for..in statment
var _loop_1 = function(i) {
defered(function () {
i;
});
};
for (var i in o) {
_loop_1(i);
}
// in a for..of statment
var _loop_2 = function(i) {
defered(function () {
i;
});
};
for (var _i = 0, _a = [1, 2, 3]; _i < _a.length; _i++) {
var i = _a[_i];
_loop_2(i);
}
// in a for. statment
var _loop_3 = function(i) {
defered(function () {
i;
});
};
for (var i = 0; i < 10; i++) {
_loop_3(i);
}
// in a block
var condition = false;
if (condition) {
var c_1 = 0;
defered(function () {
c_1;
});
}
// in try/catch/finally
try {
var a_1 = 0;
defered(function () {
a_1;
});
}
catch (e) {
var c_2 = 1;
defered(function () {
c_2;
});
}
finally {
var c_3 = 0;
defered(function () {
c_3;
});
}
// in a namespace
var N;
(function (N) {
var x;
defered(function () {
x;
});
})(N || (N = {}));
N;
@@ -0,0 +1,45 @@
//// [unusedLocalsAndParametersOverloadSignatures.ts]
export function func(details: number, message: string, ...args: any[]): void;
export function func(details: number, message: string): any {
return details + message;
}
export class C {
constructor(details: number, message: string, ...args: any[]);
constructor(details: number, message: string) {
details + message;
}
method(details: number, message: string, ...args: any[]): void;
method(details: number, message: string): any {
return details + message;
}
}
export function genericFunc<T>(details: number, message: T, ...args: any[]): void;
export function genericFunc(details: number, message: any): any {
return details + message;
}
//// [unusedLocalsAndParametersOverloadSignatures.js]
"use strict";
function func(details, message) {
return details + message;
}
exports.func = func;
var C = (function () {
function C(details, message) {
details + message;
}
C.prototype.method = function (details, message) {
return details + message;
};
return C;
}());
exports.C = C;
function genericFunc(details, message) {
return details + message;
}
exports.genericFunc = genericFunc;
@@ -0,0 +1,70 @@
=== tests/cases/compiler/unusedLocalsAndParametersOverloadSignatures.ts ===
export function func(details: number, message: string, ...args: any[]): void;
>func : Symbol(func, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 0, 0), Decl(unusedLocalsAndParametersOverloadSignatures.ts, 1, 77))
>details : Symbol(details, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 1, 21))
>message : Symbol(message, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 1, 37))
>args : Symbol(args, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 1, 54))
export function func(details: number, message: string): any {
>func : Symbol(func, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 0, 0), Decl(unusedLocalsAndParametersOverloadSignatures.ts, 1, 77))
>details : Symbol(details, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 2, 21))
>message : Symbol(message, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 2, 37))
return details + message;
>details : Symbol(details, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 2, 21))
>message : Symbol(message, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 2, 37))
}
export class C {
>C : Symbol(C, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 4, 1))
constructor(details: number, message: string, ...args: any[]);
>details : Symbol(details, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 7, 16))
>message : Symbol(message, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 7, 32))
>args : Symbol(args, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 7, 49))
constructor(details: number, message: string) {
>details : Symbol(details, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 8, 16))
>message : Symbol(message, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 8, 32))
details + message;
>details : Symbol(details, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 8, 16))
>message : Symbol(message, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 8, 32))
}
method(details: number, message: string, ...args: any[]): void;
>method : Symbol(C.method, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 10, 5), Decl(unusedLocalsAndParametersOverloadSignatures.ts, 12, 67))
>details : Symbol(details, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 12, 11))
>message : Symbol(message, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 12, 27))
>args : Symbol(args, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 12, 44))
method(details: number, message: string): any {
>method : Symbol(C.method, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 10, 5), Decl(unusedLocalsAndParametersOverloadSignatures.ts, 12, 67))
>details : Symbol(details, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 13, 11))
>message : Symbol(message, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 13, 27))
return details + message;
>details : Symbol(details, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 13, 11))
>message : Symbol(message, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 13, 27))
}
}
export function genericFunc<T>(details: number, message: T, ...args: any[]): void;
>genericFunc : Symbol(genericFunc, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 16, 1), Decl(unusedLocalsAndParametersOverloadSignatures.ts, 19, 82))
>T : Symbol(T, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 19, 28))
>details : Symbol(details, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 19, 31))
>message : Symbol(message, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 19, 47))
>T : Symbol(T, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 19, 28))
>args : Symbol(args, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 19, 59))
export function genericFunc(details: number, message: any): any {
>genericFunc : Symbol(genericFunc, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 16, 1), Decl(unusedLocalsAndParametersOverloadSignatures.ts, 19, 82))
>details : Symbol(details, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 20, 28))
>message : Symbol(message, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 20, 44))
return details + message;
>details : Symbol(details, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 20, 28))
>message : Symbol(message, Decl(unusedLocalsAndParametersOverloadSignatures.ts, 20, 44))
}
@@ -0,0 +1,74 @@
=== tests/cases/compiler/unusedLocalsAndParametersOverloadSignatures.ts ===
export function func(details: number, message: string, ...args: any[]): void;
>func : (details: number, message: string, ...args: any[]) => void
>details : number
>message : string
>args : any[]
export function func(details: number, message: string): any {
>func : (details: number, message: string, ...args: any[]) => void
>details : number
>message : string
return details + message;
>details + message : string
>details : number
>message : string
}
export class C {
>C : C
constructor(details: number, message: string, ...args: any[]);
>details : number
>message : string
>args : any[]
constructor(details: number, message: string) {
>details : number
>message : string
details + message;
>details + message : string
>details : number
>message : string
}
method(details: number, message: string, ...args: any[]): void;
>method : (details: number, message: string, ...args: any[]) => void
>details : number
>message : string
>args : any[]
method(details: number, message: string): any {
>method : (details: number, message: string, ...args: any[]) => void
>details : number
>message : string
return details + message;
>details + message : string
>details : number
>message : string
}
}
export function genericFunc<T>(details: number, message: T, ...args: any[]): void;
>genericFunc : <T>(details: number, message: T, ...args: any[]) => void
>T : T
>details : number
>message : T
>T : T
>args : any[]
export function genericFunc(details: number, message: any): any {
>genericFunc : <T>(details: number, message: T, ...args: any[]) => void
>details : number
>message : any
return details + message;
>details + message : any
>details : number
>message : any
}
@@ -0,0 +1,35 @@
//// [unusedLocalsAndParametersTypeAliases.ts]
// used in a declaration
type handler1 = () => void;
export interface I1 {
getHandler: handler1;
}
// exported
export type handler2 = () => void;
// used in extends clause
type handler3 = () => void;
export interface I3<T extends handler3> {
getHandler: T;
}
// used in another type alias declaration
type handler4 = () => void;
type handler5 = handler4 | (()=>number);
var x: handler5;
x();
// used as type argument
type handler6 = () => void;
var y: Array<handler6>;
y[0]();
//// [unusedLocalsAndParametersTypeAliases.js]
"use strict";
var x;
x();
var y;
y[0]();
@@ -0,0 +1,59 @@
=== tests/cases/compiler/unusedLocalsAndParametersTypeAliases.ts ===
// used in a declaration
type handler1 = () => void;
>handler1 : Symbol(handler1, Decl(unusedLocalsAndParametersTypeAliases.ts, 0, 0))
export interface I1 {
>I1 : Symbol(I1, Decl(unusedLocalsAndParametersTypeAliases.ts, 2, 27))
getHandler: handler1;
>getHandler : Symbol(I1.getHandler, Decl(unusedLocalsAndParametersTypeAliases.ts, 3, 21))
>handler1 : Symbol(handler1, Decl(unusedLocalsAndParametersTypeAliases.ts, 0, 0))
}
// exported
export type handler2 = () => void;
>handler2 : Symbol(handler2, Decl(unusedLocalsAndParametersTypeAliases.ts, 5, 1))
// used in extends clause
type handler3 = () => void;
>handler3 : Symbol(handler3, Decl(unusedLocalsAndParametersTypeAliases.ts, 8, 34))
export interface I3<T extends handler3> {
>I3 : Symbol(I3, Decl(unusedLocalsAndParametersTypeAliases.ts, 11, 27))
>T : Symbol(T, Decl(unusedLocalsAndParametersTypeAliases.ts, 12, 20))
>handler3 : Symbol(handler3, Decl(unusedLocalsAndParametersTypeAliases.ts, 8, 34))
getHandler: T;
>getHandler : Symbol(I3.getHandler, Decl(unusedLocalsAndParametersTypeAliases.ts, 12, 41))
>T : Symbol(T, Decl(unusedLocalsAndParametersTypeAliases.ts, 12, 20))
}
// used in another type alias declaration
type handler4 = () => void;
>handler4 : Symbol(handler4, Decl(unusedLocalsAndParametersTypeAliases.ts, 14, 1))
type handler5 = handler4 | (()=>number);
>handler5 : Symbol(handler5, Decl(unusedLocalsAndParametersTypeAliases.ts, 17, 27))
>handler4 : Symbol(handler4, Decl(unusedLocalsAndParametersTypeAliases.ts, 14, 1))
var x: handler5;
>x : Symbol(x, Decl(unusedLocalsAndParametersTypeAliases.ts, 19, 3))
>handler5 : Symbol(handler5, Decl(unusedLocalsAndParametersTypeAliases.ts, 17, 27))
x();
>x : Symbol(x, Decl(unusedLocalsAndParametersTypeAliases.ts, 19, 3))
// used as type argument
type handler6 = () => void;
>handler6 : Symbol(handler6, Decl(unusedLocalsAndParametersTypeAliases.ts, 20, 4))
var y: Array<handler6>;
>y : Symbol(y, Decl(unusedLocalsAndParametersTypeAliases.ts, 24, 3))
>Array : Symbol(Array, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --))
>handler6 : Symbol(handler6, Decl(unusedLocalsAndParametersTypeAliases.ts, 20, 4))
y[0]();
>y : Symbol(y, Decl(unusedLocalsAndParametersTypeAliases.ts, 24, 3))
@@ -0,0 +1,63 @@
=== tests/cases/compiler/unusedLocalsAndParametersTypeAliases.ts ===
// used in a declaration
type handler1 = () => void;
>handler1 : () => void
export interface I1 {
>I1 : I1
getHandler: handler1;
>getHandler : () => void
>handler1 : () => void
}
// exported
export type handler2 = () => void;
>handler2 : () => void
// used in extends clause
type handler3 = () => void;
>handler3 : () => void
export interface I3<T extends handler3> {
>I3 : I3<T>
>T : T
>handler3 : () => void
getHandler: T;
>getHandler : T
>T : T
}
// used in another type alias declaration
type handler4 = () => void;
>handler4 : () => void
type handler5 = handler4 | (()=>number);
>handler5 : (() => void) | (() => number)
>handler4 : () => void
var x: handler5;
>x : (() => void) | (() => number)
>handler5 : (() => void) | (() => number)
x();
>x() : void | number
>x : (() => void) | (() => number)
// used as type argument
type handler6 = () => void;
>handler6 : () => void
var y: Array<handler6>;
>y : (() => void)[]
>Array : T[]
>handler6 : () => void
y[0]();
>y[0]() : void
>y[0] : () => void
>y : (() => void)[]
>0 : number
@@ -0,0 +1,20 @@
tests/cases/compiler/unusedLocalsAndParametersTypeAliases2.ts(3,6): error TS6133: 'handler1' is declared but never used.
tests/cases/compiler/unusedLocalsAndParametersTypeAliases2.ts(7,10): error TS6133: 'handler2' is declared but never used.
==== tests/cases/compiler/unusedLocalsAndParametersTypeAliases2.ts (2 errors) ====
// unused
type handler1 = () => void;
~~~~~~~~
!!! error TS6133: 'handler1' is declared but never used.
function foo() {
type handler2 = () => void;
~~~~~~~~
!!! error TS6133: 'handler2' is declared but never used.
foo();
}
export {}
@@ -0,0 +1,18 @@
//// [unusedLocalsAndParametersTypeAliases2.ts]
// unused
type handler1 = () => void;
function foo() {
type handler2 = () => void;
foo();
}
export {}
//// [unusedLocalsAndParametersTypeAliases2.js]
"use strict";
function foo() {
foo();
}
@@ -1,10 +0,0 @@
tests/cases/compiler/unusedParameterInCatchClause.ts(3,18): error TS6133: 'ex' is declared but never used.
==== tests/cases/compiler/unusedParameterInCatchClause.ts (1 errors) ====
function f1() {
try {} catch(ex){}
~~
!!! error TS6133: 'ex' is declared but never used.
}
@@ -0,0 +1,8 @@
=== tests/cases/compiler/unusedParameterInCatchClause.ts ===
function f1() {
>f1 : Symbol(f1, Decl(unusedParameterInCatchClause.ts, 0, 0))
try {} catch(ex){}
>ex : Symbol(ex, Decl(unusedParameterInCatchClause.ts, 2, 17))
}
@@ -0,0 +1,8 @@
=== tests/cases/compiler/unusedParameterInCatchClause.ts ===
function f1() {
>f1 : () => void
try {} catch(ex){}
>ex : any
}
@@ -0,0 +1,114 @@
//// [unusedPrivateMembers.ts]
class Test1 {
private initializeInternal() {
}
public test() {
var x = new Test1();
x.initializeInternal();
}
}
class Test2 {
private p = 0;
public test() {
var x = new Test2();
x.p;
}
}
class Test3 {
private get x () {
return 0;
}
public test() {
var x = new Test3();
x.x;
}
}
class Test4 {
private set x(v) {
v;
}
public test() {
var x = new Test4();
x.x;
}
}
class Test5<T> {
private p: T;
public test() {
var x = new Test5<number>();
x.p;
}
}
//// [unusedPrivateMembers.js]
var Test1 = (function () {
function Test1() {
}
Test1.prototype.initializeInternal = function () {
};
Test1.prototype.test = function () {
var x = new Test1();
x.initializeInternal();
};
return Test1;
}());
var Test2 = (function () {
function Test2() {
this.p = 0;
}
Test2.prototype.test = function () {
var x = new Test2();
x.p;
};
return Test2;
}());
var Test3 = (function () {
function Test3() {
}
Object.defineProperty(Test3.prototype, "x", {
get: function () {
return 0;
},
enumerable: true,
configurable: true
});
Test3.prototype.test = function () {
var x = new Test3();
x.x;
};
return Test3;
}());
var Test4 = (function () {
function Test4() {
}
Object.defineProperty(Test4.prototype, "x", {
set: function (v) {
v;
},
enumerable: true,
configurable: true
});
Test4.prototype.test = function () {
var x = new Test4();
x.x;
};
return Test4;
}());
var Test5 = (function () {
function Test5() {
}
Test5.prototype.test = function () {
var x = new Test5();
x.p;
};
return Test5;
}());
@@ -0,0 +1,113 @@
=== tests/cases/compiler/unusedPrivateMembers.ts ===
class Test1 {
>Test1 : Symbol(Test1, Decl(unusedPrivateMembers.ts, 0, 0))
private initializeInternal() {
>initializeInternal : Symbol(Test1.initializeInternal, Decl(unusedPrivateMembers.ts, 1, 13))
}
public test() {
>test : Symbol(Test1.test, Decl(unusedPrivateMembers.ts, 3, 5))
var x = new Test1();
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 6, 11))
>Test1 : Symbol(Test1, Decl(unusedPrivateMembers.ts, 0, 0))
x.initializeInternal();
>x.initializeInternal : Symbol(Test1.initializeInternal, Decl(unusedPrivateMembers.ts, 1, 13))
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 6, 11))
>initializeInternal : Symbol(Test1.initializeInternal, Decl(unusedPrivateMembers.ts, 1, 13))
}
}
class Test2 {
>Test2 : Symbol(Test2, Decl(unusedPrivateMembers.ts, 9, 1))
private p = 0;
>p : Symbol(Test2.p, Decl(unusedPrivateMembers.ts, 11, 13))
public test() {
>test : Symbol(Test2.test, Decl(unusedPrivateMembers.ts, 12, 18))
var x = new Test2();
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 14, 11))
>Test2 : Symbol(Test2, Decl(unusedPrivateMembers.ts, 9, 1))
x.p;
>x.p : Symbol(Test2.p, Decl(unusedPrivateMembers.ts, 11, 13))
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 14, 11))
>p : Symbol(Test2.p, Decl(unusedPrivateMembers.ts, 11, 13))
}
}
class Test3 {
>Test3 : Symbol(Test3, Decl(unusedPrivateMembers.ts, 17, 1))
private get x () {
>x : Symbol(Test3.x, Decl(unusedPrivateMembers.ts, 19, 13))
return 0;
}
public test() {
>test : Symbol(Test3.test, Decl(unusedPrivateMembers.ts, 22, 5))
var x = new Test3();
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 25, 11))
>Test3 : Symbol(Test3, Decl(unusedPrivateMembers.ts, 17, 1))
x.x;
>x.x : Symbol(Test3.x, Decl(unusedPrivateMembers.ts, 19, 13))
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 25, 11))
>x : Symbol(Test3.x, Decl(unusedPrivateMembers.ts, 19, 13))
}
}
class Test4 {
>Test4 : Symbol(Test4, Decl(unusedPrivateMembers.ts, 28, 1))
private set x(v) {
>x : Symbol(Test4.x, Decl(unusedPrivateMembers.ts, 30, 13))
>v : Symbol(v, Decl(unusedPrivateMembers.ts, 31, 18))
v;
>v : Symbol(v, Decl(unusedPrivateMembers.ts, 31, 18))
}
public test() {
>test : Symbol(Test4.test, Decl(unusedPrivateMembers.ts, 33, 5))
var x = new Test4();
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 36, 11))
>Test4 : Symbol(Test4, Decl(unusedPrivateMembers.ts, 28, 1))
x.x;
>x.x : Symbol(Test4.x, Decl(unusedPrivateMembers.ts, 30, 13))
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 36, 11))
>x : Symbol(Test4.x, Decl(unusedPrivateMembers.ts, 30, 13))
}
}
class Test5<T> {
>Test5 : Symbol(Test5, Decl(unusedPrivateMembers.ts, 39, 1))
>T : Symbol(T, Decl(unusedPrivateMembers.ts, 41, 12))
private p: T;
>p : Symbol(Test5.p, Decl(unusedPrivateMembers.ts, 41, 16))
>T : Symbol(T, Decl(unusedPrivateMembers.ts, 41, 12))
public test() {
>test : Symbol(Test5.test, Decl(unusedPrivateMembers.ts, 42, 17))
var x = new Test5<number>();
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 44, 11))
>Test5 : Symbol(Test5, Decl(unusedPrivateMembers.ts, 39, 1))
x.p;
>x.p : Symbol(Test5.p, Decl(unusedPrivateMembers.ts, 41, 16))
>x : Symbol(x, Decl(unusedPrivateMembers.ts, 44, 11))
>p : Symbol(Test5.p, Decl(unusedPrivateMembers.ts, 41, 16))
}
}
@@ -0,0 +1,121 @@
=== tests/cases/compiler/unusedPrivateMembers.ts ===
class Test1 {
>Test1 : Test1
private initializeInternal() {
>initializeInternal : () => void
}
public test() {
>test : () => void
var x = new Test1();
>x : Test1
>new Test1() : Test1
>Test1 : typeof Test1
x.initializeInternal();
>x.initializeInternal() : void
>x.initializeInternal : () => void
>x : Test1
>initializeInternal : () => void
}
}
class Test2 {
>Test2 : Test2
private p = 0;
>p : number
>0 : number
public test() {
>test : () => void
var x = new Test2();
>x : Test2
>new Test2() : Test2
>Test2 : typeof Test2
x.p;
>x.p : number
>x : Test2
>p : number
}
}
class Test3 {
>Test3 : Test3
private get x () {
>x : number
return 0;
>0 : number
}
public test() {
>test : () => void
var x = new Test3();
>x : Test3
>new Test3() : Test3
>Test3 : typeof Test3
x.x;
>x.x : number
>x : Test3
>x : number
}
}
class Test4 {
>Test4 : Test4
private set x(v) {
>x : any
>v : any
v;
>v : any
}
public test() {
>test : () => void
var x = new Test4();
>x : Test4
>new Test4() : Test4
>Test4 : typeof Test4
x.x;
>x.x : any
>x : Test4
>x : any
}
}
class Test5<T> {
>Test5 : Test5<T>
>T : T
private p: T;
>p : T
>T : T
public test() {
>test : () => void
var x = new Test5<number>();
>x : Test5<number>
>new Test5<number>() : Test5<number>
>Test5 : typeof Test5
x.p;
>x.p : number
>x : Test5<number>
>p : number
}
}
@@ -0,0 +1,31 @@
tests/cases/compiler/unusedSwitchStatment.ts(4,13): error TS6133: 'x' is declared but never used.
tests/cases/compiler/unusedSwitchStatment.ts(7,15): error TS6133: 'c' is declared but never used.
tests/cases/compiler/unusedSwitchStatment.ts(10,13): error TS6133: 'z' is declared but never used.
==== tests/cases/compiler/unusedSwitchStatment.ts (3 errors) ====
switch (1) {
case 0:
let x;
~
!!! error TS6133: 'x' is declared but never used.
break;
case 1:
const c = 1;
~
!!! error TS6133: 'c' is declared but never used.
break;
default:
let z = 2;
~
!!! error TS6133: 'z' is declared but never used.
}
switch (2) {
case 0:
let x;
case 1:
x++;
}
@@ -0,0 +1,38 @@
//// [unusedSwitchStatment.ts]
switch (1) {
case 0:
let x;
break;
case 1:
const c = 1;
break;
default:
let z = 2;
}
switch (2) {
case 0:
let x;
case 1:
x++;
}
//// [unusedSwitchStatment.js]
switch (1) {
case 0:
var x = void 0;
break;
case 1:
var c = 1;
break;
default:
var z = 2;
}
switch (2) {
case 0:
var x = void 0;
case 1:
x++;
}
@@ -0,0 +1,5 @@
// @noImplicitReturns: true
async () => {
if (window)
return;
}
@@ -0,0 +1,4 @@
// @strictNullChecks: true
const a: { x?: number } = { };
let x = 0;
({x = 1} = a);
@@ -0,0 +1,3 @@
// @target: es6
export default async function foo(): Promise<void> {}
foo();
+19
View File
@@ -0,0 +1,19 @@
//@noUnusedLocals:true
//@noUnusedParameters:true
// @filename: b.ts
export class Member {}
export default Member;
// @filename: a.ts
import { Member } from './b';
import d, { Member as M } from './b';
import * as ns from './b';
import r = require("./b");
new Member();
new d();
new M();
new ns.Member();
new r.Member();
+13
View File
@@ -0,0 +1,13 @@
//@noUnusedLocals:true
//@noUnusedParameters:true
// @filename: b.ts
export class Member {}
export default Member;
// @filename: a.ts
import { Member } from './b';
import d, { Member as M } from './b';
import * as ns from './b';
import r = require("./b");
@@ -0,0 +1,86 @@
//@noUnusedLocals:true
//@noUnusedParameters:true
export { };
// function declaration paramter
function f(a) {
}
f(0);
// function expression paramter
var fexp = function (a) {
};
fexp(0);
// arrow function paramter
var farrow = (a) => {
};
class C {
// Method declaration paramter
method(a) {
}
// Accessor declaration paramter
set x(v: number) {
}
}
var E = class {
// Method declaration paramter
method(a) {
}
// Accessor declaration paramter
set x(v: number) {
}
}
var o = {
// Object literal method declaration paramter
method(a) {
},
// Accessor declaration paramter
set x(v: number) {
}
};
o;
// in a for..in statment
for (let i in o) {
}
// in a for..of statment
for (let i of [1, 2, 3]) {
}
// in a for. statment
for (let i = 0, n; i < 10; i++) {
}
// in a block
const condition = false;
if (condition) {
const c = 0;
}
// in try/catch/finally
try {
const a = 0;
}
catch (e) {
const c = 1;
}
finally {
const c = 0;
}
// in a namespace
namespace N {
var x;
}
@@ -0,0 +1,162 @@
//@noUnusedLocals:true
//@noUnusedParameters:true
export { };
function defered<T>(a: () => T): T {
return a();
}
// function declaration paramter
function f(a) {
defered(() => {
a;
});
}
f(0);
// function expression paramter
var fexp = function (a) {
defered(() => {
a;
});
};
fexp(1);
// arrow function paramter
var farrow = (a) => {
defered(() => {
a;
});
};
farrow(2);
let prop1;
class C {
// Method declaration paramter
method(a) {
defered(() => {
a;
});
}
// Accessor declaration paramter
set x(v: number) {
defered(() => {
v;
});
}
// in a property initalizer
p = defered(() => {
prop1;
});
}
new C();
let prop2;
var E = class {
// Method declaration paramter
method(a) {
defered(() => {
a;
});
}
// Accessor declaration paramter
set x(v: number) {
defered(() => {
v;
});
}
// in a property initalizer
p = defered(() => {
prop2;
});
}
new E();
var o = {
// Object literal method declaration paramter
method(a) {
defered(() => {
a;
});
},
// Accessor declaration paramter
set x(v: number) {
defered(() => {
v;
});
},
// in a property initalizer
p: defered(() => {
prop1;
})
};
o;
// in a for..in statment
for (let i in o) {
defered(() => {
i;
});
}
// in a for..of statment
for (let i of [1,2,3]) {
defered(() => {
i;
});
}
// in a for. statment
for (let i = 0; i < 10; i++) {
defered(() => {
i;
});
}
// in a block
const condition = false;
if (condition) {
const c = 0;
defered(() => {
c;
});
}
// in try/catch/finally
try {
const a = 0;
defered(() => {
a;
});
}
catch (e) {
const c = 1;
defered(() => {
c;
});
}
finally {
const c = 0;
defered(() => {
c;
});
}
// in a namespace
namespace N {
var x;
defered(() => {
x;
});
}
N;
@@ -0,0 +1,25 @@
//@noUnusedLocals:true
//@noUnusedParameters:true
export function func(details: number, message: string, ...args: any[]): void;
export function func(details: number, message: string): any {
return details + message;
}
export class C {
constructor(details: number, message: string, ...args: any[]);
constructor(details: number, message: string) {
details + message;
}
method(details: number, message: string, ...args: any[]): void;
method(details: number, message: string): any {
return details + message;
}
}
export function genericFunc<T>(details: number, message: T, ...args: any[]): void;
export function genericFunc(details: number, message: any): any {
return details + message;
}
@@ -0,0 +1,29 @@
//@noUnusedLocals:true
//@noUnusedParameters:true
// used in a declaration
type handler1 = () => void;
export interface I1 {
getHandler: handler1;
}
// exported
export type handler2 = () => void;
// used in extends clause
type handler3 = () => void;
export interface I3<T extends handler3> {
getHandler: T;
}
// used in another type alias declaration
type handler4 = () => void;
type handler5 = handler4 | (()=>number);
var x: handler5;
x();
// used as type argument
type handler6 = () => void;
var y: Array<handler6>;
y[0]();
@@ -0,0 +1,13 @@
//@noUnusedLocals:true
//@noUnusedParameters:true
// unused
type handler1 = () => void;
function foo() {
type handler2 = () => void;
foo();
}
export {}
@@ -0,0 +1,51 @@
//@noUnusedLocals:true
//@noUnusedParameters:true
//@target:ES5
class Test1 {
private initializeInternal() {
}
public test() {
var x = new Test1();
x.initializeInternal();
}
}
class Test2 {
private p = 0;
public test() {
var x = new Test2();
x.p;
}
}
class Test3 {
private get x () {
return 0;
}
public test() {
var x = new Test3();
x.x;
}
}
class Test4 {
private set x(v) {
v;
}
public test() {
var x = new Test4();
x.x;
}
}
class Test5<T> {
private p: T;
public test() {
var x = new Test5<number>();
x.p;
}
}
@@ -0,0 +1,21 @@
//@noUnusedLocals:true
//@noUnusedParameters:true
switch (1) {
case 0:
let x;
break;
case 1:
const c = 1;
break;
default:
let z = 2;
}
switch (2) {
case 0:
let x;
case 1:
x++;
}
@@ -0,0 +1,26 @@
/// <reference path='fourslash.ts' />
//// var expect = require('expect.js');
//// import React from 'react'/*1*/;
//// import { mount } from 'enzyme';
//// require('../setup');
//// var Amount = require('../../src/js/components/amount');
//// describe('<Failed />', () => {
//// var history
//// beforeEach(() => {
//// history = createMemoryHistory();
//// sinon.spy(history, 'pushState');
//// });
//// afterEach(() => {
//// })
//// it('redirects to order summary', () => {
//// });
//// });
format.document();
goTo.marker("1");
verify.currentLineContentIs("import React from 'react';")
@@ -0,0 +1,13 @@
////import *{} from 'foo';
verify.navigationBar([
{
"text": "\"navigationBarNamespaceImportWithNoName\"",
"kind": "module",
"childItems": [
{
"text": "<unknown>",
"kind": "alias"
}
]
}
]);
@@ -0,0 +1 @@
export declare var foo: number;
@@ -0,0 +1,5 @@
{
"types": "entry.d.ts",
"name": "m4",
"version": "1.0.0"
}
@@ -0,0 +1 @@
exports.test = "hello, world";
@@ -0,0 +1,5 @@
{
"name": "m4",
"version": "1.0.0",
"main": "entry.js"
}
@@ -1,4 +1,9 @@
import * as m1 from "m1";
import * as m4 from "m4";
m1.f1("test");
m1.f2.a = 10;
m1.f2.person.age = "10"; // Error: Should be number
m1.f2.person.age = "10"; // Should error if loaded the .js files correctly
let r2 = 3 + m4.foo; // Should be OK if correctly using the @types .d.ts file