Skip to content

Commit

Permalink
Remove 2018-09 implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Feb 21, 2022
1 parent 165be0f commit 73d8e36
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// TODO(Babel 8): Remove this file

import { types as t, template } from "@babel/core";
import type { File } from "@babel/core";
import type { NodePath } from "@babel/traverse";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const FEATURES = Object.freeze({
//classes: 1 << 0,
fields: 1 << 1,
privateMethods: 1 << 2,
// TODO(Babel 8): Remove this
decorators: 1 << 3,
privateIn: 1 << 4,
staticBlocks: 1 << 5,
Expand Down
75 changes: 52 additions & 23 deletions packages/babel-helper-create-class-features-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ export function createClassFeaturePlugin({
}
}

if (!props.length && !isDecorated) return;
if (process.env.BABEL_8_BREAKING) {
if (!props.length) return;
} else {
if (!props.length && !isDecorated) return;
}

const innerBinding = path.node.id;
let ref: t.Identifier;
Expand Down Expand Up @@ -210,14 +214,35 @@ export function createClassFeaturePlugin({
pureStaticNodes: t.FunctionDeclaration[],
wrapClass: (path: NodePath<t.Class>) => NodePath;

if (isDecorated) {
staticNodes = pureStaticNodes = keysNodes = [];
({ instanceNodes, wrapClass } = buildDecoratedClass(
ref,
path,
elements,
this.file,
));
if (!process.env.BABEL_8_BREAKING) {
if (isDecorated) {
staticNodes = pureStaticNodes = keysNodes = [];
({ instanceNodes, wrapClass } = buildDecoratedClass(
ref,
path,
elements,
this.file,
));
} else {
keysNodes = extractComputedKeys(
ref,
path,
computedPaths,
this.file,
);
({ staticNodes, pureStaticNodes, instanceNodes, wrapClass } =
buildFieldsInitNodes(
ref,
path.node.superClass,
props,
privateNamesMap,
state,
setPublicClassFields ?? loose,
privateFieldsAsProperties ?? loose,
constantSuper ?? loose,
innerBinding,
));
}
} else {
keysNodes = extractComputedKeys(ref, path, computedPaths, this.file);
({ staticNodes, pureStaticNodes, instanceNodes, wrapClass } =
Expand All @@ -240,7 +265,9 @@ export function createClassFeaturePlugin({
constructor,
instanceNodes,
(referenceVisitor, state) => {
if (isDecorated) return;
if (!process.env.BABEL_8_BREAKING) {
if (isDecorated) return;
}
for (const prop of props) {
// @ts-expect-error: TS doesn't infer that prop.node is not a StaticBlock
if (t.isStaticBlock?.(prop.node) || prop.node.static) continue;
Expand All @@ -264,21 +291,23 @@ export function createClassFeaturePlugin({
},

ExportDefaultDeclaration(path: NodePath<t.ExportDefaultDeclaration>) {
if (this.file.get(versionKey) !== version) return;
if (!process.env.BABEL_8_BREAKING) {
if (this.file.get(versionKey) !== version) return;

const decl = path.get("declaration");
const decl = path.get("declaration");

if (decl.isClassDeclaration() && hasDecorators(decl.node)) {
if (decl.node.id) {
// export default class Foo {}
// -->
// class Foo {} export { Foo as default }
splitExportDeclaration(path);
} else {
// Annyms class declarations can be
// transformed as if they were expressions
// @ts-expect-error
decl.node.type = "ClassExpression";
if (decl.isClassDeclaration() && hasDecorators(decl.node)) {
if (decl.node.id) {
// export default class Foo {}
// -->
// class Foo {} export { Foo as default }
splitExportDeclaration(path);
} else {
// Annyms class declarations can be
// transformed as if they were expressions
// @ts-expect-error
decl.node.type = "ClassExpression";
}
}
}
},
Expand Down

0 comments on commit 73d8e36

Please sign in to comment.