Skip to content

Commit e2e3c12

Browse files
authored
fix(49544): allow comma token after accessors (#49545)
1 parent 0bc2b65 commit e2e3c12

File tree

5 files changed

+111
-12
lines changed

5 files changed

+111
-12
lines changed

src/compiler/parser.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,11 +3631,11 @@ namespace ts {
36313631
const hasJSDoc = hasPrecedingJSDocComment();
36323632
const modifiers = parseModifiers();
36333633
if (parseContextualModifier(SyntaxKind.GetKeyword)) {
3634-
return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, SyntaxKind.GetAccessor);
3634+
return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, SyntaxKind.GetAccessor, SignatureFlags.Type);
36353635
}
36363636

36373637
if (parseContextualModifier(SyntaxKind.SetKeyword)) {
3638-
return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, SyntaxKind.SetAccessor);
3638+
return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, SyntaxKind.SetAccessor, SignatureFlags.Type);
36393639
}
36403640

36413641
if (isIndexSignature()) {
@@ -5928,10 +5928,10 @@ namespace ts {
59285928
const modifiers = parseModifiers();
59295929

59305930
if (parseContextualModifier(SyntaxKind.GetKeyword)) {
5931-
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.GetAccessor);
5931+
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.GetAccessor, SignatureFlags.None);
59325932
}
59335933
if (parseContextualModifier(SyntaxKind.SetKeyword)) {
5934-
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.SetAccessor);
5934+
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.SetAccessor, SignatureFlags.None);
59355935
}
59365936

59375937
const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
@@ -6701,11 +6701,16 @@ namespace ts {
67016701
}
67026702

67036703
function parseFunctionBlockOrSemicolon(flags: SignatureFlags, diagnosticMessage?: DiagnosticMessage): Block | undefined {
6704-
if (token() !== SyntaxKind.OpenBraceToken && canParseSemicolon()) {
6705-
parseSemicolon();
6706-
return;
6704+
if (token() !== SyntaxKind.OpenBraceToken) {
6705+
if (flags & SignatureFlags.Type) {
6706+
parseTypeMemberSemicolon();
6707+
return;
6708+
}
6709+
if (canParseSemicolon()) {
6710+
parseSemicolon();
6711+
return;
6712+
}
67076713
}
6708-
67096714
return parseFunctionBlock(flags, diagnosticMessage);
67106715
}
67116716

@@ -6972,12 +6977,12 @@ namespace ts {
69726977
return parsePropertyDeclaration(pos, hasJSDoc, decorators, modifiers, name, questionToken);
69736978
}
69746979

6975-
function parseAccessorDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray<Decorator> | undefined, modifiers: NodeArray<Modifier> | undefined, kind: AccessorDeclaration["kind"]): AccessorDeclaration {
6980+
function parseAccessorDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray<Decorator> | undefined, modifiers: NodeArray<Modifier> | undefined, kind: AccessorDeclaration["kind"], flags: SignatureFlags): AccessorDeclaration {
69766981
const name = parsePropertyName();
69776982
const typeParameters = parseTypeParameters();
69786983
const parameters = parseParameters(SignatureFlags.None);
69796984
const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false);
6980-
const body = parseFunctionBlockOrSemicolon(SignatureFlags.None);
6985+
const body = parseFunctionBlockOrSemicolon(flags);
69816986
const node = kind === SyntaxKind.GetAccessor
69826987
? factory.createGetAccessorDeclaration(combineDecoratorsAndModifiers(decorators, modifiers), name, parameters, type, body)
69836988
: factory.createSetAccessorDeclaration(combineDecoratorsAndModifiers(decorators, modifiers), name, parameters, body);
@@ -7188,11 +7193,11 @@ namespace ts {
71887193
}
71897194

71907195
if (parseContextualModifier(SyntaxKind.GetKeyword)) {
7191-
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.GetAccessor);
7196+
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.GetAccessor, SignatureFlags.None);
71927197
}
71937198

71947199
if (parseContextualModifier(SyntaxKind.SetKeyword)) {
7195-
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.SetAccessor);
7200+
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.SetAccessor, SignatureFlags.None);
71967201
}
71977202

71987203
if (token() === SyntaxKind.ConstructorKeyword || token() === SyntaxKind.StringLiteral) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//// [parserInterfaceDeclaration9.ts]
2+
interface I1 {
3+
get foo(): number,
4+
set foo(value: number),
5+
}
6+
7+
interface I2 {
8+
get foo(): number;
9+
set foo(value: number);
10+
}
11+
12+
interface I3 {
13+
get foo(): number
14+
set foo(value: number)
15+
}
16+
17+
18+
//// [parserInterfaceDeclaration9.js]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
=== tests/cases/conformance/parser/ecmascript5/InterfaceDeclarations/parserInterfaceDeclaration9.ts ===
2+
interface I1 {
3+
>I1 : Symbol(I1, Decl(parserInterfaceDeclaration9.ts, 0, 0))
4+
5+
get foo(): number,
6+
>foo : Symbol(I1.foo, Decl(parserInterfaceDeclaration9.ts, 0, 14), Decl(parserInterfaceDeclaration9.ts, 1, 22))
7+
8+
set foo(value: number),
9+
>foo : Symbol(I1.foo, Decl(parserInterfaceDeclaration9.ts, 0, 14), Decl(parserInterfaceDeclaration9.ts, 1, 22))
10+
>value : Symbol(value, Decl(parserInterfaceDeclaration9.ts, 2, 12))
11+
}
12+
13+
interface I2 {
14+
>I2 : Symbol(I2, Decl(parserInterfaceDeclaration9.ts, 3, 1))
15+
16+
get foo(): number;
17+
>foo : Symbol(I2.foo, Decl(parserInterfaceDeclaration9.ts, 5, 14), Decl(parserInterfaceDeclaration9.ts, 6, 22))
18+
19+
set foo(value: number);
20+
>foo : Symbol(I2.foo, Decl(parserInterfaceDeclaration9.ts, 5, 14), Decl(parserInterfaceDeclaration9.ts, 6, 22))
21+
>value : Symbol(value, Decl(parserInterfaceDeclaration9.ts, 7, 12))
22+
}
23+
24+
interface I3 {
25+
>I3 : Symbol(I3, Decl(parserInterfaceDeclaration9.ts, 8, 1))
26+
27+
get foo(): number
28+
>foo : Symbol(I3.foo, Decl(parserInterfaceDeclaration9.ts, 10, 14), Decl(parserInterfaceDeclaration9.ts, 11, 21))
29+
30+
set foo(value: number)
31+
>foo : Symbol(I3.foo, Decl(parserInterfaceDeclaration9.ts, 10, 14), Decl(parserInterfaceDeclaration9.ts, 11, 21))
32+
>value : Symbol(value, Decl(parserInterfaceDeclaration9.ts, 12, 12))
33+
}
34+
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
=== tests/cases/conformance/parser/ecmascript5/InterfaceDeclarations/parserInterfaceDeclaration9.ts ===
2+
interface I1 {
3+
get foo(): number,
4+
>foo : number
5+
6+
set foo(value: number),
7+
>foo : number
8+
>value : number
9+
}
10+
11+
interface I2 {
12+
get foo(): number;
13+
>foo : number
14+
15+
set foo(value: number);
16+
>foo : number
17+
>value : number
18+
}
19+
20+
interface I3 {
21+
get foo(): number
22+
>foo : number
23+
24+
set foo(value: number)
25+
>foo : number
26+
>value : number
27+
}
28+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
interface I1 {
2+
get foo(): number,
3+
set foo(value: number),
4+
}
5+
6+
interface I2 {
7+
get foo(): number;
8+
set foo(value: number);
9+
}
10+
11+
interface I3 {
12+
get foo(): number
13+
set foo(value: number)
14+
}

0 commit comments

Comments
 (0)