diff --git a/lib/enu/diagnosticMessages.generated.json.lcg b/lib/enu/diagnosticMessages.generated.json.lcg index 13173d17d73..a3f7dd8da25 100644 --- a/lib/enu/diagnosticMessages.generated.json.lcg +++ b/lib/enu/diagnosticMessages.generated.json.lcg @@ -5421,9 +5421,9 @@ - + - + diff --git a/lib/lib.es5.d.ts b/lib/lib.es5.d.ts index ac73e23d9f6..840fd682789 100644 --- a/lib/lib.es5.d.ts +++ b/lib/lib.es5.d.ts @@ -1145,15 +1145,15 @@ interface Array { * Returns a string representation of an array. The elements are converted to string using their toLocalString methods. */ toLocaleString(): string; + /** + * Removes the last element from an array and returns it. + */ + pop(): T | undefined; /** * Appends new elements to an array, and returns the new length of the array. * @param items New elements of the Array. */ push(...items: T[]): number; - /** - * Removes the last element from an array and returns it. - */ - pop(): T | undefined; /** * Combines two or more arrays. * @param items Additional items to add to the end of array1. diff --git a/lib/tsc.js b/lib/tsc.js index 2cc079c7b64..c068dcddbf8 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -2241,18 +2241,16 @@ var ts; process.stdout._handle.setBlocking(true); } }, - base64decode: Buffer.from ? function (input) { - return Buffer.from(input, "base64").toString("utf8"); - } : function (input) { - return new Buffer(input, "base64").toString("utf8"); - }, - base64encode: Buffer.from ? function (input) { - return Buffer.from(input).toString("base64"); - } : function (input) { - return new Buffer(input).toString("base64"); - } + bufferFrom: bufferFrom, + base64decode: function (input) { return bufferFrom(input, "base64").toString("utf8"); }, + base64encode: function (input) { return bufferFrom(input).toString("base64"); }, }; return nodeSystem; + function bufferFrom(input, encoding) { + return Buffer.from && Buffer.from !== Int8Array.from + ? Buffer.from(input, encoding) + : new Buffer(input, encoding); + } function isFileSystemCaseSensitive() { if (platform === "win32" || platform === "win64") { return false; @@ -3680,7 +3678,7 @@ var ts; Expected_0_1_type_arguments_provide_these_with_an_extends_tag: diag(8027, ts.DiagnosticCategory.Error, "Expected_0_1_type_arguments_provide_these_with_an_extends_tag_8027", "Expected {0}-{1} type arguments; provide these with an '@extends' tag."), JSDoc_may_only_appear_in_the_last_parameter_of_a_signature: diag(8028, ts.DiagnosticCategory.Error, "JSDoc_may_only_appear_in_the_last_parameter_of_a_signature_8028", "JSDoc '...' may only appear in the last parameter of a signature."), JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type: diag(8029, ts.DiagnosticCategory.Error, "JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_h_8029", "JSDoc '@param' tag has name '{0}', but there is no parameter with that name. It would match 'arguments' if it had an array type."), - The_type_of_a_function_declaration_must_be_callable: diag(8030, ts.DiagnosticCategory.Error, "The_type_of_a_function_declaration_must_be_callable_8030", "The type of a function declaration must be callable."), + The_type_of_a_function_declaration_must_match_the_function_s_signature: diag(8030, ts.DiagnosticCategory.Error, "The_type_of_a_function_declaration_must_match_the_function_s_signature_8030", "The type of a function declaration must match the function's signature."), Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clause: diag(9002, ts.DiagnosticCategory.Error, "Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_clas_9002", "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause."), class_expressions_are_not_currently_supported: diag(9003, ts.DiagnosticCategory.Error, "class_expressions_are_not_currently_supported_9003", "'class' expressions are not currently supported."), Language_service_is_disabled: diag(9004, ts.DiagnosticCategory.Error, "Language_service_is_disabled_9004", "Language service is disabled."), @@ -24034,8 +24032,8 @@ var ts; cancellationToken = undefined; } function addUnusedDiagnostics() { - checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (kind, diag) { - if (!unusedIsError(kind)) { + checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (containingNode, kind, diag) { + if (!ts.containsParseError(containingNode) && !unusedIsError(kind)) { (diagnostics || (diagnostics = [])).push(__assign({}, diag, { category: ts.DiagnosticCategory.Suggestion })); } }); @@ -27460,13 +27458,7 @@ var ts; return getReturnTypeOfSignature(getterSignature); } } - var type = void 0; - if (declaration.symbol.escapedName === "this") { - type = getContextualThisParameterType(func); - } - else { - type = getContextuallyTypedParameterType(declaration); - } + var type = declaration.symbol.escapedName === "this" ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration); if (type) { return addOptionality(type, isOptional); } @@ -42189,11 +42181,11 @@ var ts; if (functionFlags & 1 && ts.nodeIsPresent(body)) { getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } - if (ts.isInJavaScriptFile(node)) { - var typeTag = ts.getJSDocTypeTag(node); - if (typeTag && typeTag.typeExpression && !getSignaturesOfType(getTypeFromTypeNode(typeTag.typeExpression), 0).length) { - error(typeTag, ts.Diagnostics.The_type_of_a_function_declaration_must_be_callable); - } + } + if (ts.isInJavaScriptFile(node)) { + var typeTag = ts.getJSDocTypeTag(node); + if (typeTag && typeTag.typeExpression && !getContextualCallSignature(getTypeFromTypeNode(typeTag.typeExpression), node)) { + error(typeTag, ts.Diagnostics.The_type_of_a_function_declaration_must_match_the_function_s_signature); } } } @@ -42257,7 +42249,7 @@ var ts; function errorUnusedLocal(declaration, name, addDiagnostic) { var node = ts.getNameOfDeclaration(declaration) || declaration; var message = isTypeDeclaration(declaration) ? ts.Diagnostics._0_is_declared_but_never_used : ts.Diagnostics._0_is_declared_but_its_value_is_never_read; - addDiagnostic(0, ts.createDiagnosticForNode(node, message, name)); + addDiagnostic(declaration, 0, ts.createDiagnosticForNode(node, message, name)); } function isIdentifierThatStartsWithUnderscore(node) { return ts.isIdentifier(node) && ts.idText(node).charCodeAt(0) === 95; @@ -42276,14 +42268,14 @@ var ts; } var symbol = getSymbolOfNode(member); if (!symbol.isReferenced && ts.hasModifier(member, 8)) { - addDiagnostic(0, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); + addDiagnostic(member, 0, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); } break; case 155: for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { var parameter = _c[_b]; if (!parameter.symbol.isReferenced && ts.hasModifier(parameter, 8)) { - addDiagnostic(0, ts.createDiagnosticForNode(parameter.name, ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read, ts.symbolName(parameter.symbol))); + addDiagnostic(parameter, 0, ts.createDiagnosticForNode(parameter.name, ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read, ts.symbolName(parameter.symbol))); } } break; @@ -42302,7 +42294,7 @@ var ts; for (var _i = 0, typeParameters_2 = typeParameters; _i < typeParameters_2.length; _i++) { var typeParameter = typeParameters_2[_i]; if (!(getMergedSymbol(typeParameter.symbol).isReferenced & 262144) && !isIdentifierThatStartsWithUnderscore(typeParameter.name)) { - addDiagnostic(1, ts.createDiagnosticForNode(typeParameter.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(typeParameter.symbol))); + addDiagnostic(typeParameter, 1, ts.createDiagnosticForNode(typeParameter.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(typeParameter.symbol))); } } } @@ -42353,7 +42345,7 @@ var ts; var name = local.valueDeclaration && ts.getNameOfDeclaration(local.valueDeclaration); if (parameter && name) { if (!ts.isParameterPropertyDeclaration(parameter) && !ts.parameterIsThisKeyword(parameter) && !isIdentifierThatStartsWithUnderscore(name)) { - addDiagnostic(1, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local))); + addDiagnostic(parameter, 1, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local))); } } else { @@ -42370,7 +42362,7 @@ var ts; (importClause.namedBindings.kind === 249 ? 1 : importClause.namedBindings.elements.length) : 0); if (nDeclarations === unuseds.length) { - addDiagnostic(0, unuseds.length === 1 + addDiagnostic(importDecl, 0, unuseds.length === 1 ? ts.createDiagnosticForNode(importDecl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.first(unuseds).name)) : ts.createDiagnosticForNode(importDecl, ts.Diagnostics.All_imports_in_import_declaration_are_unused)); } @@ -42389,7 +42381,7 @@ var ts; addToGroup(unusedVariables, bindingPattern.parent.parent, bindingPattern.parent, getNodeId); } else { - addDiagnostic(kind, bindingElements.length === 1 + addDiagnostic(bindingPattern, kind, bindingElements.length === 1 ? ts.createDiagnosticForNode(bindingPattern, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(ts.first(bindingElements).name, ts.isIdentifier))) : ts.createDiagnosticForNode(bindingPattern, ts.Diagnostics.All_destructured_elements_are_unused)); } @@ -42397,21 +42389,21 @@ var ts; else { for (var _i = 0, bindingElements_1 = bindingElements; _i < bindingElements_1.length; _i++) { var e = bindingElements_1[_i]; - addDiagnostic(kind, ts.createDiagnosticForNode(e, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(e.name, ts.isIdentifier)))); + addDiagnostic(e, kind, ts.createDiagnosticForNode(e, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(e.name, ts.isIdentifier)))); } } }); unusedVariables.forEach(function (_a) { var declarationList = _a[0], declarations = _a[1]; if (declarationList.declarations.length === declarations.length) { - addDiagnostic(0, declarations.length === 1 + addDiagnostic(declarationList, 0, declarations.length === 1 ? ts.createDiagnosticForNode(ts.first(declarations).name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, bindingNameText(ts.first(declarations).name)) : ts.createDiagnosticForNode(declarationList.parent.kind === 217 ? declarationList.parent : declarationList, ts.Diagnostics.All_variables_are_unused)); } else { for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) { var decl = declarations_5[_i]; - addDiagnostic(0, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(decl.name, ts.isIdentifier)))); + addDiagnostic(decl, 0, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(decl.name, ts.isIdentifier)))); } } }); @@ -44589,8 +44581,8 @@ var ts; registerForUnusedIdentifiersCheck(node); } if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) { - checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (kind, diag) { - if (unusedIsError(kind)) { + checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) { + if (!ts.containsParseError(containingNode) && unusedIsError(kind)) { diagnostics.add(diag); } }); @@ -50318,6 +50310,9 @@ var ts; case 203: node = node.condition; continue; + case 191: + node = node.tag; + continue; case 189: if (stopAtCallExpressions) { return node; @@ -66567,7 +66562,7 @@ var ts; } function createFileWatcherWithTriggerLogging(host, file, cb, flags, passThrough, detailInfo1, detailInfo2, addWatch, log, watchCaption, getDetailWatchInfo) { return addWatch(host, file, function (fileName, cbOptional) { - var triggerredInfo = watchCaption + ":: Triggered with " + fileName + (cbOptional !== undefined ? cbOptional : "") + ":: " + getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo); + var triggerredInfo = watchCaption + ":: Triggered with " + fileName + " " + (cbOptional !== undefined ? cbOptional : "") + ":: " + getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo); log(triggerredInfo); var start = ts.timestamp(); cb(fileName, cbOptional, passThrough); @@ -67013,6 +67008,7 @@ var ts; var programDiagnostics = ts.createDiagnosticCollection(); var currentDirectory = host.getCurrentDirectory(); var supportedExtensions = ts.getSupportedExtensions(options); + var supportedExtensionsWithJsonIfResolveJsonModule = options.resolveJsonModule ? supportedExtensions.concat([".json"]) : undefined; var hasEmitBlockingDiagnostics = ts.createMap(); var _compilerOptionsObjectLiteralSyntax; var _referencesArrayLiteralSyntax; @@ -67978,7 +67974,7 @@ var ts; } function getSourceFileFromReferenceWorker(fileName, getSourceFile, fail, refFile) { if (ts.hasExtension(fileName)) { - if (!options.allowNonTsExtensions && !ts.forEach(supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) { + if (!options.allowNonTsExtensions && !ts.forEach(supportedExtensionsWithJsonIfResolveJsonModule || supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) { if (fail) fail(ts.Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1, fileName, "'" + supportedExtensions.join("', '") + "'"); return undefined; @@ -70331,16 +70327,15 @@ var ts; onUnRecoverableConfigFileDiagnostic: host.onUnRecoverableConfigFileDiagnostic }; var newLine = updateNewLine(); + if (configFileName && host.configFileParsingResult) { + setConfigFileParsingResult(host.configFileParsingResult); + newLine = updateNewLine(); + } reportWatchDiagnostic(ts.Diagnostics.Starting_compilation_in_watch_mode); - if (configFileName) { + if (configFileName && !host.configFileParsingResult) { newLine = ts.getNewLineCharacter(optionsToExtendForConfigFile, function () { return host.getNewLine(); }); - if (host.configFileParsingResult) { - setConfigFileParsingResult(host.configFileParsingResult); - } - else { - ts.Debug.assert(!rootFileNames); - parseConfigFile(); - } + ts.Debug.assert(!rootFileNames); + parseConfigFile(); newLine = updateNewLine(); } var trace = host.trace && (function (s) { host.trace(s + newLine); }); @@ -70992,6 +70987,7 @@ var ts; return builder.cleanAllProjects(); } if (watch) { + builder.buildAllProjects(); builder.startWatching(); return undefined; } diff --git a/lib/tsserver.js b/lib/tsserver.js index 37d4c81272d..6ae31807397 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -3923,7 +3923,7 @@ var ts; return parseInt(version.substring(1, dot)); } ts.getNodeMajorVersion = getNodeMajorVersion; - // TODO: this is used as if it's certainly defined in many places. + // TODO: GH#18217 this is used as if it's certainly defined in many places. ts.sys = (function () { // NodeJS detects "\uFEFF" at the start of the string and *replaces* it with the actual // byte order mark from the specified encoding. Using any other byte order mark does @@ -4032,18 +4032,17 @@ var ts; process.stdout._handle.setBlocking(true); } }, - base64decode: Buffer.from ? function (input) { - return Buffer.from(input, "base64").toString("utf8"); - } : function (input) { - return new Buffer(input, "base64").toString("utf8"); - }, - base64encode: Buffer.from ? function (input) { - return Buffer.from(input).toString("base64"); - } : function (input) { - return new Buffer(input).toString("base64"); - } + bufferFrom: bufferFrom, + base64decode: function (input) { return bufferFrom(input, "base64").toString("utf8"); }, + base64encode: function (input) { return bufferFrom(input).toString("base64"); }, }; return nodeSystem; + function bufferFrom(input, encoding) { + // See https://github.com/Microsoft/TypeScript/issues/25652 + return Buffer.from && Buffer.from !== Int8Array.from + ? Buffer.from(input, encoding) + : new Buffer(input, encoding); + } function isFileSystemCaseSensitive() { // win32\win64 are case insensitive platforms if (platform === "win32" || platform === "win64") { @@ -5545,7 +5544,7 @@ var ts; Expected_0_1_type_arguments_provide_these_with_an_extends_tag: diag(8027, ts.DiagnosticCategory.Error, "Expected_0_1_type_arguments_provide_these_with_an_extends_tag_8027", "Expected {0}-{1} type arguments; provide these with an '@extends' tag."), JSDoc_may_only_appear_in_the_last_parameter_of_a_signature: diag(8028, ts.DiagnosticCategory.Error, "JSDoc_may_only_appear_in_the_last_parameter_of_a_signature_8028", "JSDoc '...' may only appear in the last parameter of a signature."), JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type: diag(8029, ts.DiagnosticCategory.Error, "JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_h_8029", "JSDoc '@param' tag has name '{0}', but there is no parameter with that name. It would match 'arguments' if it had an array type."), - The_type_of_a_function_declaration_must_be_callable: diag(8030, ts.DiagnosticCategory.Error, "The_type_of_a_function_declaration_must_be_callable_8030", "The type of a function declaration must be callable."), + The_type_of_a_function_declaration_must_match_the_function_s_signature: diag(8030, ts.DiagnosticCategory.Error, "The_type_of_a_function_declaration_must_match_the_function_s_signature_8030", "The type of a function declaration must match the function's signature."), Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clause: diag(9002, ts.DiagnosticCategory.Error, "Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_clas_9002", "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause."), class_expressions_are_not_currently_supported: diag(9003, ts.DiagnosticCategory.Error, "class_expressions_are_not_currently_supported_9003", "'class' expressions are not currently supported."), Language_service_is_disabled: diag(9004, ts.DiagnosticCategory.Error, "Language_service_is_disabled_9004", "Language service is disabled."), @@ -29475,8 +29474,8 @@ var ts; cancellationToken = undefined; } function addUnusedDiagnostics() { - checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (kind, diag) { - if (!unusedIsError(kind)) { + checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (containingNode, kind, diag) { + if (!ts.containsParseError(containingNode) && !unusedIsError(kind)) { (diagnostics || (diagnostics = [])).push(__assign({}, diag, { category: ts.DiagnosticCategory.Suggestion })); } }); @@ -33448,13 +33447,7 @@ var ts; } } // Use contextual parameter type if one is available - var type = void 0; - if (declaration.symbol.escapedName === "this") { - type = getContextualThisParameterType(func); - } - else { - type = getContextuallyTypedParameterType(declaration); - } + var type = declaration.symbol.escapedName === "this" ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration); if (type) { return addOptionality(type, isOptional); } @@ -50798,12 +50791,12 @@ var ts; // yielded values. The only way to trigger these errors is to try checking its return type. getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } - // A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature - if (ts.isInJavaScriptFile(node)) { - var typeTag = ts.getJSDocTypeTag(node); - if (typeTag && typeTag.typeExpression && !getSignaturesOfType(getTypeFromTypeNode(typeTag.typeExpression), 0 /* Call */).length) { - error(typeTag, ts.Diagnostics.The_type_of_a_function_declaration_must_be_callable); - } + } + // A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature + if (ts.isInJavaScriptFile(node)) { + var typeTag = ts.getJSDocTypeTag(node); + if (typeTag && typeTag.typeExpression && !getContextualCallSignature(getTypeFromTypeNode(typeTag.typeExpression), node)) { + error(typeTag, ts.Diagnostics.The_type_of_a_function_declaration_must_match_the_function_s_signature); } } } @@ -50870,7 +50863,7 @@ var ts; function errorUnusedLocal(declaration, name, addDiagnostic) { var node = ts.getNameOfDeclaration(declaration) || declaration; var message = isTypeDeclaration(declaration) ? ts.Diagnostics._0_is_declared_but_never_used : ts.Diagnostics._0_is_declared_but_its_value_is_never_read; - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(node, message, name)); + addDiagnostic(declaration, 0 /* Local */, ts.createDiagnosticForNode(node, message, name)); } function isIdentifierThatStartsWithUnderscore(node) { return ts.isIdentifier(node) && ts.idText(node).charCodeAt(0) === 95 /* _ */; @@ -50890,14 +50883,14 @@ var ts; } var symbol = getSymbolOfNode(member); if (!symbol.isReferenced && ts.hasModifier(member, 8 /* Private */)) { - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); + addDiagnostic(member, 0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); } break; case 155 /* Constructor */: for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { var parameter = _c[_b]; if (!parameter.symbol.isReferenced && ts.hasModifier(parameter, 8 /* Private */)) { - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(parameter.name, ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read, ts.symbolName(parameter.symbol))); + addDiagnostic(parameter, 0 /* Local */, ts.createDiagnosticForNode(parameter.name, ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read, ts.symbolName(parameter.symbol))); } } break; @@ -50919,7 +50912,7 @@ var ts; for (var _i = 0, typeParameters_2 = typeParameters; _i < typeParameters_2.length; _i++) { var typeParameter = typeParameters_2[_i]; if (!(getMergedSymbol(typeParameter.symbol).isReferenced & 262144 /* TypeParameter */) && !isIdentifierThatStartsWithUnderscore(typeParameter.name)) { - addDiagnostic(1 /* Parameter */, ts.createDiagnosticForNode(typeParameter.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(typeParameter.symbol))); + addDiagnostic(typeParameter, 1 /* Parameter */, ts.createDiagnosticForNode(typeParameter.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(typeParameter.symbol))); } } } @@ -50974,7 +50967,7 @@ var ts; var name = local.valueDeclaration && ts.getNameOfDeclaration(local.valueDeclaration); if (parameter && name) { if (!ts.isParameterPropertyDeclaration(parameter) && !ts.parameterIsThisKeyword(parameter) && !isIdentifierThatStartsWithUnderscore(name)) { - addDiagnostic(1 /* Parameter */, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local))); + addDiagnostic(parameter, 1 /* Parameter */, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local))); } } else { @@ -50991,7 +50984,7 @@ var ts; (importClause.namedBindings.kind === 249 /* NamespaceImport */ ? 1 : importClause.namedBindings.elements.length) : 0); if (nDeclarations === unuseds.length) { - addDiagnostic(0 /* Local */, unuseds.length === 1 + addDiagnostic(importDecl, 0 /* Local */, unuseds.length === 1 ? ts.createDiagnosticForNode(importDecl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.first(unuseds).name)) : ts.createDiagnosticForNode(importDecl, ts.Diagnostics.All_imports_in_import_declaration_are_unused)); } @@ -51010,7 +51003,7 @@ var ts; addToGroup(unusedVariables, bindingPattern.parent.parent, bindingPattern.parent, getNodeId); } else { - addDiagnostic(kind, bindingElements.length === 1 + addDiagnostic(bindingPattern, kind, bindingElements.length === 1 ? ts.createDiagnosticForNode(bindingPattern, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(ts.first(bindingElements).name, ts.isIdentifier))) : ts.createDiagnosticForNode(bindingPattern, ts.Diagnostics.All_destructured_elements_are_unused)); } @@ -51018,21 +51011,21 @@ var ts; else { for (var _i = 0, bindingElements_1 = bindingElements; _i < bindingElements_1.length; _i++) { var e = bindingElements_1[_i]; - addDiagnostic(kind, ts.createDiagnosticForNode(e, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(e.name, ts.isIdentifier)))); + addDiagnostic(e, kind, ts.createDiagnosticForNode(e, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(e.name, ts.isIdentifier)))); } } }); unusedVariables.forEach(function (_a) { var declarationList = _a[0], declarations = _a[1]; if (declarationList.declarations.length === declarations.length) { - addDiagnostic(0 /* Local */, declarations.length === 1 + addDiagnostic(declarationList, 0 /* Local */, declarations.length === 1 ? ts.createDiagnosticForNode(ts.first(declarations).name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, bindingNameText(ts.first(declarations).name)) : ts.createDiagnosticForNode(declarationList.parent.kind === 217 /* VariableStatement */ ? declarationList.parent : declarationList, ts.Diagnostics.All_variables_are_unused)); } else { for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) { var decl = declarations_5[_i]; - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(decl.name, ts.isIdentifier)))); + addDiagnostic(decl, 0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(decl.name, ts.isIdentifier)))); } } }); @@ -53610,8 +53603,8 @@ var ts; registerForUnusedIdentifiersCheck(node); } if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) { - checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (kind, diag) { - if (unusedIsError(kind)) { + checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) { + if (!ts.containsParseError(containingNode) && unusedIsError(kind)) { diagnostics.add(diag); } }); @@ -60029,6 +60022,9 @@ var ts; case 203 /* ConditionalExpression */: node = node.condition; continue; + case 191 /* TaggedTemplateExpression */: + node = node.tag; + continue; case 189 /* CallExpression */: if (stopAtCallExpressions) { return node; @@ -82066,7 +82062,7 @@ var ts; } function createFileWatcherWithTriggerLogging(host, file, cb, flags, passThrough, detailInfo1, detailInfo2, addWatch, log, watchCaption, getDetailWatchInfo) { return addWatch(host, file, function (fileName, cbOptional) { - var triggerredInfo = watchCaption + ":: Triggered with " + fileName + (cbOptional !== undefined ? cbOptional : "") + ":: " + getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo); + var triggerredInfo = watchCaption + ":: Triggered with " + fileName + " " + (cbOptional !== undefined ? cbOptional : "") + ":: " + getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo); log(triggerredInfo); var start = ts.timestamp(); cb(fileName, cbOptional, passThrough); @@ -82558,6 +82554,7 @@ var ts; var programDiagnostics = ts.createDiagnosticCollection(); var currentDirectory = host.getCurrentDirectory(); var supportedExtensions = ts.getSupportedExtensions(options); + var supportedExtensionsWithJsonIfResolveJsonModule = options.resolveJsonModule ? supportedExtensions.concat([".json" /* Json */]) : undefined; // Map storing if there is emit blocking diagnostics for given input var hasEmitBlockingDiagnostics = ts.createMap(); var _compilerOptionsObjectLiteralSyntax; @@ -83706,7 +83703,7 @@ var ts; } function getSourceFileFromReferenceWorker(fileName, getSourceFile, fail, refFile) { if (ts.hasExtension(fileName)) { - if (!options.allowNonTsExtensions && !ts.forEach(supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) { + if (!options.allowNonTsExtensions && !ts.forEach(supportedExtensionsWithJsonIfResolveJsonModule || supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) { if (fail) fail(ts.Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1, fileName, "'" + supportedExtensions.join("', '") + "'"); return undefined; @@ -86476,16 +86473,15 @@ var ts; }; // From tsc we want to get already parsed result and hence check for rootFileNames var newLine = updateNewLine(); + if (configFileName && host.configFileParsingResult) { + setConfigFileParsingResult(host.configFileParsingResult); + newLine = updateNewLine(); + } reportWatchDiagnostic(ts.Diagnostics.Starting_compilation_in_watch_mode); - if (configFileName) { + if (configFileName && !host.configFileParsingResult) { newLine = ts.getNewLineCharacter(optionsToExtendForConfigFile, function () { return host.getNewLine(); }); - if (host.configFileParsingResult) { - setConfigFileParsingResult(host.configFileParsingResult); - } - else { - ts.Debug.assert(!rootFileNames); - parseConfigFile(); - } + ts.Debug.assert(!rootFileNames); + parseConfigFile(); newLine = updateNewLine(); } var trace = host.trace && (function (s) { host.trace(s + newLine); }); @@ -87200,6 +87196,7 @@ var ts; return builder.cleanAllProjects(); } if (watch) { + builder.buildAllProjects(); builder.startWatching(); return undefined; } @@ -96219,7 +96216,7 @@ var ts; "borrows", "callback", "class", - "classDesc", + "classdesc", "constant", "constructor", "constructs", @@ -96236,16 +96233,16 @@ var ts; "external", "field", "file", - "fileOverview", + "fileoverview", "fires", "function", "generator", "global", - "hideConstructor", + "hideconstructor", "host", "ignore", "implements", - "inheritDoc", + "inheritdoc", "inner", "instance", "interface", @@ -96254,7 +96251,7 @@ var ts; "license", "listens", "member", - "memberOf", + "memberof", "method", "mixes", "module", @@ -96846,7 +96843,7 @@ var ts; /** Call after calling `startNode` and adding children to it. */ function endNode() { if (parent.children) { - mergeChildren(parent.children); + mergeChildren(parent.children, parent); sortChildren(parent.children); } parent = parentsStack.pop(); @@ -97002,7 +96999,7 @@ var ts; } } /** Merge declarations of the same kind. */ - function mergeChildren(children) { + function mergeChildren(children, node) { var nameToItems = ts.createMap(); ts.filterMutate(children, function (child) { var declName = ts.getNameOfDeclaration(child.node); @@ -97019,7 +97016,7 @@ var ts; if (itemsWithSameName instanceof Array) { for (var _i = 0, itemsWithSameName_1 = itemsWithSameName; _i < itemsWithSameName_1.length; _i++) { var itemWithSameName = itemsWithSameName_1[_i]; - if (tryMerge(itemWithSameName, child)) { + if (tryMerge(itemWithSameName, child, node)) { return false; } } @@ -97028,7 +97025,7 @@ var ts; } else { var itemWithSameName = itemsWithSameName; - if (tryMerge(itemWithSameName, child)) { + if (tryMerge(itemWithSameName, child, node)) { return false; } nameToItems.set(name, [itemWithSameName, child]); @@ -97036,16 +97033,16 @@ var ts; } }); } - function tryMerge(a, b) { - if (shouldReallyMerge(a.node, b.node)) { + function tryMerge(a, b, parent) { + if (shouldReallyMerge(a.node, b.node, parent)) { merge(a, b); return true; } return false; } /** a and b have the same name, but they may not be mergeable. */ - function shouldReallyMerge(a, b) { - if (a.kind !== b.kind) { + function shouldReallyMerge(a, b, parent) { + if (a.kind !== b.kind || a.parent !== b.parent && !(isOwnChild(a, parent) && isOwnChild(b, parent))) { return false; } switch (a.kind) { @@ -97060,6 +97057,12 @@ var ts; return true; } } + // We want to merge own children like `I` in in `module A { interface I {} } module A { interface I {} }` + // We don't want to merge unrelated children like `m` in `const o = { a: { m() {} }, b: { m() {} } };` + function isOwnChild(n, parent) { + var par = ts.isModuleBlock(n.parent) ? n.parent.parent : n.parent; + return par === parent.node || ts.contains(parent.additionalNodes, par); + } // We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes. // Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'! function areSameModule(a, b) { @@ -97076,7 +97079,7 @@ var ts; } target.children = ts.concatenate(target.children, source.children); if (target.children) { - mergeChildren(target.children); + mergeChildren(target.children, target); sortChildren(target.children); } } @@ -99334,8 +99337,8 @@ var ts; var name = importNameForConvertToDefaultImport(importNode); if (!name) continue; - var module = ts.getResolvedModule(sourceFile, moduleSpecifier.text); - var resolvedFile = module && program.getSourceFile(module.resolvedFileName); + var module_1 = ts.getResolvedModule(sourceFile, moduleSpecifier.text); + var resolvedFile = module_1 && program.getSourceFile(module_1.resolvedFileName); if (resolvedFile && resolvedFile.externalModuleIndicator && ts.isExportAssignment(resolvedFile.externalModuleIndicator) && resolvedFile.externalModuleIndicator.isExportEquals) { diags.push(ts.createDiagnosticForNode(name, ts.Diagnostics.Import_may_be_converted_to_a_default_import)); } @@ -101973,7 +101976,6 @@ var ts; // split comment in lines var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line; var endLine = sourceFile.getLineAndCharacterOfPosition(commentRange.end).line; - var parts; if (startLine === endLine) { if (!firstLineIsIndented) { // treat as single line comment @@ -101981,18 +101983,18 @@ var ts; } return; } - else { - parts = []; - var startPos = commentRange.pos; - for (var line = startLine; line < endLine; line++) { - var endOfLine = ts.getEndLinePosition(line, sourceFile); - parts.push({ pos: startPos, end: endOfLine }); - startPos = ts.getStartPositionOfLine(line + 1, sourceFile); - } - if (indentFinalLine) { - parts.push({ pos: startPos, end: commentRange.end }); - } + var parts = []; + var startPos = commentRange.pos; + for (var line = startLine; line < endLine; line++) { + var endOfLine = ts.getEndLinePosition(line, sourceFile); + parts.push({ pos: startPos, end: endOfLine }); + startPos = ts.getStartPositionOfLine(line + 1, sourceFile); } + if (indentFinalLine) { + parts.push({ pos: startPos, end: commentRange.end }); + } + if (parts.length === 0) + return; var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceColumnInFirstPart = formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options); if (indentation === nonWhitespaceColumnInFirstPart.column) { @@ -102532,6 +102534,9 @@ var ts; getListIfStartEndIsInListRange(node.parent.parameters, start, end); } case 238 /* ClassDeclaration */: + case 207 /* ClassExpression */: + case 239 /* InterfaceDeclaration */: + case 240 /* TypeAliasDeclaration */: return getListIfStartEndIsInListRange(node.parent.typeParameters, node.getStart(sourceFile), end); case 190 /* NewExpression */: case 189 /* CallExpression */: { @@ -102741,17 +102746,10 @@ var ts; function isControlFlowEndingStatement(kind, parent) { switch (kind) { case 228 /* ReturnStatement */: - case 232 /* ThrowStatement */: { - if (parent.kind !== 216 /* Block */) { - return true; - } - var grandParent = parent.parent; - // In a function, we may want to write inner functions after this. - return !(grandParent && grandParent.kind === 194 /* FunctionExpression */ || grandParent.kind === 237 /* FunctionDeclaration */); - } + case 232 /* ThrowStatement */: case 226 /* ContinueStatement */: case 227 /* BreakStatement */: - return true; + return parent.kind !== 216 /* Block */; default: return false; } @@ -106134,31 +106132,32 @@ var ts; var statement = ts.findAncestor(token, ts.isStatement); ts.Debug.assert(statement.getStart(sourceFile) === token.getStart(sourceFile)); var container = (ts.isBlock(statement.parent) ? statement.parent : statement).parent; - switch (container.kind) { - case 220 /* IfStatement */: - if (container.elseStatement) { - if (ts.isBlock(statement.parent)) { - changes.deleteNodeRange(sourceFile, ts.first(statement.parent.statements), ts.last(statement.parent.statements)); + if (!ts.isBlock(statement.parent) || statement === ts.first(statement.parent.statements)) { + switch (container.kind) { + case 220 /* IfStatement */: + if (container.elseStatement) { + if (ts.isBlock(statement.parent)) { + break; + } + else { + changes.replaceNode(sourceFile, statement, ts.createBlock(ts.emptyArray)); + } + return; } - else { - changes.replaceNode(sourceFile, statement, ts.createBlock(ts.emptyArray)); - } - break; - } - // falls through - case 222 /* WhileStatement */: - case 223 /* ForStatement */: - changes.delete(sourceFile, container); - break; - default: - if (ts.isBlock(statement.parent)) { - var end_2 = start + length; - var lastStatement = ts.Debug.assertDefined(lastWhere(ts.sliceAfter(statement.parent.statements, statement), function (s) { return s.pos < end_2; })); - changes.deleteNodeRange(sourceFile, statement, lastStatement); - } - else { - changes.delete(sourceFile, statement); - } + // falls through + case 222 /* WhileStatement */: + case 223 /* ForStatement */: + changes.delete(sourceFile, container); + return; + } + } + if (ts.isBlock(statement.parent)) { + var end_2 = start + length; + var lastStatement = ts.Debug.assertDefined(lastWhere(ts.sliceAfter(statement.parent.statements, statement), function (s) { return s.pos < end_2; })); + changes.deleteNodeRange(sourceFile, statement, lastStatement); + } + else { + changes.delete(sourceFile, statement); } } function lastWhere(a, pred) { @@ -109793,9 +109792,9 @@ var ts; if (isTopLevelDeclarationStatement(statement) && !isExported(sourceFile, statement, useEs6Exports) && forEachTopLevelDeclaration(statement, function (d) { return needExport.has(ts.Debug.assertDefined(d.symbol)); })) { - var exports = addExport(statement, useEs6Exports); - if (exports) - return exports; + var exports_1 = addExport(statement, useEs6Exports); + if (exports_1) + return exports_1; } return statement; }); @@ -120414,7 +120413,7 @@ var ts; }); Logger.prototype.write = function (s) { if (this.fd >= 0) { - var buf = Buffer.from ? Buffer.from(s) : new Buffer(s); + var buf = sys.bufferFrom(s); // tslint:disable-next-line no-null-keyword fs.writeSync(this.fd, buf, 0, buf.length, /*position*/ null); // TODO: GH#18217 } @@ -121011,7 +121010,7 @@ var ts; sys.watchDirectory = watchDirectorySwallowingException; } // Override sys.write because fs.writeSync is not reliable on Node 4 - sys.write = function (s) { return writeMessage(Buffer.from ? Buffer.from(s, "utf8") : new Buffer(s, "utf8")); }; + sys.write = function (s) { return writeMessage(sys.bufferFrom(s, "utf8")); }; sys.watchFile = function (fileName, callback) { var watchedFile = pollingWatchedFileSet.addFile(fileName, callback); return { diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index f57a336bb35..77de91a63b3 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -3910,7 +3910,7 @@ var ts; return parseInt(version.substring(1, dot)); } ts.getNodeMajorVersion = getNodeMajorVersion; - // TODO: this is used as if it's certainly defined in many places. + // TODO: GH#18217 this is used as if it's certainly defined in many places. ts.sys = (function () { // NodeJS detects "\uFEFF" at the start of the string and *replaces* it with the actual // byte order mark from the specified encoding. Using any other byte order mark does @@ -4019,18 +4019,17 @@ var ts; process.stdout._handle.setBlocking(true); } }, - base64decode: Buffer.from ? function (input) { - return Buffer.from(input, "base64").toString("utf8"); - } : function (input) { - return new Buffer(input, "base64").toString("utf8"); - }, - base64encode: Buffer.from ? function (input) { - return Buffer.from(input).toString("base64"); - } : function (input) { - return new Buffer(input).toString("base64"); - } + bufferFrom: bufferFrom, + base64decode: function (input) { return bufferFrom(input, "base64").toString("utf8"); }, + base64encode: function (input) { return bufferFrom(input).toString("base64"); }, }; return nodeSystem; + function bufferFrom(input, encoding) { + // See https://github.com/Microsoft/TypeScript/issues/25652 + return Buffer.from && Buffer.from !== Int8Array.from + ? Buffer.from(input, encoding) + : new Buffer(input, encoding); + } function isFileSystemCaseSensitive() { // win32\win64 are case insensitive platforms if (platform === "win32" || platform === "win64") { @@ -5532,7 +5531,7 @@ var ts; Expected_0_1_type_arguments_provide_these_with_an_extends_tag: diag(8027, ts.DiagnosticCategory.Error, "Expected_0_1_type_arguments_provide_these_with_an_extends_tag_8027", "Expected {0}-{1} type arguments; provide these with an '@extends' tag."), JSDoc_may_only_appear_in_the_last_parameter_of_a_signature: diag(8028, ts.DiagnosticCategory.Error, "JSDoc_may_only_appear_in_the_last_parameter_of_a_signature_8028", "JSDoc '...' may only appear in the last parameter of a signature."), JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type: diag(8029, ts.DiagnosticCategory.Error, "JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_h_8029", "JSDoc '@param' tag has name '{0}', but there is no parameter with that name. It would match 'arguments' if it had an array type."), - The_type_of_a_function_declaration_must_be_callable: diag(8030, ts.DiagnosticCategory.Error, "The_type_of_a_function_declaration_must_be_callable_8030", "The type of a function declaration must be callable."), + The_type_of_a_function_declaration_must_match_the_function_s_signature: diag(8030, ts.DiagnosticCategory.Error, "The_type_of_a_function_declaration_must_match_the_function_s_signature_8030", "The type of a function declaration must match the function's signature."), Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clause: diag(9002, ts.DiagnosticCategory.Error, "Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_clas_9002", "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause."), class_expressions_are_not_currently_supported: diag(9003, ts.DiagnosticCategory.Error, "class_expressions_are_not_currently_supported_9003", "'class' expressions are not currently supported."), Language_service_is_disabled: diag(9004, ts.DiagnosticCategory.Error, "Language_service_is_disabled_9004", "Language service is disabled."), @@ -29462,8 +29461,8 @@ var ts; cancellationToken = undefined; } function addUnusedDiagnostics() { - checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (kind, diag) { - if (!unusedIsError(kind)) { + checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (containingNode, kind, diag) { + if (!ts.containsParseError(containingNode) && !unusedIsError(kind)) { (diagnostics || (diagnostics = [])).push(__assign({}, diag, { category: ts.DiagnosticCategory.Suggestion })); } }); @@ -33435,13 +33434,7 @@ var ts; } } // Use contextual parameter type if one is available - var type = void 0; - if (declaration.symbol.escapedName === "this") { - type = getContextualThisParameterType(func); - } - else { - type = getContextuallyTypedParameterType(declaration); - } + var type = declaration.symbol.escapedName === "this" ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration); if (type) { return addOptionality(type, isOptional); } @@ -50785,12 +50778,12 @@ var ts; // yielded values. The only way to trigger these errors is to try checking its return type. getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } - // A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature - if (ts.isInJavaScriptFile(node)) { - var typeTag = ts.getJSDocTypeTag(node); - if (typeTag && typeTag.typeExpression && !getSignaturesOfType(getTypeFromTypeNode(typeTag.typeExpression), 0 /* Call */).length) { - error(typeTag, ts.Diagnostics.The_type_of_a_function_declaration_must_be_callable); - } + } + // A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature + if (ts.isInJavaScriptFile(node)) { + var typeTag = ts.getJSDocTypeTag(node); + if (typeTag && typeTag.typeExpression && !getContextualCallSignature(getTypeFromTypeNode(typeTag.typeExpression), node)) { + error(typeTag, ts.Diagnostics.The_type_of_a_function_declaration_must_match_the_function_s_signature); } } } @@ -50857,7 +50850,7 @@ var ts; function errorUnusedLocal(declaration, name, addDiagnostic) { var node = ts.getNameOfDeclaration(declaration) || declaration; var message = isTypeDeclaration(declaration) ? ts.Diagnostics._0_is_declared_but_never_used : ts.Diagnostics._0_is_declared_but_its_value_is_never_read; - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(node, message, name)); + addDiagnostic(declaration, 0 /* Local */, ts.createDiagnosticForNode(node, message, name)); } function isIdentifierThatStartsWithUnderscore(node) { return ts.isIdentifier(node) && ts.idText(node).charCodeAt(0) === 95 /* _ */; @@ -50877,14 +50870,14 @@ var ts; } var symbol = getSymbolOfNode(member); if (!symbol.isReferenced && ts.hasModifier(member, 8 /* Private */)) { - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); + addDiagnostic(member, 0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); } break; case 155 /* Constructor */: for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { var parameter = _c[_b]; if (!parameter.symbol.isReferenced && ts.hasModifier(parameter, 8 /* Private */)) { - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(parameter.name, ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read, ts.symbolName(parameter.symbol))); + addDiagnostic(parameter, 0 /* Local */, ts.createDiagnosticForNode(parameter.name, ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read, ts.symbolName(parameter.symbol))); } } break; @@ -50906,7 +50899,7 @@ var ts; for (var _i = 0, typeParameters_2 = typeParameters; _i < typeParameters_2.length; _i++) { var typeParameter = typeParameters_2[_i]; if (!(getMergedSymbol(typeParameter.symbol).isReferenced & 262144 /* TypeParameter */) && !isIdentifierThatStartsWithUnderscore(typeParameter.name)) { - addDiagnostic(1 /* Parameter */, ts.createDiagnosticForNode(typeParameter.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(typeParameter.symbol))); + addDiagnostic(typeParameter, 1 /* Parameter */, ts.createDiagnosticForNode(typeParameter.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(typeParameter.symbol))); } } } @@ -50961,7 +50954,7 @@ var ts; var name = local.valueDeclaration && ts.getNameOfDeclaration(local.valueDeclaration); if (parameter && name) { if (!ts.isParameterPropertyDeclaration(parameter) && !ts.parameterIsThisKeyword(parameter) && !isIdentifierThatStartsWithUnderscore(name)) { - addDiagnostic(1 /* Parameter */, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local))); + addDiagnostic(parameter, 1 /* Parameter */, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local))); } } else { @@ -50978,7 +50971,7 @@ var ts; (importClause.namedBindings.kind === 249 /* NamespaceImport */ ? 1 : importClause.namedBindings.elements.length) : 0); if (nDeclarations === unuseds.length) { - addDiagnostic(0 /* Local */, unuseds.length === 1 + addDiagnostic(importDecl, 0 /* Local */, unuseds.length === 1 ? ts.createDiagnosticForNode(importDecl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.first(unuseds).name)) : ts.createDiagnosticForNode(importDecl, ts.Diagnostics.All_imports_in_import_declaration_are_unused)); } @@ -50997,7 +50990,7 @@ var ts; addToGroup(unusedVariables, bindingPattern.parent.parent, bindingPattern.parent, getNodeId); } else { - addDiagnostic(kind, bindingElements.length === 1 + addDiagnostic(bindingPattern, kind, bindingElements.length === 1 ? ts.createDiagnosticForNode(bindingPattern, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(ts.first(bindingElements).name, ts.isIdentifier))) : ts.createDiagnosticForNode(bindingPattern, ts.Diagnostics.All_destructured_elements_are_unused)); } @@ -51005,21 +50998,21 @@ var ts; else { for (var _i = 0, bindingElements_1 = bindingElements; _i < bindingElements_1.length; _i++) { var e = bindingElements_1[_i]; - addDiagnostic(kind, ts.createDiagnosticForNode(e, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(e.name, ts.isIdentifier)))); + addDiagnostic(e, kind, ts.createDiagnosticForNode(e, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(e.name, ts.isIdentifier)))); } } }); unusedVariables.forEach(function (_a) { var declarationList = _a[0], declarations = _a[1]; if (declarationList.declarations.length === declarations.length) { - addDiagnostic(0 /* Local */, declarations.length === 1 + addDiagnostic(declarationList, 0 /* Local */, declarations.length === 1 ? ts.createDiagnosticForNode(ts.first(declarations).name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, bindingNameText(ts.first(declarations).name)) : ts.createDiagnosticForNode(declarationList.parent.kind === 217 /* VariableStatement */ ? declarationList.parent : declarationList, ts.Diagnostics.All_variables_are_unused)); } else { for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) { var decl = declarations_5[_i]; - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(decl.name, ts.isIdentifier)))); + addDiagnostic(decl, 0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(decl.name, ts.isIdentifier)))); } } }); @@ -53597,8 +53590,8 @@ var ts; registerForUnusedIdentifiersCheck(node); } if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) { - checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (kind, diag) { - if (unusedIsError(kind)) { + checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) { + if (!ts.containsParseError(containingNode) && unusedIsError(kind)) { diagnostics.add(diag); } }); @@ -60016,6 +60009,9 @@ var ts; case 203 /* ConditionalExpression */: node = node.condition; continue; + case 191 /* TaggedTemplateExpression */: + node = node.tag; + continue; case 189 /* CallExpression */: if (stopAtCallExpressions) { return node; @@ -82053,7 +82049,7 @@ var ts; } function createFileWatcherWithTriggerLogging(host, file, cb, flags, passThrough, detailInfo1, detailInfo2, addWatch, log, watchCaption, getDetailWatchInfo) { return addWatch(host, file, function (fileName, cbOptional) { - var triggerredInfo = watchCaption + ":: Triggered with " + fileName + (cbOptional !== undefined ? cbOptional : "") + ":: " + getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo); + var triggerredInfo = watchCaption + ":: Triggered with " + fileName + " " + (cbOptional !== undefined ? cbOptional : "") + ":: " + getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo); log(triggerredInfo); var start = ts.timestamp(); cb(fileName, cbOptional, passThrough); @@ -82545,6 +82541,7 @@ var ts; var programDiagnostics = ts.createDiagnosticCollection(); var currentDirectory = host.getCurrentDirectory(); var supportedExtensions = ts.getSupportedExtensions(options); + var supportedExtensionsWithJsonIfResolveJsonModule = options.resolveJsonModule ? supportedExtensions.concat([".json" /* Json */]) : undefined; // Map storing if there is emit blocking diagnostics for given input var hasEmitBlockingDiagnostics = ts.createMap(); var _compilerOptionsObjectLiteralSyntax; @@ -83693,7 +83690,7 @@ var ts; } function getSourceFileFromReferenceWorker(fileName, getSourceFile, fail, refFile) { if (ts.hasExtension(fileName)) { - if (!options.allowNonTsExtensions && !ts.forEach(supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) { + if (!options.allowNonTsExtensions && !ts.forEach(supportedExtensionsWithJsonIfResolveJsonModule || supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) { if (fail) fail(ts.Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1, fileName, "'" + supportedExtensions.join("', '") + "'"); return undefined; @@ -86463,16 +86460,15 @@ var ts; }; // From tsc we want to get already parsed result and hence check for rootFileNames var newLine = updateNewLine(); + if (configFileName && host.configFileParsingResult) { + setConfigFileParsingResult(host.configFileParsingResult); + newLine = updateNewLine(); + } reportWatchDiagnostic(ts.Diagnostics.Starting_compilation_in_watch_mode); - if (configFileName) { + if (configFileName && !host.configFileParsingResult) { newLine = ts.getNewLineCharacter(optionsToExtendForConfigFile, function () { return host.getNewLine(); }); - if (host.configFileParsingResult) { - setConfigFileParsingResult(host.configFileParsingResult); - } - else { - ts.Debug.assert(!rootFileNames); - parseConfigFile(); - } + ts.Debug.assert(!rootFileNames); + parseConfigFile(); newLine = updateNewLine(); } var trace = host.trace && (function (s) { host.trace(s + newLine); }); @@ -87187,6 +87183,7 @@ var ts; return builder.cleanAllProjects(); } if (watch) { + builder.buildAllProjects(); builder.startWatching(); return undefined; } @@ -96588,7 +96585,7 @@ var ts; "borrows", "callback", "class", - "classDesc", + "classdesc", "constant", "constructor", "constructs", @@ -96605,16 +96602,16 @@ var ts; "external", "field", "file", - "fileOverview", + "fileoverview", "fires", "function", "generator", "global", - "hideConstructor", + "hideconstructor", "host", "ignore", "implements", - "inheritDoc", + "inheritdoc", "inner", "instance", "interface", @@ -96623,7 +96620,7 @@ var ts; "license", "listens", "member", - "memberOf", + "memberof", "method", "mixes", "module", @@ -97215,7 +97212,7 @@ var ts; /** Call after calling `startNode` and adding children to it. */ function endNode() { if (parent.children) { - mergeChildren(parent.children); + mergeChildren(parent.children, parent); sortChildren(parent.children); } parent = parentsStack.pop(); @@ -97371,7 +97368,7 @@ var ts; } } /** Merge declarations of the same kind. */ - function mergeChildren(children) { + function mergeChildren(children, node) { var nameToItems = ts.createMap(); ts.filterMutate(children, function (child) { var declName = ts.getNameOfDeclaration(child.node); @@ -97388,7 +97385,7 @@ var ts; if (itemsWithSameName instanceof Array) { for (var _i = 0, itemsWithSameName_1 = itemsWithSameName; _i < itemsWithSameName_1.length; _i++) { var itemWithSameName = itemsWithSameName_1[_i]; - if (tryMerge(itemWithSameName, child)) { + if (tryMerge(itemWithSameName, child, node)) { return false; } } @@ -97397,7 +97394,7 @@ var ts; } else { var itemWithSameName = itemsWithSameName; - if (tryMerge(itemWithSameName, child)) { + if (tryMerge(itemWithSameName, child, node)) { return false; } nameToItems.set(name, [itemWithSameName, child]); @@ -97405,16 +97402,16 @@ var ts; } }); } - function tryMerge(a, b) { - if (shouldReallyMerge(a.node, b.node)) { + function tryMerge(a, b, parent) { + if (shouldReallyMerge(a.node, b.node, parent)) { merge(a, b); return true; } return false; } /** a and b have the same name, but they may not be mergeable. */ - function shouldReallyMerge(a, b) { - if (a.kind !== b.kind) { + function shouldReallyMerge(a, b, parent) { + if (a.kind !== b.kind || a.parent !== b.parent && !(isOwnChild(a, parent) && isOwnChild(b, parent))) { return false; } switch (a.kind) { @@ -97429,6 +97426,12 @@ var ts; return true; } } + // We want to merge own children like `I` in in `module A { interface I {} } module A { interface I {} }` + // We don't want to merge unrelated children like `m` in `const o = { a: { m() {} }, b: { m() {} } };` + function isOwnChild(n, parent) { + var par = ts.isModuleBlock(n.parent) ? n.parent.parent : n.parent; + return par === parent.node || ts.contains(parent.additionalNodes, par); + } // We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes. // Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'! function areSameModule(a, b) { @@ -97445,7 +97448,7 @@ var ts; } target.children = ts.concatenate(target.children, source.children); if (target.children) { - mergeChildren(target.children); + mergeChildren(target.children, target); sortChildren(target.children); } } @@ -102342,7 +102345,6 @@ var ts; // split comment in lines var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line; var endLine = sourceFile.getLineAndCharacterOfPosition(commentRange.end).line; - var parts; if (startLine === endLine) { if (!firstLineIsIndented) { // treat as single line comment @@ -102350,18 +102352,18 @@ var ts; } return; } - else { - parts = []; - var startPos = commentRange.pos; - for (var line = startLine; line < endLine; line++) { - var endOfLine = ts.getEndLinePosition(line, sourceFile); - parts.push({ pos: startPos, end: endOfLine }); - startPos = ts.getStartPositionOfLine(line + 1, sourceFile); - } - if (indentFinalLine) { - parts.push({ pos: startPos, end: commentRange.end }); - } + var parts = []; + var startPos = commentRange.pos; + for (var line = startLine; line < endLine; line++) { + var endOfLine = ts.getEndLinePosition(line, sourceFile); + parts.push({ pos: startPos, end: endOfLine }); + startPos = ts.getStartPositionOfLine(line + 1, sourceFile); } + if (indentFinalLine) { + parts.push({ pos: startPos, end: commentRange.end }); + } + if (parts.length === 0) + return; var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceColumnInFirstPart = formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options); if (indentation === nonWhitespaceColumnInFirstPart.column) { @@ -102901,6 +102903,9 @@ var ts; getListIfStartEndIsInListRange(node.parent.parameters, start, end); } case 238 /* ClassDeclaration */: + case 207 /* ClassExpression */: + case 239 /* InterfaceDeclaration */: + case 240 /* TypeAliasDeclaration */: return getListIfStartEndIsInListRange(node.parent.typeParameters, node.getStart(sourceFile), end); case 190 /* NewExpression */: case 189 /* CallExpression */: { @@ -103110,17 +103115,10 @@ var ts; function isControlFlowEndingStatement(kind, parent) { switch (kind) { case 228 /* ReturnStatement */: - case 232 /* ThrowStatement */: { - if (parent.kind !== 216 /* Block */) { - return true; - } - var grandParent = parent.parent; - // In a function, we may want to write inner functions after this. - return !(grandParent && grandParent.kind === 194 /* FunctionExpression */ || grandParent.kind === 237 /* FunctionDeclaration */); - } + case 232 /* ThrowStatement */: case 226 /* ContinueStatement */: case 227 /* BreakStatement */: - return true; + return parent.kind !== 216 /* Block */; default: return false; } @@ -106503,31 +106501,32 @@ var ts; var statement = ts.findAncestor(token, ts.isStatement); ts.Debug.assert(statement.getStart(sourceFile) === token.getStart(sourceFile)); var container = (ts.isBlock(statement.parent) ? statement.parent : statement).parent; - switch (container.kind) { - case 220 /* IfStatement */: - if (container.elseStatement) { - if (ts.isBlock(statement.parent)) { - changes.deleteNodeRange(sourceFile, ts.first(statement.parent.statements), ts.last(statement.parent.statements)); + if (!ts.isBlock(statement.parent) || statement === ts.first(statement.parent.statements)) { + switch (container.kind) { + case 220 /* IfStatement */: + if (container.elseStatement) { + if (ts.isBlock(statement.parent)) { + break; + } + else { + changes.replaceNode(sourceFile, statement, ts.createBlock(ts.emptyArray)); + } + return; } - else { - changes.replaceNode(sourceFile, statement, ts.createBlock(ts.emptyArray)); - } - break; - } - // falls through - case 222 /* WhileStatement */: - case 223 /* ForStatement */: - changes.delete(sourceFile, container); - break; - default: - if (ts.isBlock(statement.parent)) { - var end_2 = start + length; - var lastStatement = ts.Debug.assertDefined(lastWhere(ts.sliceAfter(statement.parent.statements, statement), function (s) { return s.pos < end_2; })); - changes.deleteNodeRange(sourceFile, statement, lastStatement); - } - else { - changes.delete(sourceFile, statement); - } + // falls through + case 222 /* WhileStatement */: + case 223 /* ForStatement */: + changes.delete(sourceFile, container); + return; + } + } + if (ts.isBlock(statement.parent)) { + var end_2 = start + length; + var lastStatement = ts.Debug.assertDefined(lastWhere(ts.sliceAfter(statement.parent.statements, statement), function (s) { return s.pos < end_2; })); + changes.deleteNodeRange(sourceFile, statement, lastStatement); + } + else { + changes.delete(sourceFile, statement); } } function lastWhere(a, pred) { diff --git a/lib/typescript.js b/lib/typescript.js index 3808987a217..964a18d2006 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -3910,7 +3910,7 @@ var ts; return parseInt(version.substring(1, dot)); } ts.getNodeMajorVersion = getNodeMajorVersion; - // TODO: this is used as if it's certainly defined in many places. + // TODO: GH#18217 this is used as if it's certainly defined in many places. ts.sys = (function () { // NodeJS detects "\uFEFF" at the start of the string and *replaces* it with the actual // byte order mark from the specified encoding. Using any other byte order mark does @@ -4019,18 +4019,17 @@ var ts; process.stdout._handle.setBlocking(true); } }, - base64decode: Buffer.from ? function (input) { - return Buffer.from(input, "base64").toString("utf8"); - } : function (input) { - return new Buffer(input, "base64").toString("utf8"); - }, - base64encode: Buffer.from ? function (input) { - return Buffer.from(input).toString("base64"); - } : function (input) { - return new Buffer(input).toString("base64"); - } + bufferFrom: bufferFrom, + base64decode: function (input) { return bufferFrom(input, "base64").toString("utf8"); }, + base64encode: function (input) { return bufferFrom(input).toString("base64"); }, }; return nodeSystem; + function bufferFrom(input, encoding) { + // See https://github.com/Microsoft/TypeScript/issues/25652 + return Buffer.from && Buffer.from !== Int8Array.from + ? Buffer.from(input, encoding) + : new Buffer(input, encoding); + } function isFileSystemCaseSensitive() { // win32\win64 are case insensitive platforms if (platform === "win32" || platform === "win64") { @@ -5532,7 +5531,7 @@ var ts; Expected_0_1_type_arguments_provide_these_with_an_extends_tag: diag(8027, ts.DiagnosticCategory.Error, "Expected_0_1_type_arguments_provide_these_with_an_extends_tag_8027", "Expected {0}-{1} type arguments; provide these with an '@extends' tag."), JSDoc_may_only_appear_in_the_last_parameter_of_a_signature: diag(8028, ts.DiagnosticCategory.Error, "JSDoc_may_only_appear_in_the_last_parameter_of_a_signature_8028", "JSDoc '...' may only appear in the last parameter of a signature."), JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type: diag(8029, ts.DiagnosticCategory.Error, "JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_h_8029", "JSDoc '@param' tag has name '{0}', but there is no parameter with that name. It would match 'arguments' if it had an array type."), - The_type_of_a_function_declaration_must_be_callable: diag(8030, ts.DiagnosticCategory.Error, "The_type_of_a_function_declaration_must_be_callable_8030", "The type of a function declaration must be callable."), + The_type_of_a_function_declaration_must_match_the_function_s_signature: diag(8030, ts.DiagnosticCategory.Error, "The_type_of_a_function_declaration_must_match_the_function_s_signature_8030", "The type of a function declaration must match the function's signature."), Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clause: diag(9002, ts.DiagnosticCategory.Error, "Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_clas_9002", "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause."), class_expressions_are_not_currently_supported: diag(9003, ts.DiagnosticCategory.Error, "class_expressions_are_not_currently_supported_9003", "'class' expressions are not currently supported."), Language_service_is_disabled: diag(9004, ts.DiagnosticCategory.Error, "Language_service_is_disabled_9004", "Language service is disabled."), @@ -29462,8 +29461,8 @@ var ts; cancellationToken = undefined; } function addUnusedDiagnostics() { - checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (kind, diag) { - if (!unusedIsError(kind)) { + checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (containingNode, kind, diag) { + if (!ts.containsParseError(containingNode) && !unusedIsError(kind)) { (diagnostics || (diagnostics = [])).push(__assign({}, diag, { category: ts.DiagnosticCategory.Suggestion })); } }); @@ -33435,13 +33434,7 @@ var ts; } } // Use contextual parameter type if one is available - var type = void 0; - if (declaration.symbol.escapedName === "this") { - type = getContextualThisParameterType(func); - } - else { - type = getContextuallyTypedParameterType(declaration); - } + var type = declaration.symbol.escapedName === "this" ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration); if (type) { return addOptionality(type, isOptional); } @@ -50785,12 +50778,12 @@ var ts; // yielded values. The only way to trigger these errors is to try checking its return type. getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } - // A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature - if (ts.isInJavaScriptFile(node)) { - var typeTag = ts.getJSDocTypeTag(node); - if (typeTag && typeTag.typeExpression && !getSignaturesOfType(getTypeFromTypeNode(typeTag.typeExpression), 0 /* Call */).length) { - error(typeTag, ts.Diagnostics.The_type_of_a_function_declaration_must_be_callable); - } + } + // A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature + if (ts.isInJavaScriptFile(node)) { + var typeTag = ts.getJSDocTypeTag(node); + if (typeTag && typeTag.typeExpression && !getContextualCallSignature(getTypeFromTypeNode(typeTag.typeExpression), node)) { + error(typeTag, ts.Diagnostics.The_type_of_a_function_declaration_must_match_the_function_s_signature); } } } @@ -50857,7 +50850,7 @@ var ts; function errorUnusedLocal(declaration, name, addDiagnostic) { var node = ts.getNameOfDeclaration(declaration) || declaration; var message = isTypeDeclaration(declaration) ? ts.Diagnostics._0_is_declared_but_never_used : ts.Diagnostics._0_is_declared_but_its_value_is_never_read; - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(node, message, name)); + addDiagnostic(declaration, 0 /* Local */, ts.createDiagnosticForNode(node, message, name)); } function isIdentifierThatStartsWithUnderscore(node) { return ts.isIdentifier(node) && ts.idText(node).charCodeAt(0) === 95 /* _ */; @@ -50877,14 +50870,14 @@ var ts; } var symbol = getSymbolOfNode(member); if (!symbol.isReferenced && ts.hasModifier(member, 8 /* Private */)) { - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); + addDiagnostic(member, 0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); } break; case 155 /* Constructor */: for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { var parameter = _c[_b]; if (!parameter.symbol.isReferenced && ts.hasModifier(parameter, 8 /* Private */)) { - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(parameter.name, ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read, ts.symbolName(parameter.symbol))); + addDiagnostic(parameter, 0 /* Local */, ts.createDiagnosticForNode(parameter.name, ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read, ts.symbolName(parameter.symbol))); } } break; @@ -50906,7 +50899,7 @@ var ts; for (var _i = 0, typeParameters_2 = typeParameters; _i < typeParameters_2.length; _i++) { var typeParameter = typeParameters_2[_i]; if (!(getMergedSymbol(typeParameter.symbol).isReferenced & 262144 /* TypeParameter */) && !isIdentifierThatStartsWithUnderscore(typeParameter.name)) { - addDiagnostic(1 /* Parameter */, ts.createDiagnosticForNode(typeParameter.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(typeParameter.symbol))); + addDiagnostic(typeParameter, 1 /* Parameter */, ts.createDiagnosticForNode(typeParameter.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(typeParameter.symbol))); } } } @@ -50961,7 +50954,7 @@ var ts; var name = local.valueDeclaration && ts.getNameOfDeclaration(local.valueDeclaration); if (parameter && name) { if (!ts.isParameterPropertyDeclaration(parameter) && !ts.parameterIsThisKeyword(parameter) && !isIdentifierThatStartsWithUnderscore(name)) { - addDiagnostic(1 /* Parameter */, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local))); + addDiagnostic(parameter, 1 /* Parameter */, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local))); } } else { @@ -50978,7 +50971,7 @@ var ts; (importClause.namedBindings.kind === 249 /* NamespaceImport */ ? 1 : importClause.namedBindings.elements.length) : 0); if (nDeclarations === unuseds.length) { - addDiagnostic(0 /* Local */, unuseds.length === 1 + addDiagnostic(importDecl, 0 /* Local */, unuseds.length === 1 ? ts.createDiagnosticForNode(importDecl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.first(unuseds).name)) : ts.createDiagnosticForNode(importDecl, ts.Diagnostics.All_imports_in_import_declaration_are_unused)); } @@ -50997,7 +50990,7 @@ var ts; addToGroup(unusedVariables, bindingPattern.parent.parent, bindingPattern.parent, getNodeId); } else { - addDiagnostic(kind, bindingElements.length === 1 + addDiagnostic(bindingPattern, kind, bindingElements.length === 1 ? ts.createDiagnosticForNode(bindingPattern, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(ts.first(bindingElements).name, ts.isIdentifier))) : ts.createDiagnosticForNode(bindingPattern, ts.Diagnostics.All_destructured_elements_are_unused)); } @@ -51005,21 +50998,21 @@ var ts; else { for (var _i = 0, bindingElements_1 = bindingElements; _i < bindingElements_1.length; _i++) { var e = bindingElements_1[_i]; - addDiagnostic(kind, ts.createDiagnosticForNode(e, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(e.name, ts.isIdentifier)))); + addDiagnostic(e, kind, ts.createDiagnosticForNode(e, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(e.name, ts.isIdentifier)))); } } }); unusedVariables.forEach(function (_a) { var declarationList = _a[0], declarations = _a[1]; if (declarationList.declarations.length === declarations.length) { - addDiagnostic(0 /* Local */, declarations.length === 1 + addDiagnostic(declarationList, 0 /* Local */, declarations.length === 1 ? ts.createDiagnosticForNode(ts.first(declarations).name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, bindingNameText(ts.first(declarations).name)) : ts.createDiagnosticForNode(declarationList.parent.kind === 217 /* VariableStatement */ ? declarationList.parent : declarationList, ts.Diagnostics.All_variables_are_unused)); } else { for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) { var decl = declarations_5[_i]; - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(decl.name, ts.isIdentifier)))); + addDiagnostic(decl, 0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(decl.name, ts.isIdentifier)))); } } }); @@ -53597,8 +53590,8 @@ var ts; registerForUnusedIdentifiersCheck(node); } if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) { - checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (kind, diag) { - if (unusedIsError(kind)) { + checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) { + if (!ts.containsParseError(containingNode) && unusedIsError(kind)) { diagnostics.add(diag); } }); @@ -60016,6 +60009,9 @@ var ts; case 203 /* ConditionalExpression */: node = node.condition; continue; + case 191 /* TaggedTemplateExpression */: + node = node.tag; + continue; case 189 /* CallExpression */: if (stopAtCallExpressions) { return node; @@ -82053,7 +82049,7 @@ var ts; } function createFileWatcherWithTriggerLogging(host, file, cb, flags, passThrough, detailInfo1, detailInfo2, addWatch, log, watchCaption, getDetailWatchInfo) { return addWatch(host, file, function (fileName, cbOptional) { - var triggerredInfo = watchCaption + ":: Triggered with " + fileName + (cbOptional !== undefined ? cbOptional : "") + ":: " + getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo); + var triggerredInfo = watchCaption + ":: Triggered with " + fileName + " " + (cbOptional !== undefined ? cbOptional : "") + ":: " + getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo); log(triggerredInfo); var start = ts.timestamp(); cb(fileName, cbOptional, passThrough); @@ -82545,6 +82541,7 @@ var ts; var programDiagnostics = ts.createDiagnosticCollection(); var currentDirectory = host.getCurrentDirectory(); var supportedExtensions = ts.getSupportedExtensions(options); + var supportedExtensionsWithJsonIfResolveJsonModule = options.resolveJsonModule ? supportedExtensions.concat([".json" /* Json */]) : undefined; // Map storing if there is emit blocking diagnostics for given input var hasEmitBlockingDiagnostics = ts.createMap(); var _compilerOptionsObjectLiteralSyntax; @@ -83693,7 +83690,7 @@ var ts; } function getSourceFileFromReferenceWorker(fileName, getSourceFile, fail, refFile) { if (ts.hasExtension(fileName)) { - if (!options.allowNonTsExtensions && !ts.forEach(supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) { + if (!options.allowNonTsExtensions && !ts.forEach(supportedExtensionsWithJsonIfResolveJsonModule || supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) { if (fail) fail(ts.Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1, fileName, "'" + supportedExtensions.join("', '") + "'"); return undefined; @@ -86463,16 +86460,15 @@ var ts; }; // From tsc we want to get already parsed result and hence check for rootFileNames var newLine = updateNewLine(); + if (configFileName && host.configFileParsingResult) { + setConfigFileParsingResult(host.configFileParsingResult); + newLine = updateNewLine(); + } reportWatchDiagnostic(ts.Diagnostics.Starting_compilation_in_watch_mode); - if (configFileName) { + if (configFileName && !host.configFileParsingResult) { newLine = ts.getNewLineCharacter(optionsToExtendForConfigFile, function () { return host.getNewLine(); }); - if (host.configFileParsingResult) { - setConfigFileParsingResult(host.configFileParsingResult); - } - else { - ts.Debug.assert(!rootFileNames); - parseConfigFile(); - } + ts.Debug.assert(!rootFileNames); + parseConfigFile(); newLine = updateNewLine(); } var trace = host.trace && (function (s) { host.trace(s + newLine); }); @@ -87187,6 +87183,7 @@ var ts; return builder.cleanAllProjects(); } if (watch) { + builder.buildAllProjects(); builder.startWatching(); return undefined; } @@ -96588,7 +96585,7 @@ var ts; "borrows", "callback", "class", - "classDesc", + "classdesc", "constant", "constructor", "constructs", @@ -96605,16 +96602,16 @@ var ts; "external", "field", "file", - "fileOverview", + "fileoverview", "fires", "function", "generator", "global", - "hideConstructor", + "hideconstructor", "host", "ignore", "implements", - "inheritDoc", + "inheritdoc", "inner", "instance", "interface", @@ -96623,7 +96620,7 @@ var ts; "license", "listens", "member", - "memberOf", + "memberof", "method", "mixes", "module", @@ -97215,7 +97212,7 @@ var ts; /** Call after calling `startNode` and adding children to it. */ function endNode() { if (parent.children) { - mergeChildren(parent.children); + mergeChildren(parent.children, parent); sortChildren(parent.children); } parent = parentsStack.pop(); @@ -97371,7 +97368,7 @@ var ts; } } /** Merge declarations of the same kind. */ - function mergeChildren(children) { + function mergeChildren(children, node) { var nameToItems = ts.createMap(); ts.filterMutate(children, function (child) { var declName = ts.getNameOfDeclaration(child.node); @@ -97388,7 +97385,7 @@ var ts; if (itemsWithSameName instanceof Array) { for (var _i = 0, itemsWithSameName_1 = itemsWithSameName; _i < itemsWithSameName_1.length; _i++) { var itemWithSameName = itemsWithSameName_1[_i]; - if (tryMerge(itemWithSameName, child)) { + if (tryMerge(itemWithSameName, child, node)) { return false; } } @@ -97397,7 +97394,7 @@ var ts; } else { var itemWithSameName = itemsWithSameName; - if (tryMerge(itemWithSameName, child)) { + if (tryMerge(itemWithSameName, child, node)) { return false; } nameToItems.set(name, [itemWithSameName, child]); @@ -97405,16 +97402,16 @@ var ts; } }); } - function tryMerge(a, b) { - if (shouldReallyMerge(a.node, b.node)) { + function tryMerge(a, b, parent) { + if (shouldReallyMerge(a.node, b.node, parent)) { merge(a, b); return true; } return false; } /** a and b have the same name, but they may not be mergeable. */ - function shouldReallyMerge(a, b) { - if (a.kind !== b.kind) { + function shouldReallyMerge(a, b, parent) { + if (a.kind !== b.kind || a.parent !== b.parent && !(isOwnChild(a, parent) && isOwnChild(b, parent))) { return false; } switch (a.kind) { @@ -97429,6 +97426,12 @@ var ts; return true; } } + // We want to merge own children like `I` in in `module A { interface I {} } module A { interface I {} }` + // We don't want to merge unrelated children like `m` in `const o = { a: { m() {} }, b: { m() {} } };` + function isOwnChild(n, parent) { + var par = ts.isModuleBlock(n.parent) ? n.parent.parent : n.parent; + return par === parent.node || ts.contains(parent.additionalNodes, par); + } // We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes. // Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'! function areSameModule(a, b) { @@ -97445,7 +97448,7 @@ var ts; } target.children = ts.concatenate(target.children, source.children); if (target.children) { - mergeChildren(target.children); + mergeChildren(target.children, target); sortChildren(target.children); } } @@ -102342,7 +102345,6 @@ var ts; // split comment in lines var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line; var endLine = sourceFile.getLineAndCharacterOfPosition(commentRange.end).line; - var parts; if (startLine === endLine) { if (!firstLineIsIndented) { // treat as single line comment @@ -102350,18 +102352,18 @@ var ts; } return; } - else { - parts = []; - var startPos = commentRange.pos; - for (var line = startLine; line < endLine; line++) { - var endOfLine = ts.getEndLinePosition(line, sourceFile); - parts.push({ pos: startPos, end: endOfLine }); - startPos = ts.getStartPositionOfLine(line + 1, sourceFile); - } - if (indentFinalLine) { - parts.push({ pos: startPos, end: commentRange.end }); - } + var parts = []; + var startPos = commentRange.pos; + for (var line = startLine; line < endLine; line++) { + var endOfLine = ts.getEndLinePosition(line, sourceFile); + parts.push({ pos: startPos, end: endOfLine }); + startPos = ts.getStartPositionOfLine(line + 1, sourceFile); } + if (indentFinalLine) { + parts.push({ pos: startPos, end: commentRange.end }); + } + if (parts.length === 0) + return; var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceColumnInFirstPart = formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options); if (indentation === nonWhitespaceColumnInFirstPart.column) { @@ -102901,6 +102903,9 @@ var ts; getListIfStartEndIsInListRange(node.parent.parameters, start, end); } case 238 /* ClassDeclaration */: + case 207 /* ClassExpression */: + case 239 /* InterfaceDeclaration */: + case 240 /* TypeAliasDeclaration */: return getListIfStartEndIsInListRange(node.parent.typeParameters, node.getStart(sourceFile), end); case 190 /* NewExpression */: case 189 /* CallExpression */: { @@ -103110,17 +103115,10 @@ var ts; function isControlFlowEndingStatement(kind, parent) { switch (kind) { case 228 /* ReturnStatement */: - case 232 /* ThrowStatement */: { - if (parent.kind !== 216 /* Block */) { - return true; - } - var grandParent = parent.parent; - // In a function, we may want to write inner functions after this. - return !(grandParent && grandParent.kind === 194 /* FunctionExpression */ || grandParent.kind === 237 /* FunctionDeclaration */); - } + case 232 /* ThrowStatement */: case 226 /* ContinueStatement */: case 227 /* BreakStatement */: - return true; + return parent.kind !== 216 /* Block */; default: return false; } @@ -106503,31 +106501,32 @@ var ts; var statement = ts.findAncestor(token, ts.isStatement); ts.Debug.assert(statement.getStart(sourceFile) === token.getStart(sourceFile)); var container = (ts.isBlock(statement.parent) ? statement.parent : statement).parent; - switch (container.kind) { - case 220 /* IfStatement */: - if (container.elseStatement) { - if (ts.isBlock(statement.parent)) { - changes.deleteNodeRange(sourceFile, ts.first(statement.parent.statements), ts.last(statement.parent.statements)); + if (!ts.isBlock(statement.parent) || statement === ts.first(statement.parent.statements)) { + switch (container.kind) { + case 220 /* IfStatement */: + if (container.elseStatement) { + if (ts.isBlock(statement.parent)) { + break; + } + else { + changes.replaceNode(sourceFile, statement, ts.createBlock(ts.emptyArray)); + } + return; } - else { - changes.replaceNode(sourceFile, statement, ts.createBlock(ts.emptyArray)); - } - break; - } - // falls through - case 222 /* WhileStatement */: - case 223 /* ForStatement */: - changes.delete(sourceFile, container); - break; - default: - if (ts.isBlock(statement.parent)) { - var end_2 = start + length; - var lastStatement = ts.Debug.assertDefined(lastWhere(ts.sliceAfter(statement.parent.statements, statement), function (s) { return s.pos < end_2; })); - changes.deleteNodeRange(sourceFile, statement, lastStatement); - } - else { - changes.delete(sourceFile, statement); - } + // falls through + case 222 /* WhileStatement */: + case 223 /* ForStatement */: + changes.delete(sourceFile, container); + return; + } + } + if (ts.isBlock(statement.parent)) { + var end_2 = start + length; + var lastStatement = ts.Debug.assertDefined(lastWhere(ts.sliceAfter(statement.parent.statements, statement), function (s) { return s.pos < end_2; })); + changes.deleteNodeRange(sourceFile, statement, lastStatement); + } + else { + changes.delete(sourceFile, statement); } } function lastWhere(a, pred) { diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 3808987a217..964a18d2006 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -3910,7 +3910,7 @@ var ts; return parseInt(version.substring(1, dot)); } ts.getNodeMajorVersion = getNodeMajorVersion; - // TODO: this is used as if it's certainly defined in many places. + // TODO: GH#18217 this is used as if it's certainly defined in many places. ts.sys = (function () { // NodeJS detects "\uFEFF" at the start of the string and *replaces* it with the actual // byte order mark from the specified encoding. Using any other byte order mark does @@ -4019,18 +4019,17 @@ var ts; process.stdout._handle.setBlocking(true); } }, - base64decode: Buffer.from ? function (input) { - return Buffer.from(input, "base64").toString("utf8"); - } : function (input) { - return new Buffer(input, "base64").toString("utf8"); - }, - base64encode: Buffer.from ? function (input) { - return Buffer.from(input).toString("base64"); - } : function (input) { - return new Buffer(input).toString("base64"); - } + bufferFrom: bufferFrom, + base64decode: function (input) { return bufferFrom(input, "base64").toString("utf8"); }, + base64encode: function (input) { return bufferFrom(input).toString("base64"); }, }; return nodeSystem; + function bufferFrom(input, encoding) { + // See https://github.com/Microsoft/TypeScript/issues/25652 + return Buffer.from && Buffer.from !== Int8Array.from + ? Buffer.from(input, encoding) + : new Buffer(input, encoding); + } function isFileSystemCaseSensitive() { // win32\win64 are case insensitive platforms if (platform === "win32" || platform === "win64") { @@ -5532,7 +5531,7 @@ var ts; Expected_0_1_type_arguments_provide_these_with_an_extends_tag: diag(8027, ts.DiagnosticCategory.Error, "Expected_0_1_type_arguments_provide_these_with_an_extends_tag_8027", "Expected {0}-{1} type arguments; provide these with an '@extends' tag."), JSDoc_may_only_appear_in_the_last_parameter_of_a_signature: diag(8028, ts.DiagnosticCategory.Error, "JSDoc_may_only_appear_in_the_last_parameter_of_a_signature_8028", "JSDoc '...' may only appear in the last parameter of a signature."), JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type: diag(8029, ts.DiagnosticCategory.Error, "JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_h_8029", "JSDoc '@param' tag has name '{0}', but there is no parameter with that name. It would match 'arguments' if it had an array type."), - The_type_of_a_function_declaration_must_be_callable: diag(8030, ts.DiagnosticCategory.Error, "The_type_of_a_function_declaration_must_be_callable_8030", "The type of a function declaration must be callable."), + The_type_of_a_function_declaration_must_match_the_function_s_signature: diag(8030, ts.DiagnosticCategory.Error, "The_type_of_a_function_declaration_must_match_the_function_s_signature_8030", "The type of a function declaration must match the function's signature."), Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clause: diag(9002, ts.DiagnosticCategory.Error, "Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_clas_9002", "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause."), class_expressions_are_not_currently_supported: diag(9003, ts.DiagnosticCategory.Error, "class_expressions_are_not_currently_supported_9003", "'class' expressions are not currently supported."), Language_service_is_disabled: diag(9004, ts.DiagnosticCategory.Error, "Language_service_is_disabled_9004", "Language service is disabled."), @@ -29462,8 +29461,8 @@ var ts; cancellationToken = undefined; } function addUnusedDiagnostics() { - checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (kind, diag) { - if (!unusedIsError(kind)) { + checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (containingNode, kind, diag) { + if (!ts.containsParseError(containingNode) && !unusedIsError(kind)) { (diagnostics || (diagnostics = [])).push(__assign({}, diag, { category: ts.DiagnosticCategory.Suggestion })); } }); @@ -33435,13 +33434,7 @@ var ts; } } // Use contextual parameter type if one is available - var type = void 0; - if (declaration.symbol.escapedName === "this") { - type = getContextualThisParameterType(func); - } - else { - type = getContextuallyTypedParameterType(declaration); - } + var type = declaration.symbol.escapedName === "this" ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration); if (type) { return addOptionality(type, isOptional); } @@ -50785,12 +50778,12 @@ var ts; // yielded values. The only way to trigger these errors is to try checking its return type. getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } - // A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature - if (ts.isInJavaScriptFile(node)) { - var typeTag = ts.getJSDocTypeTag(node); - if (typeTag && typeTag.typeExpression && !getSignaturesOfType(getTypeFromTypeNode(typeTag.typeExpression), 0 /* Call */).length) { - error(typeTag, ts.Diagnostics.The_type_of_a_function_declaration_must_be_callable); - } + } + // A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature + if (ts.isInJavaScriptFile(node)) { + var typeTag = ts.getJSDocTypeTag(node); + if (typeTag && typeTag.typeExpression && !getContextualCallSignature(getTypeFromTypeNode(typeTag.typeExpression), node)) { + error(typeTag, ts.Diagnostics.The_type_of_a_function_declaration_must_match_the_function_s_signature); } } } @@ -50857,7 +50850,7 @@ var ts; function errorUnusedLocal(declaration, name, addDiagnostic) { var node = ts.getNameOfDeclaration(declaration) || declaration; var message = isTypeDeclaration(declaration) ? ts.Diagnostics._0_is_declared_but_never_used : ts.Diagnostics._0_is_declared_but_its_value_is_never_read; - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(node, message, name)); + addDiagnostic(declaration, 0 /* Local */, ts.createDiagnosticForNode(node, message, name)); } function isIdentifierThatStartsWithUnderscore(node) { return ts.isIdentifier(node) && ts.idText(node).charCodeAt(0) === 95 /* _ */; @@ -50877,14 +50870,14 @@ var ts; } var symbol = getSymbolOfNode(member); if (!symbol.isReferenced && ts.hasModifier(member, 8 /* Private */)) { - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); + addDiagnostic(member, 0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); } break; case 155 /* Constructor */: for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { var parameter = _c[_b]; if (!parameter.symbol.isReferenced && ts.hasModifier(parameter, 8 /* Private */)) { - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(parameter.name, ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read, ts.symbolName(parameter.symbol))); + addDiagnostic(parameter, 0 /* Local */, ts.createDiagnosticForNode(parameter.name, ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read, ts.symbolName(parameter.symbol))); } } break; @@ -50906,7 +50899,7 @@ var ts; for (var _i = 0, typeParameters_2 = typeParameters; _i < typeParameters_2.length; _i++) { var typeParameter = typeParameters_2[_i]; if (!(getMergedSymbol(typeParameter.symbol).isReferenced & 262144 /* TypeParameter */) && !isIdentifierThatStartsWithUnderscore(typeParameter.name)) { - addDiagnostic(1 /* Parameter */, ts.createDiagnosticForNode(typeParameter.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(typeParameter.symbol))); + addDiagnostic(typeParameter, 1 /* Parameter */, ts.createDiagnosticForNode(typeParameter.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(typeParameter.symbol))); } } } @@ -50961,7 +50954,7 @@ var ts; var name = local.valueDeclaration && ts.getNameOfDeclaration(local.valueDeclaration); if (parameter && name) { if (!ts.isParameterPropertyDeclaration(parameter) && !ts.parameterIsThisKeyword(parameter) && !isIdentifierThatStartsWithUnderscore(name)) { - addDiagnostic(1 /* Parameter */, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local))); + addDiagnostic(parameter, 1 /* Parameter */, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local))); } } else { @@ -50978,7 +50971,7 @@ var ts; (importClause.namedBindings.kind === 249 /* NamespaceImport */ ? 1 : importClause.namedBindings.elements.length) : 0); if (nDeclarations === unuseds.length) { - addDiagnostic(0 /* Local */, unuseds.length === 1 + addDiagnostic(importDecl, 0 /* Local */, unuseds.length === 1 ? ts.createDiagnosticForNode(importDecl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.first(unuseds).name)) : ts.createDiagnosticForNode(importDecl, ts.Diagnostics.All_imports_in_import_declaration_are_unused)); } @@ -50997,7 +50990,7 @@ var ts; addToGroup(unusedVariables, bindingPattern.parent.parent, bindingPattern.parent, getNodeId); } else { - addDiagnostic(kind, bindingElements.length === 1 + addDiagnostic(bindingPattern, kind, bindingElements.length === 1 ? ts.createDiagnosticForNode(bindingPattern, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(ts.first(bindingElements).name, ts.isIdentifier))) : ts.createDiagnosticForNode(bindingPattern, ts.Diagnostics.All_destructured_elements_are_unused)); } @@ -51005,21 +50998,21 @@ var ts; else { for (var _i = 0, bindingElements_1 = bindingElements; _i < bindingElements_1.length; _i++) { var e = bindingElements_1[_i]; - addDiagnostic(kind, ts.createDiagnosticForNode(e, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(e.name, ts.isIdentifier)))); + addDiagnostic(e, kind, ts.createDiagnosticForNode(e, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(e.name, ts.isIdentifier)))); } } }); unusedVariables.forEach(function (_a) { var declarationList = _a[0], declarations = _a[1]; if (declarationList.declarations.length === declarations.length) { - addDiagnostic(0 /* Local */, declarations.length === 1 + addDiagnostic(declarationList, 0 /* Local */, declarations.length === 1 ? ts.createDiagnosticForNode(ts.first(declarations).name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, bindingNameText(ts.first(declarations).name)) : ts.createDiagnosticForNode(declarationList.parent.kind === 217 /* VariableStatement */ ? declarationList.parent : declarationList, ts.Diagnostics.All_variables_are_unused)); } else { for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) { var decl = declarations_5[_i]; - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(decl.name, ts.isIdentifier)))); + addDiagnostic(decl, 0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(decl.name, ts.isIdentifier)))); } } }); @@ -53597,8 +53590,8 @@ var ts; registerForUnusedIdentifiersCheck(node); } if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) { - checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (kind, diag) { - if (unusedIsError(kind)) { + checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) { + if (!ts.containsParseError(containingNode) && unusedIsError(kind)) { diagnostics.add(diag); } }); @@ -60016,6 +60009,9 @@ var ts; case 203 /* ConditionalExpression */: node = node.condition; continue; + case 191 /* TaggedTemplateExpression */: + node = node.tag; + continue; case 189 /* CallExpression */: if (stopAtCallExpressions) { return node; @@ -82053,7 +82049,7 @@ var ts; } function createFileWatcherWithTriggerLogging(host, file, cb, flags, passThrough, detailInfo1, detailInfo2, addWatch, log, watchCaption, getDetailWatchInfo) { return addWatch(host, file, function (fileName, cbOptional) { - var triggerredInfo = watchCaption + ":: Triggered with " + fileName + (cbOptional !== undefined ? cbOptional : "") + ":: " + getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo); + var triggerredInfo = watchCaption + ":: Triggered with " + fileName + " " + (cbOptional !== undefined ? cbOptional : "") + ":: " + getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo); log(triggerredInfo); var start = ts.timestamp(); cb(fileName, cbOptional, passThrough); @@ -82545,6 +82541,7 @@ var ts; var programDiagnostics = ts.createDiagnosticCollection(); var currentDirectory = host.getCurrentDirectory(); var supportedExtensions = ts.getSupportedExtensions(options); + var supportedExtensionsWithJsonIfResolveJsonModule = options.resolveJsonModule ? supportedExtensions.concat([".json" /* Json */]) : undefined; // Map storing if there is emit blocking diagnostics for given input var hasEmitBlockingDiagnostics = ts.createMap(); var _compilerOptionsObjectLiteralSyntax; @@ -83693,7 +83690,7 @@ var ts; } function getSourceFileFromReferenceWorker(fileName, getSourceFile, fail, refFile) { if (ts.hasExtension(fileName)) { - if (!options.allowNonTsExtensions && !ts.forEach(supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) { + if (!options.allowNonTsExtensions && !ts.forEach(supportedExtensionsWithJsonIfResolveJsonModule || supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) { if (fail) fail(ts.Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1, fileName, "'" + supportedExtensions.join("', '") + "'"); return undefined; @@ -86463,16 +86460,15 @@ var ts; }; // From tsc we want to get already parsed result and hence check for rootFileNames var newLine = updateNewLine(); + if (configFileName && host.configFileParsingResult) { + setConfigFileParsingResult(host.configFileParsingResult); + newLine = updateNewLine(); + } reportWatchDiagnostic(ts.Diagnostics.Starting_compilation_in_watch_mode); - if (configFileName) { + if (configFileName && !host.configFileParsingResult) { newLine = ts.getNewLineCharacter(optionsToExtendForConfigFile, function () { return host.getNewLine(); }); - if (host.configFileParsingResult) { - setConfigFileParsingResult(host.configFileParsingResult); - } - else { - ts.Debug.assert(!rootFileNames); - parseConfigFile(); - } + ts.Debug.assert(!rootFileNames); + parseConfigFile(); newLine = updateNewLine(); } var trace = host.trace && (function (s) { host.trace(s + newLine); }); @@ -87187,6 +87183,7 @@ var ts; return builder.cleanAllProjects(); } if (watch) { + builder.buildAllProjects(); builder.startWatching(); return undefined; } @@ -96588,7 +96585,7 @@ var ts; "borrows", "callback", "class", - "classDesc", + "classdesc", "constant", "constructor", "constructs", @@ -96605,16 +96602,16 @@ var ts; "external", "field", "file", - "fileOverview", + "fileoverview", "fires", "function", "generator", "global", - "hideConstructor", + "hideconstructor", "host", "ignore", "implements", - "inheritDoc", + "inheritdoc", "inner", "instance", "interface", @@ -96623,7 +96620,7 @@ var ts; "license", "listens", "member", - "memberOf", + "memberof", "method", "mixes", "module", @@ -97215,7 +97212,7 @@ var ts; /** Call after calling `startNode` and adding children to it. */ function endNode() { if (parent.children) { - mergeChildren(parent.children); + mergeChildren(parent.children, parent); sortChildren(parent.children); } parent = parentsStack.pop(); @@ -97371,7 +97368,7 @@ var ts; } } /** Merge declarations of the same kind. */ - function mergeChildren(children) { + function mergeChildren(children, node) { var nameToItems = ts.createMap(); ts.filterMutate(children, function (child) { var declName = ts.getNameOfDeclaration(child.node); @@ -97388,7 +97385,7 @@ var ts; if (itemsWithSameName instanceof Array) { for (var _i = 0, itemsWithSameName_1 = itemsWithSameName; _i < itemsWithSameName_1.length; _i++) { var itemWithSameName = itemsWithSameName_1[_i]; - if (tryMerge(itemWithSameName, child)) { + if (tryMerge(itemWithSameName, child, node)) { return false; } } @@ -97397,7 +97394,7 @@ var ts; } else { var itemWithSameName = itemsWithSameName; - if (tryMerge(itemWithSameName, child)) { + if (tryMerge(itemWithSameName, child, node)) { return false; } nameToItems.set(name, [itemWithSameName, child]); @@ -97405,16 +97402,16 @@ var ts; } }); } - function tryMerge(a, b) { - if (shouldReallyMerge(a.node, b.node)) { + function tryMerge(a, b, parent) { + if (shouldReallyMerge(a.node, b.node, parent)) { merge(a, b); return true; } return false; } /** a and b have the same name, but they may not be mergeable. */ - function shouldReallyMerge(a, b) { - if (a.kind !== b.kind) { + function shouldReallyMerge(a, b, parent) { + if (a.kind !== b.kind || a.parent !== b.parent && !(isOwnChild(a, parent) && isOwnChild(b, parent))) { return false; } switch (a.kind) { @@ -97429,6 +97426,12 @@ var ts; return true; } } + // We want to merge own children like `I` in in `module A { interface I {} } module A { interface I {} }` + // We don't want to merge unrelated children like `m` in `const o = { a: { m() {} }, b: { m() {} } };` + function isOwnChild(n, parent) { + var par = ts.isModuleBlock(n.parent) ? n.parent.parent : n.parent; + return par === parent.node || ts.contains(parent.additionalNodes, par); + } // We use 1 NavNode to represent 'A.B.C', but there are multiple source nodes. // Only merge module nodes that have the same chain. Don't merge 'A.B.C' with 'A'! function areSameModule(a, b) { @@ -97445,7 +97448,7 @@ var ts; } target.children = ts.concatenate(target.children, source.children); if (target.children) { - mergeChildren(target.children); + mergeChildren(target.children, target); sortChildren(target.children); } } @@ -102342,7 +102345,6 @@ var ts; // split comment in lines var startLine = sourceFile.getLineAndCharacterOfPosition(commentRange.pos).line; var endLine = sourceFile.getLineAndCharacterOfPosition(commentRange.end).line; - var parts; if (startLine === endLine) { if (!firstLineIsIndented) { // treat as single line comment @@ -102350,18 +102352,18 @@ var ts; } return; } - else { - parts = []; - var startPos = commentRange.pos; - for (var line = startLine; line < endLine; line++) { - var endOfLine = ts.getEndLinePosition(line, sourceFile); - parts.push({ pos: startPos, end: endOfLine }); - startPos = ts.getStartPositionOfLine(line + 1, sourceFile); - } - if (indentFinalLine) { - parts.push({ pos: startPos, end: commentRange.end }); - } + var parts = []; + var startPos = commentRange.pos; + for (var line = startLine; line < endLine; line++) { + var endOfLine = ts.getEndLinePosition(line, sourceFile); + parts.push({ pos: startPos, end: endOfLine }); + startPos = ts.getStartPositionOfLine(line + 1, sourceFile); } + if (indentFinalLine) { + parts.push({ pos: startPos, end: commentRange.end }); + } + if (parts.length === 0) + return; var startLinePos = ts.getStartPositionOfLine(startLine, sourceFile); var nonWhitespaceColumnInFirstPart = formatting.SmartIndenter.findFirstNonWhitespaceCharacterAndColumn(startLinePos, parts[0].pos, sourceFile, options); if (indentation === nonWhitespaceColumnInFirstPart.column) { @@ -102901,6 +102903,9 @@ var ts; getListIfStartEndIsInListRange(node.parent.parameters, start, end); } case 238 /* ClassDeclaration */: + case 207 /* ClassExpression */: + case 239 /* InterfaceDeclaration */: + case 240 /* TypeAliasDeclaration */: return getListIfStartEndIsInListRange(node.parent.typeParameters, node.getStart(sourceFile), end); case 190 /* NewExpression */: case 189 /* CallExpression */: { @@ -103110,17 +103115,10 @@ var ts; function isControlFlowEndingStatement(kind, parent) { switch (kind) { case 228 /* ReturnStatement */: - case 232 /* ThrowStatement */: { - if (parent.kind !== 216 /* Block */) { - return true; - } - var grandParent = parent.parent; - // In a function, we may want to write inner functions after this. - return !(grandParent && grandParent.kind === 194 /* FunctionExpression */ || grandParent.kind === 237 /* FunctionDeclaration */); - } + case 232 /* ThrowStatement */: case 226 /* ContinueStatement */: case 227 /* BreakStatement */: - return true; + return parent.kind !== 216 /* Block */; default: return false; } @@ -106503,31 +106501,32 @@ var ts; var statement = ts.findAncestor(token, ts.isStatement); ts.Debug.assert(statement.getStart(sourceFile) === token.getStart(sourceFile)); var container = (ts.isBlock(statement.parent) ? statement.parent : statement).parent; - switch (container.kind) { - case 220 /* IfStatement */: - if (container.elseStatement) { - if (ts.isBlock(statement.parent)) { - changes.deleteNodeRange(sourceFile, ts.first(statement.parent.statements), ts.last(statement.parent.statements)); + if (!ts.isBlock(statement.parent) || statement === ts.first(statement.parent.statements)) { + switch (container.kind) { + case 220 /* IfStatement */: + if (container.elseStatement) { + if (ts.isBlock(statement.parent)) { + break; + } + else { + changes.replaceNode(sourceFile, statement, ts.createBlock(ts.emptyArray)); + } + return; } - else { - changes.replaceNode(sourceFile, statement, ts.createBlock(ts.emptyArray)); - } - break; - } - // falls through - case 222 /* WhileStatement */: - case 223 /* ForStatement */: - changes.delete(sourceFile, container); - break; - default: - if (ts.isBlock(statement.parent)) { - var end_2 = start + length; - var lastStatement = ts.Debug.assertDefined(lastWhere(ts.sliceAfter(statement.parent.statements, statement), function (s) { return s.pos < end_2; })); - changes.deleteNodeRange(sourceFile, statement, lastStatement); - } - else { - changes.delete(sourceFile, statement); - } + // falls through + case 222 /* WhileStatement */: + case 223 /* ForStatement */: + changes.delete(sourceFile, container); + return; + } + } + if (ts.isBlock(statement.parent)) { + var end_2 = start + length; + var lastStatement = ts.Debug.assertDefined(lastWhere(ts.sliceAfter(statement.parent.statements, statement), function (s) { return s.pos < end_2; })); + changes.deleteNodeRange(sourceFile, statement, lastStatement); + } + else { + changes.delete(sourceFile, statement); } } function lastWhere(a, pred) { diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 780f5c4d13d..e39d2a9a58a 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -3923,7 +3923,7 @@ var ts; return parseInt(version.substring(1, dot)); } ts.getNodeMajorVersion = getNodeMajorVersion; - // TODO: this is used as if it's certainly defined in many places. + // TODO: GH#18217 this is used as if it's certainly defined in many places. ts.sys = (function () { // NodeJS detects "\uFEFF" at the start of the string and *replaces* it with the actual // byte order mark from the specified encoding. Using any other byte order mark does @@ -4032,18 +4032,17 @@ var ts; process.stdout._handle.setBlocking(true); } }, - base64decode: Buffer.from ? function (input) { - return Buffer.from(input, "base64").toString("utf8"); - } : function (input) { - return new Buffer(input, "base64").toString("utf8"); - }, - base64encode: Buffer.from ? function (input) { - return Buffer.from(input).toString("base64"); - } : function (input) { - return new Buffer(input).toString("base64"); - } + bufferFrom: bufferFrom, + base64decode: function (input) { return bufferFrom(input, "base64").toString("utf8"); }, + base64encode: function (input) { return bufferFrom(input).toString("base64"); }, }; return nodeSystem; + function bufferFrom(input, encoding) { + // See https://github.com/Microsoft/TypeScript/issues/25652 + return Buffer.from && Buffer.from !== Int8Array.from + ? Buffer.from(input, encoding) + : new Buffer(input, encoding); + } function isFileSystemCaseSensitive() { // win32\win64 are case insensitive platforms if (platform === "win32" || platform === "win64") { @@ -5545,7 +5544,7 @@ var ts; Expected_0_1_type_arguments_provide_these_with_an_extends_tag: diag(8027, ts.DiagnosticCategory.Error, "Expected_0_1_type_arguments_provide_these_with_an_extends_tag_8027", "Expected {0}-{1} type arguments; provide these with an '@extends' tag."), JSDoc_may_only_appear_in_the_last_parameter_of_a_signature: diag(8028, ts.DiagnosticCategory.Error, "JSDoc_may_only_appear_in_the_last_parameter_of_a_signature_8028", "JSDoc '...' may only appear in the last parameter of a signature."), JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type: diag(8029, ts.DiagnosticCategory.Error, "JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_h_8029", "JSDoc '@param' tag has name '{0}', but there is no parameter with that name. It would match 'arguments' if it had an array type."), - The_type_of_a_function_declaration_must_be_callable: diag(8030, ts.DiagnosticCategory.Error, "The_type_of_a_function_declaration_must_be_callable_8030", "The type of a function declaration must be callable."), + The_type_of_a_function_declaration_must_match_the_function_s_signature: diag(8030, ts.DiagnosticCategory.Error, "The_type_of_a_function_declaration_must_match_the_function_s_signature_8030", "The type of a function declaration must match the function's signature."), Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clause: diag(9002, ts.DiagnosticCategory.Error, "Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_clas_9002", "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clause."), class_expressions_are_not_currently_supported: diag(9003, ts.DiagnosticCategory.Error, "class_expressions_are_not_currently_supported_9003", "'class' expressions are not currently supported."), Language_service_is_disabled: diag(9004, ts.DiagnosticCategory.Error, "Language_service_is_disabled_9004", "Language service is disabled."), @@ -29475,8 +29474,8 @@ var ts; cancellationToken = undefined; } function addUnusedDiagnostics() { - checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (kind, diag) { - if (!unusedIsError(kind)) { + checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(file), function (containingNode, kind, diag) { + if (!ts.containsParseError(containingNode) && !unusedIsError(kind)) { (diagnostics || (diagnostics = [])).push(__assign({}, diag, { category: ts.DiagnosticCategory.Suggestion })); } }); @@ -33448,13 +33447,7 @@ var ts; } } // Use contextual parameter type if one is available - var type = void 0; - if (declaration.symbol.escapedName === "this") { - type = getContextualThisParameterType(func); - } - else { - type = getContextuallyTypedParameterType(declaration); - } + var type = declaration.symbol.escapedName === "this" ? getContextualThisParameterType(func) : getContextuallyTypedParameterType(declaration); if (type) { return addOptionality(type, isOptional); } @@ -50798,12 +50791,12 @@ var ts; // yielded values. The only way to trigger these errors is to try checking its return type. getReturnTypeOfSignature(getSignatureFromDeclaration(node)); } - // A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature - if (ts.isInJavaScriptFile(node)) { - var typeTag = ts.getJSDocTypeTag(node); - if (typeTag && typeTag.typeExpression && !getSignaturesOfType(getTypeFromTypeNode(typeTag.typeExpression), 0 /* Call */).length) { - error(typeTag, ts.Diagnostics.The_type_of_a_function_declaration_must_be_callable); - } + } + // A js function declaration can have a @type tag instead of a return type node, but that type must have a call signature + if (ts.isInJavaScriptFile(node)) { + var typeTag = ts.getJSDocTypeTag(node); + if (typeTag && typeTag.typeExpression && !getContextualCallSignature(getTypeFromTypeNode(typeTag.typeExpression), node)) { + error(typeTag, ts.Diagnostics.The_type_of_a_function_declaration_must_match_the_function_s_signature); } } } @@ -50870,7 +50863,7 @@ var ts; function errorUnusedLocal(declaration, name, addDiagnostic) { var node = ts.getNameOfDeclaration(declaration) || declaration; var message = isTypeDeclaration(declaration) ? ts.Diagnostics._0_is_declared_but_never_used : ts.Diagnostics._0_is_declared_but_its_value_is_never_read; - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(node, message, name)); + addDiagnostic(declaration, 0 /* Local */, ts.createDiagnosticForNode(node, message, name)); } function isIdentifierThatStartsWithUnderscore(node) { return ts.isIdentifier(node) && ts.idText(node).charCodeAt(0) === 95 /* _ */; @@ -50890,14 +50883,14 @@ var ts; } var symbol = getSymbolOfNode(member); if (!symbol.isReferenced && ts.hasModifier(member, 8 /* Private */)) { - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); + addDiagnostic(member, 0 /* Local */, ts.createDiagnosticForNode(member.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, symbolToString(symbol))); } break; case 155 /* Constructor */: for (var _b = 0, _c = member.parameters; _b < _c.length; _b++) { var parameter = _c[_b]; if (!parameter.symbol.isReferenced && ts.hasModifier(parameter, 8 /* Private */)) { - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(parameter.name, ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read, ts.symbolName(parameter.symbol))); + addDiagnostic(parameter, 0 /* Local */, ts.createDiagnosticForNode(parameter.name, ts.Diagnostics.Property_0_is_declared_but_its_value_is_never_read, ts.symbolName(parameter.symbol))); } } break; @@ -50919,7 +50912,7 @@ var ts; for (var _i = 0, typeParameters_2 = typeParameters; _i < typeParameters_2.length; _i++) { var typeParameter = typeParameters_2[_i]; if (!(getMergedSymbol(typeParameter.symbol).isReferenced & 262144 /* TypeParameter */) && !isIdentifierThatStartsWithUnderscore(typeParameter.name)) { - addDiagnostic(1 /* Parameter */, ts.createDiagnosticForNode(typeParameter.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(typeParameter.symbol))); + addDiagnostic(typeParameter, 1 /* Parameter */, ts.createDiagnosticForNode(typeParameter.name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(typeParameter.symbol))); } } } @@ -50974,7 +50967,7 @@ var ts; var name = local.valueDeclaration && ts.getNameOfDeclaration(local.valueDeclaration); if (parameter && name) { if (!ts.isParameterPropertyDeclaration(parameter) && !ts.parameterIsThisKeyword(parameter) && !isIdentifierThatStartsWithUnderscore(name)) { - addDiagnostic(1 /* Parameter */, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local))); + addDiagnostic(parameter, 1 /* Parameter */, ts.createDiagnosticForNode(name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.symbolName(local))); } } else { @@ -50991,7 +50984,7 @@ var ts; (importClause.namedBindings.kind === 249 /* NamespaceImport */ ? 1 : importClause.namedBindings.elements.length) : 0); if (nDeclarations === unuseds.length) { - addDiagnostic(0 /* Local */, unuseds.length === 1 + addDiagnostic(importDecl, 0 /* Local */, unuseds.length === 1 ? ts.createDiagnosticForNode(importDecl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.first(unuseds).name)) : ts.createDiagnosticForNode(importDecl, ts.Diagnostics.All_imports_in_import_declaration_are_unused)); } @@ -51010,7 +51003,7 @@ var ts; addToGroup(unusedVariables, bindingPattern.parent.parent, bindingPattern.parent, getNodeId); } else { - addDiagnostic(kind, bindingElements.length === 1 + addDiagnostic(bindingPattern, kind, bindingElements.length === 1 ? ts.createDiagnosticForNode(bindingPattern, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(ts.first(bindingElements).name, ts.isIdentifier))) : ts.createDiagnosticForNode(bindingPattern, ts.Diagnostics.All_destructured_elements_are_unused)); } @@ -51018,21 +51011,21 @@ var ts; else { for (var _i = 0, bindingElements_1 = bindingElements; _i < bindingElements_1.length; _i++) { var e = bindingElements_1[_i]; - addDiagnostic(kind, ts.createDiagnosticForNode(e, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(e.name, ts.isIdentifier)))); + addDiagnostic(e, kind, ts.createDiagnosticForNode(e, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(e.name, ts.isIdentifier)))); } } }); unusedVariables.forEach(function (_a) { var declarationList = _a[0], declarations = _a[1]; if (declarationList.declarations.length === declarations.length) { - addDiagnostic(0 /* Local */, declarations.length === 1 + addDiagnostic(declarationList, 0 /* Local */, declarations.length === 1 ? ts.createDiagnosticForNode(ts.first(declarations).name, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, bindingNameText(ts.first(declarations).name)) : ts.createDiagnosticForNode(declarationList.parent.kind === 217 /* VariableStatement */ ? declarationList.parent : declarationList, ts.Diagnostics.All_variables_are_unused)); } else { for (var _i = 0, declarations_5 = declarations; _i < declarations_5.length; _i++) { var decl = declarations_5[_i]; - addDiagnostic(0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(decl.name, ts.isIdentifier)))); + addDiagnostic(decl, 0 /* Local */, ts.createDiagnosticForNode(decl, ts.Diagnostics._0_is_declared_but_its_value_is_never_read, ts.idText(ts.cast(decl.name, ts.isIdentifier)))); } } }); @@ -53610,8 +53603,8 @@ var ts; registerForUnusedIdentifiersCheck(node); } if (!node.isDeclarationFile && (compilerOptions.noUnusedLocals || compilerOptions.noUnusedParameters)) { - checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (kind, diag) { - if (unusedIsError(kind)) { + checkUnusedIdentifiers(getPotentiallyUnusedIdentifiers(node), function (containingNode, kind, diag) { + if (!ts.containsParseError(containingNode) && unusedIsError(kind)) { diagnostics.add(diag); } }); @@ -60029,6 +60022,9 @@ var ts; case 203 /* ConditionalExpression */: node = node.condition; continue; + case 191 /* TaggedTemplateExpression */: + node = node.tag; + continue; case 189 /* CallExpression */: if (stopAtCallExpressions) { return node; @@ -82066,7 +82062,7 @@ var ts; } function createFileWatcherWithTriggerLogging(host, file, cb, flags, passThrough, detailInfo1, detailInfo2, addWatch, log, watchCaption, getDetailWatchInfo) { return addWatch(host, file, function (fileName, cbOptional) { - var triggerredInfo = watchCaption + ":: Triggered with " + fileName + (cbOptional !== undefined ? cbOptional : "") + ":: " + getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo); + var triggerredInfo = watchCaption + ":: Triggered with " + fileName + " " + (cbOptional !== undefined ? cbOptional : "") + ":: " + getWatchInfo(file, flags, detailInfo1, detailInfo2, getDetailWatchInfo); log(triggerredInfo); var start = ts.timestamp(); cb(fileName, cbOptional, passThrough); @@ -82558,6 +82554,7 @@ var ts; var programDiagnostics = ts.createDiagnosticCollection(); var currentDirectory = host.getCurrentDirectory(); var supportedExtensions = ts.getSupportedExtensions(options); + var supportedExtensionsWithJsonIfResolveJsonModule = options.resolveJsonModule ? supportedExtensions.concat([".json" /* Json */]) : undefined; // Map storing if there is emit blocking diagnostics for given input var hasEmitBlockingDiagnostics = ts.createMap(); var _compilerOptionsObjectLiteralSyntax; @@ -83706,7 +83703,7 @@ var ts; } function getSourceFileFromReferenceWorker(fileName, getSourceFile, fail, refFile) { if (ts.hasExtension(fileName)) { - if (!options.allowNonTsExtensions && !ts.forEach(supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) { + if (!options.allowNonTsExtensions && !ts.forEach(supportedExtensionsWithJsonIfResolveJsonModule || supportedExtensions, function (extension) { return ts.fileExtensionIs(host.getCanonicalFileName(fileName), extension); })) { if (fail) fail(ts.Diagnostics.File_0_has_unsupported_extension_The_only_supported_extensions_are_1, fileName, "'" + supportedExtensions.join("', '") + "'"); return undefined; @@ -86476,16 +86473,15 @@ var ts; }; // From tsc we want to get already parsed result and hence check for rootFileNames var newLine = updateNewLine(); + if (configFileName && host.configFileParsingResult) { + setConfigFileParsingResult(host.configFileParsingResult); + newLine = updateNewLine(); + } reportWatchDiagnostic(ts.Diagnostics.Starting_compilation_in_watch_mode); - if (configFileName) { + if (configFileName && !host.configFileParsingResult) { newLine = ts.getNewLineCharacter(optionsToExtendForConfigFile, function () { return host.getNewLine(); }); - if (host.configFileParsingResult) { - setConfigFileParsingResult(host.configFileParsingResult); - } - else { - ts.Debug.assert(!rootFileNames); - parseConfigFile(); - } + ts.Debug.assert(!rootFileNames); + parseConfigFile(); newLine = updateNewLine(); } var trace = host.trace && (function (s) { host.trace(s + newLine); }); @@ -87200,6 +87196,7 @@ var ts; return builder.cleanAllProjects(); } if (watch) { + builder.buildAllProjects(); builder.startWatching(); return undefined; }