mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 05:41:22 -06:00
Modify synthetic default generation code for dual-mode module resolution (#46156)
This commit is contained in:
parent
016d78b09e
commit
ccc19092ff
@ -2629,7 +2629,23 @@ namespace ts {
|
||||
return ((isExportAssignment(node) && !node.isExportEquals) || hasSyntacticModifier(node, ModifierFlags.Default) || isExportSpecifier(node));
|
||||
}
|
||||
|
||||
function canHaveSyntheticDefault(file: SourceFile | undefined, moduleSymbol: Symbol, dontResolveAlias: boolean) {
|
||||
function getUsageModeForExpression(usage: Expression) {
|
||||
return isStringLiteralLike(usage) ? getModeForUsageLocation(getSourceFileOfNode(usage), usage) : undefined;
|
||||
}
|
||||
|
||||
function isESMFormatImportImportingCommonjsFormatFile(usageMode: SourceFile["impliedNodeFormat"], targetMode: SourceFile["impliedNodeFormat"]) {
|
||||
return usageMode === ModuleKind.ESNext && targetMode === ModuleKind.CommonJS;
|
||||
}
|
||||
|
||||
function canHaveSyntheticDefault(file: SourceFile | undefined, moduleSymbol: Symbol, dontResolveAlias: boolean, usage: Expression) {
|
||||
const usageMode = file && getUsageModeForExpression(usage);
|
||||
if (file && usageMode !== undefined) {
|
||||
const result = isESMFormatImportImportingCommonjsFormatFile(usageMode, file.impliedNodeFormat);
|
||||
if (usageMode === ModuleKind.ESNext || result) {
|
||||
return result;
|
||||
}
|
||||
// fallthrough on cjs usages so we imply defaults for interop'd imports, too
|
||||
}
|
||||
if (!allowSyntheticDefaultImports) {
|
||||
return false;
|
||||
}
|
||||
@ -2672,7 +2688,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
const file = moduleSymbol.declarations?.find(isSourceFile);
|
||||
const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias);
|
||||
const hasSyntheticDefault = canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, node.parent.moduleSpecifier);
|
||||
if (!exportDefaultSymbol && !hasSyntheticDefault) {
|
||||
if (hasExportAssignmentSymbol(moduleSymbol)) {
|
||||
const compilerOptionName = moduleKind >= ModuleKind.ES2015 ? "allowSyntheticDefaultImports" : "esModuleInterop";
|
||||
@ -2824,7 +2840,7 @@ namespace ts {
|
||||
let symbolFromModule = getExportOfModule(targetSymbol, name, specifier, dontResolveAlias);
|
||||
if (symbolFromModule === undefined && name.escapedText === InternalSymbolName.Default) {
|
||||
const file = moduleSymbol.declarations?.find(isSourceFile);
|
||||
if (canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias)) {
|
||||
if (canHaveSyntheticDefault(file, moduleSymbol, dontResolveAlias, moduleSpecifier)) {
|
||||
symbolFromModule = resolveExternalModuleSymbol(moduleSymbol, dontResolveAlias) || resolveSymbol(moduleSymbol, dontResolveAlias);
|
||||
}
|
||||
}
|
||||
@ -3587,7 +3603,7 @@ namespace ts {
|
||||
sigs = getSignaturesOfStructuredType(type, SignatureKind.Construct);
|
||||
}
|
||||
if (sigs && sigs.length) {
|
||||
const moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol!);
|
||||
const moduleType = getTypeWithSyntheticDefaultImportType(type, symbol, moduleSymbol!, isImportCall(referenceParent) ? referenceParent.arguments[0] : referenceParent.moduleSpecifier);
|
||||
// Create a new symbol which has the module's type less the call and construct signatures
|
||||
const result = createSymbol(symbol.flags, symbol.escapedName);
|
||||
result.declarations = symbol.declarations ? symbol.declarations.slice() : [];
|
||||
@ -30945,18 +30961,18 @@ namespace ts {
|
||||
if (moduleSymbol) {
|
||||
const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true, /*suppressUsageError*/ false);
|
||||
if (esModuleSymbol) {
|
||||
return createPromiseReturnType(node, getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol));
|
||||
return createPromiseReturnType(node, getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol, moduleSymbol, specifier));
|
||||
}
|
||||
}
|
||||
return createPromiseReturnType(node, anyType);
|
||||
}
|
||||
|
||||
function getTypeWithSyntheticDefaultImportType(type: Type, symbol: Symbol, originalSymbol: Symbol): Type {
|
||||
function getTypeWithSyntheticDefaultImportType(type: Type, symbol: Symbol, originalSymbol: Symbol, moduleSpecifier: Expression): Type {
|
||||
if (allowSyntheticDefaultImports && type && !isErrorType(type)) {
|
||||
const synthType = type as SyntheticDefaultModuleType;
|
||||
if (!synthType.syntheticType) {
|
||||
const file = originalSymbol.declarations?.find(isSourceFile);
|
||||
const hasSyntheticDefault = canHaveSyntheticDefault(file, originalSymbol, /*dontResolveAlias*/ false);
|
||||
const hasSyntheticDefault = canHaveSyntheticDefault(file, originalSymbol, /*dontResolveAlias*/ false, moduleSpecifier);
|
||||
if (hasSyntheticDefault) {
|
||||
const memberTable = createSymbolTable();
|
||||
const newSymbol = createSymbol(SymbolFlags.Alias, InternalSymbolName.Default);
|
||||
|
||||
@ -23,9 +23,9 @@ export async function f() {
|
||||
>"../index.js" : "../index.js"
|
||||
|
||||
const mod4 = await import ("./index.js");
|
||||
>mod4 : typeof mod2
|
||||
>await import ("./index.js") : typeof mod2
|
||||
>import ("./index.js") : Promise<typeof mod2>
|
||||
>mod4 : { default: typeof mod2; f(): Promise<void>; }
|
||||
>await import ("./index.js") : { default: typeof mod2; f(): Promise<void>; }
|
||||
>import ("./index.js") : Promise<{ default: typeof mod2; f(): Promise<void>; }>
|
||||
>"./index.js" : "./index.js"
|
||||
|
||||
h();
|
||||
@ -57,9 +57,9 @@ export async function h() {
|
||||
>"./index.js" : "./index.js"
|
||||
|
||||
const mod4 = await import ("./subfolder/index.js");
|
||||
>mod4 : typeof mod2
|
||||
>await import ("./subfolder/index.js") : typeof mod2
|
||||
>import ("./subfolder/index.js") : Promise<typeof mod2>
|
||||
>mod4 : { default: typeof mod2; f(): Promise<void>; }
|
||||
>await import ("./subfolder/index.js") : { default: typeof mod2; f(): Promise<void>; }
|
||||
>import ("./subfolder/index.js") : Promise<{ default: typeof mod2; f(): Promise<void>; }>
|
||||
>"./subfolder/index.js" : "./subfolder/index.js"
|
||||
|
||||
f();
|
||||
|
||||
@ -23,9 +23,9 @@ export async function f() {
|
||||
>"../index.js" : "../index.js"
|
||||
|
||||
const mod4 = await import ("./index.js");
|
||||
>mod4 : typeof mod2
|
||||
>await import ("./index.js") : typeof mod2
|
||||
>import ("./index.js") : Promise<typeof mod2>
|
||||
>mod4 : { default: typeof mod2; f(): Promise<void>; }
|
||||
>await import ("./index.js") : { default: typeof mod2; f(): Promise<void>; }
|
||||
>import ("./index.js") : Promise<{ default: typeof mod2; f(): Promise<void>; }>
|
||||
>"./index.js" : "./index.js"
|
||||
|
||||
h();
|
||||
@ -57,9 +57,9 @@ export async function h() {
|
||||
>"./index.js" : "./index.js"
|
||||
|
||||
const mod4 = await import ("./subfolder/index.js");
|
||||
>mod4 : typeof mod2
|
||||
>await import ("./subfolder/index.js") : typeof mod2
|
||||
>import ("./subfolder/index.js") : Promise<typeof mod2>
|
||||
>mod4 : { default: typeof mod2; f(): Promise<void>; }
|
||||
>await import ("./subfolder/index.js") : { default: typeof mod2; f(): Promise<void>; }
|
||||
>import ("./subfolder/index.js") : Promise<{ default: typeof mod2; f(): Promise<void>; }>
|
||||
>"./subfolder/index.js" : "./subfolder/index.js"
|
||||
|
||||
f();
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
//// [tests/cases/conformance/node/nodeModulesCjsFormatFileAlwaysHasDefault.ts] ////
|
||||
|
||||
//// [index.ts]
|
||||
// cjs format file
|
||||
export const a = 1;
|
||||
//// [index.ts]
|
||||
// esm format file
|
||||
import mod from "./subfolder/index.js";
|
||||
mod;
|
||||
//// [package.json]
|
||||
{
|
||||
"name": "package",
|
||||
"private": true,
|
||||
"type": "module"
|
||||
}
|
||||
//// [package.json]
|
||||
{
|
||||
"type": "commonjs"
|
||||
}
|
||||
|
||||
//// [index.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.a = void 0;
|
||||
// cjs format file
|
||||
exports.a = 1;
|
||||
//// [index.js]
|
||||
// esm format file
|
||||
import mod from "./subfolder/index.js";
|
||||
mod;
|
||||
|
||||
|
||||
//// [index.d.ts]
|
||||
export declare const a = 1;
|
||||
//// [index.d.ts]
|
||||
export {};
|
||||
@ -0,0 +1,13 @@
|
||||
=== tests/cases/conformance/node/subfolder/index.ts ===
|
||||
// cjs format file
|
||||
export const a = 1;
|
||||
>a : Symbol(a, Decl(index.ts, 1, 12))
|
||||
|
||||
=== tests/cases/conformance/node/index.ts ===
|
||||
// esm format file
|
||||
import mod from "./subfolder/index.js";
|
||||
>mod : Symbol(mod, Decl(index.ts, 1, 6))
|
||||
|
||||
mod;
|
||||
>mod : Symbol(mod, Decl(index.ts, 1, 6))
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
=== tests/cases/conformance/node/subfolder/index.ts ===
|
||||
// cjs format file
|
||||
export const a = 1;
|
||||
>a : 1
|
||||
>1 : 1
|
||||
|
||||
=== tests/cases/conformance/node/index.ts ===
|
||||
// esm format file
|
||||
import mod from "./subfolder/index.js";
|
||||
>mod : typeof mod
|
||||
|
||||
mod;
|
||||
>mod : typeof mod
|
||||
|
||||
@ -0,0 +1,36 @@
|
||||
//// [tests/cases/conformance/node/nodeModulesCjsFormatFileAlwaysHasDefault.ts] ////
|
||||
|
||||
//// [index.ts]
|
||||
// cjs format file
|
||||
export const a = 1;
|
||||
//// [index.ts]
|
||||
// esm format file
|
||||
import mod from "./subfolder/index.js";
|
||||
mod;
|
||||
//// [package.json]
|
||||
{
|
||||
"name": "package",
|
||||
"private": true,
|
||||
"type": "module"
|
||||
}
|
||||
//// [package.json]
|
||||
{
|
||||
"type": "commonjs"
|
||||
}
|
||||
|
||||
//// [index.js]
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.a = void 0;
|
||||
// cjs format file
|
||||
exports.a = 1;
|
||||
//// [index.js]
|
||||
// esm format file
|
||||
import mod from "./subfolder/index.js";
|
||||
mod;
|
||||
|
||||
|
||||
//// [index.d.ts]
|
||||
export declare const a = 1;
|
||||
//// [index.d.ts]
|
||||
export {};
|
||||
@ -0,0 +1,13 @@
|
||||
=== tests/cases/conformance/node/subfolder/index.ts ===
|
||||
// cjs format file
|
||||
export const a = 1;
|
||||
>a : Symbol(a, Decl(index.ts, 1, 12))
|
||||
|
||||
=== tests/cases/conformance/node/index.ts ===
|
||||
// esm format file
|
||||
import mod from "./subfolder/index.js";
|
||||
>mod : Symbol(mod, Decl(index.ts, 1, 6))
|
||||
|
||||
mod;
|
||||
>mod : Symbol(mod, Decl(index.ts, 1, 6))
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
=== tests/cases/conformance/node/subfolder/index.ts ===
|
||||
// cjs format file
|
||||
export const a = 1;
|
||||
>a : 1
|
||||
>1 : 1
|
||||
|
||||
=== tests/cases/conformance/node/index.ts ===
|
||||
// esm format file
|
||||
import mod from "./subfolder/index.js";
|
||||
>mod : typeof mod
|
||||
|
||||
mod;
|
||||
>mod : typeof mod
|
||||
|
||||
@ -122,7 +122,9 @@ export {};
|
||||
//// [index.d.cts]
|
||||
export {};
|
||||
//// [other.d.ts]
|
||||
export declare const a: typeof import("package/cjs");
|
||||
export declare const a: {
|
||||
default: typeof import("package/cjs");
|
||||
};
|
||||
export declare const b: typeof import("package/mjs");
|
||||
export declare const c: typeof import("package");
|
||||
export declare const f: {
|
||||
@ -134,12 +136,11 @@ export declare const d: {
|
||||
default: typeof import("inner/cjs");
|
||||
cjsNonmain: true;
|
||||
};
|
||||
export declare const e: {
|
||||
default: typeof import("inner/mjs");
|
||||
esm: true;
|
||||
};
|
||||
export declare const e: typeof import("inner/mjs");
|
||||
//// [other.d.mts]
|
||||
export declare const a: typeof import("package/cjs");
|
||||
export declare const a: {
|
||||
default: typeof import("package/cjs");
|
||||
};
|
||||
export declare const b: typeof import("package/mjs");
|
||||
export declare const c: typeof import("package");
|
||||
export declare const f: {
|
||||
@ -151,12 +152,11 @@ export declare const d: {
|
||||
default: typeof import("inner/cjs");
|
||||
cjsNonmain: true;
|
||||
};
|
||||
export declare const e: {
|
||||
default: typeof import("inner/mjs");
|
||||
esm: true;
|
||||
};
|
||||
export declare const e: typeof import("inner/mjs");
|
||||
//// [other.d.cts]
|
||||
export declare const a: Promise<typeof import("package/cjs")>;
|
||||
export declare const a: Promise<{
|
||||
default: typeof import("package/cjs");
|
||||
}>;
|
||||
export declare const b: Promise<typeof import("package/mjs")>;
|
||||
export declare const c: Promise<typeof import("package")>;
|
||||
export declare const f: Promise<{
|
||||
@ -168,18 +168,15 @@ export declare const d: Promise<{
|
||||
default: typeof import("inner/cjs");
|
||||
cjsNonmain: true;
|
||||
}>;
|
||||
export declare const e: Promise<{
|
||||
default: typeof import("inner/mjs");
|
||||
esm: true;
|
||||
}>;
|
||||
export declare const e: Promise<typeof import("inner/mjs")>;
|
||||
|
||||
|
||||
//// [DtsFileErrors]
|
||||
|
||||
|
||||
tests/cases/conformance/node/other.d.cts(2,47): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.
|
||||
tests/cases/conformance/node/other.d.cts(3,47): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.
|
||||
tests/cases/conformance/node/other2.d.cts(6,28): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.
|
||||
tests/cases/conformance/node/other.d.cts(4,47): error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.
|
||||
tests/cases/conformance/node/other.d.cts(5,47): error TS1471: Module 'package' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.
|
||||
tests/cases/conformance/node/other2.d.cts(5,47): error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.
|
||||
|
||||
|
||||
==== tests/cases/conformance/node/index.d.ts (0 errors) ====
|
||||
@ -192,7 +189,9 @@ tests/cases/conformance/node/other2.d.cts(6,28): error TS1471: Module 'inner/mjs
|
||||
export {};
|
||||
|
||||
==== tests/cases/conformance/node/other.d.ts (0 errors) ====
|
||||
export declare const a: typeof import("package/cjs");
|
||||
export declare const a: {
|
||||
default: typeof import("package/cjs");
|
||||
};
|
||||
export declare const b: typeof import("package/mjs");
|
||||
export declare const c: typeof import("package");
|
||||
export declare const f: {
|
||||
@ -205,13 +204,12 @@ tests/cases/conformance/node/other2.d.cts(6,28): error TS1471: Module 'inner/mjs
|
||||
default: typeof import("inner/cjs");
|
||||
cjsNonmain: true;
|
||||
};
|
||||
export declare const e: {
|
||||
default: typeof import("inner/mjs");
|
||||
esm: true;
|
||||
};
|
||||
export declare const e: typeof import("inner/mjs");
|
||||
|
||||
==== tests/cases/conformance/node/other.d.mts (0 errors) ====
|
||||
export declare const a: typeof import("package/cjs");
|
||||
export declare const a: {
|
||||
default: typeof import("package/cjs");
|
||||
};
|
||||
export declare const b: typeof import("package/mjs");
|
||||
export declare const c: typeof import("package");
|
||||
export declare const f: {
|
||||
@ -224,13 +222,12 @@ tests/cases/conformance/node/other2.d.cts(6,28): error TS1471: Module 'inner/mjs
|
||||
default: typeof import("inner/cjs");
|
||||
cjsNonmain: true;
|
||||
};
|
||||
export declare const e: {
|
||||
default: typeof import("inner/mjs");
|
||||
esm: true;
|
||||
};
|
||||
export declare const e: typeof import("inner/mjs");
|
||||
|
||||
==== tests/cases/conformance/node/other.d.cts (2 errors) ====
|
||||
export declare const a: Promise<typeof import("package/cjs")>;
|
||||
export declare const a: Promise<{
|
||||
default: typeof import("package/cjs");
|
||||
}>;
|
||||
export declare const b: Promise<typeof import("package/mjs")>;
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS1471: Module 'package/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.
|
||||
@ -247,12 +244,9 @@ tests/cases/conformance/node/other2.d.cts(6,28): error TS1471: Module 'inner/mjs
|
||||
default: typeof import("inner/cjs");
|
||||
cjsNonmain: true;
|
||||
}>;
|
||||
export declare const e: Promise<{
|
||||
default: typeof import("inner/mjs");
|
||||
~~~~~~~~~~~
|
||||
export declare const e: Promise<typeof import("inner/mjs")>;
|
||||
~~~~~~~~~~~
|
||||
!!! error TS1471: Module 'inner/mjs' cannot be imported using this construct. The specifier only resolves to an ES module, which cannot be imported synchronously. Use dynamic import instead.
|
||||
esm: true;
|
||||
}>;
|
||||
|
||||
==== tests/cases/conformance/node/node_modules/inner/index.d.ts (0 errors) ====
|
||||
// cjs format file
|
||||
|
||||
@ -10,9 +10,9 @@ No type information for this code.export {};
|
||||
No type information for this code.=== tests/cases/conformance/node/other.ts ===
|
||||
// esm format file
|
||||
export const a = await import("package/cjs");
|
||||
>a : typeof import("tests/cases/conformance/node/index")
|
||||
>await import("package/cjs") : typeof import("tests/cases/conformance/node/index")
|
||||
>import("package/cjs") : Promise<typeof import("tests/cases/conformance/node/index")>
|
||||
>a : { default: typeof import("tests/cases/conformance/node/index"); }
|
||||
>await import("package/cjs") : { default: typeof import("tests/cases/conformance/node/index"); }
|
||||
>import("package/cjs") : Promise<{ default: typeof import("tests/cases/conformance/node/index"); }>
|
||||
>"package/cjs" : "package/cjs"
|
||||
|
||||
export const b = await import("package/mjs");
|
||||
@ -42,17 +42,17 @@ export const d = await import("inner/cjs");
|
||||
>"inner/cjs" : "inner/cjs"
|
||||
|
||||
export const e = await import("inner/mjs");
|
||||
>e : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; }
|
||||
>await import("inner/mjs") : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; }
|
||||
>import("inner/mjs") : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; }>
|
||||
>e : typeof import("tests/cases/conformance/node/node_modules/inner/index")
|
||||
>await import("inner/mjs") : typeof import("tests/cases/conformance/node/node_modules/inner/index")
|
||||
>import("inner/mjs") : Promise<typeof import("tests/cases/conformance/node/node_modules/inner/index")>
|
||||
>"inner/mjs" : "inner/mjs"
|
||||
|
||||
=== tests/cases/conformance/node/other.mts ===
|
||||
// esm format file
|
||||
export const a = await import("package/cjs");
|
||||
>a : typeof import("tests/cases/conformance/node/index")
|
||||
>await import("package/cjs") : typeof import("tests/cases/conformance/node/index")
|
||||
>import("package/cjs") : Promise<typeof import("tests/cases/conformance/node/index")>
|
||||
>a : { default: typeof import("tests/cases/conformance/node/index"); }
|
||||
>await import("package/cjs") : { default: typeof import("tests/cases/conformance/node/index"); }
|
||||
>import("package/cjs") : Promise<{ default: typeof import("tests/cases/conformance/node/index"); }>
|
||||
>"package/cjs" : "package/cjs"
|
||||
|
||||
export const b = await import("package/mjs");
|
||||
@ -82,16 +82,16 @@ export const d = await import("inner/cjs");
|
||||
>"inner/cjs" : "inner/cjs"
|
||||
|
||||
export const e = await import("inner/mjs");
|
||||
>e : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; }
|
||||
>await import("inner/mjs") : { default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; }
|
||||
>import("inner/mjs") : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; }>
|
||||
>e : typeof import("tests/cases/conformance/node/node_modules/inner/index")
|
||||
>await import("inner/mjs") : typeof import("tests/cases/conformance/node/node_modules/inner/index")
|
||||
>import("inner/mjs") : Promise<typeof import("tests/cases/conformance/node/node_modules/inner/index")>
|
||||
>"inner/mjs" : "inner/mjs"
|
||||
|
||||
=== tests/cases/conformance/node/other.cts ===
|
||||
// cjs format file, no TLA
|
||||
export const a = import("package/cjs");
|
||||
>a : Promise<typeof import("tests/cases/conformance/node/index")>
|
||||
>import("package/cjs") : Promise<typeof import("tests/cases/conformance/node/index")>
|
||||
>a : Promise<{ default: typeof import("tests/cases/conformance/node/index"); }>
|
||||
>import("package/cjs") : Promise<{ default: typeof import("tests/cases/conformance/node/index"); }>
|
||||
>"package/cjs" : "package/cjs"
|
||||
|
||||
export const b = import("package/mjs");
|
||||
@ -117,8 +117,8 @@ export const d = import("inner/cjs");
|
||||
>"inner/cjs" : "inner/cjs"
|
||||
|
||||
export const e = import("inner/mjs");
|
||||
>e : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; }>
|
||||
>import("inner/mjs") : Promise<{ default: typeof import("tests/cases/conformance/node/node_modules/inner/index"); esm: true; }>
|
||||
>e : Promise<typeof import("tests/cases/conformance/node/node_modules/inner/index")>
|
||||
>import("inner/mjs") : Promise<typeof import("tests/cases/conformance/node/node_modules/inner/index")>
|
||||
>"inner/mjs" : "inner/mjs"
|
||||
|
||||
=== tests/cases/conformance/node/node_modules/inner/index.d.ts ===
|
||||
|
||||
@ -23,9 +23,9 @@ export async function f() {
|
||||
>"../index.js" : "../index.js"
|
||||
|
||||
const mod4 = await import ("./index.js");
|
||||
>mod4 : typeof mod2
|
||||
>await import ("./index.js") : typeof mod2
|
||||
>import ("./index.js") : Promise<typeof mod2>
|
||||
>mod4 : { default: typeof mod2; f(): Promise<void>; }
|
||||
>await import ("./index.js") : { default: typeof mod2; f(): Promise<void>; }
|
||||
>import ("./index.js") : Promise<{ default: typeof mod2; f(): Promise<void>; }>
|
||||
>"./index.js" : "./index.js"
|
||||
|
||||
h();
|
||||
@ -57,9 +57,9 @@ export async function h() {
|
||||
>"./index.js" : "./index.js"
|
||||
|
||||
const mod4 = await import ("./subfolder/index.js");
|
||||
>mod4 : typeof mod2
|
||||
>await import ("./subfolder/index.js") : typeof mod2
|
||||
>import ("./subfolder/index.js") : Promise<typeof mod2>
|
||||
>mod4 : { default: typeof mod2; f(): Promise<void>; }
|
||||
>await import ("./subfolder/index.js") : { default: typeof mod2; f(): Promise<void>; }
|
||||
>import ("./subfolder/index.js") : Promise<{ default: typeof mod2; f(): Promise<void>; }>
|
||||
>"./subfolder/index.js" : "./subfolder/index.js"
|
||||
|
||||
f();
|
||||
|
||||
@ -23,9 +23,9 @@ export async function f() {
|
||||
>"../index.js" : "../index.js"
|
||||
|
||||
const mod4 = await import ("./index.js");
|
||||
>mod4 : typeof mod2
|
||||
>await import ("./index.js") : typeof mod2
|
||||
>import ("./index.js") : Promise<typeof mod2>
|
||||
>mod4 : { default: typeof mod2; f(): Promise<void>; }
|
||||
>await import ("./index.js") : { default: typeof mod2; f(): Promise<void>; }
|
||||
>import ("./index.js") : Promise<{ default: typeof mod2; f(): Promise<void>; }>
|
||||
>"./index.js" : "./index.js"
|
||||
|
||||
h();
|
||||
@ -57,9 +57,9 @@ export async function h() {
|
||||
>"./index.js" : "./index.js"
|
||||
|
||||
const mod4 = await import ("./subfolder/index.js");
|
||||
>mod4 : typeof mod2
|
||||
>await import ("./subfolder/index.js") : typeof mod2
|
||||
>import ("./subfolder/index.js") : Promise<typeof mod2>
|
||||
>mod4 : { default: typeof mod2; f(): Promise<void>; }
|
||||
>await import ("./subfolder/index.js") : { default: typeof mod2; f(): Promise<void>; }
|
||||
>import ("./subfolder/index.js") : Promise<{ default: typeof mod2; f(): Promise<void>; }>
|
||||
>"./subfolder/index.js" : "./subfolder/index.js"
|
||||
|
||||
f();
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
// @module: node12,nodenext
|
||||
// @declaration: true
|
||||
// @filename: subfolder/index.ts
|
||||
// cjs format file
|
||||
export const a = 1;
|
||||
// @filename: index.ts
|
||||
// esm format file
|
||||
import mod from "./subfolder/index.js";
|
||||
mod;
|
||||
// @filename: package.json
|
||||
{
|
||||
"name": "package",
|
||||
"private": true,
|
||||
"type": "module"
|
||||
}
|
||||
// @filename: subfolder/package.json
|
||||
{
|
||||
"type": "commonjs"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user