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",
|
"version": "7.1.4",
|
||||||
"author": "The Babel Team (https://babeljs.io/team)",
|
"author": "The Babel Team (https://babeljs.io/team)",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -1,4 +1,3 @@
|
|||||||
import { declare } from "@babel/helper-plugin-utils";
|
|
||||||
import nameFunction from "@babel/helper-function-name";
|
import nameFunction from "@babel/helper-function-name";
|
||||||
import { types as t } from "@babel/core";
|
import { types as t } from "@babel/core";
|
||||||
import {
|
import {
|
||||||
@ -12,13 +11,12 @@ import {
|
|||||||
enableFeature,
|
enableFeature,
|
||||||
verifyUsedFeatures,
|
verifyUsedFeatures,
|
||||||
FEATURES,
|
FEATURES,
|
||||||
setLoose,
|
|
||||||
isLoose,
|
isLoose,
|
||||||
} from "./features";
|
} from "./features";
|
||||||
|
|
||||||
import pkg from "../package.json";
|
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
|
// 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
|
// 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 version = pkg.version.split(".").reduce((v, x) => v * 1e5 + +x, 0);
|
||||||
const versionKey = "@babel/plugin-class-features/version";
|
const versionKey = "@babel/plugin-class-features/version";
|
||||||
|
|
||||||
const getFeatureOptions = (options, name) => {
|
export function createClassFeaturePlugin({
|
||||||
const value = options[name];
|
name,
|
||||||
|
feature,
|
||||||
if (value === undefined || value === false) return { enabled: false };
|
loose,
|
||||||
if (value === true) return { enabled: true, loose: false };
|
manipulateOptions,
|
||||||
|
}) {
|
||||||
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");
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: "class-features",
|
name,
|
||||||
|
manipulateOptions,
|
||||||
manipulateOptions(opts, parserOpts) {
|
|
||||||
if (fields) {
|
|
||||||
parserOpts.plugins.push("classProperties", "classPrivateProperties");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
pre() {
|
pre() {
|
||||||
|
enableFeature(this.file, feature, loose);
|
||||||
|
|
||||||
if (!this.file.get(versionKey) || this.file.get(versionKey) < version) {
|
if (!this.file.get(versionKey) || this.file.get(versionKey) < version) {
|
||||||
this.file.set(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: {
|
visitor: {
|
||||||
@ -203,4 +163,4 @@ export default declare((api, options) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
@ -13,7 +13,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/helper-plugin-utils": "^7.0.0",
|
"@babel/helper-plugin-utils": "^7.0.0",
|
||||||
"@babel/plugin-class-features": "^7.1.4"
|
"@babel/helper-create-class-features-plugin": "^7.1.4"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@babel/core": "^7.0.0-0"
|
"@babel/core": "^7.0.0-0"
|
||||||
|
|||||||
@ -1,25 +1,22 @@
|
|||||||
|
/* eslint-disable local-rules/plugin-name */
|
||||||
|
|
||||||
import { declare } from "@babel/helper-plugin-utils";
|
import { declare } from "@babel/helper-plugin-utils";
|
||||||
import pluginClassFeatures, {
|
import {
|
||||||
enableFeature,
|
createClassFeaturePlugin,
|
||||||
FEATURES,
|
FEATURES,
|
||||||
} from "@babel/plugin-class-features";
|
} from "@babel/helper-create-class-features-plugin";
|
||||||
|
|
||||||
export default declare((api, options) => {
|
export default declare((api, options) => {
|
||||||
api.assertVersion(7);
|
api.assertVersion(7);
|
||||||
|
|
||||||
const { loose } = options;
|
return createClassFeaturePlugin({
|
||||||
|
|
||||||
return {
|
|
||||||
name: "proposal-class-properties",
|
name: "proposal-class-properties",
|
||||||
|
|
||||||
inherits: pluginClassFeatures,
|
feature: FEATURES.fields,
|
||||||
|
loose: options.loose,
|
||||||
|
|
||||||
manipulateOptions(opts, parserOpts) {
|
manipulateOptions(opts, parserOpts) {
|
||||||
parserOpts.plugins.push("classProperties", "classPrivateProperties");
|
parserOpts.plugins.push("classProperties", "classPrivateProperties");
|
||||||
},
|
},
|
||||||
|
});
|
||||||
pre() {
|
|
||||||
enableFeature(this.file, FEATURES.fields, loose);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/helper-plugin-utils": "^7.0.0",
|
"@babel/helper-plugin-utils": "^7.0.0",
|
||||||
"@babel/plugin-class-features": "^7.1.4"
|
"@babel/helper-create-class-features-plugin": "^7.1.4"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"@babel/core": "^7.0.0-0"
|
"@babel/core": "^7.0.0-0"
|
||||||
|
|||||||
@ -1,25 +1,22 @@
|
|||||||
|
/* eslint-disable local-rules/plugin-name */
|
||||||
|
|
||||||
import { declare } from "@babel/helper-plugin-utils";
|
import { declare } from "@babel/helper-plugin-utils";
|
||||||
import pluginClassFeatures, {
|
import {
|
||||||
enableFeature,
|
createClassFeaturePlugin,
|
||||||
FEATURES,
|
FEATURES,
|
||||||
} from "@babel/plugin-class-features";
|
} from "@babel/helper-create-class-features-plugin";
|
||||||
|
|
||||||
export default declare((api, options) => {
|
export default declare((api, options) => {
|
||||||
api.assertVersion(7);
|
api.assertVersion(7);
|
||||||
|
|
||||||
const { loose } = options;
|
return createClassFeaturePlugin({
|
||||||
|
|
||||||
return {
|
|
||||||
name: "proposal-private-methods",
|
name: "proposal-private-methods",
|
||||||
|
|
||||||
inherits: pluginClassFeatures,
|
feature: FEATURES.privateMethods,
|
||||||
|
loose: options.loose,
|
||||||
|
|
||||||
manipulateOptions(opts, parserOpts) {
|
manipulateOptions(opts, parserOpts) {
|
||||||
parserOpts.plugins.push("classPrivateMethods");
|
parserOpts.plugins.push("classPrivateMethods");
|
||||||
},
|
},
|
||||||
|
});
|
||||||
pre() {
|
|
||||||
enableFeature(this.file, FEATURES.privateMethods, loose);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user