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

Remove direct options to @babel/plugin-class-features #9050

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 1 addition & 46 deletions packages/babel-plugin-class-features/src/index.js
Expand Up @@ -27,61 +27,16 @@ export { enableFeature, FEATURES, setLoose };
const version = pkg.version.split(".").reduce((v, x) => v * 1e5 + +x, 0);
const versionKey = "@babel/plugin-class-features/version";

const getFeatureOptions = (options, name) => {
const value = options[name];

if (value === undefined || value === false) return { enabled: false };
if (value === true) return { enabled: true, loose: false };

if (typeof value === "object") {
if (
typeof value.loose !== "undefined" &&
typeof value.loose !== "boolean"
) {
throw new Error(`.${name}.loose must be a boolean or undefined.`);
}

return { enabled: true, loose: !!value.loose };
}

throw new Error(
`.${name} must be a boolean, an object with a 'loose'` +
` property or undefined.`,
);
};

export default declare((api, options) => {
export default declare(api => {
api.assertVersion(7);

const fields = getFeatureOptions(options, "fields");
const privateMethods = getFeatureOptions(options, "privateMethods");
const decorators = getFeatureOptions(options, "decorators");

return {
name: "class-features",

manipulateOptions(opts, parserOpts) {
if (fields) {
parserOpts.plugins.push("classProperties", "classPrivateProperties");
}
},

pre() {
if (!this.file.get(versionKey) || this.file.get(versionKey) < version) {
this.file.set(versionKey, version);
}

if (fields.enabled) {
enableFeature(this.file, FEATURES.fields, fields.loose);
}
if (privateMethods.enabled) {
throw new Error("Private methods are not supported yet");
enableFeature(this.file, FEATURES.privateMethods);
}
if (decorators.enabled) {
throw new Error("Decorators are not supported yet");
enableFeature(this.file, FEATURES.decorators);
}
},

visitor: {
Expand Down