diff --git a/internal/parser/parser.go b/internal/parser/parser.go index 47c17b74476..963df72e01f 100644 --- a/internal/parser/parser.go +++ b/internal/parser/parser.go @@ -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<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 {}; + diff --git a/testdata/baselines/reference/compiler/awaitInNamespaceExportedClassComputedProperty.types b/testdata/baselines/reference/compiler/awaitInNamespaceExportedClassComputedProperty.types new file mode 100644 index 00000000000..b9ff07222f6 --- /dev/null +++ b/testdata/baselines/reference/compiler/awaitInNamespaceExportedClassComputedProperty.types @@ -0,0 +1,143 @@ +//// [tests/cases/compiler/awaitInNamespaceExportedClassComputedProperty.ts] //// + +=== awaitInNamespaceExportedClassComputedProperty.ts === +declare const x: string; +>x : string + +namespace N { +>N : typeof N + + class A { [await x]() {} } +>A : A +>[await x] : () => void +>await x : string +>x : string + + export class B { +>B : B + + [await x]() {} +>[await x] : () => void +>await x : string +>x : string + + static [await x]() {} +>[await x] : () => void +>await x : string +>x : string + } +} +export class C { +>C : C + + [await x]() {} +>[await x] : () => void +>await x : string +>x : string + + static [await x]() {} +>[await x] : () => void +>await x : string +>x : string +} + +{ + class D { [await x]() {} } +>D : D +>[await x] : () => void +>await x : string +>x : string +} + +function f() { +>f : () => void + + class E { +>E : E + + [await x]() {} +>[await x] : () => void +>await x : string +>x : string + + static [await x]() {} +>[await x] : () => void +>await x : string +>x : string + } +} + +async function af() { +>af : () => Promise + + class F { +>F : F + + [await x]() {} +>[await x] : () => void +>await x : string +>x : string + + static [await x]() {} +>[await x] : () => void +>await x : string +>x : string + } +} + +function* gf() { +>gf : () => Generator + + class G { [await x]() {} } +>G : G +>[await x] : () => void +>await x : string +>x : string +} + +async function* agf() { +>agf : () => AsyncGenerator + + class H { [await x]() {} } +>H : H +>[await x] : () => void +>await x : string +>x : string +} + +function switchSync() { +>switchSync : () => void + + switch (0) { +>0 : 0 + + case 0: +>0 : 0 + + class I { [await x]() {} } +>I : I +>[await x] : () => void +>await x : string +>x : string + } +} + +async function switchAsync() { +>switchAsync : () => Promise + + switch (0) { +>0 : 0 + + case 0: +>0 : 0 + + class J { [await x]() {} } +>J : J +>[await x] : () => void +>await x : string +>x : string + } +} + +export {}; + diff --git a/testdata/tests/cases/compiler/awaitInNamespaceExportedClassComputedProperty.ts b/testdata/tests/cases/compiler/awaitInNamespaceExportedClassComputedProperty.ts new file mode 100644 index 00000000000..7dae8cf3838 --- /dev/null +++ b/testdata/tests/cases/compiler/awaitInNamespaceExportedClassComputedProperty.ts @@ -0,0 +1,57 @@ +// @target: esnext +// @module: esnext + +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 {};