Skip to content
Open
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
5 changes: 4 additions & 1 deletion internal/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,10 @@ func (p *Parser) parseClassDeclarationOrExpression(pos int, jsdoc jsdocScannerIn
// We don't parse the name here in await context, instead we will report a grammar error in the checker.
name := p.parseNameOfClassDeclarationOrExpression()
typeParameters := p.parseTypeParameters()
if modifiers != nil && core.Some(modifiers.Nodes, isExportModifier) {
if modifiers != nil &&
p.parsingContexts&(1<<PCSourceElements) != 0 &&
p.parsingContexts&((1<<PCBlockStatements)|(1<<PCSwitchClauseStatements)) == 0 &&
core.Some(modifiers.Nodes, isExportModifier) {
p.setContextFlags(ast.NodeFlagsAwaitContext, true /*value*/)
}
heritageClauses := p.parseHeritageClauses()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
awaitInNamespaceExportedClassComputedProperty.ts(3,16): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
awaitInNamespaceExportedClassComputedProperty.ts(5,10): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
awaitInNamespaceExportedClassComputedProperty.ts(6,17): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
awaitInNamespaceExportedClassComputedProperty.ts(20,10): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
awaitInNamespaceExportedClassComputedProperty.ts(21,17): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
awaitInNamespaceExportedClassComputedProperty.ts(33,16): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
awaitInNamespaceExportedClassComputedProperty.ts(43,24): error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.


==== awaitInNamespaceExportedClassComputedProperty.ts (7 errors) ====
declare const x: string;
namespace N {
class A { [await x]() {} }
~~~~~
!!! error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
!!! related TS1356 awaitInNamespaceExportedClassComputedProperty.ts:3:15: Did you mean to mark this function as 'async'?
export class B {
[await x]() {}
~~~~~
!!! error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
!!! related TS1356 awaitInNamespaceExportedClassComputedProperty.ts:5:9: Did you mean to mark this function as 'async'?
static [await x]() {}
~~~~~
!!! error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
!!! related TS1356 awaitInNamespaceExportedClassComputedProperty.ts:6:16: Did you mean to mark this function as 'async'?
}
}
export class C {
[await x]() {}
static [await x]() {}
}

{
class D { [await x]() {} }
}

function f() {
class E {
[await x]() {}
~~~~~
!!! error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
!!! related TS1356 awaitInNamespaceExportedClassComputedProperty.ts:20:9: Did you mean to mark this function as 'async'?
static [await x]() {}
~~~~~
!!! error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
!!! related TS1356 awaitInNamespaceExportedClassComputedProperty.ts:21:16: Did you mean to mark this function as 'async'?
}
}

async function af() {
class F {
[await x]() {}
static [await x]() {}
}
}

function* gf() {
class G { [await x]() {} }
~~~~~
!!! error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
!!! related TS1356 awaitInNamespaceExportedClassComputedProperty.ts:33:15: Did you mean to mark this function as 'async'?
}

async function* agf() {
class H { [await x]() {} }
}

function switchSync() {
switch (0) {
case 0:
class I { [await x]() {} }
~~~~~
!!! error TS1308: 'await' expressions are only allowed within async functions and at the top levels of modules.
!!! related TS1356 awaitInNamespaceExportedClassComputedProperty.ts:43:23: Did you mean to mark this function as 'async'?
}
}

async function switchAsync() {
switch (0) {
case 0:
class J { [await x]() {} }
}
}

export {};

Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
//// [tests/cases/compiler/awaitInNamespaceExportedClassComputedProperty.ts] ////

//// [awaitInNamespaceExportedClassComputedProperty.ts]
declare const x: string;
namespace N {
class A { [await x]() {} }
export class B {
[await x]() {}
static [await x]() {}
}
}
export class C {
[await x]() {}
static [await x]() {}
}

{
class D { [await x]() {} }
}

function f() {
class E {
[await x]() {}
static [await x]() {}
}
}

async function af() {
class F {
[await x]() {}
static [await x]() {}
}
}

function* gf() {
class G { [await x]() {} }
}

async function* agf() {
class H { [await x]() {} }
}

function switchSync() {
switch (0) {
case 0:
class I { [await x]() {} }
}
}

async function switchAsync() {
switch (0) {
case 0:
class J { [await x]() {} }
}
}

export {};


//// [awaitInNamespaceExportedClassComputedProperty.js]
var N;
(function (N) {
class A {
[await x]() { }
}
class B {
[await x]() { }
static [await x]() { }
}
N.B = B;
})(N || (N = {}));
export class C {
[await x]() { }
static [await x]() { }
}
{
class D {
[await x]() { }
}
}
function f() {
class E {
[await x]() { }
static [await x]() { }
}
}
async function af() {
class F {
[await x]() { }
static [await x]() { }
}
}
function* gf() {
class G {
[await x]() { }
}
}
async function* agf() {
class H {
[await x]() { }
}
}
function switchSync() {
switch (0) {
case 0:
class I {
[await x]() { }
}
}
}
async function switchAsync() {
switch (0) {
case 0:
class J {
[await x]() { }
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//// [tests/cases/compiler/awaitInNamespaceExportedClassComputedProperty.ts] ////

=== awaitInNamespaceExportedClassComputedProperty.ts ===
declare const x: string;
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))

namespace N {
>N : Symbol(N, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 24))

class A { [await x]() {} }
>A : Symbol(A, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 1, 13))
>[await x] : Symbol(A[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 2, 13))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))

