diff --git a/lib/tsc.js b/lib/tsc.js index 361e447f84231..9294e9ec7b2a2 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -67,7 +67,7 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook var ts; (function (ts) { ts.versionMajorMinor = "3.9"; - ts.version = "3.9.2"; + ts.version = "3.9.3"; function tryGetNativeMap() { return typeof Map !== "undefined" && "entries" in Map.prototype ? Map : undefined; } @@ -36320,7 +36320,7 @@ var ts; return type.resolvedProperties; } function getPropertiesOfType(type) { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); return type.flags & 3145728 ? getPropertiesOfUnionOrIntersectionType(type) : getPropertiesOfObjectType(type); @@ -36600,6 +36600,9 @@ var ts; t.flags & 2 && !strictNullChecks ? emptyObjectType : t; } + function getReducedApparentType(type) { + return getReducedType(getApparentType(getReducedType(type))); + } function createUnionOrIntersectionProperty(containingType, name) { var singleProp; var propSet; @@ -36782,7 +36785,7 @@ var ts; return errorInfo; } function getPropertyOfType(type, name) { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); if (type.flags & 524288) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members.get(name); @@ -36814,7 +36817,7 @@ var ts; return ts.emptyArray; } function getSignaturesOfType(type, kind) { - return getSignaturesOfStructuredType(getApparentType(getReducedType(type)), kind); + return getSignaturesOfStructuredType(getReducedApparentType(type), kind); } function getIndexInfoOfStructuredType(type, kind) { if (type.flags & 3670016) { @@ -36827,10 +36830,10 @@ var ts; return info && info.type; } function getIndexInfoOfType(type, kind) { - return getIndexInfoOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexInfoOfStructuredType(getReducedApparentType(type), kind); } function getIndexTypeOfType(type, kind) { - return getIndexTypeOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexTypeOfStructuredType(getReducedApparentType(type), kind); } function getImplicitIndexTypeOfType(type, kind) { if (isObjectTypeWithInferableIndex(type)) { @@ -38781,7 +38784,7 @@ var ts; } return type; } - var apparentObjectType = getApparentType(getReducedType(objectType)); + var apparentObjectType = getReducedApparentType(objectType); if (indexType.flags & 1048576 && !(indexType.flags & 16)) { var propTypes = []; var wasMissingProp = false; @@ -47127,7 +47130,7 @@ var ts; var right = _a[_i]; var left = props.get(right.escapedName); var rightType = getTypeOfSymbol(right); - if (left && !maybeTypeOfKind(rightType, 98304) && !(maybeTypeOfKind(rightType, 1) && right.flags & 16777216)) { + if (left && !maybeTypeOfKind(rightType, 98304) && !(maybeTypeOfKind(rightType, 3) && right.flags & 16777216)) { var diagnostic = error(left.valueDeclaration, ts.Diagnostics._0_is_specified_more_than_once_so_this_usage_will_be_overwritten, ts.unescapeLeadingUnderscores(left.escapedName)); ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(spread, ts.Diagnostics.This_spread_always_overwrites_this_property)); } @@ -65183,9 +65186,12 @@ var ts; return template.templateFlags ? ts.createIdentifier("undefined") : ts.createLiteral(template.text); } function getRawLiteral(node, currentSourceFile) { - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - var isLast = node.kind === 14 || node.kind === 17; - text = text.substring(1, text.length - (isLast ? 1 : 2)); + var text = node.rawText; + if (text === undefined) { + text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + var isLast = node.kind === 14 || node.kind === 17; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + } text = text.replace(/\r\n?/g, "\n"); return ts.setTextRange(ts.createLiteral(text), node); } @@ -74060,7 +74066,7 @@ var ts; scoped: false, dependencies: [ts.createBindingHelper], priority: 2, - text: "\n var __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);\n }" + text: "\n var __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);\n };" }; function createExportStarHelper(context, module) { context.requestEmitHelper(exportStarHelper); diff --git a/lib/tsserver.js b/lib/tsserver.js index 2b6f035cc95ba..b45cc52a00582 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -94,7 +94,7 @@ var ts; // If changing the text in this section, be sure to test `configurePrerelease` too. ts.versionMajorMinor = "3.9"; /** The version of the TypeScript compiler release */ - ts.version = "3.9.2"; + ts.version = "3.9.3"; /** * Returns the native Map implementation if it is available and compatible (i.e. supports iteration). */ @@ -43890,7 +43890,7 @@ var ts; return type.resolvedProperties; } function getPropertiesOfType(type) { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); return type.flags & 3145728 /* UnionOrIntersection */ ? getPropertiesOfUnionOrIntersectionType(type) : getPropertiesOfObjectType(type); @@ -44223,6 +44223,13 @@ var ts; t.flags & 2 /* Unknown */ && !strictNullChecks ? emptyObjectType : t; } + function getReducedApparentType(type) { + // Since getApparentType may return a non-reduced union or intersection type, we need to perform + // type reduction both before and after obtaining the apparent type. For example, given a type parameter + // 'T extends A | B', the type 'T & X' becomes 'A & X | B & X' after obtaining the apparent type, and + // that type may need futher reduction to remove empty intersections. + return getReducedType(getApparentType(getReducedType(type))); + } function createUnionOrIntersectionProperty(containingType, name) { var singleProp; var propSet; @@ -44433,7 +44440,7 @@ var ts; * @param name a name of property to look up in a given type */ function getPropertyOfType(type, name) { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); if (type.flags & 524288 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members.get(name); @@ -44469,7 +44476,7 @@ var ts; * maps primitive types and type parameters are to their apparent types. */ function getSignaturesOfType(type, kind) { - return getSignaturesOfStructuredType(getApparentType(getReducedType(type)), kind); + return getSignaturesOfStructuredType(getReducedApparentType(type), kind); } function getIndexInfoOfStructuredType(type, kind) { if (type.flags & 3670016 /* StructuredType */) { @@ -44484,12 +44491,12 @@ var ts; // Return the indexing info of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexInfoOfType(type, kind) { - return getIndexInfoOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexInfoOfStructuredType(getReducedApparentType(type), kind); } // Return the index type of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexTypeOfType(type, kind) { - return getIndexTypeOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexTypeOfStructuredType(getReducedApparentType(type), kind); } function getImplicitIndexTypeOfType(type, kind) { if (isObjectTypeWithInferableIndex(type)) { @@ -46660,7 +46667,7 @@ var ts; // In the following we resolve T[K] to the type of the property in T selected by K. // We treat boolean as different from other unions to improve errors; // skipping straight to getPropertyTypeForIndexType gives errors with 'boolean' instead of 'true'. - var apparentObjectType = getApparentType(getReducedType(objectType)); + var apparentObjectType = getReducedApparentType(objectType); if (indexType.flags & 1048576 /* Union */ && !(indexType.flags & 16 /* Boolean */)) { var propTypes = []; var wasMissingProp = false; @@ -56349,7 +56356,7 @@ var ts; var right = _a[_i]; var left = props.get(right.escapedName); var rightType = getTypeOfSymbol(right); - if (left && !maybeTypeOfKind(rightType, 98304 /* Nullable */) && !(maybeTypeOfKind(rightType, 1 /* Any */) && right.flags & 16777216 /* Optional */)) { + if (left && !maybeTypeOfKind(rightType, 98304 /* Nullable */) && !(maybeTypeOfKind(rightType, 3 /* AnyOrUnknown */) && right.flags & 16777216 /* Optional */)) { var diagnostic = error(left.valueDeclaration, ts.Diagnostics._0_is_specified_more_than_once_so_this_usage_will_be_overwritten, ts.unescapeLeadingUnderscores(left.escapedName)); ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(spread, ts.Diagnostics.This_spread_always_overwrites_this_property)); } @@ -77204,13 +77211,16 @@ var ts; // Find original source text, since we need to emit the raw strings of the tagged template. // The raw strings contain the (escaped) strings of what the user wrote. // Examples: `\n` is converted to "\\n", a template string with a newline to "\n". - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), - // thus we need to remove those characters. - // First template piece starts with "`", others with "}" - // Last template piece ends with "`", others with "${" - var isLast = node.kind === 14 /* NoSubstitutionTemplateLiteral */ || node.kind === 17 /* TemplateTail */; - text = text.substring(1, text.length - (isLast ? 1 : 2)); + var text = node.rawText; + if (text === undefined) { + text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), + // thus we need to remove those characters. + // First template piece starts with "`", others with "}" + // Last template piece ends with "`", others with "${" + var isLast = node.kind === 14 /* NoSubstitutionTemplateLiteral */ || node.kind === 17 /* TemplateTail */; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + } // Newline normalization: // ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's // and LineTerminatorSequences are normalized to for both TV and TRV. @@ -90353,7 +90363,7 @@ var ts; scoped: false, dependencies: [ts.createBindingHelper], priority: 2, - text: "\n var __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);\n }" + text: "\n var __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);\n };" }; function createExportStarHelper(context, module) { context.requestEmitHelper(exportStarHelper); @@ -109672,8 +109682,8 @@ var ts; * The default is CRLF. */ function getNewLineOrDefaultFromHost(host, formatSettings) { - return (formatSettings && formatSettings.newLineCharacter) || - (host.getNewLine && host.getNewLine()) || + var _a; + return (formatSettings === null || formatSettings === void 0 ? void 0 : formatSettings.newLineCharacter) || ((_a = host.getNewLine) === null || _a === void 0 ? void 0 : _a.call(host)) || carriageReturnLineFeed; } ts.getNewLineOrDefaultFromHost = getNewLineOrDefaultFromHost; @@ -119767,7 +119777,7 @@ var ts; } // Delete any subsequent imports. for (var i = 1; i < oldImportDecls.length; i++) { - changeTracker.delete(sourceFile, oldImportDecls[i]); + changeTracker.deleteNode(sourceFile, oldImportDecls[i]); } } } @@ -124237,8 +124247,8 @@ var ts; (function (ts) { var formatting; (function (formatting) { - function getFormatContext(options) { - return { options: options, getRules: getRulesMap() }; + function getFormatContext(options, host) { + return { options: options, getRules: getRulesMap(), host: host }; } formatting.getFormatContext = getFormatContext; var rulesMapCache; @@ -124651,7 +124661,7 @@ var ts; return formatting.getFormattingScanner(sourceFile.text, sourceFile.languageVariant, getScanStartPosition(enclosingNode, originalRange, sourceFile), originalRange.end, function (scanner) { return formatSpanWorker(originalRange, enclosingNode, formatting.SmartIndenter.getIndentationForNode(enclosingNode, originalRange, sourceFile, formatContext.options), getOwnOrInheritedDelta(enclosingNode, formatContext.options, sourceFile), scanner, formatContext, requestKind, prepareRangeContainsErrorFunction(sourceFile.parseDiagnostics, originalRange), sourceFile); }); } function formatSpanWorker(originalRange, enclosingNode, initialIndentation, delta, formattingScanner, _a, requestKind, rangeContainsError, sourceFile) { - var options = _a.options, getRules = _a.getRules; + var options = _a.options, getRules = _a.getRules, host = _a.host; // formatting context is used by rules provider var formattingContext = new formatting.FormattingContext(sourceFile, requestKind, options); var previousRange; @@ -125321,7 +125331,7 @@ var ts; // edit should not be applied if we have one line feed between elements var lineDelta = currentStartLine - previousStartLine; if (lineDelta !== 1) { - recordReplace(previousRange.end, currentRange.pos - previousRange.end, options.newLineCharacter); + recordReplace(previousRange.end, currentRange.pos - previousRange.end, ts.getNewLineOrDefaultFromHost(host, options)); return onLaterLine ? 0 /* None */ : 1 /* LineAdded */; } break; @@ -126204,6 +126214,10 @@ var ts; ChangeTracker.prototype.delete = function (sourceFile, node) { this.deletedNodes.push({ sourceFile: sourceFile, node: node }); }; + ChangeTracker.prototype.deleteNode = function (sourceFile, node, options) { + if (options === void 0) { options = { leadingTriviaOption: LeadingTriviaOption.IncludeAll }; } + this.deleteRange(sourceFile, getAdjustedRange(sourceFile, node, node, options)); + }; ChangeTracker.prototype.deleteModifier = function (sourceFile, modifier) { this.deleteRange(sourceFile, { pos: modifier.getStart(sourceFile), end: ts.skipTrivia(sourceFile.text, modifier.end, /*stopAfterLineBreak*/ true) }); }; @@ -138860,7 +138874,7 @@ var ts; function getCompletionEntryDetails(fileName, position, name, formattingOptions, source, preferences) { if (preferences === void 0) { preferences = ts.emptyOptions; } synchronizeHostData(); - return ts.Completions.getCompletionEntryDetails(program, log, getValidSourceFile(fileName), position, { name: name, source: source }, host, (formattingOptions && ts.formatting.getFormatContext(formattingOptions)), // TODO: GH#18217 + return ts.Completions.getCompletionEntryDetails(program, log, getValidSourceFile(fileName), position, { name: name, source: source }, host, (formattingOptions && ts.formatting.getFormatContext(formattingOptions, host)), // TODO: GH#18217 preferences, cancellationToken); } function getCompletionEntrySymbol(fileName, position, name, source, preferences) { @@ -139132,14 +139146,14 @@ var ts; } function getFormattingEditsForRange(fileName, start, end, options) { var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); - return ts.formatting.formatSelection(start, end, sourceFile, ts.formatting.getFormatContext(toEditorSettings(options))); + return ts.formatting.formatSelection(start, end, sourceFile, ts.formatting.getFormatContext(toEditorSettings(options), host)); } function getFormattingEditsForDocument(fileName, options) { - return ts.formatting.formatDocument(syntaxTreeCache.getCurrentSourceFile(fileName), ts.formatting.getFormatContext(toEditorSettings(options))); + return ts.formatting.formatDocument(syntaxTreeCache.getCurrentSourceFile(fileName), ts.formatting.getFormatContext(toEditorSettings(options), host)); } function getFormattingEditsAfterKeystroke(fileName, position, key, options) { var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); - var formatContext = ts.formatting.getFormatContext(toEditorSettings(options)); + var formatContext = ts.formatting.getFormatContext(toEditorSettings(options), host); if (!ts.isInComment(sourceFile, position)) { switch (key) { case "{": @@ -139159,7 +139173,7 @@ var ts; synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); var span = ts.createTextSpanFromBounds(start, end); - var formatContext = ts.formatting.getFormatContext(formatOptions); + var formatContext = ts.formatting.getFormatContext(formatOptions, host); return ts.flatMap(ts.deduplicate(errorCodes, ts.equateValues, ts.compareValues), function (errorCode) { cancellationToken.throwIfCancellationRequested(); return ts.codefix.getFixes({ errorCode: errorCode, sourceFile: sourceFile, span: span, program: program, host: host, cancellationToken: cancellationToken, formatContext: formatContext, preferences: preferences }); @@ -139170,7 +139184,7 @@ var ts; synchronizeHostData(); ts.Debug.assert(scope.type === "file"); var sourceFile = getValidSourceFile(scope.fileName); - var formatContext = ts.formatting.getFormatContext(formatOptions); + var formatContext = ts.formatting.getFormatContext(formatOptions, host); return ts.codefix.getAllFixes({ fixId: fixId, sourceFile: sourceFile, program: program, host: host, cancellationToken: cancellationToken, formatContext: formatContext, preferences: preferences }); } function organizeImports(scope, formatOptions, preferences) { @@ -139178,12 +139192,12 @@ var ts; synchronizeHostData(); ts.Debug.assert(scope.type === "file"); var sourceFile = getValidSourceFile(scope.fileName); - var formatContext = ts.formatting.getFormatContext(formatOptions); + var formatContext = ts.formatting.getFormatContext(formatOptions, host); return ts.OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences); } function getEditsForFileRename(oldFilePath, newFilePath, formatOptions, preferences) { if (preferences === void 0) { preferences = ts.emptyOptions; } - return ts.getEditsForFileRename(getProgram(), oldFilePath, newFilePath, host, ts.formatting.getFormatContext(formatOptions), preferences, sourceMapper); + return ts.getEditsForFileRename(getProgram(), oldFilePath, newFilePath, host, ts.formatting.getFormatContext(formatOptions, host), preferences, sourceMapper); } function applyCodeActionCommand(fileName, actionOrFormatSettingsOrUndefined) { var action = typeof fileName === "string" ? actionOrFormatSettingsOrUndefined : fileName; @@ -139385,7 +139399,7 @@ var ts; endPosition: endPosition, program: getProgram(), host: host, - formatContext: ts.formatting.getFormatContext(formatOptions), + formatContext: ts.formatting.getFormatContext(formatOptions, host), cancellationToken: cancellationToken, preferences: preferences, }; @@ -145503,7 +145517,9 @@ var ts; this.findConfiguredProjectByProjectName(configFileName); return (project === null || project === void 0 ? void 0 : project.isSolution()) ? project.getDefaultChildProjectFromSolution(info) : - project; + project && projectContainsInfoDirectly(project, info) ? + project : + undefined; }; /** * This function tries to search for a tsconfig.json for the given file. diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 60e8447a1cd8d..b6d633862444d 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -244,7 +244,7 @@ var ts; // If changing the text in this section, be sure to test `configurePrerelease` too. ts.versionMajorMinor = "3.9"; /** The version of the TypeScript compiler release */ - ts.version = "3.9.2"; + ts.version = "3.9.3"; /** * Returns the native Map implementation if it is available and compatible (i.e. supports iteration). */ @@ -44040,7 +44040,7 @@ var ts; return type.resolvedProperties; } function getPropertiesOfType(type) { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); return type.flags & 3145728 /* UnionOrIntersection */ ? getPropertiesOfUnionOrIntersectionType(type) : getPropertiesOfObjectType(type); @@ -44373,6 +44373,13 @@ var ts; t.flags & 2 /* Unknown */ && !strictNullChecks ? emptyObjectType : t; } + function getReducedApparentType(type) { + // Since getApparentType may return a non-reduced union or intersection type, we need to perform + // type reduction both before and after obtaining the apparent type. For example, given a type parameter + // 'T extends A | B', the type 'T & X' becomes 'A & X | B & X' after obtaining the apparent type, and + // that type may need futher reduction to remove empty intersections. + return getReducedType(getApparentType(getReducedType(type))); + } function createUnionOrIntersectionProperty(containingType, name) { var singleProp; var propSet; @@ -44583,7 +44590,7 @@ var ts; * @param name a name of property to look up in a given type */ function getPropertyOfType(type, name) { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); if (type.flags & 524288 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members.get(name); @@ -44619,7 +44626,7 @@ var ts; * maps primitive types and type parameters are to their apparent types. */ function getSignaturesOfType(type, kind) { - return getSignaturesOfStructuredType(getApparentType(getReducedType(type)), kind); + return getSignaturesOfStructuredType(getReducedApparentType(type), kind); } function getIndexInfoOfStructuredType(type, kind) { if (type.flags & 3670016 /* StructuredType */) { @@ -44634,12 +44641,12 @@ var ts; // Return the indexing info of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexInfoOfType(type, kind) { - return getIndexInfoOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexInfoOfStructuredType(getReducedApparentType(type), kind); } // Return the index type of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexTypeOfType(type, kind) { - return getIndexTypeOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexTypeOfStructuredType(getReducedApparentType(type), kind); } function getImplicitIndexTypeOfType(type, kind) { if (isObjectTypeWithInferableIndex(type)) { @@ -46810,7 +46817,7 @@ var ts; // In the following we resolve T[K] to the type of the property in T selected by K. // We treat boolean as different from other unions to improve errors; // skipping straight to getPropertyTypeForIndexType gives errors with 'boolean' instead of 'true'. - var apparentObjectType = getApparentType(getReducedType(objectType)); + var apparentObjectType = getReducedApparentType(objectType); if (indexType.flags & 1048576 /* Union */ && !(indexType.flags & 16 /* Boolean */)) { var propTypes = []; var wasMissingProp = false; @@ -56499,7 +56506,7 @@ var ts; var right = _a[_i]; var left = props.get(right.escapedName); var rightType = getTypeOfSymbol(right); - if (left && !maybeTypeOfKind(rightType, 98304 /* Nullable */) && !(maybeTypeOfKind(rightType, 1 /* Any */) && right.flags & 16777216 /* Optional */)) { + if (left && !maybeTypeOfKind(rightType, 98304 /* Nullable */) && !(maybeTypeOfKind(rightType, 3 /* AnyOrUnknown */) && right.flags & 16777216 /* Optional */)) { var diagnostic = error(left.valueDeclaration, ts.Diagnostics._0_is_specified_more_than_once_so_this_usage_will_be_overwritten, ts.unescapeLeadingUnderscores(left.escapedName)); ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(spread, ts.Diagnostics.This_spread_always_overwrites_this_property)); } @@ -77354,13 +77361,16 @@ var ts; // Find original source text, since we need to emit the raw strings of the tagged template. // The raw strings contain the (escaped) strings of what the user wrote. // Examples: `\n` is converted to "\\n", a template string with a newline to "\n". - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), - // thus we need to remove those characters. - // First template piece starts with "`", others with "}" - // Last template piece ends with "`", others with "${" - var isLast = node.kind === 14 /* NoSubstitutionTemplateLiteral */ || node.kind === 17 /* TemplateTail */; - text = text.substring(1, text.length - (isLast ? 1 : 2)); + var text = node.rawText; + if (text === undefined) { + text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), + // thus we need to remove those characters. + // First template piece starts with "`", others with "}" + // Last template piece ends with "`", others with "${" + var isLast = node.kind === 14 /* NoSubstitutionTemplateLiteral */ || node.kind === 17 /* TemplateTail */; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + } // Newline normalization: // ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's // and LineTerminatorSequences are normalized to for both TV and TRV. @@ -90503,7 +90513,7 @@ var ts; scoped: false, dependencies: [ts.createBindingHelper], priority: 2, - text: "\n var __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);\n }" + text: "\n var __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);\n };" }; function createExportStarHelper(context, module) { context.requestEmitHelper(exportStarHelper); @@ -110195,8 +110205,8 @@ var ts; * The default is CRLF. */ function getNewLineOrDefaultFromHost(host, formatSettings) { - return (formatSettings && formatSettings.newLineCharacter) || - (host.getNewLine && host.getNewLine()) || + var _a; + return (formatSettings === null || formatSettings === void 0 ? void 0 : formatSettings.newLineCharacter) || ((_a = host.getNewLine) === null || _a === void 0 ? void 0 : _a.call(host)) || carriageReturnLineFeed; } ts.getNewLineOrDefaultFromHost = getNewLineOrDefaultFromHost; @@ -120290,7 +120300,7 @@ var ts; } // Delete any subsequent imports. for (var i = 1; i < oldImportDecls.length; i++) { - changeTracker.delete(sourceFile, oldImportDecls[i]); + changeTracker.deleteNode(sourceFile, oldImportDecls[i]); } } } @@ -124760,8 +124770,8 @@ var ts; (function (ts) { var formatting; (function (formatting) { - function getFormatContext(options) { - return { options: options, getRules: getRulesMap() }; + function getFormatContext(options, host) { + return { options: options, getRules: getRulesMap(), host: host }; } formatting.getFormatContext = getFormatContext; var rulesMapCache; @@ -125174,7 +125184,7 @@ var ts; return formatting.getFormattingScanner(sourceFile.text, sourceFile.languageVariant, getScanStartPosition(enclosingNode, originalRange, sourceFile), originalRange.end, function (scanner) { return formatSpanWorker(originalRange, enclosingNode, formatting.SmartIndenter.getIndentationForNode(enclosingNode, originalRange, sourceFile, formatContext.options), getOwnOrInheritedDelta(enclosingNode, formatContext.options, sourceFile), scanner, formatContext, requestKind, prepareRangeContainsErrorFunction(sourceFile.parseDiagnostics, originalRange), sourceFile); }); } function formatSpanWorker(originalRange, enclosingNode, initialIndentation, delta, formattingScanner, _a, requestKind, rangeContainsError, sourceFile) { - var options = _a.options, getRules = _a.getRules; + var options = _a.options, getRules = _a.getRules, host = _a.host; // formatting context is used by rules provider var formattingContext = new formatting.FormattingContext(sourceFile, requestKind, options); var previousRange; @@ -125844,7 +125854,7 @@ var ts; // edit should not be applied if we have one line feed between elements var lineDelta = currentStartLine - previousStartLine; if (lineDelta !== 1) { - recordReplace(previousRange.end, currentRange.pos - previousRange.end, options.newLineCharacter); + recordReplace(previousRange.end, currentRange.pos - previousRange.end, ts.getNewLineOrDefaultFromHost(host, options)); return onLaterLine ? 0 /* None */ : 1 /* LineAdded */; } break; @@ -126727,6 +126737,10 @@ var ts; ChangeTracker.prototype.delete = function (sourceFile, node) { this.deletedNodes.push({ sourceFile: sourceFile, node: node }); }; + ChangeTracker.prototype.deleteNode = function (sourceFile, node, options) { + if (options === void 0) { options = { leadingTriviaOption: LeadingTriviaOption.IncludeAll }; } + this.deleteRange(sourceFile, getAdjustedRange(sourceFile, node, node, options)); + }; ChangeTracker.prototype.deleteModifier = function (sourceFile, modifier) { this.deleteRange(sourceFile, { pos: modifier.getStart(sourceFile), end: ts.skipTrivia(sourceFile.text, modifier.end, /*stopAfterLineBreak*/ true) }); }; @@ -139383,7 +139397,7 @@ var ts; function getCompletionEntryDetails(fileName, position, name, formattingOptions, source, preferences) { if (preferences === void 0) { preferences = ts.emptyOptions; } synchronizeHostData(); - return ts.Completions.getCompletionEntryDetails(program, log, getValidSourceFile(fileName), position, { name: name, source: source }, host, (formattingOptions && ts.formatting.getFormatContext(formattingOptions)), // TODO: GH#18217 + return ts.Completions.getCompletionEntryDetails(program, log, getValidSourceFile(fileName), position, { name: name, source: source }, host, (formattingOptions && ts.formatting.getFormatContext(formattingOptions, host)), // TODO: GH#18217 preferences, cancellationToken); } function getCompletionEntrySymbol(fileName, position, name, source, preferences) { @@ -139655,14 +139669,14 @@ var ts; } function getFormattingEditsForRange(fileName, start, end, options) { var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); - return ts.formatting.formatSelection(start, end, sourceFile, ts.formatting.getFormatContext(toEditorSettings(options))); + return ts.formatting.formatSelection(start, end, sourceFile, ts.formatting.getFormatContext(toEditorSettings(options), host)); } function getFormattingEditsForDocument(fileName, options) { - return ts.formatting.formatDocument(syntaxTreeCache.getCurrentSourceFile(fileName), ts.formatting.getFormatContext(toEditorSettings(options))); + return ts.formatting.formatDocument(syntaxTreeCache.getCurrentSourceFile(fileName), ts.formatting.getFormatContext(toEditorSettings(options), host)); } function getFormattingEditsAfterKeystroke(fileName, position, key, options) { var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); - var formatContext = ts.formatting.getFormatContext(toEditorSettings(options)); + var formatContext = ts.formatting.getFormatContext(toEditorSettings(options), host); if (!ts.isInComment(sourceFile, position)) { switch (key) { case "{": @@ -139682,7 +139696,7 @@ var ts; synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); var span = ts.createTextSpanFromBounds(start, end); - var formatContext = ts.formatting.getFormatContext(formatOptions); + var formatContext = ts.formatting.getFormatContext(formatOptions, host); return ts.flatMap(ts.deduplicate(errorCodes, ts.equateValues, ts.compareValues), function (errorCode) { cancellationToken.throwIfCancellationRequested(); return ts.codefix.getFixes({ errorCode: errorCode, sourceFile: sourceFile, span: span, program: program, host: host, cancellationToken: cancellationToken, formatContext: formatContext, preferences: preferences }); @@ -139693,7 +139707,7 @@ var ts; synchronizeHostData(); ts.Debug.assert(scope.type === "file"); var sourceFile = getValidSourceFile(scope.fileName); - var formatContext = ts.formatting.getFormatContext(formatOptions); + var formatContext = ts.formatting.getFormatContext(formatOptions, host); return ts.codefix.getAllFixes({ fixId: fixId, sourceFile: sourceFile, program: program, host: host, cancellationToken: cancellationToken, formatContext: formatContext, preferences: preferences }); } function organizeImports(scope, formatOptions, preferences) { @@ -139701,12 +139715,12 @@ var ts; synchronizeHostData(); ts.Debug.assert(scope.type === "file"); var sourceFile = getValidSourceFile(scope.fileName); - var formatContext = ts.formatting.getFormatContext(formatOptions); + var formatContext = ts.formatting.getFormatContext(formatOptions, host); return ts.OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences); } function getEditsForFileRename(oldFilePath, newFilePath, formatOptions, preferences) { if (preferences === void 0) { preferences = ts.emptyOptions; } - return ts.getEditsForFileRename(getProgram(), oldFilePath, newFilePath, host, ts.formatting.getFormatContext(formatOptions), preferences, sourceMapper); + return ts.getEditsForFileRename(getProgram(), oldFilePath, newFilePath, host, ts.formatting.getFormatContext(formatOptions, host), preferences, sourceMapper); } function applyCodeActionCommand(fileName, actionOrFormatSettingsOrUndefined) { var action = typeof fileName === "string" ? actionOrFormatSettingsOrUndefined : fileName; @@ -139908,7 +139922,7 @@ var ts; endPosition: endPosition, program: getProgram(), host: host, - formatContext: ts.formatting.getFormatContext(formatOptions), + formatContext: ts.formatting.getFormatContext(formatOptions, host), cancellationToken: cancellationToken, preferences: preferences, }; @@ -145653,7 +145667,9 @@ var ts; this.findConfiguredProjectByProjectName(configFileName); return (project === null || project === void 0 ? void 0 : project.isSolution()) ? project.getDefaultChildProjectFromSolution(info) : - project; + project && projectContainsInfoDirectly(project, info) ? + project : + undefined; }; /** * This function tries to search for a tsconfig.json for the given file. diff --git a/lib/typescript.js b/lib/typescript.js index 90202c1c5b1e7..423d4c31612db 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -244,7 +244,7 @@ var ts; // If changing the text in this section, be sure to test `configurePrerelease` too. ts.versionMajorMinor = "3.9"; /** The version of the TypeScript compiler release */ - ts.version = "3.9.2"; + ts.version = "3.9.3"; /** * Returns the native Map implementation if it is available and compatible (i.e. supports iteration). */ @@ -44040,7 +44040,7 @@ var ts; return type.resolvedProperties; } function getPropertiesOfType(type) { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); return type.flags & 3145728 /* UnionOrIntersection */ ? getPropertiesOfUnionOrIntersectionType(type) : getPropertiesOfObjectType(type); @@ -44373,6 +44373,13 @@ var ts; t.flags & 2 /* Unknown */ && !strictNullChecks ? emptyObjectType : t; } + function getReducedApparentType(type) { + // Since getApparentType may return a non-reduced union or intersection type, we need to perform + // type reduction both before and after obtaining the apparent type. For example, given a type parameter + // 'T extends A | B', the type 'T & X' becomes 'A & X | B & X' after obtaining the apparent type, and + // that type may need futher reduction to remove empty intersections. + return getReducedType(getApparentType(getReducedType(type))); + } function createUnionOrIntersectionProperty(containingType, name) { var singleProp; var propSet; @@ -44583,7 +44590,7 @@ var ts; * @param name a name of property to look up in a given type */ function getPropertyOfType(type, name) { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); if (type.flags & 524288 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members.get(name); @@ -44619,7 +44626,7 @@ var ts; * maps primitive types and type parameters are to their apparent types. */ function getSignaturesOfType(type, kind) { - return getSignaturesOfStructuredType(getApparentType(getReducedType(type)), kind); + return getSignaturesOfStructuredType(getReducedApparentType(type), kind); } function getIndexInfoOfStructuredType(type, kind) { if (type.flags & 3670016 /* StructuredType */) { @@ -44634,12 +44641,12 @@ var ts; // Return the indexing info of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexInfoOfType(type, kind) { - return getIndexInfoOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexInfoOfStructuredType(getReducedApparentType(type), kind); } // Return the index type of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexTypeOfType(type, kind) { - return getIndexTypeOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexTypeOfStructuredType(getReducedApparentType(type), kind); } function getImplicitIndexTypeOfType(type, kind) { if (isObjectTypeWithInferableIndex(type)) { @@ -46810,7 +46817,7 @@ var ts; // In the following we resolve T[K] to the type of the property in T selected by K. // We treat boolean as different from other unions to improve errors; // skipping straight to getPropertyTypeForIndexType gives errors with 'boolean' instead of 'true'. - var apparentObjectType = getApparentType(getReducedType(objectType)); + var apparentObjectType = getReducedApparentType(objectType); if (indexType.flags & 1048576 /* Union */ && !(indexType.flags & 16 /* Boolean */)) { var propTypes = []; var wasMissingProp = false; @@ -56499,7 +56506,7 @@ var ts; var right = _a[_i]; var left = props.get(right.escapedName); var rightType = getTypeOfSymbol(right); - if (left && !maybeTypeOfKind(rightType, 98304 /* Nullable */) && !(maybeTypeOfKind(rightType, 1 /* Any */) && right.flags & 16777216 /* Optional */)) { + if (left && !maybeTypeOfKind(rightType, 98304 /* Nullable */) && !(maybeTypeOfKind(rightType, 3 /* AnyOrUnknown */) && right.flags & 16777216 /* Optional */)) { var diagnostic = error(left.valueDeclaration, ts.Diagnostics._0_is_specified_more_than_once_so_this_usage_will_be_overwritten, ts.unescapeLeadingUnderscores(left.escapedName)); ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(spread, ts.Diagnostics.This_spread_always_overwrites_this_property)); } @@ -77354,13 +77361,16 @@ var ts; // Find original source text, since we need to emit the raw strings of the tagged template. // The raw strings contain the (escaped) strings of what the user wrote. // Examples: `\n` is converted to "\\n", a template string with a newline to "\n". - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), - // thus we need to remove those characters. - // First template piece starts with "`", others with "}" - // Last template piece ends with "`", others with "${" - var isLast = node.kind === 14 /* NoSubstitutionTemplateLiteral */ || node.kind === 17 /* TemplateTail */; - text = text.substring(1, text.length - (isLast ? 1 : 2)); + var text = node.rawText; + if (text === undefined) { + text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), + // thus we need to remove those characters. + // First template piece starts with "`", others with "}" + // Last template piece ends with "`", others with "${" + var isLast = node.kind === 14 /* NoSubstitutionTemplateLiteral */ || node.kind === 17 /* TemplateTail */; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + } // Newline normalization: // ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's // and LineTerminatorSequences are normalized to for both TV and TRV. @@ -90503,7 +90513,7 @@ var ts; scoped: false, dependencies: [ts.createBindingHelper], priority: 2, - text: "\n var __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);\n }" + text: "\n var __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);\n };" }; function createExportStarHelper(context, module) { context.requestEmitHelper(exportStarHelper); @@ -110195,8 +110205,8 @@ var ts; * The default is CRLF. */ function getNewLineOrDefaultFromHost(host, formatSettings) { - return (formatSettings && formatSettings.newLineCharacter) || - (host.getNewLine && host.getNewLine()) || + var _a; + return (formatSettings === null || formatSettings === void 0 ? void 0 : formatSettings.newLineCharacter) || ((_a = host.getNewLine) === null || _a === void 0 ? void 0 : _a.call(host)) || carriageReturnLineFeed; } ts.getNewLineOrDefaultFromHost = getNewLineOrDefaultFromHost; @@ -120290,7 +120300,7 @@ var ts; } // Delete any subsequent imports. for (var i = 1; i < oldImportDecls.length; i++) { - changeTracker.delete(sourceFile, oldImportDecls[i]); + changeTracker.deleteNode(sourceFile, oldImportDecls[i]); } } } @@ -124760,8 +124770,8 @@ var ts; (function (ts) { var formatting; (function (formatting) { - function getFormatContext(options) { - return { options: options, getRules: getRulesMap() }; + function getFormatContext(options, host) { + return { options: options, getRules: getRulesMap(), host: host }; } formatting.getFormatContext = getFormatContext; var rulesMapCache; @@ -125174,7 +125184,7 @@ var ts; return formatting.getFormattingScanner(sourceFile.text, sourceFile.languageVariant, getScanStartPosition(enclosingNode, originalRange, sourceFile), originalRange.end, function (scanner) { return formatSpanWorker(originalRange, enclosingNode, formatting.SmartIndenter.getIndentationForNode(enclosingNode, originalRange, sourceFile, formatContext.options), getOwnOrInheritedDelta(enclosingNode, formatContext.options, sourceFile), scanner, formatContext, requestKind, prepareRangeContainsErrorFunction(sourceFile.parseDiagnostics, originalRange), sourceFile); }); } function formatSpanWorker(originalRange, enclosingNode, initialIndentation, delta, formattingScanner, _a, requestKind, rangeContainsError, sourceFile) { - var options = _a.options, getRules = _a.getRules; + var options = _a.options, getRules = _a.getRules, host = _a.host; // formatting context is used by rules provider var formattingContext = new formatting.FormattingContext(sourceFile, requestKind, options); var previousRange; @@ -125844,7 +125854,7 @@ var ts; // edit should not be applied if we have one line feed between elements var lineDelta = currentStartLine - previousStartLine; if (lineDelta !== 1) { - recordReplace(previousRange.end, currentRange.pos - previousRange.end, options.newLineCharacter); + recordReplace(previousRange.end, currentRange.pos - previousRange.end, ts.getNewLineOrDefaultFromHost(host, options)); return onLaterLine ? 0 /* None */ : 1 /* LineAdded */; } break; @@ -126727,6 +126737,10 @@ var ts; ChangeTracker.prototype.delete = function (sourceFile, node) { this.deletedNodes.push({ sourceFile: sourceFile, node: node }); }; + ChangeTracker.prototype.deleteNode = function (sourceFile, node, options) { + if (options === void 0) { options = { leadingTriviaOption: LeadingTriviaOption.IncludeAll }; } + this.deleteRange(sourceFile, getAdjustedRange(sourceFile, node, node, options)); + }; ChangeTracker.prototype.deleteModifier = function (sourceFile, modifier) { this.deleteRange(sourceFile, { pos: modifier.getStart(sourceFile), end: ts.skipTrivia(sourceFile.text, modifier.end, /*stopAfterLineBreak*/ true) }); }; @@ -139383,7 +139397,7 @@ var ts; function getCompletionEntryDetails(fileName, position, name, formattingOptions, source, preferences) { if (preferences === void 0) { preferences = ts.emptyOptions; } synchronizeHostData(); - return ts.Completions.getCompletionEntryDetails(program, log, getValidSourceFile(fileName), position, { name: name, source: source }, host, (formattingOptions && ts.formatting.getFormatContext(formattingOptions)), // TODO: GH#18217 + return ts.Completions.getCompletionEntryDetails(program, log, getValidSourceFile(fileName), position, { name: name, source: source }, host, (formattingOptions && ts.formatting.getFormatContext(formattingOptions, host)), // TODO: GH#18217 preferences, cancellationToken); } function getCompletionEntrySymbol(fileName, position, name, source, preferences) { @@ -139655,14 +139669,14 @@ var ts; } function getFormattingEditsForRange(fileName, start, end, options) { var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); - return ts.formatting.formatSelection(start, end, sourceFile, ts.formatting.getFormatContext(toEditorSettings(options))); + return ts.formatting.formatSelection(start, end, sourceFile, ts.formatting.getFormatContext(toEditorSettings(options), host)); } function getFormattingEditsForDocument(fileName, options) { - return ts.formatting.formatDocument(syntaxTreeCache.getCurrentSourceFile(fileName), ts.formatting.getFormatContext(toEditorSettings(options))); + return ts.formatting.formatDocument(syntaxTreeCache.getCurrentSourceFile(fileName), ts.formatting.getFormatContext(toEditorSettings(options), host)); } function getFormattingEditsAfterKeystroke(fileName, position, key, options) { var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); - var formatContext = ts.formatting.getFormatContext(toEditorSettings(options)); + var formatContext = ts.formatting.getFormatContext(toEditorSettings(options), host); if (!ts.isInComment(sourceFile, position)) { switch (key) { case "{": @@ -139682,7 +139696,7 @@ var ts; synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); var span = ts.createTextSpanFromBounds(start, end); - var formatContext = ts.formatting.getFormatContext(formatOptions); + var formatContext = ts.formatting.getFormatContext(formatOptions, host); return ts.flatMap(ts.deduplicate(errorCodes, ts.equateValues, ts.compareValues), function (errorCode) { cancellationToken.throwIfCancellationRequested(); return ts.codefix.getFixes({ errorCode: errorCode, sourceFile: sourceFile, span: span, program: program, host: host, cancellationToken: cancellationToken, formatContext: formatContext, preferences: preferences }); @@ -139693,7 +139707,7 @@ var ts; synchronizeHostData(); ts.Debug.assert(scope.type === "file"); var sourceFile = getValidSourceFile(scope.fileName); - var formatContext = ts.formatting.getFormatContext(formatOptions); + var formatContext = ts.formatting.getFormatContext(formatOptions, host); return ts.codefix.getAllFixes({ fixId: fixId, sourceFile: sourceFile, program: program, host: host, cancellationToken: cancellationToken, formatContext: formatContext, preferences: preferences }); } function organizeImports(scope, formatOptions, preferences) { @@ -139701,12 +139715,12 @@ var ts; synchronizeHostData(); ts.Debug.assert(scope.type === "file"); var sourceFile = getValidSourceFile(scope.fileName); - var formatContext = ts.formatting.getFormatContext(formatOptions); + var formatContext = ts.formatting.getFormatContext(formatOptions, host); return ts.OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences); } function getEditsForFileRename(oldFilePath, newFilePath, formatOptions, preferences) { if (preferences === void 0) { preferences = ts.emptyOptions; } - return ts.getEditsForFileRename(getProgram(), oldFilePath, newFilePath, host, ts.formatting.getFormatContext(formatOptions), preferences, sourceMapper); + return ts.getEditsForFileRename(getProgram(), oldFilePath, newFilePath, host, ts.formatting.getFormatContext(formatOptions, host), preferences, sourceMapper); } function applyCodeActionCommand(fileName, actionOrFormatSettingsOrUndefined) { var action = typeof fileName === "string" ? actionOrFormatSettingsOrUndefined : fileName; @@ -139908,7 +139922,7 @@ var ts; endPosition: endPosition, program: getProgram(), host: host, - formatContext: ts.formatting.getFormatContext(formatOptions), + formatContext: ts.formatting.getFormatContext(formatOptions, host), cancellationToken: cancellationToken, preferences: preferences, }; diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index d78fb9eda99d6..3c934b9170143 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -244,7 +244,7 @@ var ts; // If changing the text in this section, be sure to test `configurePrerelease` too. ts.versionMajorMinor = "3.9"; /** The version of the TypeScript compiler release */ - ts.version = "3.9.2"; + ts.version = "3.9.3"; /** * Returns the native Map implementation if it is available and compatible (i.e. supports iteration). */ @@ -44040,7 +44040,7 @@ var ts; return type.resolvedProperties; } function getPropertiesOfType(type) { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); return type.flags & 3145728 /* UnionOrIntersection */ ? getPropertiesOfUnionOrIntersectionType(type) : getPropertiesOfObjectType(type); @@ -44373,6 +44373,13 @@ var ts; t.flags & 2 /* Unknown */ && !strictNullChecks ? emptyObjectType : t; } + function getReducedApparentType(type) { + // Since getApparentType may return a non-reduced union or intersection type, we need to perform + // type reduction both before and after obtaining the apparent type. For example, given a type parameter + // 'T extends A | B', the type 'T & X' becomes 'A & X | B & X' after obtaining the apparent type, and + // that type may need futher reduction to remove empty intersections. + return getReducedType(getApparentType(getReducedType(type))); + } function createUnionOrIntersectionProperty(containingType, name) { var singleProp; var propSet; @@ -44583,7 +44590,7 @@ var ts; * @param name a name of property to look up in a given type */ function getPropertyOfType(type, name) { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); if (type.flags & 524288 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members.get(name); @@ -44619,7 +44626,7 @@ var ts; * maps primitive types and type parameters are to their apparent types. */ function getSignaturesOfType(type, kind) { - return getSignaturesOfStructuredType(getApparentType(getReducedType(type)), kind); + return getSignaturesOfStructuredType(getReducedApparentType(type), kind); } function getIndexInfoOfStructuredType(type, kind) { if (type.flags & 3670016 /* StructuredType */) { @@ -44634,12 +44641,12 @@ var ts; // Return the indexing info of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexInfoOfType(type, kind) { - return getIndexInfoOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexInfoOfStructuredType(getReducedApparentType(type), kind); } // Return the index type of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexTypeOfType(type, kind) { - return getIndexTypeOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexTypeOfStructuredType(getReducedApparentType(type), kind); } function getImplicitIndexTypeOfType(type, kind) { if (isObjectTypeWithInferableIndex(type)) { @@ -46810,7 +46817,7 @@ var ts; // In the following we resolve T[K] to the type of the property in T selected by K. // We treat boolean as different from other unions to improve errors; // skipping straight to getPropertyTypeForIndexType gives errors with 'boolean' instead of 'true'. - var apparentObjectType = getApparentType(getReducedType(objectType)); + var apparentObjectType = getReducedApparentType(objectType); if (indexType.flags & 1048576 /* Union */ && !(indexType.flags & 16 /* Boolean */)) { var propTypes = []; var wasMissingProp = false; @@ -56499,7 +56506,7 @@ var ts; var right = _a[_i]; var left = props.get(right.escapedName); var rightType = getTypeOfSymbol(right); - if (left && !maybeTypeOfKind(rightType, 98304 /* Nullable */) && !(maybeTypeOfKind(rightType, 1 /* Any */) && right.flags & 16777216 /* Optional */)) { + if (left && !maybeTypeOfKind(rightType, 98304 /* Nullable */) && !(maybeTypeOfKind(rightType, 3 /* AnyOrUnknown */) && right.flags & 16777216 /* Optional */)) { var diagnostic = error(left.valueDeclaration, ts.Diagnostics._0_is_specified_more_than_once_so_this_usage_will_be_overwritten, ts.unescapeLeadingUnderscores(left.escapedName)); ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(spread, ts.Diagnostics.This_spread_always_overwrites_this_property)); } @@ -77354,13 +77361,16 @@ var ts; // Find original source text, since we need to emit the raw strings of the tagged template. // The raw strings contain the (escaped) strings of what the user wrote. // Examples: `\n` is converted to "\\n", a template string with a newline to "\n". - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), - // thus we need to remove those characters. - // First template piece starts with "`", others with "}" - // Last template piece ends with "`", others with "${" - var isLast = node.kind === 14 /* NoSubstitutionTemplateLiteral */ || node.kind === 17 /* TemplateTail */; - text = text.substring(1, text.length - (isLast ? 1 : 2)); + var text = node.rawText; + if (text === undefined) { + text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), + // thus we need to remove those characters. + // First template piece starts with "`", others with "}" + // Last template piece ends with "`", others with "${" + var isLast = node.kind === 14 /* NoSubstitutionTemplateLiteral */ || node.kind === 17 /* TemplateTail */; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + } // Newline normalization: // ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's // and LineTerminatorSequences are normalized to for both TV and TRV. @@ -90503,7 +90513,7 @@ var ts; scoped: false, dependencies: [ts.createBindingHelper], priority: 2, - text: "\n var __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);\n }" + text: "\n var __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);\n };" }; function createExportStarHelper(context, module) { context.requestEmitHelper(exportStarHelper); @@ -110195,8 +110205,8 @@ var ts; * The default is CRLF. */ function getNewLineOrDefaultFromHost(host, formatSettings) { - return (formatSettings && formatSettings.newLineCharacter) || - (host.getNewLine && host.getNewLine()) || + var _a; + return (formatSettings === null || formatSettings === void 0 ? void 0 : formatSettings.newLineCharacter) || ((_a = host.getNewLine) === null || _a === void 0 ? void 0 : _a.call(host)) || carriageReturnLineFeed; } ts.getNewLineOrDefaultFromHost = getNewLineOrDefaultFromHost; @@ -120290,7 +120300,7 @@ var ts; } // Delete any subsequent imports. for (var i = 1; i < oldImportDecls.length; i++) { - changeTracker.delete(sourceFile, oldImportDecls[i]); + changeTracker.deleteNode(sourceFile, oldImportDecls[i]); } } } @@ -124760,8 +124770,8 @@ var ts; (function (ts) { var formatting; (function (formatting) { - function getFormatContext(options) { - return { options: options, getRules: getRulesMap() }; + function getFormatContext(options, host) { + return { options: options, getRules: getRulesMap(), host: host }; } formatting.getFormatContext = getFormatContext; var rulesMapCache; @@ -125174,7 +125184,7 @@ var ts; return formatting.getFormattingScanner(sourceFile.text, sourceFile.languageVariant, getScanStartPosition(enclosingNode, originalRange, sourceFile), originalRange.end, function (scanner) { return formatSpanWorker(originalRange, enclosingNode, formatting.SmartIndenter.getIndentationForNode(enclosingNode, originalRange, sourceFile, formatContext.options), getOwnOrInheritedDelta(enclosingNode, formatContext.options, sourceFile), scanner, formatContext, requestKind, prepareRangeContainsErrorFunction(sourceFile.parseDiagnostics, originalRange), sourceFile); }); } function formatSpanWorker(originalRange, enclosingNode, initialIndentation, delta, formattingScanner, _a, requestKind, rangeContainsError, sourceFile) { - var options = _a.options, getRules = _a.getRules; + var options = _a.options, getRules = _a.getRules, host = _a.host; // formatting context is used by rules provider var formattingContext = new formatting.FormattingContext(sourceFile, requestKind, options); var previousRange; @@ -125844,7 +125854,7 @@ var ts; // edit should not be applied if we have one line feed between elements var lineDelta = currentStartLine - previousStartLine; if (lineDelta !== 1) { - recordReplace(previousRange.end, currentRange.pos - previousRange.end, options.newLineCharacter); + recordReplace(previousRange.end, currentRange.pos - previousRange.end, ts.getNewLineOrDefaultFromHost(host, options)); return onLaterLine ? 0 /* None */ : 1 /* LineAdded */; } break; @@ -126727,6 +126737,10 @@ var ts; ChangeTracker.prototype.delete = function (sourceFile, node) { this.deletedNodes.push({ sourceFile: sourceFile, node: node }); }; + ChangeTracker.prototype.deleteNode = function (sourceFile, node, options) { + if (options === void 0) { options = { leadingTriviaOption: LeadingTriviaOption.IncludeAll }; } + this.deleteRange(sourceFile, getAdjustedRange(sourceFile, node, node, options)); + }; ChangeTracker.prototype.deleteModifier = function (sourceFile, modifier) { this.deleteRange(sourceFile, { pos: modifier.getStart(sourceFile), end: ts.skipTrivia(sourceFile.text, modifier.end, /*stopAfterLineBreak*/ true) }); }; @@ -139383,7 +139397,7 @@ var ts; function getCompletionEntryDetails(fileName, position, name, formattingOptions, source, preferences) { if (preferences === void 0) { preferences = ts.emptyOptions; } synchronizeHostData(); - return ts.Completions.getCompletionEntryDetails(program, log, getValidSourceFile(fileName), position, { name: name, source: source }, host, (formattingOptions && ts.formatting.getFormatContext(formattingOptions)), // TODO: GH#18217 + return ts.Completions.getCompletionEntryDetails(program, log, getValidSourceFile(fileName), position, { name: name, source: source }, host, (formattingOptions && ts.formatting.getFormatContext(formattingOptions, host)), // TODO: GH#18217 preferences, cancellationToken); } function getCompletionEntrySymbol(fileName, position, name, source, preferences) { @@ -139655,14 +139669,14 @@ var ts; } function getFormattingEditsForRange(fileName, start, end, options) { var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); - return ts.formatting.formatSelection(start, end, sourceFile, ts.formatting.getFormatContext(toEditorSettings(options))); + return ts.formatting.formatSelection(start, end, sourceFile, ts.formatting.getFormatContext(toEditorSettings(options), host)); } function getFormattingEditsForDocument(fileName, options) { - return ts.formatting.formatDocument(syntaxTreeCache.getCurrentSourceFile(fileName), ts.formatting.getFormatContext(toEditorSettings(options))); + return ts.formatting.formatDocument(syntaxTreeCache.getCurrentSourceFile(fileName), ts.formatting.getFormatContext(toEditorSettings(options), host)); } function getFormattingEditsAfterKeystroke(fileName, position, key, options) { var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); - var formatContext = ts.formatting.getFormatContext(toEditorSettings(options)); + var formatContext = ts.formatting.getFormatContext(toEditorSettings(options), host); if (!ts.isInComment(sourceFile, position)) { switch (key) { case "{": @@ -139682,7 +139696,7 @@ var ts; synchronizeHostData(); var sourceFile = getValidSourceFile(fileName); var span = ts.createTextSpanFromBounds(start, end); - var formatContext = ts.formatting.getFormatContext(formatOptions); + var formatContext = ts.formatting.getFormatContext(formatOptions, host); return ts.flatMap(ts.deduplicate(errorCodes, ts.equateValues, ts.compareValues), function (errorCode) { cancellationToken.throwIfCancellationRequested(); return ts.codefix.getFixes({ errorCode: errorCode, sourceFile: sourceFile, span: span, program: program, host: host, cancellationToken: cancellationToken, formatContext: formatContext, preferences: preferences }); @@ -139693,7 +139707,7 @@ var ts; synchronizeHostData(); ts.Debug.assert(scope.type === "file"); var sourceFile = getValidSourceFile(scope.fileName); - var formatContext = ts.formatting.getFormatContext(formatOptions); + var formatContext = ts.formatting.getFormatContext(formatOptions, host); return ts.codefix.getAllFixes({ fixId: fixId, sourceFile: sourceFile, program: program, host: host, cancellationToken: cancellationToken, formatContext: formatContext, preferences: preferences }); } function organizeImports(scope, formatOptions, preferences) { @@ -139701,12 +139715,12 @@ var ts; synchronizeHostData(); ts.Debug.assert(scope.type === "file"); var sourceFile = getValidSourceFile(scope.fileName); - var formatContext = ts.formatting.getFormatContext(formatOptions); + var formatContext = ts.formatting.getFormatContext(formatOptions, host); return ts.OrganizeImports.organizeImports(sourceFile, formatContext, host, program, preferences); } function getEditsForFileRename(oldFilePath, newFilePath, formatOptions, preferences) { if (preferences === void 0) { preferences = ts.emptyOptions; } - return ts.getEditsForFileRename(getProgram(), oldFilePath, newFilePath, host, ts.formatting.getFormatContext(formatOptions), preferences, sourceMapper); + return ts.getEditsForFileRename(getProgram(), oldFilePath, newFilePath, host, ts.formatting.getFormatContext(formatOptions, host), preferences, sourceMapper); } function applyCodeActionCommand(fileName, actionOrFormatSettingsOrUndefined) { var action = typeof fileName === "string" ? actionOrFormatSettingsOrUndefined : fileName; @@ -139908,7 +139922,7 @@ var ts; endPosition: endPosition, program: getProgram(), host: host, - formatContext: ts.formatting.getFormatContext(formatOptions), + formatContext: ts.formatting.getFormatContext(formatOptions, host), cancellationToken: cancellationToken, preferences: preferences, }; diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 967aad4ef5b36..a30a2a2bb2a87 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -83,7 +83,7 @@ var ts; // If changing the text in this section, be sure to test `configurePrerelease` too. ts.versionMajorMinor = "3.9"; /** The version of the TypeScript compiler release */ - ts.version = "3.9.2"; + ts.version = "3.9.3"; /** * Returns the native Map implementation if it is available and compatible (i.e. supports iteration). */ @@ -43879,7 +43879,7 @@ var ts; return type.resolvedProperties; } function getPropertiesOfType(type) { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); return type.flags & 3145728 /* UnionOrIntersection */ ? getPropertiesOfUnionOrIntersectionType(type) : getPropertiesOfObjectType(type); @@ -44212,6 +44212,13 @@ var ts; t.flags & 2 /* Unknown */ && !strictNullChecks ? emptyObjectType : t; } + function getReducedApparentType(type) { + // Since getApparentType may return a non-reduced union or intersection type, we need to perform + // type reduction both before and after obtaining the apparent type. For example, given a type parameter + // 'T extends A | B', the type 'T & X' becomes 'A & X | B & X' after obtaining the apparent type, and + // that type may need futher reduction to remove empty intersections. + return getReducedType(getApparentType(getReducedType(type))); + } function createUnionOrIntersectionProperty(containingType, name) { var singleProp; var propSet; @@ -44422,7 +44429,7 @@ var ts; * @param name a name of property to look up in a given type */ function getPropertyOfType(type, name) { - type = getApparentType(getReducedType(type)); + type = getReducedApparentType(type); if (type.flags & 524288 /* Object */) { var resolved = resolveStructuredTypeMembers(type); var symbol = resolved.members.get(name); @@ -44458,7 +44465,7 @@ var ts; * maps primitive types and type parameters are to their apparent types. */ function getSignaturesOfType(type, kind) { - return getSignaturesOfStructuredType(getApparentType(getReducedType(type)), kind); + return getSignaturesOfStructuredType(getReducedApparentType(type), kind); } function getIndexInfoOfStructuredType(type, kind) { if (type.flags & 3670016 /* StructuredType */) { @@ -44473,12 +44480,12 @@ var ts; // Return the indexing info of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexInfoOfType(type, kind) { - return getIndexInfoOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexInfoOfStructuredType(getReducedApparentType(type), kind); } // Return the index type of the given kind in the given type. Creates synthetic union index types when necessary and // maps primitive types and type parameters are to their apparent types. function getIndexTypeOfType(type, kind) { - return getIndexTypeOfStructuredType(getApparentType(getReducedType(type)), kind); + return getIndexTypeOfStructuredType(getReducedApparentType(type), kind); } function getImplicitIndexTypeOfType(type, kind) { if (isObjectTypeWithInferableIndex(type)) { @@ -46649,7 +46656,7 @@ var ts; // In the following we resolve T[K] to the type of the property in T selected by K. // We treat boolean as different from other unions to improve errors; // skipping straight to getPropertyTypeForIndexType gives errors with 'boolean' instead of 'true'. - var apparentObjectType = getApparentType(getReducedType(objectType)); + var apparentObjectType = getReducedApparentType(objectType); if (indexType.flags & 1048576 /* Union */ && !(indexType.flags & 16 /* Boolean */)) { var propTypes = []; var wasMissingProp = false; @@ -56338,7 +56345,7 @@ var ts; var right = _a[_i]; var left = props.get(right.escapedName); var rightType = getTypeOfSymbol(right); - if (left && !maybeTypeOfKind(rightType, 98304 /* Nullable */) && !(maybeTypeOfKind(rightType, 1 /* Any */) && right.flags & 16777216 /* Optional */)) { + if (left && !maybeTypeOfKind(rightType, 98304 /* Nullable */) && !(maybeTypeOfKind(rightType, 3 /* AnyOrUnknown */) && right.flags & 16777216 /* Optional */)) { var diagnostic = error(left.valueDeclaration, ts.Diagnostics._0_is_specified_more_than_once_so_this_usage_will_be_overwritten, ts.unescapeLeadingUnderscores(left.escapedName)); ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(spread, ts.Diagnostics.This_spread_always_overwrites_this_property)); } @@ -77193,13 +77200,16 @@ var ts; // Find original source text, since we need to emit the raw strings of the tagged template. // The raw strings contain the (escaped) strings of what the user wrote. // Examples: `\n` is converted to "\\n", a template string with a newline to "\n". - var text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); - // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), - // thus we need to remove those characters. - // First template piece starts with "`", others with "}" - // Last template piece ends with "`", others with "${" - var isLast = node.kind === 14 /* NoSubstitutionTemplateLiteral */ || node.kind === 17 /* TemplateTail */; - text = text.substring(1, text.length - (isLast ? 1 : 2)); + var text = node.rawText; + if (text === undefined) { + text = ts.getSourceTextOfNodeFromSourceFile(currentSourceFile, node); + // text contains the original source, it will also contain quotes ("`"), dolar signs and braces ("${" and "}"), + // thus we need to remove those characters. + // First template piece starts with "`", others with "}" + // Last template piece ends with "`", others with "${" + var isLast = node.kind === 14 /* NoSubstitutionTemplateLiteral */ || node.kind === 17 /* TemplateTail */; + text = text.substring(1, text.length - (isLast ? 1 : 2)); + } // Newline normalization: // ES6 Spec 11.8.6.1 - Static Semantics of TV's and TRV's // and LineTerminatorSequences are normalized to for both TV and TRV. @@ -90342,7 +90352,7 @@ var ts; scoped: false, dependencies: [ts.createBindingHelper], priority: 2, - text: "\n var __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);\n }" + text: "\n var __exportStar = (this && this.__exportStar) || function(m, exports) {\n for (var p in m) if (p !== \"default\" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);\n };" }; function createExportStarHelper(context, module) { context.requestEmitHelper(exportStarHelper); diff --git a/package.json b/package.json index 79cdcc92fab90..809222e68d4f0 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "https://www.typescriptlang.org/", - "version": "3.9.2", + "version": "3.9.3", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/corePublic.ts b/src/compiler/corePublic.ts index 4cce68313f542..9b149a43c303b 100644 --- a/src/compiler/corePublic.ts +++ b/src/compiler/corePublic.ts @@ -3,7 +3,7 @@ namespace ts { // If changing the text in this section, be sure to test `configurePrerelease` too. export const versionMajorMinor = "3.9"; /** The version of the TypeScript compiler release */ - export const version = "3.9.2" as string; + export const version = "3.9.3" as string; /** * Type of objects whose values are all of the same type.