diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 84b111555df7e..019079a2f312e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -332,6 +332,7 @@ import { getLineAndCharacterOfPosition, getMembersOfDeclaration, getModifiers, + getModuleFormatInteropKind, getModuleInstanceState, getNameFromImportAttribute, getNameFromIndexInfo, @@ -859,6 +860,7 @@ import { modifierToFlag, ModuleBlock, ModuleDeclaration, + ModuleFormatInteropKind, ModuleInstanceState, ModuleKind, ModuleResolutionKind, @@ -3634,7 +3636,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { const usageMode = file && getEmitSyntaxForModuleSpecifierExpression(usage); if (file && usageMode !== undefined) { const targetMode = host.getImpliedNodeFormatForEmit(file); - if (usageMode === ModuleKind.ESNext && targetMode === ModuleKind.CommonJS && ModuleKind.Node16 <= moduleKind && moduleKind <= ModuleKind.NodeNext) { + const moduleFormatInterop = getModuleFormatInteropKind(compilerOptions); + const usesNodeLikeInteropRules = moduleFormatInterop === ModuleFormatInteropKind.BundlerNode + || ModuleFormatInteropKind.Node16 <= moduleFormatInterop && moduleFormatInterop <= ModuleFormatInteropKind.NodeNext; + if (usageMode === ModuleKind.ESNext && targetMode !== ModuleKind.ESNext && usesNodeLikeInteropRules) { // In Node.js, CommonJS modules always have a synthetic default when imported into ESM return true; } @@ -3649,6 +3654,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { } // Declaration files (and ambient modules) if (!file || file.isDeclarationFile) { + // Unambiguously ESM files do not have a synthetic default + if (file && host.getImpliedNodeFormatForEmit(file) === ModuleKind.ESNext) { + return false; + } // Definitely cannot have a synthetic default if they have a syntactic default member specified const defaultExportSymbol = resolveExportByName(moduleSymbol, InternalSymbolName.Default, /*sourceNode*/ undefined, /*dontResolveAlias*/ true); // Dont resolve alias because we want the immediately exported symbol's declaration if (defaultExportSymbol && some(defaultExportSymbol.declarations, isSyntacticDefault)) { @@ -4572,6 +4581,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { ? host.getModeForUsageLocation(currentSourceFile, contextSpecifier) : host.getDefaultResolutionModeForFile(currentSourceFile); const moduleResolutionKind = getEmitModuleResolutionKind(compilerOptions); + const moduleFormatInterop = getModuleFormatInteropKind(compilerOptions); const resolvedModule = host.getResolvedModule(currentSourceFile, moduleReference, mode)?.resolvedModule; const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule, currentSourceFile); const sourceFile = resolvedModule @@ -4607,7 +4617,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { if (resolvedModule.isExternalLibraryImport && !resolutionExtensionIsTSOrJson(resolvedModule.extension)) { errorOnImplicitAnyModule(/*isError*/ false, errorNode, currentSourceFile, mode, resolvedModule, moduleReference); } - if (moduleResolutionKind === ModuleResolutionKind.Node16 || moduleResolutionKind === ModuleResolutionKind.NodeNext) { + if (ModuleFormatInteropKind.Node16 <= moduleFormatInterop && moduleFormatInterop <= ModuleFormatInteropKind.NodeNext) { const isSyncImport = (currentSourceFile.impliedNodeFormat === ModuleKind.CommonJS && !findAncestor(location, isImportCall)) || !!findAncestor(location, isImportEqualsDeclaration); const overrideHost = findAncestor(location, l => isImportTypeNode(l) || isExportDeclaration(l) || isImportDeclaration(l)) as ImportTypeNode | ImportDeclaration | ExportDeclaration | undefined; // An override clause will take effect for type-only imports and import types, and allows importing the types across formats, regardless of diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 52db793b070a8..c8ee9e8b3d6ef 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -83,6 +83,7 @@ import { mapIterator, MapLike, ModuleDetectionKind, + ModuleFormatInteropKind, ModuleKind, ModuleResolutionKind, NewLineKind, @@ -1196,6 +1197,20 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [ category: Diagnostics.Modules, description: Diagnostics.Conditions_to_set_in_addition_to_the_resolver_specific_defaults_when_resolving_imports, }, + { + name: "moduleFormatInterop", + type: new Map(Object.entries({ + bundler: ModuleFormatInteropKind.Bundler, + bundlernode: ModuleFormatInteropKind.BundlerNode, + node16: ModuleFormatInteropKind.Node16, + nodenext: ModuleFormatInteropKind.NodeNext, + })), + affectsSemanticDiagnostics: true, + affectsBuildInfo: true, + category: Diagnostics.Modules, + description: Diagnostics.Specify_the_target_runtime_s_rules_for_ESM_CommonJS_interoperation, + defaultValueDescription: Diagnostics.node16_when_module_is_node16_nodenext_when_module_is_nodenext_bundler_otherwise, + }, // Source Maps { diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 1db3b8c70bc30..d92d7d7d2ec0d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -6392,6 +6392,10 @@ "category": "Message", "code": 6805 }, + "Specify the target runtime's rules for ESM-CommonJS interoperation.": { + "category": "Message", + "code": 6806 + }, "one of:": { "category": "Message", @@ -6521,6 +6525,10 @@ "category": "Error", "code": 6931 }, + "'node16' when 'module' is 'node16'; 'nodenext' when 'module' is 'nodenext'; 'bundler' otherwise.": { + "category": "Message", + "code": 6932 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1b737bd261363..9ae921aab7d54 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -7290,6 +7290,7 @@ export interface CompilerOptions { mapRoot?: string; maxNodeModuleJsDepth?: number; module?: ModuleKind; + moduleFormatInterop?: ModuleFormatInteropKind; moduleResolution?: ModuleResolutionKind; moduleSuffixes?: string[]; moduleDetection?: ModuleDetectionKind; @@ -7423,6 +7424,14 @@ export enum ModuleKind { Preserve = 200, } +export enum ModuleFormatInteropKind { + Bundler = 1, + BundlerNode = 2, + + Node16 = 100, + NodeNext = 199, +} + export const enum JsxEmit { None = 0, Preserve = 1, diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 655c35eacf576..b9c53eff71f28 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -420,6 +420,7 @@ import { ModuleBlock, ModuleDeclaration, ModuleDetectionKind, + ModuleFormatInteropKind, ModuleKind, ModuleResolutionKind, moduleResolutionOptionDeclarations, @@ -8852,6 +8853,22 @@ export const computedOptions = createComputedCompilerOptions({ computedOptions.module.computeValue(compilerOptions) === ModuleKind.NodeNext ? ModuleDetectionKind.Force : ModuleDetectionKind.Auto); }, }, + moduleFormatInterop: { + dependencies: ["module", "target"], + computeValue: (compilerOptions): ModuleFormatInteropKind => { + if (compilerOptions.moduleFormatInterop !== undefined) { + return compilerOptions.moduleFormatInterop; + } + switch (computedOptions.module.computeValue(compilerOptions)) { + case ModuleKind.Node16: + return ModuleFormatInteropKind.Node16; + case ModuleKind.NodeNext: + return ModuleFormatInteropKind.NodeNext; + default: + return ModuleFormatInteropKind.Bundler; + } + }, + }, isolatedModules: { dependencies: ["verbatimModuleSyntax"], computeValue: compilerOptions => { @@ -9028,6 +9045,8 @@ export const getEmitModuleResolutionKind = computedOptions.moduleResolution.comp /** @internal */ export const getEmitModuleDetectionKind = computedOptions.moduleDetection.computeValue; /** @internal */ +export const getModuleFormatInteropKind = computedOptions.moduleFormatInterop.computeValue; +/** @internal */ export const getIsolatedModules = computedOptions.isolatedModules.computeValue; /** @internal */ export const getESModuleInterop = computedOptions.esModuleInterop.computeValue; diff --git a/src/testRunner/compilerRunner.ts b/src/testRunner/compilerRunner.ts index 93bc55c1159fe..491d4aaa31828 100644 --- a/src/testRunner/compilerRunner.ts +++ b/src/testRunner/compilerRunner.ts @@ -142,6 +142,7 @@ class CompilerTest { "jsx", "module", "moduleDetection", + "moduleFormatInterop", "moduleResolution", "noEmit", "noImplicitAny", diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index b1ac4827d4fd1..51da08c2b5b92 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -6942,6 +6942,7 @@ declare namespace ts { mapRoot?: string; maxNodeModuleJsDepth?: number; module?: ModuleKind; + moduleFormatInterop?: ModuleFormatInteropKind; moduleResolution?: ModuleResolutionKind; moduleSuffixes?: string[]; moduleDetection?: ModuleDetectionKind; @@ -7044,6 +7045,12 @@ declare namespace ts { NodeNext = 199, Preserve = 200, } + enum ModuleFormatInteropKind { + Bundler = 1, + BundlerNode = 2, + Node16 = 100, + NodeNext = 199, + } enum JsxEmit { None = 0, Preserve = 1, diff --git a/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json index 8bb6097f80145..5a56795a3ae2a 100644 --- a/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json @@ -39,6 +39,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "moduleFormatInterop": "bundler", /* Specify the target runtime's rules for ESM-CommonJS interoperation. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json index 8bb6097f80145..5a56795a3ae2a 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json @@ -39,6 +39,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "moduleFormatInterop": "bundler", /* Specify the target runtime's rules for ESM-CommonJS interoperation. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json index 8bb6097f80145..5a56795a3ae2a 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json @@ -39,6 +39,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "moduleFormatInterop": "bundler", /* Specify the target runtime's rules for ESM-CommonJS interoperation. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json index b3d05912583d9..b6658b53e2557 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json @@ -39,6 +39,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "moduleFormatInterop": "bundler", /* Specify the target runtime's rules for ESM-CommonJS interoperation. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json index 558f4243438d2..e2e05e893aa2b 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json @@ -39,6 +39,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "moduleFormatInterop": "bundler", /* Specify the target runtime's rules for ESM-CommonJS interoperation. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json index 5679f8b921cdf..a65503ad8635b 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json @@ -39,6 +39,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "moduleFormatInterop": "bundler", /* Specify the target runtime's rules for ESM-CommonJS interoperation. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json index 535e6a2d97860..71ec6feaece2b 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json @@ -39,6 +39,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "moduleFormatInterop": "bundler", /* Specify the target runtime's rules for ESM-CommonJS interoperation. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json index da587b6bded7f..a98705ca32b88 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json @@ -39,6 +39,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "moduleFormatInterop": "bundler", /* Specify the target runtime's rules for ESM-CommonJS interoperation. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json index 8bb6097f80145..5a56795a3ae2a 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json @@ -39,6 +39,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "moduleFormatInterop": "bundler", /* Specify the target runtime's rules for ESM-CommonJS interoperation. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json index a6e74d92a6a8f..a2707a9da3733 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json @@ -39,6 +39,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "moduleFormatInterop": "bundler", /* Specify the target runtime's rules for ESM-CommonJS interoperation. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json index 41c2964e0e7fa..032982d928e31 100644 --- a/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json +++ b/tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json @@ -39,6 +39,7 @@ // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */ // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */ // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */ + // "moduleFormatInterop": "bundler", /* Specify the target runtime's rules for ESM-CommonJS interoperation. */ // "resolveJsonModule": true, /* Enable importing .json files. */ // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */ // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ diff --git a/tests/baselines/reference/config/showConfig/Shows tsconfig for single option/moduleFormatInterop/tsconfig.json b/tests/baselines/reference/config/showConfig/Shows tsconfig for single option/moduleFormatInterop/tsconfig.json new file mode 100644 index 0000000000000..f4972329728c4 --- /dev/null +++ b/tests/baselines/reference/config/showConfig/Shows tsconfig for single option/moduleFormatInterop/tsconfig.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + "moduleFormatInterop": "bundler" + } +} diff --git a/tests/baselines/reference/esbuildInterop(moduleformatinterop=bundler).errors.txt b/tests/baselines/reference/esbuildInterop(moduleformatinterop=bundler).errors.txt new file mode 100644 index 0000000000000..981e8790b6dc8 --- /dev/null +++ b/tests/baselines/reference/esbuildInterop(moduleformatinterop=bundler).errors.txt @@ -0,0 +1,26 @@ +/index.ts(3,5): error TS2339: Property 'default' does not exist on type 'string'. + + +==== /node_modules/dep/package.json (0 errors) ==== + { + "name": "dep", + "version": "1.0.0", + "main": "index.js" + } + +==== /node_modules/dep/index.d.ts (0 errors) ==== + declare const _default: string; + export default _default; + +==== /package.json (0 errors) ==== + { + "type": "module" + } + +==== /index.ts (1 errors) ==== + import dep from "dep"; + dep.toLowerCase(); // Error in bundlernode + dep.default.toLowerCase(); // Error in bundler + ~~~~~~~ +!!! error TS2339: Property 'default' does not exist on type 'string'. + \ No newline at end of file diff --git a/tests/baselines/reference/esbuildInterop(moduleformatinterop=bundlernode).errors.txt b/tests/baselines/reference/esbuildInterop(moduleformatinterop=bundlernode).errors.txt new file mode 100644 index 0000000000000..7c25932f39bf8 --- /dev/null +++ b/tests/baselines/reference/esbuildInterop(moduleformatinterop=bundlernode).errors.txt @@ -0,0 +1,26 @@ +/index.ts(2,5): error TS2339: Property 'toLowerCase' does not exist on type 'typeof import("/node_modules/dep/index")'. + + +==== /node_modules/dep/package.json (0 errors) ==== + { + "name": "dep", + "version": "1.0.0", + "main": "index.js" + } + +==== /node_modules/dep/index.d.ts (0 errors) ==== + declare const _default: string; + export default _default; + +==== /package.json (0 errors) ==== + { + "type": "module" + } + +==== /index.ts (1 errors) ==== + import dep from "dep"; + dep.toLowerCase(); // Error in bundlernode + ~~~~~~~~~~~ +!!! error TS2339: Property 'toLowerCase' does not exist on type 'typeof import("/node_modules/dep/index")'. + dep.default.toLowerCase(); // Error in bundler + \ No newline at end of file diff --git a/tests/cases/conformance/module/esbuildInterop.ts b/tests/cases/conformance/module/esbuildInterop.ts new file mode 100644 index 0000000000000..751664a66e75a --- /dev/null +++ b/tests/cases/conformance/module/esbuildInterop.ts @@ -0,0 +1,26 @@ +// @module: esnext +// @moduleResolution: bundler +// @moduleFormatInterop: bundler, bundlernode +// @noEmit: true +// @noTypesAndSymbols: true + +// @Filename: /node_modules/dep/package.json +{ + "name": "dep", + "version": "1.0.0", + "main": "index.js" +} + +// @Filename: /node_modules/dep/index.d.ts +declare const _default: string; +export default _default; + +// @Filename: /package.json +{ + "type": "module" +} + +// @Filename: /index.ts +import dep from "dep"; +dep.toLowerCase(); // Error in bundlernode +dep.default.toLowerCase(); // Error in bundler