Skip to content

Commit

Permalink
Always use the new implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Apr 20, 2021
1 parent bb26610 commit bf01056
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
isLoose,
} from "./features";

export { FEATURES, injectInitialization };
export { FEATURES, enableFeature, injectInitialization };

// 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,17 @@
/* eslint-disable @babel/development/plugin-name */

import { declare } from "@babel/helper-plugin-utils";
import {
createClassFeaturePlugin,
FEATURES,
} from "@babel/helper-create-class-features-plugin";
import { isRequired } from "@babel/helper-compilation-targets";

import pluginPrivateIn from "./native-private-fields";

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

const {
loose,
nativePrivateFields = !isRequired(
"proposal-private-methods",
api.targets(),
),
} = options;
// NOTE: When using the class fields or private methods plugins,
// they will also take care of '#priv in obj' checks when visiting
// the ClassExpression or ClassDeclaration nodes.
// The visitor of this plugin is only effective when not compiling
// private fields and methods.

if (nativePrivateFields) return pluginPrivateIn(api);

return createClassFeaturePlugin({
name: "proposal-class-properties",

api,
feature: FEATURES.privateIn,
loose,

manipulateOptions(opts, parserOpts) {
parserOpts.plugins.push("privateIn");
},
});
return pluginPrivateIn(api, options);
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import syntaxPlugin from "@babel/plugin-syntax-private-property-in-object";
import { injectInitialization as injectConstructorInit } from "@babel/helper-create-class-features-plugin";
import {
enableFeature,
FEATURES,
injectInitialization as injectConstructorInit,
} from "@babel/helper-create-class-features-plugin";

export default function pluginPrivateIn({ types: t, template }) {
export default function pluginPrivateIn({ types: t, template }, options) {
const classWeakSets = new WeakMap();
const fieldsWeakSets = new WeakMap();

Expand Down Expand Up @@ -68,6 +72,9 @@ export default function pluginPrivateIn({ types: t, template }) {
return {
name: "proposal-private-property-in-object",
inherits: syntaxPlugin,
pre() {
enableFeature(this.file, FEATURES.privateIn, options.loose);
},
visitor: {
BinaryExpression(path) {
const { node } = path;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"targets": { "node": 10 },
"plugins": ["proposal-private-property-in-object", "syntax-class-properties"],
"throws": "Class fields are not enabled. If you want to only compile '#priv in obj' checks, you can either pass the `nativePrivateFields: true` option to @babel/plugin-proposal-private-property-in-object or you can set the top-level 'targets' option to something that natively supports private fields and methods."
"plugins": ["proposal-private-property-in-object", "syntax-class-properties"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var _xBrandCheck = new WeakSet();

class A {
#x = void _xBrandCheck.add(this);

test() {
_xBrandCheck.has(this);
}

}

0 comments on commit bf01056

Please sign in to comment.