File tree Expand file tree Collapse file tree 7 files changed +140
-4
lines changed Expand file tree Collapse file tree 7 files changed +140
-4
lines changed Original file line number Diff line number Diff line change @@ -2960,7 +2960,7 @@ namespace ts {
2960
2960
// for now we just check if the next token is an identifier. More heuristics
2961
2961
// can be added here later as necessary. We just need to make sure that we
2962
2962
// don't accidentally consume something legal.
2963
- return lookAhead ( nextTokenIsIdentifierOrKeywordOrNumberOnSameLine ) ;
2963
+ return lookAhead ( nextTokenIsIdentifierOrKeywordOrLiteralOnSameLine ) ;
2964
2964
}
2965
2965
2966
2966
return false ;
@@ -3478,7 +3478,7 @@ namespace ts {
3478
3478
}
3479
3479
3480
3480
// here we are using similar heuristics as 'isYieldExpression'
3481
- return lookAhead ( nextTokenIsIdentifierOnSameLine ) ;
3481
+ return lookAhead ( nextTokenIsIdentifierOrKeywordOrLiteralOnSameLine ) ;
3482
3482
}
3483
3483
3484
3484
return false ;
@@ -4677,9 +4677,9 @@ namespace ts {
4677
4677
return token ( ) === SyntaxKind . FunctionKeyword && ! scanner . hasPrecedingLineBreak ( ) ;
4678
4678
}
4679
4679
4680
- function nextTokenIsIdentifierOrKeywordOrNumberOnSameLine ( ) {
4680
+ function nextTokenIsIdentifierOrKeywordOrLiteralOnSameLine ( ) {
4681
4681
nextToken ( ) ;
4682
- return ( tokenIsIdentifierOrKeyword ( token ( ) ) || token ( ) === SyntaxKind . NumericLiteral ) && ! scanner . hasPrecedingLineBreak ( ) ;
4682
+ return ( tokenIsIdentifierOrKeyword ( token ( ) ) || token ( ) === SyntaxKind . NumericLiteral || token ( ) === SyntaxKind . StringLiteral ) && ! scanner . hasPrecedingLineBreak ( ) ;
4683
4683
}
4684
4684
4685
4685
function isDeclaration ( ) : boolean {
Original file line number Diff line number Diff line change
1
+ tests/cases/compiler/awaitLiteralValues.ts(2,5): error TS1308: 'await' expression is only allowed within an async function.
2
+ tests/cases/compiler/awaitLiteralValues.ts(6,5): error TS1308: 'await' expression is only allowed within an async function.
3
+ tests/cases/compiler/awaitLiteralValues.ts(10,5): error TS1308: 'await' expression is only allowed within an async function.
4
+ tests/cases/compiler/awaitLiteralValues.ts(14,5): error TS1308: 'await' expression is only allowed within an async function.
5
+ tests/cases/compiler/awaitLiteralValues.ts(18,5): error TS1308: 'await' expression is only allowed within an async function.
6
+ tests/cases/compiler/awaitLiteralValues.ts(22,5): error TS1308: 'await' expression is only allowed within an async function.
7
+
8
+
9
+ ==== tests/cases/compiler/awaitLiteralValues.ts (6 errors) ====
10
+ function awaitString() {
11
+ await 'literal';
12
+ ~~~~~
13
+ !!! error TS1308: 'await' expression is only allowed within an async function.
14
+ }
15
+
16
+ function awaitNumber() {
17
+ await 1;
18
+ ~~~~~
19
+ !!! error TS1308: 'await' expression is only allowed within an async function.
20
+ }
21
+
22
+ function awaitTrue() {
23
+ await true;
24
+ ~~~~~
25
+ !!! error TS1308: 'await' expression is only allowed within an async function.
26
+ }
27
+
28
+ function awaitFalse() {
29
+ await false;
30
+ ~~~~~
31
+ !!! error TS1308: 'await' expression is only allowed within an async function.
32
+ }
33
+
34
+ function awaitNull() {
35
+ await null;
36
+ ~~~~~
37
+ !!! error TS1308: 'await' expression is only allowed within an async function.
38
+ }
39
+
40
+ function awaitUndefined() {
41
+ await undefined;
42
+ ~~~~~
43
+ !!! error TS1308: 'await' expression is only allowed within an async function.
44
+ }
45
+
Original file line number Diff line number Diff line change
1
+ //// [awaitLiteralValues.ts]
2
+ function awaitString ( ) {
3
+ await 'literal' ;
4
+ }
5
+
6
+ function awaitNumber ( ) {
7
+ await 1 ;
8
+ }
9
+
10
+ function awaitTrue ( ) {
11
+ await true ;
12
+ }
13
+
14
+ function awaitFalse ( ) {
15
+ await false ;
16
+ }
17
+
18
+ function awaitNull ( ) {
19
+ await null ;
20
+ }
21
+
22
+ function awaitUndefined ( ) {
23
+ await undefined ;
24
+ }
25
+
26
+
27
+ //// [awaitLiteralValues.js]
28
+ function awaitString ( ) {
29
+ yield 'literal' ;
30
+ }
31
+ function awaitNumber ( ) {
32
+ yield 1 ;
33
+ }
34
+ function awaitTrue ( ) {
35
+ yield true ;
36
+ }
37
+ function awaitFalse ( ) {
38
+ yield false ;
39
+ }
40
+ function awaitNull ( ) {
41
+ yield null ;
42
+ }
43
+ function awaitUndefined ( ) {
44
+ yield undefined ;
45
+ }
Original file line number Diff line number Diff line change
1
+ tests/cases/compiler/yieldStringLiteral.ts(2,5): error TS1163: A 'yield' expression is only allowed in a generator body.
2
+
3
+
4
+ ==== tests/cases/compiler/yieldStringLiteral.ts (1 errors) ====
5
+ function yieldString() {
6
+ yield 'literal';
7
+ ~~~~~
8
+ !!! error TS1163: A 'yield' expression is only allowed in a generator body.
9
+ }
10
+
Original file line number Diff line number Diff line change
1
+ //// [yieldStringLiteral.ts]
2
+ function yieldString ( ) {
3
+ yield 'literal' ;
4
+ }
5
+
6
+
7
+ //// [yieldStringLiteral.js]
8
+ function yieldString ( ) {
9
+ yield 'literal' ;
10
+ }
Original file line number Diff line number Diff line change
1
+ function awaitString ( ) {
2
+ await 'literal' ;
3
+ }
4
+
5
+ function awaitNumber ( ) {
6
+ await 1 ;
7
+ }
8
+
9
+ function awaitTrue ( ) {
10
+ await true ;
11
+ }
12
+
13
+ function awaitFalse ( ) {
14
+ await false ;
15
+ }
16
+
17
+ function awaitNull ( ) {
18
+ await null ;
19
+ }
20
+
21
+ function awaitUndefined ( ) {
22
+ await undefined ;
23
+ }
Original file line number Diff line number Diff line change
1
+ function yieldString ( ) {
2
+ yield 'literal' ;
3
+ }
You can’t perform that action at this time.
0 commit comments