Skip to content

Commit

Permalink
fix: Support separating interface members with commas (#1375)
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGraey authored Jul 4, 2020
1 parent ed1cd09 commit 68db679
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2169,7 +2169,7 @@ export class Parser extends DiagnosticEmitter {
tn.range()
);
}
returnType = this.parseType(tn, name.kind == NodeKind.CONSTRUCTOR || isSetter);
returnType = this.parseType(tn, isSetter || name.kind == NodeKind.CONSTRUCTOR);
if (!returnType) return null;
} else {
returnType = Node.createOmittedType(tn.range(tn.pos));
Expand Down Expand Up @@ -2209,7 +2209,7 @@ export class Parser extends DiagnosticEmitter {
}
body = this.parseBlockStatement(tn, false);
if (!body) return null;
} else if (!(flags & (CommonFlags.AMBIENT | CommonFlags.ABSTRACT)) && !isInterface) {
} else if (!isInterface && !(flags & (CommonFlags.AMBIENT | CommonFlags.ABSTRACT))) {
this.error(
DiagnosticCode.Function_implementation_is_missing_or_not_immediately_following_the_declaration,
tn.range()
Expand All @@ -2225,7 +2225,9 @@ export class Parser extends DiagnosticEmitter {
body,
tn.range(startPos, tn.pos)
);
tn.skip(Token.SEMICOLON);
if (!(isInterface && tn.skip(Token.COMMA))) {
tn.skip(Token.SEMICOLON);
}
return retMethod;

} else if (isConstructor) {
Expand Down Expand Up @@ -2288,7 +2290,10 @@ export class Parser extends DiagnosticEmitter {
if (!initializer) return null;
}
let range = tn.range(startPos, tn.pos);
if ((flags & CommonFlags.DEFINITELY_ASSIGNED) != 0 && ((flags & CommonFlags.STATIC) != 0 || isInterface || initializer !== null)) {
if (
(flags & CommonFlags.DEFINITELY_ASSIGNED) != 0 &&
(isInterface || initializer !== null || (flags & CommonFlags.STATIC) != 0)
) {
this.error(
DiagnosticCode.A_definite_assignment_assertion_is_not_permitted_in_this_context,
range
Expand All @@ -2302,7 +2307,9 @@ export class Parser extends DiagnosticEmitter {
initializer,
range
);
tn.skip(Token.SEMICOLON);
if (!(isInterface && tn.skip(Token.COMMA))) {
tn.skip(Token.SEMICOLON);
}
return retField;
}
return null;
Expand Down
6 changes: 6 additions & 0 deletions tests/parser/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@ interface Foo {
baz: i32;
readonly baz2: f64;
}

interface Boo {
bar(): void,
baz: i32,
readonly baz2: f64,
}
5 changes: 5 additions & 0 deletions tests/parser/interface.ts.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ interface Foo {
baz: i32;
readonly baz2: f64;
}
interface Boo {
bar(): void;
baz: i32;
readonly baz2: f64;
}

0 comments on commit 68db679

Please sign in to comment.