mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 20:37:46 -05:00
Forbid await await
This commit is contained in:
@@ -3337,7 +3337,10 @@ namespace ts {
|
||||
function parseAwaitExpression() {
|
||||
const node = <AwaitExpression>createNode(SyntaxKind.AwaitExpression);
|
||||
nextToken();
|
||||
node.expression = parseSimpleUnaryExpression();
|
||||
node.expression = token === SyntaxKind.AwaitKeyword
|
||||
// Forbid `await await`
|
||||
? <UnaryExpression>createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false, Diagnostics.Expression_expected)
|
||||
: parseSimpleUnaryExpression();
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
|
||||
10
tests/baselines/reference/awaitAwait.errors.txt
Normal file
10
tests/baselines/reference/awaitAwait.errors.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
tests/cases/compiler/awaitAwait.ts(2,11): error TS1109: Expression expected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/awaitAwait.ts (1 errors) ====
|
||||
async function f() {
|
||||
await await 0;
|
||||
~~~~~
|
||||
!!! error TS1109: Expression expected.
|
||||
}
|
||||
|
||||
21
tests/baselines/reference/awaitAwait.js
Normal file
21
tests/baselines/reference/awaitAwait.js
Normal file
@@ -0,0 +1,21 @@
|
||||
//// [awaitAwait.ts]
|
||||
async function f() {
|
||||
await await 0;
|
||||
}
|
||||
|
||||
|
||||
//// [awaitAwait.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 f() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
yield ;
|
||||
yield 0;
|
||||
});
|
||||
}
|
||||
4
tests/cases/compiler/awaitAwait.ts
Normal file
4
tests/cases/compiler/awaitAwait.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
// @target: es6
|
||||
async function f() {
|
||||
await await 0;
|
||||
}
|
||||
Reference in New Issue
Block a user