diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index e2200218030..1d1d16b7ee1 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1757,7 +1757,7 @@ namespace ts { // An external module with an 'export =' declaration resolves to the target of the 'export =' declaration, // and an external module with no 'export =' declaration resolves to the module itself. function resolveExternalModuleSymbol(moduleSymbol: Symbol, dontResolveAlias?: boolean): Symbol { - return moduleSymbol && getMergedSymbol(resolveSymbol(moduleSymbol.exports.get("export=" as __String), dontResolveAlias)) || moduleSymbol; + return moduleSymbol && getMergedSymbol(resolveSymbol(moduleSymbol.exports.get(InternalSymbolName.ExportEquals), dontResolveAlias)) || moduleSymbol; } // An external module with an 'export =' declaration may be referenced as an ES6 module provided the 'export =' @@ -1772,7 +1772,7 @@ namespace ts { } function hasExportAssignmentSymbol(moduleSymbol: Symbol): boolean { - return moduleSymbol.exports.get("export=" as __String) !== undefined; + return moduleSymbol.exports.get(InternalSymbolName.ExportEquals) !== undefined; } function getExportsOfModuleAsArray(moduleSymbol: Symbol): Symbol[] { @@ -16402,12 +16402,35 @@ namespace ts { if (moduleSymbol) { const esModuleSymbol = resolveESModuleSymbol(moduleSymbol, specifier, /*dontRecursivelyResolve*/ true); if (esModuleSymbol) { - return createPromiseReturnType(node, getTypeOfSymbol(esModuleSymbol)); + return createPromiseReturnType(node, getTypeWithSyntheticDefaultImportType(getTypeOfSymbol(esModuleSymbol), esModuleSymbol)); } } return createPromiseReturnType(node, anyType); } + function getTypeWithSyntheticDefaultImportType(type: Type, symbol: Symbol): Type { + if (allowSyntheticDefaultImports && type && type !== unknownType) { + const synthType = type as SyntheticDefaultModuleType; + if (!synthType.syntheticType) { + if (!getPropertyOfType(type, InternalSymbolName.Default)) { + const memberTable = createSymbolTable(); + const newSymbol = createSymbol(SymbolFlags.Alias, InternalSymbolName.Default); + newSymbol.target = resolveSymbol(symbol); + memberTable.set(InternalSymbolName.Default, newSymbol); + const anonymousSymbol = createSymbol(SymbolFlags.TypeLiteral, InternalSymbolName.Type); + const defaultContainingObject = createAnonymousType(anonymousSymbol, memberTable, emptyArray, emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined); + anonymousSymbol.type = defaultContainingObject; + synthType.syntheticType = getIntersectionType([type, defaultContainingObject]); + } + else { + synthType.syntheticType = type; + } + } + return synthType.syntheticType; + } + return type; + } + function isCommonJsRequire(node: Node) { if (!isRequireCall(node, /*checkArgumentIsStringLiteral*/ true)) { return false; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 259dad75b00..27dcbda309f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -3318,6 +3318,11 @@ namespace ts { awaitedTypeOfType?: Type; } + /* @internal */ + export interface SyntheticDefaultModuleType extends Type { + syntheticType?: Type; + } + export interface TypeVariable extends Type { /* @internal */ resolvedBaseConstraint: Type; diff --git a/tests/baselines/reference/importCallExpressionAsyncES3System.types b/tests/baselines/reference/importCallExpressionAsyncES3System.types index 4f6a2bb31be..90c981c01ca 100644 --- a/tests/baselines/reference/importCallExpressionAsyncES3System.types +++ b/tests/baselines/reference/importCallExpressionAsyncES3System.types @@ -3,9 +3,9 @@ export async function fn() { >fn : () => Promise const req = await import('./test') // ONE ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } @@ -16,9 +16,9 @@ export class cl1 { >m : () => Promise const req = await import('./test') // TWO ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } } @@ -32,9 +32,9 @@ export const obj = { >async () => { const req = await import('./test') // THREE } : () => Promise const req = await import('./test') // THREE ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } } @@ -51,9 +51,9 @@ export class cl2 { >async () => { const req = await import('./test') // FOUR } : () => Promise const req = await import('./test') // FOUR ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } } @@ -64,9 +64,9 @@ export const l = async () => { >async () => { const req = await import('./test') // FIVE} : () => Promise const req = await import('./test') // FIVE ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } diff --git a/tests/baselines/reference/importCallExpressionAsyncES5System.types b/tests/baselines/reference/importCallExpressionAsyncES5System.types index 4f6a2bb31be..90c981c01ca 100644 --- a/tests/baselines/reference/importCallExpressionAsyncES5System.types +++ b/tests/baselines/reference/importCallExpressionAsyncES5System.types @@ -3,9 +3,9 @@ export async function fn() { >fn : () => Promise const req = await import('./test') // ONE ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } @@ -16,9 +16,9 @@ export class cl1 { >m : () => Promise const req = await import('./test') // TWO ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } } @@ -32,9 +32,9 @@ export const obj = { >async () => { const req = await import('./test') // THREE } : () => Promise const req = await import('./test') // THREE ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } } @@ -51,9 +51,9 @@ export class cl2 { >async () => { const req = await import('./test') // FOUR } : () => Promise const req = await import('./test') // FOUR ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } } @@ -64,9 +64,9 @@ export const l = async () => { >async () => { const req = await import('./test') // FIVE} : () => Promise const req = await import('./test') // FIVE ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } diff --git a/tests/baselines/reference/importCallExpressionAsyncES6System.types b/tests/baselines/reference/importCallExpressionAsyncES6System.types index 4f6a2bb31be..90c981c01ca 100644 --- a/tests/baselines/reference/importCallExpressionAsyncES6System.types +++ b/tests/baselines/reference/importCallExpressionAsyncES6System.types @@ -3,9 +3,9 @@ export async function fn() { >fn : () => Promise const req = await import('./test') // ONE ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } @@ -16,9 +16,9 @@ export class cl1 { >m : () => Promise const req = await import('./test') // TWO ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } } @@ -32,9 +32,9 @@ export const obj = { >async () => { const req = await import('./test') // THREE } : () => Promise const req = await import('./test') // THREE ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } } @@ -51,9 +51,9 @@ export class cl2 { >async () => { const req = await import('./test') // FOUR } : () => Promise const req = await import('./test') // FOUR ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } } @@ -64,9 +64,9 @@ export const l = async () => { >async () => { const req = await import('./test') // FIVE} : () => Promise const req = await import('./test') // FIVE ->req : typeof "tests/cases/conformance/dynamicImport/test" ->await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" ->import('./test') : Promise +>req : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>await import('./test') : typeof "tests/cases/conformance/dynamicImport/test" & { default: typeof "tests/cases/conformance/dynamicImport/test"; } +>import('./test') : Promise >'./test' : "./test" } diff --git a/tests/baselines/reference/importCallExpressionES5System.types b/tests/baselines/reference/importCallExpressionES5System.types index e97f722b14f..02bd64142d4 100644 --- a/tests/baselines/reference/importCallExpressionES5System.types +++ b/tests/baselines/reference/importCallExpressionES5System.types @@ -5,41 +5,41 @@ export function foo() { return "foo"; } === tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" +>zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } >foo : () => string }); export var p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } @@ -50,8 +50,8 @@ class C { >method : () => void const loadAsync = import ("./0"); ->loadAsync : Promise ->import ("./0") : Promise +>loadAsync : Promise +>import ("./0") : Promise >"./0" : "./0" } } @@ -63,8 +63,8 @@ export class D { >method : () => void const loadAsync = import ("./0"); ->loadAsync : Promise ->import ("./0") : Promise +>loadAsync : Promise +>import ("./0") : Promise >"./0" : "./0" } } diff --git a/tests/baselines/reference/importCallExpressionES6System.types b/tests/baselines/reference/importCallExpressionES6System.types index e97f722b14f..02bd64142d4 100644 --- a/tests/baselines/reference/importCallExpressionES6System.types +++ b/tests/baselines/reference/importCallExpressionES6System.types @@ -5,41 +5,41 @@ export function foo() { return "foo"; } === tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" +>zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } >foo : () => string }); export var p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } @@ -50,8 +50,8 @@ class C { >method : () => void const loadAsync = import ("./0"); ->loadAsync : Promise ->import ("./0") : Promise +>loadAsync : Promise +>import ("./0") : Promise >"./0" : "./0" } } @@ -63,8 +63,8 @@ export class D { >method : () => void const loadAsync = import ("./0"); ->loadAsync : Promise ->import ("./0") : Promise +>loadAsync : Promise +>import ("./0") : Promise >"./0" : "./0" } } diff --git a/tests/baselines/reference/importCallExpressionInSystem1.types b/tests/baselines/reference/importCallExpressionInSystem1.types index 661d27d1469..a82d8176753 100644 --- a/tests/baselines/reference/importCallExpressionInSystem1.types +++ b/tests/baselines/reference/importCallExpressionInSystem1.types @@ -5,40 +5,40 @@ export function foo() { return "foo"; } === tests/cases/conformance/dynamicImport/1.ts === import("./0"); ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" var p1 = import("./0"); ->p1 : Promise ->import("./0") : Promise +>p1 : Promise +>import("./0") : Promise >"./0" : "./0" p1.then(zero => { >p1.then(zero => { return zero.foo();}) : Promise ->p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->p1 : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0") => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" +>p1.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => string +>zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } return zero.foo(); >zero.foo() : string >zero.foo : () => string ->zero : typeof "tests/cases/conformance/dynamicImport/0" +>zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } >foo : () => string }); export var p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" function foo() { >foo : () => void const p2 = import("./0"); ->p2 : Promise ->import("./0") : Promise +>p2 : Promise +>import("./0") : Promise >"./0" : "./0" } diff --git a/tests/baselines/reference/importCallExpressionInSystem2.types b/tests/baselines/reference/importCallExpressionInSystem2.types index 44b17eb51fd..160da81b214 100644 --- a/tests/baselines/reference/importCallExpressionInSystem2.types +++ b/tests/baselines/reference/importCallExpressionInSystem2.types @@ -41,6 +41,6 @@ function foo(x: Promise) { foo(import("./0")); >foo(import("./0")) : void >foo : (x: Promise) => void ->import("./0") : Promise +>import("./0") : Promise >"./0" : "./0" diff --git a/tests/baselines/reference/importCallExpressionInSystem3.types b/tests/baselines/reference/importCallExpressionInSystem3.types index e517be6e722..08bf03fb506 100644 --- a/tests/baselines/reference/importCallExpressionInSystem3.types +++ b/tests/baselines/reference/importCallExpressionInSystem3.types @@ -14,9 +14,9 @@ async function foo() { class C extends (await import("./0")).B {} >C : C >(await import("./0")).B : B ->(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" ->await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" ->import("./0") : Promise +>(await import("./0")) : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } +>await import("./0") : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } +>import("./0") : Promise >"./0" : "./0" >B : typeof B diff --git a/tests/baselines/reference/importCallExpressionInSystem4.types b/tests/baselines/reference/importCallExpressionInSystem4.types index 156247851c9..c9f2b2e5211 100644 --- a/tests/baselines/reference/importCallExpressionInSystem4.types +++ b/tests/baselines/reference/importCallExpressionInSystem4.types @@ -24,27 +24,27 @@ class C { >C : C private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise +>myModule : Promise +>import("./0") : Promise >"./0" : "./0" method() { >method : () => void const loadAsync = import("./0"); ->loadAsync : Promise ->import("./0") : Promise +>loadAsync : Promise +>import("./0") : Promise >"./0" : "./0" this.myModule.then(Zero => { >this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise ->this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise >this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void ->Zero : typeof "tests/cases/conformance/dynamicImport/0" +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => void +>Zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } console.log(Zero.foo()); >console.log(Zero.foo()) : any @@ -53,7 +53,7 @@ class C { >log : any >Zero.foo() : string >Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/dynamicImport/0" +>Zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } >foo : () => string }, async err => { @@ -68,9 +68,9 @@ class C { >err : any let one = await import("./1"); ->one : typeof "tests/cases/conformance/dynamicImport/1" ->await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" ->import("./1") : Promise +>one : typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; } +>await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; } +>import("./1") : Promise >"./1" : "./1" console.log(one.backup()); @@ -80,7 +80,7 @@ class C { >log : any >one.backup() : string >one.backup : () => string ->one : typeof "tests/cases/conformance/dynamicImport/1" +>one : typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; } >backup : () => string }); @@ -91,27 +91,27 @@ export class D { >D : D private myModule = import("./0"); ->myModule : Promise ->import("./0") : Promise +>myModule : Promise +>import("./0") : Promise >"./0" : "./0" method() { >method : () => void const loadAsync = import("./0"); ->loadAsync : Promise ->import("./0") : Promise +>loadAsync : Promise +>import("./0") : Promise >"./0" : "./0" this.myModule.then(Zero => { >this.myModule.then(Zero => { console.log(Zero.foo()); }, async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); }) : Promise ->this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->this.myModule : Promise +>this.myModule.then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise >this : this ->myModule : Promise ->then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise ->Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0") => void ->Zero : typeof "tests/cases/conformance/dynamicImport/0" +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; }) => void +>Zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } console.log(Zero.foo()); >console.log(Zero.foo()) : any @@ -120,7 +120,7 @@ export class D { >log : any >Zero.foo() : string >Zero.foo : () => string ->Zero : typeof "tests/cases/conformance/dynamicImport/0" +>Zero : typeof "tests/cases/conformance/dynamicImport/0" & { default: typeof "tests/cases/conformance/dynamicImport/0"; } >foo : () => string }, async err => { @@ -135,9 +135,9 @@ export class D { >err : any let one = await import("./1"); ->one : typeof "tests/cases/conformance/dynamicImport/1" ->await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" ->import("./1") : Promise +>one : typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; } +>await import("./1") : typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; } +>import("./1") : Promise >"./1" : "./1" console.log(one.backup()); @@ -147,7 +147,7 @@ export class D { >log : any >one.backup() : string >one.backup : () => string ->one : typeof "tests/cases/conformance/dynamicImport/1" +>one : typeof "tests/cases/conformance/dynamicImport/1" & { default: typeof "tests/cases/conformance/dynamicImport/1"; } >backup : () => string }); diff --git a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.js b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.js new file mode 100644 index 00000000000..c49924191e5 --- /dev/null +++ b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.js @@ -0,0 +1,19 @@ +//// [tests/cases/compiler/syntheticDefaultExportsWithDynamicImports.ts] //// + +//// [index.d.ts] +declare function packageExport(x: number): string; +export = packageExport; + +//// [index.ts] +import("package").then(({default: foo}) => foo(42)); + +//// [index.js] +System.register([], function (exports_1, context_1) { + var __moduleName = context_1 && context_1.id; + return { + setters: [], + execute: function () { + context_1.import("package").then(({ default: foo }) => foo(42)); + } + }; +}); diff --git a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.symbols b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.symbols new file mode 100644 index 00000000000..85019711153 --- /dev/null +++ b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.symbols @@ -0,0 +1,17 @@ +=== tests/cases/compiler/node_modules/package/index.d.ts === +declare function packageExport(x: number): string; +>packageExport : Symbol(packageExport, Decl(index.d.ts, 0, 0)) +>x : Symbol(x, Decl(index.d.ts, 0, 31)) + +export = packageExport; +>packageExport : Symbol(packageExport, Decl(index.d.ts, 0, 0)) + +=== tests/cases/compiler/index.ts === +import("package").then(({default: foo}) => foo(42)); +>import("package").then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>"package" : Symbol("tests/cases/compiler/node_modules/package/index", Decl(index.d.ts, 0, 0)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>default : Symbol(default) +>foo : Symbol(foo, Decl(index.ts, 0, 25)) +>foo : Symbol(foo, Decl(index.ts, 0, 25)) + diff --git a/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types new file mode 100644 index 00000000000..1c38ecc466c --- /dev/null +++ b/tests/baselines/reference/syntheticDefaultExportsWithDynamicImports.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/node_modules/package/index.d.ts === +declare function packageExport(x: number): string; +>packageExport : (x: number) => string +>x : number + +export = packageExport; +>packageExport : (x: number) => string + +=== tests/cases/compiler/index.ts === +import("package").then(({default: foo}) => foo(42)); +>import("package").then(({default: foo}) => foo(42)) : Promise +>import("package").then : string) & { default: (x: number) => string; }, TResult2 = never>(onfulfilled?: (value: ((x: number) => string) & { default: (x: number) => string; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>import("package") : Promise<((x: number) => string) & { default: (x: number) => string; }> +>"package" : "package" +>then : string) & { default: (x: number) => string; }, TResult2 = never>(onfulfilled?: (value: ((x: number) => string) & { default: (x: number) => string; }) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>({default: foo}) => foo(42) : ({ default: foo }: ((x: number) => string) & { default: (x: number) => string; }) => string +>default : any +>foo : (x: number) => string +>foo(42) : string +>foo : (x: number) => string +>42 : 42 + diff --git a/tests/cases/compiler/syntheticDefaultExportsWithDynamicImports.ts b/tests/cases/compiler/syntheticDefaultExportsWithDynamicImports.ts new file mode 100644 index 00000000000..07f08d03185 --- /dev/null +++ b/tests/cases/compiler/syntheticDefaultExportsWithDynamicImports.ts @@ -0,0 +1,9 @@ +// @module: system +// @target: es6 +// @moduleResolution: node +// @filename: node_modules/package/index.d.ts +declare function packageExport(x: number): string; +export = packageExport; + +// @filename: index.ts +import("package").then(({default: foo}) => foo(42)); \ No newline at end of file