mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Merge pull request #16213 from charlespierce/await_yield_literals
Update special cases for await / yield expression parsing
This commit is contained in:
commit
5b12a04965
@ -2972,7 +2972,7 @@ namespace ts {
|
||||
// for now we just check if the next token is an identifier. More heuristics
|
||||
// can be added here later as necessary. We just need to make sure that we
|
||||
// don't accidentally consume something legal.
|
||||
return lookAhead(nextTokenIsIdentifierOrKeywordOrNumberOnSameLine);
|
||||
return lookAhead(nextTokenIsIdentifierOrKeywordOrLiteralOnSameLine);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -3490,7 +3490,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// here we are using similar heuristics as 'isYieldExpression'
|
||||
return lookAhead(nextTokenIsIdentifierOnSameLine);
|
||||
return lookAhead(nextTokenIsIdentifierOrKeywordOrLiteralOnSameLine);
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -4699,9 +4699,9 @@ namespace ts {
|
||||
return token() === SyntaxKind.FunctionKeyword && !scanner.hasPrecedingLineBreak();
|
||||
}
|
||||
|
||||
function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine() {
|
||||
function nextTokenIsIdentifierOrKeywordOrLiteralOnSameLine() {
|
||||
nextToken();
|
||||
return (tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.NumericLiteral) && !scanner.hasPrecedingLineBreak();
|
||||
return (tokenIsIdentifierOrKeyword(token()) || token() === SyntaxKind.NumericLiteral || token() === SyntaxKind.StringLiteral) && !scanner.hasPrecedingLineBreak();
|
||||
}
|
||||
|
||||
function isDeclaration(): boolean {
|
||||
|
||||
45
tests/baselines/reference/awaitLiteralValues.errors.txt
Normal file
45
tests/baselines/reference/awaitLiteralValues.errors.txt
Normal file
@ -0,0 +1,45 @@
|
||||
tests/cases/compiler/awaitLiteralValues.ts(2,5): error TS1308: 'await' expression is only allowed within an async function.
|
||||
tests/cases/compiler/awaitLiteralValues.ts(6,5): error TS1308: 'await' expression is only allowed within an async function.
|
||||
tests/cases/compiler/awaitLiteralValues.ts(10,5): error TS1308: 'await' expression is only allowed within an async function.
|
||||
tests/cases/compiler/awaitLiteralValues.ts(14,5): error TS1308: 'await' expression is only allowed within an async function.
|
||||
tests/cases/compiler/awaitLiteralValues.ts(18,5): error TS1308: 'await' expression is only allowed within an async function.
|
||||
tests/cases/compiler/awaitLiteralValues.ts(22,5): error TS1308: 'await' expression is only allowed within an async function.
|
||||
|
||||
|
||||
==== tests/cases/compiler/awaitLiteralValues.ts (6 errors) ====
|
||||
function awaitString() {
|
||||
await 'literal';
|
||||
~~~~~
|
||||
!!! error TS1308: 'await' expression is only allowed within an async function.
|
||||
}
|
||||
|
||||
function awaitNumber() {
|
||||
await 1;
|
||||
~~~~~
|
||||
!!! error TS1308: 'await' expression is only allowed within an async function.
|
||||
}
|
||||
|
||||
function awaitTrue() {
|
||||
await true;
|
||||
~~~~~
|
||||
!!! error TS1308: 'await' expression is only allowed within an async function.
|
||||
}
|
||||
|
||||
function awaitFalse() {
|
||||
await false;
|
||||
~~~~~
|
||||
!!! error TS1308: 'await' expression is only allowed within an async function.
|
||||
}
|
||||
|
||||
function awaitNull() {
|
||||
await null;
|
||||
~~~~~
|
||||
!!! error TS1308: 'await' expression is only allowed within an async function.
|
||||
}
|
||||
|
||||
function awaitUndefined() {
|
||||
await undefined;
|
||||
~~~~~
|
||||
!!! error TS1308: 'await' expression is only allowed within an async function.
|
||||
}
|
||||
|
||||
45
tests/baselines/reference/awaitLiteralValues.js
Normal file
45
tests/baselines/reference/awaitLiteralValues.js
Normal file
@ -0,0 +1,45 @@
|
||||
//// [awaitLiteralValues.ts]
|
||||
function awaitString() {
|
||||
await 'literal';
|
||||
}
|
||||
|
||||
function awaitNumber() {
|
||||
await 1;
|
||||
}
|
||||
|
||||
function awaitTrue() {
|
||||
await true;
|
||||
}
|
||||
|
||||
function awaitFalse() {
|
||||
await false;
|
||||
}
|
||||
|
||||
function awaitNull() {
|
||||
await null;
|
||||
}
|
||||
|
||||
function awaitUndefined() {
|
||||
await undefined;
|
||||
}
|
||||
|
||||
|
||||
//// [awaitLiteralValues.js]
|
||||
function awaitString() {
|
||||
yield 'literal';
|
||||
}
|
||||
function awaitNumber() {
|
||||
yield 1;
|
||||
}
|
||||
function awaitTrue() {
|
||||
yield true;
|
||||
}
|
||||
function awaitFalse() {
|
||||
yield false;
|
||||
}
|
||||
function awaitNull() {
|
||||
yield null;
|
||||
}
|
||||
function awaitUndefined() {
|
||||
yield undefined;
|
||||
}
|
||||
10
tests/baselines/reference/yieldStringLiteral.errors.txt
Normal file
10
tests/baselines/reference/yieldStringLiteral.errors.txt
Normal file
@ -0,0 +1,10 @@
|
||||
tests/cases/compiler/yieldStringLiteral.ts(2,5): error TS1163: A 'yield' expression is only allowed in a generator body.
|
||||
|
||||
|
||||
==== tests/cases/compiler/yieldStringLiteral.ts (1 errors) ====
|
||||
function yieldString() {
|
||||
yield 'literal';
|
||||
~~~~~
|
||||
!!! error TS1163: A 'yield' expression is only allowed in a generator body.
|
||||
}
|
||||
|
||||
10
tests/baselines/reference/yieldStringLiteral.js
Normal file
10
tests/baselines/reference/yieldStringLiteral.js
Normal file
@ -0,0 +1,10 @@
|
||||
//// [yieldStringLiteral.ts]
|
||||
function yieldString() {
|
||||
yield 'literal';
|
||||
}
|
||||
|
||||
|
||||
//// [yieldStringLiteral.js]
|
||||
function yieldString() {
|
||||
yield 'literal';
|
||||
}
|
||||
23
tests/cases/compiler/awaitLiteralValues.ts
Normal file
23
tests/cases/compiler/awaitLiteralValues.ts
Normal file
@ -0,0 +1,23 @@
|
||||
function awaitString() {
|
||||
await 'literal';
|
||||
}
|
||||
|
||||
function awaitNumber() {
|
||||
await 1;
|
||||
}
|
||||
|
||||
function awaitTrue() {
|
||||
await true;
|
||||
}
|
||||
|
||||
function awaitFalse() {
|
||||
await false;
|
||||
}
|
||||
|
||||
function awaitNull() {
|
||||
await null;
|
||||
}
|
||||
|
||||
function awaitUndefined() {
|
||||
await undefined;
|
||||
}
|
||||
3
tests/cases/compiler/yieldStringLiteral.ts
Normal file
3
tests/cases/compiler/yieldStringLiteral.ts
Normal file
@ -0,0 +1,3 @@
|
||||
function yieldString() {
|
||||
yield 'literal';
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user