-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb26610
commit bf01056
Showing
5 changed files
with
27 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 6 additions & 25 deletions
31
packages/babel-plugin-proposal-private-property-in-object/src/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
...e-property-in-object/test/fixtures/to-native-fields-based-on-targets/node-10/options.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
} |
10 changes: 10 additions & 0 deletions
10
...vate-property-in-object/test/fixtures/to-native-fields-based-on-targets/node-10/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |