diff --git a/lib/tsc.js b/lib/tsc.js index 1c6d5b8f47a..0b5e4619e4b 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -2281,6 +2281,9 @@ var ts; Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, File_name_0_has_a_1_extension_stripping_it: { code: 6132, category: ts.DiagnosticCategory.Message, key: "File_name_0_has_a_1_extension_stripping_it_6132", message: "File name '{0}' has a '{1}' extension - stripping it" }, + _0_is_declared_but_never_used: { code: 6133, category: ts.DiagnosticCategory.Error, key: "_0_is_declared_but_never_used_6133", message: "'{0}' is declared but never used." }, + Report_Errors_on_Unused_Locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Locals_6134", message: "Report Errors on Unused Locals." }, + Report_Errors_on_Unused_Parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Parameters_6135", message: "Report Errors on Unused Parameters." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -8736,8 +8739,11 @@ var ts; if (lhs.kind === 69) { return lhs.text === rhs.text; } - return lhs.right.text === rhs.right.text && - tagNamesAreEquivalent(lhs.left, rhs.left); + if (lhs.kind === 97) { + return true; + } + return lhs.name.text === rhs.name.text && + tagNamesAreEquivalent(lhs.expression, rhs.expression); } function parseJsxElementOrSelfClosingElement(inExpressionContext) { var opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext); @@ -8834,15 +8840,15 @@ var ts; } function parseJsxElementName() { scanJsxIdentifier(); - var elementName = parseIdentifierName(); + var expression = token === 97 ? + parseTokenNode() : parseIdentifierName(); while (parseOptional(21)) { - scanJsxIdentifier(); - var node = createNode(139, elementName.pos); - node.left = elementName; - node.right = parseIdentifierName(); - elementName = finishNode(node); + var propertyAccess = createNode(172, expression.pos); + propertyAccess.expression = expression; + propertyAccess.name = parseRightSideOfDot(true); + expression = finishNode(propertyAccess); } - return elementName; + return expression; } function parseJsxExpression(inExpressionContext) { var node = createNode(248); @@ -9620,7 +9626,7 @@ var ts; case 56: return parseExportAssignment(fullStart, decorators, modifiers); case 116: - return parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers); + return parseNamespaceExportDeclaration(fullStart, decorators, modifiers); default: return parseExportDeclaration(fullStart, decorators, modifiers); } @@ -10134,7 +10140,7 @@ var ts; function nextTokenIsSlash() { return nextToken() === 39; } - function parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers) { + function parseNamespaceExportDeclaration(fullStart, decorators, modifiers) { var exportDeclaration = createNode(228, fullStart); exportDeclaration.decorators = decorators; exportDeclaration.modifiers = modifiers; @@ -13805,7 +13811,7 @@ var ts; function getTargetOfImportSpecifier(node) { return getExternalModuleMember(node.parent.parent.parent, node); } - function getTargetOfGlobalModuleExportDeclaration(node) { + function getTargetOfNamespaceExportDeclaration(node) { return resolveExternalModuleSymbol(node.parent.symbol); } function getTargetOfExportSpecifier(node) { @@ -13831,7 +13837,7 @@ var ts; case 235: return getTargetOfExportAssignment(node); case 228: - return getTargetOfGlobalModuleExportDeclaration(node); + return getTargetOfNamespaceExportDeclaration(node); } } function resolveSymbol(symbol) { @@ -13914,9 +13920,12 @@ var ts; var left = name.kind === 139 ? name.left : name.expression; var right = name.kind === 139 ? name.right : name.name; var namespace = resolveEntityName(left, 1536, ignoreErrors); - if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) { + if (!namespace || ts.nodeIsMissing(right)) { return undefined; } + else if (namespace === unknownSymbol) { + return namespace; + } symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { if (!ignoreErrors) { @@ -14877,16 +14886,13 @@ var ts; writePunctuation(writer, 27); } } - function buildDisplayForParametersAndDelimiters(thisType, parameters, writer, enclosingDeclaration, flags, symbolStack) { + function buildDisplayForParametersAndDelimiters(thisParameter, parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 17); - if (thisType) { - writeKeyword(writer, 97); - writePunctuation(writer, 54); - writeSpace(writer); - buildTypeDisplay(thisType, writer, enclosingDeclaration, flags, symbolStack); + if (thisParameter) { + buildParameterDisplay(thisParameter, writer, enclosingDeclaration, flags, symbolStack); } for (var i = 0; i < parameters.length; i++) { - if (i > 0 || thisType) { + if (i > 0 || thisParameter) { writePunctuation(writer, 24); writeSpace(writer); } @@ -14934,7 +14940,7 @@ var ts; else { buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.thisType, signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildDisplayForParametersAndDelimiters(signature.thisParameter, signature.parameters, writer, enclosingDeclaration, flags, symbolStack); buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { @@ -15265,12 +15271,13 @@ var ts; if (func.kind === 150 && !ts.hasDynamicName(func)) { var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 149); if (getter) { - var signature = getSignatureFromDeclaration(getter); + var getterSignature = getSignatureFromDeclaration(getter); var thisParameter = getAccessorThisParameter(func); if (thisParameter && declaration === thisParameter) { - return signature.thisType; + ts.Debug.assert(!thisParameter.type); + return getTypeOfSymbol(getterSignature.thisParameter); } - return getReturnTypeOfSignature(signature); + return getReturnTypeOfSignature(getterSignature); } } var type = declaration.symbol.name === "this" @@ -15428,14 +15435,12 @@ var ts; } return undefined; } - function getAnnotatedAccessorThisType(accessor) { - if (accessor) { - var parameter = getAccessorThisParameter(accessor); - if (parameter && parameter.type) { - return getTypeFromTypeNode(accessor.parameters[0].type); - } - } - return undefined; + function getAnnotatedAccessorThisParameter(accessor) { + var parameter = getAccessorThisParameter(accessor); + return parameter && parameter.symbol; + } + function getThisTypeOfDeclaration(declaration) { + return getThisTypeOfSignature(getSignatureFromDeclaration(declaration)); } function getTypeOfAccessors(symbol) { var links = getSymbolLinks(symbol); @@ -16015,12 +16020,12 @@ var ts; type.typeArguments : ts.concatenate(type.typeArguments, [type]); resolveObjectTypeMembers(type, source, typeParameters, typeArguments); } - function createSignature(declaration, typeParameters, thisType, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { + function createSignature(declaration, typeParameters, thisParameter, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { var sig = new Signature(checker); sig.declaration = declaration; sig.typeParameters = typeParameters; sig.parameters = parameters; - sig.thisType = thisType; + sig.thisParameter = thisParameter; sig.resolvedReturnType = resolvedReturnType; sig.typePredicate = typePredicate; sig.minArgumentCount = minArgumentCount; @@ -16029,7 +16034,7 @@ var ts; return sig; } function cloneSignature(sig) { - return createSignature(sig.declaration, sig.typeParameters, sig.thisType, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); + return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); } function getDefaultConstructSignatures(classType) { var baseConstructorType = getBaseConstructorTypeOfClass(classType); @@ -16113,8 +16118,9 @@ var ts; var s = signature; if (unionSignatures.length > 1) { s = cloneSignature(signature); - if (ts.forEach(unionSignatures, function (sig) { return sig.thisType; })) { - s.thisType = getUnionType(ts.map(unionSignatures, function (sig) { return sig.thisType || anyType; })); + if (ts.forEach(unionSignatures, function (sig) { return sig.thisParameter; })) { + var thisType = getUnionType(ts.map(unionSignatures, function (sig) { return getTypeOfSymbol(sig.thisParameter) || anyType; })); + s.thisParameter = createTransientSymbol(signature.thisParameter, thisType); } s.resolvedReturnType = undefined; s.unionSignatures = unionSignatures; @@ -16299,6 +16305,7 @@ var ts; var types = containingType.types; var props; var commonFlags = (containingType.flags & 32768) ? 536870912 : 0; + var isReadonly = false; for (var _i = 0, types_2 = types; _i < types_2.length; _i++) { var current = types_2[_i]; var type = getApparentType(current); @@ -16312,6 +16319,9 @@ var ts; else if (!ts.contains(props, prop)) { props.push(prop); } + if (isReadonlySymbol(prop)) { + isReadonly = true; + } } else if (containingType.flags & 16384) { return undefined; @@ -16339,6 +16349,7 @@ var ts; commonFlags, name); result.containingType = containingType; result.declarations = declarations; + result.isReadonly = isReadonly; result.type = containingType.flags & 16384 ? getUnionType(propTypes) : getIntersectionType(propTypes); return result; } @@ -16497,7 +16508,7 @@ var ts; var parameters = []; var hasStringLiterals = false; var minArgumentCount = -1; - var thisType = undefined; + var thisParameter = undefined; var hasThisParameter = void 0; var isJSConstructSignature = ts.isJSDocConstructSignature(declaration); for (var i = isJSConstructSignature ? 1 : 0, n = declaration.parameters.length; i < n; i++) { @@ -16509,7 +16520,7 @@ var ts; } if (i === 0 && paramSymbol.name === "this") { hasThisParameter = true; - thisType = param.type ? getTypeFromTypeNode(param.type) : unknownType; + thisParameter = param.symbol; } else { parameters.push(paramSymbol); @@ -16528,10 +16539,12 @@ var ts; } if ((declaration.kind === 149 || declaration.kind === 150) && !ts.hasDynamicName(declaration) && - (!hasThisParameter || thisType === unknownType)) { + (!hasThisParameter || !thisParameter)) { var otherKind = declaration.kind === 149 ? 150 : 149; - var setter = ts.getDeclarationOfKind(declaration.symbol, otherKind); - thisType = getAnnotatedAccessorThisType(setter); + var other = ts.getDeclarationOfKind(declaration.symbol, otherKind); + if (other) { + thisParameter = getAnnotatedAccessorThisParameter(other); + } } if (minArgumentCount < 0) { minArgumentCount = declaration.parameters.length - (hasThisParameter ? 1 : 0); @@ -16549,7 +16562,7 @@ var ts; var typePredicate = declaration.type && declaration.type.kind === 154 ? createTypePredicateFromTypePredicateNode(declaration.type) : undefined; - links.resolvedSignature = createSignature(declaration, typeParameters, thisType, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); + links.resolvedSignature = createSignature(declaration, typeParameters, thisParameter, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); } return links.resolvedSignature; } @@ -16619,6 +16632,11 @@ var ts; } return anyType; } + function getThisTypeOfSignature(signature) { + if (signature.thisParameter) { + return getTypeOfSymbol(signature.thisParameter); + } + } function getReturnTypeOfSignature(signature) { if (!signature.resolvedReturnType) { if (!pushTypeResolution(signature, 3)) { @@ -17336,7 +17354,7 @@ var ts; if (signature.typePredicate) { freshTypePredicate = cloneTypePredicate(signature.typePredicate, mapper); } - var result = createSignature(signature.declaration, freshTypeParameters, signature.thisType && instantiateType(signature.thisType, mapper), instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); + var result = createSignature(signature.declaration, freshTypeParameters, signature.thisParameter && instantiateSymbol(signature.thisParameter, mapper), instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); result.target = signature; result.mapper = mapper; return result; @@ -17539,16 +17557,20 @@ var ts; source = getErasedSignature(source); target = getErasedSignature(target); var result = -1; - if (source.thisType && target.thisType && source.thisType !== voidType) { - var related = compareTypes(source.thisType, target.thisType, false) - || compareTypes(target.thisType, source.thisType, reportErrors); - if (!related) { - if (reportErrors) { - errorReporter(ts.Diagnostics.The_this_types_of_each_signature_are_incompatible); + var sourceThisType = getThisTypeOfSignature(source); + if (sourceThisType && sourceThisType !== voidType) { + var targetThisType = getThisTypeOfSignature(target); + if (targetThisType) { + var related = compareTypes(sourceThisType, targetThisType, false) + || compareTypes(targetThisType, sourceThisType, reportErrors); + if (!related) { + if (reportErrors) { + errorReporter(ts.Diagnostics.The_this_types_of_each_signature_are_incompatible); + } + return 0; } - return 0; + result &= related; } - result &= related; } var sourceMax = getNumNonRestParameters(source); var targetMax = getNumNonRestParameters(target); @@ -18366,12 +18388,18 @@ var ts; source = getErasedSignature(source); target = getErasedSignature(target); var result = -1; - if (!ignoreThisTypes && source.thisType && target.thisType) { - var related = compareTypes(source.thisType, target.thisType); - if (!related) { - return 0; + if (!ignoreThisTypes) { + var sourceThisType = getThisTypeOfSignature(source); + if (sourceThisType) { + var targetThisType = getThisTypeOfSignature(target); + if (targetThisType) { + var related = compareTypes(sourceThisType, targetThisType); + if (!related) { + return 0; + } + result &= related; + } } - result &= related; } var targetLen = target.parameters.length; for (var i = 0; i < targetLen; i++) { @@ -19634,8 +19662,20 @@ var ts; } return container === declarationContainer; } + function updateReferencesForInterfaceHeritiageClauseTargets(node) { + var extendedTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (extendedTypeNode) { + var t = getTypeFromTypeNode(extendedTypeNode); + if (t !== unknownType && t.symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + t.symbol.hasReference = true; + } + } + } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); + if (symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + symbol.hasReference = true; + } if (symbol === argumentsSymbol) { var container = ts.getContainingFunction(node); if (container.kind === 180) { @@ -19845,9 +19885,9 @@ var ts; if (type) { return type; } - var signature = getSignatureFromDeclaration(container); - if (signature.thisType) { - return signature.thisType; + var thisType = getThisTypeOfDeclaration(container); + if (thisType) { + return thisType; } } if (ts.isClassLike(container.parent)) { @@ -19990,7 +20030,7 @@ var ts; if (isContextSensitiveFunctionOrObjectLiteralMethod(func) && func.kind !== 180) { var contextualSignature = getContextualSignature(func); if (contextualSignature) { - return contextualSignature.thisType; + return getThisTypeOfSignature(contextualSignature); } } return undefined; @@ -20572,7 +20612,7 @@ var ts; return name.indexOf("-") < 0; } function isJsxIntrinsicIdentifier(tagName) { - if (tagName.kind === 139) { + if (tagName.kind === 172 || tagName.kind === 97) { return false; } else { @@ -20708,6 +20748,25 @@ var ts; return getResolvedJsxType(node, type, elemClassType); })); } + if (elemType.flags & 2) { + return anyType; + } + else if (elemType.flags & 256) { + var intrinsicElementsType = getJsxType(JsxNames.IntrinsicElements); + if (intrinsicElementsType !== unknownType) { + var stringLiteralTypeName = elemType.text; + var intrinsicProp = getPropertyOfType(intrinsicElementsType, stringLiteralTypeName); + if (intrinsicProp) { + return getTypeOfSymbol(intrinsicProp); + } + var indexSignatureType = getIndexTypeOfType(intrinsicElementsType, 0); + if (indexSignatureType) { + return indexSignatureType; + } + error(node, ts.Diagnostics.Property_0_does_not_exist_on_type_1, stringLiteralTypeName, "JSX." + JsxNames.IntrinsicElements); + } + return anyType; + } var elemInstanceType = getJsxElementInstanceType(node, elemType); if (!elemClassType || !isTypeAssignableTo(elemInstanceType, elemClassType)) { if (jsxElementType) { @@ -20952,6 +21011,9 @@ var ts; } return unknownType; } + if ((compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + prop.hasReference = true; + } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & 32) { checkClassPropertyAccess(node, left, apparentType, prop); @@ -21264,10 +21326,11 @@ var ts; if (context.failedTypeParameterIndex !== undefined && !context.inferences[context.failedTypeParameterIndex].isFixed) { context.failedTypeParameterIndex = undefined; } - if (signature.thisType) { + var thisType = getThisTypeOfSignature(signature); + if (thisType) { var thisArgumentNode = getThisArgumentOfCall(node); var thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType; - inferTypes(context, thisArgumentType, signature.thisType); + inferTypes(context, thisArgumentType, thisType); } var argCount = getEffectiveArgumentCount(node, args, signature); for (var i = 0; i < argCount; i++) { @@ -21318,12 +21381,13 @@ var ts; return typeArgumentsAreAssignable; } function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) { - if (signature.thisType && signature.thisType !== voidType && node.kind !== 175) { + var thisType = getThisTypeOfSignature(signature); + if (thisType && thisType !== voidType && node.kind !== 175) { var thisArgumentNode = getThisArgumentOfCall(node); var thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType; var errorNode = reportErrors ? (thisArgumentNode || node) : undefined; var headMessage_1 = ts.Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1; - if (!checkTypeRelatedTo(thisArgumentType, signature.thisType, relation, errorNode, headMessage_1)) { + if (!checkTypeRelatedTo(thisArgumentType, getThisTypeOfSignature(signature), relation, errorNode, headMessage_1)) { return false; } } @@ -21739,7 +21803,7 @@ var ts; if (getReturnTypeOfSignature(signature) !== voidType) { error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } - if (signature.thisType === voidType) { + if (getThisTypeOfSignature(signature) === voidType) { error(node, ts.Diagnostics.A_function_that_is_called_with_the_new_keyword_cannot_have_a_this_type_that_is_void); } return signature; @@ -22219,6 +22283,8 @@ var ts; } } } + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); } } function checkArithmeticOperandType(operand, type, diagnostic) { @@ -22229,7 +22295,8 @@ var ts; return true; } function isReadonlySymbol(symbol) { - return symbol.flags & 4 && (getDeclarationFlagsFromSymbol(symbol) & 64) !== 0 || + return symbol.isReadonly || + symbol.flags & 4 && (getDeclarationFlagsFromSymbol(symbol) & 64) !== 0 || symbol.flags & 3 && (getDeclarationFlagsFromSymbol(symbol) & 2048) !== 0 || symbol.flags & 98304 && !(symbol.flags & 65536) || (symbol.flags & 8) !== 0; @@ -23064,6 +23131,9 @@ var ts; checkAsyncFunctionReturnType(node); } } + if (!node.body) { + checkUnusedTypeParameters(node); + } } } function checkClassForDuplicateDeclarations(node) { @@ -23191,6 +23261,8 @@ var ts; checkSignatureDeclaration(node); checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node); checkSourceElement(node.body); + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); var symbol = getSymbolOfNode(node); var firstDeclaration = ts.getDeclarationOfKind(symbol, node.kind); if (node === firstDeclaration) { @@ -23294,7 +23366,7 @@ var ts; error(node.name, ts.Diagnostics.Accessors_must_both_be_abstract_or_non_abstract); } checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorType, ts.Diagnostics.get_and_set_accessor_must_have_the_same_type); - checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorThisType, ts.Diagnostics.get_and_set_accessor_must_have_the_same_this_type); + checkAccessorDeclarationTypesIdentical(node, otherAccessor, getThisTypeOfDeclaration, ts.Diagnostics.get_and_set_accessor_must_have_the_same_this_type); } } getTypeOfAccessors(getSymbolOfNode(node)); @@ -23339,12 +23411,17 @@ var ts; function checkTypeReferenceNode(node) { checkGrammarTypeArguments(node, node.typeArguments); var type = getTypeFromTypeReference(node); - if (type !== unknownType && node.typeArguments) { - ts.forEach(node.typeArguments, checkSourceElement); - if (produceDiagnostics) { - var symbol = getNodeLinks(node).resolvedSymbol; - var typeParameters = symbol.flags & 524288 ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; - checkTypeArgumentConstraints(typeParameters, node.typeArguments); + if (type !== unknownType) { + if (type.symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + type.symbol.hasReference = true; + } + if (node.typeArguments) { + ts.forEach(node.typeArguments, checkSourceElement); + if (produceDiagnostics) { + var symbol = getNodeLinks(node).resolvedSymbol; + var typeParameters = symbol.flags & 524288 ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; + checkTypeArgumentConstraints(typeParameters, node.typeArguments); + } } } } @@ -23874,6 +23951,8 @@ var ts; } } checkSourceElement(node.body); + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); if (!node.asteriskToken) { var returnOrPromisedType = node.type && (isAsync ? checkAsyncFunctionReturnType(node) : getTypeFromTypeNode(node.type)); checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnOrPromisedType); @@ -23887,11 +23966,83 @@ var ts; } } } + function checkUnusedIdentifiers(node) { + if (node.parent.kind !== 222 && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + for (var key in node.locals) { + if (ts.hasProperty(node.locals, key)) { + var local = node.locals[key]; + if (!local.hasReference && local.valueDeclaration) { + if (local.valueDeclaration.kind !== 142 && compilerOptions.noUnusedLocals) { + error(local.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local.name); + } + else if (local.valueDeclaration.kind === 142 && compilerOptions.noUnusedParameters) { + if (local.valueDeclaration.flags === 0) { + error(local.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local.name); + } + } + } + } + } + } + } + function checkUnusedClassLocals(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + if (node.members) { + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 147 || member.kind === 145) { + if (isPrivateNode(member) && !member.symbol.hasReference) { + error(member.name, ts.Diagnostics._0_is_declared_but_never_used, member.symbol.name); + } + } + else if (member.kind === 148) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var parameter = _c[_b]; + if (isPrivateNode(parameter) && !parameter.symbol.hasReference) { + error(parameter.name, ts.Diagnostics._0_is_declared_but_never_used, parameter.symbol.name); + } + } + } + } + } + } + } + function checkUnusedTypeParameters(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + if (node.typeParameters) { + for (var _i = 0, _a = node.typeParameters; _i < _a.length; _i++) { + var typeParameter = _a[_i]; + if (!typeParameter.symbol.hasReference) { + error(typeParameter.name, ts.Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name); + } + } + } + } + } + function isPrivateNode(node) { + return (node.flags & 8) !== 0; + } + function checkUnusedModuleLocals(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + var _loop_1 = function(key) { + if (ts.hasProperty(node.locals, key)) { + var local_1 = node.locals[key]; + if (!local_1.hasReference && !local_1.exportSymbol) { + ts.forEach(local_1.declarations, function (d) { return error(d.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); }); + } + } + }; + for (var key in node.locals) { + _loop_1(key); + } + } + } function checkBlock(node) { if (node.kind === 199) { checkGrammarStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); + checkUnusedIdentifiers(node); } function checkCollisionWithArgumentsInGeneratedCode(node) { if (!ts.hasDeclaredRestParameter(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { @@ -24237,6 +24388,7 @@ var ts; } } checkSourceElement(node.statement); + checkUnusedIdentifiers(node); } function checkForInStatement(node) { checkGrammarForInOrForOfStatement(node); @@ -24265,6 +24417,7 @@ var ts; error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); + checkUnusedIdentifiers(node); } function checkForInOrForOfVariableDeclaration(iterationStatement) { var variableDeclarationList = iterationStatement.initializer; @@ -24561,6 +24714,7 @@ var ts; } } checkBlock(catchClause.block); + checkUnusedIdentifiers(catchClause); } if (node.finallyBlock) { checkBlock(node.finallyBlock); @@ -24683,6 +24837,8 @@ var ts; } checkClassLikeDeclaration(node); ts.forEach(node.members, checkSourceElement); + checkUnusedClassLocals(node); + checkUnusedTypeParameters(node); } function checkClassLikeDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); @@ -24923,6 +25079,8 @@ var ts; ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); + updateReferencesForInterfaceHeritiageClauseTargets(node); + checkUnusedTypeParameters(node); } } function checkTypeAliasDeclaration(node) { @@ -25242,6 +25400,7 @@ var ts; } if (node.body) { checkSourceElement(node.body); + checkUnusedModuleLocals(node); } } function checkModuleAugmentationElement(node, isGlobalAugmentation) { @@ -25392,6 +25551,9 @@ var ts; if (target.flags & 793056) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); } + if ((compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + target.hasReference = true; + } } } else { @@ -25679,6 +25841,9 @@ var ts; potentialThisCollisions.length = 0; deferredNodes = []; ts.forEach(node.statements, checkSourceElement); + if (ts.isExternalModule(node)) { + checkUnusedModuleLocals(node); + } checkDeferredNodes(); deferredNodes = undefined; if (ts.isExternalOrCommonJsModule(node)) { @@ -25967,6 +26132,13 @@ var ts; case 139: return getSymbolOfEntityNameOrPropertyAccessExpression(node); case 97: + var container = ts.getThisContainer(node, false); + if (ts.isFunctionLike(container)) { + var sig = getSignatureFromDeclaration(container); + if (sig.thisParameter) { + return sig.thisParameter; + } + } case 95: var type = ts.isExpression(node) ? checkExpression(node) : getTypeFromTypeNode(node); return type.symbol; @@ -26155,7 +26327,9 @@ var ts; var parentSymbol = getParentOfSymbol(symbol); if (parentSymbol) { if (parentSymbol.flags & 512 && parentSymbol.valueDeclaration.kind === 256) { - return parentSymbol.valueDeclaration; + if (parentSymbol.valueDeclaration === ts.getSourceFileOfNode(node)) { + return parentSymbol.valueDeclaration; + } } for (var n = node.parent; n; n = n.parent) { if ((n.kind === 225 || n.kind === 224) && getSymbolOfNode(n) === parentSymbol) { @@ -27048,7 +27222,7 @@ var ts; var GetAccessor = 2; var SetAccessor = 4; var GetOrSetAccessor = GetAccessor | SetAccessor; - var _loop_1 = function(prop) { + var _loop_2 = function(prop) { var name_21 = prop.name; if (prop.kind === 193 || name_21.kind === 140) { @@ -27109,8 +27283,8 @@ var ts; }; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var state_2 = _loop_1(prop); - if (typeof state_2 === "object") return state_2.value; + var state_3 = _loop_2(prop); + if (typeof state_3 === "object") return state_3.value; } } function checkGrammarJsxElement(node) { @@ -29740,6 +29914,8 @@ var ts; return generateNameForExportDefault(); case 192: return generateNameForClassExpression(); + default: + ts.Debug.fail(); } } function getGeneratedNameForNode(node) { @@ -30437,6 +30613,20 @@ var ts; } return false; } + function getClassExpressionInPropertyAccessInStaticPropertyDeclaration(node) { + if (languageVersion >= 2) { + var parent_14 = node.parent; + if (parent_14.kind === 172 && parent_14.expression === node) { + parent_14 = parent_14.parent; + while (parent_14 && parent_14.kind !== 145) { + parent_14 = parent_14.parent; + } + return parent_14 && parent_14.kind === 145 && (parent_14.flags & 32) !== 0 && + parent_14.parent.kind === 192 ? parent_14.parent : undefined; + } + } + return undefined; + } function emitIdentifier(node) { if (convertedLoopState) { if (node.text == "arguments" && resolver.isArgumentsLocalBinding(node)) { @@ -30449,6 +30639,14 @@ var ts; write(node.text); } else if (isExpressionIdentifier(node)) { + var classExpression = getClassExpressionInPropertyAccessInStaticPropertyDeclaration(node); + if (classExpression) { + var declaration = resolver.getReferencedValueDeclaration(node); + if (declaration === classExpression) { + write(getGeneratedNameForNode(declaration.name)); + return; + } + } emitExpressionIdentifier(node); } else if (isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(node)) { @@ -32988,7 +33186,7 @@ var ts; emitStart(property); emitStart(property.name); if (receiver) { - emit(receiver); + write(receiver); } else { if (property.flags & 32) { @@ -33271,12 +33469,15 @@ var ts; } var staticProperties = getInitializedProperties(node, true); var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 192; - var tempVariable; + var generatedName; if (isClassExpressionWithStaticProperties) { - tempVariable = createAndRecordTempVariable(0); + generatedName = getGeneratedNameForNode(node.name); + var synthesizedNode = ts.createSynthesizedNode(69); + synthesizedNode.text = generatedName; + recordTempDeclaration(synthesizedNode); write("("); increaseIndent(); - emit(tempVariable); + emit(synthesizedNode); write(" = "); } write("class"); @@ -33316,11 +33517,11 @@ var ts; var property = staticProperties_1[_a]; write(","); writeLine(); - emitPropertyDeclaration(node, property, tempVariable, true); + emitPropertyDeclaration(node, property, generatedName, true); } write(","); writeLine(); - emit(tempVariable); + write(generatedName); decreaseIndent(); write(")"); } @@ -35498,7 +35699,7 @@ var ts; ts.emitTime = 0; ts.ioReadTime = 0; ts.ioWriteTime = 0; - ts.version = "1.9.0"; + ts.version = "2.0.0"; var emptyArray = []; var defaultTypeRoots = ["node_modules/@types"]; function findConfigFile(searchPath, fileExists) { @@ -37341,6 +37542,16 @@ var ts; type: "boolean", description: ts.Diagnostics.Raise_error_on_this_expressions_with_an_implied_any_type }, + { + name: "noUnusedLocals", + type: "boolean", + description: ts.Diagnostics.Report_Errors_on_Unused_Locals + }, + { + name: "noUnusedParameters", + type: "boolean", + description: ts.Diagnostics.Report_Errors_on_Unused_Parameters + }, { name: "noLib", type: "boolean" @@ -37530,16 +37741,6 @@ var ts; isFilePath: true } }, - { - name: "typesSearchPaths", - type: "list", - isTSConfigOnly: true, - element: { - name: "typesSearchPaths", - type: "string", - isFilePath: true - } - }, { name: "typeRoots", type: "list", @@ -37614,7 +37815,7 @@ var ts; description: ts.Diagnostics.Specify_library_files_to_be_included_in_the_compilation_Colon }, { - name: "disableProjectSizeLimit", + name: "disableSizeLimit", type: "boolean" }, { @@ -38629,7 +38830,7 @@ var ts; var usageColumn = []; var descriptionColumn = []; var optionsDescriptionMap = {}; - var _loop_2 = function(i) { + var _loop_3 = function(i) { var option = optsList[i]; if (!option.description) { return "continue"; @@ -38660,7 +38861,7 @@ var ts; marginLength = Math.max(usageText_1.length, marginLength); }; for (var i = 0; i < optsList.length; i++) { - _loop_2(i); + _loop_3(i); } var usageText = " @<" + getDiagnosticText(ts.Diagnostics.file) + ">"; usageColumn.push(usageText); diff --git a/lib/tsserver.js b/lib/tsserver.js index bd80f9f800e..33c26a7cdac 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -2286,6 +2286,9 @@ var ts; Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, File_name_0_has_a_1_extension_stripping_it: { code: 6132, category: ts.DiagnosticCategory.Message, key: "File_name_0_has_a_1_extension_stripping_it_6132", message: "File name '{0}' has a '{1}' extension - stripping it" }, + _0_is_declared_but_never_used: { code: 6133, category: ts.DiagnosticCategory.Error, key: "_0_is_declared_but_never_used_6133", message: "'{0}' is declared but never used." }, + Report_Errors_on_Unused_Locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Locals_6134", message: "Report Errors on Unused Locals." }, + Report_Errors_on_Unused_Parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Parameters_6135", message: "Report Errors on Unused Parameters." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -3950,6 +3953,16 @@ var ts; type: "boolean", description: ts.Diagnostics.Raise_error_on_this_expressions_with_an_implied_any_type }, + { + name: "noUnusedLocals", + type: "boolean", + description: ts.Diagnostics.Report_Errors_on_Unused_Locals + }, + { + name: "noUnusedParameters", + type: "boolean", + description: ts.Diagnostics.Report_Errors_on_Unused_Parameters + }, { name: "noLib", type: "boolean" @@ -4139,16 +4152,6 @@ var ts; isFilePath: true } }, - { - name: "typesSearchPaths", - type: "list", - isTSConfigOnly: true, - element: { - name: "typesSearchPaths", - type: "string", - isFilePath: true - } - }, { name: "typeRoots", type: "list", @@ -4223,7 +4226,7 @@ var ts; description: ts.Diagnostics.Specify_library_files_to_be_included_in_the_compilation_Colon }, { - name: "disableProjectSizeLimit", + name: "disableSizeLimit", type: "boolean" }, { @@ -9645,8 +9648,11 @@ var ts; if (lhs.kind === 69) { return lhs.text === rhs.text; } - return lhs.right.text === rhs.right.text && - tagNamesAreEquivalent(lhs.left, rhs.left); + if (lhs.kind === 97) { + return true; + } + return lhs.name.text === rhs.name.text && + tagNamesAreEquivalent(lhs.expression, rhs.expression); } function parseJsxElementOrSelfClosingElement(inExpressionContext) { var opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext); @@ -9743,15 +9749,15 @@ var ts; } function parseJsxElementName() { scanJsxIdentifier(); - var elementName = parseIdentifierName(); + var expression = token === 97 ? + parseTokenNode() : parseIdentifierName(); while (parseOptional(21)) { - scanJsxIdentifier(); - var node = createNode(139, elementName.pos); - node.left = elementName; - node.right = parseIdentifierName(); - elementName = finishNode(node); + var propertyAccess = createNode(172, expression.pos); + propertyAccess.expression = expression; + propertyAccess.name = parseRightSideOfDot(true); + expression = finishNode(propertyAccess); } - return elementName; + return expression; } function parseJsxExpression(inExpressionContext) { var node = createNode(248); @@ -10529,7 +10535,7 @@ var ts; case 56: return parseExportAssignment(fullStart, decorators, modifiers); case 116: - return parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers); + return parseNamespaceExportDeclaration(fullStart, decorators, modifiers); default: return parseExportDeclaration(fullStart, decorators, modifiers); } @@ -11043,7 +11049,7 @@ var ts; function nextTokenIsSlash() { return nextToken() === 39; } - function parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers) { + function parseNamespaceExportDeclaration(fullStart, decorators, modifiers) { var exportDeclaration = createNode(228, fullStart); exportDeclaration.decorators = decorators; exportDeclaration.modifiers = modifiers; @@ -14714,7 +14720,7 @@ var ts; function getTargetOfImportSpecifier(node) { return getExternalModuleMember(node.parent.parent.parent, node); } - function getTargetOfGlobalModuleExportDeclaration(node) { + function getTargetOfNamespaceExportDeclaration(node) { return resolveExternalModuleSymbol(node.parent.symbol); } function getTargetOfExportSpecifier(node) { @@ -14740,7 +14746,7 @@ var ts; case 235: return getTargetOfExportAssignment(node); case 228: - return getTargetOfGlobalModuleExportDeclaration(node); + return getTargetOfNamespaceExportDeclaration(node); } } function resolveSymbol(symbol) { @@ -14823,9 +14829,12 @@ var ts; var left = name.kind === 139 ? name.left : name.expression; var right = name.kind === 139 ? name.right : name.name; var namespace = resolveEntityName(left, 1536, ignoreErrors); - if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) { + if (!namespace || ts.nodeIsMissing(right)) { return undefined; } + else if (namespace === unknownSymbol) { + return namespace; + } symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { if (!ignoreErrors) { @@ -15786,16 +15795,13 @@ var ts; writePunctuation(writer, 27); } } - function buildDisplayForParametersAndDelimiters(thisType, parameters, writer, enclosingDeclaration, flags, symbolStack) { + function buildDisplayForParametersAndDelimiters(thisParameter, parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 17); - if (thisType) { - writeKeyword(writer, 97); - writePunctuation(writer, 54); - writeSpace(writer); - buildTypeDisplay(thisType, writer, enclosingDeclaration, flags, symbolStack); + if (thisParameter) { + buildParameterDisplay(thisParameter, writer, enclosingDeclaration, flags, symbolStack); } for (var i = 0; i < parameters.length; i++) { - if (i > 0 || thisType) { + if (i > 0 || thisParameter) { writePunctuation(writer, 24); writeSpace(writer); } @@ -15843,7 +15849,7 @@ var ts; else { buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.thisType, signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildDisplayForParametersAndDelimiters(signature.thisParameter, signature.parameters, writer, enclosingDeclaration, flags, symbolStack); buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { @@ -16174,12 +16180,13 @@ var ts; if (func.kind === 150 && !ts.hasDynamicName(func)) { var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 149); if (getter) { - var signature = getSignatureFromDeclaration(getter); + var getterSignature = getSignatureFromDeclaration(getter); var thisParameter = getAccessorThisParameter(func); if (thisParameter && declaration === thisParameter) { - return signature.thisType; + ts.Debug.assert(!thisParameter.type); + return getTypeOfSymbol(getterSignature.thisParameter); } - return getReturnTypeOfSignature(signature); + return getReturnTypeOfSignature(getterSignature); } } var type = declaration.symbol.name === "this" @@ -16337,14 +16344,12 @@ var ts; } return undefined; } - function getAnnotatedAccessorThisType(accessor) { - if (accessor) { - var parameter = getAccessorThisParameter(accessor); - if (parameter && parameter.type) { - return getTypeFromTypeNode(accessor.parameters[0].type); - } - } - return undefined; + function getAnnotatedAccessorThisParameter(accessor) { + var parameter = getAccessorThisParameter(accessor); + return parameter && parameter.symbol; + } + function getThisTypeOfDeclaration(declaration) { + return getThisTypeOfSignature(getSignatureFromDeclaration(declaration)); } function getTypeOfAccessors(symbol) { var links = getSymbolLinks(symbol); @@ -16924,12 +16929,12 @@ var ts; type.typeArguments : ts.concatenate(type.typeArguments, [type]); resolveObjectTypeMembers(type, source, typeParameters, typeArguments); } - function createSignature(declaration, typeParameters, thisType, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { + function createSignature(declaration, typeParameters, thisParameter, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { var sig = new Signature(checker); sig.declaration = declaration; sig.typeParameters = typeParameters; sig.parameters = parameters; - sig.thisType = thisType; + sig.thisParameter = thisParameter; sig.resolvedReturnType = resolvedReturnType; sig.typePredicate = typePredicate; sig.minArgumentCount = minArgumentCount; @@ -16938,7 +16943,7 @@ var ts; return sig; } function cloneSignature(sig) { - return createSignature(sig.declaration, sig.typeParameters, sig.thisType, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); + return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); } function getDefaultConstructSignatures(classType) { var baseConstructorType = getBaseConstructorTypeOfClass(classType); @@ -17022,8 +17027,9 @@ var ts; var s = signature; if (unionSignatures.length > 1) { s = cloneSignature(signature); - if (ts.forEach(unionSignatures, function (sig) { return sig.thisType; })) { - s.thisType = getUnionType(ts.map(unionSignatures, function (sig) { return sig.thisType || anyType; })); + if (ts.forEach(unionSignatures, function (sig) { return sig.thisParameter; })) { + var thisType = getUnionType(ts.map(unionSignatures, function (sig) { return getTypeOfSymbol(sig.thisParameter) || anyType; })); + s.thisParameter = createTransientSymbol(signature.thisParameter, thisType); } s.resolvedReturnType = undefined; s.unionSignatures = unionSignatures; @@ -17208,6 +17214,7 @@ var ts; var types = containingType.types; var props; var commonFlags = (containingType.flags & 32768) ? 536870912 : 0; + var isReadonly = false; for (var _i = 0, types_2 = types; _i < types_2.length; _i++) { var current = types_2[_i]; var type = getApparentType(current); @@ -17221,6 +17228,9 @@ var ts; else if (!ts.contains(props, prop)) { props.push(prop); } + if (isReadonlySymbol(prop)) { + isReadonly = true; + } } else if (containingType.flags & 16384) { return undefined; @@ -17248,6 +17258,7 @@ var ts; commonFlags, name); result.containingType = containingType; result.declarations = declarations; + result.isReadonly = isReadonly; result.type = containingType.flags & 16384 ? getUnionType(propTypes) : getIntersectionType(propTypes); return result; } @@ -17406,7 +17417,7 @@ var ts; var parameters = []; var hasStringLiterals = false; var minArgumentCount = -1; - var thisType = undefined; + var thisParameter = undefined; var hasThisParameter = void 0; var isJSConstructSignature = ts.isJSDocConstructSignature(declaration); for (var i = isJSConstructSignature ? 1 : 0, n = declaration.parameters.length; i < n; i++) { @@ -17418,7 +17429,7 @@ var ts; } if (i === 0 && paramSymbol.name === "this") { hasThisParameter = true; - thisType = param.type ? getTypeFromTypeNode(param.type) : unknownType; + thisParameter = param.symbol; } else { parameters.push(paramSymbol); @@ -17437,10 +17448,12 @@ var ts; } if ((declaration.kind === 149 || declaration.kind === 150) && !ts.hasDynamicName(declaration) && - (!hasThisParameter || thisType === unknownType)) { + (!hasThisParameter || !thisParameter)) { var otherKind = declaration.kind === 149 ? 150 : 149; - var setter = ts.getDeclarationOfKind(declaration.symbol, otherKind); - thisType = getAnnotatedAccessorThisType(setter); + var other = ts.getDeclarationOfKind(declaration.symbol, otherKind); + if (other) { + thisParameter = getAnnotatedAccessorThisParameter(other); + } } if (minArgumentCount < 0) { minArgumentCount = declaration.parameters.length - (hasThisParameter ? 1 : 0); @@ -17458,7 +17471,7 @@ var ts; var typePredicate = declaration.type && declaration.type.kind === 154 ? createTypePredicateFromTypePredicateNode(declaration.type) : undefined; - links.resolvedSignature = createSignature(declaration, typeParameters, thisType, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); + links.resolvedSignature = createSignature(declaration, typeParameters, thisParameter, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); } return links.resolvedSignature; } @@ -17528,6 +17541,11 @@ var ts; } return anyType; } + function getThisTypeOfSignature(signature) { + if (signature.thisParameter) { + return getTypeOfSymbol(signature.thisParameter); + } + } function getReturnTypeOfSignature(signature) { if (!signature.resolvedReturnType) { if (!pushTypeResolution(signature, 3)) { @@ -18245,7 +18263,7 @@ var ts; if (signature.typePredicate) { freshTypePredicate = cloneTypePredicate(signature.typePredicate, mapper); } - var result = createSignature(signature.declaration, freshTypeParameters, signature.thisType && instantiateType(signature.thisType, mapper), instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); + var result = createSignature(signature.declaration, freshTypeParameters, signature.thisParameter && instantiateSymbol(signature.thisParameter, mapper), instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); result.target = signature; result.mapper = mapper; return result; @@ -18448,16 +18466,20 @@ var ts; source = getErasedSignature(source); target = getErasedSignature(target); var result = -1; - if (source.thisType && target.thisType && source.thisType !== voidType) { - var related = compareTypes(source.thisType, target.thisType, false) - || compareTypes(target.thisType, source.thisType, reportErrors); - if (!related) { - if (reportErrors) { - errorReporter(ts.Diagnostics.The_this_types_of_each_signature_are_incompatible); + var sourceThisType = getThisTypeOfSignature(source); + if (sourceThisType && sourceThisType !== voidType) { + var targetThisType = getThisTypeOfSignature(target); + if (targetThisType) { + var related = compareTypes(sourceThisType, targetThisType, false) + || compareTypes(targetThisType, sourceThisType, reportErrors); + if (!related) { + if (reportErrors) { + errorReporter(ts.Diagnostics.The_this_types_of_each_signature_are_incompatible); + } + return 0; } - return 0; + result &= related; } - result &= related; } var sourceMax = getNumNonRestParameters(source); var targetMax = getNumNonRestParameters(target); @@ -19275,12 +19297,18 @@ var ts; source = getErasedSignature(source); target = getErasedSignature(target); var result = -1; - if (!ignoreThisTypes && source.thisType && target.thisType) { - var related = compareTypes(source.thisType, target.thisType); - if (!related) { - return 0; + if (!ignoreThisTypes) { + var sourceThisType = getThisTypeOfSignature(source); + if (sourceThisType) { + var targetThisType = getThisTypeOfSignature(target); + if (targetThisType) { + var related = compareTypes(sourceThisType, targetThisType); + if (!related) { + return 0; + } + result &= related; + } } - result &= related; } var targetLen = target.parameters.length; for (var i = 0; i < targetLen; i++) { @@ -20543,8 +20571,20 @@ var ts; } return container === declarationContainer; } + function updateReferencesForInterfaceHeritiageClauseTargets(node) { + var extendedTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (extendedTypeNode) { + var t = getTypeFromTypeNode(extendedTypeNode); + if (t !== unknownType && t.symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + t.symbol.hasReference = true; + } + } + } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); + if (symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + symbol.hasReference = true; + } if (symbol === argumentsSymbol) { var container = ts.getContainingFunction(node); if (container.kind === 180) { @@ -20754,9 +20794,9 @@ var ts; if (type) { return type; } - var signature = getSignatureFromDeclaration(container); - if (signature.thisType) { - return signature.thisType; + var thisType = getThisTypeOfDeclaration(container); + if (thisType) { + return thisType; } } if (ts.isClassLike(container.parent)) { @@ -20899,7 +20939,7 @@ var ts; if (isContextSensitiveFunctionOrObjectLiteralMethod(func) && func.kind !== 180) { var contextualSignature = getContextualSignature(func); if (contextualSignature) { - return contextualSignature.thisType; + return getThisTypeOfSignature(contextualSignature); } } return undefined; @@ -21481,7 +21521,7 @@ var ts; return name.indexOf("-") < 0; } function isJsxIntrinsicIdentifier(tagName) { - if (tagName.kind === 139) { + if (tagName.kind === 172 || tagName.kind === 97) { return false; } else { @@ -21617,6 +21657,25 @@ var ts; return getResolvedJsxType(node, type, elemClassType); })); } + if (elemType.flags & 2) { + return anyType; + } + else if (elemType.flags & 256) { + var intrinsicElementsType = getJsxType(JsxNames.IntrinsicElements); + if (intrinsicElementsType !== unknownType) { + var stringLiteralTypeName = elemType.text; + var intrinsicProp = getPropertyOfType(intrinsicElementsType, stringLiteralTypeName); + if (intrinsicProp) { + return getTypeOfSymbol(intrinsicProp); + } + var indexSignatureType = getIndexTypeOfType(intrinsicElementsType, 0); + if (indexSignatureType) { + return indexSignatureType; + } + error(node, ts.Diagnostics.Property_0_does_not_exist_on_type_1, stringLiteralTypeName, "JSX." + JsxNames.IntrinsicElements); + } + return anyType; + } var elemInstanceType = getJsxElementInstanceType(node, elemType); if (!elemClassType || !isTypeAssignableTo(elemInstanceType, elemClassType)) { if (jsxElementType) { @@ -21861,6 +21920,9 @@ var ts; } return unknownType; } + if ((compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + prop.hasReference = true; + } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & 32) { checkClassPropertyAccess(node, left, apparentType, prop); @@ -22173,10 +22235,11 @@ var ts; if (context.failedTypeParameterIndex !== undefined && !context.inferences[context.failedTypeParameterIndex].isFixed) { context.failedTypeParameterIndex = undefined; } - if (signature.thisType) { + var thisType = getThisTypeOfSignature(signature); + if (thisType) { var thisArgumentNode = getThisArgumentOfCall(node); var thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType; - inferTypes(context, thisArgumentType, signature.thisType); + inferTypes(context, thisArgumentType, thisType); } var argCount = getEffectiveArgumentCount(node, args, signature); for (var i = 0; i < argCount; i++) { @@ -22227,12 +22290,13 @@ var ts; return typeArgumentsAreAssignable; } function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) { - if (signature.thisType && signature.thisType !== voidType && node.kind !== 175) { + var thisType = getThisTypeOfSignature(signature); + if (thisType && thisType !== voidType && node.kind !== 175) { var thisArgumentNode = getThisArgumentOfCall(node); var thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType; var errorNode = reportErrors ? (thisArgumentNode || node) : undefined; var headMessage_1 = ts.Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1; - if (!checkTypeRelatedTo(thisArgumentType, signature.thisType, relation, errorNode, headMessage_1)) { + if (!checkTypeRelatedTo(thisArgumentType, getThisTypeOfSignature(signature), relation, errorNode, headMessage_1)) { return false; } } @@ -22648,7 +22712,7 @@ var ts; if (getReturnTypeOfSignature(signature) !== voidType) { error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } - if (signature.thisType === voidType) { + if (getThisTypeOfSignature(signature) === voidType) { error(node, ts.Diagnostics.A_function_that_is_called_with_the_new_keyword_cannot_have_a_this_type_that_is_void); } return signature; @@ -23128,6 +23192,8 @@ var ts; } } } + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); } } function checkArithmeticOperandType(operand, type, diagnostic) { @@ -23138,7 +23204,8 @@ var ts; return true; } function isReadonlySymbol(symbol) { - return symbol.flags & 4 && (getDeclarationFlagsFromSymbol(symbol) & 64) !== 0 || + return symbol.isReadonly || + symbol.flags & 4 && (getDeclarationFlagsFromSymbol(symbol) & 64) !== 0 || symbol.flags & 3 && (getDeclarationFlagsFromSymbol(symbol) & 2048) !== 0 || symbol.flags & 98304 && !(symbol.flags & 65536) || (symbol.flags & 8) !== 0; @@ -23973,6 +24040,9 @@ var ts; checkAsyncFunctionReturnType(node); } } + if (!node.body) { + checkUnusedTypeParameters(node); + } } } function checkClassForDuplicateDeclarations(node) { @@ -24100,6 +24170,8 @@ var ts; checkSignatureDeclaration(node); checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node); checkSourceElement(node.body); + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); var symbol = getSymbolOfNode(node); var firstDeclaration = ts.getDeclarationOfKind(symbol, node.kind); if (node === firstDeclaration) { @@ -24203,7 +24275,7 @@ var ts; error(node.name, ts.Diagnostics.Accessors_must_both_be_abstract_or_non_abstract); } checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorType, ts.Diagnostics.get_and_set_accessor_must_have_the_same_type); - checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorThisType, ts.Diagnostics.get_and_set_accessor_must_have_the_same_this_type); + checkAccessorDeclarationTypesIdentical(node, otherAccessor, getThisTypeOfDeclaration, ts.Diagnostics.get_and_set_accessor_must_have_the_same_this_type); } } getTypeOfAccessors(getSymbolOfNode(node)); @@ -24248,12 +24320,17 @@ var ts; function checkTypeReferenceNode(node) { checkGrammarTypeArguments(node, node.typeArguments); var type = getTypeFromTypeReference(node); - if (type !== unknownType && node.typeArguments) { - ts.forEach(node.typeArguments, checkSourceElement); - if (produceDiagnostics) { - var symbol = getNodeLinks(node).resolvedSymbol; - var typeParameters = symbol.flags & 524288 ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; - checkTypeArgumentConstraints(typeParameters, node.typeArguments); + if (type !== unknownType) { + if (type.symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + type.symbol.hasReference = true; + } + if (node.typeArguments) { + ts.forEach(node.typeArguments, checkSourceElement); + if (produceDiagnostics) { + var symbol = getNodeLinks(node).resolvedSymbol; + var typeParameters = symbol.flags & 524288 ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; + checkTypeArgumentConstraints(typeParameters, node.typeArguments); + } } } } @@ -24783,6 +24860,8 @@ var ts; } } checkSourceElement(node.body); + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); if (!node.asteriskToken) { var returnOrPromisedType = node.type && (isAsync ? checkAsyncFunctionReturnType(node) : getTypeFromTypeNode(node.type)); checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnOrPromisedType); @@ -24796,11 +24875,83 @@ var ts; } } } + function checkUnusedIdentifiers(node) { + if (node.parent.kind !== 222 && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + for (var key in node.locals) { + if (ts.hasProperty(node.locals, key)) { + var local = node.locals[key]; + if (!local.hasReference && local.valueDeclaration) { + if (local.valueDeclaration.kind !== 142 && compilerOptions.noUnusedLocals) { + error(local.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local.name); + } + else if (local.valueDeclaration.kind === 142 && compilerOptions.noUnusedParameters) { + if (local.valueDeclaration.flags === 0) { + error(local.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local.name); + } + } + } + } + } + } + } + function checkUnusedClassLocals(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + if (node.members) { + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 147 || member.kind === 145) { + if (isPrivateNode(member) && !member.symbol.hasReference) { + error(member.name, ts.Diagnostics._0_is_declared_but_never_used, member.symbol.name); + } + } + else if (member.kind === 148) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var parameter = _c[_b]; + if (isPrivateNode(parameter) && !parameter.symbol.hasReference) { + error(parameter.name, ts.Diagnostics._0_is_declared_but_never_used, parameter.symbol.name); + } + } + } + } + } + } + } + function checkUnusedTypeParameters(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + if (node.typeParameters) { + for (var _i = 0, _a = node.typeParameters; _i < _a.length; _i++) { + var typeParameter = _a[_i]; + if (!typeParameter.symbol.hasReference) { + error(typeParameter.name, ts.Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name); + } + } + } + } + } + function isPrivateNode(node) { + return (node.flags & 8) !== 0; + } + function checkUnusedModuleLocals(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + var _loop_1 = function(key) { + if (ts.hasProperty(node.locals, key)) { + var local_1 = node.locals[key]; + if (!local_1.hasReference && !local_1.exportSymbol) { + ts.forEach(local_1.declarations, function (d) { return error(d.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); }); + } + } + }; + for (var key in node.locals) { + _loop_1(key); + } + } + } function checkBlock(node) { if (node.kind === 199) { checkGrammarStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); + checkUnusedIdentifiers(node); } function checkCollisionWithArgumentsInGeneratedCode(node) { if (!ts.hasDeclaredRestParameter(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { @@ -25146,6 +25297,7 @@ var ts; } } checkSourceElement(node.statement); + checkUnusedIdentifiers(node); } function checkForInStatement(node) { checkGrammarForInOrForOfStatement(node); @@ -25174,6 +25326,7 @@ var ts; error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); + checkUnusedIdentifiers(node); } function checkForInOrForOfVariableDeclaration(iterationStatement) { var variableDeclarationList = iterationStatement.initializer; @@ -25470,6 +25623,7 @@ var ts; } } checkBlock(catchClause.block); + checkUnusedIdentifiers(catchClause); } if (node.finallyBlock) { checkBlock(node.finallyBlock); @@ -25592,6 +25746,8 @@ var ts; } checkClassLikeDeclaration(node); ts.forEach(node.members, checkSourceElement); + checkUnusedClassLocals(node); + checkUnusedTypeParameters(node); } function checkClassLikeDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); @@ -25832,6 +25988,8 @@ var ts; ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); + updateReferencesForInterfaceHeritiageClauseTargets(node); + checkUnusedTypeParameters(node); } } function checkTypeAliasDeclaration(node) { @@ -26151,6 +26309,7 @@ var ts; } if (node.body) { checkSourceElement(node.body); + checkUnusedModuleLocals(node); } } function checkModuleAugmentationElement(node, isGlobalAugmentation) { @@ -26301,6 +26460,9 @@ var ts; if (target.flags & 793056) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); } + if ((compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + target.hasReference = true; + } } } else { @@ -26588,6 +26750,9 @@ var ts; potentialThisCollisions.length = 0; deferredNodes = []; ts.forEach(node.statements, checkSourceElement); + if (ts.isExternalModule(node)) { + checkUnusedModuleLocals(node); + } checkDeferredNodes(); deferredNodes = undefined; if (ts.isExternalOrCommonJsModule(node)) { @@ -26876,6 +27041,13 @@ var ts; case 139: return getSymbolOfEntityNameOrPropertyAccessExpression(node); case 97: + var container = ts.getThisContainer(node, false); + if (ts.isFunctionLike(container)) { + var sig = getSignatureFromDeclaration(container); + if (sig.thisParameter) { + return sig.thisParameter; + } + } case 95: var type = ts.isExpression(node) ? checkExpression(node) : getTypeFromTypeNode(node); return type.symbol; @@ -27064,7 +27236,9 @@ var ts; var parentSymbol = getParentOfSymbol(symbol); if (parentSymbol) { if (parentSymbol.flags & 512 && parentSymbol.valueDeclaration.kind === 256) { - return parentSymbol.valueDeclaration; + if (parentSymbol.valueDeclaration === ts.getSourceFileOfNode(node)) { + return parentSymbol.valueDeclaration; + } } for (var n = node.parent; n; n = n.parent) { if ((n.kind === 225 || n.kind === 224) && getSymbolOfNode(n) === parentSymbol) { @@ -27957,7 +28131,7 @@ var ts; var GetAccessor = 2; var SetAccessor = 4; var GetOrSetAccessor = GetAccessor | SetAccessor; - var _loop_1 = function(prop) { + var _loop_2 = function(prop) { var name_22 = prop.name; if (prop.kind === 193 || name_22.kind === 140) { @@ -28018,8 +28192,8 @@ var ts; }; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var state_2 = _loop_1(prop); - if (typeof state_2 === "object") return state_2.value; + var state_3 = _loop_2(prop); + if (typeof state_3 === "object") return state_3.value; } } function checkGrammarJsxElement(node) { @@ -30649,6 +30823,8 @@ var ts; return generateNameForExportDefault(); case 192: return generateNameForClassExpression(); + default: + ts.Debug.fail(); } } function getGeneratedNameForNode(node) { @@ -31346,6 +31522,20 @@ var ts; } return false; } + function getClassExpressionInPropertyAccessInStaticPropertyDeclaration(node) { + if (languageVersion >= 2) { + var parent_14 = node.parent; + if (parent_14.kind === 172 && parent_14.expression === node) { + parent_14 = parent_14.parent; + while (parent_14 && parent_14.kind !== 145) { + parent_14 = parent_14.parent; + } + return parent_14 && parent_14.kind === 145 && (parent_14.flags & 32) !== 0 && + parent_14.parent.kind === 192 ? parent_14.parent : undefined; + } + } + return undefined; + } function emitIdentifier(node) { if (convertedLoopState) { if (node.text == "arguments" && resolver.isArgumentsLocalBinding(node)) { @@ -31358,6 +31548,14 @@ var ts; write(node.text); } else if (isExpressionIdentifier(node)) { + var classExpression = getClassExpressionInPropertyAccessInStaticPropertyDeclaration(node); + if (classExpression) { + var declaration = resolver.getReferencedValueDeclaration(node); + if (declaration === classExpression) { + write(getGeneratedNameForNode(declaration.name)); + return; + } + } emitExpressionIdentifier(node); } else if (isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(node)) { @@ -33897,7 +34095,7 @@ var ts; emitStart(property); emitStart(property.name); if (receiver) { - emit(receiver); + write(receiver); } else { if (property.flags & 32) { @@ -34180,12 +34378,15 @@ var ts; } var staticProperties = getInitializedProperties(node, true); var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 192; - var tempVariable; + var generatedName; if (isClassExpressionWithStaticProperties) { - tempVariable = createAndRecordTempVariable(0); + generatedName = getGeneratedNameForNode(node.name); + var synthesizedNode = ts.createSynthesizedNode(69); + synthesizedNode.text = generatedName; + recordTempDeclaration(synthesizedNode); write("("); increaseIndent(); - emit(tempVariable); + emit(synthesizedNode); write(" = "); } write("class"); @@ -34225,11 +34426,11 @@ var ts; var property = staticProperties_1[_a]; write(","); writeLine(); - emitPropertyDeclaration(node, property, tempVariable, true); + emitPropertyDeclaration(node, property, generatedName, true); } write(","); writeLine(); - emit(tempVariable); + write(generatedName); decreaseIndent(); write(")"); } @@ -36407,7 +36608,7 @@ var ts; ts.emitTime = 0; ts.ioReadTime = 0; ts.ioWriteTime = 0; - ts.version = "1.9.0"; + ts.version = "2.0.0"; var emptyArray = []; var defaultTypeRoots = ["node_modules/@types"]; function findConfigFile(searchPath, fileExists) { @@ -38689,24 +38890,24 @@ var ts; switch (n.kind) { case 199: if (!ts.isFunctionBlock(n)) { - var parent_14 = n.parent; + var parent_15 = n.parent; var openBrace = ts.findChildOfKind(n, 15, sourceFile); var closeBrace = ts.findChildOfKind(n, 16, sourceFile); - if (parent_14.kind === 204 || - parent_14.kind === 207 || - parent_14.kind === 208 || - parent_14.kind === 206 || - parent_14.kind === 203 || - parent_14.kind === 205 || - parent_14.kind === 212 || - parent_14.kind === 252) { - addOutliningSpan(parent_14, openBrace, closeBrace, autoCollapse(n)); + if (parent_15.kind === 204 || + parent_15.kind === 207 || + parent_15.kind === 208 || + parent_15.kind === 206 || + parent_15.kind === 203 || + parent_15.kind === 205 || + parent_15.kind === 212 || + parent_15.kind === 252) { + addOutliningSpan(parent_15, openBrace, closeBrace, autoCollapse(n)); break; } - if (parent_14.kind === 216) { - var tryStatement = parent_14; + if (parent_15.kind === 216) { + var tryStatement = parent_15; if (tryStatement.tryBlock === n) { - addOutliningSpan(parent_14, openBrace, closeBrace, autoCollapse(n)); + addOutliningSpan(parent_15, openBrace, closeBrace, autoCollapse(n)); break; } else if (tryStatement.finallyBlock === n) { @@ -40114,7 +40315,7 @@ var ts; signatureHelpParameters = typeParameters && typeParameters.length > 0 ? ts.map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; suffixDisplayParts.push(ts.punctuationPart(27)); var parameterParts = ts.mapToDisplayParts(function (writer) { - return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.thisType, candidateSignature.parameters, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.thisParameter, candidateSignature.parameters, writer, invocation); }); ts.addRange(suffixDisplayParts, parameterParts); } @@ -40228,6 +40429,8 @@ var ts; case 199: case 226: case 227: + case 233: + case 237: return nodeEndsWith(n, 16, sourceFile); case 252: return isCompletedNode(n.block, sourceFile); @@ -40310,6 +40513,9 @@ var ts; return isCompletedNode(lastSpan, sourceFile); case 197: return ts.nodeIsPresent(n.literal); + case 236: + case 230: + return ts.nodeIsPresent(n.moduleSpecifier); case 185: return isCompletedNode(n.operand, sourceFile); case 187: @@ -41505,7 +41711,7 @@ var ts; this.NoSpaceAfterCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create3(20, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), 8)); this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); - this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([69, 3, 73]); + this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([69, 3, 73, 82, 89]); this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18, 3, 79, 100, 85, 80]); this.SpaceBeforeOpenBraceInControl = new formatting.Rule(formatting.RuleDescriptor.create2(this.ControlOpenBraceLeftTokenRange, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); @@ -41540,8 +41746,8 @@ var ts; this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(121, 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8)); this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([125, 129]), 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8)); - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([115, 73, 122, 77, 81, 82, 83, 123, 106, 89, 107, 125, 126, 110, 112, 111, 131, 113, 134]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([83, 106])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([115, 73, 122, 77, 81, 82, 83, 123, 106, 89, 107, 125, 126, 110, 112, 111, 131, 113, 134, 136]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([83, 106, 136])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(9, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2)); this.SpaceBeforeArrow = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 34), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); this.SpaceAfterArrow = new formatting.Rule(formatting.RuleDescriptor.create3(34, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); @@ -41667,6 +41873,8 @@ var ts; case 187: case 188: case 195: + case 238: + case 234: case 154: case 162: case 163: @@ -41754,6 +41962,10 @@ var ts; case 224: case 159: case 225: + case 236: + case 237: + case 230: + case 233: return true; } return false; @@ -42445,7 +42657,8 @@ var ts; var startLinePosition = ts.getLineStartPositionForPosition(startPos, sourceFile); var column = formatting.SmartIndenter.findFirstNonWhitespaceColumn(startLinePosition, startPos, sourceFile, options); if (startLine !== parentStartLine || startPos === column) { - return column; + var baseIndentSize = formatting.SmartIndenter.getBaseIndentation(options); + return baseIndentSize > column ? baseIndentSize : column; } } return -1; @@ -43006,14 +43219,14 @@ var ts; (function (SmartIndenter) { function getIndentation(position, sourceFile, options) { if (position > sourceFile.text.length) { - return 0; + return getBaseIndentation(options); } if (options.IndentStyle === ts.IndentStyle.None) { return 0; } var precedingToken = ts.findPrecedingToken(position, sourceFile); if (!precedingToken) { - return 0; + return getBaseIndentation(options); } var precedingTokenIsLiteral = ts.isStringOrRegularExpressionOrTemplateLiteral(precedingToken.kind); if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { @@ -43065,11 +43278,15 @@ var ts; current = current.parent; } if (!current) { - return 0; + return getBaseIndentation(options); } return getIndentationForNodeWorker(current, currentStart, undefined, indentationDelta, sourceFile, options); } SmartIndenter.getIndentation = getIndentation; + function getBaseIndentation(options) { + return options.BaseIndentSize || 0; + } + SmartIndenter.getBaseIndentation = getBaseIndentation; function getIndentationForNode(n, ignoreActualIndentationRange, sourceFile, options) { var start = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)); return getIndentationForNodeWorker(n, start, ignoreActualIndentationRange, 0, sourceFile, options); @@ -43110,7 +43327,7 @@ var ts; currentStart = parentStart; parent = current.parent; } - return indentationDelta; + return indentationDelta + getBaseIndentation(options); } function getParentStart(parent, child, sourceFile) { var containingList = getContainingList(child, sourceFile); @@ -43336,7 +43553,10 @@ var ts; case 164: case 176: case 184: + case 237: case 233: + case 238: + case 234: return true; } return false; @@ -43358,6 +43578,11 @@ var ts; case 149: case 150: return childKind !== 199; + case 236: + return childKind !== 237; + case 230: + return childKind !== 231 || + child.namedBindings.kind !== 233; case 241: return childKind !== 245; } @@ -44211,8 +44436,8 @@ var ts; if (declaration.kind !== 218 && declaration.kind !== 220) { return false; } - for (var parent_15 = declaration.parent; !ts.isFunctionBlock(parent_15); parent_15 = parent_15.parent) { - if (parent_15.kind === 256 || parent_15.kind === 226) { + for (var parent_16 = declaration.parent; !ts.isFunctionBlock(parent_16); parent_16 = parent_16.parent) { + if (parent_16.kind === 256 || parent_16.kind === 226) { return false; } } @@ -44329,7 +44554,7 @@ var ts; return typeof o.type === "object" && !ts.forEachValue(o.type, function (v) { return typeof v !== "number"; }); }); options = ts.clone(options); - var _loop_2 = function(opt) { + var _loop_3 = function(opt) { if (!ts.hasProperty(options, opt.name)) { return "continue"; } @@ -44345,7 +44570,7 @@ var ts; }; for (var _i = 0, commandLineOptionsStringToEnum_1 = commandLineOptionsStringToEnum; _i < commandLineOptionsStringToEnum_1.length; _i++) { var opt = commandLineOptionsStringToEnum_1[_i]; - _loop_2(opt); + _loop_3(opt); } return options; } @@ -45326,13 +45551,13 @@ var ts; log("Returning an empty list because completion was requested in an invalid position."); return undefined; } - var parent_16 = contextToken.parent, kind = contextToken.kind; + var parent_17 = contextToken.parent, kind = contextToken.kind; if (kind === 21) { - if (parent_16.kind === 172) { + if (parent_17.kind === 172) { node = contextToken.parent.expression; isRightOfDot = true; } - else if (parent_16.kind === 139) { + else if (parent_17.kind === 139) { node = contextToken.parent.left; isRightOfDot = true; } @@ -45620,9 +45845,9 @@ var ts; switch (contextToken.kind) { case 15: case 24: - var parent_17 = contextToken.parent; - if (parent_17 && (parent_17.kind === 171 || parent_17.kind === 167)) { - return parent_17; + var parent_18 = contextToken.parent; + if (parent_18 && (parent_18.kind === 171 || parent_18.kind === 167)) { + return parent_18; } break; } @@ -45645,34 +45870,34 @@ var ts; } function tryGetContainingJsxElement(contextToken) { if (contextToken) { - var parent_18 = contextToken.parent; + var parent_19 = contextToken.parent; switch (contextToken.kind) { case 26: case 39: case 69: case 246: case 247: - if (parent_18 && (parent_18.kind === 242 || parent_18.kind === 243)) { - return parent_18; + if (parent_19 && (parent_19.kind === 242 || parent_19.kind === 243)) { + return parent_19; } - else if (parent_18.kind === 246) { - return parent_18.parent; + else if (parent_19.kind === 246) { + return parent_19.parent; } break; case 9: - if (parent_18 && ((parent_18.kind === 246) || (parent_18.kind === 247))) { - return parent_18.parent; + if (parent_19 && ((parent_19.kind === 246) || (parent_19.kind === 247))) { + return parent_19.parent; } break; case 16: - if (parent_18 && - parent_18.kind === 248 && - parent_18.parent && - (parent_18.parent.kind === 246)) { - return parent_18.parent.parent; + if (parent_19 && + parent_19.kind === 248 && + parent_19.parent && + (parent_19.parent.kind === 246)) { + return parent_19.parent.parent; } - if (parent_18 && parent_18.kind === 247) { - return parent_18.parent; + if (parent_19 && parent_19.kind === 247) { + return parent_19.parent; } break; } @@ -46873,17 +47098,17 @@ var ts; function getThrowStatementOwner(throwStatement) { var child = throwStatement; while (child.parent) { - var parent_19 = child.parent; - if (ts.isFunctionBlock(parent_19) || parent_19.kind === 256) { - return parent_19; + var parent_20 = child.parent; + if (ts.isFunctionBlock(parent_20) || parent_20.kind === 256) { + return parent_20; } - if (parent_19.kind === 216) { - var tryStatement = parent_19; + if (parent_20.kind === 216) { + var tryStatement = parent_20; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; } } - child = parent_19; + child = parent_20; } return undefined; } @@ -47241,13 +47466,27 @@ var ts; if (node === sourceFile) { return undefined; } - if (node.kind !== 69 && - node.kind !== 9 && - !isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { - return undefined; + switch (node.kind) { + case 8: + if (!isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { + break; + } + case 69: + case 97: + case 9: + return getReferencedSymbolsForNode(node, program.getSourceFiles(), findInStrings, findInComments); + } + return undefined; + } + function isThis(node) { + switch (node.kind) { + case 97: + return true; + case 69: + return node.originalKeywordKind === 97 && node.parent.kind === 142; + default: + return false; } - ts.Debug.assert(node.kind === 69 || node.kind === 8 || node.kind === 9); - return getReferencedSymbolsForNode(node, program.getSourceFiles(), findInStrings, findInComments); } function getReferencedSymbolsForNode(node, sourceFiles, findInStrings, findInComments) { var typeChecker = program.getTypeChecker(); @@ -47260,7 +47499,7 @@ var ts; return getLabelReferencesInNode(node.parent, node); } } - if (node.kind === 97 || node.kind === 165) { + if (isThis(node)) { return getReferencesForThisKeyword(node, sourceFiles); } if (node.kind === 95) { @@ -47625,7 +47864,7 @@ var ts; ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); var node = ts.getTouchingWord(sourceFile, position); - if (!node || (node.kind !== 97 && node.kind !== 165)) { + if (!node || !isThis(node)) { return; } var container = ts.getThisContainer(node, false); @@ -48465,8 +48704,8 @@ var ts; return; case 142: if (token.parent.name === token) { - var isThis = token.kind === 69 && token.originalKeywordKind === 97; - return isThis ? 3 : 17; + var isThis_1 = token.kind === 69 && token.originalKeywordKind === 97; + return isThis_1 ? 3 : 17; } return; } @@ -48616,7 +48855,7 @@ var ts; (tokenStart === position ? newLine + indentationStr : ""); return { newText: result, caretOffset: preamble.length }; } - function isValidBraceCompletionAtPostion(fileName, position, openingBrace) { + function isValidBraceCompletionAtPosition(fileName, position, openingBrace) { if (openingBrace === 60) { return false; } @@ -48741,7 +48980,8 @@ var ts; if (node) { if (node.kind === 69 || node.kind === 9 || - isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { + isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || + isThis(node)) { var symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { var declarations = symbol.getDeclarations(); @@ -48852,7 +49092,7 @@ var ts; getFormattingEditsForDocument: getFormattingEditsForDocument, getFormattingEditsAfterKeystroke: getFormattingEditsAfterKeystroke, getDocCommentTemplateAtPosition: getDocCommentTemplateAtPosition, - isValidBraceCompletionAtPostion: isValidBraceCompletionAtPostion, + isValidBraceCompletionAtPosition: isValidBraceCompletionAtPosition, getEmitOutput: getEmitOutput, getNonBoundSourceFile: getNonBoundSourceFile, getProgram: getProgram @@ -49347,6 +49587,8 @@ var ts; CommandNames.Formatonkey = "formatonkey"; CommandNames.Geterr = "geterr"; CommandNames.GeterrForProject = "geterrForProject"; + CommandNames.SemanticDiagnosticsSync = "semanticDiagnosticsSync"; + CommandNames.SyntacticDiagnosticsSync = "syntacticDiagnosticsSync"; CommandNames.NavBar = "navbar"; CommandNames.Navto = "navto"; CommandNames.Occurrences = "occurrences"; @@ -49366,6 +49608,7 @@ var ts; var Errors; (function (Errors) { Errors.NoProject = new Error("No Project."); + Errors.ProjectLanguageServiceDisabled = new Error("The project's language service is disabled."); })(Errors || (Errors = {})); var Session = (function () { function Session(host, byteLength, hrtime, logger) { @@ -49442,6 +49685,12 @@ var ts; var signatureHelpArgs = request.arguments; return { response: _this.getSignatureHelpItems(signatureHelpArgs.line, signatureHelpArgs.offset, signatureHelpArgs.file), responseRequired: true }; }, + _a[CommandNames.SemanticDiagnosticsSync] = function (request) { + return _this.requiredResponse(_this.getSemanticDiagnosticsSync(request.arguments)); + }, + _a[CommandNames.SyntacticDiagnosticsSync] = function (request) { + return _this.requiredResponse(_this.getSyntacticDiagnosticsSync(request.arguments)); + }, _a[CommandNames.Geterr] = function (request) { var geterrArgs = request.arguments; return { response: _this.getDiagnostics(geterrArgs.delay, geterrArgs.files), responseRequired: false }; @@ -49720,6 +49969,24 @@ var ts; }; }); }; + Session.prototype.getDiagnosticsWorker = function (args, selector) { + var file = ts.normalizePath(args.file); + var project = this.projectService.getProjectForFile(file); + if (!project) { + throw Errors.NoProject; + } + if (project.languageServiceDiabled) { + throw Errors.ProjectLanguageServiceDisabled; + } + var diagnostics = selector(project, file); + return ts.map(diagnostics, function (originalDiagnostic) { return formatDiag(file, project, originalDiagnostic); }); + }; + Session.prototype.getSyntacticDiagnosticsSync = function (args) { + return this.getDiagnosticsWorker(args, function (project, file) { return project.compilerService.languageService.getSyntacticDiagnostics(file); }); + }; + Session.prototype.getSemanticDiagnosticsSync = function (args) { + return this.getDiagnosticsWorker(args, function (project, file) { return project.compilerService.languageService.getSemanticDiagnostics(file); }); + }; Session.prototype.getDocumentHighlights = function (line, offset, fileName, filesToSearch) { fileName = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(fileName); @@ -49954,6 +50221,7 @@ var ts; var lineText = lineInfo.leaf.text; if (lineText.search("\\S") < 0) { var editorOptions = { + BaseIndentSize: formatOptions.BaseIndentSize, IndentSize: formatOptions.IndentSize, TabSize: formatOptions.TabSize, NewLineCharacter: formatOptions.NewLineCharacter, @@ -50257,6 +50525,9 @@ var ts; }; Session.prototype.exit = function () { }; + Session.prototype.requiredResponse = function (response) { + return { response: response, responseRequired: true }; + }; Session.prototype.addProtocolHandler = function (command, handler) { if (this.handlers[command]) { throw new Error("Protocol handler already exists for command \"" + command + "\""); @@ -51511,6 +51782,7 @@ var ts; }; CompilerService.getDefaultFormatCodeOptions = function (host) { return ts.clone({ + BaseIndentSize: 0, IndentSize: 4, TabSize: 4, NewLineCharacter: host.newLine || "\n", @@ -52970,9 +53242,9 @@ var ts; var _this = this; return this.forwardJSONCall("getBraceMatchingAtPosition('" + fileName + "', " + position + ")", function () { return _this.languageService.getBraceMatchingAtPosition(fileName, position); }); }; - LanguageServiceShimObject.prototype.isValidBraceCompletionAtPostion = function (fileName, position, openingBrace) { + LanguageServiceShimObject.prototype.isValidBraceCompletionAtPosition = function (fileName, position, openingBrace) { var _this = this; - return this.forwardJSONCall("isValidBraceCompletionAtPostion('" + fileName + "', " + position + ", " + openingBrace + ")", function () { return _this.languageService.isValidBraceCompletionAtPostion(fileName, position, openingBrace); }); + return this.forwardJSONCall("isValidBraceCompletionAtPosition('" + fileName + "', " + position + ", " + openingBrace + ")", function () { return _this.languageService.isValidBraceCompletionAtPosition(fileName, position, openingBrace); }); }; LanguageServiceShimObject.prototype.getIndentationAtPosition = function (fileName, position, options) { var _this = this; diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index aef7909bd45..aa24fb95715 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -744,9 +744,10 @@ declare namespace ts { children: NodeArray; closingElement: JsxClosingElement; } + type JsxTagNameExpression = PrimaryExpression | PropertyAccessExpression; interface JsxOpeningElement extends Expression { _openingElementBrand?: any; - tagName: EntityName; + tagName: JsxTagNameExpression; attributes: NodeArray; } interface JsxSelfClosingElement extends PrimaryExpression, JsxOpeningElement { @@ -761,7 +762,7 @@ declare namespace ts { expression: Expression; } interface JsxClosingElement extends Node { - tagName: EntityName; + tagName: JsxTagNameExpression; } interface JsxExpression extends Expression { expression?: Expression; @@ -1263,7 +1264,7 @@ declare namespace ts { buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildTypePredicateDisplay(predicate: TypePredicate, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; - buildDisplayForParametersAndDelimiters(thisType: Type, parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildDisplayForParametersAndDelimiters(thisParameter: Symbol, parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; } @@ -1446,11 +1447,13 @@ declare namespace ts { members?: SymbolTable; exports?: SymbolTable; globalExports?: SymbolTable; + isReadonly?: boolean; id?: number; mergeId?: number; parent?: Symbol; exportSymbol?: Symbol; constEnumOnlyModule?: boolean; + hasReference?: boolean; } interface SymbolLinks { target?: Symbol; @@ -1639,7 +1642,7 @@ declare namespace ts { declaration: SignatureDeclaration; typeParameters: TypeParameter[]; parameters: Symbol[]; - thisType?: Type; + thisParameter?: Symbol; resolvedReturnType: Type; minArgumentCount: number; hasRestParameter: boolean; @@ -1757,6 +1760,8 @@ declare namespace ts { noImplicitAny?: boolean; noImplicitReturns?: boolean; noImplicitThis?: boolean; + noUnusedLocals?: boolean; + noUnusedParameters?: boolean; noImplicitUseStrict?: boolean; noLib?: boolean; noResolve?: boolean; @@ -1785,7 +1790,6 @@ declare namespace ts { disableSizeLimit?: boolean; types?: string[]; typeRoots?: string[]; - typesSearchPaths?: string[]; version?: boolean; watch?: boolean; [option: string]: CompilerOptionsValue | undefined; @@ -6438,6 +6442,24 @@ declare namespace ts { key: string; message: string; }; + _0_is_declared_but_never_used: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; + Report_Errors_on_Unused_Locals: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; + Report_Errors_on_Unused_Parameters: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; Variable_0_implicitly_has_an_1_type: { code: number; category: DiagnosticCategory; @@ -6981,7 +7003,7 @@ declare namespace ts { function isLiteralComputedPropertyDeclarationName(node: Node): boolean; function isIdentifierName(node: Identifier): boolean; function isAliasSymbolDeclaration(node: Node): boolean; - function getClassExtendsHeritageClauseElement(node: ClassLikeDeclaration): ExpressionWithTypeArguments; + function getClassExtendsHeritageClauseElement(node: ClassLikeDeclaration | InterfaceDeclaration): ExpressionWithTypeArguments; function getClassImplementsHeritageClauseElements(node: ClassLikeDeclaration): NodeArray; function getInterfaceBaseTypeNodes(node: InterfaceDeclaration): NodeArray; function getHeritageClause(clauses: NodeArray, kind: SyntaxKind): HeritageClause; @@ -7688,6 +7710,7 @@ declare namespace ts.formatting { declare namespace ts.formatting { namespace SmartIndenter { function getIndentation(position: number, sourceFile: SourceFile, options: EditorOptions): number; + function getBaseIndentation(options: EditorOptions): number; function getIndentationForNode(n: Node, ignoreActualIndentationRange: TextRange, sourceFile: SourceFile, options: FormatCodeOptions): number; function childStartsOnTheSameLineWithElseInIfStatement(parent: Node, child: TextRangeWithKind, childStartLine: number, sourceFile: SourceFile): boolean; function findFirstNonWhitespaceCharacterAndColumn(startPos: number, endPos: number, sourceFile: SourceFile, options: EditorOptions): { @@ -7826,7 +7849,7 @@ declare namespace ts { getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[]; getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[]; getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion; - isValidBraceCompletionAtPostion(fileName: string, position: number, openingBrace: number): boolean; + isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean; getEmitOutput(fileName: string): EmitOutput; getProgram(): Program; getNonBoundSourceFile(fileName: string): SourceFile; @@ -7904,6 +7927,7 @@ declare namespace ts { containerKind: string; } interface EditorOptions { + BaseIndentSize?: number; IndentSize: number; TabSize: number; NewLineCharacter: string; @@ -7926,7 +7950,7 @@ declare namespace ts { InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; PlaceOpenBraceOnNewLineForFunctions: boolean; PlaceOpenBraceOnNewLineForControlBlocks: boolean; - [s: string]: boolean | number | string; + [s: string]: boolean | number | string | undefined; } interface DefinitionInfo { fileName: string; @@ -8231,6 +8255,8 @@ declare namespace ts.server { const Formatonkey: string; const Geterr: string; const GeterrForProject: string; + const SemanticDiagnosticsSync: string; + const SyntacticDiagnosticsSync: string; const NavBar: string; const Navto: string; const Occurrences: string; @@ -8277,6 +8303,9 @@ declare namespace ts.server { private getDefinition(line, offset, fileName); private getTypeDefinition(line, offset, fileName); private getOccurrences(line, offset, fileName); + private getDiagnosticsWorker(args, selector); + private getSyntacticDiagnosticsSync(args); + private getSemanticDiagnosticsSync(args); private getDocumentHighlights(line, offset, fileName, filesToSearch); private getProjectInfo(fileName, needFileNameList); private getRenameLocations(line, offset, fileName, findInComments, findInStrings); @@ -8300,6 +8329,7 @@ declare namespace ts.server { getDiagnosticsForProject(delay: number, fileName: string): void; getCanonicalFileName(fileName: string): string; exit(): void; + private requiredResponse(response); private handlers; addProtocolHandler(command: string, handler: (request: protocol.Request) => { response?: any; @@ -8731,7 +8761,7 @@ declare namespace ts { getFormattingEditsForDocument(fileName: string, options: string): string; getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: string): string; getDocCommentTemplateAtPosition(fileName: string, position: number): string; - isValidBraceCompletionAtPostion(fileName: string, position: number, openingBrace: number): string; + isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): string; getEmitOutput(fileName: string): string; } interface ClassifierShim extends Shim { diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 22a420c25e4..37ce862d0c1 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -2286,6 +2286,9 @@ var ts; Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, File_name_0_has_a_1_extension_stripping_it: { code: 6132, category: ts.DiagnosticCategory.Message, key: "File_name_0_has_a_1_extension_stripping_it_6132", message: "File name '{0}' has a '{1}' extension - stripping it" }, + _0_is_declared_but_never_used: { code: 6133, category: ts.DiagnosticCategory.Error, key: "_0_is_declared_but_never_used_6133", message: "'{0}' is declared but never used." }, + Report_Errors_on_Unused_Locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Locals_6134", message: "Report Errors on Unused Locals." }, + Report_Errors_on_Unused_Parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Parameters_6135", message: "Report Errors on Unused Parameters." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -3950,6 +3953,16 @@ var ts; type: "boolean", description: ts.Diagnostics.Raise_error_on_this_expressions_with_an_implied_any_type }, + { + name: "noUnusedLocals", + type: "boolean", + description: ts.Diagnostics.Report_Errors_on_Unused_Locals + }, + { + name: "noUnusedParameters", + type: "boolean", + description: ts.Diagnostics.Report_Errors_on_Unused_Parameters + }, { name: "noLib", type: "boolean" @@ -4139,16 +4152,6 @@ var ts; isFilePath: true } }, - { - name: "typesSearchPaths", - type: "list", - isTSConfigOnly: true, - element: { - name: "typesSearchPaths", - type: "string", - isFilePath: true - } - }, { name: "typeRoots", type: "list", @@ -4223,7 +4226,7 @@ var ts; description: ts.Diagnostics.Specify_library_files_to_be_included_in_the_compilation_Colon }, { - name: "disableProjectSizeLimit", + name: "disableSizeLimit", type: "boolean" }, { @@ -9645,8 +9648,11 @@ var ts; if (lhs.kind === 69) { return lhs.text === rhs.text; } - return lhs.right.text === rhs.right.text && - tagNamesAreEquivalent(lhs.left, rhs.left); + if (lhs.kind === 97) { + return true; + } + return lhs.name.text === rhs.name.text && + tagNamesAreEquivalent(lhs.expression, rhs.expression); } function parseJsxElementOrSelfClosingElement(inExpressionContext) { var opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext); @@ -9743,15 +9749,15 @@ var ts; } function parseJsxElementName() { scanJsxIdentifier(); - var elementName = parseIdentifierName(); + var expression = token === 97 ? + parseTokenNode() : parseIdentifierName(); while (parseOptional(21)) { - scanJsxIdentifier(); - var node = createNode(139, elementName.pos); - node.left = elementName; - node.right = parseIdentifierName(); - elementName = finishNode(node); + var propertyAccess = createNode(172, expression.pos); + propertyAccess.expression = expression; + propertyAccess.name = parseRightSideOfDot(true); + expression = finishNode(propertyAccess); } - return elementName; + return expression; } function parseJsxExpression(inExpressionContext) { var node = createNode(248); @@ -10529,7 +10535,7 @@ var ts; case 56: return parseExportAssignment(fullStart, decorators, modifiers); case 116: - return parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers); + return parseNamespaceExportDeclaration(fullStart, decorators, modifiers); default: return parseExportDeclaration(fullStart, decorators, modifiers); } @@ -11043,7 +11049,7 @@ var ts; function nextTokenIsSlash() { return nextToken() === 39; } - function parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers) { + function parseNamespaceExportDeclaration(fullStart, decorators, modifiers) { var exportDeclaration = createNode(228, fullStart); exportDeclaration.decorators = decorators; exportDeclaration.modifiers = modifiers; @@ -14714,7 +14720,7 @@ var ts; function getTargetOfImportSpecifier(node) { return getExternalModuleMember(node.parent.parent.parent, node); } - function getTargetOfGlobalModuleExportDeclaration(node) { + function getTargetOfNamespaceExportDeclaration(node) { return resolveExternalModuleSymbol(node.parent.symbol); } function getTargetOfExportSpecifier(node) { @@ -14740,7 +14746,7 @@ var ts; case 235: return getTargetOfExportAssignment(node); case 228: - return getTargetOfGlobalModuleExportDeclaration(node); + return getTargetOfNamespaceExportDeclaration(node); } } function resolveSymbol(symbol) { @@ -14823,9 +14829,12 @@ var ts; var left = name.kind === 139 ? name.left : name.expression; var right = name.kind === 139 ? name.right : name.name; var namespace = resolveEntityName(left, 1536, ignoreErrors); - if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) { + if (!namespace || ts.nodeIsMissing(right)) { return undefined; } + else if (namespace === unknownSymbol) { + return namespace; + } symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { if (!ignoreErrors) { @@ -15786,16 +15795,13 @@ var ts; writePunctuation(writer, 27); } } - function buildDisplayForParametersAndDelimiters(thisType, parameters, writer, enclosingDeclaration, flags, symbolStack) { + function buildDisplayForParametersAndDelimiters(thisParameter, parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 17); - if (thisType) { - writeKeyword(writer, 97); - writePunctuation(writer, 54); - writeSpace(writer); - buildTypeDisplay(thisType, writer, enclosingDeclaration, flags, symbolStack); + if (thisParameter) { + buildParameterDisplay(thisParameter, writer, enclosingDeclaration, flags, symbolStack); } for (var i = 0; i < parameters.length; i++) { - if (i > 0 || thisType) { + if (i > 0 || thisParameter) { writePunctuation(writer, 24); writeSpace(writer); } @@ -15843,7 +15849,7 @@ var ts; else { buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.thisType, signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildDisplayForParametersAndDelimiters(signature.thisParameter, signature.parameters, writer, enclosingDeclaration, flags, symbolStack); buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { @@ -16174,12 +16180,13 @@ var ts; if (func.kind === 150 && !ts.hasDynamicName(func)) { var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 149); if (getter) { - var signature = getSignatureFromDeclaration(getter); + var getterSignature = getSignatureFromDeclaration(getter); var thisParameter = getAccessorThisParameter(func); if (thisParameter && declaration === thisParameter) { - return signature.thisType; + ts.Debug.assert(!thisParameter.type); + return getTypeOfSymbol(getterSignature.thisParameter); } - return getReturnTypeOfSignature(signature); + return getReturnTypeOfSignature(getterSignature); } } var type = declaration.symbol.name === "this" @@ -16337,14 +16344,12 @@ var ts; } return undefined; } - function getAnnotatedAccessorThisType(accessor) { - if (accessor) { - var parameter = getAccessorThisParameter(accessor); - if (parameter && parameter.type) { - return getTypeFromTypeNode(accessor.parameters[0].type); - } - } - return undefined; + function getAnnotatedAccessorThisParameter(accessor) { + var parameter = getAccessorThisParameter(accessor); + return parameter && parameter.symbol; + } + function getThisTypeOfDeclaration(declaration) { + return getThisTypeOfSignature(getSignatureFromDeclaration(declaration)); } function getTypeOfAccessors(symbol) { var links = getSymbolLinks(symbol); @@ -16924,12 +16929,12 @@ var ts; type.typeArguments : ts.concatenate(type.typeArguments, [type]); resolveObjectTypeMembers(type, source, typeParameters, typeArguments); } - function createSignature(declaration, typeParameters, thisType, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { + function createSignature(declaration, typeParameters, thisParameter, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { var sig = new Signature(checker); sig.declaration = declaration; sig.typeParameters = typeParameters; sig.parameters = parameters; - sig.thisType = thisType; + sig.thisParameter = thisParameter; sig.resolvedReturnType = resolvedReturnType; sig.typePredicate = typePredicate; sig.minArgumentCount = minArgumentCount; @@ -16938,7 +16943,7 @@ var ts; return sig; } function cloneSignature(sig) { - return createSignature(sig.declaration, sig.typeParameters, sig.thisType, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); + return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); } function getDefaultConstructSignatures(classType) { var baseConstructorType = getBaseConstructorTypeOfClass(classType); @@ -17022,8 +17027,9 @@ var ts; var s = signature; if (unionSignatures.length > 1) { s = cloneSignature(signature); - if (ts.forEach(unionSignatures, function (sig) { return sig.thisType; })) { - s.thisType = getUnionType(ts.map(unionSignatures, function (sig) { return sig.thisType || anyType; })); + if (ts.forEach(unionSignatures, function (sig) { return sig.thisParameter; })) { + var thisType = getUnionType(ts.map(unionSignatures, function (sig) { return getTypeOfSymbol(sig.thisParameter) || anyType; })); + s.thisParameter = createTransientSymbol(signature.thisParameter, thisType); } s.resolvedReturnType = undefined; s.unionSignatures = unionSignatures; @@ -17208,6 +17214,7 @@ var ts; var types = containingType.types; var props; var commonFlags = (containingType.flags & 32768) ? 536870912 : 0; + var isReadonly = false; for (var _i = 0, types_2 = types; _i < types_2.length; _i++) { var current = types_2[_i]; var type = getApparentType(current); @@ -17221,6 +17228,9 @@ var ts; else if (!ts.contains(props, prop)) { props.push(prop); } + if (isReadonlySymbol(prop)) { + isReadonly = true; + } } else if (containingType.flags & 16384) { return undefined; @@ -17248,6 +17258,7 @@ var ts; commonFlags, name); result.containingType = containingType; result.declarations = declarations; + result.isReadonly = isReadonly; result.type = containingType.flags & 16384 ? getUnionType(propTypes) : getIntersectionType(propTypes); return result; } @@ -17406,7 +17417,7 @@ var ts; var parameters = []; var hasStringLiterals = false; var minArgumentCount = -1; - var thisType = undefined; + var thisParameter = undefined; var hasThisParameter = void 0; var isJSConstructSignature = ts.isJSDocConstructSignature(declaration); for (var i = isJSConstructSignature ? 1 : 0, n = declaration.parameters.length; i < n; i++) { @@ -17418,7 +17429,7 @@ var ts; } if (i === 0 && paramSymbol.name === "this") { hasThisParameter = true; - thisType = param.type ? getTypeFromTypeNode(param.type) : unknownType; + thisParameter = param.symbol; } else { parameters.push(paramSymbol); @@ -17437,10 +17448,12 @@ var ts; } if ((declaration.kind === 149 || declaration.kind === 150) && !ts.hasDynamicName(declaration) && - (!hasThisParameter || thisType === unknownType)) { + (!hasThisParameter || !thisParameter)) { var otherKind = declaration.kind === 149 ? 150 : 149; - var setter = ts.getDeclarationOfKind(declaration.symbol, otherKind); - thisType = getAnnotatedAccessorThisType(setter); + var other = ts.getDeclarationOfKind(declaration.symbol, otherKind); + if (other) { + thisParameter = getAnnotatedAccessorThisParameter(other); + } } if (minArgumentCount < 0) { minArgumentCount = declaration.parameters.length - (hasThisParameter ? 1 : 0); @@ -17458,7 +17471,7 @@ var ts; var typePredicate = declaration.type && declaration.type.kind === 154 ? createTypePredicateFromTypePredicateNode(declaration.type) : undefined; - links.resolvedSignature = createSignature(declaration, typeParameters, thisType, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); + links.resolvedSignature = createSignature(declaration, typeParameters, thisParameter, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); } return links.resolvedSignature; } @@ -17528,6 +17541,11 @@ var ts; } return anyType; } + function getThisTypeOfSignature(signature) { + if (signature.thisParameter) { + return getTypeOfSymbol(signature.thisParameter); + } + } function getReturnTypeOfSignature(signature) { if (!signature.resolvedReturnType) { if (!pushTypeResolution(signature, 3)) { @@ -18245,7 +18263,7 @@ var ts; if (signature.typePredicate) { freshTypePredicate = cloneTypePredicate(signature.typePredicate, mapper); } - var result = createSignature(signature.declaration, freshTypeParameters, signature.thisType && instantiateType(signature.thisType, mapper), instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); + var result = createSignature(signature.declaration, freshTypeParameters, signature.thisParameter && instantiateSymbol(signature.thisParameter, mapper), instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); result.target = signature; result.mapper = mapper; return result; @@ -18448,16 +18466,20 @@ var ts; source = getErasedSignature(source); target = getErasedSignature(target); var result = -1; - if (source.thisType && target.thisType && source.thisType !== voidType) { - var related = compareTypes(source.thisType, target.thisType, false) - || compareTypes(target.thisType, source.thisType, reportErrors); - if (!related) { - if (reportErrors) { - errorReporter(ts.Diagnostics.The_this_types_of_each_signature_are_incompatible); + var sourceThisType = getThisTypeOfSignature(source); + if (sourceThisType && sourceThisType !== voidType) { + var targetThisType = getThisTypeOfSignature(target); + if (targetThisType) { + var related = compareTypes(sourceThisType, targetThisType, false) + || compareTypes(targetThisType, sourceThisType, reportErrors); + if (!related) { + if (reportErrors) { + errorReporter(ts.Diagnostics.The_this_types_of_each_signature_are_incompatible); + } + return 0; } - return 0; + result &= related; } - result &= related; } var sourceMax = getNumNonRestParameters(source); var targetMax = getNumNonRestParameters(target); @@ -19275,12 +19297,18 @@ var ts; source = getErasedSignature(source); target = getErasedSignature(target); var result = -1; - if (!ignoreThisTypes && source.thisType && target.thisType) { - var related = compareTypes(source.thisType, target.thisType); - if (!related) { - return 0; + if (!ignoreThisTypes) { + var sourceThisType = getThisTypeOfSignature(source); + if (sourceThisType) { + var targetThisType = getThisTypeOfSignature(target); + if (targetThisType) { + var related = compareTypes(sourceThisType, targetThisType); + if (!related) { + return 0; + } + result &= related; + } } - result &= related; } var targetLen = target.parameters.length; for (var i = 0; i < targetLen; i++) { @@ -20543,8 +20571,20 @@ var ts; } return container === declarationContainer; } + function updateReferencesForInterfaceHeritiageClauseTargets(node) { + var extendedTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (extendedTypeNode) { + var t = getTypeFromTypeNode(extendedTypeNode); + if (t !== unknownType && t.symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + t.symbol.hasReference = true; + } + } + } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); + if (symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + symbol.hasReference = true; + } if (symbol === argumentsSymbol) { var container = ts.getContainingFunction(node); if (container.kind === 180) { @@ -20754,9 +20794,9 @@ var ts; if (type) { return type; } - var signature = getSignatureFromDeclaration(container); - if (signature.thisType) { - return signature.thisType; + var thisType = getThisTypeOfDeclaration(container); + if (thisType) { + return thisType; } } if (ts.isClassLike(container.parent)) { @@ -20899,7 +20939,7 @@ var ts; if (isContextSensitiveFunctionOrObjectLiteralMethod(func) && func.kind !== 180) { var contextualSignature = getContextualSignature(func); if (contextualSignature) { - return contextualSignature.thisType; + return getThisTypeOfSignature(contextualSignature); } } return undefined; @@ -21481,7 +21521,7 @@ var ts; return name.indexOf("-") < 0; } function isJsxIntrinsicIdentifier(tagName) { - if (tagName.kind === 139) { + if (tagName.kind === 172 || tagName.kind === 97) { return false; } else { @@ -21617,6 +21657,25 @@ var ts; return getResolvedJsxType(node, type, elemClassType); })); } + if (elemType.flags & 2) { + return anyType; + } + else if (elemType.flags & 256) { + var intrinsicElementsType = getJsxType(JsxNames.IntrinsicElements); + if (intrinsicElementsType !== unknownType) { + var stringLiteralTypeName = elemType.text; + var intrinsicProp = getPropertyOfType(intrinsicElementsType, stringLiteralTypeName); + if (intrinsicProp) { + return getTypeOfSymbol(intrinsicProp); + } + var indexSignatureType = getIndexTypeOfType(intrinsicElementsType, 0); + if (indexSignatureType) { + return indexSignatureType; + } + error(node, ts.Diagnostics.Property_0_does_not_exist_on_type_1, stringLiteralTypeName, "JSX." + JsxNames.IntrinsicElements); + } + return anyType; + } var elemInstanceType = getJsxElementInstanceType(node, elemType); if (!elemClassType || !isTypeAssignableTo(elemInstanceType, elemClassType)) { if (jsxElementType) { @@ -21861,6 +21920,9 @@ var ts; } return unknownType; } + if ((compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + prop.hasReference = true; + } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & 32) { checkClassPropertyAccess(node, left, apparentType, prop); @@ -22173,10 +22235,11 @@ var ts; if (context.failedTypeParameterIndex !== undefined && !context.inferences[context.failedTypeParameterIndex].isFixed) { context.failedTypeParameterIndex = undefined; } - if (signature.thisType) { + var thisType = getThisTypeOfSignature(signature); + if (thisType) { var thisArgumentNode = getThisArgumentOfCall(node); var thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType; - inferTypes(context, thisArgumentType, signature.thisType); + inferTypes(context, thisArgumentType, thisType); } var argCount = getEffectiveArgumentCount(node, args, signature); for (var i = 0; i < argCount; i++) { @@ -22227,12 +22290,13 @@ var ts; return typeArgumentsAreAssignable; } function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) { - if (signature.thisType && signature.thisType !== voidType && node.kind !== 175) { + var thisType = getThisTypeOfSignature(signature); + if (thisType && thisType !== voidType && node.kind !== 175) { var thisArgumentNode = getThisArgumentOfCall(node); var thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType; var errorNode = reportErrors ? (thisArgumentNode || node) : undefined; var headMessage_1 = ts.Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1; - if (!checkTypeRelatedTo(thisArgumentType, signature.thisType, relation, errorNode, headMessage_1)) { + if (!checkTypeRelatedTo(thisArgumentType, getThisTypeOfSignature(signature), relation, errorNode, headMessage_1)) { return false; } } @@ -22648,7 +22712,7 @@ var ts; if (getReturnTypeOfSignature(signature) !== voidType) { error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } - if (signature.thisType === voidType) { + if (getThisTypeOfSignature(signature) === voidType) { error(node, ts.Diagnostics.A_function_that_is_called_with_the_new_keyword_cannot_have_a_this_type_that_is_void); } return signature; @@ -23128,6 +23192,8 @@ var ts; } } } + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); } } function checkArithmeticOperandType(operand, type, diagnostic) { @@ -23138,7 +23204,8 @@ var ts; return true; } function isReadonlySymbol(symbol) { - return symbol.flags & 4 && (getDeclarationFlagsFromSymbol(symbol) & 64) !== 0 || + return symbol.isReadonly || + symbol.flags & 4 && (getDeclarationFlagsFromSymbol(symbol) & 64) !== 0 || symbol.flags & 3 && (getDeclarationFlagsFromSymbol(symbol) & 2048) !== 0 || symbol.flags & 98304 && !(symbol.flags & 65536) || (symbol.flags & 8) !== 0; @@ -23973,6 +24040,9 @@ var ts; checkAsyncFunctionReturnType(node); } } + if (!node.body) { + checkUnusedTypeParameters(node); + } } } function checkClassForDuplicateDeclarations(node) { @@ -24100,6 +24170,8 @@ var ts; checkSignatureDeclaration(node); checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node); checkSourceElement(node.body); + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); var symbol = getSymbolOfNode(node); var firstDeclaration = ts.getDeclarationOfKind(symbol, node.kind); if (node === firstDeclaration) { @@ -24203,7 +24275,7 @@ var ts; error(node.name, ts.Diagnostics.Accessors_must_both_be_abstract_or_non_abstract); } checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorType, ts.Diagnostics.get_and_set_accessor_must_have_the_same_type); - checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorThisType, ts.Diagnostics.get_and_set_accessor_must_have_the_same_this_type); + checkAccessorDeclarationTypesIdentical(node, otherAccessor, getThisTypeOfDeclaration, ts.Diagnostics.get_and_set_accessor_must_have_the_same_this_type); } } getTypeOfAccessors(getSymbolOfNode(node)); @@ -24248,12 +24320,17 @@ var ts; function checkTypeReferenceNode(node) { checkGrammarTypeArguments(node, node.typeArguments); var type = getTypeFromTypeReference(node); - if (type !== unknownType && node.typeArguments) { - ts.forEach(node.typeArguments, checkSourceElement); - if (produceDiagnostics) { - var symbol = getNodeLinks(node).resolvedSymbol; - var typeParameters = symbol.flags & 524288 ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; - checkTypeArgumentConstraints(typeParameters, node.typeArguments); + if (type !== unknownType) { + if (type.symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + type.symbol.hasReference = true; + } + if (node.typeArguments) { + ts.forEach(node.typeArguments, checkSourceElement); + if (produceDiagnostics) { + var symbol = getNodeLinks(node).resolvedSymbol; + var typeParameters = symbol.flags & 524288 ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; + checkTypeArgumentConstraints(typeParameters, node.typeArguments); + } } } } @@ -24783,6 +24860,8 @@ var ts; } } checkSourceElement(node.body); + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); if (!node.asteriskToken) { var returnOrPromisedType = node.type && (isAsync ? checkAsyncFunctionReturnType(node) : getTypeFromTypeNode(node.type)); checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnOrPromisedType); @@ -24796,11 +24875,83 @@ var ts; } } } + function checkUnusedIdentifiers(node) { + if (node.parent.kind !== 222 && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + for (var key in node.locals) { + if (ts.hasProperty(node.locals, key)) { + var local = node.locals[key]; + if (!local.hasReference && local.valueDeclaration) { + if (local.valueDeclaration.kind !== 142 && compilerOptions.noUnusedLocals) { + error(local.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local.name); + } + else if (local.valueDeclaration.kind === 142 && compilerOptions.noUnusedParameters) { + if (local.valueDeclaration.flags === 0) { + error(local.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local.name); + } + } + } + } + } + } + } + function checkUnusedClassLocals(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + if (node.members) { + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 147 || member.kind === 145) { + if (isPrivateNode(member) && !member.symbol.hasReference) { + error(member.name, ts.Diagnostics._0_is_declared_but_never_used, member.symbol.name); + } + } + else if (member.kind === 148) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var parameter = _c[_b]; + if (isPrivateNode(parameter) && !parameter.symbol.hasReference) { + error(parameter.name, ts.Diagnostics._0_is_declared_but_never_used, parameter.symbol.name); + } + } + } + } + } + } + } + function checkUnusedTypeParameters(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + if (node.typeParameters) { + for (var _i = 0, _a = node.typeParameters; _i < _a.length; _i++) { + var typeParameter = _a[_i]; + if (!typeParameter.symbol.hasReference) { + error(typeParameter.name, ts.Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name); + } + } + } + } + } + function isPrivateNode(node) { + return (node.flags & 8) !== 0; + } + function checkUnusedModuleLocals(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + var _loop_1 = function(key) { + if (ts.hasProperty(node.locals, key)) { + var local_1 = node.locals[key]; + if (!local_1.hasReference && !local_1.exportSymbol) { + ts.forEach(local_1.declarations, function (d) { return error(d.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); }); + } + } + }; + for (var key in node.locals) { + _loop_1(key); + } + } + } function checkBlock(node) { if (node.kind === 199) { checkGrammarStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); + checkUnusedIdentifiers(node); } function checkCollisionWithArgumentsInGeneratedCode(node) { if (!ts.hasDeclaredRestParameter(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { @@ -25146,6 +25297,7 @@ var ts; } } checkSourceElement(node.statement); + checkUnusedIdentifiers(node); } function checkForInStatement(node) { checkGrammarForInOrForOfStatement(node); @@ -25174,6 +25326,7 @@ var ts; error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); + checkUnusedIdentifiers(node); } function checkForInOrForOfVariableDeclaration(iterationStatement) { var variableDeclarationList = iterationStatement.initializer; @@ -25470,6 +25623,7 @@ var ts; } } checkBlock(catchClause.block); + checkUnusedIdentifiers(catchClause); } if (node.finallyBlock) { checkBlock(node.finallyBlock); @@ -25592,6 +25746,8 @@ var ts; } checkClassLikeDeclaration(node); ts.forEach(node.members, checkSourceElement); + checkUnusedClassLocals(node); + checkUnusedTypeParameters(node); } function checkClassLikeDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); @@ -25832,6 +25988,8 @@ var ts; ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); + updateReferencesForInterfaceHeritiageClauseTargets(node); + checkUnusedTypeParameters(node); } } function checkTypeAliasDeclaration(node) { @@ -26151,6 +26309,7 @@ var ts; } if (node.body) { checkSourceElement(node.body); + checkUnusedModuleLocals(node); } } function checkModuleAugmentationElement(node, isGlobalAugmentation) { @@ -26301,6 +26460,9 @@ var ts; if (target.flags & 793056) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); } + if ((compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + target.hasReference = true; + } } } else { @@ -26588,6 +26750,9 @@ var ts; potentialThisCollisions.length = 0; deferredNodes = []; ts.forEach(node.statements, checkSourceElement); + if (ts.isExternalModule(node)) { + checkUnusedModuleLocals(node); + } checkDeferredNodes(); deferredNodes = undefined; if (ts.isExternalOrCommonJsModule(node)) { @@ -26876,6 +27041,13 @@ var ts; case 139: return getSymbolOfEntityNameOrPropertyAccessExpression(node); case 97: + var container = ts.getThisContainer(node, false); + if (ts.isFunctionLike(container)) { + var sig = getSignatureFromDeclaration(container); + if (sig.thisParameter) { + return sig.thisParameter; + } + } case 95: var type = ts.isExpression(node) ? checkExpression(node) : getTypeFromTypeNode(node); return type.symbol; @@ -27064,7 +27236,9 @@ var ts; var parentSymbol = getParentOfSymbol(symbol); if (parentSymbol) { if (parentSymbol.flags & 512 && parentSymbol.valueDeclaration.kind === 256) { - return parentSymbol.valueDeclaration; + if (parentSymbol.valueDeclaration === ts.getSourceFileOfNode(node)) { + return parentSymbol.valueDeclaration; + } } for (var n = node.parent; n; n = n.parent) { if ((n.kind === 225 || n.kind === 224) && getSymbolOfNode(n) === parentSymbol) { @@ -27957,7 +28131,7 @@ var ts; var GetAccessor = 2; var SetAccessor = 4; var GetOrSetAccessor = GetAccessor | SetAccessor; - var _loop_1 = function(prop) { + var _loop_2 = function(prop) { var name_22 = prop.name; if (prop.kind === 193 || name_22.kind === 140) { @@ -28018,8 +28192,8 @@ var ts; }; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var state_2 = _loop_1(prop); - if (typeof state_2 === "object") return state_2.value; + var state_3 = _loop_2(prop); + if (typeof state_3 === "object") return state_3.value; } } function checkGrammarJsxElement(node) { @@ -30649,6 +30823,8 @@ var ts; return generateNameForExportDefault(); case 192: return generateNameForClassExpression(); + default: + ts.Debug.fail(); } } function getGeneratedNameForNode(node) { @@ -31346,6 +31522,20 @@ var ts; } return false; } + function getClassExpressionInPropertyAccessInStaticPropertyDeclaration(node) { + if (languageVersion >= 2) { + var parent_14 = node.parent; + if (parent_14.kind === 172 && parent_14.expression === node) { + parent_14 = parent_14.parent; + while (parent_14 && parent_14.kind !== 145) { + parent_14 = parent_14.parent; + } + return parent_14 && parent_14.kind === 145 && (parent_14.flags & 32) !== 0 && + parent_14.parent.kind === 192 ? parent_14.parent : undefined; + } + } + return undefined; + } function emitIdentifier(node) { if (convertedLoopState) { if (node.text == "arguments" && resolver.isArgumentsLocalBinding(node)) { @@ -31358,6 +31548,14 @@ var ts; write(node.text); } else if (isExpressionIdentifier(node)) { + var classExpression = getClassExpressionInPropertyAccessInStaticPropertyDeclaration(node); + if (classExpression) { + var declaration = resolver.getReferencedValueDeclaration(node); + if (declaration === classExpression) { + write(getGeneratedNameForNode(declaration.name)); + return; + } + } emitExpressionIdentifier(node); } else if (isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(node)) { @@ -33897,7 +34095,7 @@ var ts; emitStart(property); emitStart(property.name); if (receiver) { - emit(receiver); + write(receiver); } else { if (property.flags & 32) { @@ -34180,12 +34378,15 @@ var ts; } var staticProperties = getInitializedProperties(node, true); var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 192; - var tempVariable; + var generatedName; if (isClassExpressionWithStaticProperties) { - tempVariable = createAndRecordTempVariable(0); + generatedName = getGeneratedNameForNode(node.name); + var synthesizedNode = ts.createSynthesizedNode(69); + synthesizedNode.text = generatedName; + recordTempDeclaration(synthesizedNode); write("("); increaseIndent(); - emit(tempVariable); + emit(synthesizedNode); write(" = "); } write("class"); @@ -34225,11 +34426,11 @@ var ts; var property = staticProperties_1[_a]; write(","); writeLine(); - emitPropertyDeclaration(node, property, tempVariable, true); + emitPropertyDeclaration(node, property, generatedName, true); } write(","); writeLine(); - emit(tempVariable); + write(generatedName); decreaseIndent(); write(")"); } @@ -36407,7 +36608,7 @@ var ts; ts.emitTime = 0; ts.ioReadTime = 0; ts.ioWriteTime = 0; - ts.version = "1.9.0"; + ts.version = "2.0.0"; var emptyArray = []; var defaultTypeRoots = ["node_modules/@types"]; function findConfigFile(searchPath, fileExists) { @@ -38689,24 +38890,24 @@ var ts; switch (n.kind) { case 199: if (!ts.isFunctionBlock(n)) { - var parent_14 = n.parent; + var parent_15 = n.parent; var openBrace = ts.findChildOfKind(n, 15, sourceFile); var closeBrace = ts.findChildOfKind(n, 16, sourceFile); - if (parent_14.kind === 204 || - parent_14.kind === 207 || - parent_14.kind === 208 || - parent_14.kind === 206 || - parent_14.kind === 203 || - parent_14.kind === 205 || - parent_14.kind === 212 || - parent_14.kind === 252) { - addOutliningSpan(parent_14, openBrace, closeBrace, autoCollapse(n)); + if (parent_15.kind === 204 || + parent_15.kind === 207 || + parent_15.kind === 208 || + parent_15.kind === 206 || + parent_15.kind === 203 || + parent_15.kind === 205 || + parent_15.kind === 212 || + parent_15.kind === 252) { + addOutliningSpan(parent_15, openBrace, closeBrace, autoCollapse(n)); break; } - if (parent_14.kind === 216) { - var tryStatement = parent_14; + if (parent_15.kind === 216) { + var tryStatement = parent_15; if (tryStatement.tryBlock === n) { - addOutliningSpan(parent_14, openBrace, closeBrace, autoCollapse(n)); + addOutliningSpan(parent_15, openBrace, closeBrace, autoCollapse(n)); break; } else if (tryStatement.finallyBlock === n) { @@ -40114,7 +40315,7 @@ var ts; signatureHelpParameters = typeParameters && typeParameters.length > 0 ? ts.map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; suffixDisplayParts.push(ts.punctuationPart(27)); var parameterParts = ts.mapToDisplayParts(function (writer) { - return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.thisType, candidateSignature.parameters, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.thisParameter, candidateSignature.parameters, writer, invocation); }); ts.addRange(suffixDisplayParts, parameterParts); } @@ -40228,6 +40429,8 @@ var ts; case 199: case 226: case 227: + case 233: + case 237: return nodeEndsWith(n, 16, sourceFile); case 252: return isCompletedNode(n.block, sourceFile); @@ -40310,6 +40513,9 @@ var ts; return isCompletedNode(lastSpan, sourceFile); case 197: return ts.nodeIsPresent(n.literal); + case 236: + case 230: + return ts.nodeIsPresent(n.moduleSpecifier); case 185: return isCompletedNode(n.operand, sourceFile); case 187: @@ -41505,7 +41711,7 @@ var ts; this.NoSpaceAfterCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create3(20, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), 8)); this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); - this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([69, 3, 73]); + this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([69, 3, 73, 82, 89]); this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18, 3, 79, 100, 85, 80]); this.SpaceBeforeOpenBraceInControl = new formatting.Rule(formatting.RuleDescriptor.create2(this.ControlOpenBraceLeftTokenRange, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsControlDeclContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); @@ -41540,8 +41746,8 @@ var ts; this.SpaceAfterBinaryKeywordOperator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.BinaryKeywordOperators, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsBinaryOpContext), 2)); this.NoSpaceAfterConstructor = new formatting.Rule(formatting.RuleDescriptor.create1(121, 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8)); this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([125, 129]), 17), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8)); - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([115, 73, 122, 77, 81, 82, 83, 123, 106, 89, 107, 125, 126, 110, 112, 111, 131, 113, 134]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([83, 106])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([115, 73, 122, 77, 81, 82, 83, 123, 106, 89, 107, 125, 126, 110, 112, 111, 131, 113, 134, 136]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([83, 106, 136])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(9, 15), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2)); this.SpaceBeforeArrow = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 34), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); this.SpaceAfterArrow = new formatting.Rule(formatting.RuleDescriptor.create3(34, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2)); @@ -41667,6 +41873,8 @@ var ts; case 187: case 188: case 195: + case 238: + case 234: case 154: case 162: case 163: @@ -41754,6 +41962,10 @@ var ts; case 224: case 159: case 225: + case 236: + case 237: + case 230: + case 233: return true; } return false; @@ -42445,7 +42657,8 @@ var ts; var startLinePosition = ts.getLineStartPositionForPosition(startPos, sourceFile); var column = formatting.SmartIndenter.findFirstNonWhitespaceColumn(startLinePosition, startPos, sourceFile, options); if (startLine !== parentStartLine || startPos === column) { - return column; + var baseIndentSize = formatting.SmartIndenter.getBaseIndentation(options); + return baseIndentSize > column ? baseIndentSize : column; } } return -1; @@ -43006,14 +43219,14 @@ var ts; (function (SmartIndenter) { function getIndentation(position, sourceFile, options) { if (position > sourceFile.text.length) { - return 0; + return getBaseIndentation(options); } if (options.IndentStyle === ts.IndentStyle.None) { return 0; } var precedingToken = ts.findPrecedingToken(position, sourceFile); if (!precedingToken) { - return 0; + return getBaseIndentation(options); } var precedingTokenIsLiteral = ts.isStringOrRegularExpressionOrTemplateLiteral(precedingToken.kind); if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) { @@ -43065,11 +43278,15 @@ var ts; current = current.parent; } if (!current) { - return 0; + return getBaseIndentation(options); } return getIndentationForNodeWorker(current, currentStart, undefined, indentationDelta, sourceFile, options); } SmartIndenter.getIndentation = getIndentation; + function getBaseIndentation(options) { + return options.BaseIndentSize || 0; + } + SmartIndenter.getBaseIndentation = getBaseIndentation; function getIndentationForNode(n, ignoreActualIndentationRange, sourceFile, options) { var start = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)); return getIndentationForNodeWorker(n, start, ignoreActualIndentationRange, 0, sourceFile, options); @@ -43110,7 +43327,7 @@ var ts; currentStart = parentStart; parent = current.parent; } - return indentationDelta; + return indentationDelta + getBaseIndentation(options); } function getParentStart(parent, child, sourceFile) { var containingList = getContainingList(child, sourceFile); @@ -43336,7 +43553,10 @@ var ts; case 164: case 176: case 184: + case 237: case 233: + case 238: + case 234: return true; } return false; @@ -43358,6 +43578,11 @@ var ts; case 149: case 150: return childKind !== 199; + case 236: + return childKind !== 237; + case 230: + return childKind !== 231 || + child.namedBindings.kind !== 233; case 241: return childKind !== 245; } @@ -44211,8 +44436,8 @@ var ts; if (declaration.kind !== 218 && declaration.kind !== 220) { return false; } - for (var parent_15 = declaration.parent; !ts.isFunctionBlock(parent_15); parent_15 = parent_15.parent) { - if (parent_15.kind === 256 || parent_15.kind === 226) { + for (var parent_16 = declaration.parent; !ts.isFunctionBlock(parent_16); parent_16 = parent_16.parent) { + if (parent_16.kind === 256 || parent_16.kind === 226) { return false; } } @@ -44329,7 +44554,7 @@ var ts; return typeof o.type === "object" && !ts.forEachValue(o.type, function (v) { return typeof v !== "number"; }); }); options = ts.clone(options); - var _loop_2 = function(opt) { + var _loop_3 = function(opt) { if (!ts.hasProperty(options, opt.name)) { return "continue"; } @@ -44345,7 +44570,7 @@ var ts; }; for (var _i = 0, commandLineOptionsStringToEnum_1 = commandLineOptionsStringToEnum; _i < commandLineOptionsStringToEnum_1.length; _i++) { var opt = commandLineOptionsStringToEnum_1[_i]; - _loop_2(opt); + _loop_3(opt); } return options; } @@ -45326,13 +45551,13 @@ var ts; log("Returning an empty list because completion was requested in an invalid position."); return undefined; } - var parent_16 = contextToken.parent, kind = contextToken.kind; + var parent_17 = contextToken.parent, kind = contextToken.kind; if (kind === 21) { - if (parent_16.kind === 172) { + if (parent_17.kind === 172) { node = contextToken.parent.expression; isRightOfDot = true; } - else if (parent_16.kind === 139) { + else if (parent_17.kind === 139) { node = contextToken.parent.left; isRightOfDot = true; } @@ -45620,9 +45845,9 @@ var ts; switch (contextToken.kind) { case 15: case 24: - var parent_17 = contextToken.parent; - if (parent_17 && (parent_17.kind === 171 || parent_17.kind === 167)) { - return parent_17; + var parent_18 = contextToken.parent; + if (parent_18 && (parent_18.kind === 171 || parent_18.kind === 167)) { + return parent_18; } break; } @@ -45645,34 +45870,34 @@ var ts; } function tryGetContainingJsxElement(contextToken) { if (contextToken) { - var parent_18 = contextToken.parent; + var parent_19 = contextToken.parent; switch (contextToken.kind) { case 26: case 39: case 69: case 246: case 247: - if (parent_18 && (parent_18.kind === 242 || parent_18.kind === 243)) { - return parent_18; + if (parent_19 && (parent_19.kind === 242 || parent_19.kind === 243)) { + return parent_19; } - else if (parent_18.kind === 246) { - return parent_18.parent; + else if (parent_19.kind === 246) { + return parent_19.parent; } break; case 9: - if (parent_18 && ((parent_18.kind === 246) || (parent_18.kind === 247))) { - return parent_18.parent; + if (parent_19 && ((parent_19.kind === 246) || (parent_19.kind === 247))) { + return parent_19.parent; } break; case 16: - if (parent_18 && - parent_18.kind === 248 && - parent_18.parent && - (parent_18.parent.kind === 246)) { - return parent_18.parent.parent; + if (parent_19 && + parent_19.kind === 248 && + parent_19.parent && + (parent_19.parent.kind === 246)) { + return parent_19.parent.parent; } - if (parent_18 && parent_18.kind === 247) { - return parent_18.parent; + if (parent_19 && parent_19.kind === 247) { + return parent_19.parent; } break; } @@ -46873,17 +47098,17 @@ var ts; function getThrowStatementOwner(throwStatement) { var child = throwStatement; while (child.parent) { - var parent_19 = child.parent; - if (ts.isFunctionBlock(parent_19) || parent_19.kind === 256) { - return parent_19; + var parent_20 = child.parent; + if (ts.isFunctionBlock(parent_20) || parent_20.kind === 256) { + return parent_20; } - if (parent_19.kind === 216) { - var tryStatement = parent_19; + if (parent_20.kind === 216) { + var tryStatement = parent_20; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; } } - child = parent_19; + child = parent_20; } return undefined; } @@ -47241,13 +47466,27 @@ var ts; if (node === sourceFile) { return undefined; } - if (node.kind !== 69 && - node.kind !== 9 && - !isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { - return undefined; + switch (node.kind) { + case 8: + if (!isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { + break; + } + case 69: + case 97: + case 9: + return getReferencedSymbolsForNode(node, program.getSourceFiles(), findInStrings, findInComments); + } + return undefined; + } + function isThis(node) { + switch (node.kind) { + case 97: + return true; + case 69: + return node.originalKeywordKind === 97 && node.parent.kind === 142; + default: + return false; } - ts.Debug.assert(node.kind === 69 || node.kind === 8 || node.kind === 9); - return getReferencedSymbolsForNode(node, program.getSourceFiles(), findInStrings, findInComments); } function getReferencedSymbolsForNode(node, sourceFiles, findInStrings, findInComments) { var typeChecker = program.getTypeChecker(); @@ -47260,7 +47499,7 @@ var ts; return getLabelReferencesInNode(node.parent, node); } } - if (node.kind === 97 || node.kind === 165) { + if (isThis(node)) { return getReferencesForThisKeyword(node, sourceFiles); } if (node.kind === 95) { @@ -47625,7 +47864,7 @@ var ts; ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); var node = ts.getTouchingWord(sourceFile, position); - if (!node || (node.kind !== 97 && node.kind !== 165)) { + if (!node || !isThis(node)) { return; } var container = ts.getThisContainer(node, false); @@ -48465,8 +48704,8 @@ var ts; return; case 142: if (token.parent.name === token) { - var isThis = token.kind === 69 && token.originalKeywordKind === 97; - return isThis ? 3 : 17; + var isThis_1 = token.kind === 69 && token.originalKeywordKind === 97; + return isThis_1 ? 3 : 17; } return; } @@ -48616,7 +48855,7 @@ var ts; (tokenStart === position ? newLine + indentationStr : ""); return { newText: result, caretOffset: preamble.length }; } - function isValidBraceCompletionAtPostion(fileName, position, openingBrace) { + function isValidBraceCompletionAtPosition(fileName, position, openingBrace) { if (openingBrace === 60) { return false; } @@ -48741,7 +48980,8 @@ var ts; if (node) { if (node.kind === 69 || node.kind === 9 || - isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { + isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || + isThis(node)) { var symbol = typeChecker.getSymbolAtLocation(node); if (symbol) { var declarations = symbol.getDeclarations(); @@ -48852,7 +49092,7 @@ var ts; getFormattingEditsForDocument: getFormattingEditsForDocument, getFormattingEditsAfterKeystroke: getFormattingEditsAfterKeystroke, getDocCommentTemplateAtPosition: getDocCommentTemplateAtPosition, - isValidBraceCompletionAtPostion: isValidBraceCompletionAtPostion, + isValidBraceCompletionAtPosition: isValidBraceCompletionAtPosition, getEmitOutput: getEmitOutput, getNonBoundSourceFile: getNonBoundSourceFile, getProgram: getProgram @@ -49347,6 +49587,8 @@ var ts; CommandNames.Formatonkey = "formatonkey"; CommandNames.Geterr = "geterr"; CommandNames.GeterrForProject = "geterrForProject"; + CommandNames.SemanticDiagnosticsSync = "semanticDiagnosticsSync"; + CommandNames.SyntacticDiagnosticsSync = "syntacticDiagnosticsSync"; CommandNames.NavBar = "navbar"; CommandNames.Navto = "navto"; CommandNames.Occurrences = "occurrences"; @@ -49366,6 +49608,7 @@ var ts; var Errors; (function (Errors) { Errors.NoProject = new Error("No Project."); + Errors.ProjectLanguageServiceDisabled = new Error("The project's language service is disabled."); })(Errors || (Errors = {})); var Session = (function () { function Session(host, byteLength, hrtime, logger) { @@ -49442,6 +49685,12 @@ var ts; var signatureHelpArgs = request.arguments; return { response: _this.getSignatureHelpItems(signatureHelpArgs.line, signatureHelpArgs.offset, signatureHelpArgs.file), responseRequired: true }; }, + _a[CommandNames.SemanticDiagnosticsSync] = function (request) { + return _this.requiredResponse(_this.getSemanticDiagnosticsSync(request.arguments)); + }, + _a[CommandNames.SyntacticDiagnosticsSync] = function (request) { + return _this.requiredResponse(_this.getSyntacticDiagnosticsSync(request.arguments)); + }, _a[CommandNames.Geterr] = function (request) { var geterrArgs = request.arguments; return { response: _this.getDiagnostics(geterrArgs.delay, geterrArgs.files), responseRequired: false }; @@ -49720,6 +49969,24 @@ var ts; }; }); }; + Session.prototype.getDiagnosticsWorker = function (args, selector) { + var file = ts.normalizePath(args.file); + var project = this.projectService.getProjectForFile(file); + if (!project) { + throw Errors.NoProject; + } + if (project.languageServiceDiabled) { + throw Errors.ProjectLanguageServiceDisabled; + } + var diagnostics = selector(project, file); + return ts.map(diagnostics, function (originalDiagnostic) { return formatDiag(file, project, originalDiagnostic); }); + }; + Session.prototype.getSyntacticDiagnosticsSync = function (args) { + return this.getDiagnosticsWorker(args, function (project, file) { return project.compilerService.languageService.getSyntacticDiagnostics(file); }); + }; + Session.prototype.getSemanticDiagnosticsSync = function (args) { + return this.getDiagnosticsWorker(args, function (project, file) { return project.compilerService.languageService.getSemanticDiagnostics(file); }); + }; Session.prototype.getDocumentHighlights = function (line, offset, fileName, filesToSearch) { fileName = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(fileName); @@ -49954,6 +50221,7 @@ var ts; var lineText = lineInfo.leaf.text; if (lineText.search("\\S") < 0) { var editorOptions = { + BaseIndentSize: formatOptions.BaseIndentSize, IndentSize: formatOptions.IndentSize, TabSize: formatOptions.TabSize, NewLineCharacter: formatOptions.NewLineCharacter, @@ -50257,6 +50525,9 @@ var ts; }; Session.prototype.exit = function () { }; + Session.prototype.requiredResponse = function (response) { + return { response: response, responseRequired: true }; + }; Session.prototype.addProtocolHandler = function (command, handler) { if (this.handlers[command]) { throw new Error("Protocol handler already exists for command \"" + command + "\""); @@ -51511,6 +51782,7 @@ var ts; }; CompilerService.getDefaultFormatCodeOptions = function (host) { return ts.clone({ + BaseIndentSize: 0, IndentSize: 4, TabSize: 4, NewLineCharacter: host.newLine || "\n", @@ -52736,9 +53008,9 @@ var ts; var _this = this; return this.forwardJSONCall("getBraceMatchingAtPosition('" + fileName + "', " + position + ")", function () { return _this.languageService.getBraceMatchingAtPosition(fileName, position); }); }; - LanguageServiceShimObject.prototype.isValidBraceCompletionAtPostion = function (fileName, position, openingBrace) { + LanguageServiceShimObject.prototype.isValidBraceCompletionAtPosition = function (fileName, position, openingBrace) { var _this = this; - return this.forwardJSONCall("isValidBraceCompletionAtPostion('" + fileName + "', " + position + ", " + openingBrace + ")", function () { return _this.languageService.isValidBraceCompletionAtPostion(fileName, position, openingBrace); }); + return this.forwardJSONCall("isValidBraceCompletionAtPosition('" + fileName + "', " + position + ", " + openingBrace + ")", function () { return _this.languageService.isValidBraceCompletionAtPosition(fileName, position, openingBrace); }); }; LanguageServiceShimObject.prototype.getIndentationAtPosition = function (fileName, position, options) { var _this = this; diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index 73bf72e135e..c1a94516b6f 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -753,9 +753,10 @@ declare namespace ts { children: NodeArray; closingElement: JsxClosingElement; } + type JsxTagNameExpression = PrimaryExpression | PropertyAccessExpression; interface JsxOpeningElement extends Expression { _openingElementBrand?: any; - tagName: EntityName; + tagName: JsxTagNameExpression; attributes: NodeArray; } interface JsxSelfClosingElement extends PrimaryExpression, JsxOpeningElement { @@ -770,7 +771,7 @@ declare namespace ts { expression: Expression; } interface JsxClosingElement extends Node { - tagName: EntityName; + tagName: JsxTagNameExpression; } interface JsxExpression extends Expression { expression?: Expression; @@ -1271,7 +1272,7 @@ declare namespace ts { buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildTypePredicateDisplay(predicate: TypePredicate, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; - buildDisplayForParametersAndDelimiters(thisType: Type, parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildDisplayForParametersAndDelimiters(thisParameter: Symbol, parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; } @@ -1483,7 +1484,6 @@ declare namespace ts { declaration: SignatureDeclaration; typeParameters: TypeParameter[]; parameters: Symbol[]; - thisType?: Type; } enum IndexKind { String = 0, @@ -1564,6 +1564,8 @@ declare namespace ts { noImplicitAny?: boolean; noImplicitReturns?: boolean; noImplicitThis?: boolean; + noUnusedLocals?: boolean; + noUnusedParameters?: boolean; noImplicitUseStrict?: boolean; noLib?: boolean; noResolve?: boolean; @@ -1590,7 +1592,6 @@ declare namespace ts { types?: string[]; /** Paths used to used to compute primary types search locations */ typeRoots?: string[]; - typesSearchPaths?: string[]; [option: string]: CompilerOptionsValue | undefined; } interface TypingOptions { @@ -2055,7 +2056,7 @@ declare namespace ts { getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[]; getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[]; getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion; - isValidBraceCompletionAtPostion(fileName: string, position: number, openingBrace: number): boolean; + isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean; getEmitOutput(fileName: string): EmitOutput; getProgram(): Program; dispose(): void; @@ -2133,6 +2134,7 @@ declare namespace ts { containerKind: string; } interface EditorOptions { + BaseIndentSize?: number; IndentSize: number; TabSize: number; NewLineCharacter: string; @@ -2155,7 +2157,7 @@ declare namespace ts { InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; PlaceOpenBraceOnNewLineForFunctions: boolean; PlaceOpenBraceOnNewLineForControlBlocks: boolean; - [s: string]: boolean | number | string; + [s: string]: boolean | number | string | undefined; } interface DefinitionInfo { fileName: string; diff --git a/lib/typescript.js b/lib/typescript.js index 30d49888df1..d4d4c481c81 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -3300,6 +3300,9 @@ var ts; Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, File_name_0_has_a_1_extension_stripping_it: { code: 6132, category: ts.DiagnosticCategory.Message, key: "File_name_0_has_a_1_extension_stripping_it_6132", message: "File name '{0}' has a '{1}' extension - stripping it" }, + _0_is_declared_but_never_used: { code: 6133, category: ts.DiagnosticCategory.Error, key: "_0_is_declared_but_never_used_6133", message: "'{0}' is declared but never used." }, + Report_Errors_on_Unused_Locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Locals_6134", message: "Report Errors on Unused Locals." }, + Report_Errors_on_Unused_Parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Parameters_6135", message: "Report Errors on Unused Parameters." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -11077,8 +11080,14 @@ var ts; if (lhs.kind === 69 /* Identifier */) { return lhs.text === rhs.text; } - return lhs.right.text === rhs.right.text && - tagNamesAreEquivalent(lhs.left, rhs.left); + if (lhs.kind === 97 /* ThisKeyword */) { + return true; + } + // If we are at this statement then we must have PropertyAccessExpression and because tag name in Jsx element can only + // take forms of JsxTagNameExpression which includes an identifier, "this" expression, or another propertyAccessExpression + // it is safe to case the expression property as such. See parseJsxElementName for how we parse tag name in Jsx element + return lhs.name.text === rhs.name.text && + tagNamesAreEquivalent(lhs.expression, rhs.expression); } function parseJsxElementOrSelfClosingElement(inExpressionContext) { var opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext); @@ -11189,15 +11198,20 @@ var ts; } function parseJsxElementName() { scanJsxIdentifier(); - var elementName = parseIdentifierName(); + // JsxElement can have name in the form of + // propertyAccessExpression + // primaryExpression in the form of an identifier and "this" keyword + // We can't just simply use parseLeftHandSideExpressionOrHigher because then we will start consider class,function etc as a keyword + // We only want to consider "this" as a primaryExpression + var expression = token === 97 /* ThisKeyword */ ? + parseTokenNode() : parseIdentifierName(); while (parseOptional(21 /* DotToken */)) { - scanJsxIdentifier(); - var node = createNode(139 /* QualifiedName */, elementName.pos); // !!! - node.left = elementName; - node.right = parseIdentifierName(); - elementName = finishNode(node); + var propertyAccess = createNode(172 /* PropertyAccessExpression */, expression.pos); + propertyAccess.expression = expression; + propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true); + expression = finishNode(propertyAccess); } - return elementName; + return expression; } function parseJsxExpression(inExpressionContext) { var node = createNode(248 /* JsxExpression */); @@ -12058,7 +12072,7 @@ var ts; case 56 /* EqualsToken */: return parseExportAssignment(fullStart, decorators, modifiers); case 116 /* AsKeyword */: - return parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers); + return parseNamespaceExportDeclaration(fullStart, decorators, modifiers); default: return parseExportDeclaration(fullStart, decorators, modifiers); } @@ -12647,7 +12661,7 @@ var ts; function nextTokenIsSlash() { return nextToken() === 39 /* SlashToken */; } - function parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers) { + function parseNamespaceExportDeclaration(fullStart, decorators, modifiers) { var exportDeclaration = createNode(228 /* NamespaceExportDeclaration */, fullStart); exportDeclaration.decorators = decorators; exportDeclaration.modifiers = modifiers; @@ -17123,7 +17137,7 @@ var ts; function getTargetOfImportSpecifier(node) { return getExternalModuleMember(node.parent.parent.parent, node); } - function getTargetOfGlobalModuleExportDeclaration(node) { + function getTargetOfNamespaceExportDeclaration(node) { return resolveExternalModuleSymbol(node.parent.symbol); } function getTargetOfExportSpecifier(node) { @@ -17149,7 +17163,7 @@ var ts; case 235 /* ExportAssignment */: return getTargetOfExportAssignment(node); case 228 /* NamespaceExportDeclaration */: - return getTargetOfGlobalModuleExportDeclaration(node); + return getTargetOfNamespaceExportDeclaration(node); } } function resolveSymbol(symbol) { @@ -17249,9 +17263,12 @@ var ts; var left = name.kind === 139 /* QualifiedName */ ? name.left : name.expression; var right = name.kind === 139 /* QualifiedName */ ? name.right : name.name; var namespace = resolveEntityName(left, 1536 /* Namespace */, ignoreErrors); - if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) { + if (!namespace || ts.nodeIsMissing(right)) { return undefined; } + else if (namespace === unknownSymbol) { + return namespace; + } symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { if (!ignoreErrors) { @@ -18332,16 +18349,13 @@ var ts; writePunctuation(writer, 27 /* GreaterThanToken */); } } - function buildDisplayForParametersAndDelimiters(thisType, parameters, writer, enclosingDeclaration, flags, symbolStack) { + function buildDisplayForParametersAndDelimiters(thisParameter, parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 17 /* OpenParenToken */); - if (thisType) { - writeKeyword(writer, 97 /* ThisKeyword */); - writePunctuation(writer, 54 /* ColonToken */); - writeSpace(writer); - buildTypeDisplay(thisType, writer, enclosingDeclaration, flags, symbolStack); + if (thisParameter) { + buildParameterDisplay(thisParameter, writer, enclosingDeclaration, flags, symbolStack); } for (var i = 0; i < parameters.length; i++) { - if (i > 0 || thisType) { + if (i > 0 || thisParameter) { writePunctuation(writer, 24 /* CommaToken */); writeSpace(writer); } @@ -18391,7 +18405,7 @@ var ts; else { buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.thisType, signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildDisplayForParametersAndDelimiters(signature.thisParameter, signature.parameters, writer, enclosingDeclaration, flags, symbolStack); buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { @@ -18787,12 +18801,14 @@ var ts; if (func.kind === 150 /* SetAccessor */ && !ts.hasDynamicName(func)) { var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 149 /* GetAccessor */); if (getter) { - var signature = getSignatureFromDeclaration(getter); + var getterSignature = getSignatureFromDeclaration(getter); var thisParameter = getAccessorThisParameter(func); if (thisParameter && declaration === thisParameter) { - return signature.thisType; + // Use the type from the *getter* + ts.Debug.assert(!thisParameter.type); + return getTypeOfSymbol(getterSignature.thisParameter); } - return getReturnTypeOfSignature(signature); + return getReturnTypeOfSignature(getterSignature); } } // Use contextual parameter type if one is available @@ -18993,14 +19009,12 @@ var ts; } return undefined; } - function getAnnotatedAccessorThisType(accessor) { - if (accessor) { - var parameter = getAccessorThisParameter(accessor); - if (parameter && parameter.type) { - return getTypeFromTypeNode(accessor.parameters[0].type); - } - } - return undefined; + function getAnnotatedAccessorThisParameter(accessor) { + var parameter = getAccessorThisParameter(accessor); + return parameter && parameter.symbol; + } + function getThisTypeOfDeclaration(declaration) { + return getThisTypeOfSignature(getSignatureFromDeclaration(declaration)); } function getTypeOfAccessors(symbol) { var links = getSymbolLinks(symbol); @@ -19641,12 +19655,12 @@ var ts; type.typeArguments : ts.concatenate(type.typeArguments, [type]); resolveObjectTypeMembers(type, source, typeParameters, typeArguments); } - function createSignature(declaration, typeParameters, thisType, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { + function createSignature(declaration, typeParameters, thisParameter, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { var sig = new Signature(checker); sig.declaration = declaration; sig.typeParameters = typeParameters; sig.parameters = parameters; - sig.thisType = thisType; + sig.thisParameter = thisParameter; sig.resolvedReturnType = resolvedReturnType; sig.typePredicate = typePredicate; sig.minArgumentCount = minArgumentCount; @@ -19655,7 +19669,7 @@ var ts; return sig; } function cloneSignature(sig) { - return createSignature(sig.declaration, sig.typeParameters, sig.thisType, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); + return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); } function getDefaultConstructSignatures(classType) { var baseConstructorType = getBaseConstructorTypeOfClass(classType); @@ -19749,8 +19763,9 @@ var ts; // Union the result types when more than one signature matches if (unionSignatures.length > 1) { s = cloneSignature(signature); - if (ts.forEach(unionSignatures, function (sig) { return sig.thisType; })) { - s.thisType = getUnionType(ts.map(unionSignatures, function (sig) { return sig.thisType || anyType; })); + if (ts.forEach(unionSignatures, function (sig) { return sig.thisParameter; })) { + var thisType = getUnionType(ts.map(unionSignatures, function (sig) { return getTypeOfSymbol(sig.thisParameter) || anyType; })); + s.thisParameter = createTransientSymbol(signature.thisParameter, thisType); } // Clear resolved return type we possibly got from cloneSignature s.resolvedReturnType = undefined; @@ -19960,6 +19975,7 @@ var ts; var props; // Flags we want to propagate to the result if they exist in all source symbols var commonFlags = (containingType.flags & 32768 /* Intersection */) ? 536870912 /* Optional */ : 0 /* None */; + var isReadonly = false; for (var _i = 0, types_2 = types; _i < types_2.length; _i++) { var current = types_2[_i]; var type = getApparentType(current); @@ -19973,6 +19989,9 @@ var ts; else if (!ts.contains(props, prop)) { props.push(prop); } + if (isReadonlySymbol(prop)) { + isReadonly = true; + } } else if (containingType.flags & 16384 /* Union */) { // A union type requires the property to be present in all constituent types @@ -20001,6 +20020,7 @@ var ts; commonFlags, name); result.containingType = containingType; result.declarations = declarations; + result.isReadonly = isReadonly; result.type = containingType.flags & 16384 /* Union */ ? getUnionType(propTypes) : getIntersectionType(propTypes); return result; } @@ -20172,7 +20192,7 @@ var ts; var parameters = []; var hasStringLiterals = false; var minArgumentCount = -1; - var thisType = undefined; + var thisParameter = undefined; var hasThisParameter = void 0; var isJSConstructSignature = ts.isJSDocConstructSignature(declaration); // If this is a JSDoc construct signature, then skip the first parameter in the @@ -20188,7 +20208,7 @@ var ts; } if (i === 0 && paramSymbol.name === "this") { hasThisParameter = true; - thisType = param.type ? getTypeFromTypeNode(param.type) : unknownType; + thisParameter = param.symbol; } else { parameters.push(paramSymbol); @@ -20209,10 +20229,12 @@ var ts; // If only one accessor includes a this-type annotation, the other behaves as if it had the same type annotation if ((declaration.kind === 149 /* GetAccessor */ || declaration.kind === 150 /* SetAccessor */) && !ts.hasDynamicName(declaration) && - (!hasThisParameter || thisType === unknownType)) { + (!hasThisParameter || !thisParameter)) { var otherKind = declaration.kind === 149 /* GetAccessor */ ? 150 /* SetAccessor */ : 149 /* GetAccessor */; - var setter = ts.getDeclarationOfKind(declaration.symbol, otherKind); - thisType = getAnnotatedAccessorThisType(setter); + var other = ts.getDeclarationOfKind(declaration.symbol, otherKind); + if (other) { + thisParameter = getAnnotatedAccessorThisParameter(other); + } } if (minArgumentCount < 0) { minArgumentCount = declaration.parameters.length - (hasThisParameter ? 1 : 0); @@ -20230,7 +20252,7 @@ var ts; var typePredicate = declaration.type && declaration.type.kind === 154 /* TypePredicate */ ? createTypePredicateFromTypePredicateNode(declaration.type) : undefined; - links.resolvedSignature = createSignature(declaration, typeParameters, thisType, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); + links.resolvedSignature = createSignature(declaration, typeParameters, thisParameter, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); } return links.resolvedSignature; } @@ -20305,6 +20327,11 @@ var ts; } return anyType; } + function getThisTypeOfSignature(signature) { + if (signature.thisParameter) { + return getTypeOfSymbol(signature.thisParameter); + } + } function getReturnTypeOfSignature(signature) { if (!signature.resolvedReturnType) { if (!pushTypeResolution(signature, 3 /* ResolvedReturnType */)) { @@ -21080,7 +21107,7 @@ var ts; if (signature.typePredicate) { freshTypePredicate = cloneTypePredicate(signature.typePredicate, mapper); } - var result = createSignature(signature.declaration, freshTypeParameters, signature.thisType && instantiateType(signature.thisType, mapper), instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); + var result = createSignature(signature.declaration, freshTypeParameters, signature.thisParameter && instantiateSymbol(signature.thisParameter, mapper), instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); result.target = signature; result.mapper = mapper; return result; @@ -21315,17 +21342,21 @@ var ts; source = getErasedSignature(source); target = getErasedSignature(target); var result = -1 /* True */; - if (source.thisType && target.thisType && source.thisType !== voidType) { - // void sources are assignable to anything. - var related = compareTypes(source.thisType, target.thisType, /*reportErrors*/ false) - || compareTypes(target.thisType, source.thisType, reportErrors); - if (!related) { - if (reportErrors) { - errorReporter(ts.Diagnostics.The_this_types_of_each_signature_are_incompatible); + var sourceThisType = getThisTypeOfSignature(source); + if (sourceThisType && sourceThisType !== voidType) { + var targetThisType = getThisTypeOfSignature(target); + if (targetThisType) { + // void sources are assignable to anything. + var related = compareTypes(sourceThisType, targetThisType, /*reportErrors*/ false) + || compareTypes(targetThisType, sourceThisType, reportErrors); + if (!related) { + if (reportErrors) { + errorReporter(ts.Diagnostics.The_this_types_of_each_signature_are_incompatible); + } + return 0 /* False */; } - return 0 /* False */; + result &= related; } - result &= related; } var sourceMax = getNumNonRestParameters(source); var targetMax = getNumNonRestParameters(target); @@ -22265,12 +22296,18 @@ var ts; source = getErasedSignature(source); target = getErasedSignature(target); var result = -1 /* True */; - if (!ignoreThisTypes && source.thisType && target.thisType) { - var related = compareTypes(source.thisType, target.thisType); - if (!related) { - return 0 /* False */; + if (!ignoreThisTypes) { + var sourceThisType = getThisTypeOfSignature(source); + if (sourceThisType) { + var targetThisType = getThisTypeOfSignature(target); + if (targetThisType) { + var related = compareTypes(sourceThisType, targetThisType); + if (!related) { + return 0 /* False */; + } + result &= related; + } } - result &= related; } var targetLen = target.parameters.length; for (var i = 0; i < targetLen; i++) { @@ -23698,8 +23735,20 @@ var ts; } return container === declarationContainer; } + function updateReferencesForInterfaceHeritiageClauseTargets(node) { + var extendedTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (extendedTypeNode) { + var t = getTypeFromTypeNode(extendedTypeNode); + if (t !== unknownType && t.symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + t.symbol.hasReference = true; + } + } + } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); + if (symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.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 // arguments objects will be bound to the inner object; emitting arrow function natively in ES6, arguments objects @@ -23963,9 +24012,9 @@ var ts; if (type) { return type; } - var signature = getSignatureFromDeclaration(container); - if (signature.thisType) { - return signature.thisType; + var thisType = getThisTypeOfDeclaration(container); + if (thisType) { + return thisType; } } if (ts.isClassLike(container.parent)) { @@ -24184,7 +24233,7 @@ var ts; if (isContextSensitiveFunctionOrObjectLiteralMethod(func) && func.kind !== 180 /* ArrowFunction */) { var contextualSignature = getContextualSignature(func); if (contextualSignature) { - return contextualSignature.thisType; + return getThisTypeOfSignature(contextualSignature); } } return undefined; @@ -24917,7 +24966,8 @@ var ts; * Returns true iff React would emit this tag name as a string rather than an identifier or qualified name */ function isJsxIntrinsicIdentifier(tagName) { - if (tagName.kind === 139 /* QualifiedName */) { + // TODO (yuisu): comment + if (tagName.kind === 172 /* PropertyAccessExpression */ || tagName.kind === 97 /* ThisKeyword */) { return false; } else { @@ -25093,6 +25143,28 @@ var ts; return getResolvedJsxType(node, type, elemClassType); })); } + // If the elemType is a string type, we have to return anyType to prevent an error downstream as we will try to find construct or call signature of the type + if (elemType.flags & 2 /* String */) { + return anyType; + } + else if (elemType.flags & 256 /* StringLiteral */) { + // If the elemType is a stringLiteral type, we can then provide a check to make sure that the string literal type is one of the Jsx intrinsic element type + var intrinsicElementsType = getJsxType(JsxNames.IntrinsicElements); + if (intrinsicElementsType !== unknownType) { + var stringLiteralTypeName = elemType.text; + var intrinsicProp = getPropertyOfType(intrinsicElementsType, stringLiteralTypeName); + if (intrinsicProp) { + return getTypeOfSymbol(intrinsicProp); + } + var indexSignatureType = getIndexTypeOfType(intrinsicElementsType, 0 /* String */); + if (indexSignatureType) { + return indexSignatureType; + } + error(node, ts.Diagnostics.Property_0_does_not_exist_on_type_1, stringLiteralTypeName, "JSX." + JsxNames.IntrinsicElements); + } + // If we need to report an error, we already done so here. So just return any to prevent any more error downstream + return anyType; + } // Get the element instance type (the result of newing or invoking this tag) var elemInstanceType = getJsxElementInstanceType(node, elemType); if (!elemClassType || !isTypeAssignableTo(elemInstanceType, elemClassType)) { @@ -25401,6 +25473,9 @@ var ts; } return unknownType; } + if ((compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + prop.hasReference = true; + } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & 32 /* Class */) { checkClassPropertyAccess(node, left, apparentType, prop); @@ -25806,10 +25881,11 @@ var ts; if (context.failedTypeParameterIndex !== undefined && !context.inferences[context.failedTypeParameterIndex].isFixed) { context.failedTypeParameterIndex = undefined; } - if (signature.thisType) { + var thisType = getThisTypeOfSignature(signature); + if (thisType) { var thisArgumentNode = getThisArgumentOfCall(node); var thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType; - inferTypes(context, thisArgumentType, signature.thisType); + inferTypes(context, thisArgumentType, thisType); } // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. @@ -25873,7 +25949,8 @@ var ts; return typeArgumentsAreAssignable; } function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) { - if (signature.thisType && signature.thisType !== voidType && node.kind !== 175 /* NewExpression */) { + var thisType = getThisTypeOfSignature(signature); + if (thisType && thisType !== voidType && node.kind !== 175 /* NewExpression */) { // If the called expression is not of the form `x.f` or `x["f"]`, then sourceType = voidType // If the signature's 'this' type is voidType, then the check is skipped -- anything is compatible. // If the expression is a new expression, then the check is skipped. @@ -25881,7 +25958,7 @@ var ts; var thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType; var errorNode = reportErrors ? (thisArgumentNode || node) : undefined; var headMessage_1 = ts.Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1; - if (!checkTypeRelatedTo(thisArgumentType, signature.thisType, relation, errorNode, headMessage_1)) { + if (!checkTypeRelatedTo(thisArgumentType, getThisTypeOfSignature(signature), relation, errorNode, headMessage_1)) { return false; } } @@ -26526,7 +26603,7 @@ var ts; if (getReturnTypeOfSignature(signature) !== voidType) { error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } - if (signature.thisType === voidType) { + if (getThisTypeOfSignature(signature) === voidType) { error(node, ts.Diagnostics.A_function_that_is_called_with_the_new_keyword_cannot_have_a_this_type_that_is_void); } return signature; @@ -27126,6 +27203,8 @@ var ts; } } } + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); } } function checkArithmeticOperandType(operand, type, diagnostic) { @@ -27141,7 +27220,9 @@ var ts; // Variables declared with 'const' // Get accessors without matching set accessors // Enum members - return symbol.flags & 4 /* Property */ && (getDeclarationFlagsFromSymbol(symbol) & 64 /* Readonly */) !== 0 || + // Unions and intersections of the above (unions and intersections eagerly set isReadonly on creation) + return symbol.isReadonly || + symbol.flags & 4 /* Property */ && (getDeclarationFlagsFromSymbol(symbol) & 64 /* Readonly */) !== 0 || symbol.flags & 3 /* Variable */ && (getDeclarationFlagsFromSymbol(symbol) & 2048 /* Const */) !== 0 || symbol.flags & 98304 /* Accessor */ && !(symbol.flags & 65536 /* SetAccessor */) || (symbol.flags & 8 /* EnumMember */) !== 0; @@ -28089,6 +28170,9 @@ var ts; checkAsyncFunctionReturnType(node); } } + if (!node.body) { + checkUnusedTypeParameters(node); + } } } function checkClassForDuplicateDeclarations(node) { @@ -28228,6 +28312,8 @@ var ts; // Grammar check for checking only related to constructorDeclaration checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node); checkSourceElement(node.body); + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); var symbol = getSymbolOfNode(node); var firstDeclaration = ts.getDeclarationOfKind(symbol, node.kind); // Only type check the symbol once @@ -28351,7 +28437,7 @@ var ts; // TypeScript 1.0 spec (April 2014): 4.5 // If both accessors include type annotations, the specified types must be identical. checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorType, ts.Diagnostics.get_and_set_accessor_must_have_the_same_type); - checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorThisType, ts.Diagnostics.get_and_set_accessor_must_have_the_same_this_type); + checkAccessorDeclarationTypesIdentical(node, otherAccessor, getThisTypeOfDeclaration, ts.Diagnostics.get_and_set_accessor_must_have_the_same_this_type); } } getTypeOfAccessors(getSymbolOfNode(node)); @@ -28396,13 +28482,18 @@ var ts; function checkTypeReferenceNode(node) { checkGrammarTypeArguments(node, node.typeArguments); var type = getTypeFromTypeReference(node); - if (type !== unknownType && node.typeArguments) { - // Do type argument local checks only if referenced type is successfully resolved - ts.forEach(node.typeArguments, checkSourceElement); - if (produceDiagnostics) { - var symbol = getNodeLinks(node).resolvedSymbol; - var typeParameters = symbol.flags & 524288 /* TypeAlias */ ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; - checkTypeArgumentConstraints(typeParameters, node.typeArguments); + if (type !== unknownType) { + if (type.symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + type.symbol.hasReference = true; + } + if (node.typeArguments) { + // Do type argument local checks only if referenced type is successfully resolved + ts.forEach(node.typeArguments, checkSourceElement); + if (produceDiagnostics) { + var symbol = getNodeLinks(node).resolvedSymbol; + var typeParameters = symbol.flags & 524288 /* TypeAlias */ ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; + checkTypeArgumentConstraints(typeParameters, node.typeArguments); + } } } } @@ -29137,6 +29228,8 @@ var ts; } } checkSourceElement(node.body); + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); if (!node.asteriskToken) { var returnOrPromisedType = node.type && (isAsync ? checkAsyncFunctionReturnType(node) : getTypeFromTypeNode(node.type)); checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnOrPromisedType); @@ -29155,12 +29248,84 @@ var ts; } } } + function checkUnusedIdentifiers(node) { + if (node.parent.kind !== 222 /* InterfaceDeclaration */ && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + for (var key in node.locals) { + if (ts.hasProperty(node.locals, key)) { + var local = node.locals[key]; + if (!local.hasReference && local.valueDeclaration) { + if (local.valueDeclaration.kind !== 142 /* Parameter */ && compilerOptions.noUnusedLocals) { + error(local.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local.name); + } + else if (local.valueDeclaration.kind === 142 /* Parameter */ && compilerOptions.noUnusedParameters) { + if (local.valueDeclaration.flags === 0) { + error(local.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local.name); + } + } + } + } + } + } + } + function checkUnusedClassLocals(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + if (node.members) { + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 147 /* MethodDeclaration */ || member.kind === 145 /* PropertyDeclaration */) { + if (isPrivateNode(member) && !member.symbol.hasReference) { + error(member.name, ts.Diagnostics._0_is_declared_but_never_used, member.symbol.name); + } + } + else if (member.kind === 148 /* Constructor */) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var parameter = _c[_b]; + if (isPrivateNode(parameter) && !parameter.symbol.hasReference) { + error(parameter.name, ts.Diagnostics._0_is_declared_but_never_used, parameter.symbol.name); + } + } + } + } + } + } + } + function checkUnusedTypeParameters(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + if (node.typeParameters) { + for (var _i = 0, _a = node.typeParameters; _i < _a.length; _i++) { + var typeParameter = _a[_i]; + if (!typeParameter.symbol.hasReference) { + error(typeParameter.name, ts.Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name); + } + } + } + } + } + function isPrivateNode(node) { + return (node.flags & 8 /* Private */) !== 0; + } + function checkUnusedModuleLocals(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + var _loop_1 = function(key) { + if (ts.hasProperty(node.locals, key)) { + var local_1 = node.locals[key]; + if (!local_1.hasReference && !local_1.exportSymbol) { + ts.forEach(local_1.declarations, function (d) { return error(d.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); }); + } + } + }; + for (var key in node.locals) { + _loop_1(key); + } + } + } function checkBlock(node) { // Grammar checking for SyntaxKind.Block if (node.kind === 199 /* Block */) { checkGrammarStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); + checkUnusedIdentifiers(node); } function checkCollisionWithArgumentsInGeneratedCode(node) { // no rest parameters \ declaration context \ overload - no codegen impact @@ -29602,6 +29767,7 @@ var ts; } } checkSourceElement(node.statement); + checkUnusedIdentifiers(node); } function checkForInStatement(node) { // Grammar checking @@ -29643,6 +29809,7 @@ var ts; error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); + checkUnusedIdentifiers(node); } function checkForInOrForOfVariableDeclaration(iterationStatement) { var variableDeclarationList = iterationStatement.initializer; @@ -30034,6 +30201,7 @@ var ts; } } checkBlock(catchClause.block); + checkUnusedIdentifiers(catchClause); } if (node.finallyBlock) { checkBlock(node.finallyBlock); @@ -30170,6 +30338,8 @@ var ts; } checkClassLikeDeclaration(node); ts.forEach(node.members, checkSourceElement); + checkUnusedClassLocals(node); + checkUnusedTypeParameters(node); } function checkClassLikeDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); @@ -30447,6 +30617,8 @@ var ts; ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); + updateReferencesForInterfaceHeritiageClauseTargets(node); + checkUnusedTypeParameters(node); } } function checkTypeAliasDeclaration(node) { @@ -30805,6 +30977,7 @@ var ts; } if (node.body) { checkSourceElement(node.body); + checkUnusedModuleLocals(node); } } function checkModuleAugmentationElement(node, isGlobalAugmentation) { @@ -30978,6 +31151,9 @@ var ts; if (target.flags & 793056 /* Type */) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); } + if ((compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + target.hasReference = true; + } } } else { @@ -31297,6 +31473,9 @@ var ts; potentialThisCollisions.length = 0; deferredNodes = []; ts.forEach(node.statements, checkSourceElement); + if (ts.isExternalModule(node)) { + checkUnusedModuleLocals(node); + } checkDeferredNodes(); deferredNodes = undefined; if (ts.isExternalOrCommonJsModule(node)) { @@ -31615,6 +31794,14 @@ var ts; case 139 /* QualifiedName */: return getSymbolOfEntityNameOrPropertyAccessExpression(node); case 97 /* ThisKeyword */: + var container = ts.getThisContainer(node, /*includeArrowFunctions*/ false); + if (ts.isFunctionLike(container)) { + var sig = getSignatureFromDeclaration(container); + if (sig.thisParameter) { + return sig.thisParameter; + } + } + // fallthrough case 95 /* SuperKeyword */: var type = ts.isExpression(node) ? checkExpression(node) : getTypeFromTypeNode(node); return type.symbol; @@ -31855,7 +32042,10 @@ var ts; var parentSymbol = getParentOfSymbol(symbol); if (parentSymbol) { if (parentSymbol.flags & 512 /* ValueModule */ && parentSymbol.valueDeclaration.kind === 256 /* SourceFile */) { - return parentSymbol.valueDeclaration; + // If `node` accesses an export and that export isn't in the same file, then symbol is a namespace export, so return undefined. + if (parentSymbol.valueDeclaration === ts.getSourceFileOfNode(node)) { + return parentSymbol.valueDeclaration; + } } for (var n = node.parent; n; n = n.parent) { if ((n.kind === 225 /* ModuleDeclaration */ || n.kind === 224 /* EnumDeclaration */) && getSymbolOfNode(n) === parentSymbol) { @@ -32821,7 +33011,7 @@ var ts; var GetAccessor = 2; var SetAccessor = 4; var GetOrSetAccessor = GetAccessor | SetAccessor; - var _loop_1 = function(prop) { + var _loop_2 = function(prop) { var name_21 = prop.name; if (prop.kind === 193 /* OmittedExpression */ || name_21.kind === 140 /* ComputedPropertyName */) { @@ -32895,8 +33085,8 @@ var ts; }; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var state_2 = _loop_1(prop); - if (typeof state_2 === "object") return state_2.value; + var state_3 = _loop_2(prop); + if (typeof state_3 === "object") return state_3.value; } } function checkGrammarJsxElement(node) { @@ -35814,6 +36004,8 @@ var ts; return generateNameForExportDefault(); case 192 /* ClassExpression */: return generateNameForClassExpression(); + default: + ts.Debug.fail(); } } function getGeneratedNameForNode(node) { @@ -36629,6 +36821,20 @@ var ts; } return false; } + function getClassExpressionInPropertyAccessInStaticPropertyDeclaration(node) { + if (languageVersion >= 2 /* ES6 */) { + var parent_14 = node.parent; + if (parent_14.kind === 172 /* PropertyAccessExpression */ && parent_14.expression === node) { + parent_14 = parent_14.parent; + while (parent_14 && parent_14.kind !== 145 /* PropertyDeclaration */) { + parent_14 = parent_14.parent; + } + return parent_14 && parent_14.kind === 145 /* PropertyDeclaration */ && (parent_14.flags & 32 /* Static */) !== 0 && + parent_14.parent.kind === 192 /* ClassExpression */ ? parent_14.parent : undefined; + } + } + return undefined; + } function emitIdentifier(node) { if (convertedLoopState) { if (node.text == "arguments" && resolver.isArgumentsLocalBinding(node)) { @@ -36642,6 +36848,14 @@ var ts; write(node.text); } else if (isExpressionIdentifier(node)) { + var classExpression = getClassExpressionInPropertyAccessInStaticPropertyDeclaration(node); + if (classExpression) { + var declaration = resolver.getReferencedValueDeclaration(node); + if (declaration === classExpression) { + write(getGeneratedNameForNode(declaration.name)); + return; + } + } emitExpressionIdentifier(node); } else if (isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(node)) { @@ -39666,7 +39880,7 @@ var ts; emitStart(property); emitStart(property.name); if (receiver) { - emit(receiver); + write(receiver); } else { if (property.flags & 32 /* Static */) { @@ -40057,12 +40271,15 @@ var ts; // of it have been initialized by the time it is used. var staticProperties = getInitializedProperties(node, /*isStatic*/ true); var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 192 /* ClassExpression */; - var tempVariable; + var generatedName; if (isClassExpressionWithStaticProperties) { - tempVariable = createAndRecordTempVariable(0 /* Auto */); + generatedName = getGeneratedNameForNode(node.name); + var synthesizedNode = ts.createSynthesizedNode(69 /* Identifier */); + synthesizedNode.text = generatedName; + recordTempDeclaration(synthesizedNode); write("("); increaseIndent(); - emit(tempVariable); + emit(synthesizedNode); write(" = "); } write("class"); @@ -40110,11 +40327,11 @@ var ts; var property = staticProperties_1[_a]; write(","); writeLine(); - emitPropertyDeclaration(node, property, /*receiver*/ tempVariable, /*isExpression*/ true); + emitPropertyDeclaration(node, property, /*receiver*/ generatedName, /*isExpression*/ true); } write(","); writeLine(); - emit(tempVariable); + write(generatedName); decreaseIndent(); write(")"); } @@ -42612,7 +42829,7 @@ var ts; /* @internal */ ts.ioReadTime = 0; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ - ts.version = "1.9.0"; + ts.version = "2.0.0"; var emptyArray = []; var defaultTypeRoots = ["node_modules/@types"]; function findConfigFile(searchPath, fileExists) { @@ -44697,6 +44914,16 @@ var ts; type: "boolean", description: ts.Diagnostics.Raise_error_on_this_expressions_with_an_implied_any_type }, + { + name: "noUnusedLocals", + type: "boolean", + description: ts.Diagnostics.Report_Errors_on_Unused_Locals + }, + { + name: "noUnusedParameters", + type: "boolean", + description: ts.Diagnostics.Report_Errors_on_Unused_Parameters + }, { name: "noLib", type: "boolean" @@ -44891,16 +45118,6 @@ var ts; isFilePath: true } }, - { - name: "typesSearchPaths", - type: "list", - isTSConfigOnly: true, - element: { - name: "typesSearchPaths", - type: "string", - isFilePath: true - } - }, { name: "typeRoots", type: "list", @@ -44978,7 +45195,7 @@ var ts; description: ts.Diagnostics.Specify_library_files_to_be_included_in_the_compilation_Colon }, { - name: "disableProjectSizeLimit", + name: "disableSizeLimit", type: "boolean" }, { @@ -45737,28 +45954,28 @@ var ts; switch (n.kind) { case 199 /* Block */: if (!ts.isFunctionBlock(n)) { - var parent_14 = n.parent; + var parent_15 = n.parent; var openBrace = ts.findChildOfKind(n, 15 /* OpenBraceToken */, sourceFile); var closeBrace = ts.findChildOfKind(n, 16 /* CloseBraceToken */, sourceFile); // Check if the block is standalone, or 'attached' to some parent statement. // If the latter, we want to collapse the block, but consider its hint span // to be the entire span of the parent. - if (parent_14.kind === 204 /* DoStatement */ || - parent_14.kind === 207 /* ForInStatement */ || - parent_14.kind === 208 /* ForOfStatement */ || - parent_14.kind === 206 /* ForStatement */ || - parent_14.kind === 203 /* IfStatement */ || - parent_14.kind === 205 /* WhileStatement */ || - parent_14.kind === 212 /* WithStatement */ || - parent_14.kind === 252 /* CatchClause */) { - addOutliningSpan(parent_14, openBrace, closeBrace, autoCollapse(n)); + if (parent_15.kind === 204 /* DoStatement */ || + parent_15.kind === 207 /* ForInStatement */ || + parent_15.kind === 208 /* ForOfStatement */ || + parent_15.kind === 206 /* ForStatement */ || + parent_15.kind === 203 /* IfStatement */ || + parent_15.kind === 205 /* WhileStatement */ || + parent_15.kind === 212 /* WithStatement */ || + parent_15.kind === 252 /* CatchClause */) { + addOutliningSpan(parent_15, openBrace, closeBrace, autoCollapse(n)); break; } - if (parent_14.kind === 216 /* TryStatement */) { + if (parent_15.kind === 216 /* TryStatement */) { // Could be the try-block, or the finally-block. - var tryStatement = parent_14; + var tryStatement = parent_15; if (tryStatement.tryBlock === n) { - addOutliningSpan(parent_14, openBrace, closeBrace, autoCollapse(n)); + addOutliningSpan(parent_15, openBrace, closeBrace, autoCollapse(n)); break; } else if (tryStatement.finallyBlock === n) { @@ -47447,8 +47664,8 @@ var ts; return undefined; } function getArgumentIndex(argumentsList, node) { - // The list we got back can include commas. In the presence of errors it may - // also just have nodes without commas. For example "Foo(a b c)" will have 3 + // The list we got back can include commas. In the presence of errors it may + // also just have nodes without commas. For example "Foo(a b c)" will have 3 // args without commas. We want to find what index we're at. So we count // forward until we hit ourselves, only incrementing the index if it isn't a // comma. @@ -47479,8 +47696,8 @@ var ts; // 'a' ''. So, in the case where the last child is a comma, we increase the // arg count by one to compensate. // - // Note: this subtlety only applies to the last comma. If you had "Foo(a,," then - // we'll have: 'a' '' '' + // Note: this subtlety only applies to the last comma. If you had "Foo(a,," then + // we'll have: 'a' '' '' // That will give us 2 non-commas. We then add one for the last comma, givin us an // arg count of 3. var listChildren = argumentsList.getChildren(); @@ -47628,7 +47845,7 @@ var ts; signatureHelpParameters = typeParameters && typeParameters.length > 0 ? ts.map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; suffixDisplayParts.push(ts.punctuationPart(27 /* GreaterThanToken */)); var parameterParts = ts.mapToDisplayParts(function (writer) { - return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.thisType, candidateSignature.parameters, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.thisParameter, candidateSignature.parameters, writer, invocation); }); ts.addRange(suffixDisplayParts, parameterParts); } @@ -47745,6 +47962,8 @@ var ts; case 199 /* Block */: case 226 /* ModuleBlock */: case 227 /* CaseBlock */: + case 233 /* NamedImports */: + case 237 /* NamedExports */: return nodeEndsWith(n, 16 /* CloseBraceToken */, sourceFile); case 252 /* CatchClause */: return isCompletedNode(n.block, sourceFile); @@ -47832,6 +48051,9 @@ var ts; return isCompletedNode(lastSpan, sourceFile); case 197 /* TemplateSpan */: return ts.nodeIsPresent(n.literal); + case 236 /* ExportDeclaration */: + case 230 /* ImportDeclaration */: + return ts.nodeIsPresent(n.moduleSpecifier); case 185 /* PrefixUnaryExpression */: return isCompletedNode(n.operand, sourceFile); case 187 /* BinaryExpression */: @@ -49282,7 +49504,7 @@ var ts; this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Place a space before open brace in a TypeScript declaration that has braces as children (class, module, enum, etc) - this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([69 /* Identifier */, 3 /* MultiLineCommentTrivia */, 73 /* ClassKeyword */]); + this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([69 /* Identifier */, 3 /* MultiLineCommentTrivia */, 73 /* ClassKeyword */, 82 /* ExportKeyword */, 89 /* ImportKeyword */]); this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Place a space before open brace in a control flow construct this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 3 /* MultiLineCommentTrivia */, 79 /* DoKeyword */, 100 /* TryKeyword */, 85 /* FinallyKeyword */, 80 /* ElseKeyword */]); @@ -49339,8 +49561,8 @@ var ts; // Use of module as a function call. e.g.: import m2 = module("m2"); this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([125 /* ModuleKeyword */, 129 /* RequireKeyword */]), 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8 /* Delete */)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([115 /* AbstractKeyword */, 73 /* ClassKeyword */, 122 /* DeclareKeyword */, 77 /* DefaultKeyword */, 81 /* EnumKeyword */, 82 /* ExportKeyword */, 83 /* ExtendsKeyword */, 123 /* GetKeyword */, 106 /* ImplementsKeyword */, 89 /* ImportKeyword */, 107 /* InterfaceKeyword */, 125 /* ModuleKeyword */, 126 /* NamespaceKeyword */, 110 /* PrivateKeyword */, 112 /* PublicKeyword */, 111 /* ProtectedKeyword */, 131 /* SetKeyword */, 113 /* StaticKeyword */, 134 /* TypeKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([83 /* ExtendsKeyword */, 106 /* ImplementsKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([115 /* AbstractKeyword */, 73 /* ClassKeyword */, 122 /* DeclareKeyword */, 77 /* DefaultKeyword */, 81 /* EnumKeyword */, 82 /* ExportKeyword */, 83 /* ExtendsKeyword */, 123 /* GetKeyword */, 106 /* ImplementsKeyword */, 89 /* ImportKeyword */, 107 /* InterfaceKeyword */, 125 /* ModuleKeyword */, 126 /* NamespaceKeyword */, 110 /* PrivateKeyword */, 112 /* PublicKeyword */, 111 /* ProtectedKeyword */, 131 /* SetKeyword */, 113 /* StaticKeyword */, 134 /* TypeKeyword */, 136 /* FromKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([83 /* ExtendsKeyword */, 106 /* ImplementsKeyword */, 136 /* FromKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(9 /* StringLiteral */, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2 /* Space */)); // Lambda expressions @@ -49495,6 +49717,8 @@ var ts; case 187 /* BinaryExpression */: case 188 /* ConditionalExpression */: case 195 /* AsExpression */: + case 238 /* ExportSpecifier */: + case 234 /* ImportSpecifier */: case 154 /* TypePredicate */: case 162 /* UnionType */: case 163 /* IntersectionType */: @@ -49613,6 +49837,10 @@ var ts; case 224 /* EnumDeclaration */: case 159 /* TypeLiteral */: case 225 /* ModuleDeclaration */: + case 236 /* ExportDeclaration */: + case 237 /* NamedExports */: + case 230 /* ImportDeclaration */: + case 233 /* NamedImports */: return true; } return false; @@ -50420,7 +50648,10 @@ var ts; var startLinePosition = ts.getLineStartPositionForPosition(startPos, sourceFile); var column = formatting.SmartIndenter.findFirstNonWhitespaceColumn(startLinePosition, startPos, sourceFile, options); if (startLine !== parentStartLine || startPos === column) { - return column; + // Use the base indent size if it is greater than + // the indentation of the inherited predecessor. + var baseIndentSize = formatting.SmartIndenter.getBaseIndentation(options); + return baseIndentSize > column ? baseIndentSize : column; } } return -1 /* Unknown */; @@ -51060,7 +51291,7 @@ var ts; })(Value || (Value = {})); function getIndentation(position, sourceFile, options) { if (position > sourceFile.text.length) { - return 0; // past EOF + return getBaseIndentation(options); // past EOF } // no indentation when the indent style is set to none, // so we can return fast @@ -51069,7 +51300,7 @@ var ts; } var precedingToken = ts.findPrecedingToken(position, sourceFile); if (!precedingToken) { - return 0; + return getBaseIndentation(options); } // no indentation in string \regex\template literals var precedingTokenIsLiteral = ts.isStringOrRegularExpressionOrTemplateLiteral(precedingToken.kind); @@ -51131,12 +51362,16 @@ var ts; current = current.parent; } if (!current) { - // no parent was found - return 0 to be indented on the level of SourceFile - return 0; + // no parent was found - return the base indentation of the SourceFile + return getBaseIndentation(options); } return getIndentationForNodeWorker(current, currentStart, /*ignoreActualIndentationRange*/ undefined, indentationDelta, sourceFile, options); } SmartIndenter.getIndentation = getIndentation; + function getBaseIndentation(options) { + return options.BaseIndentSize || 0; + } + SmartIndenter.getBaseIndentation = getBaseIndentation; function getIndentationForNode(n, ignoreActualIndentationRange, sourceFile, options) { var start = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)); return getIndentationForNodeWorker(n, start, ignoreActualIndentationRange, /*indentationDelta*/ 0, sourceFile, options); @@ -51182,7 +51417,7 @@ var ts; currentStart = parentStart; parent = current.parent; } - return indentationDelta; + return indentationDelta + getBaseIndentation(options); } function getParentStart(parent, child, sourceFile) { var containingList = getContainingList(child, sourceFile); @@ -51440,7 +51675,10 @@ var ts; case 164 /* ParenthesizedType */: case 176 /* TaggedTemplateExpression */: case 184 /* AwaitExpression */: + case 237 /* NamedExports */: case 233 /* NamedImports */: + case 238 /* ExportSpecifier */: + case 234 /* ImportSpecifier */: return true; } return false; @@ -51463,6 +51701,11 @@ var ts; case 149 /* GetAccessor */: case 150 /* SetAccessor */: return childKind !== 199 /* Block */; + case 236 /* ExportDeclaration */: + return childKind !== 237 /* NamedExports */; + case 230 /* ImportDeclaration */: + return childKind !== 231 /* ImportClause */ || + child.namedBindings.kind !== 233 /* NamedImports */; case 241 /* JsxElement */: return childKind !== 245 /* JsxClosingElement */; } @@ -52468,9 +52711,9 @@ var ts; return false; } // If the parent is not sourceFile or module block it is local variable - for (var parent_15 = declaration.parent; !ts.isFunctionBlock(parent_15); parent_15 = parent_15.parent) { + for (var parent_16 = declaration.parent; !ts.isFunctionBlock(parent_16); parent_16 = parent_16.parent) { // Reached source file or module block - if (parent_15.kind === 256 /* SourceFile */ || parent_15.kind === 226 /* ModuleBlock */) { + if (parent_16.kind === 256 /* SourceFile */ || parent_16.kind === 226 /* ModuleBlock */) { return false; } } @@ -52601,7 +52844,7 @@ var ts; return typeof o.type === "object" && !ts.forEachValue(o.type, function (v) { return typeof v !== "number"; }); }); options = ts.clone(options); - var _loop_2 = function(opt) { + var _loop_3 = function(opt) { if (!ts.hasProperty(options, opt.name)) { return "continue"; } @@ -52620,7 +52863,7 @@ var ts; }; for (var _i = 0, commandLineOptionsStringToEnum_1 = commandLineOptionsStringToEnum; _i < commandLineOptionsStringToEnum_1.length; _i++) { var opt = commandLineOptionsStringToEnum_1[_i]; - _loop_2(opt); + _loop_3(opt); } return options; } @@ -53821,13 +54064,13 @@ var ts; log("Returning an empty list because completion was requested in an invalid position."); return undefined; } - var parent_16 = contextToken.parent, kind = contextToken.kind; + var parent_17 = contextToken.parent, kind = contextToken.kind; if (kind === 21 /* DotToken */) { - if (parent_16.kind === 172 /* PropertyAccessExpression */) { + if (parent_17.kind === 172 /* PropertyAccessExpression */) { node = contextToken.parent.expression; isRightOfDot = true; } - else if (parent_16.kind === 139 /* QualifiedName */) { + else if (parent_17.kind === 139 /* QualifiedName */) { node = contextToken.parent.left; isRightOfDot = true; } @@ -54203,9 +54446,9 @@ var ts; switch (contextToken.kind) { case 15 /* OpenBraceToken */: // const x = { | case 24 /* CommaToken */: - var parent_17 = contextToken.parent; - if (parent_17 && (parent_17.kind === 171 /* ObjectLiteralExpression */ || parent_17.kind === 167 /* ObjectBindingPattern */)) { - return parent_17; + var parent_18 = contextToken.parent; + if (parent_18 && (parent_18.kind === 171 /* ObjectLiteralExpression */ || parent_18.kind === 167 /* ObjectBindingPattern */)) { + return parent_18; } break; } @@ -54232,37 +54475,37 @@ var ts; } function tryGetContainingJsxElement(contextToken) { if (contextToken) { - var parent_18 = contextToken.parent; + var parent_19 = contextToken.parent; switch (contextToken.kind) { case 26 /* LessThanSlashToken */: case 39 /* SlashToken */: case 69 /* Identifier */: case 246 /* JsxAttribute */: case 247 /* JsxSpreadAttribute */: - if (parent_18 && (parent_18.kind === 242 /* JsxSelfClosingElement */ || parent_18.kind === 243 /* JsxOpeningElement */)) { - return parent_18; + if (parent_19 && (parent_19.kind === 242 /* JsxSelfClosingElement */ || parent_19.kind === 243 /* JsxOpeningElement */)) { + return parent_19; } - else if (parent_18.kind === 246 /* JsxAttribute */) { - return parent_18.parent; + else if (parent_19.kind === 246 /* JsxAttribute */) { + return parent_19.parent; } break; // The context token is the closing } or " of an attribute, which means // its parent is a JsxExpression, whose parent is a JsxAttribute, // whose parent is a JsxOpeningLikeElement case 9 /* StringLiteral */: - if (parent_18 && ((parent_18.kind === 246 /* JsxAttribute */) || (parent_18.kind === 247 /* JsxSpreadAttribute */))) { - return parent_18.parent; + if (parent_19 && ((parent_19.kind === 246 /* JsxAttribute */) || (parent_19.kind === 247 /* JsxSpreadAttribute */))) { + return parent_19.parent; } break; case 16 /* CloseBraceToken */: - if (parent_18 && - parent_18.kind === 248 /* JsxExpression */ && - parent_18.parent && - (parent_18.parent.kind === 246 /* JsxAttribute */)) { - return parent_18.parent.parent; + if (parent_19 && + parent_19.kind === 248 /* JsxExpression */ && + parent_19.parent && + (parent_19.parent.kind === 246 /* JsxAttribute */)) { + return parent_19.parent.parent; } - if (parent_18 && parent_18.kind === 247 /* JsxSpreadAttribute */) { - return parent_18.parent; + if (parent_19 && parent_19.kind === 247 /* JsxSpreadAttribute */) { + return parent_19.parent; } break; } @@ -55594,19 +55837,19 @@ var ts; function getThrowStatementOwner(throwStatement) { var child = throwStatement; while (child.parent) { - var parent_19 = child.parent; - if (ts.isFunctionBlock(parent_19) || parent_19.kind === 256 /* SourceFile */) { - return parent_19; + var parent_20 = child.parent; + if (ts.isFunctionBlock(parent_20) || parent_20.kind === 256 /* SourceFile */) { + return parent_20; } // A throw-statement is only owned by a try-statement if the try-statement has // a catch clause, and if the throw-statement occurs within the try block. - if (parent_19.kind === 216 /* TryStatement */) { - var tryStatement = parent_19; + if (parent_20.kind === 216 /* TryStatement */) { + var tryStatement = parent_20; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; } } - child = parent_19; + child = parent_20; } return undefined; } @@ -55986,16 +56229,31 @@ var ts; if (node === sourceFile) { return undefined; } - if (node.kind !== 69 /* Identifier */ && - // TODO (drosen): This should be enabled in a later release - currently breaks rename. - // node.kind !== SyntaxKind.ThisKeyword && - // node.kind !== SyntaxKind.SuperKeyword && - node.kind !== 9 /* StringLiteral */ && - !isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { - return undefined; + switch (node.kind) { + case 8 /* NumericLiteral */: + if (!isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { + break; + } + // Fallthrough + case 69 /* Identifier */: + case 97 /* ThisKeyword */: + // case SyntaxKind.SuperKeyword: TODO:GH#9268 + case 9 /* StringLiteral */: + return getReferencedSymbolsForNode(node, program.getSourceFiles(), findInStrings, findInComments); + } + return undefined; + } + function isThis(node) { + switch (node.kind) { + case 97 /* ThisKeyword */: + // case SyntaxKind.ThisType: TODO: GH#9267 + return true; + case 69 /* Identifier */: + // 'this' as a parameter + return node.originalKeywordKind === 97 /* ThisKeyword */ && node.parent.kind === 142 /* Parameter */; + default: + return false; } - ts.Debug.assert(node.kind === 69 /* Identifier */ || node.kind === 8 /* NumericLiteral */ || node.kind === 9 /* StringLiteral */); - return getReferencedSymbolsForNode(node, program.getSourceFiles(), findInStrings, findInComments); } function getReferencedSymbolsForNode(node, sourceFiles, findInStrings, findInComments) { var typeChecker = program.getTypeChecker(); @@ -56012,7 +56270,7 @@ var ts; return getLabelReferencesInNode(node.parent, node); } } - if (node.kind === 97 /* ThisKeyword */ || node.kind === 165 /* ThisType */) { + if (isThis(node)) { return getReferencesForThisKeyword(node, sourceFiles); } if (node.kind === 95 /* SuperKeyword */) { @@ -56447,7 +56705,7 @@ var ts; ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); var node = ts.getTouchingWord(sourceFile, position); - if (!node || (node.kind !== 97 /* ThisKeyword */ && node.kind !== 165 /* ThisType */)) { + if (!node || !isThis(node)) { return; } var container = ts.getThisContainer(node, /* includeArrowFunctions */ false); @@ -57453,8 +57711,8 @@ var ts; return; case 142 /* Parameter */: if (token.parent.name === token) { - var isThis = token.kind === 69 /* Identifier */ && token.originalKeywordKind === 97 /* ThisKeyword */; - return isThis ? 3 /* keyword */ : 17 /* parameterName */; + var isThis_1 = token.kind === 69 /* Identifier */ && token.originalKeywordKind === 97 /* ThisKeyword */; + return isThis_1 ? 3 /* keyword */ : 17 /* parameterName */; } return; } @@ -57645,7 +57903,7 @@ var ts; (tokenStart === position ? newLine + indentationStr : ""); return { newText: result, caretOffset: preamble.length }; } - function isValidBraceCompletionAtPostion(fileName, position, openingBrace) { + function isValidBraceCompletionAtPosition(fileName, position, openingBrace) { // '<' is currently not supported, figuring out if we're in a Generic Type vs. a comparison is too // expensive to do during typing scenarios // i.e. whether we're dealing with: @@ -57847,11 +58105,11 @@ var ts; var defaultLibFileName = host.getDefaultLibFileName(host.getCompilationSettings()); var canonicalDefaultLibName = getCanonicalFileName(ts.normalizePath(defaultLibFileName)); var node = ts.getTouchingWord(sourceFile, position, /*includeJsDocComment*/ true); - // Can only rename an identifier. if (node) { if (node.kind === 69 /* Identifier */ || node.kind === 9 /* StringLiteral */ || - isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { + isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || + isThis(node)) { var symbol = typeChecker.getSymbolAtLocation(node); // Only allow a symbol to be renamed if it actually has at least one declaration. if (symbol) { @@ -57965,7 +58223,7 @@ var ts; getFormattingEditsForDocument: getFormattingEditsForDocument, getFormattingEditsAfterKeystroke: getFormattingEditsAfterKeystroke, getDocCommentTemplateAtPosition: getDocCommentTemplateAtPosition, - isValidBraceCompletionAtPostion: isValidBraceCompletionAtPostion, + isValidBraceCompletionAtPosition: isValidBraceCompletionAtPosition, getEmitOutput: getEmitOutput, getNonBoundSourceFile: getNonBoundSourceFile, getProgram: getProgram @@ -59503,9 +59761,9 @@ var ts; var _this = this; return this.forwardJSONCall("getBraceMatchingAtPosition('" + fileName + "', " + position + ")", function () { return _this.languageService.getBraceMatchingAtPosition(fileName, position); }); }; - LanguageServiceShimObject.prototype.isValidBraceCompletionAtPostion = function (fileName, position, openingBrace) { + LanguageServiceShimObject.prototype.isValidBraceCompletionAtPosition = function (fileName, position, openingBrace) { var _this = this; - return this.forwardJSONCall("isValidBraceCompletionAtPostion('" + fileName + "', " + position + ", " + openingBrace + ")", function () { return _this.languageService.isValidBraceCompletionAtPostion(fileName, position, openingBrace); }); + return this.forwardJSONCall("isValidBraceCompletionAtPosition('" + fileName + "', " + position + ", " + openingBrace + ")", function () { return _this.languageService.isValidBraceCompletionAtPosition(fileName, position, openingBrace); }); }; /// GET SMART INDENT LanguageServiceShimObject.prototype.getIndentationAtPosition = function (fileName, position, options /*Services.EditorOptions*/) { diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts index 76690ff9d0f..e69723c237d 100644 --- a/lib/typescriptServices.d.ts +++ b/lib/typescriptServices.d.ts @@ -753,9 +753,10 @@ declare namespace ts { children: NodeArray; closingElement: JsxClosingElement; } + type JsxTagNameExpression = PrimaryExpression | PropertyAccessExpression; interface JsxOpeningElement extends Expression { _openingElementBrand?: any; - tagName: EntityName; + tagName: JsxTagNameExpression; attributes: NodeArray; } interface JsxSelfClosingElement extends PrimaryExpression, JsxOpeningElement { @@ -770,7 +771,7 @@ declare namespace ts { expression: Expression; } interface JsxClosingElement extends Node { - tagName: EntityName; + tagName: JsxTagNameExpression; } interface JsxExpression extends Expression { expression?: Expression; @@ -1271,7 +1272,7 @@ declare namespace ts { buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildTypePredicateDisplay(predicate: TypePredicate, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; - buildDisplayForParametersAndDelimiters(thisType: Type, parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; + buildDisplayForParametersAndDelimiters(thisParameter: Symbol, parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags): void; } @@ -1483,7 +1484,6 @@ declare namespace ts { declaration: SignatureDeclaration; typeParameters: TypeParameter[]; parameters: Symbol[]; - thisType?: Type; } enum IndexKind { String = 0, @@ -1564,6 +1564,8 @@ declare namespace ts { noImplicitAny?: boolean; noImplicitReturns?: boolean; noImplicitThis?: boolean; + noUnusedLocals?: boolean; + noUnusedParameters?: boolean; noImplicitUseStrict?: boolean; noLib?: boolean; noResolve?: boolean; @@ -1590,7 +1592,6 @@ declare namespace ts { types?: string[]; /** Paths used to used to compute primary types search locations */ typeRoots?: string[]; - typesSearchPaths?: string[]; [option: string]: CompilerOptionsValue | undefined; } interface TypingOptions { @@ -2055,7 +2056,7 @@ declare namespace ts { getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions): TextChange[]; getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions): TextChange[]; getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion; - isValidBraceCompletionAtPostion(fileName: string, position: number, openingBrace: number): boolean; + isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean; getEmitOutput(fileName: string): EmitOutput; getProgram(): Program; dispose(): void; @@ -2133,6 +2134,7 @@ declare namespace ts { containerKind: string; } interface EditorOptions { + BaseIndentSize?: number; IndentSize: number; TabSize: number; NewLineCharacter: string; @@ -2155,7 +2157,7 @@ declare namespace ts { InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; PlaceOpenBraceOnNewLineForFunctions: boolean; PlaceOpenBraceOnNewLineForControlBlocks: boolean; - [s: string]: boolean | number | string; + [s: string]: boolean | number | string | undefined; } interface DefinitionInfo { fileName: string; diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 30d49888df1..d4d4c481c81 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -3300,6 +3300,9 @@ var ts; Resolving_real_path_for_0_result_1: { code: 6130, category: ts.DiagnosticCategory.Message, key: "Resolving_real_path_for_0_result_1_6130", message: "Resolving real path for '{0}', result '{1}'" }, Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system: { code: 6131, category: ts.DiagnosticCategory.Error, key: "Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system_6131", message: "Cannot compile modules using option '{0}' unless the '--module' flag is 'amd' or 'system'." }, File_name_0_has_a_1_extension_stripping_it: { code: 6132, category: ts.DiagnosticCategory.Message, key: "File_name_0_has_a_1_extension_stripping_it_6132", message: "File name '{0}' has a '{1}' extension - stripping it" }, + _0_is_declared_but_never_used: { code: 6133, category: ts.DiagnosticCategory.Error, key: "_0_is_declared_but_never_used_6133", message: "'{0}' is declared but never used." }, + Report_Errors_on_Unused_Locals: { code: 6134, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Locals_6134", message: "Report Errors on Unused Locals." }, + Report_Errors_on_Unused_Parameters: { code: 6135, category: ts.DiagnosticCategory.Message, key: "Report_Errors_on_Unused_Parameters_6135", message: "Report Errors on Unused Parameters." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable_0_implicitly_has_an_1_type_7005", message: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter_0_implicitly_has_an_1_type_7006", message: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member_0_implicitly_has_an_1_type_7008", message: "Member '{0}' implicitly has an '{1}' type." }, @@ -11077,8 +11080,14 @@ var ts; if (lhs.kind === 69 /* Identifier */) { return lhs.text === rhs.text; } - return lhs.right.text === rhs.right.text && - tagNamesAreEquivalent(lhs.left, rhs.left); + if (lhs.kind === 97 /* ThisKeyword */) { + return true; + } + // If we are at this statement then we must have PropertyAccessExpression and because tag name in Jsx element can only + // take forms of JsxTagNameExpression which includes an identifier, "this" expression, or another propertyAccessExpression + // it is safe to case the expression property as such. See parseJsxElementName for how we parse tag name in Jsx element + return lhs.name.text === rhs.name.text && + tagNamesAreEquivalent(lhs.expression, rhs.expression); } function parseJsxElementOrSelfClosingElement(inExpressionContext) { var opening = parseJsxOpeningOrSelfClosingElement(inExpressionContext); @@ -11189,15 +11198,20 @@ var ts; } function parseJsxElementName() { scanJsxIdentifier(); - var elementName = parseIdentifierName(); + // JsxElement can have name in the form of + // propertyAccessExpression + // primaryExpression in the form of an identifier and "this" keyword + // We can't just simply use parseLeftHandSideExpressionOrHigher because then we will start consider class,function etc as a keyword + // We only want to consider "this" as a primaryExpression + var expression = token === 97 /* ThisKeyword */ ? + parseTokenNode() : parseIdentifierName(); while (parseOptional(21 /* DotToken */)) { - scanJsxIdentifier(); - var node = createNode(139 /* QualifiedName */, elementName.pos); // !!! - node.left = elementName; - node.right = parseIdentifierName(); - elementName = finishNode(node); + var propertyAccess = createNode(172 /* PropertyAccessExpression */, expression.pos); + propertyAccess.expression = expression; + propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true); + expression = finishNode(propertyAccess); } - return elementName; + return expression; } function parseJsxExpression(inExpressionContext) { var node = createNode(248 /* JsxExpression */); @@ -12058,7 +12072,7 @@ var ts; case 56 /* EqualsToken */: return parseExportAssignment(fullStart, decorators, modifiers); case 116 /* AsKeyword */: - return parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers); + return parseNamespaceExportDeclaration(fullStart, decorators, modifiers); default: return parseExportDeclaration(fullStart, decorators, modifiers); } @@ -12647,7 +12661,7 @@ var ts; function nextTokenIsSlash() { return nextToken() === 39 /* SlashToken */; } - function parseGlobalModuleExportDeclaration(fullStart, decorators, modifiers) { + function parseNamespaceExportDeclaration(fullStart, decorators, modifiers) { var exportDeclaration = createNode(228 /* NamespaceExportDeclaration */, fullStart); exportDeclaration.decorators = decorators; exportDeclaration.modifiers = modifiers; @@ -17123,7 +17137,7 @@ var ts; function getTargetOfImportSpecifier(node) { return getExternalModuleMember(node.parent.parent.parent, node); } - function getTargetOfGlobalModuleExportDeclaration(node) { + function getTargetOfNamespaceExportDeclaration(node) { return resolveExternalModuleSymbol(node.parent.symbol); } function getTargetOfExportSpecifier(node) { @@ -17149,7 +17163,7 @@ var ts; case 235 /* ExportAssignment */: return getTargetOfExportAssignment(node); case 228 /* NamespaceExportDeclaration */: - return getTargetOfGlobalModuleExportDeclaration(node); + return getTargetOfNamespaceExportDeclaration(node); } } function resolveSymbol(symbol) { @@ -17249,9 +17263,12 @@ var ts; var left = name.kind === 139 /* QualifiedName */ ? name.left : name.expression; var right = name.kind === 139 /* QualifiedName */ ? name.right : name.name; var namespace = resolveEntityName(left, 1536 /* Namespace */, ignoreErrors); - if (!namespace || namespace === unknownSymbol || ts.nodeIsMissing(right)) { + if (!namespace || ts.nodeIsMissing(right)) { return undefined; } + else if (namespace === unknownSymbol) { + return namespace; + } symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { if (!ignoreErrors) { @@ -18332,16 +18349,13 @@ var ts; writePunctuation(writer, 27 /* GreaterThanToken */); } } - function buildDisplayForParametersAndDelimiters(thisType, parameters, writer, enclosingDeclaration, flags, symbolStack) { + function buildDisplayForParametersAndDelimiters(thisParameter, parameters, writer, enclosingDeclaration, flags, symbolStack) { writePunctuation(writer, 17 /* OpenParenToken */); - if (thisType) { - writeKeyword(writer, 97 /* ThisKeyword */); - writePunctuation(writer, 54 /* ColonToken */); - writeSpace(writer); - buildTypeDisplay(thisType, writer, enclosingDeclaration, flags, symbolStack); + if (thisParameter) { + buildParameterDisplay(thisParameter, writer, enclosingDeclaration, flags, symbolStack); } for (var i = 0; i < parameters.length; i++) { - if (i > 0 || thisType) { + if (i > 0 || thisParameter) { writePunctuation(writer, 24 /* CommaToken */); writeSpace(writer); } @@ -18391,7 +18405,7 @@ var ts; else { buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.thisType, signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildDisplayForParametersAndDelimiters(signature.thisParameter, signature.parameters, writer, enclosingDeclaration, flags, symbolStack); buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { @@ -18787,12 +18801,14 @@ var ts; if (func.kind === 150 /* SetAccessor */ && !ts.hasDynamicName(func)) { var getter = ts.getDeclarationOfKind(declaration.parent.symbol, 149 /* GetAccessor */); if (getter) { - var signature = getSignatureFromDeclaration(getter); + var getterSignature = getSignatureFromDeclaration(getter); var thisParameter = getAccessorThisParameter(func); if (thisParameter && declaration === thisParameter) { - return signature.thisType; + // Use the type from the *getter* + ts.Debug.assert(!thisParameter.type); + return getTypeOfSymbol(getterSignature.thisParameter); } - return getReturnTypeOfSignature(signature); + return getReturnTypeOfSignature(getterSignature); } } // Use contextual parameter type if one is available @@ -18993,14 +19009,12 @@ var ts; } return undefined; } - function getAnnotatedAccessorThisType(accessor) { - if (accessor) { - var parameter = getAccessorThisParameter(accessor); - if (parameter && parameter.type) { - return getTypeFromTypeNode(accessor.parameters[0].type); - } - } - return undefined; + function getAnnotatedAccessorThisParameter(accessor) { + var parameter = getAccessorThisParameter(accessor); + return parameter && parameter.symbol; + } + function getThisTypeOfDeclaration(declaration) { + return getThisTypeOfSignature(getSignatureFromDeclaration(declaration)); } function getTypeOfAccessors(symbol) { var links = getSymbolLinks(symbol); @@ -19641,12 +19655,12 @@ var ts; type.typeArguments : ts.concatenate(type.typeArguments, [type]); resolveObjectTypeMembers(type, source, typeParameters, typeArguments); } - function createSignature(declaration, typeParameters, thisType, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { + function createSignature(declaration, typeParameters, thisParameter, parameters, resolvedReturnType, typePredicate, minArgumentCount, hasRestParameter, hasStringLiterals) { var sig = new Signature(checker); sig.declaration = declaration; sig.typeParameters = typeParameters; sig.parameters = parameters; - sig.thisType = thisType; + sig.thisParameter = thisParameter; sig.resolvedReturnType = resolvedReturnType; sig.typePredicate = typePredicate; sig.minArgumentCount = minArgumentCount; @@ -19655,7 +19669,7 @@ var ts; return sig; } function cloneSignature(sig) { - return createSignature(sig.declaration, sig.typeParameters, sig.thisType, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); + return createSignature(sig.declaration, sig.typeParameters, sig.thisParameter, sig.parameters, sig.resolvedReturnType, sig.typePredicate, sig.minArgumentCount, sig.hasRestParameter, sig.hasStringLiterals); } function getDefaultConstructSignatures(classType) { var baseConstructorType = getBaseConstructorTypeOfClass(classType); @@ -19749,8 +19763,9 @@ var ts; // Union the result types when more than one signature matches if (unionSignatures.length > 1) { s = cloneSignature(signature); - if (ts.forEach(unionSignatures, function (sig) { return sig.thisType; })) { - s.thisType = getUnionType(ts.map(unionSignatures, function (sig) { return sig.thisType || anyType; })); + if (ts.forEach(unionSignatures, function (sig) { return sig.thisParameter; })) { + var thisType = getUnionType(ts.map(unionSignatures, function (sig) { return getTypeOfSymbol(sig.thisParameter) || anyType; })); + s.thisParameter = createTransientSymbol(signature.thisParameter, thisType); } // Clear resolved return type we possibly got from cloneSignature s.resolvedReturnType = undefined; @@ -19960,6 +19975,7 @@ var ts; var props; // Flags we want to propagate to the result if they exist in all source symbols var commonFlags = (containingType.flags & 32768 /* Intersection */) ? 536870912 /* Optional */ : 0 /* None */; + var isReadonly = false; for (var _i = 0, types_2 = types; _i < types_2.length; _i++) { var current = types_2[_i]; var type = getApparentType(current); @@ -19973,6 +19989,9 @@ var ts; else if (!ts.contains(props, prop)) { props.push(prop); } + if (isReadonlySymbol(prop)) { + isReadonly = true; + } } else if (containingType.flags & 16384 /* Union */) { // A union type requires the property to be present in all constituent types @@ -20001,6 +20020,7 @@ var ts; commonFlags, name); result.containingType = containingType; result.declarations = declarations; + result.isReadonly = isReadonly; result.type = containingType.flags & 16384 /* Union */ ? getUnionType(propTypes) : getIntersectionType(propTypes); return result; } @@ -20172,7 +20192,7 @@ var ts; var parameters = []; var hasStringLiterals = false; var minArgumentCount = -1; - var thisType = undefined; + var thisParameter = undefined; var hasThisParameter = void 0; var isJSConstructSignature = ts.isJSDocConstructSignature(declaration); // If this is a JSDoc construct signature, then skip the first parameter in the @@ -20188,7 +20208,7 @@ var ts; } if (i === 0 && paramSymbol.name === "this") { hasThisParameter = true; - thisType = param.type ? getTypeFromTypeNode(param.type) : unknownType; + thisParameter = param.symbol; } else { parameters.push(paramSymbol); @@ -20209,10 +20229,12 @@ var ts; // If only one accessor includes a this-type annotation, the other behaves as if it had the same type annotation if ((declaration.kind === 149 /* GetAccessor */ || declaration.kind === 150 /* SetAccessor */) && !ts.hasDynamicName(declaration) && - (!hasThisParameter || thisType === unknownType)) { + (!hasThisParameter || !thisParameter)) { var otherKind = declaration.kind === 149 /* GetAccessor */ ? 150 /* SetAccessor */ : 149 /* GetAccessor */; - var setter = ts.getDeclarationOfKind(declaration.symbol, otherKind); - thisType = getAnnotatedAccessorThisType(setter); + var other = ts.getDeclarationOfKind(declaration.symbol, otherKind); + if (other) { + thisParameter = getAnnotatedAccessorThisParameter(other); + } } if (minArgumentCount < 0) { minArgumentCount = declaration.parameters.length - (hasThisParameter ? 1 : 0); @@ -20230,7 +20252,7 @@ var ts; var typePredicate = declaration.type && declaration.type.kind === 154 /* TypePredicate */ ? createTypePredicateFromTypePredicateNode(declaration.type) : undefined; - links.resolvedSignature = createSignature(declaration, typeParameters, thisType, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); + links.resolvedSignature = createSignature(declaration, typeParameters, thisParameter, parameters, returnType, typePredicate, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); } return links.resolvedSignature; } @@ -20305,6 +20327,11 @@ var ts; } return anyType; } + function getThisTypeOfSignature(signature) { + if (signature.thisParameter) { + return getTypeOfSymbol(signature.thisParameter); + } + } function getReturnTypeOfSignature(signature) { if (!signature.resolvedReturnType) { if (!pushTypeResolution(signature, 3 /* ResolvedReturnType */)) { @@ -21080,7 +21107,7 @@ var ts; if (signature.typePredicate) { freshTypePredicate = cloneTypePredicate(signature.typePredicate, mapper); } - var result = createSignature(signature.declaration, freshTypeParameters, signature.thisType && instantiateType(signature.thisType, mapper), instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); + var result = createSignature(signature.declaration, freshTypeParameters, signature.thisParameter && instantiateSymbol(signature.thisParameter, mapper), instantiateList(signature.parameters, mapper, instantiateSymbol), instantiateType(signature.resolvedReturnType, mapper), freshTypePredicate, signature.minArgumentCount, signature.hasRestParameter, signature.hasStringLiterals); result.target = signature; result.mapper = mapper; return result; @@ -21315,17 +21342,21 @@ var ts; source = getErasedSignature(source); target = getErasedSignature(target); var result = -1 /* True */; - if (source.thisType && target.thisType && source.thisType !== voidType) { - // void sources are assignable to anything. - var related = compareTypes(source.thisType, target.thisType, /*reportErrors*/ false) - || compareTypes(target.thisType, source.thisType, reportErrors); - if (!related) { - if (reportErrors) { - errorReporter(ts.Diagnostics.The_this_types_of_each_signature_are_incompatible); + var sourceThisType = getThisTypeOfSignature(source); + if (sourceThisType && sourceThisType !== voidType) { + var targetThisType = getThisTypeOfSignature(target); + if (targetThisType) { + // void sources are assignable to anything. + var related = compareTypes(sourceThisType, targetThisType, /*reportErrors*/ false) + || compareTypes(targetThisType, sourceThisType, reportErrors); + if (!related) { + if (reportErrors) { + errorReporter(ts.Diagnostics.The_this_types_of_each_signature_are_incompatible); + } + return 0 /* False */; } - return 0 /* False */; + result &= related; } - result &= related; } var sourceMax = getNumNonRestParameters(source); var targetMax = getNumNonRestParameters(target); @@ -22265,12 +22296,18 @@ var ts; source = getErasedSignature(source); target = getErasedSignature(target); var result = -1 /* True */; - if (!ignoreThisTypes && source.thisType && target.thisType) { - var related = compareTypes(source.thisType, target.thisType); - if (!related) { - return 0 /* False */; + if (!ignoreThisTypes) { + var sourceThisType = getThisTypeOfSignature(source); + if (sourceThisType) { + var targetThisType = getThisTypeOfSignature(target); + if (targetThisType) { + var related = compareTypes(sourceThisType, targetThisType); + if (!related) { + return 0 /* False */; + } + result &= related; + } } - result &= related; } var targetLen = target.parameters.length; for (var i = 0; i < targetLen; i++) { @@ -23698,8 +23735,20 @@ var ts; } return container === declarationContainer; } + function updateReferencesForInterfaceHeritiageClauseTargets(node) { + var extendedTypeNode = ts.getClassExtendsHeritageClauseElement(node); + if (extendedTypeNode) { + var t = getTypeFromTypeNode(extendedTypeNode); + if (t !== unknownType && t.symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + t.symbol.hasReference = true; + } + } + } function checkIdentifier(node) { var symbol = getResolvedSymbol(node); + if (symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.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 // arguments objects will be bound to the inner object; emitting arrow function natively in ES6, arguments objects @@ -23963,9 +24012,9 @@ var ts; if (type) { return type; } - var signature = getSignatureFromDeclaration(container); - if (signature.thisType) { - return signature.thisType; + var thisType = getThisTypeOfDeclaration(container); + if (thisType) { + return thisType; } } if (ts.isClassLike(container.parent)) { @@ -24184,7 +24233,7 @@ var ts; if (isContextSensitiveFunctionOrObjectLiteralMethod(func) && func.kind !== 180 /* ArrowFunction */) { var contextualSignature = getContextualSignature(func); if (contextualSignature) { - return contextualSignature.thisType; + return getThisTypeOfSignature(contextualSignature); } } return undefined; @@ -24917,7 +24966,8 @@ var ts; * Returns true iff React would emit this tag name as a string rather than an identifier or qualified name */ function isJsxIntrinsicIdentifier(tagName) { - if (tagName.kind === 139 /* QualifiedName */) { + // TODO (yuisu): comment + if (tagName.kind === 172 /* PropertyAccessExpression */ || tagName.kind === 97 /* ThisKeyword */) { return false; } else { @@ -25093,6 +25143,28 @@ var ts; return getResolvedJsxType(node, type, elemClassType); })); } + // If the elemType is a string type, we have to return anyType to prevent an error downstream as we will try to find construct or call signature of the type + if (elemType.flags & 2 /* String */) { + return anyType; + } + else if (elemType.flags & 256 /* StringLiteral */) { + // If the elemType is a stringLiteral type, we can then provide a check to make sure that the string literal type is one of the Jsx intrinsic element type + var intrinsicElementsType = getJsxType(JsxNames.IntrinsicElements); + if (intrinsicElementsType !== unknownType) { + var stringLiteralTypeName = elemType.text; + var intrinsicProp = getPropertyOfType(intrinsicElementsType, stringLiteralTypeName); + if (intrinsicProp) { + return getTypeOfSymbol(intrinsicProp); + } + var indexSignatureType = getIndexTypeOfType(intrinsicElementsType, 0 /* String */); + if (indexSignatureType) { + return indexSignatureType; + } + error(node, ts.Diagnostics.Property_0_does_not_exist_on_type_1, stringLiteralTypeName, "JSX." + JsxNames.IntrinsicElements); + } + // If we need to report an error, we already done so here. So just return any to prevent any more error downstream + return anyType; + } // Get the element instance type (the result of newing or invoking this tag) var elemInstanceType = getJsxElementInstanceType(node, elemType); if (!elemClassType || !isTypeAssignableTo(elemInstanceType, elemClassType)) { @@ -25401,6 +25473,9 @@ var ts; } return unknownType; } + if ((compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + prop.hasReference = true; + } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & 32 /* Class */) { checkClassPropertyAccess(node, left, apparentType, prop); @@ -25806,10 +25881,11 @@ var ts; if (context.failedTypeParameterIndex !== undefined && !context.inferences[context.failedTypeParameterIndex].isFixed) { context.failedTypeParameterIndex = undefined; } - if (signature.thisType) { + var thisType = getThisTypeOfSignature(signature); + if (thisType) { var thisArgumentNode = getThisArgumentOfCall(node); var thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType; - inferTypes(context, thisArgumentType, signature.thisType); + inferTypes(context, thisArgumentType, thisType); } // We perform two passes over the arguments. In the first pass we infer from all arguments, but use // wildcards for all context sensitive function expressions. @@ -25873,7 +25949,8 @@ var ts; return typeArgumentsAreAssignable; } function checkApplicableSignature(node, args, signature, relation, excludeArgument, reportErrors) { - if (signature.thisType && signature.thisType !== voidType && node.kind !== 175 /* NewExpression */) { + var thisType = getThisTypeOfSignature(signature); + if (thisType && thisType !== voidType && node.kind !== 175 /* NewExpression */) { // If the called expression is not of the form `x.f` or `x["f"]`, then sourceType = voidType // If the signature's 'this' type is voidType, then the check is skipped -- anything is compatible. // If the expression is a new expression, then the check is skipped. @@ -25881,7 +25958,7 @@ var ts; var thisArgumentType = thisArgumentNode ? checkExpression(thisArgumentNode) : voidType; var errorNode = reportErrors ? (thisArgumentNode || node) : undefined; var headMessage_1 = ts.Diagnostics.The_this_context_of_type_0_is_not_assignable_to_method_s_this_of_type_1; - if (!checkTypeRelatedTo(thisArgumentType, signature.thisType, relation, errorNode, headMessage_1)) { + if (!checkTypeRelatedTo(thisArgumentType, getThisTypeOfSignature(signature), relation, errorNode, headMessage_1)) { return false; } } @@ -26526,7 +26603,7 @@ var ts; if (getReturnTypeOfSignature(signature) !== voidType) { error(node, ts.Diagnostics.Only_a_void_function_can_be_called_with_the_new_keyword); } - if (signature.thisType === voidType) { + if (getThisTypeOfSignature(signature) === voidType) { error(node, ts.Diagnostics.A_function_that_is_called_with_the_new_keyword_cannot_have_a_this_type_that_is_void); } return signature; @@ -27126,6 +27203,8 @@ var ts; } } } + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); } } function checkArithmeticOperandType(operand, type, diagnostic) { @@ -27141,7 +27220,9 @@ var ts; // Variables declared with 'const' // Get accessors without matching set accessors // Enum members - return symbol.flags & 4 /* Property */ && (getDeclarationFlagsFromSymbol(symbol) & 64 /* Readonly */) !== 0 || + // Unions and intersections of the above (unions and intersections eagerly set isReadonly on creation) + return symbol.isReadonly || + symbol.flags & 4 /* Property */ && (getDeclarationFlagsFromSymbol(symbol) & 64 /* Readonly */) !== 0 || symbol.flags & 3 /* Variable */ && (getDeclarationFlagsFromSymbol(symbol) & 2048 /* Const */) !== 0 || symbol.flags & 98304 /* Accessor */ && !(symbol.flags & 65536 /* SetAccessor */) || (symbol.flags & 8 /* EnumMember */) !== 0; @@ -28089,6 +28170,9 @@ var ts; checkAsyncFunctionReturnType(node); } } + if (!node.body) { + checkUnusedTypeParameters(node); + } } } function checkClassForDuplicateDeclarations(node) { @@ -28228,6 +28312,8 @@ var ts; // Grammar check for checking only related to constructorDeclaration checkGrammarConstructorTypeParameters(node) || checkGrammarConstructorTypeAnnotation(node); checkSourceElement(node.body); + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); var symbol = getSymbolOfNode(node); var firstDeclaration = ts.getDeclarationOfKind(symbol, node.kind); // Only type check the symbol once @@ -28351,7 +28437,7 @@ var ts; // TypeScript 1.0 spec (April 2014): 4.5 // If both accessors include type annotations, the specified types must be identical. checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorType, ts.Diagnostics.get_and_set_accessor_must_have_the_same_type); - checkAccessorDeclarationTypesIdentical(node, otherAccessor, getAnnotatedAccessorThisType, ts.Diagnostics.get_and_set_accessor_must_have_the_same_this_type); + checkAccessorDeclarationTypesIdentical(node, otherAccessor, getThisTypeOfDeclaration, ts.Diagnostics.get_and_set_accessor_must_have_the_same_this_type); } } getTypeOfAccessors(getSymbolOfNode(node)); @@ -28396,13 +28482,18 @@ var ts; function checkTypeReferenceNode(node) { checkGrammarTypeArguments(node, node.typeArguments); var type = getTypeFromTypeReference(node); - if (type !== unknownType && node.typeArguments) { - // Do type argument local checks only if referenced type is successfully resolved - ts.forEach(node.typeArguments, checkSourceElement); - if (produceDiagnostics) { - var symbol = getNodeLinks(node).resolvedSymbol; - var typeParameters = symbol.flags & 524288 /* TypeAlias */ ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; - checkTypeArgumentConstraints(typeParameters, node.typeArguments); + if (type !== unknownType) { + if (type.symbol && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + type.symbol.hasReference = true; + } + if (node.typeArguments) { + // Do type argument local checks only if referenced type is successfully resolved + ts.forEach(node.typeArguments, checkSourceElement); + if (produceDiagnostics) { + var symbol = getNodeLinks(node).resolvedSymbol; + var typeParameters = symbol.flags & 524288 /* TypeAlias */ ? getSymbolLinks(symbol).typeParameters : type.target.localTypeParameters; + checkTypeArgumentConstraints(typeParameters, node.typeArguments); + } } } } @@ -29137,6 +29228,8 @@ var ts; } } checkSourceElement(node.body); + checkUnusedIdentifiers(node); + checkUnusedTypeParameters(node); if (!node.asteriskToken) { var returnOrPromisedType = node.type && (isAsync ? checkAsyncFunctionReturnType(node) : getTypeFromTypeNode(node.type)); checkAllCodePathsInNonVoidFunctionReturnOrThrow(node, returnOrPromisedType); @@ -29155,12 +29248,84 @@ var ts; } } } + function checkUnusedIdentifiers(node) { + if (node.parent.kind !== 222 /* InterfaceDeclaration */ && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + for (var key in node.locals) { + if (ts.hasProperty(node.locals, key)) { + var local = node.locals[key]; + if (!local.hasReference && local.valueDeclaration) { + if (local.valueDeclaration.kind !== 142 /* Parameter */ && compilerOptions.noUnusedLocals) { + error(local.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local.name); + } + else if (local.valueDeclaration.kind === 142 /* Parameter */ && compilerOptions.noUnusedParameters) { + if (local.valueDeclaration.flags === 0) { + error(local.valueDeclaration.name, ts.Diagnostics._0_is_declared_but_never_used, local.name); + } + } + } + } + } + } + } + function checkUnusedClassLocals(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + if (node.members) { + for (var _i = 0, _a = node.members; _i < _a.length; _i++) { + var member = _a[_i]; + if (member.kind === 147 /* MethodDeclaration */ || member.kind === 145 /* PropertyDeclaration */) { + if (isPrivateNode(member) && !member.symbol.hasReference) { + error(member.name, ts.Diagnostics._0_is_declared_but_never_used, member.symbol.name); + } + } + else if (member.kind === 148 /* Constructor */) { + for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { + var parameter = _c[_b]; + if (isPrivateNode(parameter) && !parameter.symbol.hasReference) { + error(parameter.name, ts.Diagnostics._0_is_declared_but_never_used, parameter.symbol.name); + } + } + } + } + } + } + } + function checkUnusedTypeParameters(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + if (node.typeParameters) { + for (var _i = 0, _a = node.typeParameters; _i < _a.length; _i++) { + var typeParameter = _a[_i]; + if (!typeParameter.symbol.hasReference) { + error(typeParameter.name, ts.Diagnostics._0_is_declared_but_never_used, typeParameter.symbol.name); + } + } + } + } + } + function isPrivateNode(node) { + return (node.flags & 8 /* Private */) !== 0; + } + function checkUnusedModuleLocals(node) { + if (compilerOptions.noUnusedLocals && !ts.isInAmbientContext(node)) { + var _loop_1 = function(key) { + if (ts.hasProperty(node.locals, key)) { + var local_1 = node.locals[key]; + if (!local_1.hasReference && !local_1.exportSymbol) { + ts.forEach(local_1.declarations, function (d) { return error(d.name, ts.Diagnostics._0_is_declared_but_never_used, local_1.name); }); + } + } + }; + for (var key in node.locals) { + _loop_1(key); + } + } + } function checkBlock(node) { // Grammar checking for SyntaxKind.Block if (node.kind === 199 /* Block */) { checkGrammarStatementInAmbientContext(node); } ts.forEach(node.statements, checkSourceElement); + checkUnusedIdentifiers(node); } function checkCollisionWithArgumentsInGeneratedCode(node) { // no rest parameters \ declaration context \ overload - no codegen impact @@ -29602,6 +29767,7 @@ var ts; } } checkSourceElement(node.statement); + checkUnusedIdentifiers(node); } function checkForInStatement(node) { // Grammar checking @@ -29643,6 +29809,7 @@ var ts; error(node.expression, ts.Diagnostics.The_right_hand_side_of_a_for_in_statement_must_be_of_type_any_an_object_type_or_a_type_parameter); } checkSourceElement(node.statement); + checkUnusedIdentifiers(node); } function checkForInOrForOfVariableDeclaration(iterationStatement) { var variableDeclarationList = iterationStatement.initializer; @@ -30034,6 +30201,7 @@ var ts; } } checkBlock(catchClause.block); + checkUnusedIdentifiers(catchClause); } if (node.finallyBlock) { checkBlock(node.finallyBlock); @@ -30170,6 +30338,8 @@ var ts; } checkClassLikeDeclaration(node); ts.forEach(node.members, checkSourceElement); + checkUnusedClassLocals(node); + checkUnusedTypeParameters(node); } function checkClassLikeDeclaration(node) { checkGrammarClassDeclarationHeritageClauses(node); @@ -30447,6 +30617,8 @@ var ts; ts.forEach(node.members, checkSourceElement); if (produceDiagnostics) { checkTypeForDuplicateIndexSignatures(node); + updateReferencesForInterfaceHeritiageClauseTargets(node); + checkUnusedTypeParameters(node); } } function checkTypeAliasDeclaration(node) { @@ -30805,6 +30977,7 @@ var ts; } if (node.body) { checkSourceElement(node.body); + checkUnusedModuleLocals(node); } } function checkModuleAugmentationElement(node, isGlobalAugmentation) { @@ -30978,6 +31151,9 @@ var ts; if (target.flags & 793056 /* Type */) { checkTypeNameIsReserved(node.name, ts.Diagnostics.Import_name_cannot_be_0); } + if ((compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters) && !ts.isInAmbientContext(node)) { + target.hasReference = true; + } } } else { @@ -31297,6 +31473,9 @@ var ts; potentialThisCollisions.length = 0; deferredNodes = []; ts.forEach(node.statements, checkSourceElement); + if (ts.isExternalModule(node)) { + checkUnusedModuleLocals(node); + } checkDeferredNodes(); deferredNodes = undefined; if (ts.isExternalOrCommonJsModule(node)) { @@ -31615,6 +31794,14 @@ var ts; case 139 /* QualifiedName */: return getSymbolOfEntityNameOrPropertyAccessExpression(node); case 97 /* ThisKeyword */: + var container = ts.getThisContainer(node, /*includeArrowFunctions*/ false); + if (ts.isFunctionLike(container)) { + var sig = getSignatureFromDeclaration(container); + if (sig.thisParameter) { + return sig.thisParameter; + } + } + // fallthrough case 95 /* SuperKeyword */: var type = ts.isExpression(node) ? checkExpression(node) : getTypeFromTypeNode(node); return type.symbol; @@ -31855,7 +32042,10 @@ var ts; var parentSymbol = getParentOfSymbol(symbol); if (parentSymbol) { if (parentSymbol.flags & 512 /* ValueModule */ && parentSymbol.valueDeclaration.kind === 256 /* SourceFile */) { - return parentSymbol.valueDeclaration; + // If `node` accesses an export and that export isn't in the same file, then symbol is a namespace export, so return undefined. + if (parentSymbol.valueDeclaration === ts.getSourceFileOfNode(node)) { + return parentSymbol.valueDeclaration; + } } for (var n = node.parent; n; n = n.parent) { if ((n.kind === 225 /* ModuleDeclaration */ || n.kind === 224 /* EnumDeclaration */) && getSymbolOfNode(n) === parentSymbol) { @@ -32821,7 +33011,7 @@ var ts; var GetAccessor = 2; var SetAccessor = 4; var GetOrSetAccessor = GetAccessor | SetAccessor; - var _loop_1 = function(prop) { + var _loop_2 = function(prop) { var name_21 = prop.name; if (prop.kind === 193 /* OmittedExpression */ || name_21.kind === 140 /* ComputedPropertyName */) { @@ -32895,8 +33085,8 @@ var ts; }; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var state_2 = _loop_1(prop); - if (typeof state_2 === "object") return state_2.value; + var state_3 = _loop_2(prop); + if (typeof state_3 === "object") return state_3.value; } } function checkGrammarJsxElement(node) { @@ -35814,6 +36004,8 @@ var ts; return generateNameForExportDefault(); case 192 /* ClassExpression */: return generateNameForClassExpression(); + default: + ts.Debug.fail(); } } function getGeneratedNameForNode(node) { @@ -36629,6 +36821,20 @@ var ts; } return false; } + function getClassExpressionInPropertyAccessInStaticPropertyDeclaration(node) { + if (languageVersion >= 2 /* ES6 */) { + var parent_14 = node.parent; + if (parent_14.kind === 172 /* PropertyAccessExpression */ && parent_14.expression === node) { + parent_14 = parent_14.parent; + while (parent_14 && parent_14.kind !== 145 /* PropertyDeclaration */) { + parent_14 = parent_14.parent; + } + return parent_14 && parent_14.kind === 145 /* PropertyDeclaration */ && (parent_14.flags & 32 /* Static */) !== 0 && + parent_14.parent.kind === 192 /* ClassExpression */ ? parent_14.parent : undefined; + } + } + return undefined; + } function emitIdentifier(node) { if (convertedLoopState) { if (node.text == "arguments" && resolver.isArgumentsLocalBinding(node)) { @@ -36642,6 +36848,14 @@ var ts; write(node.text); } else if (isExpressionIdentifier(node)) { + var classExpression = getClassExpressionInPropertyAccessInStaticPropertyDeclaration(node); + if (classExpression) { + var declaration = resolver.getReferencedValueDeclaration(node); + if (declaration === classExpression) { + write(getGeneratedNameForNode(declaration.name)); + return; + } + } emitExpressionIdentifier(node); } else if (isNameOfNestedBlockScopedRedeclarationOrCapturedBinding(node)) { @@ -39666,7 +39880,7 @@ var ts; emitStart(property); emitStart(property.name); if (receiver) { - emit(receiver); + write(receiver); } else { if (property.flags & 32 /* Static */) { @@ -40057,12 +40271,15 @@ var ts; // of it have been initialized by the time it is used. var staticProperties = getInitializedProperties(node, /*isStatic*/ true); var isClassExpressionWithStaticProperties = staticProperties.length > 0 && node.kind === 192 /* ClassExpression */; - var tempVariable; + var generatedName; if (isClassExpressionWithStaticProperties) { - tempVariable = createAndRecordTempVariable(0 /* Auto */); + generatedName = getGeneratedNameForNode(node.name); + var synthesizedNode = ts.createSynthesizedNode(69 /* Identifier */); + synthesizedNode.text = generatedName; + recordTempDeclaration(synthesizedNode); write("("); increaseIndent(); - emit(tempVariable); + emit(synthesizedNode); write(" = "); } write("class"); @@ -40110,11 +40327,11 @@ var ts; var property = staticProperties_1[_a]; write(","); writeLine(); - emitPropertyDeclaration(node, property, /*receiver*/ tempVariable, /*isExpression*/ true); + emitPropertyDeclaration(node, property, /*receiver*/ generatedName, /*isExpression*/ true); } write(","); writeLine(); - emit(tempVariable); + write(generatedName); decreaseIndent(); write(")"); } @@ -42612,7 +42829,7 @@ var ts; /* @internal */ ts.ioReadTime = 0; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ - ts.version = "1.9.0"; + ts.version = "2.0.0"; var emptyArray = []; var defaultTypeRoots = ["node_modules/@types"]; function findConfigFile(searchPath, fileExists) { @@ -44697,6 +44914,16 @@ var ts; type: "boolean", description: ts.Diagnostics.Raise_error_on_this_expressions_with_an_implied_any_type }, + { + name: "noUnusedLocals", + type: "boolean", + description: ts.Diagnostics.Report_Errors_on_Unused_Locals + }, + { + name: "noUnusedParameters", + type: "boolean", + description: ts.Diagnostics.Report_Errors_on_Unused_Parameters + }, { name: "noLib", type: "boolean" @@ -44891,16 +45118,6 @@ var ts; isFilePath: true } }, - { - name: "typesSearchPaths", - type: "list", - isTSConfigOnly: true, - element: { - name: "typesSearchPaths", - type: "string", - isFilePath: true - } - }, { name: "typeRoots", type: "list", @@ -44978,7 +45195,7 @@ var ts; description: ts.Diagnostics.Specify_library_files_to_be_included_in_the_compilation_Colon }, { - name: "disableProjectSizeLimit", + name: "disableSizeLimit", type: "boolean" }, { @@ -45737,28 +45954,28 @@ var ts; switch (n.kind) { case 199 /* Block */: if (!ts.isFunctionBlock(n)) { - var parent_14 = n.parent; + var parent_15 = n.parent; var openBrace = ts.findChildOfKind(n, 15 /* OpenBraceToken */, sourceFile); var closeBrace = ts.findChildOfKind(n, 16 /* CloseBraceToken */, sourceFile); // Check if the block is standalone, or 'attached' to some parent statement. // If the latter, we want to collapse the block, but consider its hint span // to be the entire span of the parent. - if (parent_14.kind === 204 /* DoStatement */ || - parent_14.kind === 207 /* ForInStatement */ || - parent_14.kind === 208 /* ForOfStatement */ || - parent_14.kind === 206 /* ForStatement */ || - parent_14.kind === 203 /* IfStatement */ || - parent_14.kind === 205 /* WhileStatement */ || - parent_14.kind === 212 /* WithStatement */ || - parent_14.kind === 252 /* CatchClause */) { - addOutliningSpan(parent_14, openBrace, closeBrace, autoCollapse(n)); + if (parent_15.kind === 204 /* DoStatement */ || + parent_15.kind === 207 /* ForInStatement */ || + parent_15.kind === 208 /* ForOfStatement */ || + parent_15.kind === 206 /* ForStatement */ || + parent_15.kind === 203 /* IfStatement */ || + parent_15.kind === 205 /* WhileStatement */ || + parent_15.kind === 212 /* WithStatement */ || + parent_15.kind === 252 /* CatchClause */) { + addOutliningSpan(parent_15, openBrace, closeBrace, autoCollapse(n)); break; } - if (parent_14.kind === 216 /* TryStatement */) { + if (parent_15.kind === 216 /* TryStatement */) { // Could be the try-block, or the finally-block. - var tryStatement = parent_14; + var tryStatement = parent_15; if (tryStatement.tryBlock === n) { - addOutliningSpan(parent_14, openBrace, closeBrace, autoCollapse(n)); + addOutliningSpan(parent_15, openBrace, closeBrace, autoCollapse(n)); break; } else if (tryStatement.finallyBlock === n) { @@ -47447,8 +47664,8 @@ var ts; return undefined; } function getArgumentIndex(argumentsList, node) { - // The list we got back can include commas. In the presence of errors it may - // also just have nodes without commas. For example "Foo(a b c)" will have 3 + // The list we got back can include commas. In the presence of errors it may + // also just have nodes without commas. For example "Foo(a b c)" will have 3 // args without commas. We want to find what index we're at. So we count // forward until we hit ourselves, only incrementing the index if it isn't a // comma. @@ -47479,8 +47696,8 @@ var ts; // 'a' ''. So, in the case where the last child is a comma, we increase the // arg count by one to compensate. // - // Note: this subtlety only applies to the last comma. If you had "Foo(a,," then - // we'll have: 'a' '' '' + // Note: this subtlety only applies to the last comma. If you had "Foo(a,," then + // we'll have: 'a' '' '' // That will give us 2 non-commas. We then add one for the last comma, givin us an // arg count of 3. var listChildren = argumentsList.getChildren(); @@ -47628,7 +47845,7 @@ var ts; signatureHelpParameters = typeParameters && typeParameters.length > 0 ? ts.map(typeParameters, createSignatureHelpParameterForTypeParameter) : emptyArray; suffixDisplayParts.push(ts.punctuationPart(27 /* GreaterThanToken */)); var parameterParts = ts.mapToDisplayParts(function (writer) { - return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.thisType, candidateSignature.parameters, writer, invocation); + return typeChecker.getSymbolDisplayBuilder().buildDisplayForParametersAndDelimiters(candidateSignature.thisParameter, candidateSignature.parameters, writer, invocation); }); ts.addRange(suffixDisplayParts, parameterParts); } @@ -47745,6 +47962,8 @@ var ts; case 199 /* Block */: case 226 /* ModuleBlock */: case 227 /* CaseBlock */: + case 233 /* NamedImports */: + case 237 /* NamedExports */: return nodeEndsWith(n, 16 /* CloseBraceToken */, sourceFile); case 252 /* CatchClause */: return isCompletedNode(n.block, sourceFile); @@ -47832,6 +48051,9 @@ var ts; return isCompletedNode(lastSpan, sourceFile); case 197 /* TemplateSpan */: return ts.nodeIsPresent(n.literal); + case 236 /* ExportDeclaration */: + case 230 /* ImportDeclaration */: + return ts.nodeIsPresent(n.moduleSpecifier); case 185 /* PrefixUnaryExpression */: return isCompletedNode(n.operand, sourceFile); case 187 /* BinaryExpression */: @@ -49282,7 +49504,7 @@ var ts; this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Place a space before open brace in a TypeScript declaration that has braces as children (class, module, enum, etc) - this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([69 /* Identifier */, 3 /* MultiLineCommentTrivia */, 73 /* ClassKeyword */]); + this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([69 /* Identifier */, 3 /* MultiLineCommentTrivia */, 73 /* ClassKeyword */, 82 /* ExportKeyword */, 89 /* ImportKeyword */]); this.SpaceBeforeOpenBraceInTypeScriptDeclWithBlock = new formatting.Rule(formatting.RuleDescriptor.create2(this.TypeScriptOpenBraceLeftTokenRange, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsTypeScriptDeclWithBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); // Place a space before open brace in a control flow construct this.ControlOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([18 /* CloseParenToken */, 3 /* MultiLineCommentTrivia */, 79 /* DoKeyword */, 100 /* TryKeyword */, 85 /* FinallyKeyword */, 80 /* ElseKeyword */]); @@ -49339,8 +49561,8 @@ var ts; // Use of module as a function call. e.g.: import m2 = module("m2"); this.NoSpaceAfterModuleImport = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.FromTokens([125 /* ModuleKeyword */, 129 /* RequireKeyword */]), 17 /* OpenParenToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 8 /* Delete */)); // Add a space around certain TypeScript keywords - this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([115 /* AbstractKeyword */, 73 /* ClassKeyword */, 122 /* DeclareKeyword */, 77 /* DefaultKeyword */, 81 /* EnumKeyword */, 82 /* ExportKeyword */, 83 /* ExtendsKeyword */, 123 /* GetKeyword */, 106 /* ImplementsKeyword */, 89 /* ImportKeyword */, 107 /* InterfaceKeyword */, 125 /* ModuleKeyword */, 126 /* NamespaceKeyword */, 110 /* PrivateKeyword */, 112 /* PublicKeyword */, 111 /* ProtectedKeyword */, 131 /* SetKeyword */, 113 /* StaticKeyword */, 134 /* TypeKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); - this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([83 /* ExtendsKeyword */, 106 /* ImplementsKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); + this.SpaceAfterCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([115 /* AbstractKeyword */, 73 /* ClassKeyword */, 122 /* DeclareKeyword */, 77 /* DefaultKeyword */, 81 /* EnumKeyword */, 82 /* ExportKeyword */, 83 /* ExtendsKeyword */, 123 /* GetKeyword */, 106 /* ImplementsKeyword */, 89 /* ImportKeyword */, 107 /* InterfaceKeyword */, 125 /* ModuleKeyword */, 126 /* NamespaceKeyword */, 110 /* PrivateKeyword */, 112 /* PublicKeyword */, 111 /* ProtectedKeyword */, 131 /* SetKeyword */, 113 /* StaticKeyword */, 134 /* TypeKeyword */, 136 /* FromKeyword */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); + this.SpaceBeforeCertainTypeScriptKeywords = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([83 /* ExtendsKeyword */, 106 /* ImplementsKeyword */, 136 /* FromKeyword */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), 2 /* Space */)); // Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" { this.SpaceAfterModuleName = new formatting.Rule(formatting.RuleDescriptor.create1(9 /* StringLiteral */, 15 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsModuleDeclContext), 2 /* Space */)); // Lambda expressions @@ -49495,6 +49717,8 @@ var ts; case 187 /* BinaryExpression */: case 188 /* ConditionalExpression */: case 195 /* AsExpression */: + case 238 /* ExportSpecifier */: + case 234 /* ImportSpecifier */: case 154 /* TypePredicate */: case 162 /* UnionType */: case 163 /* IntersectionType */: @@ -49613,6 +49837,10 @@ var ts; case 224 /* EnumDeclaration */: case 159 /* TypeLiteral */: case 225 /* ModuleDeclaration */: + case 236 /* ExportDeclaration */: + case 237 /* NamedExports */: + case 230 /* ImportDeclaration */: + case 233 /* NamedImports */: return true; } return false; @@ -50420,7 +50648,10 @@ var ts; var startLinePosition = ts.getLineStartPositionForPosition(startPos, sourceFile); var column = formatting.SmartIndenter.findFirstNonWhitespaceColumn(startLinePosition, startPos, sourceFile, options); if (startLine !== parentStartLine || startPos === column) { - return column; + // Use the base indent size if it is greater than + // the indentation of the inherited predecessor. + var baseIndentSize = formatting.SmartIndenter.getBaseIndentation(options); + return baseIndentSize > column ? baseIndentSize : column; } } return -1 /* Unknown */; @@ -51060,7 +51291,7 @@ var ts; })(Value || (Value = {})); function getIndentation(position, sourceFile, options) { if (position > sourceFile.text.length) { - return 0; // past EOF + return getBaseIndentation(options); // past EOF } // no indentation when the indent style is set to none, // so we can return fast @@ -51069,7 +51300,7 @@ var ts; } var precedingToken = ts.findPrecedingToken(position, sourceFile); if (!precedingToken) { - return 0; + return getBaseIndentation(options); } // no indentation in string \regex\template literals var precedingTokenIsLiteral = ts.isStringOrRegularExpressionOrTemplateLiteral(precedingToken.kind); @@ -51131,12 +51362,16 @@ var ts; current = current.parent; } if (!current) { - // no parent was found - return 0 to be indented on the level of SourceFile - return 0; + // no parent was found - return the base indentation of the SourceFile + return getBaseIndentation(options); } return getIndentationForNodeWorker(current, currentStart, /*ignoreActualIndentationRange*/ undefined, indentationDelta, sourceFile, options); } SmartIndenter.getIndentation = getIndentation; + function getBaseIndentation(options) { + return options.BaseIndentSize || 0; + } + SmartIndenter.getBaseIndentation = getBaseIndentation; function getIndentationForNode(n, ignoreActualIndentationRange, sourceFile, options) { var start = sourceFile.getLineAndCharacterOfPosition(n.getStart(sourceFile)); return getIndentationForNodeWorker(n, start, ignoreActualIndentationRange, /*indentationDelta*/ 0, sourceFile, options); @@ -51182,7 +51417,7 @@ var ts; currentStart = parentStart; parent = current.parent; } - return indentationDelta; + return indentationDelta + getBaseIndentation(options); } function getParentStart(parent, child, sourceFile) { var containingList = getContainingList(child, sourceFile); @@ -51440,7 +51675,10 @@ var ts; case 164 /* ParenthesizedType */: case 176 /* TaggedTemplateExpression */: case 184 /* AwaitExpression */: + case 237 /* NamedExports */: case 233 /* NamedImports */: + case 238 /* ExportSpecifier */: + case 234 /* ImportSpecifier */: return true; } return false; @@ -51463,6 +51701,11 @@ var ts; case 149 /* GetAccessor */: case 150 /* SetAccessor */: return childKind !== 199 /* Block */; + case 236 /* ExportDeclaration */: + return childKind !== 237 /* NamedExports */; + case 230 /* ImportDeclaration */: + return childKind !== 231 /* ImportClause */ || + child.namedBindings.kind !== 233 /* NamedImports */; case 241 /* JsxElement */: return childKind !== 245 /* JsxClosingElement */; } @@ -52468,9 +52711,9 @@ var ts; return false; } // If the parent is not sourceFile or module block it is local variable - for (var parent_15 = declaration.parent; !ts.isFunctionBlock(parent_15); parent_15 = parent_15.parent) { + for (var parent_16 = declaration.parent; !ts.isFunctionBlock(parent_16); parent_16 = parent_16.parent) { // Reached source file or module block - if (parent_15.kind === 256 /* SourceFile */ || parent_15.kind === 226 /* ModuleBlock */) { + if (parent_16.kind === 256 /* SourceFile */ || parent_16.kind === 226 /* ModuleBlock */) { return false; } } @@ -52601,7 +52844,7 @@ var ts; return typeof o.type === "object" && !ts.forEachValue(o.type, function (v) { return typeof v !== "number"; }); }); options = ts.clone(options); - var _loop_2 = function(opt) { + var _loop_3 = function(opt) { if (!ts.hasProperty(options, opt.name)) { return "continue"; } @@ -52620,7 +52863,7 @@ var ts; }; for (var _i = 0, commandLineOptionsStringToEnum_1 = commandLineOptionsStringToEnum; _i < commandLineOptionsStringToEnum_1.length; _i++) { var opt = commandLineOptionsStringToEnum_1[_i]; - _loop_2(opt); + _loop_3(opt); } return options; } @@ -53821,13 +54064,13 @@ var ts; log("Returning an empty list because completion was requested in an invalid position."); return undefined; } - var parent_16 = contextToken.parent, kind = contextToken.kind; + var parent_17 = contextToken.parent, kind = contextToken.kind; if (kind === 21 /* DotToken */) { - if (parent_16.kind === 172 /* PropertyAccessExpression */) { + if (parent_17.kind === 172 /* PropertyAccessExpression */) { node = contextToken.parent.expression; isRightOfDot = true; } - else if (parent_16.kind === 139 /* QualifiedName */) { + else if (parent_17.kind === 139 /* QualifiedName */) { node = contextToken.parent.left; isRightOfDot = true; } @@ -54203,9 +54446,9 @@ var ts; switch (contextToken.kind) { case 15 /* OpenBraceToken */: // const x = { | case 24 /* CommaToken */: - var parent_17 = contextToken.parent; - if (parent_17 && (parent_17.kind === 171 /* ObjectLiteralExpression */ || parent_17.kind === 167 /* ObjectBindingPattern */)) { - return parent_17; + var parent_18 = contextToken.parent; + if (parent_18 && (parent_18.kind === 171 /* ObjectLiteralExpression */ || parent_18.kind === 167 /* ObjectBindingPattern */)) { + return parent_18; } break; } @@ -54232,37 +54475,37 @@ var ts; } function tryGetContainingJsxElement(contextToken) { if (contextToken) { - var parent_18 = contextToken.parent; + var parent_19 = contextToken.parent; switch (contextToken.kind) { case 26 /* LessThanSlashToken */: case 39 /* SlashToken */: case 69 /* Identifier */: case 246 /* JsxAttribute */: case 247 /* JsxSpreadAttribute */: - if (parent_18 && (parent_18.kind === 242 /* JsxSelfClosingElement */ || parent_18.kind === 243 /* JsxOpeningElement */)) { - return parent_18; + if (parent_19 && (parent_19.kind === 242 /* JsxSelfClosingElement */ || parent_19.kind === 243 /* JsxOpeningElement */)) { + return parent_19; } - else if (parent_18.kind === 246 /* JsxAttribute */) { - return parent_18.parent; + else if (parent_19.kind === 246 /* JsxAttribute */) { + return parent_19.parent; } break; // The context token is the closing } or " of an attribute, which means // its parent is a JsxExpression, whose parent is a JsxAttribute, // whose parent is a JsxOpeningLikeElement case 9 /* StringLiteral */: - if (parent_18 && ((parent_18.kind === 246 /* JsxAttribute */) || (parent_18.kind === 247 /* JsxSpreadAttribute */))) { - return parent_18.parent; + if (parent_19 && ((parent_19.kind === 246 /* JsxAttribute */) || (parent_19.kind === 247 /* JsxSpreadAttribute */))) { + return parent_19.parent; } break; case 16 /* CloseBraceToken */: - if (parent_18 && - parent_18.kind === 248 /* JsxExpression */ && - parent_18.parent && - (parent_18.parent.kind === 246 /* JsxAttribute */)) { - return parent_18.parent.parent; + if (parent_19 && + parent_19.kind === 248 /* JsxExpression */ && + parent_19.parent && + (parent_19.parent.kind === 246 /* JsxAttribute */)) { + return parent_19.parent.parent; } - if (parent_18 && parent_18.kind === 247 /* JsxSpreadAttribute */) { - return parent_18.parent; + if (parent_19 && parent_19.kind === 247 /* JsxSpreadAttribute */) { + return parent_19.parent; } break; } @@ -55594,19 +55837,19 @@ var ts; function getThrowStatementOwner(throwStatement) { var child = throwStatement; while (child.parent) { - var parent_19 = child.parent; - if (ts.isFunctionBlock(parent_19) || parent_19.kind === 256 /* SourceFile */) { - return parent_19; + var parent_20 = child.parent; + if (ts.isFunctionBlock(parent_20) || parent_20.kind === 256 /* SourceFile */) { + return parent_20; } // A throw-statement is only owned by a try-statement if the try-statement has // a catch clause, and if the throw-statement occurs within the try block. - if (parent_19.kind === 216 /* TryStatement */) { - var tryStatement = parent_19; + if (parent_20.kind === 216 /* TryStatement */) { + var tryStatement = parent_20; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; } } - child = parent_19; + child = parent_20; } return undefined; } @@ -55986,16 +56229,31 @@ var ts; if (node === sourceFile) { return undefined; } - if (node.kind !== 69 /* Identifier */ && - // TODO (drosen): This should be enabled in a later release - currently breaks rename. - // node.kind !== SyntaxKind.ThisKeyword && - // node.kind !== SyntaxKind.SuperKeyword && - node.kind !== 9 /* StringLiteral */ && - !isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { - return undefined; + switch (node.kind) { + case 8 /* NumericLiteral */: + if (!isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { + break; + } + // Fallthrough + case 69 /* Identifier */: + case 97 /* ThisKeyword */: + // case SyntaxKind.SuperKeyword: TODO:GH#9268 + case 9 /* StringLiteral */: + return getReferencedSymbolsForNode(node, program.getSourceFiles(), findInStrings, findInComments); + } + return undefined; + } + function isThis(node) { + switch (node.kind) { + case 97 /* ThisKeyword */: + // case SyntaxKind.ThisType: TODO: GH#9267 + return true; + case 69 /* Identifier */: + // 'this' as a parameter + return node.originalKeywordKind === 97 /* ThisKeyword */ && node.parent.kind === 142 /* Parameter */; + default: + return false; } - ts.Debug.assert(node.kind === 69 /* Identifier */ || node.kind === 8 /* NumericLiteral */ || node.kind === 9 /* StringLiteral */); - return getReferencedSymbolsForNode(node, program.getSourceFiles(), findInStrings, findInComments); } function getReferencedSymbolsForNode(node, sourceFiles, findInStrings, findInComments) { var typeChecker = program.getTypeChecker(); @@ -56012,7 +56270,7 @@ var ts; return getLabelReferencesInNode(node.parent, node); } } - if (node.kind === 97 /* ThisKeyword */ || node.kind === 165 /* ThisType */) { + if (isThis(node)) { return getReferencesForThisKeyword(node, sourceFiles); } if (node.kind === 95 /* SuperKeyword */) { @@ -56447,7 +56705,7 @@ var ts; ts.forEach(possiblePositions, function (position) { cancellationToken.throwIfCancellationRequested(); var node = ts.getTouchingWord(sourceFile, position); - if (!node || (node.kind !== 97 /* ThisKeyword */ && node.kind !== 165 /* ThisType */)) { + if (!node || !isThis(node)) { return; } var container = ts.getThisContainer(node, /* includeArrowFunctions */ false); @@ -57453,8 +57711,8 @@ var ts; return; case 142 /* Parameter */: if (token.parent.name === token) { - var isThis = token.kind === 69 /* Identifier */ && token.originalKeywordKind === 97 /* ThisKeyword */; - return isThis ? 3 /* keyword */ : 17 /* parameterName */; + var isThis_1 = token.kind === 69 /* Identifier */ && token.originalKeywordKind === 97 /* ThisKeyword */; + return isThis_1 ? 3 /* keyword */ : 17 /* parameterName */; } return; } @@ -57645,7 +57903,7 @@ var ts; (tokenStart === position ? newLine + indentationStr : ""); return { newText: result, caretOffset: preamble.length }; } - function isValidBraceCompletionAtPostion(fileName, position, openingBrace) { + function isValidBraceCompletionAtPosition(fileName, position, openingBrace) { // '<' is currently not supported, figuring out if we're in a Generic Type vs. a comparison is too // expensive to do during typing scenarios // i.e. whether we're dealing with: @@ -57847,11 +58105,11 @@ var ts; var defaultLibFileName = host.getDefaultLibFileName(host.getCompilationSettings()); var canonicalDefaultLibName = getCanonicalFileName(ts.normalizePath(defaultLibFileName)); var node = ts.getTouchingWord(sourceFile, position, /*includeJsDocComment*/ true); - // Can only rename an identifier. if (node) { if (node.kind === 69 /* Identifier */ || node.kind === 9 /* StringLiteral */ || - isLiteralNameOfPropertyDeclarationOrIndexAccess(node)) { + isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || + isThis(node)) { var symbol = typeChecker.getSymbolAtLocation(node); // Only allow a symbol to be renamed if it actually has at least one declaration. if (symbol) { @@ -57965,7 +58223,7 @@ var ts; getFormattingEditsForDocument: getFormattingEditsForDocument, getFormattingEditsAfterKeystroke: getFormattingEditsAfterKeystroke, getDocCommentTemplateAtPosition: getDocCommentTemplateAtPosition, - isValidBraceCompletionAtPostion: isValidBraceCompletionAtPostion, + isValidBraceCompletionAtPosition: isValidBraceCompletionAtPosition, getEmitOutput: getEmitOutput, getNonBoundSourceFile: getNonBoundSourceFile, getProgram: getProgram @@ -59503,9 +59761,9 @@ var ts; var _this = this; return this.forwardJSONCall("getBraceMatchingAtPosition('" + fileName + "', " + position + ")", function () { return _this.languageService.getBraceMatchingAtPosition(fileName, position); }); }; - LanguageServiceShimObject.prototype.isValidBraceCompletionAtPostion = function (fileName, position, openingBrace) { + LanguageServiceShimObject.prototype.isValidBraceCompletionAtPosition = function (fileName, position, openingBrace) { var _this = this; - return this.forwardJSONCall("isValidBraceCompletionAtPostion('" + fileName + "', " + position + ", " + openingBrace + ")", function () { return _this.languageService.isValidBraceCompletionAtPostion(fileName, position, openingBrace); }); + return this.forwardJSONCall("isValidBraceCompletionAtPosition('" + fileName + "', " + position + ", " + openingBrace + ")", function () { return _this.languageService.isValidBraceCompletionAtPosition(fileName, position, openingBrace); }); }; /// GET SMART INDENT LanguageServiceShimObject.prototype.getIndentationAtPosition = function (fileName, position, options /*Services.EditorOptions*/) {