Skip to content

Commit 71fc581

Browse files
committed
Fix8256 (#8292)
* Consider identifier in await expression to be expression * Add tests * Update baselines
1 parent c953128 commit 71fc581

9 files changed

+219
-0
lines changed

src/compiler/emitter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
15241524
switch (parent.kind) {
15251525
case SyntaxKind.ArrayLiteralExpression:
15261526
case SyntaxKind.AsExpression:
1527+
case SyntaxKind.AwaitExpression:
15271528
case SyntaxKind.BinaryExpression:
15281529
case SyntaxKind.CallExpression:
15291530
case SyntaxKind.CaseClause:
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//// [tests/cases/conformance/es6/modules/defaultExportInAwaitExpression01.ts] ////
2+
3+
//// [a.ts]
4+
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
5+
export default x;
6+
7+
//// [b.ts]
8+
import x from './a';
9+
10+
( async function() {
11+
const value = await x;
12+
}() );
13+
14+
15+
//// [a.js]
16+
(function (factory) {
17+
if (typeof module === 'object' && typeof module.exports === 'object') {
18+
var v = factory(require, exports); if (v !== undefined) module.exports = v;
19+
}
20+
else if (typeof define === 'function' && define.amd) {
21+
define(["require", "exports"], factory);
22+
}
23+
})(function (require, exports) {
24+
"use strict";
25+
const x = new Promise((resolve, reject) => { resolve({}); });
26+
Object.defineProperty(exports, "__esModule", { value: true });
27+
exports.default = x;
28+
});
29+
//// [b.js]
30+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
31+
return new (P || (P = Promise))(function (resolve, reject) {
32+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
33+
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
34+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
35+
step((generator = generator.apply(thisArg, _arguments)).next());
36+
});
37+
};
38+
(function (factory) {
39+
if (typeof module === 'object' && typeof module.exports === 'object') {
40+
var v = factory(require, exports); if (v !== undefined) module.exports = v;
41+
}
42+
else if (typeof define === 'function' && define.amd) {
43+
define(["require", "exports", './a'], factory);
44+
}
45+
})(function (require, exports) {
46+
"use strict";
47+
const a_1 = require('./a');
48+
(function () {
49+
return __awaiter(this, void 0, void 0, function* () {
50+
const value = yield a_1.default;
51+
});
52+
}());
53+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/es6/modules/a.ts ===
2+
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
3+
>x : Symbol(x, Decl(a.ts, 0, 5))
4+
>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, --, --))
5+
>resolve : Symbol(resolve, Decl(a.ts, 0, 24))
6+
>reject : Symbol(reject, Decl(a.ts, 0, 33))
7+
>resolve : Symbol(resolve, Decl(a.ts, 0, 24))
8+
9+
export default x;
10+
>x : Symbol(x, Decl(a.ts, 0, 5))
11+
12+
=== tests/cases/conformance/es6/modules/b.ts ===
13+
import x from './a';
14+
>x : Symbol(x, Decl(b.ts, 0, 6))
15+
16+
( async function() {
17+
const value = await x;
18+
>value : Symbol(value, Decl(b.ts, 3, 9))
19+
>x : Symbol(x, Decl(b.ts, 0, 6))
20+
21+
}() );
22+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== tests/cases/conformance/es6/modules/a.ts ===
2+
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
3+
>x : Promise<{}>
4+
>new Promise( ( resolve, reject ) => { resolve( {} ); } ) : Promise<{}>
5+
>Promise : PromiseConstructor
6+
>( resolve, reject ) => { resolve( {} ); } : (resolve: (value?: {} | PromiseLike<{}>) => void, reject: (reason?: any) => void) => void
7+
>resolve : (value?: {} | PromiseLike<{}>) => void
8+
>reject : (reason?: any) => void
9+
>resolve( {} ) : void
10+
>resolve : (value?: {} | PromiseLike<{}>) => void
11+
>{} : {}
12+
13+
export default x;
14+
>x : Promise<{}>
15+
16+
=== tests/cases/conformance/es6/modules/b.ts ===
17+
import x from './a';
18+
>x : Promise<{}>
19+
20+
( async function() {
21+
>( async function() { const value = await x;}() ) : Promise<void>
22+
>async function() { const value = await x;}() : Promise<void>
23+
>async function() { const value = await x;} : () => Promise<void>
24+
25+
const value = await x;
26+
>value : {}
27+
>await x : {}
28+
>x : Promise<{}>
29+
30+
}() );
31+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//// [tests/cases/conformance/es6/modules/defaultExportInAwaitExpression02.ts] ////
2+
3+
//// [a.ts]
4+
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
5+
export default x;
6+
7+
//// [b.ts]
8+
import x from './a';
9+
10+
( async function() {
11+
const value = await x;
12+
}() );
13+
14+
15+
//// [a.js]
16+
"use strict";
17+
const x = new Promise((resolve, reject) => { resolve({}); });
18+
Object.defineProperty(exports, "__esModule", { value: true });
19+
exports.default = x;
20+
//// [b.js]
21+
"use strict";
22+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
23+
return new (P || (P = Promise))(function (resolve, reject) {
24+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25+
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
26+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
27+
step((generator = generator.apply(thisArg, _arguments)).next());
28+
});
29+
};
30+
const a_1 = require('./a');
31+
(function () {
32+
return __awaiter(this, void 0, void 0, function* () {
33+
const value = yield a_1.default;
34+
});
35+
}());
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/es6/modules/a.ts ===
2+
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
3+
>x : Symbol(x, Decl(a.ts, 0, 5))
4+
>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, --, --))
5+
>resolve : Symbol(resolve, Decl(a.ts, 0, 24))
6+
>reject : Symbol(reject, Decl(a.ts, 0, 33))
7+
>resolve : Symbol(resolve, Decl(a.ts, 0, 24))
8+
9+
export default x;
10+
>x : Symbol(x, Decl(a.ts, 0, 5))
11+
12+
=== tests/cases/conformance/es6/modules/b.ts ===
13+
import x from './a';
14+
>x : Symbol(x, Decl(b.ts, 0, 6))
15+
16+
( async function() {
17+
const value = await x;
18+
>value : Symbol(value, Decl(b.ts, 3, 9))
19+
>x : Symbol(x, Decl(b.ts, 0, 6))
20+
21+
}() );
22+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
=== tests/cases/conformance/es6/modules/a.ts ===
2+
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
3+
>x : Promise<{}>
4+
>new Promise( ( resolve, reject ) => { resolve( {} ); } ) : Promise<{}>
5+
>Promise : PromiseConstructor
6+
>( resolve, reject ) => { resolve( {} ); } : (resolve: (value?: {} | PromiseLike<{}>) => void, reject: (reason?: any) => void) => void
7+
>resolve : (value?: {} | PromiseLike<{}>) => void
8+
>reject : (reason?: any) => void
9+
>resolve( {} ) : void
10+
>resolve : (value?: {} | PromiseLike<{}>) => void
11+
>{} : {}
12+
13+
export default x;
14+
>x : Promise<{}>
15+
16+
=== tests/cases/conformance/es6/modules/b.ts ===
17+
import x from './a';
18+
>x : Promise<{}>
19+
20+
( async function() {
21+
>( async function() { const value = await x;}() ) : Promise<void>
22+
>async function() { const value = await x;}() : Promise<void>
23+
>async function() { const value = await x;} : () => Promise<void>
24+
25+
const value = await x;
26+
>value : {}
27+
>await x : {}
28+
>x : Promise<{}>
29+
30+
}() );
31+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @target: ES6
2+
// @module: umd
3+
// @filename: a.ts
4+
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
5+
export default x;
6+
7+
// @filename: b.ts
8+
import x from './a';
9+
10+
( async function() {
11+
const value = await x;
12+
}() );
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// @target: ES6
2+
// @module: commonjs
3+
// @filename: a.ts
4+
const x = new Promise( ( resolve, reject ) => { resolve( {} ); } );
5+
export default x;
6+
7+
// @filename: b.ts
8+
import x from './a';
9+
10+
( async function() {
11+
const value = await x;
12+
}() );

0 commit comments

Comments
 (0)