diff --git a/lib/tsc.js b/lib/tsc.js index 0314c27f785..e3dc24d79de 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -18,7 +18,7 @@ and limitations under the License. // src/compiler/corePublic.ts var versionMajorMinor = "5.5"; -var version = "5.5.1-rc"; +var version = "5.5.2"; // src/compiler/core.ts var emptyArray = []; @@ -5923,7 +5923,6 @@ var Diagnostics = { _0_resolves_to_a_type_only_declaration_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_export_type_0_as_default: diag(1290, 1 /* Error */, "_0_resolves_to_a_type_only_declaration_and_must_be_marked_type_only_in_this_file_before_re_exporting_1290", "'{0}' resolves to a type-only declaration and must be marked type-only in this file before re-exporting when '{1}' is enabled. Consider using 'export type { {0} as default }'."), _0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_import_type_where_0_is_imported: diag(1291, 1 /* Error */, "_0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enable_1291", "'{0}' resolves to a type and must be marked type-only in this file before re-exporting when '{1}' is enabled. Consider using 'import type' where '{0}' is imported."), _0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_export_type_0_as_default: diag(1292, 1 /* Error */, "_0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enable_1292", "'{0}' resolves to a type and must be marked type-only in this file before re-exporting when '{1}' is enabled. Consider using 'export type { {0} as default }'."), - ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve: diag(1293, 1 /* Error */, "ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve_1293", "ESM syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'."), with_statements_are_not_allowed_in_an_async_function_block: diag(1300, 1 /* Error */, "with_statements_are_not_allowed_in_an_async_function_block_1300", "'with' statements are not allowed in an async function block."), await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(1308, 1 /* Error */, "await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_1308", "'await' expressions are only allowed within async functions and at the top levels of modules."), The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level: diag(1309, 1 /* Error */, "The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level_1309", "The current file is a CommonJS module and cannot use 'await' at the top level."), @@ -12459,6 +12458,9 @@ function createSymbolTable(symbols) { function isTransientSymbol(symbol) { return (symbol.flags & 33554432 /* Transient */) !== 0; } +function isExternalModuleSymbol(moduleSymbol) { + return !!(moduleSymbol.flags & 1536 /* Module */) && moduleSymbol.escapedName.charCodeAt(0) === 34 /* doubleQuote */; +} var stringWriter = createSingleLineStringWriter(); function createSingleLineStringWriter() { var str = ""; @@ -14736,23 +14738,6 @@ function isFunctionSymbol(symbol) { const decl = symbol.valueDeclaration; return decl.kind === 262 /* FunctionDeclaration */ || isVariableDeclaration(decl) && decl.initializer && isFunctionLike(decl.initializer); } -function canHaveModuleSpecifier(node) { - switch (node == null ? void 0 : node.kind) { - case 260 /* VariableDeclaration */: - case 208 /* BindingElement */: - case 272 /* ImportDeclaration */: - case 278 /* ExportDeclaration */: - case 271 /* ImportEqualsDeclaration */: - case 273 /* ImportClause */: - case 280 /* NamespaceExport */: - case 274 /* NamespaceImport */: - case 281 /* ExportSpecifier */: - case 276 /* ImportSpecifier */: - case 205 /* ImportType */: - return true; - } - return false; -} function tryGetModuleSpecifierFromDeclaration(node) { var _a, _b; switch (node.kind) { @@ -17470,8 +17455,8 @@ function walkTreeForJSXTags(node) { function isFileModuleFromUsingJSXTag(file) { return !file.isDeclarationFile ? walkTreeForJSXTags(file) : void 0; } -function isFileForcedToBeModuleByFormat(file, options) { - return (getImpliedNodeFormatForEmitWorker(file, options) === 99 /* ESNext */ || fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */, ".mjs" /* Mjs */, ".mts" /* Mts */])) && !file.isDeclarationFile ? true : void 0; +function isFileForcedToBeModuleByFormat(file) { + return (file.impliedNodeFormat === 99 /* ESNext */ || fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */, ".mjs" /* Mjs */, ".mts" /* Mts */])) && !file.isDeclarationFile ? true : void 0; } function getSetExternalModuleIndicator(options) { switch (getEmitModuleDetectionKind(options)) { @@ -17490,14 +17475,10 @@ function getSetExternalModuleIndicator(options) { } checks.push(isFileForcedToBeModuleByFormat); const combined = or(...checks); - const callback = (file) => void (file.externalModuleIndicator = combined(file, options)); + const callback = (file) => void (file.externalModuleIndicator = combined(file)); return callback; } } -function importSyntaxAffectsModuleResolution(options) { - const moduleResolution = getEmitModuleResolutionKind(options); - return 3 /* Node16 */ <= moduleResolution && moduleResolution <= 99 /* NodeNext */ || getResolvePackageJsonExports(options) || getResolvePackageJsonImports(options); -} function createComputedCompilerOptions(options) { return options; } @@ -19171,7 +19152,7 @@ function createNameResolver({ } break; } - if (isSelfReferenceLocation(location)) { + if (isSelfReferenceLocation(location, lastLocation)) { lastSelfReferenceLocation = location; } lastLocation = location; @@ -19272,8 +19253,10 @@ function createNameResolver({ } return !getImmediatelyInvokedFunctionExpression(location); } - function isSelfReferenceLocation(node) { + function isSelfReferenceLocation(node, lastLocation) { switch (node.kind) { + case 169 /* Parameter */: + return !!lastLocation && lastLocation === node.name; case 262 /* FunctionDeclaration */: case 263 /* ClassDeclaration */: case 264 /* InterfaceDeclaration */: @@ -26655,7 +26638,7 @@ function createExternalHelpersImportDeclarationIfNeeded(nodeFactory, helperFacto if (compilerOptions.importHelpers && isEffectiveExternalModule(sourceFile, compilerOptions)) { let namedBindings; const moduleKind = getEmitModuleKind(compilerOptions); - if (moduleKind >= 5 /* ES2015 */ && moduleKind <= 99 /* ESNext */ || getImpliedNodeFormatForEmitWorker(sourceFile, compilerOptions) === 99 /* ESNext */) { + if (moduleKind >= 5 /* ES2015 */ && moduleKind <= 99 /* ESNext */ || sourceFile.impliedNodeFormat === 99 /* ESNext */) { const helpers = getEmitHelpers(sourceFile); if (helpers) { const helperNames = []; @@ -26720,7 +26703,8 @@ function getOrCreateExternalHelpersModuleNameIfNeeded(factory2, node, compilerOp if (externalHelpersModuleName) { return externalHelpersModuleName; } - let create = (hasExportStarsToExportValues || getESModuleInterop(compilerOptions) && hasImportStarOrImportDefault) && getEmitModuleFormatOfFileWorker(node, compilerOptions) < 4 /* System */; + const moduleKind = getEmitModuleKind(compilerOptions); + let create = (hasExportStarsToExportValues || getESModuleInterop(compilerOptions) && hasImportStarOrImportDefault) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || node.impliedNodeFormat === 1 /* CommonJS */); if (!create) { const helpers = getEmitHelpers(node); if (helpers) { @@ -44129,15 +44113,13 @@ function createGetSymbolWalker(getRestTypeOfSignature, getTypePredicateOfSignatu } // src/compiler/moduleSpecifiers.ts -function getModuleSpecifierPreferences({ importModuleSpecifierPreference, importModuleSpecifierEnding }, host, compilerOptions, importingSourceFile, oldImportSpecifier) { +function getModuleSpecifierPreferences({ importModuleSpecifierPreference, importModuleSpecifierEnding }, compilerOptions, importingSourceFile, oldImportSpecifier) { const filePreferredEnding = getPreferredEnding(); return { relativePreference: oldImportSpecifier !== void 0 ? isExternalModuleNameRelative(oldImportSpecifier) ? 0 /* Relative */ : 1 /* NonRelative */ : importModuleSpecifierPreference === "relative" ? 0 /* Relative */ : importModuleSpecifierPreference === "non-relative" ? 1 /* NonRelative */ : importModuleSpecifierPreference === "project-relative" ? 3 /* ExternalNonRelative */ : 2 /* Shortest */, getAllowedEndingsInPreferredOrder: (syntaxImpliedNodeFormat) => { - const impliedNodeFormat = getDefaultResolutionModeForFile(importingSourceFile, host, compilerOptions); - const preferredEnding = syntaxImpliedNodeFormat !== impliedNodeFormat ? getPreferredEnding(syntaxImpliedNodeFormat) : filePreferredEnding; - const moduleResolution = getEmitModuleResolutionKind(compilerOptions); - if ((syntaxImpliedNodeFormat ?? impliedNodeFormat) === 99 /* ESNext */ && 3 /* Node16 */ <= moduleResolution && moduleResolution <= 99 /* NodeNext */) { + const preferredEnding = syntaxImpliedNodeFormat !== importingSourceFile.impliedNodeFormat ? getPreferredEnding(syntaxImpliedNodeFormat) : filePreferredEnding; + if ((syntaxImpliedNodeFormat ?? importingSourceFile.impliedNodeFormat) === 99 /* ESNext */) { if (shouldAllowImportingTsExtension(compilerOptions, importingSourceFile.fileName)) { return [3 /* TsExtension */, 2 /* JsExtension */]; } @@ -44168,7 +44150,7 @@ function getModuleSpecifierPreferences({ importModuleSpecifierPreference, import } return getModuleSpecifierEndingPreference( importModuleSpecifierEnding, - resolutionMode ?? getDefaultResolutionModeForFile(importingSourceFile, host, compilerOptions), + resolutionMode ?? importingSourceFile.impliedNodeFormat, compilerOptions, isFullSourceFile(importingSourceFile) ? importingSourceFile : void 0 ); @@ -44226,16 +44208,12 @@ function getModuleSpecifiersWithCacheInfo(moduleSymbol, checker, compilerOptions } function computeModuleSpecifiers(modulePaths, compilerOptions, importingSourceFile, host, userPreferences, options = {}, forAutoImport) { const info = getInfo(importingSourceFile.fileName, host); - const preferences = getModuleSpecifierPreferences(userPreferences, host, compilerOptions, importingSourceFile); + const preferences = getModuleSpecifierPreferences(userPreferences, compilerOptions, importingSourceFile); const existingSpecifier = isFullSourceFile(importingSourceFile) && forEach(modulePaths, (modulePath) => forEach( host.getFileIncludeReasons().get(toPath(modulePath.path, host.getCurrentDirectory(), info.getCanonicalFileName)), (reason) => { if (reason.kind !== 3 /* Import */ || reason.file !== importingSourceFile.path) return void 0; - const existingMode = host.getModeForResolutionAtIndex(importingSourceFile, reason.index); - const targetMode = options.overrideImportMode ?? host.getDefaultResolutionModeForFile(importingSourceFile); - if (existingMode !== targetMode && existingMode !== void 0 && targetMode !== void 0) { - return void 0; - } + if (importingSourceFile.impliedNodeFormat && importingSourceFile.impliedNodeFormat !== getModeForResolutionAtIndex(importingSourceFile, reason.index, compilerOptions)) return void 0; const specifier = getModuleNameStringLiteralAt(importingSourceFile, reason.index).text; return preferences.relativePreference !== 1 /* NonRelative */ || !pathIsRelative(specifier) ? specifier : void 0; } @@ -44750,7 +44728,7 @@ function tryGetModuleNameAsNodeModule({ path, isRedirect }, { getCanonicalFileNa if (!parts) { return void 0; } - const preferences = getModuleSpecifierPreferences(userPreferences, host, options, importingSourceFile); + const preferences = getModuleSpecifierPreferences(userPreferences, options, importingSourceFile); const allowedEndings = preferences.getAllowedEndingsInPreferredOrder(); let moduleSpecifier = path; let isPackageRootPath = false; @@ -44800,7 +44778,7 @@ function tryGetModuleNameAsNodeModule({ path, isRedirect }, { getCanonicalFileNa const cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) == null ? void 0 : _a.call(host)) == null ? void 0 : _b.getPackageJsonInfo(packageJsonPath); if (isPackageJsonInfo(cachedPackageJson) || cachedPackageJson === void 0 && host.fileExists(packageJsonPath)) { const packageJsonContent = (cachedPackageJson == null ? void 0 : cachedPackageJson.contents.packageJsonContent) || tryParseJson(host.readFile(packageJsonPath)); - const importMode = overrideMode || getDefaultResolutionModeForFile(importingSourceFile, host, options); + const importMode = overrideMode || importingSourceFile.impliedNodeFormat; if (getResolvePackageJsonExports(options)) { const nodeModulesDirectoryName2 = packageRootPath.substring(parts.topLevelPackageNameIndex + 1); const packageName2 = getPackageNameFromTypesPackageName(nodeModulesDirectoryName2); @@ -44950,9 +44928,6 @@ function getRelativePathIfInSameVolume(path, directoryPath, getCanonicalFileName function isPathRelativeToParent(path) { return startsWith(path, ".."); } -function getDefaultResolutionModeForFile(file, host, compilerOptions) { - return isFullSourceFile(file) ? host.getDefaultResolutionModeForFile(file) : getDefaultResolutionModeForFileWorker(file, compilerOptions); -} // src/compiler/checker.ts var ambientModuleSymbolRegex = /^".+"$/; @@ -47159,28 +47134,22 @@ function createTypeChecker(host) { function isSyntacticDefault(node) { return isExportAssignment(node) && !node.isExportEquals || hasSyntacticModifier(node, 2048 /* Default */) || isExportSpecifier(node) || isNamespaceExport(node); } - function getEmitSyntaxForModuleSpecifierExpression(usage) { - return isStringLiteralLike(usage) ? host.getEmitSyntaxForUsageLocation(getSourceFileOfNode(usage), usage) : void 0; + function getUsageModeForExpression(usage) { + return isStringLiteralLike(usage) ? host.getModeForUsageLocation(getSourceFileOfNode(usage), usage) : void 0; } function isESMFormatImportImportingCommonjsFormatFile(usageMode, targetMode) { return usageMode === 99 /* ESNext */ && targetMode === 1 /* CommonJS */; } - function isOnlyImportableAsDefault(usage) { - if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) { - const usageMode = getEmitSyntaxForModuleSpecifierExpression(usage); - return usageMode === 99 /* ESNext */ && endsWith(usage.text, ".json" /* Json */); - } - return false; + function isOnlyImportedAsDefault(usage) { + const usageMode = getUsageModeForExpression(usage); + return usageMode === 99 /* ESNext */ && endsWith(usage.text, ".json" /* Json */); } function canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, usage) { - const usageMode = file && getEmitSyntaxForModuleSpecifierExpression(usage); - if (file && usageMode !== void 0) { - const targetMode = host.getImpliedNodeFormatForEmit(file); - if (usageMode === 99 /* ESNext */ && targetMode === 1 /* CommonJS */ && 100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) { - return true; - } - if (usageMode === 99 /* ESNext */ && targetMode === 99 /* ESNext */) { - return false; + const usageMode = file && getUsageModeForExpression(usage); + if (file && usageMode !== void 0 && 100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) { + const result = isESMFormatImportImportingCommonjsFormatFile(usageMode, file.impliedNodeFormat); + if (usageMode === 99 /* ESNext */ || result) { + return result; } } if (!allowSyntheticDefaultImports) { @@ -47239,7 +47208,7 @@ function createTypeChecker(host) { if (!specifier) { return exportDefaultSymbol; } - const hasDefaultOnly = isOnlyImportableAsDefault(specifier); + const hasDefaultOnly = isOnlyImportedAsDefault(specifier); const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { if (hasExportAssignmentSymbol(moduleSymbol) && !allowSyntheticDefaultImports) { @@ -47440,7 +47409,7 @@ function createTypeChecker(host) { let symbolFromModule = getExportOfModule(targetSymbol, name, specifier, dontResolveAlias); if (symbolFromModule === void 0 && name.escapedText === "default" /* Default */) { const file = (_a = moduleSymbol.declarations) == null ? void 0 : _a.find(isSourceFile); - if (isOnlyImportableAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) { + if (isOnlyImportedAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) { symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); } } @@ -48040,7 +48009,7 @@ function createTypeChecker(host) { /*requireStringLiteralLikeArgument*/ true ) ? location.initializer.arguments[0] : void 0) || ((_c = findAncestor(location, isImportCall)) == null ? void 0 : _c.arguments[0]) || ((_d = findAncestor(location, isImportDeclaration)) == null ? void 0 : _d.moduleSpecifier) || ((_e = findAncestor(location, isExternalModuleImportEqualsDeclaration)) == null ? void 0 : _e.moduleReference.expression) || ((_f = findAncestor(location, isExportDeclaration)) == null ? void 0 : _f.moduleSpecifier); - const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? host.getModeForUsageLocation(currentSourceFile, contextSpecifier) : host.getDefaultResolutionModeForFile(currentSourceFile); + const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? host.getModeForUsageLocation(currentSourceFile, contextSpecifier) : currentSourceFile.impliedNodeFormat; const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions); const resolvedModule = (_g = host.getResolvedModule(currentSourceFile, moduleReference, mode)) == null ? void 0 : _g.resolvedModule; const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule, currentSourceFile); @@ -48284,7 +48253,7 @@ function createTypeChecker(host) { return cloneTypeAsModuleType(symbol, defaultOnlyType, referenceParent); } const targetFile = (_a = moduleSymbol == null ? void 0 : moduleSymbol.declarations) == null ? void 0 : _a.find(isSourceFile); - const isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getEmitSyntaxForModuleSpecifierExpression(reference), host.getImpliedNodeFormatForEmit(targetFile)); + const isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getUsageModeForExpression(reference), targetFile.impliedNodeFormat); if (getESModuleInterop(compilerOptions) || isEsmCjsRef) { let sigs = getSignaturesOfStructuredType(type, 0 /* Call */); if (!sigs || !sigs.length) { @@ -50890,10 +50859,8 @@ function createTypeChecker(host) { } return getSourceFileOfNode(getNonAugmentationDeclaration(symbol)).fileName; } - const enclosingDeclaration = getOriginalNode(context.enclosingDeclaration); - const originalModuleSpecifier = canHaveModuleSpecifier(enclosingDeclaration) ? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration) : void 0; const contextFile = context.enclosingFile; - const resolutionMode = overrideImportMode || originalModuleSpecifier && host.getModeForUsageLocation(contextFile, originalModuleSpecifier) || contextFile && host.getDefaultResolutionModeForFile(contextFile); + const resolutionMode = overrideImportMode || (contextFile == null ? void 0 : contextFile.impliedNodeFormat); const cacheKey = createModeAwareCacheKey(contextFile.path, resolutionMode); const links = getSymbolLinks(symbol); let specifier = links.specifierCache && links.specifierCache.get(cacheKey); @@ -51715,7 +51682,7 @@ function createTypeChecker(host) { } if (isJSDocTypeLiteral(node)) { return factory.createTypeLiteralNode(map(node.jsDocPropertyTags, (t) => { - const name = isIdentifier(t.name) ? t.name : t.name.right; + const name = visitNode(isIdentifier(t.name) ? t.name : t.name.right, visitExistingNodeTreeSymbols, isIdentifier); const typeViaParent = getTypeOfPropertyOfType(getTypeFromTypeNode2(context, node), name.escapedText); const overrideTypeNode = typeViaParent && t.typeExpression && getTypeFromTypeNode2(context, t.typeExpression.type) !== typeViaParent ? typeToTypeNodeHelper(typeViaParent, context) : void 0; return factory.createPropertySignature( @@ -51759,7 +51726,7 @@ function createTypeChecker(host) { void 0, getEffectiveDotDotDotForParameter(p), setTextRange2(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p), - p.questionToken, + factory.cloneNode(p.questionToken), visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode), /*initializer*/ void 0 @@ -51774,7 +51741,7 @@ function createTypeChecker(host) { void 0, getEffectiveDotDotDotForParameter(p), setTextRange2(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p), - p.questionToken, + factory.cloneNode(p.questionToken), visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode), /*initializer*/ void 0 @@ -51793,7 +51760,7 @@ function createTypeChecker(host) { if (isTypeParameterDeclaration(node)) { return factory.updateTypeParameterDeclaration( node, - node.modifiers, + visitNodes2(node.modifiers, visitExistingNodeTreeSymbols, isModifier), setTextRange2(context, typeParameterToName(getDeclaredTypeOfSymbol(getSymbolOfDeclaration(node)), context), node), visitNode(node.constraint, visitExistingNodeTreeSymbols, isTypeNode), visitNode(node.default, visitExistingNodeTreeSymbols, isTypeNode) @@ -51825,8 +51792,8 @@ function createTypeChecker(host) { return factory.updateImportTypeNode( node, factory.updateLiteralTypeNode(node.argument, rewriteModuleSpecifier(node, node.argument.literal)), - node.attributes, - node.qualifier, + visitNode(node.attributes, visitExistingNodeTreeSymbols, isImportAttributes), + visitNode(node.qualifier, visitExistingNodeTreeSymbols, isEntityName), visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode), node.isTypeOf ); @@ -51862,8 +51829,28 @@ function createTypeChecker(host) { } else { const type = getWidenedType(getRegularTypeOfExpression(node.expression)); const computedPropertyNameType = typeToTypeNodeHelper(type, context); - Debug.assertNode(computedPropertyNameType, isLiteralTypeNode); - const literal = computedPropertyNameType.literal; + let literal; + if (isLiteralTypeNode(computedPropertyNameType)) { + literal = computedPropertyNameType.literal; + } else { + const evaluated = evaluateEntityNameExpression(node.expression); + const literalNode = typeof evaluated.value === "string" ? factory.createStringLiteral( + evaluated.value, + /*isSingleQuote*/ + void 0 + ) : typeof evaluated.value === "number" ? factory.createNumericLiteral( + evaluated.value, + /*numericLiteralFlags*/ + 0 + ) : void 0; + if (!literalNode) { + if (isImportTypeNode(computedPropertyNameType)) { + trackComputedName(node.expression, context.enclosingDeclaration, context); + } + return node; + } + literal = literalNode; + } if (literal.kind === 11 /* StringLiteral */ && isIdentifierText(literal.text, getEmitScriptTarget(compilerOptions))) { return factory.createIdentifier(literal.text); } @@ -51880,9 +51867,9 @@ function createTypeChecker(host) { hadError = hadError || introducesError; parameterName = result; } else { - parameterName = node.parameterName; + parameterName = factory.cloneNode(node.parameterName); } - return factory.updateTypePredicateNode(node, node.assertsModifier, parameterName, visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode)); + return factory.updateTypePredicateNode(node, factory.cloneNode(node.assertsModifier), parameterName, visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode)); } if (isTupleTypeNode(node) || isTypeLiteralNode(node) || isMappedTypeNode(node)) { const visited = visitEachChild2(node, visitExistingNodeTreeSymbols); @@ -51973,7 +51960,7 @@ function createTypeChecker(host) { /*yieldModuleSymbol*/ true )[0]; - if (parentSymbol && parentSymbol.flags & 1536 /* Module */) { + if (parentSymbol && isExternalModuleSymbol(parentSymbol)) { name = getSpecifierForModuleSymbol(parentSymbol, context); } else { const targetFile = getExternalModuleFileFromDeclaration(parent); @@ -75357,7 +75344,7 @@ function createTypeChecker(host) { return createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, emptyArray); } function getTypeWithSyntheticDefaultOnly(type, symbol, originalSymbol, moduleSpecifier) { - const hasDefaultOnly = isOnlyImportableAsDefault(moduleSpecifier); + const hasDefaultOnly = isOnlyImportedAsDefault(moduleSpecifier); if (hasDefaultOnly && type && !isErrorType(type)) { const synthType = type; if (!synthType.defaultOnlyType) { @@ -80584,7 +80571,7 @@ function createTypeChecker(host) { }); } function checkCollisionWithRequireExportsInGeneratedCode(node, name) { - if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) >= 5 /* ES2015 */) { + if (moduleKind >= 5 /* ES2015 */ && !(moduleKind >= 100 /* Node16 */ && getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) { return; } if (!name || !needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { @@ -82005,7 +81992,7 @@ function createTypeChecker(host) { } } function checkClassNameCollisionWithObject(name) { - if (languageVersion >= 1 /* ES5 */ && name.escapedText === "Object" && host.getEmitModuleFormatOfFile(getSourceFileOfNode(name)) < 5 /* ES2015 */) { + if (languageVersion >= 1 /* ES5 */ && name.escapedText === "Object" && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(name).impliedNodeFormat === 1 /* CommonJS */)) { error(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]); } } @@ -83086,7 +83073,7 @@ function createTypeChecker(host) { getNodeLinks(node).flags |= 2048 /* LexicalModuleMergesWithClass */; } } - if (compilerOptions.verbatimModuleSyntax && node.parent.kind === 307 /* SourceFile */ && host.getEmitModuleFormatOfFile(node.parent) === 1 /* CommonJS */) { + if (compilerOptions.verbatimModuleSyntax && node.parent.kind === 307 /* SourceFile */ && (moduleKind === 1 /* CommonJS */ || node.parent.impliedNodeFormat === 1 /* CommonJS */)) { const exportModifier = (_b = node.modifiers) == null ? void 0 : _b.find((m) => m.kind === 95 /* ExportKeyword */); if (exportModifier) { error(exportModifier, Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled); @@ -83296,10 +83283,8 @@ function createTypeChecker(host) { } } } - if (compilerOptions.verbatimModuleSyntax && node.kind !== 271 /* ImportEqualsDeclaration */ && !isInJSFile(node) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) { + if (compilerOptions.verbatimModuleSyntax && node.kind !== 271 /* ImportEqualsDeclaration */ && !isInJSFile(node) && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) { error(node, Diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled); - } else if (moduleKind === 200 /* Preserve */ && node.kind !== 271 /* ImportEqualsDeclaration */ && node.kind !== 260 /* VariableDeclaration */ && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) { - error(node, Diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve); } } if (isImportSpecifier(node)) { @@ -83338,7 +83323,7 @@ function createTypeChecker(host) { function checkImportBinding(node) { checkCollisionsForDeclarationName(node, node.name); checkAliasSymbol(node); - if (node.kind === 276 /* ImportSpecifier */ && idText(node.propertyName || node.name) === "default" && getESModuleInterop(compilerOptions) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */) { + if (node.kind === 276 /* ImportSpecifier */ && idText(node.propertyName || node.name) === "default" && getESModuleInterop(compilerOptions) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) { checkExternalEmitHelpers(node, 131072 /* ImportDefault */); } } @@ -83359,7 +83344,7 @@ function createTypeChecker(host) { if (validForTypeAttributes && override) { return; } - const mode = moduleKind === 199 /* NodeNext */ && declaration.moduleSpecifier && getEmitSyntaxForModuleSpecifierExpression(declaration.moduleSpecifier); + const mode = moduleKind === 199 /* NodeNext */ && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier); if (mode !== 99 /* ESNext */ && moduleKind !== 99 /* ESNext */ && moduleKind !== 200 /* Preserve */) { const message = isImportAttributes2 ? moduleKind === 199 /* NodeNext */ ? Diagnostics.Import_attributes_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls : Diagnostics.Import_attributes_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve : moduleKind === 199 /* NodeNext */ ? Diagnostics.Import_assertions_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls : Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve; return grammarErrorOnNode(node, message); @@ -83392,7 +83377,7 @@ function createTypeChecker(host) { if (importClause.namedBindings) { if (importClause.namedBindings.kind === 274 /* NamespaceImport */) { checkImportBinding(importClause.namedBindings); - if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && getESModuleInterop(compilerOptions)) { + if (moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && getESModuleInterop(compilerOptions)) { checkExternalEmitHelpers(node, 65536 /* ImportStar */); } } else { @@ -83432,7 +83417,7 @@ function createTypeChecker(host) { grammarErrorOnNode(node, Diagnostics.An_import_alias_cannot_use_import_type); } } else { - if (5 /* ES2015 */ <= moduleKind && moduleKind <= 99 /* ESNext */ && !node.isTypeOnly && !(node.flags & 33554432 /* Ambient */)) { + if (moduleKind >= 5 /* ES2015 */ && moduleKind !== 200 /* Preserve */ && getSourceFileOfNode(node).impliedNodeFormat === void 0 && !node.isTypeOnly && !(node.flags & 33554432 /* Ambient */)) { grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead); } } @@ -83461,7 +83446,7 @@ function createTypeChecker(host) { } else if (node.exportClause) { checkAliasSymbol(node.exportClause); } - if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */) { + if (moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) { if (node.exportClause) { if (getESModuleInterop(compilerOptions)) { checkExternalEmitHelpers(node, 65536 /* ImportStar */); @@ -83514,7 +83499,7 @@ function createTypeChecker(host) { markLinkedReferences(node, 7 /* ExportSpecifier */); } } else { - if (getESModuleInterop(compilerOptions) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && idText(node.propertyName || node.name) === "default") { + if (getESModuleInterop(compilerOptions) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && idText(node.propertyName || node.name) === "default") { checkExternalEmitHelpers(node, 131072 /* ImportDefault */); } } @@ -83540,7 +83525,7 @@ function createTypeChecker(host) { if (typeAnnotationNode) { checkTypeAssignableTo(checkExpressionCached(node.expression), getTypeFromTypeNode(typeAnnotationNode), node.expression); } - const isIllegalExportDefaultInCJS = !node.isExportEquals && !(node.flags & 33554432 /* Ambient */) && compilerOptions.verbatimModuleSyntax && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */; + const isIllegalExportDefaultInCJS = !node.isExportEquals && !(node.flags & 33554432 /* Ambient */) && compilerOptions.verbatimModuleSyntax && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */); if (node.expression.kind === 80 /* Identifier */) { const id = node.expression; const sym = getExportSymbolOfValueSymbolIfExported(resolveEntityName( @@ -83620,7 +83605,7 @@ function createTypeChecker(host) { grammarErrorOnNode(node.expression, Diagnostics.The_expression_of_an_export_assignment_must_be_an_identifier_or_qualified_name_in_an_ambient_context); } if (node.isExportEquals) { - if (moduleKind >= 5 /* ES2015 */ && moduleKind !== 200 /* Preserve */ && (node.flags & 33554432 /* Ambient */ && host.getImpliedNodeFormatForEmit(getSourceFileOfNode(node)) === 99 /* ESNext */ || !(node.flags & 33554432 /* Ambient */) && host.getImpliedNodeFormatForEmit(getSourceFileOfNode(node)) !== 1 /* CommonJS */)) { + if (moduleKind >= 5 /* ES2015 */ && moduleKind !== 200 /* Preserve */ && (node.flags & 33554432 /* Ambient */ && getSourceFileOfNode(node).impliedNodeFormat === 99 /* ESNext */ || !(node.flags & 33554432 /* Ambient */) && getSourceFileOfNode(node).impliedNodeFormat !== 1 /* CommonJS */)) { grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead); } else if (moduleKind === 4 /* System */ && !(node.flags & 33554432 /* Ambient */)) { grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system); @@ -86118,7 +86103,7 @@ function createTypeChecker(host) { break; case 95 /* ExportKeyword */: if (compilerOptions.verbatimModuleSyntax && !(node.flags & 33554432 /* Ambient */) && node.kind !== 265 /* TypeAliasDeclaration */ && node.kind !== 264 /* InterfaceDeclaration */ && // ModuleDeclaration needs to be checked that it is uninstantiated later - node.kind !== 267 /* ModuleDeclaration */ && node.parent.kind === 307 /* SourceFile */ && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) { + node.kind !== 267 /* ModuleDeclaration */ && node.parent.kind === 307 /* SourceFile */ && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) { return grammarErrorOnNode(modifier, Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled); } if (flags & 32 /* Export */) { @@ -87027,7 +87012,7 @@ function createTypeChecker(host) { const message = node.initializer ? Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions : !node.type ? Diagnostics.Declarations_with_definite_assignment_assertions_must_also_have_type_annotations : Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context; return grammarErrorOnNode(node.exclamationToken, message); } - if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && !(node.parent.parent.flags & 33554432 /* Ambient */) && hasSyntacticModifier(node.parent.parent, 32 /* Export */)) { + if ((moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && moduleKind !== 4 /* System */ && !(node.parent.parent.flags & 33554432 /* Ambient */) && hasSyntacticModifier(node.parent.parent, 32 /* Export */)) { checkESModuleMarker(node.name); } return !!blockScopeKind && checkGrammarNameInLetOrConstDeclarations(node.name); @@ -87528,9 +87513,7 @@ function createBasicNodeBuilderModuleSpecifierResolutionHost(host) { isSourceOfProjectReferenceRedirect: (fileName) => host.isSourceOfProjectReferenceRedirect(fileName), fileExists: (fileName) => host.fileExists(fileName), getFileIncludeReasons: () => host.getFileIncludeReasons(), - readFile: host.readFile ? (fileName) => host.readFile(fileName) : void 0, - getDefaultResolutionModeForFile: (file) => host.getDefaultResolutionModeForFile(file), - getModeForResolutionAtIndex: (file, index) => host.getModeForResolutionAtIndex(file, index) + readFile: host.readFile ? (fileName) => host.readFile(fileName) : void 0 }; } var SymbolTrackerImpl = class _SymbolTrackerImpl { @@ -107195,7 +107178,7 @@ function transformModule(context) { case 354 /* PartiallyEmittedExpression */: return visitPartiallyEmittedExpression(node, valueIsDiscarded); case 213 /* CallExpression */: - if (isImportCall(node) && host.shouldTransformImportCall(currentSourceFile)) { + if (isImportCall(node) && currentSourceFile.impliedNodeFormat === void 0) { return visitImportCallExpression(node); } break; @@ -110190,8 +110173,8 @@ function transformECMAScriptModule(context) { } } -// src/compiler/transformers/module/impliedNodeFormatDependent.ts -function transformImpliedNodeFormatDependentModule(context) { +// src/compiler/transformers/module/node.ts +function transformNodeModule(context) { const previousOnSubstituteNode = context.onSubstituteNode; const previousOnEmitNode = context.onEmitNode; const esmTransform = transformECMAScriptModule(context); @@ -110202,7 +110185,6 @@ function transformImpliedNodeFormatDependentModule(context) { const cjsTransform = transformModule(context); const cjsOnSubstituteNode = context.onSubstituteNode; const cjsOnEmitNode = context.onEmitNode; - const getEmitModuleFormatOfFile = (file) => context.getEmitHost().getEmitModuleFormatOfFile(file); context.onSubstituteNode = onSubstituteNode; context.onEmitNode = onEmitNode; context.enableSubstitution(307 /* SourceFile */); @@ -110217,7 +110199,7 @@ function transformImpliedNodeFormatDependentModule(context) { if (!currentSourceFile) { return previousOnSubstituteNode(hint, node); } - if (getEmitModuleFormatOfFile(currentSourceFile) >= 5 /* ES2015 */) { + if (currentSourceFile.impliedNodeFormat === 99 /* ESNext */) { return esmOnSubstituteNode(hint, node); } return cjsOnSubstituteNode(hint, node); @@ -110230,13 +110212,13 @@ function transformImpliedNodeFormatDependentModule(context) { if (!currentSourceFile) { return previousOnEmitNode(hint, node, emitCallback); } - if (getEmitModuleFormatOfFile(currentSourceFile) >= 5 /* ES2015 */) { + if (currentSourceFile.impliedNodeFormat === 99 /* ESNext */) { return esmOnEmitNode(hint, node, emitCallback); } return cjsOnEmitNode(hint, node, emitCallback); } function getModuleTransformForFile(file) { - return getEmitModuleFormatOfFile(file) >= 5 /* ES2015 */ ? esmTransform : cjsTransform; + return file.impliedNodeFormat === 99 /* ESNext */ ? esmTransform : cjsTransform; } function transformSourceFile(node) { if (node.isDeclarationFile) { @@ -112356,18 +112338,17 @@ function isProcessedComponent(node) { // src/compiler/transformer.ts function getModuleTransformer(moduleKind) { switch (moduleKind) { - case 200 /* Preserve */: - return transformECMAScriptModule; case 99 /* ESNext */: case 7 /* ES2022 */: case 6 /* ES2020 */: case 5 /* ES2015 */: - case 100 /* Node16 */: - case 199 /* NodeNext */: - case 1 /* CommonJS */: - return transformImpliedNodeFormatDependentModule; + case 200 /* Preserve */: + return transformECMAScriptModule; case 4 /* System */: return transformSystemModule; + case 100 /* Node16 */: + case 199 /* NodeNext */: + return transformNodeModule; default: return transformModule; } @@ -113086,7 +113067,6 @@ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, decla newLine: compilerOptions.newLine, noEmitHelpers: compilerOptions.noEmitHelpers, module: getEmitModuleKind(compilerOptions), - moduleResolution: getEmitModuleResolutionKind(compilerOptions), target: getEmitScriptTarget(compilerOptions), sourceMap: compilerOptions.sourceMap, inlineSourceMap: compilerOptions.inlineSourceMap, @@ -113149,7 +113129,6 @@ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, decla newLine: compilerOptions.newLine, noEmitHelpers: true, module: compilerOptions.module, - moduleResolution: compilerOptions.moduleResolution, target: compilerOptions.target, sourceMap: !forceDtsEmit && compilerOptions.declarationMap, inlineSourceMap: compilerOptions.inlineSourceMap, @@ -118607,6 +118586,9 @@ function flattenDiagnosticMessageText(diag2, newLine, indent2 = 0) { function getModeForFileReference(ref, containingFileMode) { return (isString(ref) ? containingFileMode : ref.resolutionMode) || containingFileMode; } +function getModeForResolutionAtIndex(file, index, compilerOptions) { + return getModeForUsageLocationWorker(file, getModuleNameStringLiteralAt(file, index), compilerOptions); +} function isExclusivelyTypeOnlyImportOrExport(decl) { var _a; if (isExportDeclaration(decl)) { @@ -118621,6 +118603,7 @@ function getModeForUsageLocation(file, usage, compilerOptions) { return getModeForUsageLocationWorker(file, usage, compilerOptions); } function getModeForUsageLocationWorker(file, usage, compilerOptions) { + var _a; if (isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent)) { const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent); if (isTypeOnly) { @@ -118636,28 +118619,19 @@ function getModeForUsageLocationWorker(file, usage, compilerOptions) { return override; } } - if (compilerOptions && importSyntaxAffectsModuleResolution(compilerOptions)) { - return getEmitSyntaxForUsageLocationWorker(file, usage, compilerOptions); + if (compilerOptions && getEmitModuleKind(compilerOptions) === 200 /* Preserve */) { + return usage.parent.parent && isImportEqualsDeclaration(usage.parent.parent) || isRequireCall( + usage.parent, + /*requireStringLiteralLikeArgument*/ + false + ) ? 1 /* CommonJS */ : 99 /* ESNext */; } -} -function getEmitSyntaxForUsageLocationWorker(file, usage, compilerOptions) { - var _a; - if (!compilerOptions) { - return void 0; + if (file.impliedNodeFormat === void 0) return void 0; + if (file.impliedNodeFormat !== 99 /* ESNext */) { + return isImportCall(walkUpParenthesizedExpressions(usage.parent)) ? 99 /* ESNext */ : 1 /* CommonJS */; } const exprParentParent = (_a = walkUpParenthesizedExpressions(usage.parent)) == null ? void 0 : _a.parent; - if (exprParentParent && isImportEqualsDeclaration(exprParentParent) || isRequireCall( - usage.parent, - /*requireStringLiteralLikeArgument*/ - false - )) { - return 1 /* CommonJS */; - } - if (isImportCall(walkUpParenthesizedExpressions(usage.parent))) { - return shouldTransformImportCallWorker(file, compilerOptions) ? 1 /* CommonJS */ : 99 /* ESNext */; - } - const fileEmitMode = getEmitModuleFormatOfFileWorker(file, compilerOptions); - return fileEmitMode === 1 /* CommonJS */ ? 1 /* CommonJS */ : emitModuleKindIsNonNodeESM(fileEmitMode) || fileEmitMode === 200 /* Preserve */ ? 99 /* ESNext */ : void 0; + return exprParentParent && isImportEqualsDeclaration(exprParentParent) ? 1 /* CommonJS */ : 99 /* ESNext */; } function getResolutionModeOverride(node, grammarErrorOnNode) { if (!node) return void 0; @@ -118714,7 +118688,7 @@ function getTypeReferenceResolutionName(entry) { } var typeReferenceResolutionNameAndModeGetter = { getName: getTypeReferenceResolutionName, - getMode: (entry, file, compilerOptions) => getModeForFileReference(entry, file && getDefaultResolutionModeForFileWorker(file, compilerOptions)) + getMode: (entry, file) => getModeForFileReference(entry, file == null ? void 0 : file.impliedNodeFormat) }; function createTypeReferenceResolutionLoader(containingFile, redirectedReference, options, host, cache) { return { @@ -118884,7 +118858,13 @@ function getConfigFileParsingDiagnostics(configFileParseResult) { return configFileParseResult.options.configFile ? [...configFileParseResult.options.configFile.parseDiagnostics, ...configFileParseResult.errors] : configFileParseResult.errors; } function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options) { - return fileExtensionIsOneOf(fileName, [".d.mts" /* Dmts */, ".mts" /* Mts */, ".mjs" /* Mjs */]) ? 99 /* ESNext */ : fileExtensionIsOneOf(fileName, [".d.cts" /* Dcts */, ".cts" /* Cts */, ".cjs" /* Cjs */]) ? 1 /* CommonJS */ : fileExtensionIsOneOf(fileName, [".d.ts" /* Dts */, ".ts" /* Ts */, ".tsx" /* Tsx */, ".js" /* Js */, ".jsx" /* Jsx */]) ? lookupFromPackageJson() : void 0; + switch (getEmitModuleResolutionKind(options)) { + case 3 /* Node16 */: + case 99 /* NodeNext */: + return fileExtensionIsOneOf(fileName, [".d.mts" /* Dmts */, ".mts" /* Mts */, ".mjs" /* Mjs */]) ? 99 /* ESNext */ : fileExtensionIsOneOf(fileName, [".d.cts" /* Dcts */, ".cts" /* Cts */, ".cjs" /* Cjs */]) ? 1 /* CommonJS */ : fileExtensionIsOneOf(fileName, [".d.ts" /* Dts */, ".ts" /* Ts */, ".tsx" /* Tsx */, ".js" /* Js */, ".jsx" /* Jsx */]) ? lookupFromPackageJson() : void 0; + default: + return void 0; + } function lookupFromPackageJson() { const state = getTemporaryModuleResolutionState(packageJsonInfoCache, host, options); const packageJsonLocations = []; @@ -119343,8 +119323,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config isSourceFileFromExternalLibrary, isSourceFileDefaultLibrary, getModeForUsageLocation: getModeForUsageLocation2, - getEmitSyntaxForUsageLocation, - getModeForResolutionAtIndex, + getModeForResolutionAtIndex: getModeForResolutionAtIndex2, getSourceFileFromReference, getLibFileFromReference, sourceFileToPackageName, @@ -119372,11 +119351,6 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config forEachResolvedProjectReference: forEachResolvedProjectReference2, isSourceOfProjectReferenceRedirect, getRedirectReferenceForResolutionFromSourceOfProject, - getCompilerOptionsForFile, - getDefaultResolutionModeForFile: getDefaultResolutionModeForFile2, - getEmitModuleFormatOfFile, - getImpliedNodeFormatForEmit, - shouldTransformImportCall, emitBuildInfo, fileExists, readFile, @@ -119959,10 +119933,6 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config getSymlinkCache, writeFile: writeFileCallback || writeFile2, isEmitBlocked, - shouldTransformImportCall, - getEmitModuleFormatOfFile, - getDefaultResolutionModeForFile: getDefaultResolutionModeForFile2, - getModeForResolutionAtIndex, readFile: (f) => host.readFile(f), fileExists: (f) => { const path = toPath3(f); @@ -121012,14 +120982,10 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config const resolvedTypeReferenceDirective = resolutions[index]; const fileName = ref.fileName; resolutionsInFile.set(fileName, getModeForFileReference(ref, file.impliedNodeFormat), resolvedTypeReferenceDirective); - const mode = ref.resolutionMode || getDefaultResolutionModeForFile2(file); + const mode = ref.resolutionMode || file.impliedNodeFormat; processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: 5 /* TypeReferenceDirective */, file: file.path, index }); } } - function getCompilerOptionsForFile(file) { - var _a2; - return ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options; - } function processTypeReferenceDirective(typeReferenceDirective, mode, resolution, reason) { var _a2, _b2; (_a2 = tracing) == null ? void 0 : _a2.push(tracing.Phase.Program, "processTypeReferenceDirective", { directive: typeReferenceDirective, hasResolved: !!resolution.resolvedTypeReferenceDirective, refKind: reason.kind, refPath: isReferencedFile(reason) ? reason.file : void 0 }); @@ -121120,12 +121086,13 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config return host.getCanonicalFileName(fileName); } function processImportedModules(file) { + var _a2; collectExternalModuleReferences(file); if (file.imports.length || file.moduleAugmentations.length) { const moduleNames = getModuleNames(file); const resolutions = (resolvedModulesProcessing == null ? void 0 : resolvedModulesProcessing.get(file.path)) || resolveModuleNamesReusingOldState(moduleNames, file); Debug.assert(resolutions.length === moduleNames.length); - const optionsForFile = getCompilerOptionsForFile(file); + const optionsForFile = ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options; const resolutionsInFile = createModeAwareCache(); (resolvedModules ?? (resolvedModules = /* @__PURE__ */ new Map())).set(file.path, resolutionsInFile); for (let index = 0; index < moduleNames.length; index++) { @@ -121681,7 +121648,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config redirectInfo = cachedChain.redirectInfo; } else { reasons == null ? void 0 : reasons.forEach(processReason); - redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file, getCompilerOptionsForFile(file)); + redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file); } if (fileProcessingReason) processReason(fileProcessingReason); const processedExtraReason = (seenReasons == null ? void 0 : seenReasons.size) !== (reasons == null ? void 0 : reasons.length); @@ -122039,53 +122006,13 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config return symlinks; } function getModeForUsageLocation2(file, usage) { - return getModeForUsageLocationWorker(file, usage, getCompilerOptionsForFile(file)); + var _a2; + const optionsForFile = ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options; + return getModeForUsageLocationWorker(file, usage, optionsForFile); } - function getEmitSyntaxForUsageLocation(file, usage) { - return getEmitSyntaxForUsageLocationWorker(file, usage, getCompilerOptionsForFile(file)); - } - function getModeForResolutionAtIndex(file, index) { + function getModeForResolutionAtIndex2(file, index) { return getModeForUsageLocation2(file, getModuleNameStringLiteralAt(file, index)); } - function getDefaultResolutionModeForFile2(sourceFile) { - return getDefaultResolutionModeForFileWorker(sourceFile, getCompilerOptionsForFile(sourceFile)); - } - function getImpliedNodeFormatForEmit(sourceFile) { - return getImpliedNodeFormatForEmitWorker(sourceFile, getCompilerOptionsForFile(sourceFile)); - } - function getEmitModuleFormatOfFile(sourceFile) { - return getEmitModuleFormatOfFileWorker(sourceFile, getCompilerOptionsForFile(sourceFile)); - } - function shouldTransformImportCall(sourceFile) { - return shouldTransformImportCallWorker(sourceFile, getCompilerOptionsForFile(sourceFile)); - } -} -function shouldTransformImportCallWorker(sourceFile, options) { - const moduleKind = getEmitModuleKind(options); - if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */ || moduleKind === 200 /* Preserve */) { - return false; - } - return getEmitModuleFormatOfFileWorker(sourceFile, options) < 5 /* ES2015 */; -} -function getEmitModuleFormatOfFileWorker(sourceFile, options) { - return getImpliedNodeFormatForEmitWorker(sourceFile, options) ?? getEmitModuleKind(options); -} -function getImpliedNodeFormatForEmitWorker(sourceFile, options) { - var _a, _b; - const moduleKind = getEmitModuleKind(options); - if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) { - return sourceFile.impliedNodeFormat; - } - if (sourceFile.impliedNodeFormat === 1 /* CommonJS */ && (((_a = sourceFile.packageJsonScope) == null ? void 0 : _a.contents.packageJsonContent.type) === "commonjs" || fileExtensionIsOneOf(sourceFile.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */]))) { - return 1 /* CommonJS */; - } - if (sourceFile.impliedNodeFormat === 99 /* ESNext */ && (((_b = sourceFile.packageJsonScope) == null ? void 0 : _b.contents.packageJsonContent.type) === "module" || fileExtensionIsOneOf(sourceFile.fileName, [".mjs" /* Mjs */, ".mts" /* Mts */]))) { - return 99 /* ESNext */; - } - return void 0; -} -function getDefaultResolutionModeForFileWorker(sourceFile, options) { - return importSyntaxAffectsModuleResolution(options) ? getImpliedNodeFormatForEmitWorker(sourceFile, options) : void 0; } function updateHostForUseSourceOfProjectReferenceRedirect(host) { let setOfDeclarationDirectories; @@ -125269,10 +125196,10 @@ function explainFiles(program, write) { for (const file of program.getSourceFiles()) { write(`${toFileName(file, relativeFileName)}`); (_a = reasons.get(file.path)) == null ? void 0 : _a.forEach((reason) => write(` ${fileIncludeReasonToDiagnostics(program, reason, relativeFileName).messageText}`)); - (_b = explainIfFileIsRedirectAndImpliedFormat(file, program.getCompilerOptionsForFile(file), relativeFileName)) == null ? void 0 : _b.forEach((d) => write(` ${d.messageText}`)); + (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) == null ? void 0 : _b.forEach((d) => write(` ${d.messageText}`)); } } -function explainIfFileIsRedirectAndImpliedFormat(file, options, fileNameConvertor) { +function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) { var _a; let result; if (file.path !== file.resolvedPath) { @@ -125292,7 +125219,7 @@ function explainIfFileIsRedirectAndImpliedFormat(file, options, fileNameConverto )); } if (isExternalOrCommonJsModule(file)) { - switch (getImpliedNodeFormatForEmitWorker(file, options)) { + switch (file.impliedNodeFormat) { case 99 /* ESNext */: if (file.packageJsonScope) { (result ?? (result = [])).push(chainDiagnosticMessages( diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts index e6dfbf92004..fbb3e4912fc 100644 --- a/lib/typescript.d.ts +++ b/lib/typescript.d.ts @@ -6014,67 +6014,19 @@ declare namespace ts { isSourceFileFromExternalLibrary(file: SourceFile): boolean; isSourceFileDefaultLibrary(file: SourceFile): boolean; /** - * Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution - * settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes, - * which cause an `import` or `require` condition to be used during resolution regardless of module resolution settings. In absence of - * overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript. - * Some examples: - * - * ```ts - * // tsc foo.mts --module nodenext - * import {} from "mod"; - * // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension - * - * // tsc foo.cts --module nodenext - * import {} from "mod"; - * // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension - * - * // tsc foo.ts --module preserve --moduleResolution bundler - * import {} from "mod"; - * // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler` - * // supports conditional imports/exports - * - * // tsc foo.ts --module preserve --moduleResolution node10 - * import {} from "mod"; - * // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10` - * // does not support conditional imports/exports - * - * // tsc foo.ts --module commonjs --moduleResolution node10 - * import type {} from "mod" with { "resolution-mode": "import" }; - * // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute - * ``` + * Calculates the final resolution mode for a given module reference node. This is the resolution mode explicitly provided via import + * attributes, if present, or the syntax the usage would have if emitted to JavaScript. In `--module node16` or `nodenext`, this may + * depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the input syntax of the reference. In other + * `module` modes, when overriding import attributes are not provided, this function returns `undefined`, as the result would have no + * impact on module resolution, emit, or type checking. */ getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike): ResolutionMode; /** - * Calculates the final resolution mode for an import at some index within a file's `imports` list. This function only returns a result - * when module resolution settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided - * via import attributes, which cause an `import` or `require` condition to be used during resolution regardless of module resolution - * settings. In absence of overriding attributes, and in modes that support differing resolution, the result indicates the syntax the - * usage would emit to JavaScript. Some examples: - * - * ```ts - * // tsc foo.mts --module nodenext - * import {} from "mod"; - * // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension - * - * // tsc foo.cts --module nodenext - * import {} from "mod"; - * // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension - * - * // tsc foo.ts --module preserve --moduleResolution bundler - * import {} from "mod"; - * // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler` - * // supports conditional imports/exports - * - * // tsc foo.ts --module preserve --moduleResolution node10 - * import {} from "mod"; - * // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10` - * // does not support conditional imports/exports - * - * // tsc foo.ts --module commonjs --moduleResolution node10 - * import type {} from "mod" with { "resolution-mode": "import" }; - * // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute - * ``` + * Calculates the final resolution mode for an import at some index within a file's `imports` list. This is the resolution mode + * explicitly provided via import attributes, if present, or the syntax the usage would have if emitted to JavaScript. In + * `--module node16` or `nodenext`, this may depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the + * input syntax of the reference. In other `module` modes, when overriding import attributes are not provided, this function returns + * `undefined`, as the result would have no impact on module resolution, emit, or type checking. */ getModeForResolutionAtIndex(file: SourceFile, index: number): ResolutionMode; getProjectReferences(): readonly ProjectReference[] | undefined; @@ -9427,43 +9379,24 @@ declare namespace ts { function getModeForResolutionAtIndex(file: SourceFile, index: number, compilerOptions: CompilerOptions): ResolutionMode; /** * Use `program.getModeForUsageLocation`, which retrieves the correct `compilerOptions`, instead of this function whenever possible. - * Calculates the final resolution mode for a given module reference node. This function only returns a result when module resolution - * settings allow differing resolution between ESM imports and CJS requires, or when a mode is explicitly provided via import attributes, - * which cause an `import` or `require` condition to be used during resolution regardless of module resolution settings. In absence of - * overriding attributes, and in modes that support differing resolution, the result indicates the syntax the usage would emit to JavaScript. - * Some examples: - * - * ```ts - * // tsc foo.mts --module nodenext - * import {} from "mod"; - * // Result: ESNext - the import emits as ESM due to `impliedNodeFormat` set by .mts file extension - * - * // tsc foo.cts --module nodenext - * import {} from "mod"; - * // Result: CommonJS - the import emits as CJS due to `impliedNodeFormat` set by .cts file extension - * - * // tsc foo.ts --module preserve --moduleResolution bundler - * import {} from "mod"; - * // Result: ESNext - the import emits as ESM due to `--module preserve` and `--moduleResolution bundler` - * // supports conditional imports/exports - * - * // tsc foo.ts --module preserve --moduleResolution node10 - * import {} from "mod"; - * // Result: undefined - the import emits as ESM due to `--module preserve`, but `--moduleResolution node10` - * // does not support conditional imports/exports - * - * // tsc foo.ts --module commonjs --moduleResolution node10 - * import type {} from "mod" with { "resolution-mode": "import" }; - * // Result: ESNext - conditional imports/exports always supported with "resolution-mode" attribute - * ``` - * + * Calculates the final resolution mode for a given module reference node. This is the resolution mode explicitly provided via import + * attributes, if present, or the syntax the usage would have if emitted to JavaScript. In `--module node16` or `nodenext`, this may + * depend on the file's `impliedNodeFormat`. In `--module preserve`, it depends only on the input syntax of the reference. In other + * `module` modes, when overriding import attributes are not provided, this function returns `undefined`, as the result would have no + * impact on module resolution, emit, or type checking. * @param file The file the import or import-like reference is contained within * @param usage The module reference string * @param compilerOptions The compiler options for the program that owns the file. If the file belongs to a referenced project, the compiler options * should be the options of the referenced project, not the referencing project. * @returns The final resolution mode of the import */ - function getModeForUsageLocation(file: SourceFile, usage: StringLiteralLike, compilerOptions: CompilerOptions): ResolutionMode; + function getModeForUsageLocation( + file: { + impliedNodeFormat?: ResolutionMode; + }, + usage: StringLiteralLike, + compilerOptions: CompilerOptions, + ): ModuleKind.CommonJS | ModuleKind.ESNext | undefined; function getConfigFileParsingDiagnostics(configFileParseResult: ParsedCommandLine): readonly Diagnostic[]; /** * A function for determining if a given file is esm or cjs format, assuming modern node module resolution rules, as configured by the diff --git a/lib/typescript.js b/lib/typescript.js index 86aeb338c4a..4b7a6252d38 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -258,7 +258,6 @@ __export(typescript_exports, { canHaveJSDoc: () => canHaveJSDoc, canHaveLocals: () => canHaveLocals, canHaveModifiers: () => canHaveModifiers, - canHaveModuleSpecifier: () => canHaveModuleSpecifier, canHaveSymbol: () => canHaveSymbol, canIncludeBindAndCheckDiagnsotics: () => canIncludeBindAndCheckDiagnsotics, canJsonReportNoInputFiles: () => canJsonReportNoInputFiles, @@ -736,7 +735,6 @@ __export(typescript_exports, { getDefaultLibFilePath: () => getDefaultLibFilePath, getDefaultLikeExportInfo: () => getDefaultLikeExportInfo, getDefaultLikeExportNameFromDeclaration: () => getDefaultLikeExportNameFromDeclaration, - getDefaultResolutionModeForFileWorker: () => getDefaultResolutionModeForFileWorker, getDiagnosticText: () => getDiagnosticText, getDiagnosticsWithinSpan: () => getDiagnosticsWithinSpan, getDirectoryPath: () => getDirectoryPath, @@ -767,7 +765,6 @@ __export(typescript_exports, { getEmitFlags: () => getEmitFlags, getEmitHelpers: () => getEmitHelpers, getEmitModuleDetectionKind: () => getEmitModuleDetectionKind, - getEmitModuleFormatOfFileWorker: () => getEmitModuleFormatOfFileWorker, getEmitModuleKind: () => getEmitModuleKind, getEmitModuleResolutionKind: () => getEmitModuleResolutionKind, getEmitScriptTarget: () => getEmitScriptTarget, @@ -818,7 +815,6 @@ __export(typescript_exports, { getIdentifierGeneratedImportReference: () => getIdentifierGeneratedImportReference, getIdentifierTypeArguments: () => getIdentifierTypeArguments, getImmediatelyInvokedFunctionExpression: () => getImmediatelyInvokedFunctionExpression, - getImpliedNodeFormatForEmitWorker: () => getImpliedNodeFormatForEmitWorker, getImpliedNodeFormatForFile: () => getImpliedNodeFormatForFile, getImpliedNodeFormatForFileWorker: () => getImpliedNodeFormatForFileWorker, getImportNeedsImportDefaultHelper: () => getImportNeedsImportDefaultHelper, @@ -1178,7 +1174,6 @@ __export(typescript_exports, { importDefaultHelper: () => importDefaultHelper, importFromModuleSpecifier: () => importFromModuleSpecifier, importStarHelper: () => importStarHelper, - importSyntaxAffectsModuleResolution: () => importSyntaxAffectsModuleResolution, indexOfAnyCharCode: () => indexOfAnyCharCode, indexOfNode: () => indexOfNode, indicesOf: () => indicesOf, @@ -2273,11 +2268,11 @@ __export(typescript_exports, { transformESDecorators: () => transformESDecorators, transformESNext: () => transformESNext, transformGenerators: () => transformGenerators, - transformImpliedNodeFormatDependentModule: () => transformImpliedNodeFormatDependentModule, transformJsx: () => transformJsx, transformLegacyDecorators: () => transformLegacyDecorators, transformModule: () => transformModule, transformNamedEvaluation: () => transformNamedEvaluation, + transformNodeModule: () => transformNodeModule, transformNodes: () => transformNodes, transformSystemModule: () => transformSystemModule, transformTypeScript: () => transformTypeScript, @@ -2371,7 +2366,7 @@ module.exports = __toCommonJS(typescript_exports); // src/compiler/corePublic.ts var versionMajorMinor = "5.5"; -var version = "5.5.1-rc"; +var version = "5.5.2"; var Comparison = /* @__PURE__ */ ((Comparison3) => { Comparison3[Comparison3["LessThan"] = -1] = "LessThan"; Comparison3[Comparison3["EqualTo"] = 0] = "EqualTo"; @@ -9506,7 +9501,6 @@ var Diagnostics = { _0_resolves_to_a_type_only_declaration_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_export_type_0_as_default: diag(1290, 1 /* Error */, "_0_resolves_to_a_type_only_declaration_and_must_be_marked_type_only_in_this_file_before_re_exporting_1290", "'{0}' resolves to a type-only declaration and must be marked type-only in this file before re-exporting when '{1}' is enabled. Consider using 'export type { {0} as default }'."), _0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_import_type_where_0_is_imported: diag(1291, 1 /* Error */, "_0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enable_1291", "'{0}' resolves to a type and must be marked type-only in this file before re-exporting when '{1}' is enabled. Consider using 'import type' where '{0}' is imported."), _0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enabled_Consider_using_export_type_0_as_default: diag(1292, 1 /* Error */, "_0_resolves_to_a_type_and_must_be_marked_type_only_in_this_file_before_re_exporting_when_1_is_enable_1292", "'{0}' resolves to a type and must be marked type-only in this file before re-exporting when '{1}' is enabled. Consider using 'export type { {0} as default }'."), - ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve: diag(1293, 1 /* Error */, "ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve_1293", "ESM syntax is not allowed in a CommonJS module when 'module' is set to 'preserve'."), with_statements_are_not_allowed_in_an_async_function_block: diag(1300, 1 /* Error */, "with_statements_are_not_allowed_in_an_async_function_block_1300", "'with' statements are not allowed in an async function block."), await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules: diag(1308, 1 /* Error */, "await_expressions_are_only_allowed_within_async_functions_and_at_the_top_levels_of_modules_1308", "'await' expressions are only allowed within async functions and at the top levels of modules."), The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level: diag(1309, 1 /* Error */, "The_current_file_is_a_CommonJS_module_and_cannot_use_await_at_the_top_level_1309", "The current file is a CommonJS module and cannot use 'await' at the top level."), @@ -16232,6 +16226,9 @@ function createSymbolTable(symbols) { function isTransientSymbol(symbol) { return (symbol.flags & 33554432 /* Transient */) !== 0; } +function isExternalModuleSymbol(moduleSymbol) { + return !!(moduleSymbol.flags & 1536 /* Module */) && moduleSymbol.escapedName.charCodeAt(0) === 34 /* doubleQuote */; +} var stringWriter = createSingleLineStringWriter(); function createSingleLineStringWriter() { var str = ""; @@ -18630,23 +18627,6 @@ function isFunctionSymbol(symbol) { const decl = symbol.valueDeclaration; return decl.kind === 262 /* FunctionDeclaration */ || isVariableDeclaration(decl) && decl.initializer && isFunctionLike(decl.initializer); } -function canHaveModuleSpecifier(node) { - switch (node == null ? void 0 : node.kind) { - case 260 /* VariableDeclaration */: - case 208 /* BindingElement */: - case 272 /* ImportDeclaration */: - case 278 /* ExportDeclaration */: - case 271 /* ImportEqualsDeclaration */: - case 273 /* ImportClause */: - case 280 /* NamespaceExport */: - case 274 /* NamespaceImport */: - case 281 /* ExportSpecifier */: - case 276 /* ImportSpecifier */: - case 205 /* ImportType */: - return true; - } - return false; -} function tryGetModuleSpecifierFromDeclaration(node) { var _a, _b; switch (node.kind) { @@ -21661,8 +21641,8 @@ function walkTreeForJSXTags(node) { function isFileModuleFromUsingJSXTag(file) { return !file.isDeclarationFile ? walkTreeForJSXTags(file) : void 0; } -function isFileForcedToBeModuleByFormat(file, options) { - return (getImpliedNodeFormatForEmitWorker(file, options) === 99 /* ESNext */ || fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */, ".mjs" /* Mjs */, ".mts" /* Mts */])) && !file.isDeclarationFile ? true : void 0; +function isFileForcedToBeModuleByFormat(file) { + return (file.impliedNodeFormat === 99 /* ESNext */ || fileExtensionIsOneOf(file.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */, ".mjs" /* Mjs */, ".mts" /* Mts */])) && !file.isDeclarationFile ? true : void 0; } function getSetExternalModuleIndicator(options) { switch (getEmitModuleDetectionKind(options)) { @@ -21681,14 +21661,10 @@ function getSetExternalModuleIndicator(options) { } checks.push(isFileForcedToBeModuleByFormat); const combined = or(...checks); - const callback = (file) => void (file.externalModuleIndicator = combined(file, options)); + const callback = (file) => void (file.externalModuleIndicator = combined(file)); return callback; } } -function importSyntaxAffectsModuleResolution(options) { - const moduleResolution = getEmitModuleResolutionKind(options); - return 3 /* Node16 */ <= moduleResolution && moduleResolution <= 99 /* NodeNext */ || getResolvePackageJsonExports(options) || getResolvePackageJsonImports(options); -} function createComputedCompilerOptions(options) { return options; } @@ -23414,7 +23390,7 @@ function createNameResolver({ } break; } - if (isSelfReferenceLocation(location)) { + if (isSelfReferenceLocation(location, lastLocation)) { lastSelfReferenceLocation = location; } lastLocation = location; @@ -23515,8 +23491,10 @@ function createNameResolver({ } return !getImmediatelyInvokedFunctionExpression(location); } - function isSelfReferenceLocation(node) { + function isSelfReferenceLocation(node, lastLocation) { switch (node.kind) { + case 169 /* Parameter */: + return !!lastLocation && lastLocation === node.name; case 262 /* FunctionDeclaration */: case 263 /* ClassDeclaration */: case 264 /* InterfaceDeclaration */: @@ -31048,7 +31026,7 @@ function createExternalHelpersImportDeclarationIfNeeded(nodeFactory, helperFacto if (compilerOptions.importHelpers && isEffectiveExternalModule(sourceFile, compilerOptions)) { let namedBindings; const moduleKind = getEmitModuleKind(compilerOptions); - if (moduleKind >= 5 /* ES2015 */ && moduleKind <= 99 /* ESNext */ || getImpliedNodeFormatForEmitWorker(sourceFile, compilerOptions) === 99 /* ESNext */) { + if (moduleKind >= 5 /* ES2015 */ && moduleKind <= 99 /* ESNext */ || sourceFile.impliedNodeFormat === 99 /* ESNext */) { const helpers = getEmitHelpers(sourceFile); if (helpers) { const helperNames = []; @@ -31113,7 +31091,8 @@ function getOrCreateExternalHelpersModuleNameIfNeeded(factory2, node, compilerOp if (externalHelpersModuleName) { return externalHelpersModuleName; } - let create = (hasExportStarsToExportValues || getESModuleInterop(compilerOptions) && hasImportStarOrImportDefault) && getEmitModuleFormatOfFileWorker(node, compilerOptions) < 4 /* System */; + const moduleKind = getEmitModuleKind(compilerOptions); + let create = (hasExportStarsToExportValues || getESModuleInterop(compilerOptions) && hasImportStarOrImportDefault) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || node.impliedNodeFormat === 1 /* CommonJS */); if (!create) { const helpers = getEmitHelpers(node); if (helpers) { @@ -48823,15 +48802,13 @@ var RelativePreference = /* @__PURE__ */ ((RelativePreference2) => { RelativePreference2[RelativePreference2["ExternalNonRelative"] = 3] = "ExternalNonRelative"; return RelativePreference2; })(RelativePreference || {}); -function getModuleSpecifierPreferences({ importModuleSpecifierPreference, importModuleSpecifierEnding }, host, compilerOptions, importingSourceFile, oldImportSpecifier) { +function getModuleSpecifierPreferences({ importModuleSpecifierPreference, importModuleSpecifierEnding }, compilerOptions, importingSourceFile, oldImportSpecifier) { const filePreferredEnding = getPreferredEnding(); return { relativePreference: oldImportSpecifier !== void 0 ? isExternalModuleNameRelative(oldImportSpecifier) ? 0 /* Relative */ : 1 /* NonRelative */ : importModuleSpecifierPreference === "relative" ? 0 /* Relative */ : importModuleSpecifierPreference === "non-relative" ? 1 /* NonRelative */ : importModuleSpecifierPreference === "project-relative" ? 3 /* ExternalNonRelative */ : 2 /* Shortest */, getAllowedEndingsInPreferredOrder: (syntaxImpliedNodeFormat) => { - const impliedNodeFormat = getDefaultResolutionModeForFile(importingSourceFile, host, compilerOptions); - const preferredEnding = syntaxImpliedNodeFormat !== impliedNodeFormat ? getPreferredEnding(syntaxImpliedNodeFormat) : filePreferredEnding; - const moduleResolution = getEmitModuleResolutionKind(compilerOptions); - if ((syntaxImpliedNodeFormat ?? impliedNodeFormat) === 99 /* ESNext */ && 3 /* Node16 */ <= moduleResolution && moduleResolution <= 99 /* NodeNext */) { + const preferredEnding = syntaxImpliedNodeFormat !== importingSourceFile.impliedNodeFormat ? getPreferredEnding(syntaxImpliedNodeFormat) : filePreferredEnding; + if ((syntaxImpliedNodeFormat ?? importingSourceFile.impliedNodeFormat) === 99 /* ESNext */) { if (shouldAllowImportingTsExtension(compilerOptions, importingSourceFile.fileName)) { return [3 /* TsExtension */, 2 /* JsExtension */]; } @@ -48862,19 +48839,19 @@ function getModuleSpecifierPreferences({ importModuleSpecifierPreference, import } return getModuleSpecifierEndingPreference( importModuleSpecifierEnding, - resolutionMode ?? getDefaultResolutionModeForFile(importingSourceFile, host, compilerOptions), + resolutionMode ?? importingSourceFile.impliedNodeFormat, compilerOptions, isFullSourceFile(importingSourceFile) ? importingSourceFile : void 0 ); } } function updateModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName2, host, oldImportSpecifier, options = {}) { - const res = getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName2, host, getModuleSpecifierPreferences({}, host, compilerOptions, importingSourceFile, oldImportSpecifier), {}, options); + const res = getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName2, host, getModuleSpecifierPreferences({}, compilerOptions, importingSourceFile, oldImportSpecifier), {}, options); if (res === oldImportSpecifier) return void 0; return res; } function getModuleSpecifier(compilerOptions, importingSourceFile, importingSourceFileName, toFileName2, host, options = {}) { - return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName2, host, getModuleSpecifierPreferences({}, host, compilerOptions, importingSourceFile), {}, options); + return getModuleSpecifierWorker(compilerOptions, importingSourceFile, importingSourceFileName, toFileName2, host, getModuleSpecifierPreferences({}, compilerOptions, importingSourceFile), {}, options); } function getNodeModulesPackageName(compilerOptions, importingSourceFile, nodeModulesFileName, host, preferences, options = {}) { const info = getInfo(importingSourceFile.fileName, host); @@ -48904,7 +48881,7 @@ function getModuleSpecifierWorker(compilerOptions, importingSourceFile, importin /*packageNameOnly*/ void 0, options.overrideImportMode - )) || getLocalModuleSpecifier(toFileName2, info, compilerOptions, host, options.overrideImportMode || getDefaultResolutionModeForFile(importingSourceFile, host, compilerOptions), preferences); + )) || getLocalModuleSpecifier(toFileName2, info, compilerOptions, host, options.overrideImportMode || importingSourceFile.impliedNodeFormat, preferences); } function tryGetModuleSpecifiersFromCache(moduleSymbol, importingSourceFile, host, userPreferences, options = {}) { const result = tryGetModuleSpecifiersFromCacheWorker( @@ -48975,21 +48952,17 @@ function getLocalModuleSpecifierBetweenFileNames(importingFile, targetFileName, compilerOptions, host, importMode, - getModuleSpecifierPreferences({}, host, compilerOptions, importingFile) + getModuleSpecifierPreferences({}, compilerOptions, importingFile) ); } function computeModuleSpecifiers(modulePaths, compilerOptions, importingSourceFile, host, userPreferences, options = {}, forAutoImport) { const info = getInfo(importingSourceFile.fileName, host); - const preferences = getModuleSpecifierPreferences(userPreferences, host, compilerOptions, importingSourceFile); + const preferences = getModuleSpecifierPreferences(userPreferences, compilerOptions, importingSourceFile); const existingSpecifier = isFullSourceFile(importingSourceFile) && forEach(modulePaths, (modulePath) => forEach( host.getFileIncludeReasons().get(toPath(modulePath.path, host.getCurrentDirectory(), info.getCanonicalFileName)), (reason) => { if (reason.kind !== 3 /* Import */ || reason.file !== importingSourceFile.path) return void 0; - const existingMode = host.getModeForResolutionAtIndex(importingSourceFile, reason.index); - const targetMode = options.overrideImportMode ?? host.getDefaultResolutionModeForFile(importingSourceFile); - if (existingMode !== targetMode && existingMode !== void 0 && targetMode !== void 0) { - return void 0; - } + if (importingSourceFile.impliedNodeFormat && importingSourceFile.impliedNodeFormat !== getModeForResolutionAtIndex(importingSourceFile, reason.index, compilerOptions)) return void 0; const specifier = getModuleNameStringLiteralAt(importingSourceFile, reason.index).text; return preferences.relativePreference !== 1 /* NonRelative */ || !pathIsRelative(specifier) ? specifier : void 0; } @@ -49519,7 +49492,7 @@ function tryGetModuleNameAsNodeModule({ path, isRedirect }, { getCanonicalFileNa if (!parts) { return void 0; } - const preferences = getModuleSpecifierPreferences(userPreferences, host, options, importingSourceFile); + const preferences = getModuleSpecifierPreferences(userPreferences, options, importingSourceFile); const allowedEndings = preferences.getAllowedEndingsInPreferredOrder(); let moduleSpecifier = path; let isPackageRootPath = false; @@ -49569,7 +49542,7 @@ function tryGetModuleNameAsNodeModule({ path, isRedirect }, { getCanonicalFileNa const cachedPackageJson = (_b = (_a = host.getPackageJsonInfoCache) == null ? void 0 : _a.call(host)) == null ? void 0 : _b.getPackageJsonInfo(packageJsonPath); if (isPackageJsonInfo(cachedPackageJson) || cachedPackageJson === void 0 && host.fileExists(packageJsonPath)) { const packageJsonContent = (cachedPackageJson == null ? void 0 : cachedPackageJson.contents.packageJsonContent) || tryParseJson(host.readFile(packageJsonPath)); - const importMode = overrideMode || getDefaultResolutionModeForFile(importingSourceFile, host, options); + const importMode = overrideMode || importingSourceFile.impliedNodeFormat; if (getResolvePackageJsonExports(options)) { const nodeModulesDirectoryName2 = packageRootPath.substring(parts.topLevelPackageNameIndex + 1); const packageName2 = getPackageNameFromTypesPackageName(nodeModulesDirectoryName2); @@ -49719,9 +49692,6 @@ function getRelativePathIfInSameVolume(path, directoryPath, getCanonicalFileName function isPathRelativeToParent(path) { return startsWith(path, ".."); } -function getDefaultResolutionModeForFile(file, host, compilerOptions) { - return isFullSourceFile(file) ? host.getDefaultResolutionModeForFile(file) : getDefaultResolutionModeForFileWorker(file, compilerOptions); -} // src/compiler/checker.ts var ambientModuleSymbolRegex = /^".+"$/; @@ -51928,28 +51898,22 @@ function createTypeChecker(host) { function isSyntacticDefault(node) { return isExportAssignment(node) && !node.isExportEquals || hasSyntacticModifier(node, 2048 /* Default */) || isExportSpecifier(node) || isNamespaceExport(node); } - function getEmitSyntaxForModuleSpecifierExpression(usage) { - return isStringLiteralLike(usage) ? host.getEmitSyntaxForUsageLocation(getSourceFileOfNode(usage), usage) : void 0; + function getUsageModeForExpression(usage) { + return isStringLiteralLike(usage) ? host.getModeForUsageLocation(getSourceFileOfNode(usage), usage) : void 0; } function isESMFormatImportImportingCommonjsFormatFile(usageMode, targetMode) { return usageMode === 99 /* ESNext */ && targetMode === 1 /* CommonJS */; } - function isOnlyImportableAsDefault(usage) { - if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) { - const usageMode = getEmitSyntaxForModuleSpecifierExpression(usage); - return usageMode === 99 /* ESNext */ && endsWith(usage.text, ".json" /* Json */); - } - return false; + function isOnlyImportedAsDefault(usage) { + const usageMode = getUsageModeForExpression(usage); + return usageMode === 99 /* ESNext */ && endsWith(usage.text, ".json" /* Json */); } function canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, usage) { - const usageMode = file && getEmitSyntaxForModuleSpecifierExpression(usage); - if (file && usageMode !== void 0) { - const targetMode = host.getImpliedNodeFormatForEmit(file); - if (usageMode === 99 /* ESNext */ && targetMode === 1 /* CommonJS */ && 100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) { - return true; - } - if (usageMode === 99 /* ESNext */ && targetMode === 99 /* ESNext */) { - return false; + const usageMode = file && getUsageModeForExpression(usage); + if (file && usageMode !== void 0 && 100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) { + const result = isESMFormatImportImportingCommonjsFormatFile(usageMode, file.impliedNodeFormat); + if (usageMode === 99 /* ESNext */ || result) { + return result; } } if (!allowSyntheticDefaultImports) { @@ -52008,7 +51972,7 @@ function createTypeChecker(host) { if (!specifier) { return exportDefaultSymbol; } - const hasDefaultOnly = isOnlyImportableAsDefault(specifier); + const hasDefaultOnly = isOnlyImportedAsDefault(specifier); const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, specifier); if (!exportDefaultSymbol && !hasSyntheticDefault && !hasDefaultOnly) { if (hasExportAssignmentSymbol(moduleSymbol) && !allowSyntheticDefaultImports) { @@ -52209,7 +52173,7 @@ function createTypeChecker(host) { let symbolFromModule = getExportOfModule(targetSymbol, name, specifier, dontResolveAlias); if (symbolFromModule === void 0 && name.escapedText === "default" /* Default */) { const file = (_a = moduleSymbol.declarations) == null ? void 0 : _a.find(isSourceFile); - if (isOnlyImportableAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) { + if (isOnlyImportedAsDefault(moduleSpecifier) || canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) { symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias); } } @@ -52809,7 +52773,7 @@ function createTypeChecker(host) { /*requireStringLiteralLikeArgument*/ true ) ? location.initializer.arguments[0] : void 0) || ((_c = findAncestor(location, isImportCall)) == null ? void 0 : _c.arguments[0]) || ((_d = findAncestor(location, isImportDeclaration)) == null ? void 0 : _d.moduleSpecifier) || ((_e = findAncestor(location, isExternalModuleImportEqualsDeclaration)) == null ? void 0 : _e.moduleReference.expression) || ((_f = findAncestor(location, isExportDeclaration)) == null ? void 0 : _f.moduleSpecifier); - const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? host.getModeForUsageLocation(currentSourceFile, contextSpecifier) : host.getDefaultResolutionModeForFile(currentSourceFile); + const mode = contextSpecifier && isStringLiteralLike(contextSpecifier) ? host.getModeForUsageLocation(currentSourceFile, contextSpecifier) : currentSourceFile.impliedNodeFormat; const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions); const resolvedModule = (_g = host.getResolvedModule(currentSourceFile, moduleReference, mode)) == null ? void 0 : _g.resolvedModule; const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule, currentSourceFile); @@ -53053,7 +53017,7 @@ function createTypeChecker(host) { return cloneTypeAsModuleType(symbol, defaultOnlyType, referenceParent); } const targetFile = (_a = moduleSymbol == null ? void 0 : moduleSymbol.declarations) == null ? void 0 : _a.find(isSourceFile); - const isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getEmitSyntaxForModuleSpecifierExpression(reference), host.getImpliedNodeFormatForEmit(targetFile)); + const isEsmCjsRef = targetFile && isESMFormatImportImportingCommonjsFormatFile(getUsageModeForExpression(reference), targetFile.impliedNodeFormat); if (getESModuleInterop(compilerOptions) || isEsmCjsRef) { let sigs = getSignaturesOfStructuredType(type, 0 /* Call */); if (!sigs || !sigs.length) { @@ -55659,10 +55623,8 @@ function createTypeChecker(host) { } return getSourceFileOfNode(getNonAugmentationDeclaration(symbol)).fileName; } - const enclosingDeclaration = getOriginalNode(context.enclosingDeclaration); - const originalModuleSpecifier = canHaveModuleSpecifier(enclosingDeclaration) ? tryGetModuleSpecifierFromDeclaration(enclosingDeclaration) : void 0; const contextFile = context.enclosingFile; - const resolutionMode = overrideImportMode || originalModuleSpecifier && host.getModeForUsageLocation(contextFile, originalModuleSpecifier) || contextFile && host.getDefaultResolutionModeForFile(contextFile); + const resolutionMode = overrideImportMode || (contextFile == null ? void 0 : contextFile.impliedNodeFormat); const cacheKey = createModeAwareCacheKey(contextFile.path, resolutionMode); const links = getSymbolLinks(symbol); let specifier = links.specifierCache && links.specifierCache.get(cacheKey); @@ -56484,7 +56446,7 @@ function createTypeChecker(host) { } if (isJSDocTypeLiteral(node)) { return factory.createTypeLiteralNode(map(node.jsDocPropertyTags, (t) => { - const name = isIdentifier(t.name) ? t.name : t.name.right; + const name = visitNode(isIdentifier(t.name) ? t.name : t.name.right, visitExistingNodeTreeSymbols, isIdentifier); const typeViaParent = getTypeOfPropertyOfType(getTypeFromTypeNode2(context, node), name.escapedText); const overrideTypeNode = typeViaParent && t.typeExpression && getTypeFromTypeNode2(context, t.typeExpression.type) !== typeViaParent ? typeToTypeNodeHelper(typeViaParent, context) : void 0; return factory.createPropertySignature( @@ -56528,7 +56490,7 @@ function createTypeChecker(host) { void 0, getEffectiveDotDotDotForParameter(p), setTextRange2(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p), - p.questionToken, + factory.cloneNode(p.questionToken), visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode), /*initializer*/ void 0 @@ -56543,7 +56505,7 @@ function createTypeChecker(host) { void 0, getEffectiveDotDotDotForParameter(p), setTextRange2(context, factory.createIdentifier(getNameForJSDocFunctionParameter(p, i)), p), - p.questionToken, + factory.cloneNode(p.questionToken), visitNode(p.type, visitExistingNodeTreeSymbols, isTypeNode), /*initializer*/ void 0 @@ -56562,7 +56524,7 @@ function createTypeChecker(host) { if (isTypeParameterDeclaration(node)) { return factory.updateTypeParameterDeclaration( node, - node.modifiers, + visitNodes2(node.modifiers, visitExistingNodeTreeSymbols, isModifier), setTextRange2(context, typeParameterToName(getDeclaredTypeOfSymbol(getSymbolOfDeclaration(node)), context), node), visitNode(node.constraint, visitExistingNodeTreeSymbols, isTypeNode), visitNode(node.default, visitExistingNodeTreeSymbols, isTypeNode) @@ -56594,8 +56556,8 @@ function createTypeChecker(host) { return factory.updateImportTypeNode( node, factory.updateLiteralTypeNode(node.argument, rewriteModuleSpecifier(node, node.argument.literal)), - node.attributes, - node.qualifier, + visitNode(node.attributes, visitExistingNodeTreeSymbols, isImportAttributes), + visitNode(node.qualifier, visitExistingNodeTreeSymbols, isEntityName), visitNodes2(node.typeArguments, visitExistingNodeTreeSymbols, isTypeNode), node.isTypeOf ); @@ -56631,8 +56593,28 @@ function createTypeChecker(host) { } else { const type = getWidenedType(getRegularTypeOfExpression(node.expression)); const computedPropertyNameType = typeToTypeNodeHelper(type, context); - Debug.assertNode(computedPropertyNameType, isLiteralTypeNode); - const literal = computedPropertyNameType.literal; + let literal; + if (isLiteralTypeNode(computedPropertyNameType)) { + literal = computedPropertyNameType.literal; + } else { + const evaluated = evaluateEntityNameExpression(node.expression); + const literalNode = typeof evaluated.value === "string" ? factory.createStringLiteral( + evaluated.value, + /*isSingleQuote*/ + void 0 + ) : typeof evaluated.value === "number" ? factory.createNumericLiteral( + evaluated.value, + /*numericLiteralFlags*/ + 0 + ) : void 0; + if (!literalNode) { + if (isImportTypeNode(computedPropertyNameType)) { + trackComputedName(node.expression, context.enclosingDeclaration, context); + } + return node; + } + literal = literalNode; + } if (literal.kind === 11 /* StringLiteral */ && isIdentifierText(literal.text, getEmitScriptTarget(compilerOptions))) { return factory.createIdentifier(literal.text); } @@ -56649,9 +56631,9 @@ function createTypeChecker(host) { hadError = hadError || introducesError; parameterName = result; } else { - parameterName = node.parameterName; + parameterName = factory.cloneNode(node.parameterName); } - return factory.updateTypePredicateNode(node, node.assertsModifier, parameterName, visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode)); + return factory.updateTypePredicateNode(node, factory.cloneNode(node.assertsModifier), parameterName, visitNode(node.type, visitExistingNodeTreeSymbols, isTypeNode)); } if (isTupleTypeNode(node) || isTypeLiteralNode(node) || isMappedTypeNode(node)) { const visited = visitEachChild2(node, visitExistingNodeTreeSymbols); @@ -56742,7 +56724,7 @@ function createTypeChecker(host) { /*yieldModuleSymbol*/ true )[0]; - if (parentSymbol && parentSymbol.flags & 1536 /* Module */) { + if (parentSymbol && isExternalModuleSymbol(parentSymbol)) { name = getSpecifierForModuleSymbol(parentSymbol, context); } else { const targetFile = getExternalModuleFileFromDeclaration(parent2); @@ -80126,7 +80108,7 @@ function createTypeChecker(host) { return createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, emptyArray); } function getTypeWithSyntheticDefaultOnly(type, symbol, originalSymbol, moduleSpecifier) { - const hasDefaultOnly = isOnlyImportableAsDefault(moduleSpecifier); + const hasDefaultOnly = isOnlyImportedAsDefault(moduleSpecifier); if (hasDefaultOnly && type && !isErrorType(type)) { const synthType = type; if (!synthType.defaultOnlyType) { @@ -85353,7 +85335,7 @@ function createTypeChecker(host) { }); } function checkCollisionWithRequireExportsInGeneratedCode(node, name) { - if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) >= 5 /* ES2015 */) { + if (moduleKind >= 5 /* ES2015 */ && !(moduleKind >= 100 /* Node16 */ && getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) { return; } if (!name || !needCollisionCheckForIdentifier(node, name, "require") && !needCollisionCheckForIdentifier(node, name, "exports")) { @@ -86774,7 +86756,7 @@ function createTypeChecker(host) { } } function checkClassNameCollisionWithObject(name) { - if (languageVersion >= 1 /* ES5 */ && name.escapedText === "Object" && host.getEmitModuleFormatOfFile(getSourceFileOfNode(name)) < 5 /* ES2015 */) { + if (languageVersion >= 1 /* ES5 */ && name.escapedText === "Object" && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(name).impliedNodeFormat === 1 /* CommonJS */)) { error2(name, Diagnostics.Class_name_cannot_be_Object_when_targeting_ES5_with_module_0, ModuleKind[moduleKind]); } } @@ -87855,7 +87837,7 @@ function createTypeChecker(host) { getNodeLinks(node).flags |= 2048 /* LexicalModuleMergesWithClass */; } } - if (compilerOptions.verbatimModuleSyntax && node.parent.kind === 307 /* SourceFile */ && host.getEmitModuleFormatOfFile(node.parent) === 1 /* CommonJS */) { + if (compilerOptions.verbatimModuleSyntax && node.parent.kind === 307 /* SourceFile */ && (moduleKind === 1 /* CommonJS */ || node.parent.impliedNodeFormat === 1 /* CommonJS */)) { const exportModifier = (_b = node.modifiers) == null ? void 0 : _b.find((m) => m.kind === 95 /* ExportKeyword */); if (exportModifier) { error2(exportModifier, Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled); @@ -88065,10 +88047,8 @@ function createTypeChecker(host) { } } } - if (compilerOptions.verbatimModuleSyntax && node.kind !== 271 /* ImportEqualsDeclaration */ && !isInJSFile(node) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) { + if (compilerOptions.verbatimModuleSyntax && node.kind !== 271 /* ImportEqualsDeclaration */ && !isInJSFile(node) && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) { error2(node, Diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled); - } else if (moduleKind === 200 /* Preserve */ && node.kind !== 271 /* ImportEqualsDeclaration */ && node.kind !== 260 /* VariableDeclaration */ && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) { - error2(node, Diagnostics.ESM_syntax_is_not_allowed_in_a_CommonJS_module_when_module_is_set_to_preserve); } } if (isImportSpecifier(node)) { @@ -88107,7 +88087,7 @@ function createTypeChecker(host) { function checkImportBinding(node) { checkCollisionsForDeclarationName(node, node.name); checkAliasSymbol(node); - if (node.kind === 276 /* ImportSpecifier */ && idText(node.propertyName || node.name) === "default" && getESModuleInterop(compilerOptions) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */) { + if (node.kind === 276 /* ImportSpecifier */ && idText(node.propertyName || node.name) === "default" && getESModuleInterop(compilerOptions) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) { checkExternalEmitHelpers(node, 131072 /* ImportDefault */); } } @@ -88128,7 +88108,7 @@ function createTypeChecker(host) { if (validForTypeAttributes && override) { return; } - const mode = moduleKind === 199 /* NodeNext */ && declaration.moduleSpecifier && getEmitSyntaxForModuleSpecifierExpression(declaration.moduleSpecifier); + const mode = moduleKind === 199 /* NodeNext */ && declaration.moduleSpecifier && getUsageModeForExpression(declaration.moduleSpecifier); if (mode !== 99 /* ESNext */ && moduleKind !== 99 /* ESNext */ && moduleKind !== 200 /* Preserve */) { const message = isImportAttributes2 ? moduleKind === 199 /* NodeNext */ ? Diagnostics.Import_attributes_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls : Diagnostics.Import_attributes_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve : moduleKind === 199 /* NodeNext */ ? Diagnostics.Import_assertions_are_not_allowed_on_statements_that_compile_to_CommonJS_require_calls : Diagnostics.Import_assertions_are_only_supported_when_the_module_option_is_set_to_esnext_nodenext_or_preserve; return grammarErrorOnNode(node, message); @@ -88161,7 +88141,7 @@ function createTypeChecker(host) { if (importClause.namedBindings) { if (importClause.namedBindings.kind === 274 /* NamespaceImport */) { checkImportBinding(importClause.namedBindings); - if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && getESModuleInterop(compilerOptions)) { + if (moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && getESModuleInterop(compilerOptions)) { checkExternalEmitHelpers(node, 65536 /* ImportStar */); } } else { @@ -88201,7 +88181,7 @@ function createTypeChecker(host) { grammarErrorOnNode(node, Diagnostics.An_import_alias_cannot_use_import_type); } } else { - if (5 /* ES2015 */ <= moduleKind && moduleKind <= 99 /* ESNext */ && !node.isTypeOnly && !(node.flags & 33554432 /* Ambient */)) { + if (moduleKind >= 5 /* ES2015 */ && moduleKind !== 200 /* Preserve */ && getSourceFileOfNode(node).impliedNodeFormat === void 0 && !node.isTypeOnly && !(node.flags & 33554432 /* Ambient */)) { grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead); } } @@ -88230,7 +88210,7 @@ function createTypeChecker(host) { } else if (node.exportClause) { checkAliasSymbol(node.exportClause); } - if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */) { + if (moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) { if (node.exportClause) { if (getESModuleInterop(compilerOptions)) { checkExternalEmitHelpers(node, 65536 /* ImportStar */); @@ -88283,7 +88263,7 @@ function createTypeChecker(host) { markLinkedReferences(node, 7 /* ExportSpecifier */); } } else { - if (getESModuleInterop(compilerOptions) && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && idText(node.propertyName || node.name) === "default") { + if (getESModuleInterop(compilerOptions) && moduleKind !== 4 /* System */ && (moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && idText(node.propertyName || node.name) === "default") { checkExternalEmitHelpers(node, 131072 /* ImportDefault */); } } @@ -88309,7 +88289,7 @@ function createTypeChecker(host) { if (typeAnnotationNode) { checkTypeAssignableTo(checkExpressionCached(node.expression), getTypeFromTypeNode(typeAnnotationNode), node.expression); } - const isIllegalExportDefaultInCJS = !node.isExportEquals && !(node.flags & 33554432 /* Ambient */) && compilerOptions.verbatimModuleSyntax && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */; + const isIllegalExportDefaultInCJS = !node.isExportEquals && !(node.flags & 33554432 /* Ambient */) && compilerOptions.verbatimModuleSyntax && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */); if (node.expression.kind === 80 /* Identifier */) { const id = node.expression; const sym = getExportSymbolOfValueSymbolIfExported(resolveEntityName( @@ -88389,7 +88369,7 @@ function createTypeChecker(host) { grammarErrorOnNode(node.expression, Diagnostics.The_expression_of_an_export_assignment_must_be_an_identifier_or_qualified_name_in_an_ambient_context); } if (node.isExportEquals) { - if (moduleKind >= 5 /* ES2015 */ && moduleKind !== 200 /* Preserve */ && (node.flags & 33554432 /* Ambient */ && host.getImpliedNodeFormatForEmit(getSourceFileOfNode(node)) === 99 /* ESNext */ || !(node.flags & 33554432 /* Ambient */) && host.getImpliedNodeFormatForEmit(getSourceFileOfNode(node)) !== 1 /* CommonJS */)) { + if (moduleKind >= 5 /* ES2015 */ && moduleKind !== 200 /* Preserve */ && (node.flags & 33554432 /* Ambient */ && getSourceFileOfNode(node).impliedNodeFormat === 99 /* ESNext */ || !(node.flags & 33554432 /* Ambient */) && getSourceFileOfNode(node).impliedNodeFormat !== 1 /* CommonJS */)) { grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_export_default_or_another_module_format_instead); } else if (moduleKind === 4 /* System */ && !(node.flags & 33554432 /* Ambient */)) { grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system); @@ -90887,7 +90867,7 @@ function createTypeChecker(host) { break; case 95 /* ExportKeyword */: if (compilerOptions.verbatimModuleSyntax && !(node.flags & 33554432 /* Ambient */) && node.kind !== 265 /* TypeAliasDeclaration */ && node.kind !== 264 /* InterfaceDeclaration */ && // ModuleDeclaration needs to be checked that it is uninstantiated later - node.kind !== 267 /* ModuleDeclaration */ && node.parent.kind === 307 /* SourceFile */ && host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) === 1 /* CommonJS */) { + node.kind !== 267 /* ModuleDeclaration */ && node.parent.kind === 307 /* SourceFile */ && (moduleKind === 1 /* CommonJS */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */)) { return grammarErrorOnNode(modifier, Diagnostics.A_top_level_export_modifier_cannot_be_used_on_value_declarations_in_a_CommonJS_module_when_verbatimModuleSyntax_is_enabled); } if (flags & 32 /* Export */) { @@ -91796,7 +91776,7 @@ function createTypeChecker(host) { const message = node.initializer ? Diagnostics.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions : !node.type ? Diagnostics.Declarations_with_definite_assignment_assertions_must_also_have_type_annotations : Diagnostics.A_definite_assignment_assertion_is_not_permitted_in_this_context; return grammarErrorOnNode(node.exclamationToken, message); } - if (host.getEmitModuleFormatOfFile(getSourceFileOfNode(node)) < 4 /* System */ && !(node.parent.parent.flags & 33554432 /* Ambient */) && hasSyntacticModifier(node.parent.parent, 32 /* Export */)) { + if ((moduleKind < 5 /* ES2015 */ || getSourceFileOfNode(node).impliedNodeFormat === 1 /* CommonJS */) && moduleKind !== 4 /* System */ && !(node.parent.parent.flags & 33554432 /* Ambient */) && hasSyntacticModifier(node.parent.parent, 32 /* Export */)) { checkESModuleMarker(node.name); } return !!blockScopeKind && checkGrammarNameInLetOrConstDeclarations(node.name); @@ -92297,9 +92277,7 @@ function createBasicNodeBuilderModuleSpecifierResolutionHost(host) { isSourceOfProjectReferenceRedirect: (fileName) => host.isSourceOfProjectReferenceRedirect(fileName), fileExists: (fileName) => host.fileExists(fileName), getFileIncludeReasons: () => host.getFileIncludeReasons(), - readFile: host.readFile ? (fileName) => host.readFile(fileName) : void 0, - getDefaultResolutionModeForFile: (file) => host.getDefaultResolutionModeForFile(file), - getModeForResolutionAtIndex: (file, index) => host.getModeForResolutionAtIndex(file, index) + readFile: host.readFile ? (fileName) => host.readFile(fileName) : void 0 }; } var SymbolTrackerImpl = class _SymbolTrackerImpl { @@ -112146,7 +112124,7 @@ function transformModule(context) { case 354 /* PartiallyEmittedExpression */: return visitPartiallyEmittedExpression(node, valueIsDiscarded); case 213 /* CallExpression */: - if (isImportCall(node) && host.shouldTransformImportCall(currentSourceFile)) { + if (isImportCall(node) && currentSourceFile.impliedNodeFormat === void 0) { return visitImportCallExpression(node); } break; @@ -115141,8 +115119,8 @@ function transformECMAScriptModule(context) { } } -// src/compiler/transformers/module/impliedNodeFormatDependent.ts -function transformImpliedNodeFormatDependentModule(context) { +// src/compiler/transformers/module/node.ts +function transformNodeModule(context) { const previousOnSubstituteNode = context.onSubstituteNode; const previousOnEmitNode = context.onEmitNode; const esmTransform = transformECMAScriptModule(context); @@ -115153,7 +115131,6 @@ function transformImpliedNodeFormatDependentModule(context) { const cjsTransform = transformModule(context); const cjsOnSubstituteNode = context.onSubstituteNode; const cjsOnEmitNode = context.onEmitNode; - const getEmitModuleFormatOfFile2 = (file) => context.getEmitHost().getEmitModuleFormatOfFile(file); context.onSubstituteNode = onSubstituteNode; context.onEmitNode = onEmitNode; context.enableSubstitution(307 /* SourceFile */); @@ -115168,7 +115145,7 @@ function transformImpliedNodeFormatDependentModule(context) { if (!currentSourceFile) { return previousOnSubstituteNode(hint, node); } - if (getEmitModuleFormatOfFile2(currentSourceFile) >= 5 /* ES2015 */) { + if (currentSourceFile.impliedNodeFormat === 99 /* ESNext */) { return esmOnSubstituteNode(hint, node); } return cjsOnSubstituteNode(hint, node); @@ -115181,13 +115158,13 @@ function transformImpliedNodeFormatDependentModule(context) { if (!currentSourceFile) { return previousOnEmitNode(hint, node, emitCallback); } - if (getEmitModuleFormatOfFile2(currentSourceFile) >= 5 /* ES2015 */) { + if (currentSourceFile.impliedNodeFormat === 99 /* ESNext */) { return esmOnEmitNode(hint, node, emitCallback); } return cjsOnEmitNode(hint, node, emitCallback); } function getModuleTransformForFile(file) { - return getEmitModuleFormatOfFile2(file) >= 5 /* ES2015 */ ? esmTransform : cjsTransform; + return file.impliedNodeFormat === 99 /* ESNext */ ? esmTransform : cjsTransform; } function transformSourceFile(node) { if (node.isDeclarationFile) { @@ -117307,18 +117284,17 @@ function isProcessedComponent(node) { // src/compiler/transformer.ts function getModuleTransformer(moduleKind) { switch (moduleKind) { - case 200 /* Preserve */: - return transformECMAScriptModule; case 99 /* ESNext */: case 7 /* ES2022 */: case 6 /* ES2020 */: case 5 /* ES2015 */: - case 100 /* Node16 */: - case 199 /* NodeNext */: - case 1 /* CommonJS */: - return transformImpliedNodeFormatDependentModule; + case 200 /* Preserve */: + return transformECMAScriptModule; case 4 /* System */: return transformSystemModule; + case 100 /* Node16 */: + case 199 /* NodeNext */: + return transformNodeModule; default: return transformModule; } @@ -118048,7 +118024,6 @@ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, decla newLine: compilerOptions.newLine, noEmitHelpers: compilerOptions.noEmitHelpers, module: getEmitModuleKind(compilerOptions), - moduleResolution: getEmitModuleResolutionKind(compilerOptions), target: getEmitScriptTarget(compilerOptions), sourceMap: compilerOptions.sourceMap, inlineSourceMap: compilerOptions.inlineSourceMap, @@ -118111,7 +118086,6 @@ function emitFiles(resolver, host, targetSourceFile, { scriptTransformers, decla newLine: compilerOptions.newLine, noEmitHelpers: true, module: compilerOptions.module, - moduleResolution: compilerOptions.moduleResolution, target: compilerOptions.target, sourceMap: !forceDtsEmit && compilerOptions.declarationMap, inlineSourceMap: compilerOptions.inlineSourceMap, @@ -123625,6 +123599,7 @@ function getModeForUsageLocation(file, usage, compilerOptions) { return getModeForUsageLocationWorker(file, usage, compilerOptions); } function getModeForUsageLocationWorker(file, usage, compilerOptions) { + var _a; if (isImportDeclaration(usage.parent) || isExportDeclaration(usage.parent)) { const isTypeOnly = isExclusivelyTypeOnlyImportOrExport(usage.parent); if (isTypeOnly) { @@ -123640,28 +123615,19 @@ function getModeForUsageLocationWorker(file, usage, compilerOptions) { return override; } } - if (compilerOptions && importSyntaxAffectsModuleResolution(compilerOptions)) { - return getEmitSyntaxForUsageLocationWorker(file, usage, compilerOptions); + if (compilerOptions && getEmitModuleKind(compilerOptions) === 200 /* Preserve */) { + return usage.parent.parent && isImportEqualsDeclaration(usage.parent.parent) || isRequireCall( + usage.parent, + /*requireStringLiteralLikeArgument*/ + false + ) ? 1 /* CommonJS */ : 99 /* ESNext */; } -} -function getEmitSyntaxForUsageLocationWorker(file, usage, compilerOptions) { - var _a; - if (!compilerOptions) { - return void 0; + if (file.impliedNodeFormat === void 0) return void 0; + if (file.impliedNodeFormat !== 99 /* ESNext */) { + return isImportCall(walkUpParenthesizedExpressions(usage.parent)) ? 99 /* ESNext */ : 1 /* CommonJS */; } const exprParentParent = (_a = walkUpParenthesizedExpressions(usage.parent)) == null ? void 0 : _a.parent; - if (exprParentParent && isImportEqualsDeclaration(exprParentParent) || isRequireCall( - usage.parent, - /*requireStringLiteralLikeArgument*/ - false - )) { - return 1 /* CommonJS */; - } - if (isImportCall(walkUpParenthesizedExpressions(usage.parent))) { - return shouldTransformImportCallWorker(file, compilerOptions) ? 1 /* CommonJS */ : 99 /* ESNext */; - } - const fileEmitMode = getEmitModuleFormatOfFileWorker(file, compilerOptions); - return fileEmitMode === 1 /* CommonJS */ ? 1 /* CommonJS */ : emitModuleKindIsNonNodeESM(fileEmitMode) || fileEmitMode === 200 /* Preserve */ ? 99 /* ESNext */ : void 0; + return exprParentParent && isImportEqualsDeclaration(exprParentParent) ? 1 /* CommonJS */ : 99 /* ESNext */; } function getResolutionModeOverride(node, grammarErrorOnNode) { if (!node) return void 0; @@ -123718,7 +123684,7 @@ function getTypeReferenceResolutionName(entry) { } var typeReferenceResolutionNameAndModeGetter = { getName: getTypeReferenceResolutionName, - getMode: (entry, file, compilerOptions) => getModeForFileReference(entry, file && getDefaultResolutionModeForFileWorker(file, compilerOptions)) + getMode: (entry, file) => getModeForFileReference(entry, file == null ? void 0 : file.impliedNodeFormat) }; function createTypeReferenceResolutionLoader(containingFile, redirectedReference, options, host, cache) { return { @@ -123892,7 +123858,13 @@ function getImpliedNodeFormatForFile(fileName, packageJsonInfoCache, host, optio return typeof result === "object" ? result.impliedNodeFormat : result; } function getImpliedNodeFormatForFileWorker(fileName, packageJsonInfoCache, host, options) { - return fileExtensionIsOneOf(fileName, [".d.mts" /* Dmts */, ".mts" /* Mts */, ".mjs" /* Mjs */]) ? 99 /* ESNext */ : fileExtensionIsOneOf(fileName, [".d.cts" /* Dcts */, ".cts" /* Cts */, ".cjs" /* Cjs */]) ? 1 /* CommonJS */ : fileExtensionIsOneOf(fileName, [".d.ts" /* Dts */, ".ts" /* Ts */, ".tsx" /* Tsx */, ".js" /* Js */, ".jsx" /* Jsx */]) ? lookupFromPackageJson() : void 0; + switch (getEmitModuleResolutionKind(options)) { + case 3 /* Node16 */: + case 99 /* NodeNext */: + return fileExtensionIsOneOf(fileName, [".d.mts" /* Dmts */, ".mts" /* Mts */, ".mjs" /* Mjs */]) ? 99 /* ESNext */ : fileExtensionIsOneOf(fileName, [".d.cts" /* Dcts */, ".cts" /* Cts */, ".cjs" /* Cjs */]) ? 1 /* CommonJS */ : fileExtensionIsOneOf(fileName, [".d.ts" /* Dts */, ".ts" /* Ts */, ".tsx" /* Tsx */, ".js" /* Js */, ".jsx" /* Jsx */]) ? lookupFromPackageJson() : void 0; + default: + return void 0; + } function lookupFromPackageJson() { const state = getTemporaryModuleResolutionState(packageJsonInfoCache, host, options); const packageJsonLocations = []; @@ -124351,7 +124323,6 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config isSourceFileFromExternalLibrary, isSourceFileDefaultLibrary, getModeForUsageLocation: getModeForUsageLocation2, - getEmitSyntaxForUsageLocation, getModeForResolutionAtIndex: getModeForResolutionAtIndex2, getSourceFileFromReference, getLibFileFromReference, @@ -124380,11 +124351,6 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config forEachResolvedProjectReference: forEachResolvedProjectReference2, isSourceOfProjectReferenceRedirect, getRedirectReferenceForResolutionFromSourceOfProject, - getCompilerOptionsForFile, - getDefaultResolutionModeForFile: getDefaultResolutionModeForFile2, - getEmitModuleFormatOfFile: getEmitModuleFormatOfFile2, - getImpliedNodeFormatForEmit: getImpliedNodeFormatForEmit2, - shouldTransformImportCall, emitBuildInfo, fileExists, readFile, @@ -124967,10 +124933,6 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config getSymlinkCache, writeFile: writeFileCallback || writeFile2, isEmitBlocked, - shouldTransformImportCall, - getEmitModuleFormatOfFile: getEmitModuleFormatOfFile2, - getDefaultResolutionModeForFile: getDefaultResolutionModeForFile2, - getModeForResolutionAtIndex: getModeForResolutionAtIndex2, readFile: (f) => host.readFile(f), fileExists: (f) => { const path = toPath3(f); @@ -126020,14 +125982,10 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config const resolvedTypeReferenceDirective = resolutions[index]; const fileName = ref.fileName; resolutionsInFile.set(fileName, getModeForFileReference(ref, file.impliedNodeFormat), resolvedTypeReferenceDirective); - const mode = ref.resolutionMode || getDefaultResolutionModeForFile2(file); + const mode = ref.resolutionMode || file.impliedNodeFormat; processTypeReferenceDirective(fileName, mode, resolvedTypeReferenceDirective, { kind: 5 /* TypeReferenceDirective */, file: file.path, index }); } } - function getCompilerOptionsForFile(file) { - var _a2; - return ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options; - } function processTypeReferenceDirective(typeReferenceDirective, mode, resolution, reason) { var _a2, _b2; (_a2 = tracing) == null ? void 0 : _a2.push(tracing.Phase.Program, "processTypeReferenceDirective", { directive: typeReferenceDirective, hasResolved: !!resolution.resolvedTypeReferenceDirective, refKind: reason.kind, refPath: isReferencedFile(reason) ? reason.file : void 0 }); @@ -126128,12 +126086,13 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config return host.getCanonicalFileName(fileName); } function processImportedModules(file) { + var _a2; collectExternalModuleReferences(file); if (file.imports.length || file.moduleAugmentations.length) { const moduleNames = getModuleNames(file); const resolutions = (resolvedModulesProcessing == null ? void 0 : resolvedModulesProcessing.get(file.path)) || resolveModuleNamesReusingOldState(moduleNames, file); Debug.assert(resolutions.length === moduleNames.length); - const optionsForFile = getCompilerOptionsForFile(file); + const optionsForFile = ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options; const resolutionsInFile = createModeAwareCache(); (resolvedModules ?? (resolvedModules = /* @__PURE__ */ new Map())).set(file.path, resolutionsInFile); for (let index = 0; index < moduleNames.length; index++) { @@ -126689,7 +126648,7 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config redirectInfo = cachedChain.redirectInfo; } else { reasons == null ? void 0 : reasons.forEach(processReason); - redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file, getCompilerOptionsForFile(file)); + redirectInfo = file && explainIfFileIsRedirectAndImpliedFormat(file); } if (fileProcessingReason) processReason(fileProcessingReason); const processedExtraReason = (seenReasons == null ? void 0 : seenReasons.size) !== (reasons == null ? void 0 : reasons.length); @@ -127047,53 +127006,13 @@ function createProgram(rootNamesOrOptions, _options, _host, _oldProgram, _config return symlinks; } function getModeForUsageLocation2(file, usage) { - return getModeForUsageLocationWorker(file, usage, getCompilerOptionsForFile(file)); - } - function getEmitSyntaxForUsageLocation(file, usage) { - return getEmitSyntaxForUsageLocationWorker(file, usage, getCompilerOptionsForFile(file)); + var _a2; + const optionsForFile = ((_a2 = getRedirectReferenceForResolution(file)) == null ? void 0 : _a2.commandLine.options) || options; + return getModeForUsageLocationWorker(file, usage, optionsForFile); } function getModeForResolutionAtIndex2(file, index) { return getModeForUsageLocation2(file, getModuleNameStringLiteralAt(file, index)); } - function getDefaultResolutionModeForFile2(sourceFile) { - return getDefaultResolutionModeForFileWorker(sourceFile, getCompilerOptionsForFile(sourceFile)); - } - function getImpliedNodeFormatForEmit2(sourceFile) { - return getImpliedNodeFormatForEmitWorker(sourceFile, getCompilerOptionsForFile(sourceFile)); - } - function getEmitModuleFormatOfFile2(sourceFile) { - return getEmitModuleFormatOfFileWorker(sourceFile, getCompilerOptionsForFile(sourceFile)); - } - function shouldTransformImportCall(sourceFile) { - return shouldTransformImportCallWorker(sourceFile, getCompilerOptionsForFile(sourceFile)); - } -} -function shouldTransformImportCallWorker(sourceFile, options) { - const moduleKind = getEmitModuleKind(options); - if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */ || moduleKind === 200 /* Preserve */) { - return false; - } - return getEmitModuleFormatOfFileWorker(sourceFile, options) < 5 /* ES2015 */; -} -function getEmitModuleFormatOfFileWorker(sourceFile, options) { - return getImpliedNodeFormatForEmitWorker(sourceFile, options) ?? getEmitModuleKind(options); -} -function getImpliedNodeFormatForEmitWorker(sourceFile, options) { - var _a, _b; - const moduleKind = getEmitModuleKind(options); - if (100 /* Node16 */ <= moduleKind && moduleKind <= 199 /* NodeNext */) { - return sourceFile.impliedNodeFormat; - } - if (sourceFile.impliedNodeFormat === 1 /* CommonJS */ && (((_a = sourceFile.packageJsonScope) == null ? void 0 : _a.contents.packageJsonContent.type) === "commonjs" || fileExtensionIsOneOf(sourceFile.fileName, [".cjs" /* Cjs */, ".cts" /* Cts */]))) { - return 1 /* CommonJS */; - } - if (sourceFile.impliedNodeFormat === 99 /* ESNext */ && (((_b = sourceFile.packageJsonScope) == null ? void 0 : _b.contents.packageJsonContent.type) === "module" || fileExtensionIsOneOf(sourceFile.fileName, [".mjs" /* Mjs */, ".mts" /* Mts */]))) { - return 99 /* ESNext */; - } - return void 0; -} -function getDefaultResolutionModeForFileWorker(sourceFile, options) { - return importSyntaxAffectsModuleResolution(options) ? getImpliedNodeFormatForEmitWorker(sourceFile, options) : void 0; } function updateHostForUseSourceOfProjectReferenceRedirect(host) { let setOfDeclarationDirectories; @@ -130318,10 +130237,10 @@ function explainFiles(program, write) { for (const file of program.getSourceFiles()) { write(`${toFileName(file, relativeFileName)}`); (_a = reasons.get(file.path)) == null ? void 0 : _a.forEach((reason) => write(` ${fileIncludeReasonToDiagnostics(program, reason, relativeFileName).messageText}`)); - (_b = explainIfFileIsRedirectAndImpliedFormat(file, program.getCompilerOptionsForFile(file), relativeFileName)) == null ? void 0 : _b.forEach((d) => write(` ${d.messageText}`)); + (_b = explainIfFileIsRedirectAndImpliedFormat(file, relativeFileName)) == null ? void 0 : _b.forEach((d) => write(` ${d.messageText}`)); } } -function explainIfFileIsRedirectAndImpliedFormat(file, options, fileNameConvertor) { +function explainIfFileIsRedirectAndImpliedFormat(file, fileNameConvertor) { var _a; let result; if (file.path !== file.resolvedPath) { @@ -130341,7 +130260,7 @@ function explainIfFileIsRedirectAndImpliedFormat(file, options, fileNameConverto )); } if (isExternalOrCommonJsModule(file)) { - switch (getImpliedNodeFormatForEmitWorker(file, options)) { + switch (file.impliedNodeFormat) { case 99 /* ESNext */: if (file.packageJsonScope) { (result ?? (result = [])).push(chainDiagnosticMessages( @@ -136959,9 +136878,6 @@ function isTypeKeywordToken(node) { function isTypeKeywordTokenOrIdentifier(node) { return isTypeKeywordToken(node) || isIdentifier(node) && node.text === "type"; } -function isExternalModuleSymbol(moduleSymbol) { - return !!(moduleSymbol.flags & 1536 /* Module */) && moduleSymbol.name.charCodeAt(0) === 34 /* doubleQuote */; -} function nodeSeenTracker() { const seen = []; return (node) => { @@ -137012,9 +136928,7 @@ function createModuleSpecifierResolutionHost(program, host) { isSourceOfProjectReferenceRedirect: (fileName) => program.isSourceOfProjectReferenceRedirect(fileName), getNearestAncestorDirectoryWithPackageJson: maybeBind(host, host.getNearestAncestorDirectoryWithPackageJson), getFileIncludeReasons: () => program.getFileIncludeReasons(), - getCommonSourceDirectory: () => program.getCommonSourceDirectory(), - getDefaultResolutionModeForFile: (file) => program.getDefaultResolutionModeForFile(file), - getModeForResolutionAtIndex: (file, index) => program.getModeForResolutionAtIndex(file, index) + getCommonSourceDirectory: () => program.getCommonSourceDirectory() }; } function getModuleSpecifierResolverHost(program, host) { @@ -138320,13 +138234,9 @@ function fileShouldUseJavaScriptRequire(file, program, host, preferRequire) { if (!hasJSFileExtension(fileName)) { return false; } - const compilerOptions = typeof file === "string" ? program.getCompilerOptions() : program.getCompilerOptionsForFile(file); + const compilerOptions = program.getCompilerOptions(); const moduleKind = getEmitModuleKind(compilerOptions); - const sourceFileLike = typeof file === "string" ? { - fileName: file, - impliedNodeFormat: getImpliedNodeFormatForFile(toPath(file, host.getCurrentDirectory(), hostGetCanonicalFileName(host)), (_a = program.getPackageJsonInfoCache) == null ? void 0 : _a.call(program), host, compilerOptions) - } : file; - const impliedNodeFormat = getImpliedNodeFormatForEmitWorker(sourceFileLike, compilerOptions); + const impliedNodeFormat = typeof file === "string" ? getImpliedNodeFormatForFile(toPath(file, host.getCurrentDirectory(), hostGetCanonicalFileName(host)), (_a = program.getPackageJsonInfoCache) == null ? void 0 : _a.call(program), host, compilerOptions) : file.impliedNodeFormat; if (impliedNodeFormat === 99 /* ESNext */) { return false; } @@ -141306,7 +141216,7 @@ function computeSuggestionDiagnostics(sourceFile, program, cancellationToken) { program.getSemanticDiagnostics(sourceFile, cancellationToken); const diags = []; const checker = program.getTypeChecker(); - const isCommonJSFile = program.getImpliedNodeFormatForEmit(sourceFile) === 1 /* CommonJS */ || fileExtensionIsOneOf(sourceFile.fileName, [".cts" /* Cts */, ".cjs" /* Cjs */]); + const isCommonJSFile = sourceFile.impliedNodeFormat === 1 /* CommonJS */ || fileExtensionIsOneOf(sourceFile.fileName, [".cts" /* Cts */, ".cjs" /* Cjs */]); if (!isCommonJSFile && sourceFile.commonJsModuleIndicator && (programContainsEsModules(program) || compilerOptionsIndicateEsModules(program.getCompilerOptions())) && containsTopLevelCommonjs(sourceFile)) { diags.push(createDiagnosticForNode(getErrorNodeFromCommonJsIndicator(sourceFile.commonJsModuleIndicator), Diagnostics.File_is_a_CommonJS_module_it_may_be_converted_to_an_ES_module)); } @@ -154302,7 +154212,7 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre compilerOptions, createModuleSpecifierResolutionHost(program, host) ); - const importKind = getImportKind(futureExportingSourceFile, exportKind, program); + const importKind = getImportKind(futureExportingSourceFile, exportKind, compilerOptions); const addAsTypeOnly = getAddAsTypeOnly( isImportUsageValidAsTypeOnly, /*isForNewImportDeclaration*/ @@ -154642,7 +154552,7 @@ function createImportAdderWorker(sourceFile, program, useAutoImportProvider, pre } function createImportSpecifierResolver(importingFile, program, host, preferences) { const packageJsonImportFilter = createPackageJsonImportFilter(importingFile, preferences, host); - const importMap = createExistingImportMap(importingFile, program); + const importMap = createExistingImportMap(program.getTypeChecker(), importingFile, program.getCompilerOptions()); return { getModuleSpecifierForBestExportInfo }; function getModuleSpecifierForBestExportInfo(exportInfo, position, isValidTypeOnlyUseSite, fromCacheOnly) { const { fixes, computedWithoutCacheCount } = getImportFixes( @@ -154745,7 +154655,7 @@ function getSingleExportInfoForSymbol(symbol, symbolName2, moduleSymbol, program } } } -function getImportFixes(exportInfos, usagePosition, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, importMap = isFullSourceFile(sourceFile) ? createExistingImportMap(sourceFile, program) : void 0, fromCacheOnly) { +function getImportFixes(exportInfos, usagePosition, isValidTypeOnlyUseSite, useRequire, program, sourceFile, host, preferences, importMap = isFullSourceFile(sourceFile) ? createExistingImportMap(program.getTypeChecker(), sourceFile, program.getCompilerOptions()) : void 0, fromCacheOnly) { const checker = program.getTypeChecker(); const existingImports = importMap ? flatMap(exportInfos, importMap.getImportsForExportInfo) : emptyArray; const useNamespace = usagePosition !== void 0 && tryUseExistingNamespaceImport(existingImports, usagePosition); @@ -154860,8 +154770,7 @@ function tryAddToExistingImport(existingImports, isValidTypeOnlyUseSite, checker }; } } -function createExistingImportMap(importingFile, program) { - const checker = program.getTypeChecker(); +function createExistingImportMap(checker, importingFile, compilerOptions) { let importMap; for (const moduleSpecifier of importingFile.imports) { const i = importFromModuleSpecifier(moduleSpecifier); @@ -154882,7 +154791,7 @@ function createExistingImportMap(importingFile, program) { const matchingDeclarations = importMap == null ? void 0 : importMap.get(getSymbolId(moduleSymbol)); if (!matchingDeclarations) return emptyArray; if (isSourceFileJS(importingFile) && !(targetFlags & 111551 /* Value */) && !every(matchingDeclarations, isJSDocImportTag)) return emptyArray; - const importKind = getImportKind(importingFile, exportKind, program); + const importKind = getImportKind(importingFile, exportKind, compilerOptions); return matchingDeclarations.map((declaration) => ({ declaration, importKind, symbol, targetFlags })); } }; @@ -154897,8 +154806,8 @@ function shouldUseRequire(sourceFile, program) { if (compilerOptions.configFile) { return getEmitModuleKind(compilerOptions) < 5 /* ES2015 */; } - if (getImpliedNodeFormatForEmit(sourceFile, program) === 1 /* CommonJS */) return true; - if (getImpliedNodeFormatForEmit(sourceFile, program) === 99 /* ESNext */) return false; + if (sourceFile.impliedNodeFormat === 1 /* CommonJS */) return true; + if (sourceFile.impliedNodeFormat === 99 /* ESNext */) return false; for (const otherFile of program.getSourceFiles()) { if (otherFile === sourceFile || !isSourceFileJS(otherFile) || program.isSourceFileFromExternalLibrary(otherFile)) continue; if (otherFile.commonJsModuleIndicator && !otherFile.externalModuleIndicator) return true; @@ -154950,7 +154859,7 @@ function getNewImportFixes(program, sourceFile, usagePosition, isValidTypeOnlyUs if (!importedSymbolHasValueMeaning && isJs && usagePosition !== void 0) { return { kind: 1 /* JsdocTypeImport */, moduleSpecifierKind, moduleSpecifier, usagePosition, exportInfo: exportInfo2, isReExport: i > 0 }; } - const importKind = getImportKind(sourceFile, exportInfo2.exportKind, program); + const importKind = getImportKind(sourceFile, exportInfo2.exportKind, compilerOptions); let qualification; if (usagePosition !== void 0 && importKind === 3 /* CommonJS */ && exportInfo2.exportKind === 0 /* Named */) { const exportEquals = checker.resolveExternalModuleSymbol(exportInfo2.moduleSymbol); @@ -155136,8 +155045,8 @@ function getUmdSymbol(token, checker) { } return void 0; } -function getImportKind(importingFile, exportKind, program, forceImportKeyword) { - if (program.getCompilerOptions().verbatimModuleSyntax && getEmitModuleFormatOfFile(importingFile, program) === 1 /* CommonJS */) { +function getImportKind(importingFile, exportKind, compilerOptions, forceImportKeyword) { + if (compilerOptions.verbatimModuleSyntax && (getEmitModuleKind(compilerOptions) === 1 /* CommonJS */ || importingFile.impliedNodeFormat === 1 /* CommonJS */)) { return 3 /* CommonJS */; } switch (exportKind) { @@ -155146,18 +155055,18 @@ function getImportKind(importingFile, exportKind, program, forceImportKeyword) { case 1 /* Default */: return 1 /* Default */; case 2 /* ExportEquals */: - return getExportEqualsImportKind(importingFile, program.getCompilerOptions(), !!forceImportKeyword); + return getExportEqualsImportKind(importingFile, compilerOptions, !!forceImportKeyword); case 3 /* UMD */: - return getUmdImportKind(importingFile, program, !!forceImportKeyword); + return getUmdImportKind(importingFile, compilerOptions, !!forceImportKeyword); default: return Debug.assertNever(exportKind); } } -function getUmdImportKind(importingFile, program, forceImportKeyword) { - if (getAllowSyntheticDefaultImports(program.getCompilerOptions())) { +function getUmdImportKind(importingFile, compilerOptions, forceImportKeyword) { + if (getAllowSyntheticDefaultImports(compilerOptions)) { return 1 /* Default */; } - const moduleKind = getEmitModuleKind(program.getCompilerOptions()); + const moduleKind = getEmitModuleKind(compilerOptions); switch (moduleKind) { case 2 /* AMD */: case 1 /* CommonJS */: @@ -155176,7 +155085,7 @@ function getUmdImportKind(importingFile, program, forceImportKeyword) { return 2 /* Namespace */; case 100 /* Node16 */: case 199 /* NodeNext */: - return getImpliedNodeFormatForEmit(importingFile, program) === 99 /* ESNext */ ? 2 /* Namespace */ : 3 /* CommonJS */; + return importingFile.impliedNodeFormat === 99 /* ESNext */ ? 2 /* Namespace */ : 3 /* CommonJS */; default: return Debug.assertNever(moduleKind, `Unexpected moduleKind ${moduleKind}`); } @@ -155660,12 +155569,6 @@ function createConstEqualsRequireDeclaration(name, quotedModuleSpecifier) { function symbolFlagsHaveMeaning(flags, meaning) { return meaning === 7 /* All */ ? true : meaning & 1 /* Value */ ? !!(flags & 111551 /* Value */) : meaning & 2 /* Type */ ? !!(flags & 788968 /* Type */) : meaning & 4 /* Namespace */ ? !!(flags & 1920 /* Namespace */) : false; } -function getImpliedNodeFormatForEmit(file, program) { - return isFullSourceFile(file) ? program.getImpliedNodeFormatForEmit(file) : getImpliedNodeFormatForEmitWorker(file, program.getCompilerOptions()); -} -function getEmitModuleFormatOfFile(file, program) { - return isFullSourceFile(file) ? program.getEmitModuleFormatOfFile(file) : getEmitModuleFormatOfFileWorker(file, program.getCompilerOptions()); -} // src/services/codefixes/fixAddMissingConstraint.ts var fixId17 = "addMissingConstraint"; @@ -162938,12 +162841,10 @@ function getJSDocParamAnnotation(paramName, initializer, dotDotDotToken, isJs, i const printer = isSnippet ? createSnippetPrinter({ removeComments: true, module: options.module, - moduleResolution: options.moduleResolution, target: options.target }) : createPrinter({ removeComments: true, module: options.module, - moduleResolution: options.moduleResolution, target: options.target }); setEmitFlags(typeNode, 1 /* SingleLine */); @@ -163199,7 +163100,6 @@ function getExhaustiveCaseSnippets(caseBlock, sourceFile, preferences, options, const printer = createSnippetPrinter({ removeComments: true, module: options.module, - moduleResolution: options.moduleResolution, target: options.target, newLine: getNewLineKind(newLineChar) }); @@ -163386,7 +163286,7 @@ function createCompletionEntry(symbol, sortText, replacementToken, contextToken, if (originIsResolvedExport(origin)) { sourceDisplay = [textPart(origin.moduleSpecifier)]; if (importStatementCompletion) { - ({ insertText, replacementSpan } = getInsertTextAndReplacementSpanForImportCompletion(name, importStatementCompletion, origin, useSemicolons, sourceFile, program, preferences)); + ({ insertText, replacementSpan } = getInsertTextAndReplacementSpanForImportCompletion(name, importStatementCompletion, origin, useSemicolons, sourceFile, options, preferences)); isSnippet = preferences.includeCompletionsWithSnippetText ? true : void 0; } } @@ -163502,7 +163402,6 @@ function getEntryForMemberCompletion(host, program, options, preferences, name, const printer = createSnippetPrinter({ removeComments: true, module: options.module, - moduleResolution: options.moduleResolution, target: options.target, omitTrailingSemicolon: false, newLine: getNewLineKind(getNewLineOrDefaultFromHost(host, formatContext == null ? void 0 : formatContext.options)) @@ -163653,7 +163552,6 @@ function getEntryForObjectLiteralMethodCompletion(symbol, name, enclosingDeclara const printer = createSnippetPrinter({ removeComments: true, module: options.module, - moduleResolution: options.moduleResolution, target: options.target, omitTrailingSemicolon: false, newLine: getNewLineKind(getNewLineOrDefaultFromHost(host, formatContext == null ? void 0 : formatContext.options)) @@ -163674,7 +163572,6 @@ function getEntryForObjectLiteralMethodCompletion(symbol, name, enclosingDeclara const signaturePrinter = createPrinter({ removeComments: true, module: options.module, - moduleResolution: options.moduleResolution, target: options.target, omitTrailingSemicolon: true }); @@ -163936,7 +163833,7 @@ function completionEntryDataToSymbolOriginInfo(data, completionName, moduleSymbo }; return unresolvedOrigin; } -function getInsertTextAndReplacementSpanForImportCompletion(name, importStatementCompletion, origin, useSemicolons, sourceFile, program, preferences) { +function getInsertTextAndReplacementSpanForImportCompletion(name, importStatementCompletion, origin, useSemicolons, sourceFile, options, preferences) { const replacementSpan = importStatementCompletion.replacementSpan; const quotedModuleSpecifier = escapeSnippetText(quote(sourceFile, preferences, origin.moduleSpecifier)); const exportKind = origin.isDefaultExport ? 1 /* Default */ : origin.exportName === "export=" /* ExportEquals */ ? 2 /* ExportEquals */ : 0 /* Named */; @@ -163944,7 +163841,7 @@ function getInsertTextAndReplacementSpanForImportCompletion(name, importStatemen const importKind = ts_codefix_exports.getImportKind( sourceFile, exportKind, - program, + options, /*forceImportKeyword*/ true ); @@ -166320,7 +166217,7 @@ function createNameAndKindSet() { } function getStringLiteralCompletions(sourceFile, position, contextToken, options, host, program, log, preferences, includeSymbol) { if (isInReferenceComment(sourceFile, position)) { - const entries = getTripleSlashReferenceCompletion(sourceFile, position, program, host); + const entries = getTripleSlashReferenceCompletion(sourceFile, position, options, host); return entries && convertPathCompletions(entries); } if (isInString(sourceFile, position, contextToken)) { @@ -166628,7 +166525,7 @@ function getStringLiteralCompletionsFromModuleNamesWorker(sourceFile, node, prog const compilerOptions = program.getCompilerOptions(); const typeChecker = program.getTypeChecker(); const extensionOptions = getExtensionOptions(compilerOptions, 1 /* ModuleSpecifier */, sourceFile, typeChecker, preferences, mode); - return isPathRelativeToScript(literalValue) || !compilerOptions.baseUrl && !compilerOptions.paths && (isRootedDiskPath(literalValue) || isUrl(literalValue)) ? getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, program, host, scriptPath, extensionOptions) : getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, mode, program, host, extensionOptions); + return isPathRelativeToScript(literalValue) || !compilerOptions.baseUrl && !compilerOptions.paths && (isRootedDiskPath(literalValue) || isUrl(literalValue)) ? getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath, extensionOptions) : getCompletionEntriesForNonRelativeModules(literalValue, scriptDirectory, mode, compilerOptions, host, extensionOptions, typeChecker); } function getExtensionOptions(compilerOptions, referenceKind, importingSourceFile, typeChecker, preferences, resolutionMode) { return { @@ -166639,15 +166536,14 @@ function getExtensionOptions(compilerOptions, referenceKind, importingSourceFile resolutionMode }; } -function getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, program, host, scriptPath, extensionOptions) { - const compilerOptions = program.getCompilerOptions(); +function getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, compilerOptions, host, scriptPath, extensionOptions) { if (compilerOptions.rootDirs) { return getCompletionEntriesForDirectoryFragmentWithRootDirs( compilerOptions.rootDirs, literalValue, scriptDirectory, extensionOptions, - program, + compilerOptions, host, scriptPath ); @@ -166656,7 +166552,6 @@ function getCompletionEntriesForRelativeModules(literalValue, scriptDirectory, p literalValue, scriptDirectory, extensionOptions, - program, host, /*moduleSpecifierIsRelative*/ true, @@ -166683,8 +166578,7 @@ function getBaseDirectoriesFromRootDirs(rootDirs, basePath, scriptDirectory, ign compareStringsCaseSensitive ); } -function getCompletionEntriesForDirectoryFragmentWithRootDirs(rootDirs, fragment, scriptDirectory, extensionOptions, program, host, exclude) { - const compilerOptions = program.getCompilerOptions(); +function getCompletionEntriesForDirectoryFragmentWithRootDirs(rootDirs, fragment, scriptDirectory, extensionOptions, compilerOptions, host, exclude) { const basePath = compilerOptions.project || host.getCurrentDirectory(); const ignoreCase = !(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames()); const baseDirectories = getBaseDirectoriesFromRootDirs(rootDirs, basePath, scriptDirectory, ignoreCase); @@ -166693,7 +166587,6 @@ function getCompletionEntriesForDirectoryFragmentWithRootDirs(rootDirs, fragment fragment, baseDirectory, extensionOptions, - program, host, /*moduleSpecifierIsRelative*/ true, @@ -166702,7 +166595,7 @@ function getCompletionEntriesForDirectoryFragmentWithRootDirs(rootDirs, fragment (itemA, itemB) => itemA.name === itemB.name && itemA.kind === itemB.kind && itemA.extension === itemB.extension ); } -function getCompletionEntriesForDirectoryFragment(fragment, scriptDirectory, extensionOptions, program, host, moduleSpecifierIsRelative, exclude, result = createNameAndKindSet()) { +function getCompletionEntriesForDirectoryFragment(fragment, scriptDirectory, extensionOptions, host, moduleSpecifierIsRelative, exclude, result = createNameAndKindSet()) { var _a; if (fragment === void 0) { fragment = ""; @@ -166727,7 +166620,7 @@ function getCompletionEntriesForDirectoryFragment(fragment, scriptDirectory, ext if (versionPaths) { const packageDirectory = getDirectoryPath(packageJsonPath); const pathInPackage = absolutePath.slice(ensureTrailingDirectorySeparator(packageDirectory).length); - if (addCompletionEntriesFromPaths(result, pathInPackage, packageDirectory, extensionOptions, program, host, versionPaths)) { + if (addCompletionEntriesFromPaths(result, pathInPackage, packageDirectory, extensionOptions, host, versionPaths)) { return result; } } @@ -166753,7 +166646,7 @@ function getCompletionEntriesForDirectoryFragment(fragment, scriptDirectory, ext } const { name, extension } = getFilenameWithExtensionOption( getBaseFileName(filePath), - program, + host.getCompilationSettings(), extensionOptions, /*isExportsWildcard*/ false @@ -166772,7 +166665,7 @@ function getCompletionEntriesForDirectoryFragment(fragment, scriptDirectory, ext } return result; } -function getFilenameWithExtensionOption(name, program, extensionOptions, isExportsWildcard) { +function getFilenameWithExtensionOption(name, compilerOptions, extensionOptions, isExportsWildcard) { const nonJsResult = ts_moduleSpecifiers_exports.tryGetRealFileNameForNonJsDeclarationFileName(name); if (nonJsResult) { return { name: nonJsResult, extension: tryGetExtensionFromPath2(nonJsResult) }; @@ -166782,8 +166675,7 @@ function getFilenameWithExtensionOption(name, program, extensionOptions, isExpor } let allowedEndings = getModuleSpecifierPreferences( { importModuleSpecifierEnding: extensionOptions.endingPreference }, - program, - program.getCompilerOptions(), + compilerOptions, extensionOptions.importingSourceFile ).getAllowedEndingsInPreferredOrder(extensionOptions.resolutionMode); if (isExportsWildcard) { @@ -166793,16 +166685,16 @@ function getFilenameWithExtensionOption(name, program, extensionOptions, isExpor if (fileExtensionIsOneOf(name, supportedTSImplementationExtensions)) { return { name, extension: tryGetExtensionFromPath2(name) }; } - const outputExtension2 = ts_moduleSpecifiers_exports.tryGetJSExtensionForFile(name, program.getCompilerOptions()); + const outputExtension2 = ts_moduleSpecifiers_exports.tryGetJSExtensionForFile(name, compilerOptions); return outputExtension2 ? { name: changeExtension(name, outputExtension2), extension: outputExtension2 } : { name, extension: tryGetExtensionFromPath2(name) }; } if (!isExportsWildcard && (allowedEndings[0] === 0 /* Minimal */ || allowedEndings[0] === 1 /* Index */) && fileExtensionIsOneOf(name, [".js" /* Js */, ".jsx" /* Jsx */, ".ts" /* Ts */, ".tsx" /* Tsx */, ".d.ts" /* Dts */])) { return { name: removeFileExtension(name), extension: tryGetExtensionFromPath2(name) }; } - const outputExtension = ts_moduleSpecifiers_exports.tryGetJSExtensionForFile(name, program.getCompilerOptions()); + const outputExtension = ts_moduleSpecifiers_exports.tryGetJSExtensionForFile(name, compilerOptions); return outputExtension ? { name: changeExtension(name, outputExtension), extension: outputExtension } : { name, extension: tryGetExtensionFromPath2(name) }; } -function addCompletionEntriesFromPaths(result, fragment, baseDirectory, extensionOptions, program, host, paths) { +function addCompletionEntriesFromPaths(result, fragment, baseDirectory, extensionOptions, host, paths) { const getPatternsForKey = (key) => paths[key]; const comparePaths2 = (a, b) => { const patternA = tryParsePattern(a); @@ -166818,14 +166710,13 @@ function addCompletionEntriesFromPaths(result, fragment, baseDirectory, extensio fragment, baseDirectory, extensionOptions, - program, host, getOwnKeys(paths), getPatternsForKey, comparePaths2 ); } -function addCompletionEntriesFromPathsOrExports(result, isExports, fragment, baseDirectory, extensionOptions, program, host, keys, getPatternsForKey, comparePaths2) { +function addCompletionEntriesFromPathsOrExports(result, isExports, fragment, baseDirectory, extensionOptions, host, keys, getPatternsForKey, comparePaths2) { let pathResults = []; let matchedPath; for (const key of keys) { @@ -166844,7 +166735,7 @@ function addCompletionEntriesFromPathsOrExports(result, isExports, fragment, bas if (typeof pathPattern === "string" || matchedPath === void 0 || comparePaths2(key, matchedPath) !== 1 /* GreaterThan */) { pathResults.push({ matchedPattern: isMatch, - results: getCompletionsForPathMapping(keyWithoutLeadingDotSlash, patterns, fragment, baseDirectory, extensionOptions, isExports && isMatch, program, host).map(({ name, kind, extension }) => nameAndKind(name, kind, extension)) + results: getCompletionsForPathMapping(keyWithoutLeadingDotSlash, patterns, fragment, baseDirectory, extensionOptions, isExports && isMatch, host).map(({ name, kind, extension }) => nameAndKind(name, kind, extension)) }); } } @@ -166852,9 +166743,7 @@ function addCompletionEntriesFromPathsOrExports(result, isExports, fragment, bas pathResults.forEach((pathResult) => pathResult.results.forEach((r) => result.add(r))); return matchedPath !== void 0; } -function getCompletionEntriesForNonRelativeModules(fragment, scriptPath, mode, program, host, extensionOptions) { - const typeChecker = program.getTypeChecker(); - const compilerOptions = program.getCompilerOptions(); +function getCompletionEntriesForNonRelativeModules(fragment, scriptPath, mode, compilerOptions, host, extensionOptions, typeChecker) { const { baseUrl, paths } = compilerOptions; const result = createNameAndKindSet(); const moduleResolution = getEmitModuleResolutionKind(compilerOptions); @@ -166864,7 +166753,6 @@ function getCompletionEntriesForNonRelativeModules(fragment, scriptPath, mode, p fragment, absolute, extensionOptions, - program, host, /*moduleSpecifierIsRelative*/ false, @@ -166875,7 +166763,7 @@ function getCompletionEntriesForNonRelativeModules(fragment, scriptPath, mode, p } if (paths) { const absolute = getPathsBasePath(compilerOptions, host); - addCompletionEntriesFromPaths(result, fragment, absolute, extensionOptions, program, host, paths); + addCompletionEntriesFromPaths(result, fragment, absolute, extensionOptions, host, paths); } const fragmentDirectory = getFragmentDirectory(fragment); for (const ambientName of getAmbientModuleCompletions(fragment, fragmentDirectory, typeChecker)) { @@ -166886,7 +166774,7 @@ function getCompletionEntriesForNonRelativeModules(fragment, scriptPath, mode, p void 0 )); } - getCompletionEntriesFromTypings(host, program, scriptPath, fragmentDirectory, extensionOptions, result); + getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, fragmentDirectory, extensionOptions, result); if (moduleResolutionUsesNodeModules(moduleResolution)) { let foundGlobal = false; if (fragmentDirectory === void 0) { @@ -166911,7 +166799,6 @@ function getCompletionEntriesForNonRelativeModules(fragment, scriptPath, mode, p fragment, nodeModules, extensionOptions, - program, host, /*moduleSpecifierIsRelative*/ false, @@ -166956,7 +166843,6 @@ function getCompletionEntriesForNonRelativeModules(fragment, scriptPath, mode, p fragmentSubpath, packageDirectory, extensionOptions, - program, host, keys, (key) => singleElementArray(getPatternFromFirstMatchingCondition(exports2[key], conditions)), @@ -166989,7 +166875,7 @@ function getPatternFromFirstMatchingCondition(target, conditions) { function getFragmentDirectory(fragment) { return containsSlash(fragment) ? hasTrailingDirectorySeparator(fragment) ? fragment : getDirectoryPath(fragment) : void 0; } -function getCompletionsForPathMapping(path, patterns, fragment, packageDirectory, extensionOptions, isExportsWildcard, program, host) { +function getCompletionsForPathMapping(path, patterns, fragment, packageDirectory, extensionOptions, isExportsWildcard, host) { if (!endsWith(path, "*")) { return !path.includes("*") ? justPathMappingName(path, "script" /* scriptElement */) : emptyArray; } @@ -166999,15 +166885,15 @@ function getCompletionsForPathMapping(path, patterns, fragment, packageDirectory const starIsFullPathComponent = path[path.length - 2] === "/"; return starIsFullPathComponent ? justPathMappingName(pathPrefix, "directory" /* directory */) : flatMap(patterns, (pattern) => { var _a; - return (_a = getModulesForPathsPattern("", packageDirectory, pattern, extensionOptions, isExportsWildcard, program, host)) == null ? void 0 : _a.map(({ name, ...rest }) => ({ name: pathPrefix + name, ...rest })); + return (_a = getModulesForPathsPattern("", packageDirectory, pattern, extensionOptions, isExportsWildcard, host)) == null ? void 0 : _a.map(({ name, ...rest }) => ({ name: pathPrefix + name, ...rest })); }); } - return flatMap(patterns, (pattern) => getModulesForPathsPattern(remainingFragment, packageDirectory, pattern, extensionOptions, isExportsWildcard, program, host)); + return flatMap(patterns, (pattern) => getModulesForPathsPattern(remainingFragment, packageDirectory, pattern, extensionOptions, isExportsWildcard, host)); function justPathMappingName(name, kind) { return startsWith(name, fragment) ? [{ name: removeTrailingDirectorySeparator(name), kind, extension: void 0 }] : emptyArray; } } -function getModulesForPathsPattern(fragment, packageDirectory, pattern, extensionOptions, isExportsWildcard, program, host) { +function getModulesForPathsPattern(fragment, packageDirectory, pattern, extensionOptions, isExportsWildcard, host) { if (!host.readDirectory) { return void 0; } @@ -167040,7 +166926,7 @@ function getModulesForPathsPattern(fragment, packageDirectory, pattern, extensio if (containsSlash(trimmedWithPattern)) { return directoryResult(getPathComponents(removeLeadingDirectorySeparator(trimmedWithPattern))[1]); } - const { name, extension } = getFilenameWithExtensionOption(trimmedWithPattern, program, extensionOptions, isExportsWildcard); + const { name, extension } = getFilenameWithExtensionOption(trimmedWithPattern, host.getCompilationSettings(), extensionOptions, isExportsWildcard); return nameAndKind(name, "script" /* scriptElement */, extension); } }); @@ -167068,8 +166954,7 @@ function getAmbientModuleCompletions(fragment, fragmentDirectory, checker) { } return nonRelativeModuleNames; } -function getTripleSlashReferenceCompletion(sourceFile, position, program, host) { - const compilerOptions = program.getCompilerOptions(); +function getTripleSlashReferenceCompletion(sourceFile, position, compilerOptions, host) { const token = getTokenAtPosition(sourceFile, position); const commentRanges = getLeadingCommentRanges(sourceFile.text, token.pos); const range = commentRanges && find(commentRanges, (commentRange) => position >= commentRange.pos && position <= commentRange.end); @@ -167087,16 +166972,14 @@ function getTripleSlashReferenceCompletion(sourceFile, position, program, host) toComplete, scriptPath, getExtensionOptions(compilerOptions, 0 /* Filename */, sourceFile), - program, host, /*moduleSpecifierIsRelative*/ true, sourceFile.path - ) : kind === "types" ? getCompletionEntriesFromTypings(host, program, scriptPath, getFragmentDirectory(toComplete), getExtensionOptions(compilerOptions, 1 /* ModuleSpecifier */, sourceFile)) : Debug.fail(); + ) : kind === "types" ? getCompletionEntriesFromTypings(host, compilerOptions, scriptPath, getFragmentDirectory(toComplete), getExtensionOptions(compilerOptions, 1 /* ModuleSpecifier */, sourceFile)) : Debug.fail(); return addReplacementSpans(toComplete, range.pos + prefix.length, arrayFrom(names.values())); } -function getCompletionEntriesFromTypings(host, program, scriptPath, fragmentDirectory, extensionOptions, result = createNameAndKindSet()) { - const options = program.getCompilerOptions(); +function getCompletionEntriesFromTypings(host, options, scriptPath, fragmentDirectory, extensionOptions, result = createNameAndKindSet()) { const seen = /* @__PURE__ */ new Map(); const typeRoots = tryAndIgnoreErrors(() => getEffectiveTypeRoots(options, host)) || emptyArray; for (const root of typeRoots) { @@ -167130,7 +167013,6 @@ function getCompletionEntriesFromTypings(host, program, scriptPath, fragmentDire remainingFragment, baseDirectory, extensionOptions, - program, host, /*moduleSpecifierIsRelative*/ false, @@ -178479,7 +178361,6 @@ __export(ts_exports2, { canHaveJSDoc: () => canHaveJSDoc, canHaveLocals: () => canHaveLocals, canHaveModifiers: () => canHaveModifiers, - canHaveModuleSpecifier: () => canHaveModuleSpecifier, canHaveSymbol: () => canHaveSymbol, canIncludeBindAndCheckDiagnsotics: () => canIncludeBindAndCheckDiagnsotics, canJsonReportNoInputFiles: () => canJsonReportNoInputFiles, @@ -178957,7 +178838,6 @@ __export(ts_exports2, { getDefaultLibFilePath: () => getDefaultLibFilePath, getDefaultLikeExportInfo: () => getDefaultLikeExportInfo, getDefaultLikeExportNameFromDeclaration: () => getDefaultLikeExportNameFromDeclaration, - getDefaultResolutionModeForFileWorker: () => getDefaultResolutionModeForFileWorker, getDiagnosticText: () => getDiagnosticText, getDiagnosticsWithinSpan: () => getDiagnosticsWithinSpan, getDirectoryPath: () => getDirectoryPath, @@ -178988,7 +178868,6 @@ __export(ts_exports2, { getEmitFlags: () => getEmitFlags, getEmitHelpers: () => getEmitHelpers, getEmitModuleDetectionKind: () => getEmitModuleDetectionKind, - getEmitModuleFormatOfFileWorker: () => getEmitModuleFormatOfFileWorker, getEmitModuleKind: () => getEmitModuleKind, getEmitModuleResolutionKind: () => getEmitModuleResolutionKind, getEmitScriptTarget: () => getEmitScriptTarget, @@ -179039,7 +178918,6 @@ __export(ts_exports2, { getIdentifierGeneratedImportReference: () => getIdentifierGeneratedImportReference, getIdentifierTypeArguments: () => getIdentifierTypeArguments, getImmediatelyInvokedFunctionExpression: () => getImmediatelyInvokedFunctionExpression, - getImpliedNodeFormatForEmitWorker: () => getImpliedNodeFormatForEmitWorker, getImpliedNodeFormatForFile: () => getImpliedNodeFormatForFile, getImpliedNodeFormatForFileWorker: () => getImpliedNodeFormatForFileWorker, getImportNeedsImportDefaultHelper: () => getImportNeedsImportDefaultHelper, @@ -179399,7 +179277,6 @@ __export(ts_exports2, { importDefaultHelper: () => importDefaultHelper, importFromModuleSpecifier: () => importFromModuleSpecifier, importStarHelper: () => importStarHelper, - importSyntaxAffectsModuleResolution: () => importSyntaxAffectsModuleResolution, indexOfAnyCharCode: () => indexOfAnyCharCode, indexOfNode: () => indexOfNode, indicesOf: () => indicesOf, @@ -180494,11 +180371,11 @@ __export(ts_exports2, { transformESDecorators: () => transformESDecorators, transformESNext: () => transformESNext, transformGenerators: () => transformGenerators, - transformImpliedNodeFormatDependentModule: () => transformImpliedNodeFormatDependentModule, transformJsx: () => transformJsx, transformLegacyDecorators: () => transformLegacyDecorators, transformModule: () => transformModule, transformNamedEvaluation: () => transformNamedEvaluation, + transformNodeModule: () => transformNodeModule, transformNodes: () => transformNodes, transformSystemModule: () => transformSystemModule, transformTypeScript: () => transformTypeScript, @@ -183869,8 +183746,11 @@ var Project3 = class _Project { const originalText = Debug.checkDefined(rootSourceFile.getText()); (_b = this.getScriptInfo(rootFile)) == null ? void 0 : _b.editContent(0, originalText.length, updatedText); this.updateGraph(); - cb(this.program, originalProgram, (_c = this.program) == null ? void 0 : _c.getSourceFile(rootFile)); - (_d = this.getScriptInfo(rootFile)) == null ? void 0 : _d.editContent(0, this.program.getSourceFile(rootFile).getText().length, originalText); + try { + cb(this.program, originalProgram, (_c = this.program) == null ? void 0 : _c.getSourceFile(rootFile)); + } finally { + (_d = this.getScriptInfo(rootFile)) == null ? void 0 : _d.editContent(0, this.program.getSourceFile(rootFile).getText().length, originalText); + } } /** @internal */ getCompilerOptionsForNoDtsResolutionProject() { @@ -192911,7 +192791,6 @@ if (typeof console !== "undefined") { canHaveJSDoc, canHaveLocals, canHaveModifiers, - canHaveModuleSpecifier, canHaveSymbol, canIncludeBindAndCheckDiagnsotics, canJsonReportNoInputFiles, @@ -193389,7 +193268,6 @@ if (typeof console !== "undefined") { getDefaultLibFilePath, getDefaultLikeExportInfo, getDefaultLikeExportNameFromDeclaration, - getDefaultResolutionModeForFileWorker, getDiagnosticText, getDiagnosticsWithinSpan, getDirectoryPath, @@ -193420,7 +193298,6 @@ if (typeof console !== "undefined") { getEmitFlags, getEmitHelpers, getEmitModuleDetectionKind, - getEmitModuleFormatOfFileWorker, getEmitModuleKind, getEmitModuleResolutionKind, getEmitScriptTarget, @@ -193471,7 +193348,6 @@ if (typeof console !== "undefined") { getIdentifierGeneratedImportReference, getIdentifierTypeArguments, getImmediatelyInvokedFunctionExpression, - getImpliedNodeFormatForEmitWorker, getImpliedNodeFormatForFile, getImpliedNodeFormatForFileWorker, getImportNeedsImportDefaultHelper, @@ -193831,7 +193707,6 @@ if (typeof console !== "undefined") { importDefaultHelper, importFromModuleSpecifier, importStarHelper, - importSyntaxAffectsModuleResolution, indexOfAnyCharCode, indexOfNode, indicesOf, @@ -194926,11 +194801,11 @@ if (typeof console !== "undefined") { transformESDecorators, transformESNext, transformGenerators, - transformImpliedNodeFormatDependentModule, transformJsx, transformLegacyDecorators, transformModule, transformNamedEvaluation, + transformNodeModule, transformNodes, transformSystemModule, transformTypeScript, @@ -195020,6 +194895,5 @@ if (typeof console !== "undefined") { writeFileEnsuringDirectories, zipWith }); -})(typeof module !== "undefined" && module.exports ? module : { exports: ts }); -if (typeof module !== "undefined" && module.exports) { ts = module.exports; } +})({ get exports() { return ts; }, set exports(v) { ts = v; if (typeof module !== "undefined" && module.exports) { module.exports = v; } } }) //# sourceMappingURL=typescript.js.map diff --git a/package-lock.json b/package-lock.json index 35b1ff92f74..0fd6163cf5f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "typescript", - "version": "5.5.1-rc", + "version": "5.5.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "typescript", - "version": "5.5.1-rc", + "version": "5.5.2", "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", diff --git a/package.json b/package.json index 3971b37079e..db4d4f448de 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "https://www.typescriptlang.org/", - "version": "5.5.1-rc", + "version": "5.5.2", "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ diff --git a/src/compiler/corePublic.ts b/src/compiler/corePublic.ts index cec8afac843..3d8748fc6e6 100644 --- a/src/compiler/corePublic.ts +++ b/src/compiler/corePublic.ts @@ -3,7 +3,7 @@ export const versionMajorMinor = "5.5"; // The following is baselined as a literal template type without intervention /** The version of the TypeScript compiler release */ -export const version = "5.5.1-rc" as string; +export const version = "5.5.2" as string; /** * Type of objects whose values are all of the same type.