diff --git a/lib/tsc.js b/lib/tsc.js index 97db13aa62a50..ab79f9e91feec 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -69,7 +69,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) { var ts; (function (ts) { ts.versionMajorMinor = "4.8"; - ts.version = "4.8.2"; + ts.version = "4.8.3"; var NativeCollections; (function (NativeCollections) { var globals = typeof globalThis !== "undefined" ? globalThis : @@ -6031,7 +6031,7 @@ var ts; Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: diag(2591, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591", "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: diag(2592, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592", "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: diag(2593, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_type_2593", "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig."), - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the__2594", "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag."), + This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag_2594", "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag."), _0_can_only_be_imported_by_using_a_default_import: diag(2595, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_default_import_2595", "'{0}' can only be imported by using a default import."), _0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import: diag(2596, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import_2596", "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import."), _0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import: diag(2597, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import_2597", "'{0}' can only be imported by using a 'require' call or by using a default import."), @@ -36545,7 +36545,7 @@ var ts; var _a, _b; if (path === undefined) return path; - return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a))); + return ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); } function combineDirectoryPath(root, dir) { return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir)); @@ -36560,7 +36560,7 @@ var ts; if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) { + && (state.compilerOptions.configFile ? ts.containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)) { var getCanonicalFileName = ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames }); var commonSourceDirGuesses = []; if (state.compilerOptions.rootDir || (state.compilerOptions.composite && state.compilerOptions.configFilePath)) { @@ -36590,7 +36590,7 @@ var ts; var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) { var candidateDir = candidateDirectories_1[_e]; - if (ts.startsWith(finalPath, candidateDir)) { + if (ts.containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { var pathFragment = finalPath.slice(candidateDir.length + 1); var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment); var jsAndDtsExtensions = [".mjs", ".cjs", ".js", ".json", ".d.mts", ".d.cts", ".d.ts"]; @@ -41875,40 +41875,60 @@ var ts; return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { - var _a; var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - var exportDefaultSymbol = void 0; - if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, "default", node, dontResolveAlias); - } - var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); - var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - var exportEqualsSymbol = moduleSymbol.exports.get("export="); - var exportAssignment = exportEqualsSymbol.valueDeclaration; - var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - if (exportAssignment) { - ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + function getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias) { + var _a; + var exportDefaultSymbol; + if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, "default", node, dontResolveAlias); + } + var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); + var specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + var hasDefaultOnly = isOnlyImportedAsDefault(specifier); + var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + var exportEqualsSymbol = moduleSymbol.exports.get("export="); + var exportAssignment = exportEqualsSymbol.valueDeclaration; + var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + if (exportAssignment) { + ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, false); - return resolved; + else if (ts.isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); + } + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, ts.isImportOrExportSpecifier(node) && node.propertyName || node.name); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, undefined, false); - return exportDefaultSymbol; + } + else if (hasSyntheticDefault || hasDefaultOnly) { + var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, undefined, false); + return exportDefaultSymbol; + } + function getModuleSpecifierForImportOrExport(node) { + switch (node.kind) { + case 267: return node.parent.moduleSpecifier; + case 265: return ts.isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case 268: return node.parent.parent.moduleSpecifier; + case 270: return node.parent.parent.parent.moduleSpecifier; + case 275: return node.parent.parent.moduleSpecifier; + default: return ts.Debug.assertNever(node); } } function reportNonDefaultExport(moduleSymbol, node) { @@ -41980,7 +42000,7 @@ var ts; } } function getExternalModuleMember(node, specifier, dontResolveAlias) { - var _a, _b; + var _a; if (dontResolveAlias === void 0) { dontResolveAlias = false; } var moduleSpecifier = ts.getExternalModuleRequireArgument(node) || node.moduleSpecifier; var moduleSymbol = resolveExternalModuleName(node, moduleSpecifier); @@ -42014,29 +42034,33 @@ var ts; combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - var moduleName = getFullyQualifiedName(moduleSymbol, node); - var declarationName = ts.declarationNameToString(name); - var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - var suggestionName = symbolToString(suggestion); - var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); - } - } - else { - if ((_b = moduleSymbol.exports) === null || _b === void 0 ? void 0 : _b.has("default")) { - error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } + function errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name) { + var _a; + var moduleName = getFullyQualifiedName(moduleSymbol, node); + var declarationName = ts.declarationNameToString(name); + var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + var suggestionName = symbolToString(suggestion); + var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); + } + } + else { + if ((_a = moduleSymbol.exports) === null || _a === void 0 ? void 0 : _a.has("default")) { + error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } function reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName) { var _a, _b; var localSymbol = (_b = (_a = moduleSymbol.valueDeclaration) === null || _a === void 0 ? void 0 : _a.locals) === null || _b === void 0 ? void 0 : _b.get(name.escapedText); @@ -42082,6 +42106,13 @@ var ts; } } function getTargetOfImportSpecifier(node, dontResolveAlias) { + if (ts.isImportSpecifier(node) && ts.idText(node.propertyName || node.name) === "default") { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } var root = ts.isBindingElement(node) ? ts.getRootDeclaration(node) : node.parent.parent.parent; var commonJSPropertyAccess = getCommonJSPropertyAccess(root); var resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -42103,6 +42134,13 @@ var ts; return resolved; } function getTargetOfExportSpecifier(node, meaning, dontResolveAlias) { + if (ts.idText(node.propertyName || node.name) === "default") { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } var resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, false, dontResolveAlias); @@ -51674,7 +51712,7 @@ var ts; return includes & 8388608 ? wildcardType : anyType; } if (!strictNullChecks && includes & 98304) { - return includes & 32768 ? undefinedType : nullType; + return includes & 16777216 ? neverType : includes & 32768 ? undefinedType : nullType; } if (includes & 4 && includes & (128 | 134217728 | 268435456) || includes & 8 && includes & 256 || @@ -52309,7 +52347,7 @@ var ts; type; } function distributeIndexOverObjectType(objectType, indexType, writing) { - if (objectType.flags & 3145728) { + if (objectType.flags & 1048576 || objectType.flags & 2097152 && !shouldDeferIndexType(objectType)) { var types = ts.map(objectType.types, function (t) { return getSimplifiedType(getIndexedAccessType(t, indexType), writing); }); return objectType.flags & 2097152 || writing ? getIntersectionType(types) : getUnionType(types); } @@ -54448,7 +54486,7 @@ var ts; if (reduced !== type) { return reduced; } - if (type.flags & 2097152) { + if (type.flags & 2097152 && ts.some(type.types, isEmptyAnonymousObjectType)) { var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); }); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -55432,7 +55470,7 @@ var ts; if (reportErrors && originalErrorInfo) { resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, 2, reportErrors)) { + if (result = isRelatedTo(source, constraint, 2, reportErrors, undefined, intersectionState)) { return result; } if (reportErrors && originalErrorInfo && errorInfo) { @@ -55495,8 +55533,8 @@ var ts; if (!c.root.inferTypeParameters && !isDistributionDependent(c.root)) { var skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); var skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); - if (result = skipTrue ? -1 : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2, false)) { - result &= skipFalse ? -1 : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2, false); + if (result = skipTrue ? -1 : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2, false, undefined, intersectionState)) { + result &= skipFalse ? -1 : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2, false, undefined, intersectionState); if (result) { return result; } @@ -59855,7 +59893,7 @@ var ts; var narrowedPropType = narrowType(propType); return filterType(type, function (t) { var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & 131072) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & 131072) && areTypesComparable(narrowedPropType, discriminantType); }); } function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) { @@ -59904,7 +59942,7 @@ var ts; } function narrowByInKeyword(type, name, assumeTrue) { if (type.flags & 1048576 - || type.flags & 524288 && declaredType !== type + || type.flags & 524288 && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || ts.isThisTypeParameter(type) || type.flags & 2097152 && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) { return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); }); @@ -60024,14 +60062,18 @@ var ts; assumeTrue = !assumeTrue; } var valueType = getTypeOfExpression(value); - if ((type.flags & 2) && assumeTrue && (operator === 36 || operator === 37)) { + if (((type.flags & 2) || isEmptyAnonymousObjectType(type) && !(valueType.flags & 98304)) && + assumeTrue && + (operator === 36 || operator === 37)) { if (valueType.flags & (131068 | 67108864)) { return valueType; } if (valueType.flags & 524288) { return nonPrimitiveType; } - return type; + if (type.flags & 2) { + return type; + } } if (valueType.flags & 98304) { if (!strictNullChecks) { @@ -60426,7 +60468,9 @@ var ts; !!(type.flags & 465829888 && getBaseConstraintOrType(type).flags & (98304 | 1048576)); } function isGenericTypeWithoutNullableConstraint(type) { - return !!(type.flags & 465829888 && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304)); + return type.flags & 2097152 ? + ts.some(type.types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & 465829888 && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304)); } function hasContextualTypeWithNoGenericTypes(node, checkMode) { var contextualType = (ts.isIdentifier(node) || ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) && @@ -105437,9 +105481,7 @@ var ts; } } } - var seenRefs = buildInfoPath ? new ts.Set() : undefined; var buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs === null || seenRefs === void 0 ? void 0 : seenRefs.add(resolvedPath); var pseudoUpToDate = false; var usesPrepend = false; var upstreamChangedProject; @@ -105450,7 +105492,7 @@ var ts; if (refStatus.newestInputFileTime && refStatus.newestInputFileTime <= oldestOutputFileTime) { continue; } - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: ts.UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath, @@ -105501,24 +105543,9 @@ var ts; oldestOutputFileName: oldestOutputFileName }; } - function hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath) { - if (seenRefs.has(resolvedRefPath)) - return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath) { var refBuildInfo = state.buildInfoCache.get(resolvedRefPath); - if (refBuildInfo.path === buildInfoCacheEntry.path) - return true; - if (resolvedConfig.projectReferences) { - for (var _i = 0, _a = resolvedConfig.projectReferences; _i < _a.length; _i++) { - var ref = _a[_i]; - var resolvedRef = ts.resolveProjectReferencePath(ref); - var resolvedRefPath_1 = toResolvedConfigFilePath(state, resolvedRef); - var resolvedConfig_1 = parseConfigFile(state, resolvedRef, resolvedRefPath_1); - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig_1, resolvedRefPath_1)) - return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state, project, resolvedPath) { if (project === undefined) { diff --git a/lib/tsserver.js b/lib/tsserver.js index 481cb5866634e..b696263504d68 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -109,7 +109,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.8.2"; + ts.version = "4.8.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -8875,7 +8875,7 @@ var ts; Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: diag(2591, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591", "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: diag(2592, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592", "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: diag(2593, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_type_2593", "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig."), - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the__2594", "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag."), + This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag_2594", "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag."), _0_can_only_be_imported_by_using_a_default_import: diag(2595, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_default_import_2595", "'{0}' can only be imported by using a default import."), _0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import: diag(2596, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import_2596", "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import."), _0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import: diag(2597, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import_2597", "'{0}' can only be imported by using a 'require' call or by using a default import."), @@ -44636,7 +44636,7 @@ var ts; var _a, _b; if (path === undefined) return path; - return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a))); + return ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); } function combineDirectoryPath(root, dir) { return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir)); @@ -44656,7 +44656,7 @@ var ts; if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) { + && (state.compilerOptions.configFile ? ts.containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)) { // So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings. // Even with all that, we still don't know if the root of the output file structure will be (relative to the package file) // `.`, `./src` or any other deeper directory structure. (If project references are used, it's definitely `.` by fiat, so that should be pretty common.) @@ -44712,7 +44712,7 @@ var ts; var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) { var candidateDir = candidateDirectories_1[_e]; - if (ts.startsWith(finalPath, candidateDir)) { + if (ts.containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension var pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment); @@ -50994,41 +50994,61 @@ var ts; return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { - var _a; var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - var exportDefaultSymbol = void 0; - if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); - } - var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); - var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); - var exportAssignment = exportEqualsSymbol.valueDeclaration; - var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - if (exportAssignment) { - ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + function getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias) { + var _a; + var exportDefaultSymbol; + if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); + } + var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); + var specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + var hasDefaultOnly = isOnlyImportedAsDefault(specifier); + var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); + var exportAssignment = exportEqualsSymbol.valueDeclaration; + var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + if (exportAssignment) { + ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present - var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); - return resolved; + else if (ts.isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); - return exportDefaultSymbol; + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, ts.isImportOrExportSpecifier(node) && node.propertyName || node.name); + } + } + else if (hasSyntheticDefault || hasDefaultOnly) { + // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present + var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); + return exportDefaultSymbol; + } + function getModuleSpecifierForImportOrExport(node) { + switch (node.kind) { + case 267 /* SyntaxKind.ImportClause */: return node.parent.moduleSpecifier; + case 265 /* SyntaxKind.ImportEqualsDeclaration */: return ts.isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case 268 /* SyntaxKind.NamespaceImport */: return node.parent.parent.moduleSpecifier; + case 270 /* SyntaxKind.ImportSpecifier */: return node.parent.parent.parent.moduleSpecifier; + case 275 /* SyntaxKind.ExportSpecifier */: return node.parent.parent.moduleSpecifier; + default: return ts.Debug.assertNever(node); } } function reportNonDefaultExport(moduleSymbol, node) { @@ -51118,7 +51138,7 @@ var ts; } } function getExternalModuleMember(node, specifier, dontResolveAlias) { - var _a, _b; + var _a; if (dontResolveAlias === void 0) { dontResolveAlias = false; } var moduleSpecifier = ts.getExternalModuleRequireArgument(node) || node.moduleSpecifier; var moduleSymbol = resolveExternalModuleName(node, moduleSpecifier); // TODO: GH#18217 @@ -51154,29 +51174,33 @@ var ts; combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - var moduleName = getFullyQualifiedName(moduleSymbol, node); - var declarationName = ts.declarationNameToString(name); - var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - var suggestionName = symbolToString(suggestion); - var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); - } - } - else { - if ((_b = moduleSymbol.exports) === null || _b === void 0 ? void 0 : _b.has("default" /* InternalSymbolName.Default */)) { - error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } + function errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name) { + var _a; + var moduleName = getFullyQualifiedName(moduleSymbol, node); + var declarationName = ts.declarationNameToString(name); + var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + var suggestionName = symbolToString(suggestion); + var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); + } + } + else { + if ((_a = moduleSymbol.exports) === null || _a === void 0 ? void 0 : _a.has("default" /* InternalSymbolName.Default */)) { + error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } function reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName) { var _a, _b; var localSymbol = (_b = (_a = moduleSymbol.valueDeclaration) === null || _a === void 0 ? void 0 : _a.locals) === null || _b === void 0 ? void 0 : _b.get(name.escapedText); @@ -51222,6 +51246,13 @@ var ts; } } function getTargetOfImportSpecifier(node, dontResolveAlias) { + if (ts.isImportSpecifier(node) && ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } var root = ts.isBindingElement(node) ? ts.getRootDeclaration(node) : node.parent.parent.parent; var commonJSPropertyAccess = getCommonJSPropertyAccess(root); var resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -51243,6 +51274,13 @@ var ts; return resolved; } function getTargetOfExportSpecifier(node, meaning, dontResolveAlias) { + if (ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } var resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); @@ -62193,7 +62231,7 @@ var ts; return includes & 8388608 /* TypeFlags.IncludesWildcard */ ? wildcardType : anyType; } if (!strictNullChecks && includes & 98304 /* TypeFlags.Nullable */) { - return includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; + return includes & 16777216 /* TypeFlags.IncludesEmptyObject */ ? neverType : includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; } if (includes & 4 /* TypeFlags.String */ && includes & (128 /* TypeFlags.StringLiteral */ | 134217728 /* TypeFlags.TemplateLiteral */ | 268435456 /* TypeFlags.StringMapping */) || includes & 8 /* TypeFlags.Number */ && includes & 256 /* TypeFlags.NumberLiteral */ || @@ -62883,7 +62921,7 @@ var ts; // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] - if (objectType.flags & 3145728 /* TypeFlags.UnionOrIntersection */) { + if (objectType.flags & 1048576 /* TypeFlags.Union */ || objectType.flags & 2097152 /* TypeFlags.Intersection */ && !shouldDeferIndexType(objectType)) { var types = ts.map(objectType.types, function (t) { return getSimplifiedType(getIndexedAccessType(t, indexType), writing); }); return objectType.flags & 2097152 /* TypeFlags.Intersection */ || writing ? getIntersectionType(types) : getUnionType(types); } @@ -65291,7 +65329,7 @@ var ts; if (reduced !== type) { return reduced; } - if (type.flags & 2097152 /* TypeFlags.Intersection */) { + if (type.flags & 2097152 /* TypeFlags.Intersection */ && ts.some(type.types, isEmptyAnonymousObjectType)) { var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); }); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -66462,7 +66500,7 @@ var ts; // create a new chain for the constraint error resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors)) { + if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors, /* headMessage */ undefined, intersectionState)) { return result; } // prefer the shorter chain of the constraint comparison chain, and the direct comparison chain @@ -66554,8 +66592,8 @@ var ts; var skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); var skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); // TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't) - if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false)) { - result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false); + if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { + result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState); if (result) { return result; } @@ -71584,7 +71622,7 @@ var ts; var narrowedPropType = narrowType(propType); return filterType(type, function (t) { var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && areTypesComparable(narrowedPropType, discriminantType); }); } function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) { @@ -71633,7 +71671,7 @@ var ts; } function narrowByInKeyword(type, name, assumeTrue) { if (type.flags & 1048576 /* TypeFlags.Union */ - || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type + || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || ts.isThisTypeParameter(type) || type.flags & 2097152 /* TypeFlags.Intersection */ && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) { return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); }); @@ -71766,14 +71804,18 @@ var ts; assumeTrue = !assumeTrue; } var valueType = getTypeOfExpression(value); - if ((type.flags & 2 /* TypeFlags.Unknown */) && assumeTrue && (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { + if (((type.flags & 2 /* TypeFlags.Unknown */) || isEmptyAnonymousObjectType(type) && !(valueType.flags & 98304 /* TypeFlags.Nullable */)) && + assumeTrue && + (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { if (valueType.flags & (131068 /* TypeFlags.Primitive */ | 67108864 /* TypeFlags.NonPrimitive */)) { return valueType; } if (valueType.flags & 524288 /* TypeFlags.Object */) { return nonPrimitiveType; } - return type; + if (type.flags & 2 /* TypeFlags.Unknown */) { + return type; + } } if (valueType.flags & 98304 /* TypeFlags.Nullable */) { if (!strictNullChecks) { @@ -72232,7 +72274,9 @@ var ts; !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* TypeFlags.Nullable */ | 1048576 /* TypeFlags.Union */)); } function isGenericTypeWithoutNullableConstraint(type) { - return !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); + return type.flags & 2097152 /* TypeFlags.Intersection */ ? + ts.some(type.types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); } function hasContextualTypeWithNoGenericTypes(node, checkMode) { // Computing the contextual type for a child of a JSX element involves resolving the type of the @@ -126929,9 +126973,7 @@ var ts; } } } - var seenRefs = buildInfoPath ? new ts.Set() : undefined; var buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs === null || seenRefs === void 0 ? void 0 : seenRefs.add(resolvedPath); /** Inputs are up-to-date, just need either timestamp update or bundle prepend manipulation to make it look up-to-date */ var pseudoUpToDate = false; var usesPrepend = false; @@ -126946,7 +126988,7 @@ var ts; continue; } // Check if tsbuildinfo path is shared, then we need to rebuild - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: ts.UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath, @@ -127004,25 +127046,9 @@ var ts; oldestOutputFileName: oldestOutputFileName }; } - function hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath) { - if (seenRefs.has(resolvedRefPath)) - return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath) { var refBuildInfo = state.buildInfoCache.get(resolvedRefPath); - if (refBuildInfo.path === buildInfoCacheEntry.path) - return true; - if (resolvedConfig.projectReferences) { - // Check references - for (var _i = 0, _a = resolvedConfig.projectReferences; _i < _a.length; _i++) { - var ref = _a[_i]; - var resolvedRef = ts.resolveProjectReferencePath(ref); - var resolvedRefPath_1 = toResolvedConfigFilePath(state, resolvedRef); - var resolvedConfig_1 = parseConfigFile(state, resolvedRef, resolvedRefPath_1); - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig_1, resolvedRefPath_1)) - return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state, project, resolvedPath) { if (project === undefined) { @@ -171614,13 +171640,13 @@ var ts; return __generator(this, function (_a) { switch (_a.label) { case 0: - ts.Debug.assertIsDefined(host.importServicePlugin); + ts.Debug.assertIsDefined(host.importPlugin); resolvedPath = ts.combinePaths(initialDir, "node_modules"); log("Dynamically importing ".concat(moduleName, " from ").concat(initialDir, " (resolved to ").concat(resolvedPath, ")")); _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, host.importServicePlugin(resolvedPath, moduleName)]; + return [4 /*yield*/, host.importPlugin(resolvedPath, moduleName)]; case 2: result = _a.sent(); return [3 /*break*/, 4]; @@ -172699,7 +172725,7 @@ var ts; }; Project.prototype.enableGlobalPlugins = function (options, pluginConfigOverrides) { var host = this.projectService.host; - if (!host.require && !host.importServicePlugin) { + if (!host.require && !host.importPlugin) { this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -172756,7 +172782,7 @@ var ts; return __generator(this, function (_a) { switch (_a.label) { case 0: - ts.Debug.assertIsDefined(this.projectService.host.importServicePlugin); + ts.Debug.assertIsDefined(this.projectService.host.importPlugin); log = function (message) { return _this.projectService.logger.info(message); }; logError = function (message) { (errorLogs !== null && errorLogs !== void 0 ? errorLogs : (errorLogs = [])).push(message); @@ -173457,7 +173483,7 @@ var ts; /*@internal*/ ConfiguredProject.prototype.enablePluginsWithOptions = function (options, pluginConfigOverrides) { var host = this.projectService.host; - if (!host.require && !host.importServicePlugin) { + if (!host.require && !host.importPlugin) { this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -176901,7 +176927,7 @@ var ts; /*@internal*/ ProjectService.prototype.requestEnablePlugin = function (project, pluginConfigEntry, searchPaths, pluginConfigOverrides) { var _a; - if (!this.host.importServicePlugin && !this.host.require) { + if (!this.host.importPlugin && !this.host.require) { this.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -176911,7 +176937,7 @@ var ts; return; } // If the host supports dynamic import, begin enabling the plugin asynchronously. - if (this.host.importServicePlugin) { + if (this.host.importPlugin) { var importPromise = project.beginEnablePluginAsync(pluginConfigEntry, searchPaths, pluginConfigOverrides); (_a = this.pendingPluginEnablements) !== null && _a !== void 0 ? _a : (this.pendingPluginEnablements = new ts.Map()); var promises = this.pendingPluginEnablements.get(project); @@ -181210,7 +181236,7 @@ var ts; setImmediate: function (x) { return setTimeout(x, 0); }, clearImmediate: function (handle) { return clearTimeout(handle); }, /* eslint-enable no-restricted-globals */ - importServicePlugin: function (initialDir, moduleName) { return __awaiter(_this, void 0, void 0, function () { + importPlugin: function (initialDir, moduleName) { return __awaiter(_this, void 0, void 0, function () { var packageRoot, packageJson, packageJsonResponse, e_1, browser, scriptPath, module_1, e_2; return __generator(this, function (_a) { switch (_a.label) { diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index 4744d065a38ac..8003ac00a3c64 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -7033,7 +7033,6 @@ declare namespace ts.server { gc?(): void; trace?(s: string): void; require?(initialPath: string, moduleName: string): ModuleImportResult; - importServicePlugin?(root: string, moduleName: string): Promise; } } declare namespace ts.server { diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 57276bce88f5a..53b8c929ba8f1 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -303,7 +303,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.8.2"; + ts.version = "4.8.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -9069,7 +9069,7 @@ var ts; Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: diag(2591, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591", "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: diag(2592, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592", "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: diag(2593, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_type_2593", "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig."), - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the__2594", "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag."), + This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag_2594", "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag."), _0_can_only_be_imported_by_using_a_default_import: diag(2595, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_default_import_2595", "'{0}' can only be imported by using a default import."), _0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import: diag(2596, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import_2596", "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import."), _0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import: diag(2597, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import_2597", "'{0}' can only be imported by using a 'require' call or by using a default import."), @@ -44830,7 +44830,7 @@ var ts; var _a, _b; if (path === undefined) return path; - return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a))); + return ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); } function combineDirectoryPath(root, dir) { return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir)); @@ -44850,7 +44850,7 @@ var ts; if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) { + && (state.compilerOptions.configFile ? ts.containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)) { // So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings. // Even with all that, we still don't know if the root of the output file structure will be (relative to the package file) // `.`, `./src` or any other deeper directory structure. (If project references are used, it's definitely `.` by fiat, so that should be pretty common.) @@ -44906,7 +44906,7 @@ var ts; var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) { var candidateDir = candidateDirectories_1[_e]; - if (ts.startsWith(finalPath, candidateDir)) { + if (ts.containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension var pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment); @@ -51188,41 +51188,61 @@ var ts; return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { - var _a; var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - var exportDefaultSymbol = void 0; - if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); - } - var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); - var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); - var exportAssignment = exportEqualsSymbol.valueDeclaration; - var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - if (exportAssignment) { - ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + function getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias) { + var _a; + var exportDefaultSymbol; + if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); + } + var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); + var specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + var hasDefaultOnly = isOnlyImportedAsDefault(specifier); + var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); + var exportAssignment = exportEqualsSymbol.valueDeclaration; + var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + if (exportAssignment) { + ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present - var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); - return resolved; + else if (ts.isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); - return exportDefaultSymbol; + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, ts.isImportOrExportSpecifier(node) && node.propertyName || node.name); + } + } + else if (hasSyntheticDefault || hasDefaultOnly) { + // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present + var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); + return exportDefaultSymbol; + } + function getModuleSpecifierForImportOrExport(node) { + switch (node.kind) { + case 267 /* SyntaxKind.ImportClause */: return node.parent.moduleSpecifier; + case 265 /* SyntaxKind.ImportEqualsDeclaration */: return ts.isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case 268 /* SyntaxKind.NamespaceImport */: return node.parent.parent.moduleSpecifier; + case 270 /* SyntaxKind.ImportSpecifier */: return node.parent.parent.parent.moduleSpecifier; + case 275 /* SyntaxKind.ExportSpecifier */: return node.parent.parent.moduleSpecifier; + default: return ts.Debug.assertNever(node); } } function reportNonDefaultExport(moduleSymbol, node) { @@ -51312,7 +51332,7 @@ var ts; } } function getExternalModuleMember(node, specifier, dontResolveAlias) { - var _a, _b; + var _a; if (dontResolveAlias === void 0) { dontResolveAlias = false; } var moduleSpecifier = ts.getExternalModuleRequireArgument(node) || node.moduleSpecifier; var moduleSymbol = resolveExternalModuleName(node, moduleSpecifier); // TODO: GH#18217 @@ -51348,29 +51368,33 @@ var ts; combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - var moduleName = getFullyQualifiedName(moduleSymbol, node); - var declarationName = ts.declarationNameToString(name); - var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - var suggestionName = symbolToString(suggestion); - var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); - } - } - else { - if ((_b = moduleSymbol.exports) === null || _b === void 0 ? void 0 : _b.has("default" /* InternalSymbolName.Default */)) { - error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } + function errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name) { + var _a; + var moduleName = getFullyQualifiedName(moduleSymbol, node); + var declarationName = ts.declarationNameToString(name); + var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + var suggestionName = symbolToString(suggestion); + var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); + } + } + else { + if ((_a = moduleSymbol.exports) === null || _a === void 0 ? void 0 : _a.has("default" /* InternalSymbolName.Default */)) { + error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } function reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName) { var _a, _b; var localSymbol = (_b = (_a = moduleSymbol.valueDeclaration) === null || _a === void 0 ? void 0 : _a.locals) === null || _b === void 0 ? void 0 : _b.get(name.escapedText); @@ -51416,6 +51440,13 @@ var ts; } } function getTargetOfImportSpecifier(node, dontResolveAlias) { + if (ts.isImportSpecifier(node) && ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } var root = ts.isBindingElement(node) ? ts.getRootDeclaration(node) : node.parent.parent.parent; var commonJSPropertyAccess = getCommonJSPropertyAccess(root); var resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -51437,6 +51468,13 @@ var ts; return resolved; } function getTargetOfExportSpecifier(node, meaning, dontResolveAlias) { + if (ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } var resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); @@ -62387,7 +62425,7 @@ var ts; return includes & 8388608 /* TypeFlags.IncludesWildcard */ ? wildcardType : anyType; } if (!strictNullChecks && includes & 98304 /* TypeFlags.Nullable */) { - return includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; + return includes & 16777216 /* TypeFlags.IncludesEmptyObject */ ? neverType : includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; } if (includes & 4 /* TypeFlags.String */ && includes & (128 /* TypeFlags.StringLiteral */ | 134217728 /* TypeFlags.TemplateLiteral */ | 268435456 /* TypeFlags.StringMapping */) || includes & 8 /* TypeFlags.Number */ && includes & 256 /* TypeFlags.NumberLiteral */ || @@ -63077,7 +63115,7 @@ var ts; // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] - if (objectType.flags & 3145728 /* TypeFlags.UnionOrIntersection */) { + if (objectType.flags & 1048576 /* TypeFlags.Union */ || objectType.flags & 2097152 /* TypeFlags.Intersection */ && !shouldDeferIndexType(objectType)) { var types = ts.map(objectType.types, function (t) { return getSimplifiedType(getIndexedAccessType(t, indexType), writing); }); return objectType.flags & 2097152 /* TypeFlags.Intersection */ || writing ? getIntersectionType(types) : getUnionType(types); } @@ -65485,7 +65523,7 @@ var ts; if (reduced !== type) { return reduced; } - if (type.flags & 2097152 /* TypeFlags.Intersection */) { + if (type.flags & 2097152 /* TypeFlags.Intersection */ && ts.some(type.types, isEmptyAnonymousObjectType)) { var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); }); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -66656,7 +66694,7 @@ var ts; // create a new chain for the constraint error resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors)) { + if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors, /* headMessage */ undefined, intersectionState)) { return result; } // prefer the shorter chain of the constraint comparison chain, and the direct comparison chain @@ -66748,8 +66786,8 @@ var ts; var skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); var skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); // TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't) - if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false)) { - result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false); + if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { + result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState); if (result) { return result; } @@ -71778,7 +71816,7 @@ var ts; var narrowedPropType = narrowType(propType); return filterType(type, function (t) { var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && areTypesComparable(narrowedPropType, discriminantType); }); } function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) { @@ -71827,7 +71865,7 @@ var ts; } function narrowByInKeyword(type, name, assumeTrue) { if (type.flags & 1048576 /* TypeFlags.Union */ - || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type + || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || ts.isThisTypeParameter(type) || type.flags & 2097152 /* TypeFlags.Intersection */ && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) { return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); }); @@ -71960,14 +71998,18 @@ var ts; assumeTrue = !assumeTrue; } var valueType = getTypeOfExpression(value); - if ((type.flags & 2 /* TypeFlags.Unknown */) && assumeTrue && (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { + if (((type.flags & 2 /* TypeFlags.Unknown */) || isEmptyAnonymousObjectType(type) && !(valueType.flags & 98304 /* TypeFlags.Nullable */)) && + assumeTrue && + (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { if (valueType.flags & (131068 /* TypeFlags.Primitive */ | 67108864 /* TypeFlags.NonPrimitive */)) { return valueType; } if (valueType.flags & 524288 /* TypeFlags.Object */) { return nonPrimitiveType; } - return type; + if (type.flags & 2 /* TypeFlags.Unknown */) { + return type; + } } if (valueType.flags & 98304 /* TypeFlags.Nullable */) { if (!strictNullChecks) { @@ -72426,7 +72468,9 @@ var ts; !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* TypeFlags.Nullable */ | 1048576 /* TypeFlags.Union */)); } function isGenericTypeWithoutNullableConstraint(type) { - return !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); + return type.flags & 2097152 /* TypeFlags.Intersection */ ? + ts.some(type.types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); } function hasContextualTypeWithNoGenericTypes(node, checkMode) { // Computing the contextual type for a child of a JSX element involves resolving the type of the @@ -127123,9 +127167,7 @@ var ts; } } } - var seenRefs = buildInfoPath ? new ts.Set() : undefined; var buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs === null || seenRefs === void 0 ? void 0 : seenRefs.add(resolvedPath); /** Inputs are up-to-date, just need either timestamp update or bundle prepend manipulation to make it look up-to-date */ var pseudoUpToDate = false; var usesPrepend = false; @@ -127140,7 +127182,7 @@ var ts; continue; } // Check if tsbuildinfo path is shared, then we need to rebuild - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: ts.UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath, @@ -127198,25 +127240,9 @@ var ts; oldestOutputFileName: oldestOutputFileName }; } - function hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath) { - if (seenRefs.has(resolvedRefPath)) - return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath) { var refBuildInfo = state.buildInfoCache.get(resolvedRefPath); - if (refBuildInfo.path === buildInfoCacheEntry.path) - return true; - if (resolvedConfig.projectReferences) { - // Check references - for (var _i = 0, _a = resolvedConfig.projectReferences; _i < _a.length; _i++) { - var ref = _a[_i]; - var resolvedRef = ts.resolveProjectReferencePath(ref); - var resolvedRefPath_1 = toResolvedConfigFilePath(state, resolvedRef); - var resolvedConfig_1 = parseConfigFile(state, resolvedRef, resolvedRefPath_1); - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig_1, resolvedRefPath_1)) - return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state, project, resolvedPath) { if (project === undefined) { @@ -171808,13 +171834,13 @@ var ts; return __generator(this, function (_a) { switch (_a.label) { case 0: - ts.Debug.assertIsDefined(host.importServicePlugin); + ts.Debug.assertIsDefined(host.importPlugin); resolvedPath = ts.combinePaths(initialDir, "node_modules"); log("Dynamically importing ".concat(moduleName, " from ").concat(initialDir, " (resolved to ").concat(resolvedPath, ")")); _a.label = 1; case 1: _a.trys.push([1, 3, , 4]); - return [4 /*yield*/, host.importServicePlugin(resolvedPath, moduleName)]; + return [4 /*yield*/, host.importPlugin(resolvedPath, moduleName)]; case 2: result = _a.sent(); return [3 /*break*/, 4]; @@ -172893,7 +172919,7 @@ var ts; }; Project.prototype.enableGlobalPlugins = function (options, pluginConfigOverrides) { var host = this.projectService.host; - if (!host.require && !host.importServicePlugin) { + if (!host.require && !host.importPlugin) { this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -172950,7 +172976,7 @@ var ts; return __generator(this, function (_a) { switch (_a.label) { case 0: - ts.Debug.assertIsDefined(this.projectService.host.importServicePlugin); + ts.Debug.assertIsDefined(this.projectService.host.importPlugin); log = function (message) { return _this.projectService.logger.info(message); }; logError = function (message) { (errorLogs !== null && errorLogs !== void 0 ? errorLogs : (errorLogs = [])).push(message); @@ -173651,7 +173677,7 @@ var ts; /*@internal*/ ConfiguredProject.prototype.enablePluginsWithOptions = function (options, pluginConfigOverrides) { var host = this.projectService.host; - if (!host.require && !host.importServicePlugin) { + if (!host.require && !host.importPlugin) { this.projectService.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -177095,7 +177121,7 @@ var ts; /*@internal*/ ProjectService.prototype.requestEnablePlugin = function (project, pluginConfigEntry, searchPaths, pluginConfigOverrides) { var _a; - if (!this.host.importServicePlugin && !this.host.require) { + if (!this.host.importPlugin && !this.host.require) { this.logger.info("Plugins were requested but not running in environment that supports 'require'. Nothing will be loaded"); return; } @@ -177105,7 +177131,7 @@ var ts; return; } // If the host supports dynamic import, begin enabling the plugin asynchronously. - if (this.host.importServicePlugin) { + if (this.host.importPlugin) { var importPromise = project.beginEnablePluginAsync(pluginConfigEntry, searchPaths, pluginConfigOverrides); (_a = this.pendingPluginEnablements) !== null && _a !== void 0 ? _a : (this.pendingPluginEnablements = new ts.Map()); var promises = this.pendingPluginEnablements.get(project); diff --git a/lib/typescript.js b/lib/typescript.js index 49899ec44b380..3c93c04e0e47a 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -294,7 +294,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.8.2"; + ts.version = "4.8.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -9060,7 +9060,7 @@ var ts; Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: diag(2591, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591", "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: diag(2592, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592", "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: diag(2593, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_type_2593", "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig."), - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the__2594", "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag."), + This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag_2594", "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag."), _0_can_only_be_imported_by_using_a_default_import: diag(2595, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_default_import_2595", "'{0}' can only be imported by using a default import."), _0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import: diag(2596, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import_2596", "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import."), _0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import: diag(2597, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import_2597", "'{0}' can only be imported by using a 'require' call or by using a default import."), @@ -44821,7 +44821,7 @@ var ts; var _a, _b; if (path === undefined) return path; - return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a))); + return ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); } function combineDirectoryPath(root, dir) { return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir)); @@ -44841,7 +44841,7 @@ var ts; if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) { + && (state.compilerOptions.configFile ? ts.containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)) { // So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings. // Even with all that, we still don't know if the root of the output file structure will be (relative to the package file) // `.`, `./src` or any other deeper directory structure. (If project references are used, it's definitely `.` by fiat, so that should be pretty common.) @@ -44897,7 +44897,7 @@ var ts; var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) { var candidateDir = candidateDirectories_1[_e]; - if (ts.startsWith(finalPath, candidateDir)) { + if (ts.containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension var pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment); @@ -51179,41 +51179,61 @@ var ts; return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { - var _a; var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - var exportDefaultSymbol = void 0; - if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); - } - var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); - var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); - var exportAssignment = exportEqualsSymbol.valueDeclaration; - var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - if (exportAssignment) { - ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + function getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias) { + var _a; + var exportDefaultSymbol; + if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); + } + var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); + var specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + var hasDefaultOnly = isOnlyImportedAsDefault(specifier); + var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); + var exportAssignment = exportEqualsSymbol.valueDeclaration; + var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + if (exportAssignment) { + ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present - var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); - return resolved; + else if (ts.isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); - return exportDefaultSymbol; + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, ts.isImportOrExportSpecifier(node) && node.propertyName || node.name); + } + } + else if (hasSyntheticDefault || hasDefaultOnly) { + // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present + var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); + return exportDefaultSymbol; + } + function getModuleSpecifierForImportOrExport(node) { + switch (node.kind) { + case 267 /* SyntaxKind.ImportClause */: return node.parent.moduleSpecifier; + case 265 /* SyntaxKind.ImportEqualsDeclaration */: return ts.isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case 268 /* SyntaxKind.NamespaceImport */: return node.parent.parent.moduleSpecifier; + case 270 /* SyntaxKind.ImportSpecifier */: return node.parent.parent.parent.moduleSpecifier; + case 275 /* SyntaxKind.ExportSpecifier */: return node.parent.parent.moduleSpecifier; + default: return ts.Debug.assertNever(node); } } function reportNonDefaultExport(moduleSymbol, node) { @@ -51303,7 +51323,7 @@ var ts; } } function getExternalModuleMember(node, specifier, dontResolveAlias) { - var _a, _b; + var _a; if (dontResolveAlias === void 0) { dontResolveAlias = false; } var moduleSpecifier = ts.getExternalModuleRequireArgument(node) || node.moduleSpecifier; var moduleSymbol = resolveExternalModuleName(node, moduleSpecifier); // TODO: GH#18217 @@ -51339,29 +51359,33 @@ var ts; combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - var moduleName = getFullyQualifiedName(moduleSymbol, node); - var declarationName = ts.declarationNameToString(name); - var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - var suggestionName = symbolToString(suggestion); - var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); - } - } - else { - if ((_b = moduleSymbol.exports) === null || _b === void 0 ? void 0 : _b.has("default" /* InternalSymbolName.Default */)) { - error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } + function errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name) { + var _a; + var moduleName = getFullyQualifiedName(moduleSymbol, node); + var declarationName = ts.declarationNameToString(name); + var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + var suggestionName = symbolToString(suggestion); + var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); + } + } + else { + if ((_a = moduleSymbol.exports) === null || _a === void 0 ? void 0 : _a.has("default" /* InternalSymbolName.Default */)) { + error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } function reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName) { var _a, _b; var localSymbol = (_b = (_a = moduleSymbol.valueDeclaration) === null || _a === void 0 ? void 0 : _a.locals) === null || _b === void 0 ? void 0 : _b.get(name.escapedText); @@ -51407,6 +51431,13 @@ var ts; } } function getTargetOfImportSpecifier(node, dontResolveAlias) { + if (ts.isImportSpecifier(node) && ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } var root = ts.isBindingElement(node) ? ts.getRootDeclaration(node) : node.parent.parent.parent; var commonJSPropertyAccess = getCommonJSPropertyAccess(root); var resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -51428,6 +51459,13 @@ var ts; return resolved; } function getTargetOfExportSpecifier(node, meaning, dontResolveAlias) { + if (ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } var resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); @@ -62378,7 +62416,7 @@ var ts; return includes & 8388608 /* TypeFlags.IncludesWildcard */ ? wildcardType : anyType; } if (!strictNullChecks && includes & 98304 /* TypeFlags.Nullable */) { - return includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; + return includes & 16777216 /* TypeFlags.IncludesEmptyObject */ ? neverType : includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; } if (includes & 4 /* TypeFlags.String */ && includes & (128 /* TypeFlags.StringLiteral */ | 134217728 /* TypeFlags.TemplateLiteral */ | 268435456 /* TypeFlags.StringMapping */) || includes & 8 /* TypeFlags.Number */ && includes & 256 /* TypeFlags.NumberLiteral */ || @@ -63068,7 +63106,7 @@ var ts; // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] - if (objectType.flags & 3145728 /* TypeFlags.UnionOrIntersection */) { + if (objectType.flags & 1048576 /* TypeFlags.Union */ || objectType.flags & 2097152 /* TypeFlags.Intersection */ && !shouldDeferIndexType(objectType)) { var types = ts.map(objectType.types, function (t) { return getSimplifiedType(getIndexedAccessType(t, indexType), writing); }); return objectType.flags & 2097152 /* TypeFlags.Intersection */ || writing ? getIntersectionType(types) : getUnionType(types); } @@ -65476,7 +65514,7 @@ var ts; if (reduced !== type) { return reduced; } - if (type.flags & 2097152 /* TypeFlags.Intersection */) { + if (type.flags & 2097152 /* TypeFlags.Intersection */ && ts.some(type.types, isEmptyAnonymousObjectType)) { var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); }); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -66647,7 +66685,7 @@ var ts; // create a new chain for the constraint error resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors)) { + if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors, /* headMessage */ undefined, intersectionState)) { return result; } // prefer the shorter chain of the constraint comparison chain, and the direct comparison chain @@ -66739,8 +66777,8 @@ var ts; var skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); var skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); // TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't) - if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false)) { - result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false); + if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { + result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState); if (result) { return result; } @@ -71769,7 +71807,7 @@ var ts; var narrowedPropType = narrowType(propType); return filterType(type, function (t) { var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && areTypesComparable(narrowedPropType, discriminantType); }); } function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) { @@ -71818,7 +71856,7 @@ var ts; } function narrowByInKeyword(type, name, assumeTrue) { if (type.flags & 1048576 /* TypeFlags.Union */ - || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type + || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || ts.isThisTypeParameter(type) || type.flags & 2097152 /* TypeFlags.Intersection */ && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) { return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); }); @@ -71951,14 +71989,18 @@ var ts; assumeTrue = !assumeTrue; } var valueType = getTypeOfExpression(value); - if ((type.flags & 2 /* TypeFlags.Unknown */) && assumeTrue && (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { + if (((type.flags & 2 /* TypeFlags.Unknown */) || isEmptyAnonymousObjectType(type) && !(valueType.flags & 98304 /* TypeFlags.Nullable */)) && + assumeTrue && + (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { if (valueType.flags & (131068 /* TypeFlags.Primitive */ | 67108864 /* TypeFlags.NonPrimitive */)) { return valueType; } if (valueType.flags & 524288 /* TypeFlags.Object */) { return nonPrimitiveType; } - return type; + if (type.flags & 2 /* TypeFlags.Unknown */) { + return type; + } } if (valueType.flags & 98304 /* TypeFlags.Nullable */) { if (!strictNullChecks) { @@ -72417,7 +72459,9 @@ var ts; !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* TypeFlags.Nullable */ | 1048576 /* TypeFlags.Union */)); } function isGenericTypeWithoutNullableConstraint(type) { - return !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); + return type.flags & 2097152 /* TypeFlags.Intersection */ ? + ts.some(type.types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); } function hasContextualTypeWithNoGenericTypes(node, checkMode) { // Computing the contextual type for a child of a JSX element involves resolving the type of the @@ -127114,9 +127158,7 @@ var ts; } } } - var seenRefs = buildInfoPath ? new ts.Set() : undefined; var buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs === null || seenRefs === void 0 ? void 0 : seenRefs.add(resolvedPath); /** Inputs are up-to-date, just need either timestamp update or bundle prepend manipulation to make it look up-to-date */ var pseudoUpToDate = false; var usesPrepend = false; @@ -127131,7 +127173,7 @@ var ts; continue; } // Check if tsbuildinfo path is shared, then we need to rebuild - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: ts.UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath, @@ -127189,25 +127231,9 @@ var ts; oldestOutputFileName: oldestOutputFileName }; } - function hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath) { - if (seenRefs.has(resolvedRefPath)) - return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath) { var refBuildInfo = state.buildInfoCache.get(resolvedRefPath); - if (refBuildInfo.path === buildInfoCacheEntry.path) - return true; - if (resolvedConfig.projectReferences) { - // Check references - for (var _i = 0, _a = resolvedConfig.projectReferences; _i < _a.length; _i++) { - var ref = _a[_i]; - var resolvedRef = ts.resolveProjectReferencePath(ref); - var resolvedRefPath_1 = toResolvedConfigFilePath(state, resolvedRef); - var resolvedConfig_1 = parseConfigFile(state, resolvedRef, resolvedRefPath_1); - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig_1, resolvedRefPath_1)) - return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state, project, resolvedPath) { if (project === undefined) { diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 9e45164b7c4c9..61b1259b561f8 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -294,7 +294,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.8.2"; + ts.version = "4.8.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -9060,7 +9060,7 @@ var ts; Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: diag(2591, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591", "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: diag(2592, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592", "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: diag(2593, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_type_2593", "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig."), - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the__2594", "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag."), + This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag_2594", "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag."), _0_can_only_be_imported_by_using_a_default_import: diag(2595, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_default_import_2595", "'{0}' can only be imported by using a default import."), _0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import: diag(2596, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import_2596", "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import."), _0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import: diag(2597, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import_2597", "'{0}' can only be imported by using a 'require' call or by using a default import."), @@ -44821,7 +44821,7 @@ var ts; var _a, _b; if (path === undefined) return path; - return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a))); + return ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); } function combineDirectoryPath(root, dir) { return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir)); @@ -44841,7 +44841,7 @@ var ts; if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) { + && (state.compilerOptions.configFile ? ts.containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)) { // So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings. // Even with all that, we still don't know if the root of the output file structure will be (relative to the package file) // `.`, `./src` or any other deeper directory structure. (If project references are used, it's definitely `.` by fiat, so that should be pretty common.) @@ -44897,7 +44897,7 @@ var ts; var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) { var candidateDir = candidateDirectories_1[_e]; - if (ts.startsWith(finalPath, candidateDir)) { + if (ts.containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension var pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment); @@ -51179,41 +51179,61 @@ var ts; return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { - var _a; var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - var exportDefaultSymbol = void 0; - if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); - } - var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); - var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); - var exportAssignment = exportEqualsSymbol.valueDeclaration; - var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - if (exportAssignment) { - ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + function getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias) { + var _a; + var exportDefaultSymbol; + if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); + } + var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); + var specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + var hasDefaultOnly = isOnlyImportedAsDefault(specifier); + var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); + var exportAssignment = exportEqualsSymbol.valueDeclaration; + var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + if (exportAssignment) { + ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present - var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); - return resolved; + else if (ts.isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); - return exportDefaultSymbol; + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, ts.isImportOrExportSpecifier(node) && node.propertyName || node.name); + } + } + else if (hasSyntheticDefault || hasDefaultOnly) { + // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present + var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); + return exportDefaultSymbol; + } + function getModuleSpecifierForImportOrExport(node) { + switch (node.kind) { + case 267 /* SyntaxKind.ImportClause */: return node.parent.moduleSpecifier; + case 265 /* SyntaxKind.ImportEqualsDeclaration */: return ts.isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case 268 /* SyntaxKind.NamespaceImport */: return node.parent.parent.moduleSpecifier; + case 270 /* SyntaxKind.ImportSpecifier */: return node.parent.parent.parent.moduleSpecifier; + case 275 /* SyntaxKind.ExportSpecifier */: return node.parent.parent.moduleSpecifier; + default: return ts.Debug.assertNever(node); } } function reportNonDefaultExport(moduleSymbol, node) { @@ -51303,7 +51323,7 @@ var ts; } } function getExternalModuleMember(node, specifier, dontResolveAlias) { - var _a, _b; + var _a; if (dontResolveAlias === void 0) { dontResolveAlias = false; } var moduleSpecifier = ts.getExternalModuleRequireArgument(node) || node.moduleSpecifier; var moduleSymbol = resolveExternalModuleName(node, moduleSpecifier); // TODO: GH#18217 @@ -51339,29 +51359,33 @@ var ts; combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - var moduleName = getFullyQualifiedName(moduleSymbol, node); - var declarationName = ts.declarationNameToString(name); - var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - var suggestionName = symbolToString(suggestion); - var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); - } - } - else { - if ((_b = moduleSymbol.exports) === null || _b === void 0 ? void 0 : _b.has("default" /* InternalSymbolName.Default */)) { - error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } + function errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name) { + var _a; + var moduleName = getFullyQualifiedName(moduleSymbol, node); + var declarationName = ts.declarationNameToString(name); + var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + var suggestionName = symbolToString(suggestion); + var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); + } + } + else { + if ((_a = moduleSymbol.exports) === null || _a === void 0 ? void 0 : _a.has("default" /* InternalSymbolName.Default */)) { + error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } function reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName) { var _a, _b; var localSymbol = (_b = (_a = moduleSymbol.valueDeclaration) === null || _a === void 0 ? void 0 : _a.locals) === null || _b === void 0 ? void 0 : _b.get(name.escapedText); @@ -51407,6 +51431,13 @@ var ts; } } function getTargetOfImportSpecifier(node, dontResolveAlias) { + if (ts.isImportSpecifier(node) && ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } var root = ts.isBindingElement(node) ? ts.getRootDeclaration(node) : node.parent.parent.parent; var commonJSPropertyAccess = getCommonJSPropertyAccess(root); var resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -51428,6 +51459,13 @@ var ts; return resolved; } function getTargetOfExportSpecifier(node, meaning, dontResolveAlias) { + if (ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } var resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); @@ -62378,7 +62416,7 @@ var ts; return includes & 8388608 /* TypeFlags.IncludesWildcard */ ? wildcardType : anyType; } if (!strictNullChecks && includes & 98304 /* TypeFlags.Nullable */) { - return includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; + return includes & 16777216 /* TypeFlags.IncludesEmptyObject */ ? neverType : includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; } if (includes & 4 /* TypeFlags.String */ && includes & (128 /* TypeFlags.StringLiteral */ | 134217728 /* TypeFlags.TemplateLiteral */ | 268435456 /* TypeFlags.StringMapping */) || includes & 8 /* TypeFlags.Number */ && includes & 256 /* TypeFlags.NumberLiteral */ || @@ -63068,7 +63106,7 @@ var ts; // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] - if (objectType.flags & 3145728 /* TypeFlags.UnionOrIntersection */) { + if (objectType.flags & 1048576 /* TypeFlags.Union */ || objectType.flags & 2097152 /* TypeFlags.Intersection */ && !shouldDeferIndexType(objectType)) { var types = ts.map(objectType.types, function (t) { return getSimplifiedType(getIndexedAccessType(t, indexType), writing); }); return objectType.flags & 2097152 /* TypeFlags.Intersection */ || writing ? getIntersectionType(types) : getUnionType(types); } @@ -65476,7 +65514,7 @@ var ts; if (reduced !== type) { return reduced; } - if (type.flags & 2097152 /* TypeFlags.Intersection */) { + if (type.flags & 2097152 /* TypeFlags.Intersection */ && ts.some(type.types, isEmptyAnonymousObjectType)) { var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); }); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -66647,7 +66685,7 @@ var ts; // create a new chain for the constraint error resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors)) { + if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors, /* headMessage */ undefined, intersectionState)) { return result; } // prefer the shorter chain of the constraint comparison chain, and the direct comparison chain @@ -66739,8 +66777,8 @@ var ts; var skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); var skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); // TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't) - if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false)) { - result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false); + if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { + result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState); if (result) { return result; } @@ -71769,7 +71807,7 @@ var ts; var narrowedPropType = narrowType(propType); return filterType(type, function (t) { var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && areTypesComparable(narrowedPropType, discriminantType); }); } function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) { @@ -71818,7 +71856,7 @@ var ts; } function narrowByInKeyword(type, name, assumeTrue) { if (type.flags & 1048576 /* TypeFlags.Union */ - || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type + || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || ts.isThisTypeParameter(type) || type.flags & 2097152 /* TypeFlags.Intersection */ && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) { return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); }); @@ -71951,14 +71989,18 @@ var ts; assumeTrue = !assumeTrue; } var valueType = getTypeOfExpression(value); - if ((type.flags & 2 /* TypeFlags.Unknown */) && assumeTrue && (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { + if (((type.flags & 2 /* TypeFlags.Unknown */) || isEmptyAnonymousObjectType(type) && !(valueType.flags & 98304 /* TypeFlags.Nullable */)) && + assumeTrue && + (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { if (valueType.flags & (131068 /* TypeFlags.Primitive */ | 67108864 /* TypeFlags.NonPrimitive */)) { return valueType; } if (valueType.flags & 524288 /* TypeFlags.Object */) { return nonPrimitiveType; } - return type; + if (type.flags & 2 /* TypeFlags.Unknown */) { + return type; + } } if (valueType.flags & 98304 /* TypeFlags.Nullable */) { if (!strictNullChecks) { @@ -72417,7 +72459,9 @@ var ts; !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* TypeFlags.Nullable */ | 1048576 /* TypeFlags.Union */)); } function isGenericTypeWithoutNullableConstraint(type) { - return !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); + return type.flags & 2097152 /* TypeFlags.Intersection */ ? + ts.some(type.types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); } function hasContextualTypeWithNoGenericTypes(node, checkMode) { // Computing the contextual type for a child of a JSX element involves resolving the type of the @@ -127114,9 +127158,7 @@ var ts; } } } - var seenRefs = buildInfoPath ? new ts.Set() : undefined; var buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs === null || seenRefs === void 0 ? void 0 : seenRefs.add(resolvedPath); /** Inputs are up-to-date, just need either timestamp update or bundle prepend manipulation to make it look up-to-date */ var pseudoUpToDate = false; var usesPrepend = false; @@ -127131,7 +127173,7 @@ var ts; continue; } // Check if tsbuildinfo path is shared, then we need to rebuild - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: ts.UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath, @@ -127189,25 +127231,9 @@ var ts; oldestOutputFileName: oldestOutputFileName }; } - function hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath) { - if (seenRefs.has(resolvedRefPath)) - return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath) { var refBuildInfo = state.buildInfoCache.get(resolvedRefPath); - if (refBuildInfo.path === buildInfoCacheEntry.path) - return true; - if (resolvedConfig.projectReferences) { - // Check references - for (var _i = 0, _a = resolvedConfig.projectReferences; _i < _a.length; _i++) { - var ref = _a[_i]; - var resolvedRef = ts.resolveProjectReferencePath(ref); - var resolvedRefPath_1 = toResolvedConfigFilePath(state, resolvedRef); - var resolvedConfig_1 = parseConfigFile(state, resolvedRef, resolvedRefPath_1); - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig_1, resolvedRefPath_1)) - return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state, project, resolvedPath) { if (project === undefined) { diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 8ab14c8266cf2..9303e787c1ef4 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -89,7 +89,7 @@ var ts; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ // eslint-disable-next-line @typescript-eslint/no-inferrable-types - ts.version = "4.8.2"; + ts.version = "4.8.3"; /* @internal */ var Comparison; (function (Comparison) { @@ -8855,7 +8855,7 @@ var ts; Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashnode_and_then_add_node_to_the_types_field_in_your_tsconfig: diag(2591, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_node_Try_npm_i_save_dev_types_Slashno_2591", "Cannot find name '{0}'. Do you need to install type definitions for node? Try `npm i --save-dev @types/node` and then add 'node' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slashjquery_and_then_add_jquery_to_the_types_field_in_your_tsconfig: diag(2592, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_jQuery_Try_npm_i_save_dev_types_Slash_2592", "Cannot find name '{0}'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig."), Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_types_Slashjest_or_npm_i_save_dev_types_Slashmocha_and_then_add_jest_or_mocha_to_the_types_field_in_your_tsconfig: diag(2593, ts.DiagnosticCategory.Error, "Cannot_find_name_0_Do_you_need_to_install_type_definitions_for_a_test_runner_Try_npm_i_save_dev_type_2593", "Cannot find name '{0}'. Do you need to install type definitions for a test runner? Try `npm i --save-dev @types/jest` or `npm i --save-dev @types/mocha` and then add 'jest' or 'mocha' to the types field in your tsconfig."), - This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the__2594", "This module is declared with using 'export =', and can only be used with a default import when using the '{0}' flag."), + This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag: diag(2594, ts.DiagnosticCategory.Error, "This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag_2594", "This module is declared with 'export =', and can only be used with a default import when using the '{0}' flag."), _0_can_only_be_imported_by_using_a_default_import: diag(2595, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_default_import_2595", "'{0}' can only be imported by using a default import."), _0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import: diag(2596, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_turning_on_the_esModuleInterop_flag_and_using_a_default_import_2596", "'{0}' can only be imported by turning on the 'esModuleInterop' flag and using a default import."), _0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import: diag(2597, ts.DiagnosticCategory.Error, "_0_can_only_be_imported_by_using_a_require_call_or_by_using_a_default_import_2597", "'{0}' can only be imported by using a 'require' call or by using a default import."), @@ -44616,7 +44616,7 @@ var ts; var _a, _b; if (path === undefined) return path; - return ts.hostGetCanonicalFileName({ useCaseSensitiveFileNames: useCaseSensitiveFileNames })(ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a))); + return ts.getNormalizedAbsolutePath(path, (_b = (_a = state.host).getCurrentDirectory) === null || _b === void 0 ? void 0 : _b.call(_a)); } function combineDirectoryPath(root, dir) { return ts.ensureTrailingDirectorySeparator(ts.combinePaths(root, dir)); @@ -44636,7 +44636,7 @@ var ts; if ((extensions === Extensions.TypeScript || extensions === Extensions.JavaScript || extensions === Extensions.Json) && (state.compilerOptions.declarationDir || state.compilerOptions.outDir) && finalPath.indexOf("/node_modules/") === -1 - && (state.compilerOptions.configFile ? ts.startsWith(toAbsolutePath(state.compilerOptions.configFile.fileName), scope.packageDirectory) : true)) { + && (state.compilerOptions.configFile ? ts.containsPath(scope.packageDirectory, toAbsolutePath(state.compilerOptions.configFile.fileName), !useCaseSensitiveFileNames()) : true)) { // So that all means we'll only try these guesses for files outside `node_modules` in a directory where the `package.json` and `tsconfig.json` are siblings. // Even with all that, we still don't know if the root of the output file structure will be (relative to the package file) // `.`, `./src` or any other deeper directory structure. (If project references are used, it's definitely `.` by fiat, so that should be pretty common.) @@ -44692,7 +44692,7 @@ var ts; var candidateDirectories = getOutputDirectoriesForBaseDirectory(commonSourceDirGuess); for (var _e = 0, candidateDirectories_1 = candidateDirectories; _e < candidateDirectories_1.length; _e++) { var candidateDir = candidateDirectories_1[_e]; - if (ts.startsWith(finalPath, candidateDir)) { + if (ts.containsPath(candidateDir, finalPath, !useCaseSensitiveFileNames())) { // The matched export is looking up something in either the out declaration or js dir, now map the written path back into the source dir and source extension var pathFragment = finalPath.slice(candidateDir.length + 1); // +1 to also remove directory seperator var possibleInputBase = ts.combinePaths(commonSourceDirGuess, pathFragment); @@ -50974,41 +50974,61 @@ var ts; return typeof file.externalModuleIndicator !== "object" && !resolveExportByName(moduleSymbol, ts.escapeLeadingUnderscores("__esModule"), /*sourceNode*/ undefined, dontResolveAlias); } function getTargetOfImportClause(node, dontResolveAlias) { - var _a; var moduleSymbol = resolveExternalModuleName(node, node.parent.moduleSpecifier); if (moduleSymbol) { - var exportDefaultSymbol = void 0; - if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { - exportDefaultSymbol = moduleSymbol; - } - else { - exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); - } - var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); - var hasDefaultOnly = isOnlyImportedAsDefault(node.parent.moduleSpecifier); - var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier); - if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { - if (hasExportAssignmentSymbol(moduleSymbol)) { - var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; - var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); - var exportAssignment = exportEqualsSymbol.valueDeclaration; - var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); - if (exportAssignment) { - ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_using_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); - } - } - else { - reportNonDefaultExport(moduleSymbol, node); + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } + function getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias) { + var _a; + var exportDefaultSymbol; + if (ts.isShorthandAmbientModuleSymbol(moduleSymbol)) { + exportDefaultSymbol = moduleSymbol; + } + else { + exportDefaultSymbol = resolveExportByName(moduleSymbol, "default" /* InternalSymbolName.Default */, node, dontResolveAlias); + } + var file = (_a = moduleSymbol.declarations) === null || _a === void 0 ? void 0 : _a.find(ts.isSourceFile); + var specifier = getModuleSpecifierForImportOrExport(node); + if (!specifier) { + return exportDefaultSymbol; + } + var hasDefaultOnly = isOnlyImportedAsDefault(specifier); + var hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); + if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { + if (hasExportAssignmentSymbol(moduleSymbol)) { + var compilerOptionName = moduleKind >= ts.ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop"; + var exportEqualsSymbol = moduleSymbol.exports.get("export=" /* InternalSymbolName.ExportEquals */); + var exportAssignment = exportEqualsSymbol.valueDeclaration; + var err = error(node.name, ts.Diagnostics.Module_0_can_only_be_default_imported_using_the_1_flag, symbolToString(moduleSymbol), compilerOptionName); + if (exportAssignment) { + ts.addRelatedInfo(err, ts.createDiagnosticForNode(exportAssignment, ts.Diagnostics.This_module_is_declared_with_export_and_can_only_be_used_with_a_default_import_when_using_the_0_flag, compilerOptionName)); } } - else if (hasSyntheticDefault || hasDefaultOnly) { - // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present - var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); - markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); - return resolved; + else if (ts.isImportClause(node)) { + reportNonDefaultExport(moduleSymbol, node); + } + else { + errorNoModuleMemberSymbol(moduleSymbol, moduleSymbol, node, ts.isImportOrExportSpecifier(node) && node.propertyName || node.name); } - markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); - return exportDefaultSymbol; + } + else if (hasSyntheticDefault || hasDefaultOnly) { + // per emit behavior, a synthetic default overrides a "real" .default member if `__esModule` is not present + var resolved = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); + markSymbolOfAliasDeclarationIfTypeOnly(node, moduleSymbol, resolved, /*overwriteTypeOnly*/ false); + return resolved; + } + markSymbolOfAliasDeclarationIfTypeOnly(node, exportDefaultSymbol, /*finalTarget*/ undefined, /*overwriteTypeOnly*/ false); + return exportDefaultSymbol; + } + function getModuleSpecifierForImportOrExport(node) { + switch (node.kind) { + case 267 /* SyntaxKind.ImportClause */: return node.parent.moduleSpecifier; + case 265 /* SyntaxKind.ImportEqualsDeclaration */: return ts.isExternalModuleReference(node.moduleReference) ? node.moduleReference.expression : undefined; + case 268 /* SyntaxKind.NamespaceImport */: return node.parent.parent.moduleSpecifier; + case 270 /* SyntaxKind.ImportSpecifier */: return node.parent.parent.parent.moduleSpecifier; + case 275 /* SyntaxKind.ExportSpecifier */: return node.parent.parent.moduleSpecifier; + default: return ts.Debug.assertNever(node); } } function reportNonDefaultExport(moduleSymbol, node) { @@ -51098,7 +51118,7 @@ var ts; } } function getExternalModuleMember(node, specifier, dontResolveAlias) { - var _a, _b; + var _a; if (dontResolveAlias === void 0) { dontResolveAlias = false; } var moduleSpecifier = ts.getExternalModuleRequireArgument(node) || node.moduleSpecifier; var moduleSymbol = resolveExternalModuleName(node, moduleSpecifier); // TODO: GH#18217 @@ -51134,29 +51154,33 @@ var ts; combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - var moduleName = getFullyQualifiedName(moduleSymbol, node); - var declarationName = ts.declarationNameToString(name); - var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); - if (suggestion !== undefined) { - var suggestionName = symbolToString(suggestion); - var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); - if (suggestion.valueDeclaration) { - ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); - } - } - else { - if ((_b = moduleSymbol.exports) === null || _b === void 0 ? void 0 : _b.has("default" /* InternalSymbolName.Default */)) { - error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); - } - else { - reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); - } - } + errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name); } return symbol; } } } + function errorNoModuleMemberSymbol(moduleSymbol, targetSymbol, node, name) { + var _a; + var moduleName = getFullyQualifiedName(moduleSymbol, node); + var declarationName = ts.declarationNameToString(name); + var suggestion = getSuggestedSymbolForNonexistentModule(name, targetSymbol); + if (suggestion !== undefined) { + var suggestionName = symbolToString(suggestion); + var diagnostic = error(name, ts.Diagnostics._0_has_no_exported_member_named_1_Did_you_mean_2, moduleName, declarationName, suggestionName); + if (suggestion.valueDeclaration) { + ts.addRelatedInfo(diagnostic, ts.createDiagnosticForNode(suggestion.valueDeclaration, ts.Diagnostics._0_is_declared_here, suggestionName)); + } + } + else { + if ((_a = moduleSymbol.exports) === null || _a === void 0 ? void 0 : _a.has("default" /* InternalSymbolName.Default */)) { + error(name, ts.Diagnostics.Module_0_has_no_exported_member_1_Did_you_mean_to_use_import_1_from_0_instead, moduleName, declarationName); + } + else { + reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName); + } + } + } function reportNonExportedMember(node, name, declarationName, moduleSymbol, moduleName) { var _a, _b; var localSymbol = (_b = (_a = moduleSymbol.valueDeclaration) === null || _a === void 0 ? void 0 : _a.locals) === null || _b === void 0 ? void 0 : _b.get(name.escapedText); @@ -51202,6 +51226,13 @@ var ts; } } function getTargetOfImportSpecifier(node, dontResolveAlias) { + if (ts.isImportSpecifier(node) && ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, dontResolveAlias); + } + } var root = ts.isBindingElement(node) ? ts.getRootDeclaration(node) : node.parent.parent.parent; var commonJSPropertyAccess = getCommonJSPropertyAccess(root); var resolved = getExternalModuleMember(root, commonJSPropertyAccess || node, dontResolveAlias); @@ -51223,6 +51254,13 @@ var ts; return resolved; } function getTargetOfExportSpecifier(node, meaning, dontResolveAlias) { + if (ts.idText(node.propertyName || node.name) === "default" /* InternalSymbolName.Default */) { + var specifier = getModuleSpecifierForImportOrExport(node); + var moduleSymbol = specifier && resolveExternalModuleName(node, specifier); + if (moduleSymbol) { + return getTargetofModuleDefault(moduleSymbol, node, !!dontResolveAlias); + } + } var resolved = node.parent.parent.moduleSpecifier ? getExternalModuleMember(node.parent.parent, node, dontResolveAlias) : resolveEntityName(node.propertyName || node.name, meaning, /*ignoreErrors*/ false, dontResolveAlias); @@ -62173,7 +62211,7 @@ var ts; return includes & 8388608 /* TypeFlags.IncludesWildcard */ ? wildcardType : anyType; } if (!strictNullChecks && includes & 98304 /* TypeFlags.Nullable */) { - return includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; + return includes & 16777216 /* TypeFlags.IncludesEmptyObject */ ? neverType : includes & 32768 /* TypeFlags.Undefined */ ? undefinedType : nullType; } if (includes & 4 /* TypeFlags.String */ && includes & (128 /* TypeFlags.StringLiteral */ | 134217728 /* TypeFlags.TemplateLiteral */ | 268435456 /* TypeFlags.StringMapping */) || includes & 8 /* TypeFlags.Number */ && includes & 256 /* TypeFlags.NumberLiteral */ || @@ -62863,7 +62901,7 @@ var ts; // (T | U)[K] -> T[K] | U[K] (reading) // (T | U)[K] -> T[K] & U[K] (writing) // (T & U)[K] -> T[K] & U[K] - if (objectType.flags & 3145728 /* TypeFlags.UnionOrIntersection */) { + if (objectType.flags & 1048576 /* TypeFlags.Union */ || objectType.flags & 2097152 /* TypeFlags.Intersection */ && !shouldDeferIndexType(objectType)) { var types = ts.map(objectType.types, function (t) { return getSimplifiedType(getIndexedAccessType(t, indexType), writing); }); return objectType.flags & 2097152 /* TypeFlags.Intersection */ || writing ? getIntersectionType(types) : getUnionType(types); } @@ -65271,7 +65309,7 @@ var ts; if (reduced !== type) { return reduced; } - if (type.flags & 2097152 /* TypeFlags.Intersection */) { + if (type.flags & 2097152 /* TypeFlags.Intersection */ && ts.some(type.types, isEmptyAnonymousObjectType)) { var normalizedTypes = ts.sameMap(type.types, function (t) { return getNormalizedType(t, writing); }); if (normalizedTypes !== type.types) { return getIntersectionType(normalizedTypes); @@ -66442,7 +66480,7 @@ var ts; // create a new chain for the constraint error resetErrorInfo(saveErrorInfo); } - if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors)) { + if (result = isRelatedTo(source, constraint, 2 /* RecursionFlags.Target */, reportErrors, /* headMessage */ undefined, intersectionState)) { return result; } // prefer the shorter chain of the constraint comparison chain, and the direct comparison chain @@ -66534,8 +66572,8 @@ var ts; var skipTrue = !isTypeAssignableTo(getPermissiveInstantiation(c.checkType), getPermissiveInstantiation(c.extendsType)); var skipFalse = !skipTrue && isTypeAssignableTo(getRestrictiveInstantiation(c.checkType), getRestrictiveInstantiation(c.extendsType)); // TODO: Find a nice way to include potential conditional type breakdowns in error output, if they seem good (they usually don't) - if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false)) { - result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false); + if (result = skipTrue ? -1 /* Ternary.True */ : isRelatedTo(source, getTrueTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState)) { + result &= skipFalse ? -1 /* Ternary.True */ : isRelatedTo(source, getFalseTypeFromConditionalType(c), 2 /* RecursionFlags.Target */, /*reportErrors*/ false, /*headMessage*/ undefined, intersectionState); if (result) { return result; } @@ -71564,7 +71602,7 @@ var ts; var narrowedPropType = narrowType(propType); return filterType(type, function (t) { var discriminantType = getTypeOfPropertyOrIndexSignature(t, propName); - return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && isTypeComparableTo(narrowedPropType, discriminantType); + return !(narrowedPropType.flags & 131072 /* TypeFlags.Never */) && areTypesComparable(narrowedPropType, discriminantType); }); } function narrowTypeByDiscriminantProperty(type, access, operator, value, assumeTrue) { @@ -71613,7 +71651,7 @@ var ts; } function narrowByInKeyword(type, name, assumeTrue) { if (type.flags & 1048576 /* TypeFlags.Union */ - || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type + || type.flags & 524288 /* TypeFlags.Object */ && declaredType !== type && !(declaredType === unknownType && isEmptyAnonymousObjectType(type)) || ts.isThisTypeParameter(type) || type.flags & 2097152 /* TypeFlags.Intersection */ && ts.every(type.types, function (t) { return t.symbol !== globalThisSymbol; })) { return filterType(type, function (t) { return isTypePresencePossible(t, name, assumeTrue); }); @@ -71746,14 +71784,18 @@ var ts; assumeTrue = !assumeTrue; } var valueType = getTypeOfExpression(value); - if ((type.flags & 2 /* TypeFlags.Unknown */) && assumeTrue && (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { + if (((type.flags & 2 /* TypeFlags.Unknown */) || isEmptyAnonymousObjectType(type) && !(valueType.flags & 98304 /* TypeFlags.Nullable */)) && + assumeTrue && + (operator === 36 /* SyntaxKind.EqualsEqualsEqualsToken */ || operator === 37 /* SyntaxKind.ExclamationEqualsEqualsToken */)) { if (valueType.flags & (131068 /* TypeFlags.Primitive */ | 67108864 /* TypeFlags.NonPrimitive */)) { return valueType; } if (valueType.flags & 524288 /* TypeFlags.Object */) { return nonPrimitiveType; } - return type; + if (type.flags & 2 /* TypeFlags.Unknown */) { + return type; + } } if (valueType.flags & 98304 /* TypeFlags.Nullable */) { if (!strictNullChecks) { @@ -72212,7 +72254,9 @@ var ts; !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && getBaseConstraintOrType(type).flags & (98304 /* TypeFlags.Nullable */ | 1048576 /* TypeFlags.Union */)); } function isGenericTypeWithoutNullableConstraint(type) { - return !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); + return type.flags & 2097152 /* TypeFlags.Intersection */ ? + ts.some(type.types, isGenericTypeWithoutNullableConstraint) : + !!(type.flags & 465829888 /* TypeFlags.Instantiable */ && !maybeTypeOfKind(getBaseConstraintOrType(type), 98304 /* TypeFlags.Nullable */)); } function hasContextualTypeWithNoGenericTypes(node, checkMode) { // Computing the contextual type for a child of a JSX element involves resolving the type of the @@ -126909,9 +126953,7 @@ var ts; } } } - var seenRefs = buildInfoPath ? new ts.Set() : undefined; var buildInfoCacheEntry = state.buildInfoCache.get(resolvedPath); - seenRefs === null || seenRefs === void 0 ? void 0 : seenRefs.add(resolvedPath); /** Inputs are up-to-date, just need either timestamp update or bundle prepend manipulation to make it look up-to-date */ var pseudoUpToDate = false; var usesPrepend = false; @@ -126926,7 +126968,7 @@ var ts; continue; } // Check if tsbuildinfo path is shared, then we need to rebuild - if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath)) { + if (buildInfoCacheEntry && hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath)) { return { type: ts.UpToDateStatusType.OutOfDateWithUpstream, outOfDateOutputFileName: buildInfoPath, @@ -126984,25 +127026,9 @@ var ts; oldestOutputFileName: oldestOutputFileName }; } - function hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig, resolvedRefPath) { - if (seenRefs.has(resolvedRefPath)) - return false; - seenRefs.add(resolvedRefPath); + function hasSameBuildInfo(state, buildInfoCacheEntry, resolvedRefPath) { var refBuildInfo = state.buildInfoCache.get(resolvedRefPath); - if (refBuildInfo.path === buildInfoCacheEntry.path) - return true; - if (resolvedConfig.projectReferences) { - // Check references - for (var _i = 0, _a = resolvedConfig.projectReferences; _i < _a.length; _i++) { - var ref = _a[_i]; - var resolvedRef = ts.resolveProjectReferencePath(ref); - var resolvedRefPath_1 = toResolvedConfigFilePath(state, resolvedRef); - var resolvedConfig_1 = parseConfigFile(state, resolvedRef, resolvedRefPath_1); - if (hasSameBuildInfo(state, buildInfoCacheEntry, seenRefs, resolvedConfig_1, resolvedRefPath_1)) - return true; - } - } - return false; + return refBuildInfo.path === buildInfoCacheEntry.path; } function getUpToDateStatus(state, project, resolvedPath) { if (project === undefined) { diff --git a/package-lock.json b/package-lock.json index 0a3476c8534f2..338dfdda3caf7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -65,7 +65,7 @@ "ms": "^2.1.3", "node-fetch": "^2.6.7", "source-map-support": "latest", - "typescript": "^4.8.2", + "typescript": "^4.8.3", "vinyl": "latest", "which": "^2.0.2", "xml2js": "^0.4.23" @@ -7960,9 +7960,9 @@ "dev": true }, "node_modules/typescript": { - "version": "4.8.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.2.tgz", - "integrity": "sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw==", + "version": "4.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.3.tgz", + "integrity": "sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig==", "dev": true, "bin": { "tsc": "bin/tsc", @@ -14723,9 +14723,9 @@ "dev": true }, "typescript": { - "version": "4.8.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.2.tgz", - "integrity": "sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw==", + "version": "4.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.3.tgz", + "integrity": "sha512-goMHfm00nWPa8UvR/CPSvykqf6dVV8x/dp0c5mFTMTIu0u0FlGWRioyy7Nn0PGAdHxpJZnuO/ut+PpQ8UiHAig==", "dev": true }, "unbox-primitive": { diff --git a/package.json b/package.json index d21e3030d1b01..0d80542b7fab5 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,7 @@ "ms": "^2.1.3", "node-fetch": "^2.6.7", "source-map-support": "latest", - "typescript": "^4.8.2", + "typescript": "^4.8.3", "vinyl": "latest", "which": "^2.0.2", "xml2js": "^0.4.23"