Skip to content

Commit 68db679

Browse files
authored
fix: Support separating interface members with commas (#1375)
1 parent ed1cd09 commit 68db679

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

Diff for: src/parser.ts

+12-5
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ export class Parser extends DiagnosticEmitter {
21692169
tn.range()
21702170
);
21712171
}
2172-
returnType = this.parseType(tn, name.kind == NodeKind.CONSTRUCTOR || isSetter);
2172+
returnType = this.parseType(tn, isSetter || name.kind == NodeKind.CONSTRUCTOR);
21732173
if (!returnType) return null;
21742174
} else {
21752175
returnType = Node.createOmittedType(tn.range(tn.pos));
@@ -2209,7 +2209,7 @@ export class Parser extends DiagnosticEmitter {
22092209
}
22102210
body = this.parseBlockStatement(tn, false);
22112211
if (!body) return null;
2212-
} else if (!(flags & (CommonFlags.AMBIENT | CommonFlags.ABSTRACT)) && !isInterface) {
2212+
} else if (!isInterface && !(flags & (CommonFlags.AMBIENT | CommonFlags.ABSTRACT))) {
22132213
this.error(
22142214
DiagnosticCode.Function_implementation_is_missing_or_not_immediately_following_the_declaration,
22152215
tn.range()
@@ -2225,7 +2225,9 @@ export class Parser extends DiagnosticEmitter {
22252225
body,
22262226
tn.range(startPos, tn.pos)
22272227
);
2228-
tn.skip(Token.SEMICOLON);
2228+
if (!(isInterface && tn.skip(Token.COMMA))) {
2229+
tn.skip(Token.SEMICOLON);
2230+
}
22292231
return retMethod;
22302232

22312233
} else if (isConstructor) {
@@ -2288,7 +2290,10 @@ export class Parser extends DiagnosticEmitter {
22882290
if (!initializer) return null;
22892291
}
22902292
let range = tn.range(startPos, tn.pos);
2291-
if ((flags & CommonFlags.DEFINITELY_ASSIGNED) != 0 && ((flags & CommonFlags.STATIC) != 0 || isInterface || initializer !== null)) {
2293+
if (
2294+
(flags & CommonFlags.DEFINITELY_ASSIGNED) != 0 &&
2295+
(isInterface || initializer !== null || (flags & CommonFlags.STATIC) != 0)
2296+
) {
22922297
this.error(
22932298
DiagnosticCode.A_definite_assignment_assertion_is_not_permitted_in_this_context,
22942299
range
@@ -2302,7 +2307,9 @@ export class Parser extends DiagnosticEmitter {
23022307
initializer,
23032308
range
23042309
);
2305-
tn.skip(Token.SEMICOLON);
2310+
if (!(isInterface && tn.skip(Token.COMMA))) {
2311+
tn.skip(Token.SEMICOLON);
2312+
}
23062313
return retField;
23072314
}
23082315
return null;

Diff for: tests/parser/interface.ts

+6
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ interface Foo {
33
baz: i32;
44
readonly baz2: f64;
55
}
6+
7+
interface Boo {
8+
bar(): void,
9+
baz: i32,
10+
readonly baz2: f64,
11+
}

Diff for: tests/parser/interface.ts.fixture.ts

+5
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ interface Foo {
33
baz: i32;
44
readonly baz2: f64;
55
}
6+
interface Boo {
7+
bar(): void;
8+
baz: i32;
9+
readonly baz2: f64;
10+
}

0 commit comments

Comments
 (0)