diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c4e3c8668fd67..a1f02f520d80b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1524,6 +1524,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge switch (parent.kind) { case SyntaxKind.ArrayLiteralExpression: case SyntaxKind.AsExpression: + case SyntaxKind.AwaitExpression: case SyntaxKind.BinaryExpression: case SyntaxKind.CallExpression: case SyntaxKind.CaseClause: diff --git a/tests/baselines/reference/defaultExportInAwaitExpression01.js b/tests/baselines/reference/defaultExportInAwaitExpression01.js new file mode 100644 index 0000000000000..afd4dfa7a562a --- /dev/null +++ b/tests/baselines/reference/defaultExportInAwaitExpression01.js @@ -0,0 +1,53 @@ +//// [tests/cases/conformance/es6/modules/defaultExportInAwaitExpression01.ts] //// + +//// [a.ts] +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +export default x; + +//// [b.ts] +import x from './a'; + +( async function() { + const value = await x; +}() ); + + +//// [a.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"; + const x = new Promise((resolve, reject) => { resolve({}); }); + Object.defineProperty(exports, "__esModule", { value: true }); + exports.default = x; +}); +//// [b.js] +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments)).next()); + }); +}; +(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", './a'], factory); + } +})(function (require, exports) { + "use strict"; + const a_1 = require('./a'); + (function () { + return __awaiter(this, void 0, void 0, function* () { + const value = yield a_1.default; + }); + }()); +}); diff --git a/tests/baselines/reference/defaultExportInAwaitExpression01.symbols b/tests/baselines/reference/defaultExportInAwaitExpression01.symbols new file mode 100644 index 0000000000000..eb833f63895ca --- /dev/null +++ b/tests/baselines/reference/defaultExportInAwaitExpression01.symbols @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/modules/a.ts === +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +>x : Symbol(x, Decl(a.ts, 0, 5)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(resolve, Decl(a.ts, 0, 24)) +>reject : Symbol(reject, Decl(a.ts, 0, 33)) +>resolve : Symbol(resolve, Decl(a.ts, 0, 24)) + +export default x; +>x : Symbol(x, Decl(a.ts, 0, 5)) + +=== tests/cases/conformance/es6/modules/b.ts === +import x from './a'; +>x : Symbol(x, Decl(b.ts, 0, 6)) + +( async function() { + const value = await x; +>value : Symbol(value, Decl(b.ts, 3, 9)) +>x : Symbol(x, Decl(b.ts, 0, 6)) + +}() ); + diff --git a/tests/baselines/reference/defaultExportInAwaitExpression01.types b/tests/baselines/reference/defaultExportInAwaitExpression01.types new file mode 100644 index 0000000000000..1f7de76b90eae --- /dev/null +++ b/tests/baselines/reference/defaultExportInAwaitExpression01.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/es6/modules/a.ts === +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +>x : Promise<{}> +>new Promise( ( resolve, reject ) => { resolve( {} ); } ) : Promise<{}> +>Promise : PromiseConstructor +>( resolve, reject ) => { resolve( {} ); } : (resolve: (value?: {} | PromiseLike<{}>) => void, reject: (reason?: any) => void) => void +>resolve : (value?: {} | PromiseLike<{}>) => void +>reject : (reason?: any) => void +>resolve( {} ) : void +>resolve : (value?: {} | PromiseLike<{}>) => void +>{} : {} + +export default x; +>x : Promise<{}> + +=== tests/cases/conformance/es6/modules/b.ts === +import x from './a'; +>x : Promise<{}> + +( async function() { +>( async function() { const value = await x;}() ) : Promise +>async function() { const value = await x;}() : Promise +>async function() { const value = await x;} : () => Promise + + const value = await x; +>value : {} +>await x : {} +>x : Promise<{}> + +}() ); + diff --git a/tests/baselines/reference/defaultExportInAwaitExpression02.js b/tests/baselines/reference/defaultExportInAwaitExpression02.js new file mode 100644 index 0000000000000..70a9ce6c2d375 --- /dev/null +++ b/tests/baselines/reference/defaultExportInAwaitExpression02.js @@ -0,0 +1,35 @@ +//// [tests/cases/conformance/es6/modules/defaultExportInAwaitExpression02.ts] //// + +//// [a.ts] +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +export default x; + +//// [b.ts] +import x from './a'; + +( async function() { + const value = await x; +}() ); + + +//// [a.js] +"use strict"; +const x = new Promise((resolve, reject) => { resolve({}); }); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = x; +//// [b.js] +"use strict"; +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments)).next()); + }); +}; +const a_1 = require('./a'); +(function () { + return __awaiter(this, void 0, void 0, function* () { + const value = yield a_1.default; + }); +}()); diff --git a/tests/baselines/reference/defaultExportInAwaitExpression02.symbols b/tests/baselines/reference/defaultExportInAwaitExpression02.symbols new file mode 100644 index 0000000000000..eb833f63895ca --- /dev/null +++ b/tests/baselines/reference/defaultExportInAwaitExpression02.symbols @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/modules/a.ts === +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +>x : Symbol(x, Decl(a.ts, 0, 5)) +>Promise : Symbol(Promise, Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --)) +>resolve : Symbol(resolve, Decl(a.ts, 0, 24)) +>reject : Symbol(reject, Decl(a.ts, 0, 33)) +>resolve : Symbol(resolve, Decl(a.ts, 0, 24)) + +export default x; +>x : Symbol(x, Decl(a.ts, 0, 5)) + +=== tests/cases/conformance/es6/modules/b.ts === +import x from './a'; +>x : Symbol(x, Decl(b.ts, 0, 6)) + +( async function() { + const value = await x; +>value : Symbol(value, Decl(b.ts, 3, 9)) +>x : Symbol(x, Decl(b.ts, 0, 6)) + +}() ); + diff --git a/tests/baselines/reference/defaultExportInAwaitExpression02.types b/tests/baselines/reference/defaultExportInAwaitExpression02.types new file mode 100644 index 0000000000000..1f7de76b90eae --- /dev/null +++ b/tests/baselines/reference/defaultExportInAwaitExpression02.types @@ -0,0 +1,31 @@ +=== tests/cases/conformance/es6/modules/a.ts === +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +>x : Promise<{}> +>new Promise( ( resolve, reject ) => { resolve( {} ); } ) : Promise<{}> +>Promise : PromiseConstructor +>( resolve, reject ) => { resolve( {} ); } : (resolve: (value?: {} | PromiseLike<{}>) => void, reject: (reason?: any) => void) => void +>resolve : (value?: {} | PromiseLike<{}>) => void +>reject : (reason?: any) => void +>resolve( {} ) : void +>resolve : (value?: {} | PromiseLike<{}>) => void +>{} : {} + +export default x; +>x : Promise<{}> + +=== tests/cases/conformance/es6/modules/b.ts === +import x from './a'; +>x : Promise<{}> + +( async function() { +>( async function() { const value = await x;}() ) : Promise +>async function() { const value = await x;}() : Promise +>async function() { const value = await x;} : () => Promise + + const value = await x; +>value : {} +>await x : {} +>x : Promise<{}> + +}() ); + diff --git a/tests/cases/conformance/es6/modules/defaultExportInAwaitExpression01.ts b/tests/cases/conformance/es6/modules/defaultExportInAwaitExpression01.ts new file mode 100644 index 0000000000000..45f1542301663 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportInAwaitExpression01.ts @@ -0,0 +1,12 @@ +// @target: ES6 +// @module: umd +// @filename: a.ts +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +export default x; + +// @filename: b.ts +import x from './a'; + +( async function() { + const value = await x; +}() ); diff --git a/tests/cases/conformance/es6/modules/defaultExportInAwaitExpression02.ts b/tests/cases/conformance/es6/modules/defaultExportInAwaitExpression02.ts new file mode 100644 index 0000000000000..cd878540a3c64 --- /dev/null +++ b/tests/cases/conformance/es6/modules/defaultExportInAwaitExpression02.ts @@ -0,0 +1,12 @@ +// @target: ES6 +// @module: commonjs +// @filename: a.ts +const x = new Promise( ( resolve, reject ) => { resolve( {} ); } ); +export default x; + +// @filename: b.ts +import x from './a'; + +( async function() { + const value = await x; +}() );