Skip to content

Commit

Permalink
disallow mixins/implements in flow interface (#15479)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Mar 9, 2023
1 parent d251d86 commit 6e3dffe
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 17 deletions.
31 changes: 14 additions & 17 deletions packages/babel-parser/src/plugins/flow/index.ts
Expand Up @@ -692,16 +692,13 @@ export default (superClass: typeof Parser) =>
node: Undone<N.FlowDeclareInterface>,
): N.FlowDeclareInterface {
this.next();
this.flowParseInterfaceish(node);
this.flowParseInterfaceish(node, /* isClass */ false);
return this.finishNode(node, "DeclareInterface");
}

// Interfaces

flowParseInterfaceish(
node: Undone<N.FlowDeclare>,
isClass: boolean = false,
): void {
flowParseInterfaceish(node: Undone<N.FlowDeclare>, isClass: boolean): void {
node.id = this.flowParseRestrictedIdentifier(
/* liberal */ !isClass,
/* declaration */ true,
Expand Down Expand Up @@ -729,18 +726,18 @@ export default (superClass: typeof Parser) =>
} while (!isClass && this.eat(tt.comma));
}

if (this.isContextual(tt._mixins)) {
this.next();
do {
node.mixins.push(this.flowParseInterfaceExtends());
} while (this.eat(tt.comma));
}
if (isClass) {
if (this.eatContextual(tt._mixins)) {
do {
node.mixins.push(this.flowParseInterfaceExtends());
} while (this.eat(tt.comma));
}

if (this.isContextual(tt._implements)) {
this.next();
do {
node.implements.push(this.flowParseInterfaceExtends());
} while (this.eat(tt.comma));
if (this.eatContextual(tt._implements)) {
do {
node.implements.push(this.flowParseInterfaceExtends());
} while (this.eat(tt.comma));
}
}

node.body = this.flowParseObjectType({
Expand All @@ -766,7 +763,7 @@ export default (superClass: typeof Parser) =>
}

flowParseInterface(node: Undone<N.FlowInterface>): N.FlowInterface {
this.flowParseInterfaceish(node);
this.flowParseInterfaceish(node, /* isClass */ false);
return this.finishNode(node, "InterfaceDeclaration");
}

Expand Down
@@ -0,0 +1 @@
declare interface A implements I { p: string }
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \"{\" (1:20)"
}
@@ -0,0 +1 @@
declare interface A mixins M { p: string }
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \"{\" (1:20)"
}
@@ -0,0 +1 @@
interface A implements I { p: string }
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \"{\" (1:12)"
}
@@ -0,0 +1 @@
interface A mixins M { p: string }
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \"{\" (1:12)"
}

0 comments on commit 6e3dffe

Please sign in to comment.