Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7505,7 +7505,11 @@ namespace Parser {
case SyntaxKind.LetKeyword:
case SyntaxKind.ConstKeyword:
case SyntaxKind.UsingKeyword:
return parseVariableStatement(pos, hasJSDoc, modifiersIn);
case SyntaxKind.AwaitKeyword:
if (!isAwaitUsingDeclaration()) {
break;
}
return parseVariableStatement(pos, hasJSDoc, modifiersIn);
case SyntaxKind.FunctionKeyword:
return parseFunctionDeclaration(pos, hasJSDoc, modifiersIn);
Expand Down Expand Up @@ -7534,17 +7538,16 @@ namespace Parser {
default:
return parseExportDeclaration(pos, hasJSDoc, modifiersIn);
}
default:
if (modifiersIn) {
// We reached this point because we encountered decorators and/or modifiers and assumed a declaration
// would follow. For recovery and error reporting purposes, return an incomplete declaration.
const missing = createMissingNode<MissingDeclaration>(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected);
setTextRangePos(missing, pos);
(missing as Mutable<MissingDeclaration>).modifiers = modifiersIn;
return missing;
}
return undefined!; // TODO: GH#18217
}
if (modifiersIn) {
// We reached this point because we encountered decorators and/or modifiers and assumed a declaration
// would follow. For recovery and error reporting purposes, return an incomplete declaration.
const missing = createMissingNode<MissingDeclaration>(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected);
setTextRangePos(missing, pos);
(missing as Mutable<MissingDeclaration>).modifiers = modifiersIn;
return missing;
}
return undefined!; // TODO: GH#18217
}

function nextTokenIsStringLiteral() {
Expand Down Expand Up @@ -7677,7 +7680,9 @@ namespace Parser {
flags |= NodeFlags.Using;
break;
case SyntaxKind.AwaitKeyword:
Debug.assert(isAwaitUsingDeclaration());
if (!isAwaitUsingDeclaration()) {
break;
}
flags |= NodeFlags.AwaitUsing;
nextToken();
break;
Expand Down
11 changes: 11 additions & 0 deletions tests/baselines/reference/decoratorOnAwait.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
decoratorOnAwait.ts(3,5): error TS1146: Declaration expected.


==== decoratorOnAwait.ts (1 errors) ====
declare function dec<T>(target: T): T;

@dec

!!! error TS1146: Declaration expected.
await 1

11 changes: 11 additions & 0 deletions tests/baselines/reference/decoratorOnAwait.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//// [tests/cases/conformance/decorators/invalid/decoratorOnAwait.ts] ////

//// [decoratorOnAwait.ts]
declare function dec<T>(target: T): T;

@dec
await 1


//// [decoratorOnAwait.js]
await 1;
15 changes: 15 additions & 0 deletions tests/baselines/reference/decoratorOnAwait.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [tests/cases/conformance/decorators/invalid/decoratorOnAwait.ts] ////

=== decoratorOnAwait.ts ===
declare function dec<T>(target: T): T;
>dec : Symbol(dec, Decl(decoratorOnAwait.ts, 0, 0))
>T : Symbol(T, Decl(decoratorOnAwait.ts, 0, 21))
>target : Symbol(target, Decl(decoratorOnAwait.ts, 0, 24))
>T : Symbol(T, Decl(decoratorOnAwait.ts, 0, 21))
>T : Symbol(T, Decl(decoratorOnAwait.ts, 0, 21))

@dec
>dec : Symbol(dec, Decl(decoratorOnAwait.ts, 0, 0))

await 1

19 changes: 19 additions & 0 deletions tests/baselines/reference/decoratorOnAwait.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//// [tests/cases/conformance/decorators/invalid/decoratorOnAwait.ts] ////

=== decoratorOnAwait.ts ===
declare function dec<T>(target: T): T;
>dec : <T>(target: T) => T
> : ^ ^^ ^^ ^^^^^
>target : T
> : ^

@dec
>dec : <T>(target: T) => T
> : ^ ^^ ^^ ^^^^^

await 1
>await 1 : 1
> : ^
>1 : 1
> : ^

14 changes: 14 additions & 0 deletions tests/baselines/reference/decoratorOnUsing.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
decoratorOnUsing.ts(4,7): error TS1134: Variable declaration expected.


==== decoratorOnUsing.ts (1 errors) ====
declare function dec<T>(target: T): T;

@dec
using 1
~
!!! error TS1134: Variable declaration expected.

@dec
using x

16 changes: 16 additions & 0 deletions tests/baselines/reference/decoratorOnUsing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//// [tests/cases/conformance/decorators/invalid/decoratorOnUsing.ts] ////

//// [decoratorOnUsing.ts]
declare function dec<T>(target: T): T;

@dec
using 1

@dec
using x


//// [decoratorOnUsing.js]
using ;
1;
using x;
21 changes: 21 additions & 0 deletions tests/baselines/reference/decoratorOnUsing.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//// [tests/cases/conformance/decorators/invalid/decoratorOnUsing.ts] ////

=== decoratorOnUsing.ts ===
declare function dec<T>(target: T): T;
>dec : Symbol(dec, Decl(decoratorOnUsing.ts, 0, 0))
>T : Symbol(T, Decl(decoratorOnUsing.ts, 0, 21))
>target : Symbol(target, Decl(decoratorOnUsing.ts, 0, 24))
>T : Symbol(T, Decl(decoratorOnUsing.ts, 0, 21))
>T : Symbol(T, Decl(decoratorOnUsing.ts, 0, 21))

@dec
>dec : Symbol(dec, Decl(decoratorOnUsing.ts, 0, 0))

using 1

@dec
>dec : Symbol(dec, Decl(decoratorOnUsing.ts, 0, 0))

using x
>x : Symbol(x, Decl(decoratorOnUsing.ts, 6, 5))

25 changes: 25 additions & 0 deletions tests/baselines/reference/decoratorOnUsing.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//// [tests/cases/conformance/decorators/invalid/decoratorOnUsing.ts] ////

=== decoratorOnUsing.ts ===
declare function dec<T>(target: T): T;
>dec : <T>(target: T) => T
> : ^ ^^ ^^ ^^^^^
>target : T
> : ^

@dec
>dec : <T>(target: T) => T
> : ^ ^^ ^^ ^^^^^

using 1
>1 : 1
> : ^

@dec
>dec : <T>(target: T) => T
> : ^ ^^ ^^ ^^^^^

using x
>x : any
> : ^^^

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare function dec<T>(target: T): T;

@dec
await 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @target: esnext
declare function dec<T>(target: T): T;

@dec
using 1

@dec
using x