Cleanup visitor keys for DeclareInterface and InterfaceDeclaration (#14272)
This commit is contained in:
1 parent
06a7bd1d0b
commit
47830dbedb
9 files changed
+123
-24
No files matched your search
@@ -112,6 +112,23 @@ function postprocess(ast, options) {
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "DeclareInterface":
|
||||
case "InterfaceDeclaration":
|
||||
case "TSInterfaceDeclaration":
|
||||
if (isNonEmptyArray(node.mixins)) {
|
||||
throwSyntaxError(
|
||||
node.mixins[0],
|
||||
"Interface declaration cannot have 'mixins' clause."
|
||||
);
|
||||
}
|
||||
if (isNonEmptyArray(node.implements)) {
|
||||
throwSyntaxError(
|
||||
node.implements[0],
|
||||
"Interface declaration cannot have 'implements' clause."
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case "TSPropertySignature":
|
||||
if (node.initializer) {
|
||||
throwSyntaxError(
|
||||
|
||||
@@ -57,6 +57,8 @@ const excludeKeys = {
|
||||
// TODO: Remove `types` when babel changes AST of `TupleTypeAnnotation`
|
||||
// Flow parser changed `.types` to `.elementTypes` https://github.com/facebook/flow/commit/5b60e6a81dc277dfab2e88fa3737a4dc9aafdcab
|
||||
// TupleTypeAnnotation: ["types"],
|
||||
DeclareInterface: ["mixins", "implements"],
|
||||
InterfaceDeclaration: ["mixins", "implements"],
|
||||
|
||||
// TypeScript
|
||||
TSPropertySignature: ["initializer"],
|
||||
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`snippet: #0 [babel-flow] format 1`] = `
|
||||
"\`declare export interface\` is not supported. Use \`export interface\` instead. (1:16)
|
||||
> 1 | declare export interface A {}
|
||||
| ^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #0 [flow] format 1`] = `
|
||||
"\`declare export interface\` is not supported. Use \`export interface\` instead. (1:16)
|
||||
> 1 | declare export interface A {}
|
||||
| ^^^^^^^^^"
|
||||
`;
|
||||
@@ -1,7 +0,0 @@
|
||||
run_spec(
|
||||
{
|
||||
importMeta: import.meta,
|
||||
snippets: ["declare export interface A {}"],
|
||||
},
|
||||
["flow", "babel-flow"]
|
||||
);
|
||||
@@ -0,0 +1,61 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`snippet: #0 [babel-flow] format 1`] = `
|
||||
"\`declare export interface\` is not supported. Use \`export interface\` instead. (1:16)
|
||||
> 1 | declare export interface A {}
|
||||
| ^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #0 [flow] format 1`] = `
|
||||
"\`declare export interface\` is not supported. Use \`export interface\` instead. (1:16)
|
||||
> 1 | declare export interface A {}
|
||||
| ^^^^^^^^^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #1 [babel-flow] format 1`] = `
|
||||
"Interface declaration cannot have 'mixins' clause. (1:20)
|
||||
> 1 | interface A mixins B {}
|
||||
| ^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #1 [flow] format 1`] = `
|
||||
"Unexpected identifier, expected the token \`{\` (1:13)
|
||||
> 1 | interface A mixins B {}
|
||||
| ^^^^^^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #2 [babel-flow] format 1`] = `
|
||||
"Interface declaration cannot have 'implements' clause. (1:24)
|
||||
> 1 | interface A implements B {}
|
||||
| ^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #2 [flow] format 1`] = `
|
||||
"Unexpected identifier, expected the token \`{\` (1:13)
|
||||
> 1 | interface A implements B {}
|
||||
| ^^^^^^^^^^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #3 [babel-flow] format 1`] = `
|
||||
"Interface declaration cannot have 'mixins' clause. (1:28)
|
||||
> 1 | declare interface A mixins B {}
|
||||
| ^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #3 [flow] format 1`] = `
|
||||
"Unexpected identifier, expected the token \`{\` (1:21)
|
||||
> 1 | declare interface A mixins B {}
|
||||
| ^^^^^^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #4 [babel-flow] format 1`] = `
|
||||
"Interface declaration cannot have 'implements' clause. (1:32)
|
||||
> 1 | declare interface A implements B {}
|
||||
| ^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #4 [flow] format 1`] = `
|
||||
"Unexpected identifier, expected the token \`{\` (1:21)
|
||||
> 1 | declare interface A implements B {}
|
||||
| ^^^^^^^^^^"
|
||||
`;
|
||||
@@ -0,0 +1,16 @@
|
||||
run_spec(
|
||||
{
|
||||
importMeta: import.meta,
|
||||
snippets: [
|
||||
// Not allowed
|
||||
"declare export interface A {}",
|
||||
|
||||
// Can't have mixins nor implements
|
||||
"interface A mixins B {}",
|
||||
"interface A implements B {}",
|
||||
"declare interface A mixins B {}",
|
||||
"declare interface A implements B {}",
|
||||
],
|
||||
},
|
||||
["flow", "babel-flow"]
|
||||
);
|
||||
@@ -11,3 +11,27 @@ exports[`snippet: #0 [typescript] format 1`] = `
|
||||
> 1 | interface I { x: number = 1;}
|
||||
| ^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #1 [babel-ts] format 1`] = `
|
||||
"Unexpected token, expected "{" (1:13)
|
||||
> 1 | interface A mixins B {}
|
||||
| ^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #1 [typescript] format 1`] = `
|
||||
"'{' expected. (1:13)
|
||||
> 1 | interface A mixins B {}
|
||||
| ^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #2 [babel-ts] format 1`] = `
|
||||
"Unexpected token, expected "{" (1:13)
|
||||
> 1 | interface A implements B {}
|
||||
| ^"
|
||||
`;
|
||||
|
||||
exports[`snippet: #2 [typescript] format 1`] = `
|
||||
"Interface declaration cannot have 'implements' clause. (1:24)
|
||||
> 1 | interface A implements B {}
|
||||
| ^"
|
||||
`;
|
||||
@@ -4,6 +4,9 @@ run_spec(
|
||||
snippets: [
|
||||
// Invalid initializer
|
||||
"interface I { x: number = 1;}",
|
||||
// Can't have mixins nor implements
|
||||
"interface A mixins B {}",
|
||||
"interface A implements B {}",
|
||||
],
|
||||
},
|
||||
["babel-ts", "typescript"]
|
||||
|
||||
@@ -176,8 +176,6 @@ exports[`visitor keys estree 1`] = `
|
||||
"id",
|
||||
"typeParameters",
|
||||
"extends",
|
||||
"mixins",
|
||||
"implements",
|
||||
"body",
|
||||
],
|
||||
"DeclareModule": [
|
||||
@@ -375,8 +373,6 @@ exports[`visitor keys estree 1`] = `
|
||||
"id",
|
||||
"typeParameters",
|
||||
"extends",
|
||||
"mixins",
|
||||
"implements",
|
||||
"body",
|
||||
],
|
||||
"InterfaceExtends": [
|
||||
|
||||
Reference in new issue
Block a user