mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
fix(49544): allow comma token after accessors (#49545)
This commit is contained in:
+17
-12
@@ -3631,11 +3631,11 @@ namespace ts {
|
||||
const hasJSDoc = hasPrecedingJSDocComment();
|
||||
const modifiers = parseModifiers();
|
||||
if (parseContextualModifier(SyntaxKind.GetKeyword)) {
|
||||
return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, SyntaxKind.GetAccessor);
|
||||
return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, SyntaxKind.GetAccessor, SignatureFlags.Type);
|
||||
}
|
||||
|
||||
if (parseContextualModifier(SyntaxKind.SetKeyword)) {
|
||||
return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, SyntaxKind.SetAccessor);
|
||||
return parseAccessorDeclaration(pos, hasJSDoc, /*decorators*/ undefined, modifiers, SyntaxKind.SetAccessor, SignatureFlags.Type);
|
||||
}
|
||||
|
||||
if (isIndexSignature()) {
|
||||
@@ -5928,10 +5928,10 @@ namespace ts {
|
||||
const modifiers = parseModifiers();
|
||||
|
||||
if (parseContextualModifier(SyntaxKind.GetKeyword)) {
|
||||
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.GetAccessor);
|
||||
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.GetAccessor, SignatureFlags.None);
|
||||
}
|
||||
if (parseContextualModifier(SyntaxKind.SetKeyword)) {
|
||||
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.SetAccessor);
|
||||
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.SetAccessor, SignatureFlags.None);
|
||||
}
|
||||
|
||||
const asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
|
||||
@@ -6701,11 +6701,16 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseFunctionBlockOrSemicolon(flags: SignatureFlags, diagnosticMessage?: DiagnosticMessage): Block | undefined {
|
||||
if (token() !== SyntaxKind.OpenBraceToken && canParseSemicolon()) {
|
||||
parseSemicolon();
|
||||
return;
|
||||
if (token() !== SyntaxKind.OpenBraceToken) {
|
||||
if (flags & SignatureFlags.Type) {
|
||||
parseTypeMemberSemicolon();
|
||||
return;
|
||||
}
|
||||
if (canParseSemicolon()) {
|
||||
parseSemicolon();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return parseFunctionBlock(flags, diagnosticMessage);
|
||||
}
|
||||
|
||||
@@ -6972,12 +6977,12 @@ namespace ts {
|
||||
return parsePropertyDeclaration(pos, hasJSDoc, decorators, modifiers, name, questionToken);
|
||||
}
|
||||
|
||||
function parseAccessorDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray<Decorator> | undefined, modifiers: NodeArray<Modifier> | undefined, kind: AccessorDeclaration["kind"]): AccessorDeclaration {
|
||||
function parseAccessorDeclaration(pos: number, hasJSDoc: boolean, decorators: NodeArray<Decorator> | undefined, modifiers: NodeArray<Modifier> | undefined, kind: AccessorDeclaration["kind"], flags: SignatureFlags): AccessorDeclaration {
|
||||
const name = parsePropertyName();
|
||||
const typeParameters = parseTypeParameters();
|
||||
const parameters = parseParameters(SignatureFlags.None);
|
||||
const type = parseReturnType(SyntaxKind.ColonToken, /*isType*/ false);
|
||||
const body = parseFunctionBlockOrSemicolon(SignatureFlags.None);
|
||||
const body = parseFunctionBlockOrSemicolon(flags);
|
||||
const node = kind === SyntaxKind.GetAccessor
|
||||
? factory.createGetAccessorDeclaration(combineDecoratorsAndModifiers(decorators, modifiers), name, parameters, type, body)
|
||||
: factory.createSetAccessorDeclaration(combineDecoratorsAndModifiers(decorators, modifiers), name, parameters, body);
|
||||
@@ -7188,11 +7193,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (parseContextualModifier(SyntaxKind.GetKeyword)) {
|
||||
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.GetAccessor);
|
||||
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.GetAccessor, SignatureFlags.None);
|
||||
}
|
||||
|
||||
if (parseContextualModifier(SyntaxKind.SetKeyword)) {
|
||||
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.SetAccessor);
|
||||
return parseAccessorDeclaration(pos, hasJSDoc, decorators, modifiers, SyntaxKind.SetAccessor, SignatureFlags.None);
|
||||
}
|
||||
|
||||
if (token() === SyntaxKind.ConstructorKeyword || token() === SyntaxKind.StringLiteral) {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
//// [parserInterfaceDeclaration9.ts]
|
||||
interface I1 {
|
||||
get foo(): number,
|
||||
set foo(value: number),
|
||||
}
|
||||
|
||||
interface I2 {
|
||||
get foo(): number;
|
||||
set foo(value: number);
|
||||
}
|
||||
|
||||
interface I3 {
|
||||
get foo(): number
|
||||
set foo(value: number)
|
||||
}
|
||||
|
||||
|
||||
//// [parserInterfaceDeclaration9.js]
|
||||
@@ -0,0 +1,34 @@
|
||||
=== tests/cases/conformance/parser/ecmascript5/InterfaceDeclarations/parserInterfaceDeclaration9.ts ===
|
||||
interface I1 {
|
||||
>I1 : Symbol(I1, Decl(parserInterfaceDeclaration9.ts, 0, 0))
|
||||
|
||||
get foo(): number,
|
||||
>foo : Symbol(I1.foo, Decl(parserInterfaceDeclaration9.ts, 0, 14), Decl(parserInterfaceDeclaration9.ts, 1, 22))
|
||||
|
||||
set foo(value: number),
|
||||
>foo : Symbol(I1.foo, Decl(parserInterfaceDeclaration9.ts, 0, 14), Decl(parserInterfaceDeclaration9.ts, 1, 22))
|
||||
>value : Symbol(value, Decl(parserInterfaceDeclaration9.ts, 2, 12))
|
||||
}
|
||||
|
||||
interface I2 {
|
||||
>I2 : Symbol(I2, Decl(parserInterfaceDeclaration9.ts, 3, 1))
|
||||
|
||||
get foo(): number;
|
||||
>foo : Symbol(I2.foo, Decl(parserInterfaceDeclaration9.ts, 5, 14), Decl(parserInterfaceDeclaration9.ts, 6, 22))
|
||||
|
||||
set foo(value: number);
|
||||
>foo : Symbol(I2.foo, Decl(parserInterfaceDeclaration9.ts, 5, 14), Decl(parserInterfaceDeclaration9.ts, 6, 22))
|
||||
>value : Symbol(value, Decl(parserInterfaceDeclaration9.ts, 7, 12))
|
||||
}
|
||||
|
||||
interface I3 {
|
||||
>I3 : Symbol(I3, Decl(parserInterfaceDeclaration9.ts, 8, 1))
|
||||
|
||||
get foo(): number
|
||||
>foo : Symbol(I3.foo, Decl(parserInterfaceDeclaration9.ts, 10, 14), Decl(parserInterfaceDeclaration9.ts, 11, 21))
|
||||
|
||||
set foo(value: number)
|
||||
>foo : Symbol(I3.foo, Decl(parserInterfaceDeclaration9.ts, 10, 14), Decl(parserInterfaceDeclaration9.ts, 11, 21))
|
||||
>value : Symbol(value, Decl(parserInterfaceDeclaration9.ts, 12, 12))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
=== tests/cases/conformance/parser/ecmascript5/InterfaceDeclarations/parserInterfaceDeclaration9.ts ===
|
||||
interface I1 {
|
||||
get foo(): number,
|
||||
>foo : number
|
||||
|
||||
set foo(value: number),
|
||||
>foo : number
|
||||
>value : number
|
||||
}
|
||||
|
||||
interface I2 {
|
||||
get foo(): number;
|
||||
>foo : number
|
||||
|
||||
set foo(value: number);
|
||||
>foo : number
|
||||
>value : number
|
||||
}
|
||||
|
||||
interface I3 {
|
||||
get foo(): number
|
||||
>foo : number
|
||||
|
||||
set foo(value: number)
|
||||
>foo : number
|
||||
>value : number
|
||||
}
|
||||
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
interface I1 {
|
||||
get foo(): number,
|
||||
set foo(value: number),
|
||||
}
|
||||
|
||||
interface I2 {
|
||||
get foo(): number;
|
||||
set foo(value: number);
|
||||
}
|
||||
|
||||
interface I3 {
|
||||
get foo(): number
|
||||
set foo(value: number)
|
||||
}
|
||||
Reference in New Issue
Block a user