From b5f457af5ed49c6790656a30f1300ef76a5e3016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 20 Jun 2022 13:57:23 -0400 Subject: [PATCH] supress Babel 7 AST errors --- .../src/generators/typescript.ts | 10 +++-- packages/babel-types/src/definitions/core.ts | 38 ++++++++++++++++--- .../babel-types/src/definitions/typescript.ts | 6 ++- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/packages/babel-generator/src/generators/typescript.ts b/packages/babel-generator/src/generators/typescript.ts index 9f0405b7b09f..0ffce6004dd3 100644 --- a/packages/babel-generator/src/generators/typescript.ts +++ b/packages/babel-generator/src/generators/typescript.ts @@ -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); @@ -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); } diff --git a/packages/babel-types/src/definitions/core.ts b/packages/babel-types/src/definitions/core.ts index 213ed8c27c9f..bdd8fa61a794 100644 --- a/packages/babel-types/src/definitions/core.ts +++ b/packages/babel-types/src/definitions/core.ts @@ -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: { @@ -390,6 +395,7 @@ export const functionTypeAnnotationCommon = { : assertNodeType( "TypeParameterDeclaration", "TSTypeParameterDeclaration", + // @ts-ignore Babel 7 AST "Noop", ), optional: true, @@ -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: { @@ -1354,6 +1365,7 @@ defineType("ClassExpression", { : assertNodeType( "TypeParameterDeclaration", "TSTypeParameterDeclaration", + // @ts-ignore Babel 7 AST "Noop", ), optional: true, @@ -1411,6 +1423,7 @@ defineType("ClassDeclaration", { : assertNodeType( "TypeParameterDeclaration", "TSTypeParameterDeclaration", + // @ts-ignore Babel 7 AST "Noop", ), optional: true, @@ -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: { @@ -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: { @@ -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: { diff --git a/packages/babel-types/src/definitions/typescript.ts b/packages/babel-types/src/definitions/typescript.ts index f480a461488d..c82ee224a214 100644 --- a/packages/babel-types/src/definitions/typescript.ts +++ b/packages/babel-types/src/definitions/typescript.ts @@ -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, }, };