Make @babel/plugin-class-features a normal helper package (#9083)
* Make @babel/plugin-class-features a normal helper package This effectively disallows using it directly. * Rename helper * Style * Don't add prefix to plugin name * Move private methods plugin
This commit is contained in:
parent
c4d6f6dcce
commit
4e28459a2f
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "@babel/plugin-class-features",
|
||||
"name": "@babel/helper-create-class-features-plugin",
|
||||
"version": "7.1.4",
|
||||
"author": "The Babel Team (https://babeljs.io/team)",
|
||||
"license": "MIT",
|
||||
@ -1,4 +1,3 @@
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
import nameFunction from "@babel/helper-function-name";
|
||||
import { types as t } from "@babel/core";
|
||||
import {
|
||||
@ -12,13 +11,12 @@ import {
|
||||
enableFeature,
|
||||
verifyUsedFeatures,
|
||||
FEATURES,
|
||||
setLoose,
|
||||
isLoose,
|
||||
} from "./features";
|
||||
|
||||
import pkg from "../package.json";
|
||||
|
||||
export { enableFeature, FEATURES, setLoose };
|
||||
export { FEATURES };
|
||||
|
||||
// Note: Versions are represented as an integer. e.g. 7.1.5 is represented
|
||||
// as 70000100005. This method is easier than using a semver-parsing
|
||||
@ -27,60 +25,22 @@ 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) => {
|
||||
api.assertVersion(7);
|
||||
|
||||
const fields = getFeatureOptions(options, "fields");
|
||||
const privateMethods = getFeatureOptions(options, "privateMethods");
|
||||
const decorators = getFeatureOptions(options, "decorators");
|
||||
|
||||
export function createClassFeaturePlugin({
|
||||
name,
|
||||
feature,
|
||||
loose,
|
||||
manipulateOptions,
|
||||
}) {
|
||||
return {
|
||||
name: "class-features",
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
if (fields) {
|
||||
parserOpts.plugins.push("classProperties", "classPrivateProperties");
|
||||
}
|
||||
},
|
||||
name,
|
||||
manipulateOptions,
|
||||
|
||||
pre() {
|
||||
enableFeature(this.file, feature, loose);
|
||||
|
||||
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) {
|
||||
enableFeature(this.file, FEATURES.privateMethods);
|
||||
}
|
||||
if (decorators.enabled) {
|
||||
throw new Error("Decorators are not supported yet");
|
||||
enableFeature(this.file, FEATURES.decorators);
|
||||
}
|
||||
},
|
||||
|
||||
visitor: {
|
||||
@ -203,4 +163,4 @@ export default declare((api, options) => {
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
@ -13,7 +13,7 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": "^7.0.0",
|
||||
"@babel/plugin-class-features": "^7.1.4"
|
||||
"@babel/helper-create-class-features-plugin": "^7.1.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "^7.0.0-0"
|
||||
|
||||
@ -1,25 +1,22 @@
|
||||
/* eslint-disable local-rules/plugin-name */
|
||||
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
import pluginClassFeatures, {
|
||||
enableFeature,
|
||||
import {
|
||||
createClassFeaturePlugin,
|
||||
FEATURES,
|
||||
} from "@babel/plugin-class-features";
|
||||
} from "@babel/helper-create-class-features-plugin";
|
||||
|
||||
export default declare((api, options) => {
|
||||
api.assertVersion(7);
|
||||
|
||||
const { loose } = options;
|
||||
|
||||
return {
|
||||
return createClassFeaturePlugin({
|
||||
name: "proposal-class-properties",
|
||||
|
||||
inherits: pluginClassFeatures,
|
||||
feature: FEATURES.fields,
|
||||
loose: options.loose,
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("classProperties", "classPrivateProperties");
|
||||
},
|
||||
|
||||
pre() {
|
||||
enableFeature(this.file, FEATURES.fields, loose);
|
||||
},
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": "^7.0.0",
|
||||
"@babel/plugin-class-features": "^7.1.4"
|
||||
"@babel/helper-create-class-features-plugin": "^7.1.4"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@babel/core": "^7.0.0-0"
|
||||
|
||||
@ -1,25 +1,22 @@
|
||||
/* eslint-disable local-rules/plugin-name */
|
||||
|
||||
import { declare } from "@babel/helper-plugin-utils";
|
||||
import pluginClassFeatures, {
|
||||
enableFeature,
|
||||
import {
|
||||
createClassFeaturePlugin,
|
||||
FEATURES,
|
||||
} from "@babel/plugin-class-features";
|
||||
} from "@babel/helper-create-class-features-plugin";
|
||||
|
||||
export default declare((api, options) => {
|
||||
api.assertVersion(7);
|
||||
|
||||
const { loose } = options;
|
||||
|
||||
return {
|
||||
return createClassFeaturePlugin({
|
||||
name: "proposal-private-methods",
|
||||
|
||||
inherits: pluginClassFeatures,
|
||||
feature: FEATURES.privateMethods,
|
||||
loose: options.loose,
|
||||
|
||||
manipulateOptions(opts, parserOpts) {
|
||||
parserOpts.plugins.push("classPrivateMethods");
|
||||
},
|
||||
|
||||
pre() {
|
||||
enableFeature(this.file, FEATURES.privateMethods, loose);
|
||||
},
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user