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

[babel 8] Remove the Noop node type #12361

Merged
merged 4 commits into from
Feb 21, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/babel-generator/src/generators/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
this.print(node.value, node);
this.semicolon();
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-generator/src/generators/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export function DeclareFunction(
this.word("function");
this.space();
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);

if (node.predicate) {
Expand Down
5 changes: 5 additions & 0 deletions packages/babel-generator/src/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,11 @@ class Printer {
// Expose the node type functions and helpers on the prototype for easy usage.
Object.assign(Printer.prototype, generatorFunctions);

if (!process.env.BABEL_8_BREAKING) {
// @ts-ignore
Printer.prototype.Noop = function Noop(this: Printer) {};
}

type GeneratorFunctions = typeof generatorFunctions;
interface Printer extends GeneratorFunctions {}
export default Printer;
Expand Down
51 changes: 33 additions & 18 deletions packages/babel-types/src/definitions/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -373,15 +373,19 @@ export const functionCommon = {

export const functionTypeAnnotationCommon = {
returnType: {
validate: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
optional: true,
},
typeParameters: {
validate: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
"Noop",
),
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TypeParameterDeclaration", "TSTypeParameterDeclaration")
: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
"Noop",
),
optional: true,
},
};
Expand Down Expand Up @@ -455,8 +459,9 @@ defineType("FunctionExpression", {

export const patternLikeCommon = {
typeAnnotation: {
// TODO: @babel/plugin-transform-flow-comments puts a Noop here, is there a better way?
validate: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
optional: true,
},
decorators: {
Expand Down Expand Up @@ -1272,11 +1277,16 @@ defineType("ClassExpression", {
optional: true,
},
typeParameters: {
validate: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
"Noop",
),
validate: process.env.BABEL_8_BREAKING
? assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
)
: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
"Noop",
),
optional: true,
},
body: {
Expand Down Expand Up @@ -1324,11 +1334,16 @@ defineType("ClassDeclaration", {
validate: assertNodeType("Identifier"),
},
typeParameters: {
validate: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
"Noop",
),
validate: process.env.BABEL_8_BREAKING
? assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
)
: assertNodeType(
"TypeParameterDeclaration",
"TSTypeParameterDeclaration",
"Noop",
),
optional: true,
},
body: {
Expand Down
8 changes: 6 additions & 2 deletions packages/babel-types/src/definitions/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ defineType("ClassProperty", {
optional: true,
},
typeAnnotation: {
validate: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
optional: true,
},
decorators: {
Expand Down Expand Up @@ -118,7 +120,9 @@ defineType("ClassPrivateProperty", {
optional: true,
},
typeAnnotation: {
validate: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TypeAnnotation", "TSTypeAnnotation")
: assertNodeType("TypeAnnotation", "TSTypeAnnotation", "Noop"),
optional: true,
},
decorators: {
Expand Down
8 changes: 5 additions & 3 deletions packages/babel-types/src/definitions/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import defineType, {
} from "./utils";
import { PLACEHOLDERS } from "./placeholders";

defineType("Noop", {
visitor: [],
});
if (!process.env.BABEL_8_BREAKING) {
defineType("Noop", {
visitor: [],
});
}

defineType("Placeholder", {
visitor: [],
Expand Down
8 changes: 6 additions & 2 deletions packages/babel-types/src/definitions/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ const bool = assertValueType("boolean");

const tSFunctionTypeAnnotationCommon = {
returnType: {
validate: assertNodeType("TSTypeAnnotation", "Noop"),
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TSTypeAnnotation")
: assertNodeType("TSTypeAnnotation", "Noop"),
optional: true,
},
typeParameters: {
validate: assertNodeType("TSTypeParameterDeclaration", "Noop"),
validate: process.env.BABEL_8_BREAKING
? assertNodeType("TSTypeParameterDeclaration")
: assertNodeType("TSTypeParameterDeclaration", "Noop"),
optional: true,
},
};
Expand Down
10 changes: 7 additions & 3 deletions scripts/integration-tests/e2e-jest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ python --version
# TEST #
#==============================================================================#

startLocalRegistry "$root"/verdaccio-config.yml
yarn install
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

startLocalRegistry "$root"/verdaccio-config.yml
yarn install
yarn dedupe '@babel/*'
yarn build

# The full test suite takes about 20mins on CircleCI. We run only a few of them
Expand Down