Avoid yield and await check in identifier

This commit is contained in:
kingwl 2021-06-21 15:45:53 +08:00
parent 2b6feefcf6
commit 9644859f29
14 changed files with 184 additions and 129 deletions

View file

@ -1510,17 +1510,17 @@ namespace ts {
return true;
}
// If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is
// considered a keyword and is not an identifier.
if (token() === SyntaxKind.YieldKeyword && inYieldContext()) {
return false;
}
// // If we have a 'yield' keyword, and we're in the [yield] context, then 'yield' is
// // considered a keyword and is not an identifier.
// if (token() === SyntaxKind.YieldKeyword && inYieldContext()) {
// return false;
// }
// If we have a 'await' keyword, and we're in the [Await] context, then 'await' is
// considered a keyword and is not an identifier.
if (token() === SyntaxKind.AwaitKeyword && inAwaitContext()) {
return false;
}
// // If we have a 'await' keyword, and we're in the [Await] context, then 'await' is
// // considered a keyword and is not an identifier.
// if (token() === SyntaxKind.AwaitKeyword && inAwaitContext()) {
// return false;
// }
return token() > SyntaxKind.LastReservedWord;
}

View file

@ -1,18 +1,24 @@
tests/cases/conformance/async/es2017/await_unaryExpression_es2017_3.ts(2,7): error TS1109: Expression expected.
tests/cases/conformance/async/es2017/await_unaryExpression_es2017_3.ts(6,7): error TS1109: Expression expected.
tests/cases/conformance/async/es2017/await_unaryExpression_es2017_3.ts(2,7): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es2017/await_unaryExpression_es2017_3.ts(2,13): error TS1005: ';' expected.
tests/cases/conformance/async/es2017/await_unaryExpression_es2017_3.ts(6,7): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es2017/await_unaryExpression_es2017_3.ts(6,13): error TS1005: ';' expected.
==== tests/cases/conformance/async/es2017/await_unaryExpression_es2017_3.ts (2 errors) ====
==== tests/cases/conformance/async/es2017/await_unaryExpression_es2017_3.ts (4 errors) ====
async function bar1() {
++await 42; // Error
~~~~~
!!! error TS1109: Expression expected.
!!! error TS2304: Cannot find name 'await'.
~~
!!! error TS1005: ';' expected.
}
async function bar2() {
--await 42; // Error
~~~~~
!!! error TS1109: Expression expected.
!!! error TS2304: Cannot find name 'await'.
~~
!!! error TS1005: ';' expected.
}
async function bar3() {

View file

@ -19,12 +19,12 @@ async function bar4() {
//// [await_unaryExpression_es2017_3.js]
async function bar1() {
++;
await 42; // Error
++await;
42; // Error
}
async function bar2() {
--;
await 42; // Error
--await;
42; // Error
}
async function bar3() {
var x = 42;

View file

@ -3,9 +3,8 @@ async function bar1() {
>bar1 : () => Promise<void>
++await 42; // Error
>++ : number
> : any
>await 42 : 42
>++await : number
>await : any
>42 : 42
}
@ -13,9 +12,8 @@ async function bar2() {
>bar2 : () => Promise<void>
--await 42; // Error
>-- : number
> : any
>await 42 : 42
>--await : number
>await : any
>42 : 42
}

View file

@ -1,18 +1,24 @@
tests/cases/conformance/async/es6/await_unaryExpression_es6_3.ts(2,7): error TS1109: Expression expected.
tests/cases/conformance/async/es6/await_unaryExpression_es6_3.ts(6,7): error TS1109: Expression expected.
tests/cases/conformance/async/es6/await_unaryExpression_es6_3.ts(2,7): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es6/await_unaryExpression_es6_3.ts(2,13): error TS1005: ';' expected.
tests/cases/conformance/async/es6/await_unaryExpression_es6_3.ts(6,7): error TS2304: Cannot find name 'await'.
tests/cases/conformance/async/es6/await_unaryExpression_es6_3.ts(6,13): error TS1005: ';' expected.
==== tests/cases/conformance/async/es6/await_unaryExpression_es6_3.ts (2 errors) ====
==== tests/cases/conformance/async/es6/await_unaryExpression_es6_3.ts (4 errors) ====
async function bar1() {
++await 42; // Error
~~~~~
!!! error TS1109: Expression expected.
!!! error TS2304: Cannot find name 'await'.
~~
!!! error TS1005: ';' expected.
}
async function bar2() {
--await 42; // Error
~~~~~
!!! error TS1109: Expression expected.
!!! error TS2304: Cannot find name 'await'.
~~
!!! error TS1005: ';' expected.
}
async function bar3() {

View file

@ -29,14 +29,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
function bar1() {
return __awaiter(this, void 0, void 0, function* () {
++;
yield 42; // Error
++await;
42; // Error
});
}
function bar2() {
return __awaiter(this, void 0, void 0, function* () {
--;
yield 42; // Error
--await;
42; // Error
});
}
function bar3() {

View file

@ -3,9 +3,8 @@ async function bar1() {
>bar1 : () => Promise<void>
++await 42; // Error
>++ : number
> : any
>await 42 : 42
>++await : number
>await : any
>42 : 42
}
@ -13,9 +12,8 @@ async function bar2() {
>bar2 : () => Promise<void>
--await 42; // Error
>-- : number
> : any
>await 42 : 42
>--await : number
>await : any
>42 : 42
}

View file

@ -1,14 +1,17 @@
error TS2318: Cannot find global type 'IterableIterator'.
tests/cases/compiler/castOfYield.ts(4,14): error TS1109: Expression expected.
tests/cases/compiler/castOfYield.ts(4,14): error TS2304: Cannot find name 'yield'.
tests/cases/compiler/castOfYield.ts(4,20): error TS1005: ';' expected.
!!! error TS2318: Cannot find global type 'IterableIterator'.
==== tests/cases/compiler/castOfYield.ts (1 errors) ====
==== tests/cases/compiler/castOfYield.ts (2 errors) ====
function* f() {
<number> (yield 0);
// Unlike await, yield is not allowed to appear in a simple unary expression.
<number> yield 0;
~~~~~
!!! error TS1109: Expression expected.
!!! error TS2304: Cannot find name 'yield'.
~
!!! error TS1005: ';' expected.
}

View file

@ -41,10 +41,8 @@ function f() {
case 1:
(_a.sent());
// Unlike await, yield is not allowed to appear in a simple unary expression.
;
return [4 /*yield*/, 0];
case 2:
_a.sent();
yield;
0;
return [2 /*return*/];
}
});

View file

@ -10,9 +10,8 @@ function* f() {
// Unlike await, yield is not allowed to appear in a simple unary expression.
<number> yield 0;
><number> : number
> : any
>yield 0 : any
><number> yield : number
>yield : any
>0 : 0
}

View file

@ -4,23 +4,40 @@ tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(5,14): error TS
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(5,16): error TS2693: 'string' only refers to a type, but is being used as a value here.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(8,14): error TS1005: '>' expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(8,16): error TS2693: 'string' only refers to a type, but is being used as a value here.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(11,17): error TS1109: Expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(11,22): error TS1109: Expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(11,23): error TS2693: 'string' only refers to a type, but is being used as a value here.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(11,29): error TS1005: ',' expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(11,17): error TS2304: Cannot find name 'await'.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(15,8): error TS1109: Expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(18,2): error TS1109: Expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(18,8): error TS1146: Declaration expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(18,8): error TS2304: Cannot find name 'x'.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(21,2): error TS1109: Expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(26,6): error TS1109: Expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(30,6): error TS1109: Expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(18,9): error TS1005: ';' expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(22,6): error TS1146: Declaration expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(22,7): error TS2304: Cannot find name 'C3'.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(22,10): error TS1005: ';' expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(26,6): error TS2304: Cannot find name 'await'.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(27,11): error TS1005: ';' expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(27,12): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(27,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(27,15): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(28,1): error TS1109: Expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(30,6): error TS2304: Cannot find name 'await'.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(30,13): error TS1005: ';' expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(34,12): error TS1109: Expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(40,14): error TS1109: Expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(41,14): error TS1109: Expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(40,14): error TS2304: Cannot find name 'await'.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(40,22): error TS1005: ')' expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(40,23): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(40,25): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(41,5): error TS2304: Cannot find name 'method2'.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(41,13): error TS1135: Argument expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(41,24): error TS2304: Cannot find name 'x'.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(41,28): error TS1005: ';' expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(42,5): error TS2304: Cannot find name 'method3'.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(42,13): error TS1135: Argument expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(42,20): error TS1109: Expression expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(42,23): error TS2304: Cannot find name 'x'.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(42,27): error TS1005: ';' expected.
tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(43,1): error TS1109: Expression expected.
==== tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts (20 errors) ====
==== tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts (37 errors) ====
export {};
// reparse call as invalid await should error
@ -45,13 +62,7 @@ tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(42,20): error T
// reparse class extends clause should fail
class C extends await<string> {
~~~~~
!!! error TS1109: Expression expected.
~
!!! error TS1109: Expression expected.
~~~~~~
!!! error TS2693: 'string' only refers to a type, but is being used as a value here.
~
!!! error TS1005: ',' expected.
!!! error TS2304: Cannot find name 'await'.
}
// await in class decorators should fail
@ -61,28 +72,46 @@ tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(42,20): error T
class C1 {}
@await(x)
~~~~~
!!! error TS1109: Expression expected.
!!! error TS1146: Declaration expected.
~
!!! error TS2304: Cannot find name 'x'.
~
!!! error TS1005: ';' expected.
class C2 {}
@await
~~~~~
!!! error TS1109: Expression expected.
class C3 {}
!!! error TS1146: Declaration expected.
~~
!!! error TS2304: Cannot find name 'C3'.
~
!!! error TS1005: ';' expected.
// await in member decorators should fail
class C4 {
@await
~~~~~
!!! error TS1109: Expression expected.
!!! error TS2304: Cannot find name 'await'.
["foo"]() {}
~
!!! error TS1005: ';' expected.
~
!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
~
!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
~
!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
}
~
!!! error TS1109: Expression expected.
class C5 {
@await(1)
~~~~~
!!! error TS1109: Expression expected.
!!! error TS2304: Cannot find name 'await'.
~
!!! error TS1005: ';' expected.
["foo"]() {}
}
class C6 {
@ -96,12 +125,34 @@ tests/cases/conformance/externalModules/topLevelAwaitErrors.1.ts(42,20): error T
class C7 {
method1(@await [x]) {}
~~~~~
!!! error TS1109: Expression expected.
!!! error TS2304: Cannot find name 'await'.
~
!!! error TS1005: ')' expected.
~
!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
~
!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
method2(@await(1) [x]) {}
~~~~~
!!! error TS1109: Expression expected.
~~~~~~~
!!! error TS2304: Cannot find name 'method2'.
~
!!! error TS1135: Argument expression expected.
~
!!! error TS2304: Cannot find name 'x'.
~
!!! error TS1005: ';' expected.
method3(@(await) [x]) {}
~~~~~~~
!!! error TS2304: Cannot find name 'method3'.
~
!!! error TS1135: Argument expression expected.
~
!!! error TS1109: Expression expected.
~
!!! error TS2304: Cannot find name 'x'.
~
!!! error TS1005: ';' expected.
}
~
!!! error TS1109: Expression expected.

View file

@ -51,7 +51,7 @@ await , string > (1);
// reparse tagged template as invalid await should error
await , string > ``;
// reparse class extends clause should fail
class C extends string {
class C extends await {
}
// await in class decorators should fail
let C1 = class C1 {
@ -59,27 +59,27 @@ let C1 = class C1 {
C1 = __decorate([
(await )
], C1);
let C2 = class C2 {
};
C2 = __decorate([
(x)
], C2);
let C3 = class C3 {
};
C3 = __decorate([
], C3);
x;
;
class C2 {
}
C3;
{ }
// await in member decorators should fail
class C4 {
["foo"]() { }
"foo";
}
__decorate([
], C4.prototype, "foo", null);
await
], C4.prototype, "foo", void 0);
;
class C5 {
1;
["foo"]() { }
}
__decorate([
(1)
], C5.prototype, "foo", null);
await
], C5.prototype, 1, void 0);
class C6 {
["foo"]() { }
}
@ -88,17 +88,13 @@ __decorate([
], C6.prototype, "foo", null);
// await in parameter decorators should fail
class C7 {
method1([x]) { }
method2([x]) { }
method3([x]) { }
}
__decorate([
__param(0, )
__param(0, await)
], C7.prototype, "method1", null);
__decorate([
__param(0, (1))
], C7.prototype, "method2", null);
__decorate([
__param(0, (await ))
], C7.prototype, "method3", null);
method2(await (1)[x]);
{ }
method3((await )[x]);
{ }
;
export {};

View file

@ -20,11 +20,10 @@ class C1 {}
@await(x)
class C2 {}
>C2 : Symbol(C2, Decl(topLevelAwaitErrors.1.ts, 15, 11))
>C2 : Symbol(C2, Decl(topLevelAwaitErrors.1.ts, 17, 9))
@await
class C3 {}
>C3 : Symbol(C3, Decl(topLevelAwaitErrors.1.ts, 18, 11))
// await in member decorators should fail
class C4 {
@ -32,16 +31,17 @@ class C4 {
@await
["foo"]() {}
>["foo"] : Symbol(C4["foo"], Decl(topLevelAwaitErrors.1.ts, 24, 10))
>"foo" : Symbol(C4["foo"], Decl(topLevelAwaitErrors.1.ts, 24, 10))
}
class C5 {
>C5 : Symbol(C5, Decl(topLevelAwaitErrors.1.ts, 27, 1))
@await(1)
>1 : Symbol(C5[1], Decl(topLevelAwaitErrors.1.ts, 28, 10))
["foo"]() {}
>["foo"] : Symbol(C5["foo"], Decl(topLevelAwaitErrors.1.ts, 28, 10))
>"foo" : Symbol(C5["foo"], Decl(topLevelAwaitErrors.1.ts, 28, 10))
>["foo"] : Symbol(C5["foo"], Decl(topLevelAwaitErrors.1.ts, 29, 13))
>"foo" : Symbol(C5["foo"], Decl(topLevelAwaitErrors.1.ts, 29, 13))
}
class C6 {
>C6 : Symbol(C6, Decl(topLevelAwaitErrors.1.ts, 31, 1))
@ -58,14 +58,9 @@ class C7 {
method1(@await [x]) {}
>method1 : Symbol(C7.method1, Decl(topLevelAwaitErrors.1.ts, 38, 10))
>x : Symbol(x, Decl(topLevelAwaitErrors.1.ts, 39, 20))
>x : Symbol(x, Decl(topLevelAwaitErrors.1.ts, 39, 12))
method2(@await(1) [x]) {}
>method2 : Symbol(C7.method2, Decl(topLevelAwaitErrors.1.ts, 39, 26))
>x : Symbol(x, Decl(topLevelAwaitErrors.1.ts, 40, 23))
method3(@(await) [x]) {}
>method3 : Symbol(C7.method3, Decl(topLevelAwaitErrors.1.ts, 40, 29))
>x : Symbol(x, Decl(topLevelAwaitErrors.1.ts, 41, 22))
}

View file

@ -32,7 +32,7 @@ await <number, string> ``;
// reparse class extends clause should fail
class C extends await<string> {
>C : C
>string : any
>await : any
}
// await in class decorators should fail
@ -45,37 +45,37 @@ class C1 {}
>C1 : C1
@await(x)
>await(x) : any
> : any
>await : any
>x : any
> : any
class C2 {}
>C2 : C2
@await
> : any
>await : any
class C3 {}
>C3 : C3
>C3 : any
// await in member decorators should fail
class C4 {
>C4 : C4
@await
> : any
>await : any
["foo"]() {}
>["foo"] : () => void
>"foo" : "foo"
>"foo" : any
}
> : any
class C5 {
>C5 : C5
@await(1)
>await(1) : any
> : any
>1 : 1
>await : any
>1 : any
["foo"]() {}
>["foo"] : () => void
@ -99,22 +99,27 @@ class C7 {
>C7 : C7
method1(@await [x]) {}
>method1 : ([x]: [any]) => void
> : any
>method1 : (x: any) => any
>await : any
>x : any
method2(@await(1) [x]) {}
>method2 : ([x]: [any]) => void
>await(1) : any
> : any
>method2(@await(1) [x]) : any
>method2 : any
>await(1) [x] : any
>(1) [x] : any
>(1) : 1
>1 : 1
>x : any
method3(@(await) [x]) {}
>method3 : ([x]: [any]) => void
>method3(@(await) [x]) : any
>method3 : any
>(await) [x] : any
>(await) : any
>await : any
> : any
>x : any
}
> : any