diff --git a/Makefile b/Makefile index ee06da1a82af..50390d60c967 100644 --- a/Makefile +++ b/Makefile @@ -192,8 +192,8 @@ new-version-checklist: # @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" # @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" # @echo "!!!!!! !!!!!!" - # @echo "!!!!!! Write any message that should !!!!!!" - # @echo "!!!!!! block the release here !!!!!!" + # @echo "!!!!!! Update the minVersion of packages/babel-helpers/src/helpers/checkInRHS.js" + # @echo "!!!!!! !!!!!!" # @echo "!!!!!! !!!!!!" # @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" # @echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" diff --git a/packages/babel-helper-create-class-features-plugin/src/decorators.ts b/packages/babel-helper-create-class-features-plugin/src/decorators.ts index d2acfde94c61..4e0e4920bd10 100644 --- a/packages/babel-helper-create-class-features-plugin/src/decorators.ts +++ b/packages/babel-helper-create-class-features-plugin/src/decorators.ts @@ -142,17 +142,7 @@ function extractElementDescriptor( } function addDecorateHelper(file: File) { - try { - return file.addHelper("decorate"); - } catch (err) { - if (err.code === "BABEL_HELPER_UNKNOWN") { - err.message += - "\n '@babel/plugin-transform-decorators' in non-legacy mode" + - " requires '@babel/core' version ^7.0.2 and you appear to be using" + - " an older version."; - } - throw err; - } + return file.addHelper("decorate"); } type ClassElement = t.Class["body"]["body"][number]; diff --git a/packages/babel-helper-create-class-features-plugin/src/fields.ts b/packages/babel-helper-create-class-features-plugin/src/fields.ts index 5bfa6d2af402..749f5c0110dc 100644 --- a/packages/babel-helper-create-class-features-plugin/src/fields.ts +++ b/packages/babel-helper-create-class-features-plugin/src/fields.ts @@ -206,12 +206,21 @@ function unshadow( } } +export function buildCheckInRHS( + rhs: t.Expression, + file: File, + inRHSIsObject?: boolean, +) { + if (inRHSIsObject || !file.availableHelper?.("checkInRHS")) return rhs; + return t.callExpression(file.addHelper("checkInRHS"), [rhs]); +} + const privateInVisitor = privateNameVisitorFactory<{ classRef: t.Identifier; file: File; innerBinding?: t.Identifier; }>({ - BinaryExpression(path) { + BinaryExpression(path, { file }) { const { operator, left, right } = path.node; if (operator !== "in") return; if (!t.isPrivateName(left)) return; @@ -230,7 +239,10 @@ const privateInVisitor = privateNameVisitorFactory<{ if (privateFieldsAsProperties) { const { id } = privateNamesMap.get(name); path.replaceWith(template.expression.ast` - Object.prototype.hasOwnProperty.call(${right}, ${t.cloneNode(id)}) + Object.prototype.hasOwnProperty.call(${buildCheckInRHS( + right, + file, + )}, ${t.cloneNode(id)}) `); return; } @@ -238,11 +250,21 @@ const privateInVisitor = privateNameVisitorFactory<{ const { id, static: isStatic } = privateNamesMap.get(name); if (isStatic) { - path.replaceWith(template.expression.ast`${right} === ${this.classRef}`); + path.replaceWith( + template.expression.ast`${buildCheckInRHS( + right, + file, + )} === ${t.cloneNode(this.classRef)}`, + ); return; } - path.replaceWith(template.expression.ast`${t.cloneNode(id)}.has(${right})`); + path.replaceWith( + template.expression.ast`${t.cloneNode(id)}.has(${buildCheckInRHS( + right, + file, + )})`, + ); }, }); diff --git a/packages/babel-helper-create-class-features-plugin/src/index.ts b/packages/babel-helper-create-class-features-plugin/src/index.ts index 6705416de160..4a655f30ff1a 100644 --- a/packages/babel-helper-create-class-features-plugin/src/index.ts +++ b/packages/babel-helper-create-class-features-plugin/src/index.ts @@ -8,6 +8,7 @@ import { buildPrivateNamesMap, transformPrivateNamesUsage, buildFieldsInitNodes, + buildCheckInRHS, } from "./fields"; import type { PropPath } from "./fields"; import { buildDecoratedClass, hasDecorators } from "./decorators"; @@ -15,7 +16,7 @@ import { injectInitialization, extractComputedKeys } from "./misc"; import { enableFeature, FEATURES, isLoose, shouldTransform } from "./features"; import { assertFieldTransformed } from "./typescript"; -export { FEATURES, enableFeature, injectInitialization }; +export { FEATURES, enableFeature, injectInitialization, buildCheckInRHS }; declare const PACKAGE_JSON: { name: string; version: string }; diff --git a/packages/babel-helpers/src/helpers-generated.ts b/packages/babel-helpers/src/helpers-generated.ts index 17c1db2e87cb..c176a2f9f122 100644 --- a/packages/babel-helpers/src/helpers-generated.ts +++ b/packages/babel-helpers/src/helpers-generated.ts @@ -41,6 +41,10 @@ export default Object.freeze({ "7.0.0-beta.0", 'import OverloadYield from"OverloadYield";export default function _awaitAsyncGenerator(value){return new OverloadYield(value,0)}', ), + checkInRHS: helper( + "7.20.1", + 'export default function _checkInRHS(value){if(Object(value)!==value)throw TypeError("right-hand side of \'in\' should be an object, got "+(null!==value?typeof value:"null"));return value}', + ), jsx: helper( "7.0.0-beta.0", 'var REACT_ELEMENT_TYPE;export default function _createRawReactElement(type,props,key,children){REACT_ELEMENT_TYPE||(REACT_ELEMENT_TYPE="function"==typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103);var defaultProps=type&&type.defaultProps,childrenLength=arguments.length-3;if(props||0===childrenLength||(props={children:void 0}),1===childrenLength)props.children=children;else if(childrenLength>1){for(var childArray=new Array(childrenLength),i=0;i { } else if (version === "2021-12" || version === "2022-03") { return transformer2022_03(api, options, version); } else if (!process.env.BABEL_8_BREAKING) { + api.assertVersion("^7.0.2"); return createClassFeaturePlugin({ name: "proposal-decorators", diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js index 205896728741..c79b2b7601bc 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2021-12-classes--to-es2015/replacement-static-installed-on-correct-class/output.js @@ -8,8 +8,8 @@ new (_x = /*#__PURE__*/new WeakMap(), _m = /*#__PURE__*/new WeakSet(), (_temp = writable: true, value: void 0 }), babelHelpers.defineProperty(this, "x", void 0)), (() => { - hasX = o => _x.has(o); - hasM = o => _m.has(o); + hasX = o => _x.has(babelHelpers.checkInRHS(o)); + hasM = o => _m.has(babelHelpers.checkInRHS(o)); })(), _initClass(); } }, (() => { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement-static-installed-on-correct-class/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement-static-installed-on-correct-class/output.js index 25f93b046cdf..002c642fdb27 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement-static-installed-on-correct-class/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2022-03-classes--to-es2015/replacement-static-installed-on-correct-class/output.js @@ -8,8 +8,8 @@ new (_x = /*#__PURE__*/new WeakMap(), _m = /*#__PURE__*/new WeakSet(), (_temp = writable: true, value: void 0 }), babelHelpers.defineProperty(this, "x", void 0)), (() => { - hasX = o => _x.has(o); - hasM = o => _m.has(o); + hasX = o => _x.has(babelHelpers.checkInRHS(o)); + hasM = o => _m.has(babelHelpers.checkInRHS(o)); })(), _initClass(); } }, (() => { diff --git a/packages/babel-plugin-proposal-private-property-in-object/src/index.ts b/packages/babel-plugin-proposal-private-property-in-object/src/index.ts index c359eedcd193..91ff58cd94a7 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/src/index.ts +++ b/packages/babel-plugin-proposal-private-property-in-object/src/index.ts @@ -4,6 +4,7 @@ import { enableFeature, FEATURES, injectInitialization as injectConstructorInit, + buildCheckInRHS, } from "@babel/helper-create-class-features-plugin"; import annotateAsPure from "@babel/helper-annotate-as-pure"; import type * as t from "@babel/types"; @@ -119,8 +120,9 @@ export default declare((api, opt: Options) => { enableFeature(this.file, FEATURES.privateIn, loose); }, visitor: { - BinaryExpression(path) { + BinaryExpression(path, state) { const { node } = path; + const { file } = state; if (node.operator !== "in") return; if (!t.isPrivateName(node.left)) return; @@ -158,7 +160,10 @@ export default declare((api, opt: Options) => { } path.replaceWith( template.expression.ast` - ${t.cloneNode(outerClass.node.id)} === ${path.node.right} + ${t.cloneNode(outerClass.node.id)} === ${buildCheckInRHS( + node.right, + file, + )} `, ); } else { @@ -171,7 +176,10 @@ export default declare((api, opt: Options) => { ); path.replaceWith( - template.expression.ast`${id}.has(${path.node.right})`, + template.expression.ast`${id}.has(${buildCheckInRHS( + node.right, + file, + )})`, ); } } else { @@ -187,7 +195,10 @@ export default declare((api, opt: Options) => { ); path.replaceWith( - template.expression.ast`${id}.has(${path.node.right})`, + template.expression.ast`${id}.has(${buildCheckInRHS( + node.right, + file, + )})`, ); } }, diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/accessor/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/accessor/output.js index b784b4ea02e5..99af0664387d 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/accessor/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/accessor/output.js @@ -7,7 +7,7 @@ class Foo { }); } test(other) { - return Object.prototype.hasOwnProperty.call(other, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(other), _foo); } } function _get_foo() {} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/compiled-classes/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/compiled-classes/output.js index d0f50c534427..56723c59b197 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/compiled-classes/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/compiled-classes/output.js @@ -13,12 +13,12 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test() { - return Object.prototype.hasOwnProperty.call(this, _bar); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _bar); } }], [{ key: "test", value: function test() { - return Object.prototype.hasOwnProperty.call(Foo, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(Foo), _foo); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/field/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/field/output.js index 352d2b534f23..d16e99fa240c 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/field/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/field/output.js @@ -7,6 +7,6 @@ class Foo { }); } test(other) { - return Object.prototype.hasOwnProperty.call(other, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(other), _foo); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/method/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/method/output.js index 2e000bf1a9b0..90eb3d1a859f 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/method/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/method/output.js @@ -6,7 +6,7 @@ class Foo { }); } test(other) { - return Object.prototype.hasOwnProperty.call(other, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(other), _foo); } } function _foo2() {} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/nested-class-other-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/nested-class-other-redeclared/output.js index 6ded895fec68..4c9f46dd0ef5 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/nested-class-other-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/nested-class-other-redeclared/output.js @@ -21,11 +21,11 @@ class Foo { }); } test() { - Object.prototype.hasOwnProperty.call(this, _foo); - Object.prototype.hasOwnProperty.call(this, _bar2); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _foo); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _bar2); } } - Object.prototype.hasOwnProperty.call(this, _foo); - Object.prototype.hasOwnProperty.call(this, _bar); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _foo); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _bar); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/nested-class-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/nested-class-redeclared/output.js index d3073f234bf7..e066ef767fc0 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/nested-class-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/nested-class-redeclared/output.js @@ -16,9 +16,9 @@ class Foo { }); } test() { - Object.prototype.hasOwnProperty.call(this, _foo2); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _foo2); } } - Object.prototype.hasOwnProperty.call(this, _foo); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _foo); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/nested-class/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/nested-class/output.js index dcf02e546ead..406473c5fb9c 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/nested-class/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/nested-class/output.js @@ -9,9 +9,9 @@ class Foo { test() { class Nested { test() { - Object.prototype.hasOwnProperty.call(this, _foo); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _foo); } } - Object.prototype.hasOwnProperty.call(this, _foo); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _foo); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/rhs-not-object/exec.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/rhs-not-object/exec.js new file mode 100644 index 000000000000..fc8e80090694 --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/rhs-not-object/exec.js @@ -0,0 +1,31 @@ +expect(() => class { static #p = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => class { static #p = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => class { static #p = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => class { static #p = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => class { static #p = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => class { static #p = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => class { static #p = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); + +expect(() => class { static #p() {}; static q = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => class { static #p() {}; static q = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => class { static #p() {}; static q = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => class { static #p() {}; static q = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => class { static #p() {}; static q = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => class { static #p() {}; static q = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => class { static #p() {}; static q = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); + +expect(() => new class { #p = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => new class { #p = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => new class { #p = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => new class { #p = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => new class { #p = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => new class { #p = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => new class { #p = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); + +expect(() => new class { #p() {}; q = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => new class { #p() {}; q = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => new class { #p() {}; q = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => new class { #p() {}; q = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => new class { #p() {}; q = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => new class { #p() {}; q = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => new class { #p() {}; q = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/rhs-not-object/options.json b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/rhs-not-object/options.json new file mode 100644 index 000000000000..22b476c4bb57 --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/rhs-not-object/options.json @@ -0,0 +1,3 @@ +{ + "minNodeVersion": "12.0.0" +} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/static-accessor/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/static-accessor/output.js index 11ec1676f116..de80926eea95 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/static-accessor/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/static-accessor/output.js @@ -1,7 +1,7 @@ var _foo = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("foo"); class Foo { test(other) { - return Object.prototype.hasOwnProperty.call(other, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(other), _foo); } } function _get_foo() {} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/static-field/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/static-field/output.js index 86970d674978..78c397d3f887 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/static-field/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/static-field/output.js @@ -1,7 +1,7 @@ var _foo = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("foo"); class Foo { test(other) { - return Object.prototype.hasOwnProperty.call(other, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(other), _foo); } } Object.defineProperty(Foo, _foo, { diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/static-method/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/static-method/output.js index 71829bd804c2..a94d7e2df94c 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/static-method/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/assumption-privateFieldsAsProperties/static-method/output.js @@ -1,7 +1,7 @@ var _foo = /*#__PURE__*/babelHelpers.classPrivateFieldLooseKey("foo"); class Foo { test(other) { - return Object.prototype.hasOwnProperty.call(other, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(other), _foo); } } function _foo2() {} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/accessor/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/accessor/output.js index 853e6bd7062a..e77b8058492b 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/accessor/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/accessor/output.js @@ -12,7 +12,7 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test(other) { - return Object.prototype.hasOwnProperty.call(other, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(other), _foo); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/field/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/field/output.js index c2591821c193..f34fd44e153c 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/field/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/field/output.js @@ -12,7 +12,7 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test(other) { - return Object.prototype.hasOwnProperty.call(other, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(other), _foo); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/method/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/method/output.js index 8f150b89393c..d8ff2d463c4a 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/method/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/method/output.js @@ -11,7 +11,7 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test(other) { - return Object.prototype.hasOwnProperty.call(other, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(other), _foo); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/native-classes/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/native-classes/output.js index bc0b5d930fbd..596332f31431 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/native-classes/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/native-classes/output.js @@ -7,10 +7,10 @@ class Foo { }); } static test() { - return Foo === Foo; + return babelHelpers.checkInRHS(Foo) === Foo; } test() { - return _bar.has(this); + return _bar.has(babelHelpers.checkInRHS(this)); } } var _foo = { diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/nested-class-other-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/nested-class-other-redeclared/output.js index 63c8a088a85b..7992e14ef759 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/nested-class-other-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/nested-class-other-redeclared/output.js @@ -29,14 +29,14 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Nested, [{ key: "test", value: function test() { - Object.prototype.hasOwnProperty.call(this, _foo); - Object.prototype.hasOwnProperty.call(this, _bar2); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _foo); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _bar2); } }]); return Nested; }(); - Object.prototype.hasOwnProperty.call(this, _foo); - Object.prototype.hasOwnProperty.call(this, _bar); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _foo); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _bar); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/nested-class-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/nested-class-redeclared/output.js index 17b292e242a9..da5cf04f3c0d 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/nested-class-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/nested-class-redeclared/output.js @@ -24,12 +24,12 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Nested, [{ key: "test", value: function test() { - Object.prototype.hasOwnProperty.call(this, _foo2); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _foo2); } }]); return Nested; }(); - Object.prototype.hasOwnProperty.call(this, _foo); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _foo); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/nested-class/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/nested-class/output.js index af8cf8073cd4..ea0b82693e83 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/nested-class/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/nested-class/output.js @@ -19,12 +19,12 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Nested, [{ key: "test", value: function test() { - Object.prototype.hasOwnProperty.call(this, _foo); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _foo); } }]); return Nested; }(); - Object.prototype.hasOwnProperty.call(this, _foo); + Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(this), _foo); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/rhs-not-object/exec.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/rhs-not-object/exec.js new file mode 100644 index 000000000000..fc8e80090694 --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/rhs-not-object/exec.js @@ -0,0 +1,31 @@ +expect(() => class { static #p = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => class { static #p = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => class { static #p = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => class { static #p = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => class { static #p = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => class { static #p = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => class { static #p = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); + +expect(() => class { static #p() {}; static q = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => class { static #p() {}; static q = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => class { static #p() {}; static q = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => class { static #p() {}; static q = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => class { static #p() {}; static q = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => class { static #p() {}; static q = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => class { static #p() {}; static q = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); + +expect(() => new class { #p = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => new class { #p = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => new class { #p = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => new class { #p = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => new class { #p = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => new class { #p = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => new class { #p = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); + +expect(() => new class { #p() {}; q = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => new class { #p() {}; q = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => new class { #p() {}; q = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => new class { #p() {}; q = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => new class { #p() {}; q = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => new class { #p() {}; q = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => new class { #p() {}; q = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/rhs-not-object/options.json b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/rhs-not-object/options.json new file mode 100644 index 000000000000..22b476c4bb57 --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/rhs-not-object/options.json @@ -0,0 +1,3 @@ +{ + "minNodeVersion": "12.0.0" +} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-accessor/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-accessor/output.js index 4b3e093c8c94..c44e1f808ba8 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-accessor/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-accessor/output.js @@ -8,7 +8,7 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test(other) { - return Object.prototype.hasOwnProperty.call(other, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(other), _foo); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-field/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-field/output.js index be9098e07384..420281e8fc4f 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-field/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-field/output.js @@ -8,7 +8,7 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test(other) { - return Object.prototype.hasOwnProperty.call(other, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(other), _foo); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-method/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-method/output.js index 5ec524d065be..ca661fe7cdb3 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-method/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-method/output.js @@ -8,7 +8,7 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test(other) { - return Object.prototype.hasOwnProperty.call(other, _foo); + return Object.prototype.hasOwnProperty.call(babelHelpers.checkInRHS(other), _foo); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/output.js index 1ca900812373..ae4aa620ac05 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private-loose/static-shadow/output.js @@ -3,7 +3,7 @@ class Test { const _Test2 = 2; const func = () => { const _Test = 3; - return other === Test && _Test; + return babelHelpers.checkInRHS(other) === Test && _Test; }; return func() + _Test2; } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/accessor/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/accessor/output.js index 1a5a171e62ea..2ddcb76181b9 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/accessor/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/accessor/output.js @@ -12,7 +12,7 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test(other) { - return _foo.has(other); + return _foo.has(babelHelpers.checkInRHS(other)); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/field/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/field/output.js index 5c19f387b89f..a632933ac604 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/field/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/field/output.js @@ -12,7 +12,7 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test(other) { - return _foo.has(other); + return _foo.has(babelHelpers.checkInRHS(other)); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/method/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/method/output.js index 7d7f7a60aa0e..ff73b1d6e42c 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/method/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/method/output.js @@ -9,7 +9,7 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test(other) { - return _foo.has(other); + return _foo.has(babelHelpers.checkInRHS(other)); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/native-classes/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/native-classes/output.js index bc0b5d930fbd..596332f31431 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/native-classes/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/native-classes/output.js @@ -7,10 +7,10 @@ class Foo { }); } static test() { - return Foo === Foo; + return babelHelpers.checkInRHS(Foo) === Foo; } test() { - return _bar.has(this); + return _bar.has(babelHelpers.checkInRHS(this)); } } var _foo = { diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-other-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-other-redeclared/output.js index a93260ef0c89..e67fc1769a46 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-other-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-other-redeclared/output.js @@ -29,14 +29,14 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Nested, [{ key: "test", value: function test() { - _foo.has(this); - _bar2.has(this); + _foo.has(babelHelpers.checkInRHS(this)); + _bar2.has(babelHelpers.checkInRHS(this)); } }]); return Nested; }(); - _foo.has(this); - _bar.has(this); + _foo.has(babelHelpers.checkInRHS(this)); + _bar.has(babelHelpers.checkInRHS(this)); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-redeclared/output.js index ff76f6033e13..faacad85de43 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class-redeclared/output.js @@ -24,12 +24,12 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Nested, [{ key: "test", value: function test() { - _foo2.has(this); + _foo2.has(babelHelpers.checkInRHS(this)); } }]); return Nested; }(); - _foo.has(this); + _foo.has(babelHelpers.checkInRHS(this)); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class/output.js index e1eecdc3989f..d0bb08ff47f3 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/nested-class/output.js @@ -19,12 +19,12 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Nested, [{ key: "test", value: function test() { - _foo.has(this); + _foo.has(babelHelpers.checkInRHS(this)); } }]); return Nested; }(); - _foo.has(this); + _foo.has(babelHelpers.checkInRHS(this)); } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/rhs-not-object/exec.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/rhs-not-object/exec.js new file mode 100644 index 000000000000..fc8e80090694 --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/rhs-not-object/exec.js @@ -0,0 +1,31 @@ +expect(() => class { static #p = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => class { static #p = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => class { static #p = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => class { static #p = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => class { static #p = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => class { static #p = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => class { static #p = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); + +expect(() => class { static #p() {}; static q = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => class { static #p() {}; static q = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => class { static #p() {}; static q = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => class { static #p() {}; static q = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => class { static #p() {}; static q = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => class { static #p() {}; static q = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => class { static #p() {}; static q = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); + +expect(() => new class { #p = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => new class { #p = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => new class { #p = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => new class { #p = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => new class { #p = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => new class { #p = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => new class { #p = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); + +expect(() => new class { #p() {}; q = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => new class { #p() {}; q = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => new class { #p() {}; q = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => new class { #p() {}; q = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => new class { #p() {}; q = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => new class { #p() {}; q = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => new class { #p() {}; q = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/rhs-not-object/options.json b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/rhs-not-object/options.json new file mode 100644 index 000000000000..22b476c4bb57 --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/rhs-not-object/options.json @@ -0,0 +1,3 @@ +{ + "minNodeVersion": "12.0.0" +} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-accessor/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-accessor/output.js index 4cf51b3fe313..e1dddc3e9c71 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-accessor/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-accessor/output.js @@ -7,7 +7,7 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test(other) { - return other === Foo; + return babelHelpers.checkInRHS(other) === Foo; } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-field/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-field/output.js index d6c3295514d4..9c65a222b8b2 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-field/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-field/output.js @@ -7,7 +7,7 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test(other) { - return other === Foo; + return babelHelpers.checkInRHS(other) === Foo; } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-method/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-method/output.js index dfa898f00021..a373036cb199 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-method/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-method/output.js @@ -7,7 +7,7 @@ let Foo = /*#__PURE__*/function () { babelHelpers.createClass(Foo, [{ key: "test", value: function test(other) { - return other === Foo; + return babelHelpers.checkInRHS(other) === Foo; } }]); return Foo; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/output.js index 1ca900812373..ae4aa620ac05 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/private/static-shadow/output.js @@ -3,7 +3,7 @@ class Test { const _Test2 = 2; const func = () => { const _Test = 3; - return other === Test && _Test; + return babelHelpers.checkInRHS(other) === Test && _Test; }; return func() + _Test2; } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/accessor/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/accessor/output.js index 0ebe7e230972..1513b126cc8a 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/accessor/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/accessor/output.js @@ -5,6 +5,6 @@ class Foo { } get #foo() {} test(other) { - return _FooBrandCheck.has(other); + return _FooBrandCheck.has(babelHelpers.checkInRHS(other)); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/class-expression-in-default-param/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/class-expression-in-default-param/output.js index 47b5bf829a39..4512aecc3a6c 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/class-expression-in-default-param/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/class-expression-in-default-param/output.js @@ -3,7 +3,7 @@ return _fooBrandCheck = /*#__PURE__*/new WeakSet(), class { #foo = void _fooBrandCheck.add(this); test(other) { - return _fooBrandCheck.has(other); + return _fooBrandCheck.has(babelHelpers.checkInRHS(other)); } }; })()) => {}; diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/class-expression-instance/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/class-expression-instance/output.js index 211a179a6097..dc8de3baec41 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/class-expression-instance/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/class-expression-instance/output.js @@ -3,7 +3,7 @@ function fn() { return new (_privBrandCheck = /*#__PURE__*/new WeakSet(), class { #priv = void _privBrandCheck.add(this); method(obj) { - return _privBrandCheck.has(obj); + return _privBrandCheck.has(babelHelpers.checkInRHS(obj)); } })(); } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/class-expression-static/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/class-expression-static/output.js index ab557072c40d..e14a04f0b1c6 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/class-expression-static/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/class-expression-static/output.js @@ -3,7 +3,7 @@ function fn() { return new (_privBrandCheck = /*#__PURE__*/new WeakSet(), class { static #priv = void _privBrandCheck.add(this); method(obj) { - return _privBrandCheck.has(obj); + return _privBrandCheck.has(babelHelpers.checkInRHS(obj)); } })(); } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/field/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/field/output.js index 282aa9358f9b..449eea44e4b6 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/field/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/field/output.js @@ -2,6 +2,6 @@ var _fooBrandCheck = /*#__PURE__*/new WeakSet(); class Foo { #foo = (_fooBrandCheck.add(this), 1); test(other) { - return _fooBrandCheck.has(other); + return _fooBrandCheck.has(babelHelpers.checkInRHS(other)); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-instance/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-instance/output.js index 1a8571bbc811..6f7596336600 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-instance/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-instance/output.js @@ -4,10 +4,10 @@ var _xBrandCheck = /*#__PURE__*/new WeakSet(); var _yBrandCheck = /*#__PURE__*/new WeakSet(); class F { m() { - _FBrandCheck.has(this); - _xBrandCheck.has(this); - _yBrandCheck.has(this); - _FBrandCheck.has(this); + _FBrandCheck.has(babelHelpers.checkInRHS(this)); + _xBrandCheck.has(babelHelpers.checkInRHS(this)); + _yBrandCheck.has(babelHelpers.checkInRHS(this)); + _FBrandCheck.has(babelHelpers.checkInRHS(this)); } get #w() {} #x = (_FBrandCheck.add(this), (_xBrandCheck.add(this), 0)); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-static/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-static/output.js index c7d088022683..b754eb6f1441 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-static/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/half-constructed-static/output.js @@ -3,9 +3,9 @@ var _xBrandCheck = /*#__PURE__*/new WeakSet(); var _yBrandCheck = /*#__PURE__*/new WeakSet(); class F { static m() { - _xBrandCheck.has(this); - _yBrandCheck.has(this); - F === this; + _xBrandCheck.has(babelHelpers.checkInRHS(this)); + _yBrandCheck.has(babelHelpers.checkInRHS(this)); + F === babelHelpers.checkInRHS(this); } static #x = (_xBrandCheck.add(this), 0); static #y = (_temp = (() => { diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/method/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/method/output.js index 691a2c72d844..81c8571f0748 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/method/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/method/output.js @@ -5,6 +5,6 @@ class Foo { } #foo() {} test(other) { - return _FooBrandCheck.has(other); + return _FooBrandCheck.has(babelHelpers.checkInRHS(other)); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/multiple-checks/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/multiple-checks/output.js index 902bef31fb0c..8c7f1a2a7577 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/multiple-checks/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/multiple-checks/output.js @@ -4,9 +4,9 @@ class A { #x = (_ABrandCheck.add(this), void _xBrandCheck.add(this)); #m() {} test() { - _xBrandCheck.has(this); - _ABrandCheck.has(this); - _xBrandCheck.has(this); - _ABrandCheck.has(this); + _xBrandCheck.has(babelHelpers.checkInRHS(this)); + _ABrandCheck.has(babelHelpers.checkInRHS(this)); + _xBrandCheck.has(babelHelpers.checkInRHS(this)); + _ABrandCheck.has(babelHelpers.checkInRHS(this)); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-other-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-other-redeclared/output.js index 0ca6c142536e..fa17e8b056ad 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-other-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-other-redeclared/output.js @@ -8,11 +8,11 @@ class Foo { class Nested { #bar = (_barBrandCheck.add(this), 2); test() { - _fooBrandCheck.has(this); - _barBrandCheck.has(this); + _fooBrandCheck.has(babelHelpers.checkInRHS(this)); + _barBrandCheck.has(babelHelpers.checkInRHS(this)); } } - _fooBrandCheck.has(this); - _barBrandCheck2.has(this); + _fooBrandCheck.has(babelHelpers.checkInRHS(this)); + _barBrandCheck2.has(babelHelpers.checkInRHS(this)); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-redeclared/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-redeclared/output.js index 13789de0d07c..ca46a4626a2c 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-redeclared/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class-redeclared/output.js @@ -6,9 +6,9 @@ class Foo { class Nested { #foo = (_fooBrandCheck.add(this), 2); test() { - _fooBrandCheck.has(this); + _fooBrandCheck.has(babelHelpers.checkInRHS(this)); } } - _fooBrandCheck2.has(this); + _fooBrandCheck2.has(babelHelpers.checkInRHS(this)); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class/output.js index 276ad2b3dc91..7b10bc175396 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/nested-class/output.js @@ -4,9 +4,9 @@ class Foo { test() { class Nested { test() { - _fooBrandCheck.has(this); + _fooBrandCheck.has(babelHelpers.checkInRHS(this)); } } - _fooBrandCheck.has(this); + _fooBrandCheck.has(babelHelpers.checkInRHS(this)); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/rhs-not-object/exec.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/rhs-not-object/exec.js new file mode 100644 index 000000000000..fc8e80090694 --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/rhs-not-object/exec.js @@ -0,0 +1,31 @@ +expect(() => class { static #p = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => class { static #p = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => class { static #p = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => class { static #p = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => class { static #p = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => class { static #p = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => class { static #p = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); + +expect(() => class { static #p() {}; static q = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => class { static #p() {}; static q = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => class { static #p() {}; static q = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => class { static #p() {}; static q = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => class { static #p() {}; static q = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => class { static #p() {}; static q = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => class { static #p() {}; static q = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); + +expect(() => new class { #p = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => new class { #p = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => new class { #p = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => new class { #p = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => new class { #p = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => new class { #p = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => new class { #p = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); + +expect(() => new class { #p() {}; q = #p in 0 }).toThrowError(`right-hand side of 'in' should be an object, got number`); +expect(() => new class { #p() {}; q = #p in "" }).toThrowError(`right-hand side of 'in' should be an object, got string`); +expect(() => new class { #p() {}; q = #p in true }).toThrowError(`right-hand side of 'in' should be an object, got boolean`); +expect(() => new class { #p() {}; q = #p in void 0 }).toThrowError(`right-hand side of 'in' should be an object, got undefined`); +expect(() => new class { #p() {}; q = #p in null }).toThrowError(`right-hand side of 'in' should be an object, got null`); +expect(() => new class { #p() {}; q = #p in Symbol.iterator }).toThrowError(`right-hand side of 'in' should be an object, got symbol`); +expect(() => new class { #p() {}; q = #p in 0n }).toThrowError(`right-hand side of 'in' should be an object, got bigint`); diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/rhs-not-object/options.json b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/rhs-not-object/options.json new file mode 100644 index 000000000000..1655c55f42cc --- /dev/null +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/rhs-not-object/options.json @@ -0,0 +1,3 @@ +{ + "minNodeVersion": "14.0.0" +} diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-accessor/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-accessor/output.js index 4523533658f3..3dda06a5c5b1 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-accessor/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-accessor/output.js @@ -1,6 +1,6 @@ class Foo { static get #foo() {} test(other) { - return Foo === other; + return Foo === babelHelpers.checkInRHS(other); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-field/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-field/output.js index 3951619cf7f4..2a8c5cbd5242 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-field/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-field/output.js @@ -2,6 +2,6 @@ var _fooBrandCheck = /*#__PURE__*/new WeakSet(); class Foo { static #foo = (_fooBrandCheck.add(this), 1); test(other) { - return _fooBrandCheck.has(other); + return _fooBrandCheck.has(babelHelpers.checkInRHS(other)); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-method/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-method/output.js index b2036b980999..97ce37327d2b 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-method/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-method/output.js @@ -1,6 +1,6 @@ class Foo { static #foo() {} test(other) { - return Foo === other; + return Foo === babelHelpers.checkInRHS(other); } } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/output.js index 1ca900812373..ae4aa620ac05 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadow/output.js @@ -3,7 +3,7 @@ class Test { const _Test2 = 2; const func = () => { const _Test = 3; - return other === Test && _Test; + return babelHelpers.checkInRHS(other) === Test && _Test; }; return func() + _Test2; } diff --git a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadowed-binding/output.js b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadowed-binding/output.js index 8ef264ad2df3..6aef183b2b97 100644 --- a/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadowed-binding/output.js +++ b/packages/babel-plugin-proposal-private-property-in-object/test/fixtures/to-native-fields/static-shadowed-binding/output.js @@ -3,7 +3,7 @@ class A { static #foo = void _fooBrandCheck.add(this); test() { let A = function fn(A) { - return _fooBrandCheck.has(A); + return _fooBrandCheck.has(babelHelpers.checkInRHS(A)); }; } } diff --git a/packages/babel-preset-env/test/fixtures/preset-options-babel-7/deno-1_0/output.js b/packages/babel-preset-env/test/fixtures/preset-options-babel-7/deno-1_0/output.js index 7145fbed83c1..57c67758beb9 100644 --- a/packages/babel-preset-env/test/fixtures/preset-options-babel-7/deno-1_0/output.js +++ b/packages/babel-preset-env/test/fixtures/preset-options-babel-7/deno-1_0/output.js @@ -6,5 +6,5 @@ var _selfBrandCheck = /*#__PURE__*/new WeakSet(); // The class declaration and the static private property should not be transpiled class C { static #self = (_selfBrandCheck.add(this), C); - static #_ = C.#self ?? (C.#self = _selfBrandCheck.has(C === null || C === void 0 ? void 0 : C.#self)); + static #_ = C.#self ?? (C.#self = _selfBrandCheck.has(babelHelpers.checkInRHS(C === null || C === void 0 ? void 0 : C.#self))); } diff --git a/packages/babel-preset-env/test/fixtures/preset-options/deno-1_0/output.js b/packages/babel-preset-env/test/fixtures/preset-options/deno-1_0/output.js index e68220a425b4..27cb93f987cc 100644 --- a/packages/babel-preset-env/test/fixtures/preset-options/deno-1_0/output.js +++ b/packages/babel-preset-env/test/fixtures/preset-options/deno-1_0/output.js @@ -6,5 +6,5 @@ var _selfBrandCheck = /*#__PURE__*/new WeakSet(); // The class declaration and the static private property should not be transpiled class C { static #self = (_selfBrandCheck.add(this), C); - static #_ = C.#self ?? (C.#self = _selfBrandCheck.has(C?.#self)); + static #_ = C.#self ?? (C.#self = _selfBrandCheck.has(babelHelpers.checkInRHS(C?.#self))); } diff --git a/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-chrome-90/output.js b/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-chrome-90/output.js index 29c094f4d751..1e330ea914f7 100644 --- a/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-chrome-90/output.js +++ b/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-chrome-90/output.js @@ -1,5 +1,5 @@ var _fooBrandCheck = /*#__PURE__*/new WeakSet(); class A { #foo = void _fooBrandCheck.add(this); - static #_ = register(A, _fooBrandCheck.has(A)); + static #_ = register(A, _fooBrandCheck.has(babelHelpers.checkInRHS(A))); } diff --git a/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-firefox-70/output.js b/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-firefox-70/output.js index 94782590fd19..46c391672cdc 100644 --- a/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-firefox-70/output.js +++ b/packages/babel-preset-env/test/fixtures/shipped-proposals/new-class-features-firefox-70/output.js @@ -7,4 +7,4 @@ class A { }); } } -register(A, _foo.has(A)); +register(A, _foo.has(babelHelpers.checkInRHS(A))); diff --git a/packages/babel-runtime-corejs2/package.json b/packages/babel-runtime-corejs2/package.json index 1e9b28e41640..1125f427adcb 100644 --- a/packages/babel-runtime-corejs2/package.json +++ b/packages/babel-runtime-corejs2/package.json @@ -81,6 +81,15 @@ "./helpers/awaitAsyncGenerator.js" ], "./helpers/esm/awaitAsyncGenerator": "./helpers/esm/awaitAsyncGenerator.js", + "./helpers/checkInRHS": [ + { + "node": "./helpers/checkInRHS.js", + "import": "./helpers/esm/checkInRHS.js", + "default": "./helpers/checkInRHS.js" + }, + "./helpers/checkInRHS.js" + ], + "./helpers/esm/checkInRHS": "./helpers/esm/checkInRHS.js", "./helpers/jsx": [ { "node": "./helpers/jsx.js", diff --git a/packages/babel-runtime-corejs3/package.json b/packages/babel-runtime-corejs3/package.json index 1f396fb8f796..53dc26f87b45 100644 --- a/packages/babel-runtime-corejs3/package.json +++ b/packages/babel-runtime-corejs3/package.json @@ -80,6 +80,15 @@ "./helpers/awaitAsyncGenerator.js" ], "./helpers/esm/awaitAsyncGenerator": "./helpers/esm/awaitAsyncGenerator.js", + "./helpers/checkInRHS": [ + { + "node": "./helpers/checkInRHS.js", + "import": "./helpers/esm/checkInRHS.js", + "default": "./helpers/checkInRHS.js" + }, + "./helpers/checkInRHS.js" + ], + "./helpers/esm/checkInRHS": "./helpers/esm/checkInRHS.js", "./helpers/jsx": [ { "node": "./helpers/jsx.js", diff --git a/packages/babel-runtime/package.json b/packages/babel-runtime/package.json index 0b2226d1d004..c98104256edb 100644 --- a/packages/babel-runtime/package.json +++ b/packages/babel-runtime/package.json @@ -80,6 +80,15 @@ "./helpers/awaitAsyncGenerator.js" ], "./helpers/esm/awaitAsyncGenerator": "./helpers/esm/awaitAsyncGenerator.js", + "./helpers/checkInRHS": [ + { + "node": "./helpers/checkInRHS.js", + "import": "./helpers/esm/checkInRHS.js", + "default": "./helpers/checkInRHS.js" + }, + "./helpers/checkInRHS.js" + ], + "./helpers/esm/checkInRHS": "./helpers/esm/checkInRHS.js", "./helpers/jsx": [ { "node": "./helpers/jsx.js",