diff --git a/tests/baselines/reference/importCallExpression1ES2018.js b/tests/baselines/reference/importCallExpression1ES2018.js new file mode 100644 index 00000000000..e98562ba360 --- /dev/null +++ b/tests/baselines/reference/importCallExpression1ES2018.js @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression1ES2018.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}) + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +export function foo() { return "foo"; } +//// [1.js] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); +function foo() { + const p2 = import("./0"); +} diff --git a/tests/baselines/reference/importCallExpression1ES2018.symbols b/tests/baselines/reference/importCallExpression1ES2018.symbols new file mode 100644 index 00000000000..93f0d8f6deb --- /dev/null +++ b/tests/baselines/reference/importCallExpression1ES2018.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}) + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 2)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpression1ES2018.types b/tests/baselines/reference/importCallExpression1ES2018.types new file mode 100644 index 00000000000..6d67b0f20b4 --- /dev/null +++ b/tests/baselines/reference/importCallExpression1ES2018.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>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/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}) + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpression2ES2018.js b/tests/baselines/reference/importCallExpression2ES2018.js new file mode 100644 index 00000000000..293fa4e49d2 --- /dev/null +++ b/tests/baselines/reference/importCallExpression2ES2018.js @@ -0,0 +1,29 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression2ES2018.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); + +//// [0.js] +export class B { + print() { return "I am B"; } +} +//// [2.js] +function foo(x) { + x.then(value => { + let b = new value.B(); + b.print(); + }); +} +foo(import("./0")); diff --git a/tests/baselines/reference/importCallExpression2ES2018.symbols b/tests/baselines/reference/importCallExpression2ES2018.symbols new file mode 100644 index 00000000000..4e8931cb729 --- /dev/null +++ b/tests/baselines/reference/importCallExpression2ES2018.symbols @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +function foo(x: Promise) { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) +>x : Symbol(x, Decl(2.ts, 0, 13)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + x.then(value => { +>x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(2.ts, 0, 13)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>value : Symbol(value, Decl(2.ts, 1, 11)) + + let b = new value.B(); +>b : Symbol(b, Decl(2.ts, 2, 11)) +>value : Symbol(value, Decl(2.ts, 1, 11)) + + b.print(); +>b : Symbol(b, Decl(2.ts, 2, 11)) + + }) +} + +foo(import("./0")); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpression2ES2018.types b/tests/baselines/reference/importCallExpression2ES2018.types new file mode 100644 index 00000000000..01e3c0d99bd --- /dev/null +++ b/tests/baselines/reference/importCallExpression2ES2018.types @@ -0,0 +1,45 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +function foo(x: Promise) { +>foo : (x: Promise) => void +>x : Promise +>Promise : Promise + + x.then(value => { +>x.then(value => { let b = new value.B(); b.print(); }) : Promise +>x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>x : Promise +>then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>value => { let b = new value.B(); b.print(); } : (value: any) => void +>value : any + + let b = new value.B(); +>b : any +>new value.B() : any +>value.B : any +>value : any +>B : any + + b.print(); +>b.print() : any +>b.print : any +>b : any +>print : any + + }) +} + +foo(import("./0")); +>foo(import("./0")) : void +>foo : (x: Promise) => void +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpression4ES2018.js b/tests/baselines/reference/importCallExpression4ES2018.js new file mode 100644 index 00000000000..a132bd8ac65 --- /dev/null +++ b/tests/baselines/reference/importCallExpression4ES2018.js @@ -0,0 +1,49 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpression4ES2018.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} + +//// [0.js] +export class B { + print() { return "I am B"; } +} +export function foo() { return "foo"; } +//// [1.js] +export function backup() { return "backup"; } +//// [2.js] +class C { + constructor() { + this.myModule = import("./0"); + } + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async (err) => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} diff --git a/tests/baselines/reference/importCallExpression4ES2018.symbols b/tests/baselines/reference/importCallExpression4ES2018.symbols new file mode 100644 index 00000000000..1d2a9aec25c --- /dev/null +++ b/tests/baselines/reference/importCallExpression4ES2018.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +export function foo() { return "foo" } +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : Symbol(console, Decl(2.ts, 0, 11)) + +class C { +>C : Symbol(C, Decl(2.ts, 0, 25)) + + private myModule = import("./0"); +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) + + method() { +>method : Symbol(C.method, Decl(2.ts, 2, 37)) + + this.myModule.then(Zero => { +>this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>this : Symbol(C, Decl(2.ts, 0, 25)) +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) + + console.log(Zero.foo()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + + }, async err => { +>err : Symbol(err, Decl(2.ts, 6, 16)) + + console.log(err); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>err : Symbol(err, Decl(2.ts, 6, 16)) + + let one = await import("./1"); +>one : Symbol(one, Decl(2.ts, 8, 15)) + + console.log(one.backup()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>one.backup : Symbol(backup, Decl(1.ts, 0, 0)) +>one : Symbol(one, Decl(2.ts, 8, 15)) +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + + }); + } +} diff --git a/tests/baselines/reference/importCallExpression4ES2018.types b/tests/baselines/reference/importCallExpression4ES2018.types new file mode 100644 index 00000000000..6da36879f64 --- /dev/null +++ b/tests/baselines/reference/importCallExpression4ES2018.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +export function foo() { return "foo" } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : any + +class C { +>C : C + + private myModule = import("./0"); +>myModule : Promise +>import("./0") : Promise +>"./0" : "./0" + + method() { +>method : () => void + + 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/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + console.log(Zero.foo()); +>console.log(Zero.foo()) : any +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + + }, async err => { +>async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise +>err : any + + console.log(err); +>console.log(err) : any +>console.log : any +>console : any +>log : any +>err : any + + let one = await import("./1"); +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>import("./1") : Promise +>"./1" : "./1" + + console.log(one.backup()); +>console.log(one.backup()) : any +>console.log : any +>console : any +>log : any +>one.backup() : string +>one.backup : () => string +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt b/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt new file mode 100644 index 00000000000..e5ea311f44c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/es2018/dynamicImport/1.ts(4,5): error TS2322: Type 'Promise' is not assignable to type 'Promise'. + Type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"' is not assignable to type 'typeof "tests/cases/conformance/es2018/dynamicImport/anotherModule"'. + Property 'D' is missing in type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"'. +tests/cases/conformance/es2018/dynamicImport/1.ts(5,10): error TS2352: Type 'Promise' cannot be converted to type 'Promise'. + Type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"' is not comparable to type 'typeof "tests/cases/conformance/es2018/dynamicImport/anotherModule"'. + Property 'D' is missing in type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"'. + + +==== tests/cases/conformance/es2018/dynamicImport/anotherModule.ts (0 errors) ==== + + export class D{} + +==== tests/cases/conformance/es2018/dynamicImport/defaultPath.ts (0 errors) ==== + export class C {} + +==== tests/cases/conformance/es2018/dynamicImport/1.ts (2 errors) ==== + import * as defaultModule from "./defaultPath"; + import * as anotherModule from "./anotherModule"; + + let p1: Promise = import("./defaultPath"); + ~~ +!!! error TS2322: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2322: Type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"' is not assignable to type 'typeof "tests/cases/conformance/es2018/dynamicImport/anotherModule"'. +!!! error TS2322: Property 'D' is missing in type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"'. + let p2 = import("./defaultPath") as Promise; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2352: Type 'Promise' cannot be converted to type 'Promise'. +!!! error TS2352: Type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"' is not comparable to type 'typeof "tests/cases/conformance/es2018/dynamicImport/anotherModule"'. +!!! error TS2352: Property 'D' is missing in type 'typeof "tests/cases/conformance/es2018/dynamicImport/defaultPath"'. + let p3: Promise = import("./defaultPath"); + \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionCheckReturntype1.js b/tests/baselines/reference/importCallExpressionCheckReturntype1.js new file mode 100644 index 00000000000..2ef1e729b84 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionCheckReturntype1.js @@ -0,0 +1,36 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionCheckReturntype1.ts] //// + +//// [anotherModule.ts] + +export class D{} + +//// [defaultPath.ts] +export class C {} + +//// [1.ts] +import * as defaultModule from "./defaultPath"; +import * as anotherModule from "./anotherModule"; + +let p1: Promise = import("./defaultPath"); +let p2 = import("./defaultPath") as Promise; +let p3: Promise = import("./defaultPath"); + + +//// [anotherModule.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class D { +} +exports.D = D; +//// [defaultPath.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class C { +} +exports.C = C; +//// [1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +let p1 = Promise.resolve().then(() => require("./defaultPath")); +let p2 = Promise.resolve().then(() => require("./defaultPath")); +let p3 = Promise.resolve().then(() => require("./defaultPath")); diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.js b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js new file mode 100644 index 00000000000..333bc8768be --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.js @@ -0,0 +1,37 @@ +//// [importCallExpressionDeclarationEmit1.ts] + +declare function getSpecifier(): string; +declare var whatToLoad: boolean; +declare const directory: string; +declare const moduleFile: number; + +import(getSpecifier()); + +var p0 = import(`${directory}\${moduleFile}`); +var p1 = import(getSpecifier()); +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") + +function returnDynamicLoad(path: string) { + return import(path); +} + +//// [importCallExpressionDeclarationEmit1.js] +"use strict"; +Promise.resolve().then(() => require(getSpecifier())); +var p0 = Promise.resolve().then(() => require(`${directory}\${moduleFile}`)); +var p1 = Promise.resolve().then(() => require(getSpecifier())); +const p2 = Promise.resolve().then(() => require(whatToLoad ? getSpecifier() : "defaulPath")); +function returnDynamicLoad(path) { + return Promise.resolve().then(() => require(path)); +} + + +//// [importCallExpressionDeclarationEmit1.d.ts] +declare function getSpecifier(): string; +declare var whatToLoad: boolean; +declare const directory: string; +declare const moduleFile: number; +declare var p0: Promise; +declare var p1: Promise; +declare const p2: Promise; +declare function returnDynamicLoad(path: string): Promise; diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols b/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols new file mode 100644 index 00000000000..24fa2bc206d --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts === + +declare function getSpecifier(): string; +>getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) + +declare var whatToLoad: boolean; +>whatToLoad : Symbol(whatToLoad, Decl(importCallExpressionDeclarationEmit1.ts, 2, 11)) + +declare const directory: string; +>directory : Symbol(directory, Decl(importCallExpressionDeclarationEmit1.ts, 3, 13)) + +declare const moduleFile: number; +>moduleFile : Symbol(moduleFile, Decl(importCallExpressionDeclarationEmit1.ts, 4, 13)) + +import(getSpecifier()); +>getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) + +var p0 = import(`${directory}\${moduleFile}`); +>p0 : Symbol(p0, Decl(importCallExpressionDeclarationEmit1.ts, 8, 3)) +>directory : Symbol(directory, Decl(importCallExpressionDeclarationEmit1.ts, 3, 13)) + +var p1 = import(getSpecifier()); +>p1 : Symbol(p1, Decl(importCallExpressionDeclarationEmit1.ts, 9, 3)) +>getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) + +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") +>p2 : Symbol(p2, Decl(importCallExpressionDeclarationEmit1.ts, 10, 5)) +>whatToLoad : Symbol(whatToLoad, Decl(importCallExpressionDeclarationEmit1.ts, 2, 11)) +>getSpecifier : Symbol(getSpecifier, Decl(importCallExpressionDeclarationEmit1.ts, 0, 0)) + +function returnDynamicLoad(path: string) { +>returnDynamicLoad : Symbol(returnDynamicLoad, Decl(importCallExpressionDeclarationEmit1.ts, 10, 61)) +>path : Symbol(path, Decl(importCallExpressionDeclarationEmit1.ts, 12, 27)) + + return import(path); +>path : Symbol(path, Decl(importCallExpressionDeclarationEmit1.ts, 12, 27)) +} diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit1.types b/tests/baselines/reference/importCallExpressionDeclarationEmit1.types new file mode 100644 index 00000000000..9aedf5fcc6a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit1.types @@ -0,0 +1,48 @@ +=== tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit1.ts === + +declare function getSpecifier(): string; +>getSpecifier : () => string + +declare var whatToLoad: boolean; +>whatToLoad : boolean + +declare const directory: string; +>directory : string + +declare const moduleFile: number; +>moduleFile : number + +import(getSpecifier()); +>import(getSpecifier()) : Promise +>getSpecifier() : string +>getSpecifier : () => string + +var p0 = import(`${directory}\${moduleFile}`); +>p0 : Promise +>import(`${directory}\${moduleFile}`) : Promise +>`${directory}\${moduleFile}` : string +>directory : string + +var p1 = import(getSpecifier()); +>p1 : Promise +>import(getSpecifier()) : Promise +>getSpecifier() : string +>getSpecifier : () => string + +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") +>p2 : Promise +>import(whatToLoad ? getSpecifier() : "defaulPath") : Promise +>whatToLoad ? getSpecifier() : "defaulPath" : string +>whatToLoad : boolean +>getSpecifier() : string +>getSpecifier : () => string +>"defaulPath" : "defaulPath" + +function returnDynamicLoad(path: string) { +>returnDynamicLoad : (path: string) => Promise +>path : string + + return import(path); +>import(path) : Promise +>path : string +} diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt b/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt new file mode 100644 index 00000000000..908bfb6a409 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit2.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/es2018/dynamicImport/1.ts(1,5): error TS4023: Exported variable 'p1' has or is using name '"tests/cases/conformance/es2018/dynamicImport/0"' from external module "tests/cases/conformance/es2018/dynamicImport/0" but cannot be named. + + +==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== + + export function foo() { return "foo"; } + +==== tests/cases/conformance/es2018/dynamicImport/1.ts (1 errors) ==== + var p1 = import("./0"); + ~~ +!!! error TS4023: Exported variable 'p1' has or is using name '"tests/cases/conformance/es2018/dynamicImport/0"' from external module "tests/cases/conformance/es2018/dynamicImport/0" but cannot be named. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit2.js b/tests/baselines/reference/importCallExpressionDeclarationEmit2.js new file mode 100644 index 00000000000..b2f2cac8c6d --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit2.js @@ -0,0 +1,17 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit2.ts] //// + +//// [0.ts] + +export function foo() { return "foo"; } + +//// [1.ts] +var p1 = import("./0"); + +//// [0.js] +export function foo() { return "foo"; } +//// [1.js] +var p1 = import("./0"); + + +//// [0.d.ts] +export declare function foo(): string; diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.js b/tests/baselines/reference/importCallExpressionDeclarationEmit3.js new file mode 100644 index 00000000000..42ae75acbb3 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.js @@ -0,0 +1,32 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionDeclarationEmit3.ts] //// + +//// [0.ts] + +export function foo() { return "foo"; } + +//// [1.ts] +declare function getPath(): string; +import * as Zero from "./0"; +import("./0"); + +export var p0: Promise = import(getPath()); +export var p1: Promise = import("./0"); +export var p2: Promise = import("./0"); + + +//// [0.js] +export function foo() { return "foo"; } +//// [1.js] +import("./0"); +export var p0 = import(getPath()); +export var p1 = import("./0"); +export var p2 = import("./0"); + + +//// [0.d.ts] +export declare function foo(): string; +//// [1.d.ts] +import * as Zero from "./0"; +export declare var p0: Promise; +export declare var p1: Promise; +export declare var p2: Promise; diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols b/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols new file mode 100644 index 00000000000..6579d08ce34 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.symbols @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === + +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +declare function getPath(): string; +>getPath : Symbol(getPath, Decl(1.ts, 0, 0)) + +import * as Zero from "./0"; +>Zero : Symbol(Zero, Decl(1.ts, 1, 6)) + +import("./0"); + +export var p0: Promise = import(getPath()); +>p0 : Symbol(p0, Decl(1.ts, 4, 10)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(1.ts, 1, 6)) +>getPath : Symbol(getPath, Decl(1.ts, 0, 0)) + +export var p1: Promise = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 5, 10)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(1.ts, 1, 6)) + +export var p2: Promise = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 6, 10)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + diff --git a/tests/baselines/reference/importCallExpressionDeclarationEmit3.types b/tests/baselines/reference/importCallExpressionDeclarationEmit3.types new file mode 100644 index 00000000000..a03628e917a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionDeclarationEmit3.types @@ -0,0 +1,38 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === + +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +declare function getPath(): string; +>getPath : () => string + +import * as Zero from "./0"; +>Zero : typeof Zero + +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +export var p0: Promise = import(getPath()); +>p0 : Promise +>Promise : Promise +>Zero : typeof Zero +>import(getPath()) : Promise +>getPath() : string +>getPath : () => string + +export var p1: Promise = import("./0"); +>p1 : Promise +>Promise : Promise +>Zero : typeof Zero +>import("./0") : Promise +>"./0" : "./0" + +export var p2: Promise = import("./0"); +>p2 : Promise +>Promise : Promise +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt b/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt new file mode 100644 index 00000000000..ccd867f831c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionErrorInES2015.errors.txt @@ -0,0 +1,24 @@ +tests/cases/conformance/es2018/dynamicImport/1.ts(1,1): error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +tests/cases/conformance/es2018/dynamicImport/1.ts(2,10): error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. +tests/cases/conformance/es2018/dynamicImport/1.ts(8,16): error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. + + +==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== + export function foo() { return "foo"; } + +==== tests/cases/conformance/es2018/dynamicImport/1.ts (3 errors) ==== + import("./0"); + ~~~~~~~~~~~~~ +!!! error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. + var p1 = import("./0"); + ~~~~~~~~~~~~~ +!!! error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. + p1.then(zero => { + return zero.foo(); + }) + + function foo() { + const p2 = import("./0"); + ~~~~~~~~~~~~~ +!!! error TS1320: Dynamic import cannot be used when targeting ECMAScript 2015 modules. + } \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionErrorInES2015.js b/tests/baselines/reference/importCallExpressionErrorInES2015.js new file mode 100644 index 00000000000..afe29bbe9ca --- /dev/null +++ b/tests/baselines/reference/importCallExpressionErrorInES2015.js @@ -0,0 +1,27 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionErrorInES2015.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}) + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +export function foo() { return "foo"; } +//// [1.js] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); +function foo() { + const p2 = import("./0"); +} diff --git a/tests/baselines/reference/importCallExpressionGrammarError.errors.txt b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt new file mode 100644 index 00000000000..4d9c6829953 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionGrammarError.errors.txt @@ -0,0 +1,29 @@ +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(6,8): error TS1322: Specifier of dynamic import cannot be spread element. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(8,17): error TS1322: Specifier of dynamic import cannot be spread element. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(9,12): error TS1321: Dynamic import must have one specifier as an argument. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(10,19): error TS1135: Argument expression expected. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts(11,12): error TS1321: Dynamic import must have one specifier as an argument. + + +==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionGrammarError.ts (5 errors) ==== + + declare function getSpecifier(): string; + declare var whatToLoad: boolean; + + var a = ["./0"]; + import(...["PathModule"]); + ~~~~~~~~~~~~~~~~~ +!!! error TS1322: Specifier of dynamic import cannot be spread element. + + var p1 = import(...a); + ~~~~ +!!! error TS1322: Specifier of dynamic import cannot be spread element. + const p2 = import(); + ~~~~~~~~ +!!! error TS1321: Dynamic import must have one specifier as an argument. + const p3 = import(,); + +!!! error TS1135: Argument expression expected. + const p4 = import("pathToModule", "secondModule"); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1321: Dynamic import must have one specifier as an argument. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionGrammarError.js b/tests/baselines/reference/importCallExpressionGrammarError.js new file mode 100644 index 00000000000..6f31587a23d --- /dev/null +++ b/tests/baselines/reference/importCallExpressionGrammarError.js @@ -0,0 +1,21 @@ +//// [importCallExpressionGrammarError.ts] + +declare function getSpecifier(): string; +declare var whatToLoad: boolean; + +var a = ["./0"]; +import(...["PathModule"]); + +var p1 = import(...a); +const p2 = import(); +const p3 = import(,); +const p4 = import("pathToModule", "secondModule"); + +//// [importCallExpressionGrammarError.js] +"use strict"; +var a = ["./0"]; +Promise.resolve().then(() => require(...["PathModule"])); +var p1 = Promise.resolve().then(() => require(...a)); +const p2 = Promise.resolve().then(() => require()); +const p3 = Promise.resolve().then(() => require()); +const p4 = Promise.resolve().then(() => require("pathToModule", "secondModule")); diff --git a/tests/baselines/reference/importCallExpressionInAMD1.js b/tests/baselines/reference/importCallExpressionInAMD1.js new file mode 100644 index 00000000000..ed02c4893c3 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD1.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD1.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function foo() { return "foo"; } + exports.foo = foo; +}); +//// [1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + new Promise(resolve => require(["./0"], resolve)); + var p1 = new Promise(resolve => require(["./0"], resolve)); + p1.then(zero => { + return zero.foo(); + }); + function foo() { + const p2 = new Promise(resolve => require(["./0"], resolve)); + } +}); diff --git a/tests/baselines/reference/importCallExpressionInAMD1.symbols b/tests/baselines/reference/importCallExpressionInAMD1.symbols new file mode 100644 index 00000000000..15356c694ed --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}); + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 3)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpressionInAMD1.types b/tests/baselines/reference/importCallExpressionInAMD1.types new file mode 100644 index 00000000000..2733f3ff14a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD1.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>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/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}); + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpressionInAMD2.js b/tests/baselines/reference/importCallExpressionInAMD2.js new file mode 100644 index 00000000000..8f451643b5a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD2.js @@ -0,0 +1,39 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD2.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + class B { + print() { return "I am B"; } + } + exports.B = B; +}); +//// [2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + // We use Promise for now as there is no way to specify shape of module object + function foo(x) { + x.then(value => { + let b = new value.B(); + b.print(); + }); + } + foo(new Promise(resolve => require(["./0"], resolve))); +}); diff --git a/tests/baselines/reference/importCallExpressionInAMD2.symbols b/tests/baselines/reference/importCallExpressionInAMD2.symbols new file mode 100644 index 00000000000..7db47944520 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + x.then(value => { +>x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + let b = new value.B(); +>b : Symbol(b, Decl(2.ts, 3, 11)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + b.print(); +>b : Symbol(b, Decl(2.ts, 3, 11)) + + }) +} + +foo(import("./0")); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInAMD2.types b/tests/baselines/reference/importCallExpressionInAMD2.types new file mode 100644 index 00000000000..2db06142911 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD2.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : (x: Promise) => void +>x : Promise +>Promise : Promise + + x.then(value => { +>x.then(value => { let b = new value.B(); b.print(); }) : Promise +>x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>x : Promise +>then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>value => { let b = new value.B(); b.print(); } : (value: any) => void +>value : any + + let b = new value.B(); +>b : any +>new value.B() : any +>value.B : any +>value : any +>B : any + + b.print(); +>b.print() : any +>b.print : any +>b : any +>print : any + + }) +} + +foo(import("./0")); +>foo(import("./0")) : void +>foo : (x: Promise) => void +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpressionInAMD4.js b/tests/baselines/reference/importCallExpressionInAMD4.js new file mode 100644 index 00000000000..796e1a7996e --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD4.js @@ -0,0 +1,63 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInAMD4.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} + +//// [0.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + class B { + print() { return "I am B"; } + } + exports.B = B; + function foo() { return "foo"; } + exports.foo = foo; +}); +//// [1.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function backup() { return "backup"; } + exports.backup = backup; +}); +//// [2.js] +define(["require", "exports"], function (require, exports) { + "use strict"; + class C { + constructor() { + this.myModule = new Promise(resolve => require(["./0"], resolve)); + } + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async (err) => { + console.log(err); + let one = await new Promise(resolve => require(["./1"], resolve)); + console.log(one.backup()); + }); + } + } +}); diff --git a/tests/baselines/reference/importCallExpressionInAMD4.symbols b/tests/baselines/reference/importCallExpressionInAMD4.symbols new file mode 100644 index 00000000000..1d2a9aec25c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD4.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +export function foo() { return "foo" } +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : Symbol(console, Decl(2.ts, 0, 11)) + +class C { +>C : Symbol(C, Decl(2.ts, 0, 25)) + + private myModule = import("./0"); +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) + + method() { +>method : Symbol(C.method, Decl(2.ts, 2, 37)) + + this.myModule.then(Zero => { +>this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>this : Symbol(C, Decl(2.ts, 0, 25)) +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) + + console.log(Zero.foo()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + + }, async err => { +>err : Symbol(err, Decl(2.ts, 6, 16)) + + console.log(err); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>err : Symbol(err, Decl(2.ts, 6, 16)) + + let one = await import("./1"); +>one : Symbol(one, Decl(2.ts, 8, 15)) + + console.log(one.backup()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>one.backup : Symbol(backup, Decl(1.ts, 0, 0)) +>one : Symbol(one, Decl(2.ts, 8, 15)) +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInAMD4.types b/tests/baselines/reference/importCallExpressionInAMD4.types new file mode 100644 index 00000000000..6da36879f64 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInAMD4.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +export function foo() { return "foo" } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : any + +class C { +>C : C + + private myModule = import("./0"); +>myModule : Promise +>import("./0") : Promise +>"./0" : "./0" + + method() { +>method : () => void + + 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/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + console.log(Zero.foo()); +>console.log(Zero.foo()) : any +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + + }, async err => { +>async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise +>err : any + + console.log(err); +>console.log(err) : any +>console.log : any +>console : any +>log : any +>err : any + + let one = await import("./1"); +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>import("./1") : Promise +>"./1" : "./1" + + console.log(one.backup()); +>console.log(one.backup()) : any +>console.log : any +>console : any +>log : any +>one.backup() : string +>one.backup : () => string +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInCJS1.js b/tests/baselines/reference/importCallExpressionInCJS1.js new file mode 100644 index 00000000000..e9a5ffa3656 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS1.js @@ -0,0 +1,31 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS1.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function foo() { return "foo"; } +exports.foo = foo; +//// [1.js] +"use strict"; +Promise.resolve().then(() => require("./0")); +var p1 = Promise.resolve().then(() => require("./0")); +p1.then(zero => { + return zero.foo(); +}); +function foo() { + const p2 = Promise.resolve().then(() => require("./0")); +} diff --git a/tests/baselines/reference/importCallExpressionInCJS1.symbols b/tests/baselines/reference/importCallExpressionInCJS1.symbols new file mode 100644 index 00000000000..15356c694ed --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}); + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 3)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpressionInCJS1.types b/tests/baselines/reference/importCallExpressionInCJS1.types new file mode 100644 index 00000000000..2733f3ff14a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS1.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>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/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}); + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpressionInCJS2.js b/tests/baselines/reference/importCallExpressionInCJS2.js new file mode 100644 index 00000000000..7430541b51e --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS2.js @@ -0,0 +1,41 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS2.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +async function compute(promise: Promise) { + let j = await promise; + if (!j) { + j = await import("./1"); + return j.backup(); + } + return j.foo(); +} + +compute(import("./0")); + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function foo() { return "foo"; } +exports.foo = foo; +//// [1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function backup() { return "backup"; } +exports.backup = backup; +//// [2.js] +"use strict"; +async function compute(promise) { + let j = await promise; + if (!j) { + j = await Promise.resolve().then(() => require("./1")); + return j.backup(); + } + return j.foo(); +} +compute(Promise.resolve().then(() => require("./0"))); diff --git a/tests/baselines/reference/importCallExpressionInCJS2.symbols b/tests/baselines/reference/importCallExpressionInCJS2.symbols new file mode 100644 index 00000000000..8a62908868c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function compute(promise: Promise) { +>compute : Symbol(compute, Decl(2.ts, 0, 0)) +>promise : Symbol(promise, Decl(2.ts, 0, 23)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + let j = await promise; +>j : Symbol(j, Decl(2.ts, 1, 7)) +>promise : Symbol(promise, Decl(2.ts, 0, 23)) + + if (!j) { +>j : Symbol(j, Decl(2.ts, 1, 7)) + + j = await import("./1"); +>j : Symbol(j, Decl(2.ts, 1, 7)) + + return j.backup(); +>j : Symbol(j, Decl(2.ts, 1, 7)) + } + return j.foo(); +>j : Symbol(j, Decl(2.ts, 1, 7)) +} + +compute(import("./0")); +>compute : Symbol(compute, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInCJS2.types b/tests/baselines/reference/importCallExpressionInCJS2.types new file mode 100644 index 00000000000..88317f387fe --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS2.types @@ -0,0 +1,51 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +async function compute(promise: Promise) { +>compute : (promise: Promise) => Promise +>promise : Promise +>Promise : Promise + + let j = await promise; +>j : any +>await promise : any +>promise : Promise + + if (!j) { +>!j : boolean +>j : any + + j = await import("./1"); +>j = await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>j : any +>await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>import("./1") : Promise +>"./1" : "./1" + + return j.backup(); +>j.backup() : any +>j.backup : any +>j : any +>backup : any + } + return j.foo(); +>j.foo() : any +>j.foo : any +>j : any +>foo : any +} + +compute(import("./0")); +>compute(import("./0")) : Promise +>compute : (promise: Promise) => Promise +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpressionInCJS3.js b/tests/baselines/reference/importCallExpressionInCJS3.js new file mode 100644 index 00000000000..264888091ab --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS3.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS3.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class B { + print() { return "I am B"; } +} +exports.B = B; +//// [2.js] +"use strict"; +// We use Promise for now as there is no way to specify shape of module object +function foo(x) { + x.then(value => { + let b = new value.B(); + b.print(); + }); +} +foo(Promise.resolve().then(() => require("./0"))); diff --git a/tests/baselines/reference/importCallExpressionInCJS3.symbols b/tests/baselines/reference/importCallExpressionInCJS3.symbols new file mode 100644 index 00000000000..7db47944520 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS3.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + x.then(value => { +>x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + let b = new value.B(); +>b : Symbol(b, Decl(2.ts, 3, 11)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + b.print(); +>b : Symbol(b, Decl(2.ts, 3, 11)) + + }) +} + +foo(import("./0")); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInCJS3.types b/tests/baselines/reference/importCallExpressionInCJS3.types new file mode 100644 index 00000000000..2db06142911 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS3.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : (x: Promise) => void +>x : Promise +>Promise : Promise + + x.then(value => { +>x.then(value => { let b = new value.B(); b.print(); }) : Promise +>x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>x : Promise +>then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>value => { let b = new value.B(); b.print(); } : (value: any) => void +>value : any + + let b = new value.B(); +>b : any +>new value.B() : any +>value.B : any +>value : any +>B : any + + b.print(); +>b.print() : any +>b.print : any +>b : any +>print : any + + }) +} + +foo(import("./0")); +>foo(import("./0")) : void +>foo : (x: Promise) => void +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpressionInCJS5.js b/tests/baselines/reference/importCallExpressionInCJS5.js new file mode 100644 index 00000000000..82845416b45 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS5.js @@ -0,0 +1,57 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInCJS5.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class B { + print() { return "I am B"; } +} +exports.B = B; +function foo() { return "foo"; } +exports.foo = foo; +//// [1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function backup() { return "backup"; } +exports.backup = backup; +//// [2.js] +"use strict"; +class C { + constructor() { + this.myModule = Promise.resolve().then(() => require("./0")); + } + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async (err) => { + console.log(err); + let one = await Promise.resolve().then(() => require("./1")); + console.log(one.backup()); + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInCJS5.symbols b/tests/baselines/reference/importCallExpressionInCJS5.symbols new file mode 100644 index 00000000000..1d2a9aec25c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS5.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +export function foo() { return "foo" } +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : Symbol(console, Decl(2.ts, 0, 11)) + +class C { +>C : Symbol(C, Decl(2.ts, 0, 25)) + + private myModule = import("./0"); +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) + + method() { +>method : Symbol(C.method, Decl(2.ts, 2, 37)) + + this.myModule.then(Zero => { +>this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>this : Symbol(C, Decl(2.ts, 0, 25)) +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) + + console.log(Zero.foo()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + + }, async err => { +>err : Symbol(err, Decl(2.ts, 6, 16)) + + console.log(err); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>err : Symbol(err, Decl(2.ts, 6, 16)) + + let one = await import("./1"); +>one : Symbol(one, Decl(2.ts, 8, 15)) + + console.log(one.backup()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>one.backup : Symbol(backup, Decl(1.ts, 0, 0)) +>one : Symbol(one, Decl(2.ts, 8, 15)) +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInCJS5.types b/tests/baselines/reference/importCallExpressionInCJS5.types new file mode 100644 index 00000000000..6da36879f64 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInCJS5.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +export function foo() { return "foo" } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : any + +class C { +>C : C + + private myModule = import("./0"); +>myModule : Promise +>import("./0") : Promise +>"./0" : "./0" + + method() { +>method : () => void + + 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/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + console.log(Zero.foo()); +>console.log(Zero.foo()) : any +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + + }, async err => { +>async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise +>err : any + + console.log(err); +>console.log(err) : any +>console.log : any +>console : any +>log : any +>err : any + + let one = await import("./1"); +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>import("./1") : Promise +>"./1" : "./1" + + console.log(one.backup()); +>console.log(one.backup()) : any +>console.log : any +>console : any +>log : any +>one.backup() : string +>one.backup : () => string +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt b/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt new file mode 100644 index 00000000000..b7645851b28 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es2018/dynamicImport/1.ts(3,10): error TS1100: Invalid use of 'arguments' in strict mode. + + +==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== + + export function foo() { return "foo"; } + +==== tests/cases/conformance/es2018/dynamicImport/1.ts (1 errors) ==== + "use strict" + var p1 = import("./0"); + function arguments() { } + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionInScriptContext2.js b/tests/baselines/reference/importCallExpressionInScriptContext2.js new file mode 100644 index 00000000000..b278a60b6bb --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInScriptContext2.js @@ -0,0 +1,20 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInScriptContext2.ts] //// + +//// [0.ts] + +export function foo() { return "foo"; } + +//// [1.ts] +"use strict" +var p1 = import("./0"); +function arguments() { } + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function foo() { return "foo"; } +exports.foo = foo; +//// [1.js] +"use strict"; +var p1 = Promise.resolve().then(() => require("./0")); +function arguments() { } diff --git a/tests/baselines/reference/importCallExpressionInSystem1.js b/tests/baselines/reference/importCallExpressionInSystem1.js new file mode 100644 index 00000000000..1a146b02fcd --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem1.js @@ -0,0 +1,47 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem1.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + function foo() { return "foo"; } + exports_1("foo", foo); + return { + setters: [], + execute: function () { + } + }; +}); +//// [1.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + function foo() { + const p2 = context_1.import("./0"); + } + var p1; + return { + setters: [], + execute: function () { + context_1.import("./0"); + p1 = context_1.import("./0"); + p1.then(zero => { + return zero.foo(); + }); + } + }; +}); diff --git a/tests/baselines/reference/importCallExpressionInSystem1.symbols b/tests/baselines/reference/importCallExpressionInSystem1.symbols new file mode 100644 index 00000000000..15356c694ed --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}); + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 3)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpressionInSystem1.types b/tests/baselines/reference/importCallExpressionInSystem1.types new file mode 100644 index 00000000000..2733f3ff14a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem1.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>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/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}); + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpressionInSystem2.js b/tests/baselines/reference/importCallExpressionInSystem2.js new file mode 100644 index 00000000000..198f4c4c7a2 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem2.js @@ -0,0 +1,51 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem2.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var B; + return { + setters: [], + execute: function () { + B = class B { + print() { return "I am B"; } + }; + exports_1("B", B); + } + }; +}); +//// [2.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + // We use Promise for now as there is no way to specify shape of module object + function foo(x) { + x.then(value => { + let b = new value.B(); + b.print(); + }); + } + return { + setters: [], + execute: function () { + foo(context_1.import("./0")); + } + }; +}); diff --git a/tests/baselines/reference/importCallExpressionInSystem2.symbols b/tests/baselines/reference/importCallExpressionInSystem2.symbols new file mode 100644 index 00000000000..7db47944520 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + x.then(value => { +>x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + let b = new value.B(); +>b : Symbol(b, Decl(2.ts, 3, 11)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + b.print(); +>b : Symbol(b, Decl(2.ts, 3, 11)) + + }) +} + +foo(import("./0")); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInSystem2.types b/tests/baselines/reference/importCallExpressionInSystem2.types new file mode 100644 index 00000000000..2db06142911 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem2.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : (x: Promise) => void +>x : Promise +>Promise : Promise + + x.then(value => { +>x.then(value => { let b = new value.B(); b.print(); }) : Promise +>x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>x : Promise +>then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>value => { let b = new value.B(); b.print(); } : (value: any) => void +>value : any + + let b = new value.B(); +>b : any +>new value.B() : any +>value.B : any +>value : any +>B : any + + b.print(); +>b.print() : any +>b.print : any +>b : any +>print : any + + }) +} + +foo(import("./0")); +>foo(import("./0")) : void +>foo : (x: Promise) => void +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpressionInSystem4.js b/tests/baselines/reference/importCallExpressionInSystem4.js new file mode 100644 index 00000000000..e3a938b826e --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem4.js @@ -0,0 +1,81 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInSystem4.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} + +//// [0.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + function foo() { return "foo"; } + exports_1("foo", foo); + var B; + return { + setters: [], + execute: function () { + B = class B { + print() { return "I am B"; } + }; + exports_1("B", B); + } + }; +}); +//// [1.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + function backup() { return "backup"; } + exports_1("backup", backup); + return { + setters: [], + execute: function () { + } + }; +}); +//// [2.js] +System.register([], function (exports_1, context_1) { + "use strict"; + var __moduleName = context_1 && context_1.id; + var C; + return { + setters: [], + execute: function () { + C = class C { + constructor() { + this.myModule = context_1.import("./0"); + } + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async (err) => { + console.log(err); + let one = await context_1.import("./1"); + console.log(one.backup()); + }); + } + }; + } + }; +}); diff --git a/tests/baselines/reference/importCallExpressionInSystem4.symbols b/tests/baselines/reference/importCallExpressionInSystem4.symbols new file mode 100644 index 00000000000..1d2a9aec25c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem4.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +export function foo() { return "foo" } +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : Symbol(console, Decl(2.ts, 0, 11)) + +class C { +>C : Symbol(C, Decl(2.ts, 0, 25)) + + private myModule = import("./0"); +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) + + method() { +>method : Symbol(C.method, Decl(2.ts, 2, 37)) + + this.myModule.then(Zero => { +>this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>this : Symbol(C, Decl(2.ts, 0, 25)) +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) + + console.log(Zero.foo()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + + }, async err => { +>err : Symbol(err, Decl(2.ts, 6, 16)) + + console.log(err); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>err : Symbol(err, Decl(2.ts, 6, 16)) + + let one = await import("./1"); +>one : Symbol(one, Decl(2.ts, 8, 15)) + + console.log(one.backup()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>one.backup : Symbol(backup, Decl(1.ts, 0, 0)) +>one : Symbol(one, Decl(2.ts, 8, 15)) +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInSystem4.types b/tests/baselines/reference/importCallExpressionInSystem4.types new file mode 100644 index 00000000000..6da36879f64 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInSystem4.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +export function foo() { return "foo" } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : any + +class C { +>C : C + + private myModule = import("./0"); +>myModule : Promise +>import("./0") : Promise +>"./0" : "./0" + + method() { +>method : () => void + + 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/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + console.log(Zero.foo()); +>console.log(Zero.foo()) : any +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + + }, async err => { +>async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise +>err : any + + console.log(err); +>console.log(err) : any +>console.log : any +>console : any +>log : any +>err : any + + let one = await import("./1"); +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>import("./1") : Promise +>"./1" : "./1" + + console.log(one.backup()); +>console.log(one.backup()) : any +>console.log : any +>console : any +>log : any +>one.backup() : string +>one.backup : () => string +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInUMD1.js b/tests/baselines/reference/importCallExpressionInUMD1.js new file mode 100644 index 00000000000..16668df030f --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD1.js @@ -0,0 +1,51 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD1.ts] //// + +//// [0.ts] +export function foo() { return "foo"; } + +//// [1.ts] +import("./0"); +var p1 = import("./0"); +p1.then(zero => { + return zero.foo(); +}); + +function foo() { + const p2 = import("./0"); +} + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function foo() { return "foo"; } + exports.foo = foo; +}); +//// [1.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)); + var p1 = require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)); + p1.then(zero => { + return zero.foo(); + }); + function foo() { + const p2 = require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)); + } +}); diff --git a/tests/baselines/reference/importCallExpressionInUMD1.symbols b/tests/baselines/reference/importCallExpressionInUMD1.symbols new file mode 100644 index 00000000000..15356c694ed --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD1.symbols @@ -0,0 +1,28 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +var p1 = import("./0"); +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 1, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) + + return zero.foo(); +>zero.foo : Symbol(foo, Decl(0.ts, 0, 0)) +>zero : Symbol(zero, Decl(1.ts, 2, 8)) +>foo : Symbol(foo, Decl(0.ts, 0, 0)) + +}); + +function foo() { +>foo : Symbol(foo, Decl(1.ts, 4, 3)) + + const p2 = import("./0"); +>p2 : Symbol(p2, Decl(1.ts, 7, 9)) +} diff --git a/tests/baselines/reference/importCallExpressionInUMD1.types b/tests/baselines/reference/importCallExpressionInUMD1.types new file mode 100644 index 00000000000..2733f3ff14a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD1.types @@ -0,0 +1,39 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export function foo() { return "foo"; } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import("./0"); +>import("./0") : Promise +>"./0" : "./0" + +var p1 = import("./0"); +>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/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo();} : (zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + return zero.foo(); +>zero.foo() : string +>zero.foo : () => string +>zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + +}); + +function foo() { +>foo : () => void + + const p2 = import("./0"); +>p2 : Promise +>import("./0") : Promise +>"./0" : "./0" +} diff --git a/tests/baselines/reference/importCallExpressionInUMD2.js b/tests/baselines/reference/importCallExpressionInUMD2.js new file mode 100644 index 00000000000..ebaeca6311a --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD2.js @@ -0,0 +1,55 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD2.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +//// [2.ts] +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { + x.then(value => { + let b = new value.B(); + b.print(); + }) +} + +foo(import("./0")); + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + class B { + print() { return "I am B"; } + } + exports.B = B; +}); +//// [2.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + // We use Promise for now as there is no way to specify shape of module object + function foo(x) { + x.then(value => { + let b = new value.B(); + b.print(); + }); + } + foo(require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve))); +}); diff --git a/tests/baselines/reference/importCallExpressionInUMD2.symbols b/tests/baselines/reference/importCallExpressionInUMD2.symbols new file mode 100644 index 00000000000..7db47944520 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD2.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : Symbol(foo, Decl(2.ts, 0, 0)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) + + x.then(value => { +>x.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>x : Symbol(x, Decl(2.ts, 1, 13)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + let b = new value.B(); +>b : Symbol(b, Decl(2.ts, 3, 11)) +>value : Symbol(value, Decl(2.ts, 2, 11)) + + b.print(); +>b : Symbol(b, Decl(2.ts, 3, 11)) + + }) +} + +foo(import("./0")); +>foo : Symbol(foo, Decl(2.ts, 0, 0)) + diff --git a/tests/baselines/reference/importCallExpressionInUMD2.types b/tests/baselines/reference/importCallExpressionInUMD2.types new file mode 100644 index 00000000000..2db06142911 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD2.types @@ -0,0 +1,46 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +// We use Promise for now as there is no way to specify shape of module object +function foo(x: Promise) { +>foo : (x: Promise) => void +>x : Promise +>Promise : Promise + + x.then(value => { +>x.then(value => { let b = new value.B(); b.print(); }) : Promise +>x.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>x : Promise +>then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>value => { let b = new value.B(); b.print(); } : (value: any) => void +>value : any + + let b = new value.B(); +>b : any +>new value.B() : any +>value.B : any +>value : any +>B : any + + b.print(); +>b.print() : any +>b.print : any +>b : any +>print : any + + }) +} + +foo(import("./0")); +>foo(import("./0")) : void +>foo : (x: Promise) => void +>import("./0") : Promise +>"./0" : "./0" + diff --git a/tests/baselines/reference/importCallExpressionInUMD4.js b/tests/baselines/reference/importCallExpressionInUMD4.js new file mode 100644 index 00000000000..ac36081a536 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD4.js @@ -0,0 +1,87 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionInUMD4.ts] //// + +//// [0.ts] +export class B { + print() { return "I am B"} +} + +export function foo() { return "foo" } + +//// [1.ts] +export function backup() { return "backup"; } + +//// [2.ts] +declare var console: any; +class C { + private myModule = import("./0"); + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async err => { + console.log(err); + let one = await import("./1"); + console.log(one.backup()); + }); + } +} + +//// [0.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + class B { + print() { return "I am B"; } + } + exports.B = B; + function foo() { return "foo"; } + exports.foo = foo; +}); +//// [1.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + Object.defineProperty(exports, "__esModule", { value: true }); + function backup() { return "backup"; } + exports.backup = backup; +}); +//// [2.js] +(function (factory) { + if (typeof module === "object" && typeof module.exports === "object") { + var v = factory(require, exports); + if (v !== undefined) module.exports = v; + } + else if (typeof define === "function" && define.amd) { + define(["require", "exports"], factory); + } +})(function (require, exports) { + "use strict"; + class C { + constructor() { + this.myModule = require.length === 1 ? Promise.resolve().then(() => require("./0")) : new Promise(resolve => require(["./0"], resolve)); + } + method() { + this.myModule.then(Zero => { + console.log(Zero.foo()); + }, async (err) => { + console.log(err); + let one = await (require.length === 1 ? Promise.resolve().then(() => require("./1")) : new Promise(resolve => require(["./1"], resolve))); + console.log(one.backup()); + }); + } + } +}); diff --git a/tests/baselines/reference/importCallExpressionInUMD4.symbols b/tests/baselines/reference/importCallExpressionInUMD4.symbols new file mode 100644 index 00000000000..1d2a9aec25c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD4.symbols @@ -0,0 +1,61 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : Symbol(B, Decl(0.ts, 0, 0)) + + print() { return "I am B"} +>print : Symbol(B.print, Decl(0.ts, 0, 16)) +} + +export function foo() { return "foo" } +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : Symbol(console, Decl(2.ts, 0, 11)) + +class C { +>C : Symbol(C, Decl(2.ts, 0, 25)) + + private myModule = import("./0"); +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) + + method() { +>method : Symbol(C.method, Decl(2.ts, 2, 37)) + + this.myModule.then(Zero => { +>this.myModule.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>this.myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>this : Symbol(C, Decl(2.ts, 0, 25)) +>myModule : Symbol(C.myModule, Decl(2.ts, 1, 9)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) + + console.log(Zero.foo()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>Zero.foo : Symbol(foo, Decl(0.ts, 2, 1)) +>Zero : Symbol(Zero, Decl(2.ts, 4, 27)) +>foo : Symbol(foo, Decl(0.ts, 2, 1)) + + }, async err => { +>err : Symbol(err, Decl(2.ts, 6, 16)) + + console.log(err); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>err : Symbol(err, Decl(2.ts, 6, 16)) + + let one = await import("./1"); +>one : Symbol(one, Decl(2.ts, 8, 15)) + + console.log(one.backup()); +>console : Symbol(console, Decl(2.ts, 0, 11)) +>one.backup : Symbol(backup, Decl(1.ts, 0, 0)) +>one : Symbol(one, Decl(2.ts, 8, 15)) +>backup : Symbol(backup, Decl(1.ts, 0, 0)) + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionInUMD4.types b/tests/baselines/reference/importCallExpressionInUMD4.types new file mode 100644 index 00000000000..6da36879f64 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionInUMD4.types @@ -0,0 +1,83 @@ +=== tests/cases/conformance/es2018/dynamicImport/0.ts === +export class B { +>B : B + + print() { return "I am B"} +>print : () => string +>"I am B" : "I am B" +} + +export function foo() { return "foo" } +>foo : () => string +>"foo" : "foo" + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +export function backup() { return "backup"; } +>backup : () => string +>"backup" : "backup" + +=== tests/cases/conformance/es2018/dynamicImport/2.ts === +declare var console: any; +>console : any + +class C { +>C : C + + private myModule = import("./0"); +>myModule : Promise +>import("./0") : Promise +>"./0" : "./0" + + method() { +>method : () => void + + 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/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>this.myModule : Promise +>this : this +>myModule : Promise +>then : (onfulfilled?: (value: typeof "tests/cases/conformance/es2018/dynamicImport/0") => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>Zero => { console.log(Zero.foo()); } : (Zero: typeof "tests/cases/conformance/es2018/dynamicImport/0") => void +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" + + console.log(Zero.foo()); +>console.log(Zero.foo()) : any +>console.log : any +>console : any +>log : any +>Zero.foo() : string +>Zero.foo : () => string +>Zero : typeof "tests/cases/conformance/es2018/dynamicImport/0" +>foo : () => string + + }, async err => { +>async err => { console.log(err); let one = await import("./1"); console.log(one.backup()); } : (err: any) => Promise +>err : any + + console.log(err); +>console.log(err) : any +>console.log : any +>console : any +>log : any +>err : any + + let one = await import("./1"); +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>await import("./1") : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>import("./1") : Promise +>"./1" : "./1" + + console.log(one.backup()); +>console.log(one.backup()) : any +>console.log : any +>console : any +>log : any +>one.backup() : string +>one.backup : () => string +>one : typeof "tests/cases/conformance/es2018/dynamicImport/1" +>backup : () => string + + }); + } +} diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js new file mode 100644 index 00000000000..0ba536b4c39 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.js @@ -0,0 +1,61 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionReturnPromiseOfAny.ts] //// + +//// [defaultPath.ts] +export class C {} + +//// [1.ts] +import * as defaultModule from "./defaultPath"; +declare function getSpecifier(): string; +declare function ValidSomeCondition(): boolean; +declare var whatToLoad: boolean; +declare const directory: string; +declare const moduleFile: number; + +import(`${directory}\${moduleFile}`); +import(getSpecifier()); + +var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); +var p1: Promise = import(getSpecifier()); +var p11: Promise = import(getSpecifier()); +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") as Promise; +p1.then(zero => { + return zero.foo(); // ok, zero is any +}); + +let j: string; +var p3: Promise = import(j=getSpecifier()); + +function * loadModule(directories: string[]) { + for (const directory of directories) { + const path = `${directory}\moduleFile`; + import(yield path); + } +} + + +//// [defaultPath.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +class C { +} +exports.C = C; +//// [1.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +Promise.resolve().then(() => require(`${directory}\${moduleFile}`)); +Promise.resolve().then(() => require(getSpecifier())); +var p1 = Promise.resolve().then(() => require(ValidSomeCondition() ? "./0" : "externalModule")); +var p1 = Promise.resolve().then(() => require(getSpecifier())); +var p11 = Promise.resolve().then(() => require(getSpecifier())); +const p2 = Promise.resolve().then(() => require(whatToLoad ? getSpecifier() : "defaulPath")); +p1.then(zero => { + return zero.foo(); // ok, zero is any +}); +let j; +var p3 = Promise.resolve().then(() => require(j = getSpecifier())); +function* loadModule(directories) { + for (const directory of directories) { + const path = `${directory}\moduleFile`; + Promise.resolve().then(() => require(yield path)); + } +} diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols new file mode 100644 index 00000000000..275bedd4c93 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.symbols @@ -0,0 +1,89 @@ +=== tests/cases/conformance/es2018/dynamicImport/defaultPath.ts === +export class C {} +>C : Symbol(C, Decl(defaultPath.ts, 0, 0)) + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import * as defaultModule from "./defaultPath"; +>defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) + +declare function getSpecifier(): string; +>getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) + +declare function ValidSomeCondition(): boolean; +>ValidSomeCondition : Symbol(ValidSomeCondition, Decl(1.ts, 1, 40)) + +declare var whatToLoad: boolean; +>whatToLoad : Symbol(whatToLoad, Decl(1.ts, 3, 11)) + +declare const directory: string; +>directory : Symbol(directory, Decl(1.ts, 4, 13)) + +declare const moduleFile: number; +>moduleFile : Symbol(moduleFile, Decl(1.ts, 5, 13)) + +import(`${directory}\${moduleFile}`); +>directory : Symbol(directory, Decl(1.ts, 4, 13)) + +import(getSpecifier()); +>getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) + +var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); +>p1 : Symbol(p1, Decl(1.ts, 10, 3), Decl(1.ts, 11, 3)) +>ValidSomeCondition : Symbol(ValidSomeCondition, Decl(1.ts, 1, 40)) + +var p1: Promise = import(getSpecifier()); +>p1 : Symbol(p1, Decl(1.ts, 10, 3), Decl(1.ts, 11, 3)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) + +var p11: Promise = import(getSpecifier()); +>p11 : Symbol(p11, Decl(1.ts, 12, 3)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) +>getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) + +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") as Promise; +>p2 : Symbol(p2, Decl(1.ts, 13, 5)) +>whatToLoad : Symbol(whatToLoad, Decl(1.ts, 3, 11)) +>getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) + +p1.then(zero => { +>p1.then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>p1 : Symbol(p1, Decl(1.ts, 10, 3), Decl(1.ts, 11, 3)) +>then : Symbol(Promise.then, Decl(lib.es5.d.ts, --, --)) +>zero : Symbol(zero, Decl(1.ts, 14, 8)) + + return zero.foo(); // ok, zero is any +>zero : Symbol(zero, Decl(1.ts, 14, 8)) + +}); + +let j: string; +>j : Symbol(j, Decl(1.ts, 18, 3)) + +var p3: Promise = import(j=getSpecifier()); +>p3 : Symbol(p3, Decl(1.ts, 19, 3)) +>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>defaultModule : Symbol(defaultModule, Decl(1.ts, 0, 6)) +>j : Symbol(j, Decl(1.ts, 18, 3)) +>getSpecifier : Symbol(getSpecifier, Decl(1.ts, 0, 47)) + +function * loadModule(directories: string[]) { +>loadModule : Symbol(loadModule, Decl(1.ts, 19, 65)) +>directories : Symbol(directories, Decl(1.ts, 21, 22)) + + for (const directory of directories) { +>directory : Symbol(directory, Decl(1.ts, 22, 14)) +>directories : Symbol(directories, Decl(1.ts, 21, 22)) + + const path = `${directory}\moduleFile`; +>path : Symbol(path, Decl(1.ts, 23, 13)) +>directory : Symbol(directory, Decl(1.ts, 22, 14)) + + import(yield path); +>path : Symbol(path, Decl(1.ts, 23, 13)) + } +} + diff --git a/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types new file mode 100644 index 00000000000..4337e970bd1 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionReturnPromiseOfAny.types @@ -0,0 +1,118 @@ +=== tests/cases/conformance/es2018/dynamicImport/defaultPath.ts === +export class C {} +>C : C + +=== tests/cases/conformance/es2018/dynamicImport/1.ts === +import * as defaultModule from "./defaultPath"; +>defaultModule : typeof defaultModule + +declare function getSpecifier(): string; +>getSpecifier : () => string + +declare function ValidSomeCondition(): boolean; +>ValidSomeCondition : () => boolean + +declare var whatToLoad: boolean; +>whatToLoad : boolean + +declare const directory: string; +>directory : string + +declare const moduleFile: number; +>moduleFile : number + +import(`${directory}\${moduleFile}`); +>import(`${directory}\${moduleFile}`) : Promise +>`${directory}\${moduleFile}` : string +>directory : string + +import(getSpecifier()); +>import(getSpecifier()) : Promise +>getSpecifier() : string +>getSpecifier : () => string + +var p1 = import(ValidSomeCondition() ? "./0" : "externalModule"); +>p1 : Promise +>import(ValidSomeCondition() ? "./0" : "externalModule") : Promise +>ValidSomeCondition() ? "./0" : "externalModule" : "./0" | "externalModule" +>ValidSomeCondition() : boolean +>ValidSomeCondition : () => boolean +>"./0" : "./0" +>"externalModule" : "externalModule" + +var p1: Promise = import(getSpecifier()); +>p1 : Promise +>Promise : Promise +>import(getSpecifier()) : Promise +>getSpecifier() : string +>getSpecifier : () => string + +var p11: Promise = import(getSpecifier()); +>p11 : Promise +>Promise : Promise +>defaultModule : typeof defaultModule +>import(getSpecifier()) : Promise +>getSpecifier() : string +>getSpecifier : () => string + +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") as Promise; +>p2 : Promise +>import(whatToLoad ? getSpecifier() : "defaulPath") as Promise : Promise +>import(whatToLoad ? getSpecifier() : "defaulPath") : Promise +>whatToLoad ? getSpecifier() : "defaulPath" : string +>whatToLoad : boolean +>getSpecifier() : string +>getSpecifier : () => string +>"defaulPath" : "defaulPath" +>Promise : Promise +>defaultModule : typeof defaultModule + +p1.then(zero => { +>p1.then(zero => { return zero.foo(); // ok, zero is any}) : Promise +>p1.then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>p1 : Promise +>then : (onfulfilled?: (value: any) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike) => Promise +>zero => { return zero.foo(); // ok, zero is any} : (zero: any) => any +>zero : any + + return zero.foo(); // ok, zero is any +>zero.foo() : any +>zero.foo : any +>zero : any +>foo : any + +}); + +let j: string; +>j : string + +var p3: Promise = import(j=getSpecifier()); +>p3 : Promise +>Promise : Promise +>defaultModule : typeof defaultModule +>import(j=getSpecifier()) : Promise +>j=getSpecifier() : string +>j : string +>getSpecifier() : string +>getSpecifier : () => string + +function * loadModule(directories: string[]) { +>loadModule : (directories: string[]) => IterableIterator +>directories : string[] + + for (const directory of directories) { +>directory : string +>directories : string[] + + const path = `${directory}\moduleFile`; +>path : string +>`${directory}\moduleFile` : string +>directory : string + + import(yield path); +>import(yield path) : Promise +>yield path : any +>path : string + } +} + diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt new file mode 100644 index 00000000000..8136597ab93 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.errors.txt @@ -0,0 +1,32 @@ +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(6,8): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(7,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(8,19): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(13,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. +tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts(14,17): error TS7035: Dynamic import's specifier must be of type 'string', but here has type '() => string'. + + +==== tests/cases/conformance/es2018/dynamicImport/importCallExpressionSpecifierNotStringTypeError.ts (5 errors) ==== + + declare function getSpecifier(): boolean; + declare var whatToLoad: boolean; + + // Error specifier is not assignable to string + import(getSpecifier()); + ~~~~~~~~~~~~~~ +!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. + var p1 = import(getSpecifier()); + ~~~~~~~~~~~~~~ +!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean'. + const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'boolean | "defaulPath"'. + p1.then(zero => { + return zero.foo(); // ok, zero is any + }); + + var p3 = import(["path1", "path2"]); + ~~~~~~~~~~~~~~~~~~ +!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type 'string[]'. + var p4 = import(()=>"PathToModule"); + ~~~~~~~~~~~~~~~~~~ +!!! error TS7035: Dynamic import's specifier must be of type 'string', but here has type '() => string'. \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js new file mode 100644 index 00000000000..23dd3425c45 --- /dev/null +++ b/tests/baselines/reference/importCallExpressionSpecifierNotStringTypeError.js @@ -0,0 +1,27 @@ +//// [importCallExpressionSpecifierNotStringTypeError.ts] + +declare function getSpecifier(): boolean; +declare var whatToLoad: boolean; + +// Error specifier is not assignable to string +import(getSpecifier()); +var p1 = import(getSpecifier()); +const p2 = import(whatToLoad ? getSpecifier() : "defaulPath") +p1.then(zero => { + return zero.foo(); // ok, zero is any +}); + +var p3 = import(["path1", "path2"]); +var p4 = import(()=>"PathToModule"); + +//// [importCallExpressionSpecifierNotStringTypeError.js] +"use strict"; +// Error specifier is not assignable to string +Promise.resolve().then(() => require(getSpecifier())); +var p1 = Promise.resolve().then(() => require(getSpecifier())); +const p2 = Promise.resolve().then(() => require(whatToLoad ? getSpecifier() : "defaulPath")); +p1.then(zero => { + return zero.foo(); // ok, zero is any +}); +var p3 = Promise.resolve().then(() => require(["path1", "path2"])); +var p4 = Promise.resolve().then(() => require(() => "PathToModule")); diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt new file mode 100644 index 00000000000..d0b17931e2e --- /dev/null +++ b/tests/baselines/reference/importCallExpressionWithTypeArgument.errors.txt @@ -0,0 +1,19 @@ +tests/cases/conformance/es2018/dynamicImport/1.ts(2,10): error TS1323: Dynamic import cannot have type arguments +tests/cases/conformance/es2018/dynamicImport/1.ts(3,10): error TS1323: Dynamic import cannot have type arguments + + +==== tests/cases/conformance/es2018/dynamicImport/0.ts (0 errors) ==== + + export function foo() { return "foo"; } + +==== tests/cases/conformance/es2018/dynamicImport/1.ts (2 errors) ==== + "use strict" + var p1 = import>("./0"); // error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS1323: Dynamic import cannot have type arguments + var p2 = import<>("./0"); // error + ~~~~~~~~~~~~~~~ +!!! error TS1323: Dynamic import cannot have type arguments + // p1.then(value => { + // value.anyFunction(); + // }) \ No newline at end of file diff --git a/tests/baselines/reference/importCallExpressionWithTypeArgument.js b/tests/baselines/reference/importCallExpressionWithTypeArgument.js new file mode 100644 index 00000000000..59ad9b6026c --- /dev/null +++ b/tests/baselines/reference/importCallExpressionWithTypeArgument.js @@ -0,0 +1,26 @@ +//// [tests/cases/conformance/es2018/dynamicImport/importCallExpressionWithTypeArgument.ts] //// + +//// [0.ts] + +export function foo() { return "foo"; } + +//// [1.ts] +"use strict" +var p1 = import>("./0"); // error +var p2 = import<>("./0"); // error +// p1.then(value => { +// value.anyFunction(); +// }) + +//// [0.js] +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function foo() { return "foo"; } +exports.foo = foo; +//// [1.js] +"use strict"; +var p1 = (import)("./0"); // error +var p2 = (import)("./0"); // error +// p1.then(value => { +// value.anyFunction(); +// })