[babel 8] Remove the Noop node type (#12361)
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
parent
03d7911be6
commit
507ad63140
@ -46,8 +46,6 @@ export function BlockStatement(this: Printer, node: t.BlockStatement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Noop(this: Printer) {}
|
|
||||||
|
|
||||||
export function Directive(this: Printer, node: t.Directive) {
|
export function Directive(this: Printer, node: t.Directive) {
|
||||||
this.print(node.value, node);
|
this.print(node.value, node);
|
||||||
this.semicolon();
|
this.semicolon();
|
||||||
|
|||||||
@ -56,7 +56,7 @@ export function DeclareFunction(
|
|||||||
this.word("function");
|
this.word("function");
|
||||||
this.space();
|
this.space();
|
||||||
this.print(node.id, node);
|
this.print(node.id, node);
|
||||||
// @ts-expect-error todo(flow->ts) typeAnnotation does not exist on Noop
|
// @ts-ignore TODO(Babel 8) Remove this comment, since we'll remove the Noop node
|
||||||
this.print(node.id.typeAnnotation.typeAnnotation, node);
|
this.print(node.id.typeAnnotation.typeAnnotation, node);
|
||||||
|
|
||||||
if (node.predicate) {
|
if (node.predicate) {
|
||||||
|
|||||||
@ -680,6 +680,11 @@ class Printer {
|
|||||||
// Expose the node type functions and helpers on the prototype for easy usage.
|
// Expose the node type functions and helpers on the prototype for easy usage.
|
||||||
Object.assign(Printer.prototype, generatorFunctions);
|
Object.assign(Printer.prototype, generatorFunctions);
|
||||||
|
|
||||||
|
if (!process.env.BABEL_8_BREAKING) {
|
||||||
|
// @ts-ignore
|
||||||
|
Printer.prototype.Noop = function Noop(this: Printer) {};
|
||||||
|
}
|
||||||
|
|
||||||
type GeneratorFunctions = typeof generatorFunctions;
|
type GeneratorFunctions = typeof generatorFunctions;
|
||||||
interface Printer extends GeneratorFunctions {}
|
interface Printer extends GeneratorFunctions {}
|
||||||
export default Printer;
|
export default Printer;
|
||||||
|
|||||||
@ -373,11 +373,15 @@ export const functionCommon = {
|
|||||||
|
|
||||||
export const functionTypeAnnotationCommon = {
|
export const functionTypeAnnotationCommon = {
|
||||||
returnType: {
|
returnType: {
|
||||||
validate: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
|
validate: process.env.BABEL_8_BREAKING
|
||||||
|
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
|
||||||
|
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
typeParameters: {
|
typeParameters: {
|
||||||
validate: assertNodeType(
|
validate: process.env.BABEL_8_BREAKING
|
||||||
|
? assertNodeType("TypeParameterDeclaration", "TSTypeParameterDeclaration")
|
||||||
|
: assertNodeType(
|
||||||
"TypeParameterDeclaration",
|
"TypeParameterDeclaration",
|
||||||
"TSTypeParameterDeclaration",
|
"TSTypeParameterDeclaration",
|
||||||
"Noop",
|
"Noop",
|
||||||
@ -455,8 +459,9 @@ defineType("FunctionExpression", {
|
|||||||
|
|
||||||
export const patternLikeCommon = {
|
export const patternLikeCommon = {
|
||||||
typeAnnotation: {
|
typeAnnotation: {
|
||||||
// TODO: @babel/plugin-transform-flow-comments puts a Noop here, is there a better way?
|
validate: process.env.BABEL_8_BREAKING
|
||||||
validate: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
|
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
|
||||||
|
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
decorators: {
|
decorators: {
|
||||||
@ -1272,7 +1277,12 @@ defineType("ClassExpression", {
|
|||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
typeParameters: {
|
typeParameters: {
|
||||||
validate: assertNodeType(
|
validate: process.env.BABEL_8_BREAKING
|
||||||
|
? assertNodeType(
|
||||||
|
"TypeParameterDeclaration",
|
||||||
|
"TSTypeParameterDeclaration",
|
||||||
|
)
|
||||||
|
: assertNodeType(
|
||||||
"TypeParameterDeclaration",
|
"TypeParameterDeclaration",
|
||||||
"TSTypeParameterDeclaration",
|
"TSTypeParameterDeclaration",
|
||||||
"Noop",
|
"Noop",
|
||||||
@ -1324,7 +1334,12 @@ defineType("ClassDeclaration", {
|
|||||||
validate: assertNodeType("Identifier"),
|
validate: assertNodeType("Identifier"),
|
||||||
},
|
},
|
||||||
typeParameters: {
|
typeParameters: {
|
||||||
validate: assertNodeType(
|
validate: process.env.BABEL_8_BREAKING
|
||||||
|
? assertNodeType(
|
||||||
|
"TypeParameterDeclaration",
|
||||||
|
"TSTypeParameterDeclaration",
|
||||||
|
)
|
||||||
|
: assertNodeType(
|
||||||
"TypeParameterDeclaration",
|
"TypeParameterDeclaration",
|
||||||
"TSTypeParameterDeclaration",
|
"TSTypeParameterDeclaration",
|
||||||
"Noop",
|
"Noop",
|
||||||
|
|||||||
@ -60,7 +60,9 @@ defineType("ClassProperty", {
|
|||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
typeAnnotation: {
|
typeAnnotation: {
|
||||||
validate: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
|
validate: process.env.BABEL_8_BREAKING
|
||||||
|
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
|
||||||
|
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
decorators: {
|
decorators: {
|
||||||
@ -118,7 +120,9 @@ defineType("ClassPrivateProperty", {
|
|||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
typeAnnotation: {
|
typeAnnotation: {
|
||||||
validate: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
|
validate: process.env.BABEL_8_BREAKING
|
||||||
|
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
|
||||||
|
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
decorators: {
|
decorators: {
|
||||||
|
|||||||
@ -5,9 +5,11 @@ import defineType, {
|
|||||||
} from "./utils";
|
} from "./utils";
|
||||||
import { PLACEHOLDERS } from "./placeholders";
|
import { PLACEHOLDERS } from "./placeholders";
|
||||||
|
|
||||||
defineType("Noop", {
|
if (!process.env.BABEL_8_BREAKING) {
|
||||||
|
defineType("Noop", {
|
||||||
visitor: [],
|
visitor: [],
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
defineType("Placeholder", {
|
defineType("Placeholder", {
|
||||||
visitor: [],
|
visitor: [],
|
||||||
|
|||||||
@ -20,11 +20,15 @@ const bool = assertValueType("boolean");
|
|||||||
|
|
||||||
const tSFunctionTypeAnnotationCommon = {
|
const tSFunctionTypeAnnotationCommon = {
|
||||||
returnType: {
|
returnType: {
|
||||||
validate: assertNodeType("TSTypeAnnotation", "Noop"),
|
validate: process.env.BABEL_8_BREAKING
|
||||||
|
? assertNodeType("TSTypeAnnotation")
|
||||||
|
: assertNodeType("TSTypeAnnotation", "Noop"),
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
typeParameters: {
|
typeParameters: {
|
||||||
validate: assertNodeType("TSTypeParameterDeclaration", "Noop"),
|
validate: process.env.BABEL_8_BREAKING
|
||||||
|
? assertNodeType("TSTypeParameterDeclaration")
|
||||||
|
: assertNodeType("TSTypeParameterDeclaration", "Noop"),
|
||||||
optional: true,
|
optional: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -37,14 +37,18 @@ python --version
|
|||||||
# TEST #
|
# TEST #
|
||||||
#==============================================================================#
|
#==============================================================================#
|
||||||
|
|
||||||
if [ "$BABEL_8_BREAKING" = true ] ; then
|
|
||||||
# This option is removed in Babel 8
|
|
||||||
sed -i 's/allowDeclareFields: true,\?/\/* allowDeclareFields: true *\//g' babel.config.js
|
|
||||||
fi
|
|
||||||
|
|
||||||
startLocalRegistry "$root"/verdaccio-config.yml
|
startLocalRegistry "$root"/verdaccio-config.yml
|
||||||
yarn install
|
yarn install
|
||||||
yarn dedupe '@babel/*'
|
yarn dedupe '@babel/*'
|
||||||
|
|
||||||
|
if [ "$BABEL_8_BREAKING" = true ] ; then
|
||||||
|
# This option is removed in Babel 8
|
||||||
|
sed -i 's/allowDeclareFields: true,\?/\/* allowDeclareFields: true *\//g' babel.config.js
|
||||||
|
|
||||||
|
# Jest depends on @types/babel__traverse for Babel 7, and they contain the removed Noop node
|
||||||
|
sed -i 's/t.Noop/any/g' node_modules/@types/babel__traverse/index.d.ts
|
||||||
|
fi
|
||||||
|
|
||||||
yarn build
|
yarn build
|
||||||
|
|
||||||
# The full test suite takes about 20mins on CircleCI. We run only a few of them
|
# The full test suite takes about 20mins on CircleCI. We run only a few of them
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user