export class B {
>B : Symbol(B, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 2, 30))

[await x]() {}
>[await x] : Symbol(B[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 3, 20))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))

static [await x]() {}
>[await x] : Symbol(B[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 4, 22))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))
}
}
export class C {
>C : Symbol(C, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 7, 1))

[await x]() {}
>[await x] : Symbol(C[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 8, 16))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))

static [await x]() {}
>[await x] : Symbol(C[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 9, 18))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))
}

{
class D { [await x]() {} }
>D : Symbol(D, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 13, 1))
>[await x] : Symbol(D[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 14, 13))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))
}

function f() {
>f : Symbol(f, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 15, 1))

class E {
>E : Symbol(E, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 17, 14))

[await x]() {}
>[await x] : Symbol(E[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 18, 13))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))

static [await x]() {}
>[await x] : Symbol(E[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 19, 22))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))
}
}

async function af() {
>af : Symbol(af, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 22, 1))

class F {
>F : Symbol(F, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 24, 21))

[await x]() {}
>[await x] : Symbol(F[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 25, 13))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))

static [await x]() {}
>[await x] : Symbol(F[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 26, 22))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))
}
}

function* gf() {
>gf : Symbol(gf, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 29, 1))

class G { [await x]() {} }
>G : Symbol(G, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 31, 16))
>[await x] : Symbol(G[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 32, 13))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))
}

async function* agf() {
>agf : Symbol(agf, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 33, 1))

class H { [await x]() {} }
>H : Symbol(H, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 35, 23))
>[await x] : Symbol(H[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 36, 13))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))
}

function switchSync() {
>switchSync : Symbol(switchSync, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 37, 1))

switch (0) {
case 0:
class I { [await x]() {} }
>I : Symbol(I, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 41, 15))
>[await x] : Symbol(I[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 42, 21))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))
}
}

async function switchAsync() {
>switchAsync : Symbol(switchAsync, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 44, 1))

switch (0) {
case 0:
class J { [await x]() {} }
>J : Symbol(J, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 48, 15))
>[await x] : Symbol(J[await x], Decl(awaitInNamespaceExportedClassComputedProperty.ts, 49, 21))
>x : Symbol(x, Decl(awaitInNamespaceExportedClassComputedProperty.ts, 0, 13))
}
}

export {};

Loading