Skip to content

Commit

Permalink
supress Babel 7 AST errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jun 20, 2022
1 parent 21f5a9b commit b5f457a
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 11 deletions.
10 changes: 6 additions & 4 deletions packages/babel-generator/src/generators/typescript.ts
Expand Up @@ -239,9 +239,10 @@ export function tsPrintFunctionOrConstructorType(
) {
const { typeParameters } = node;
const parameters = process.env.BABEL_8_BREAKING
? // @ts-expect-error Babel 8 AST shape
? // @ts-ignore Babel 8 AST shape
node.params
: node.parameters;
: // @ts-ignore Babel 7 AST shape
node.parameters;
this.print(typeParameters, node);
this.token("(");
this._parameters(parameters, node);
Expand All @@ -250,9 +251,10 @@ export function tsPrintFunctionOrConstructorType(
this.token("=>");
this.space();
const returnType = process.env.BABEL_8_BREAKING
? // @ts-expect-error Babel 8 AST shape
? // @ts-ignore Babel 8 AST shape
node.returnType
: node.typeAnnotation;
: // @ts-ignore Babel 7 AST shape
node.typeAnnotation;
this.print(returnType.typeAnnotation, node);
}

Expand Down
38 changes: 33 additions & 5 deletions packages/babel-types/src/definitions/core.ts
Expand Up @@ -381,7 +381,12 @@ export const functionTypeAnnotationCommon = {
returnType: {
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
: assertNodeType(
"TypeAnnotation",
"TSTypeAnnotation",
// @ts-ignore Babel 7 AST
"Noop",
),
optional: true,
},
typeParameters: {
Expand All @@ -390,6 +395,7 @@ export const functionTypeAnnotationCommon = {
: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
// @ts-ignore Babel 7 AST
"Noop",
),
optional: true,
Expand Down Expand Up @@ -475,7 +481,12 @@ export const patternLikeCommon = {
typeAnnotation: {
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
: assertNodeType(
"TypeAnnotation",
"TSTypeAnnotation",
// @ts-ignore Babel 7 AST
"Noop",
),
optional: true,
},
decorators: {
Expand Down Expand Up @@ -1354,6 +1365,7 @@ defineType("ClassExpression", {
: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
// @ts-ignore Babel 7 AST
"Noop",
),
optional: true,
Expand Down Expand Up @@ -1411,6 +1423,7 @@ defineType("ClassDeclaration", {
: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
// @ts-ignore Babel 7 AST
"Noop",
),
optional: true,
Expand Down Expand Up @@ -2159,7 +2172,12 @@ defineType("ClassProperty", {
typeAnnotation: {
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
: assertNodeType(
"TypeAnnotation",
"TSTypeAnnotation",
// @ts-ignore Babel 7 AST
"Noop",
),
optional: true,
},
decorators: {
Expand Down Expand Up @@ -2233,7 +2251,12 @@ defineType("ClassAccessorProperty", {
typeAnnotation: {
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
: assertNodeType(
"TypeAnnotation",
"TSTypeAnnotation",
// @ts-ignore Babel 7 AST
"Noop",
),
optional: true,
},
decorators: {
Expand Down Expand Up @@ -2273,7 +2296,12 @@ defineType("ClassPrivateProperty", {
typeAnnotation: {
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
: assertNodeType(
"TypeAnnotation",
"TSTypeAnnotation",
// @ts-ignore Babel 7 AST
"Noop",
),
optional: true,
},
decorators: {
Expand Down
6 changes: 4 additions & 2 deletions packages/babel-types/src/definitions/typescript.ts
Expand Up @@ -26,13 +26,15 @@ const tSFunctionTypeAnnotationCommon = {
returnType: {
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TSTypeAnnotation")
: assertNodeType("TSTypeAnnotation", "Noop"),
: // @ts-ignore Babel 7 AST
assertNodeType("TSTypeAnnotation", "Noop"),
optional: true,
},
typeParameters: {
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TSTypeParameterDeclaration")
: assertNodeType("TSTypeParameterDeclaration", "Noop"),
: // @ts-ignore Babel 7 AST
assertNodeType("TSTypeParameterDeclaration", "Noop"),
optional: true,
},
};
Expand Down

0 comments on commit b5f457a

Please sign in to comment.