Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove mixins and implements for DeclareInterface and InterfaceDeclaration #15539

Merged
merged 2 commits into from Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 26 additions & 21 deletions packages/babel-generator/src/generators/flow.ts
Expand Up @@ -299,7 +299,7 @@ export function ExistsTypeAnnotation(this: Printer) {
export function FunctionTypeAnnotation(
this: Printer,
node: t.FunctionTypeAnnotation,
parent: t.Node | void,
parent?: t.Node,
) {
this.print(node.typeParameters, node);
this.token("(");
Expand Down Expand Up @@ -329,12 +329,14 @@ export function FunctionTypeAnnotation(
this.token(")");

// this node type is overloaded, not sure why but it makes it EXTREMELY annoying

const type = parent?.type;
if (
parent &&
(parent.type === "ObjectTypeCallProperty" ||
parent.type === "ObjectTypeInternalSlot" ||
parent.type === "DeclareFunction" ||
(parent.type === "ObjectTypeProperty" && parent.method))
type != null &&
(type === "ObjectTypeCallProperty" ||
type === "ObjectTypeInternalSlot" ||
type === "DeclareFunction" ||
(type === "ObjectTypeProperty" && parent.method))
) {
this.token(":");
} else {
Expand Down Expand Up @@ -378,17 +380,19 @@ export function _interfaceish(
this.space();
this.printList(node.extends, node);
}
if (node.mixins && node.mixins.length) {
this.space();
this.word("mixins");
this.space();
this.printList(node.mixins, node);
}
if (node.implements && node.implements.length) {
this.space();
this.word("implements");
this.space();
this.printList(node.implements, node);
if (node.type === "DeclareClass") {
if (node.mixins?.length) {
this.space();
this.word("mixins");
this.space();
this.printList(node.mixins, node);
}
if (node.implements?.length) {
this.space();
this.word("implements");
this.space();
this.printList(node.implements, node);
}
}
this.space();
this.print(node.body, node);
Expand All @@ -404,10 +408,11 @@ export function _variance(
| t.ClassPrivateProperty
| t.ClassAccessorProperty,
) {
if (node.variance) {
if (node.variance.kind === "plus") {
const kind = node.variance?.kind;
if (kind != null) {
if (kind === "plus") {
this.token("+");
} else if (node.variance.kind === "minus") {
} else if (kind === "minus") {
this.token("-");
}
}
Expand All @@ -433,7 +438,7 @@ export function InterfaceTypeAnnotation(
node: t.InterfaceTypeAnnotation,
) {
this.word("interface");
if (node.extends && node.extends.length) {
if (node.extends?.length) {
this.space();
this.word("extends");
this.space();
Expand Down
5 changes: 3 additions & 2 deletions packages/babel-parser/src/plugins/flow/index.ts
Expand Up @@ -717,8 +717,6 @@ export default (superClass: typeof Parser) =>
}

node.extends = [];
node.implements = [];
node.mixins = [];

if (this.eat(tt._extends)) {
do {
Expand All @@ -727,6 +725,9 @@ export default (superClass: typeof Parser) =>
}

if (isClass) {
node.implements = [];
node.mixins = [];

if (this.eatContextual(tt._mixins)) {
do {
node.mixins.push(this.flowParseInterfaceExtends());
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":12,"end":27,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":27,"index":27}},
Expand Down
Expand Up @@ -38,8 +38,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":52,"end":54,"loc":{"start":{"line":1,"column":52,"index":52},"end":{"line":1,"column":54,"index":54}},
Expand Down
Expand Up @@ -38,8 +38,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":52,"end":54,"loc":{"start":{"line":1,"column":52,"index":52},"end":{"line":1,"column":54,"index":54}},
Expand Down
Expand Up @@ -38,8 +38,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":52,"end":54,"loc":{"start":{"line":1,"column":52,"index":52},"end":{"line":1,"column":54,"index":54}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":20,"end":35,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":35,"index":35}},
Expand Down Expand Up @@ -70,8 +68,6 @@
]
},
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":60,"end":70,"loc":{"start":{"line":2,"column":24,"index":60},"end":{"line":2,"column":34,"index":70}},
Expand Down
Expand Up @@ -20,8 +20,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":20,"end":45,"loc":{"start":{"line":2,"column":12,"index":20},"end":{"line":5,"column":1,"index":45}},
Expand Down
Expand Up @@ -21,8 +21,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":20,"end":45,"loc":{"start":{"line":2,"column":12,"index":20},"end":{"line":5,"column":1,"index":45}},
Expand Down
Expand Up @@ -21,8 +21,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":20,"end":60,"loc":{"start":{"line":2,"column":12,"index":20},"end":{"line":6,"column":1,"index":60}},
Expand Down
Expand Up @@ -20,8 +20,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":17,"end":19,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":19,"index":19}},
Expand Down
Expand Up @@ -41,8 +41,6 @@
"typeParameters": null
}
],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":37,"end":39,"loc":{"start":{"line":2,"column":28,"index":37},"end":{"line":2,"column":30,"index":39}},
Expand Down
Expand Up @@ -50,8 +50,6 @@
"typeParameters": null
}
],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":39,"end":41,"loc":{"start":{"line":2,"column":30,"index":39},"end":{"line":2,"column":32,"index":41}},
Expand Down
Expand Up @@ -31,8 +31,6 @@
"typeParameters": null
}
],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":34,"end":36,"loc":{"start":{"line":2,"column":25,"index":34},"end":{"line":2,"column":27,"index":36}},
Expand Down
Expand Up @@ -40,8 +40,6 @@
"typeParameters": null
}
],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":36,"end":38,"loc":{"start":{"line":2,"column":27,"index":36},"end":{"line":2,"column":29,"index":38}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":12,"end":14,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":14,"index":14}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":15,"end":51,"loc":{"start":{"line":1,"column":15,"index":15},"end":{"line":4,"column":1,"index":51}},
Expand Down
Expand Up @@ -28,8 +28,6 @@
"typeParameters": null
}
],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":22,"end":24,"loc":{"start":{"line":1,"column":22,"index":22},"end":{"line":1,"column":24,"index":24}},
Expand Down
Expand Up @@ -79,8 +79,6 @@
}
}
],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":34,"end":36,"loc":{"start":{"line":1,"column":34,"index":34},"end":{"line":1,"column":36,"index":36}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":12,"end":34,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":34,"index":34}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":21,"end":65,"loc":{"start":{"line":1,"column":21,"index":21},"end":{"line":1,"column":65,"index":65}},
Expand Down
Expand Up @@ -20,8 +20,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":17,"end":19,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":19,"index":19}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":17,"end":19,"loc":{"start":{"line":1,"column":17,"index":17},"end":{"line":1,"column":19,"index":19}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":12,"end":32,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":32,"index":32}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":12,"end":31,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":31,"index":31}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":14,"end":16,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":16,"index":16}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":12,"end":28,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":28,"index":28}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":12,"end":26,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":26,"index":26}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":12,"end":47,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":3,"column":1,"index":47}},
Expand Down
Expand Up @@ -17,8 +17,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":12,"end":52,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":3,"column":1,"index":52}},
Expand Down
Expand Up @@ -20,8 +20,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":12,"end":14,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":14,"index":14}},
Expand All @@ -46,8 +44,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":28,"end":30,"loc":{"start":{"line":2,"column":12,"index":28},"end":{"line":2,"column":14,"index":30}},
Expand Down
Expand Up @@ -39,8 +39,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":41,"end":43,"loc":{"start":{"line":2,"column":21,"index":41},"end":{"line":2,"column":23,"index":43}},
Expand Down Expand Up @@ -75,8 +73,6 @@
},
"typeParameters": null,
"extends": [],
"implements": [],
"mixins": [],
"body": {
"type": "ObjectTypeAnnotation",
"start":84,"end":86,"loc":{"start":{"line":5,"column":13,"index":84},"end":{"line":5,"column":15,"index":86}},
Expand Down