From d3bed4d3feb32a39361ea97da173dfa9582ea7c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 3 Feb 2023 15:38:28 +0100 Subject: [PATCH] Add `.has` method to `context.access` --- .../babel-helpers/src/helpers-generated.ts | 4 +- .../src/helpers/applyDecs2301.js | 51 ++++++++----- .../src/transformer-2023-01.ts | 73 ++++++++++--------- .../private/exec.js | 4 + .../private/output.js | 4 +- .../public/exec.js | 6 ++ .../static-private/exec.js | 4 + .../static-private/output.js | 4 +- .../static-public/exec.js | 6 ++ .../2023-01-accessors/private/output.js | 4 +- .../static-private/output.js | 4 +- .../super-in-private-accessor/output.js | 2 +- .../super-in-private-method/output.js | 2 +- .../2023-01-fields--to-es2015/private/exec.js | 4 + .../private/output.js | 4 +- .../2023-01-fields--to-es2015/public/exec.js | 6 ++ .../static-private/exec.js | 4 + .../static-private/output.js | 4 +- .../static-public/exec.js | 6 ++ .../fixtures/2023-01-fields/private/output.js | 4 +- .../2023-01-fields/static-private/output.js | 4 +- .../private/exec.js | 4 + .../private/output.js | 2 +- .../2023-01-getters--to-es2015/public/exec.js | 6 ++ .../static-private/exec.js | 4 + .../static-private/output.js | 2 +- .../static-public/exec.js | 6 ++ .../private/exec.js | 8 ++ .../private/output.js | 4 +- .../public/exec.js | 12 +++ .../static-private/exec.js | 8 ++ .../static-private/output.js | 4 +- .../static-public/exec.js | 12 +++ .../private/output.js | 4 +- .../static-private/output.js | 4 +- .../2023-01-getters/private/output.js | 2 +- .../2023-01-getters/static-private/output.js | 2 +- .../private-with-initializers/exec.js | 4 + .../private/output.js | 2 +- .../public-with-initializers/exec.js | 6 ++ .../static-private-with-initializers/exec.js | 4 + .../static-private/output.js | 2 +- .../static-public-with-initializers/exec.js | 6 ++ .../2023-01-methods/private/output.js | 2 +- .../2023-01-methods/static-private/output.js | 2 +- .../2023-01-misc/all-decorators/output.js | 10 +-- .../super-in-private-accessor/output.js | 2 +- .../super-in-private-method/output.js | 2 +- .../private/exec.js | 4 + .../private/output.js | 2 +- .../2023-01-setters--to-es2015/public/exec.js | 6 ++ .../static-private/exec.js | 4 + .../static-private/output.js | 2 +- .../static-public/exec.js | 5 ++ .../2023-01-setters/private/output.js | 2 +- .../2023-01-setters/static-private/output.js | 2 +- 56 files changed, 259 insertions(+), 98 deletions(-) diff --git a/packages/babel-helpers/src/helpers-generated.ts b/packages/babel-helpers/src/helpers-generated.ts index 37537bdc25ac..42fe5fc81e96 100644 --- a/packages/babel-helpers/src/helpers-generated.ts +++ b/packages/babel-helpers/src/helpers-generated.ts @@ -30,12 +30,12 @@ export default Object.freeze({ 'function applyDecs2203Factory(){function createAddInitializerMethod(initializers,decoratorFinishedRef){return function(initializer){!function(decoratorFinishedRef,fnName){if(decoratorFinishedRef.v)throw new Error("attempted to call "+fnName+" after decoration was finished")}(decoratorFinishedRef,"addInitializer"),assertCallable(initializer,"An initializer"),initializers.push(initializer)}}function memberDec(dec,name,desc,initializers,kind,isStatic,isPrivate,value){var kindStr;switch(kind){case 1:kindStr="accessor";break;case 2:kindStr="method";break;case 3:kindStr="getter";break;case 4:kindStr="setter";break;default:kindStr="field"}var get,set,ctx={kind:kindStr,name:isPrivate?"#"+name:name,static:isStatic,private:isPrivate},decoratorFinishedRef={v:!1};0!==kind&&(ctx.addInitializer=createAddInitializerMethod(initializers,decoratorFinishedRef)),0===kind?isPrivate?(get=desc.get,set=desc.set):(get=function(){return this[name]},set=function(v){this[name]=v}):2===kind?get=function(){return desc.value}:(1!==kind&&3!==kind||(get=function(){return desc.get.call(this)}),1!==kind&&4!==kind||(set=function(v){desc.set.call(this,v)})),ctx.access=get&&set?{get:get,set:set}:get?{get:get}:{set:set};try{return dec(value,ctx)}finally{decoratorFinishedRef.v=!0}}function assertCallable(fn,hint){if("function"!=typeof fn)throw new TypeError(hint+" must be a function")}function assertValidReturnValue(kind,value){var type=typeof value;if(1===kind){if("object"!==type||null===value)throw new TypeError("accessor decorators must return an object with get, set, or init properties or void 0");void 0!==value.get&&assertCallable(value.get,"accessor.get"),void 0!==value.set&&assertCallable(value.set,"accessor.set"),void 0!==value.init&&assertCallable(value.init,"accessor.init")}else if("function"!==type){var hint;throw hint=0===kind?"field":10===kind?"class":"method",new TypeError(hint+" decorators must return a function or void 0")}}function applyMemberDec(ret,base,decInfo,name,kind,isStatic,isPrivate,initializers){var desc,init,value,newValue,get,set,decs=decInfo[0];if(isPrivate?desc=0===kind||1===kind?{get:decInfo[3],set:decInfo[4]}:3===kind?{get:decInfo[3]}:4===kind?{set:decInfo[3]}:{value:decInfo[3]}:0!==kind&&(desc=Object.getOwnPropertyDescriptor(base,name)),1===kind?value={get:desc.get,set:desc.set}:2===kind?value=desc.value:3===kind?value=desc.get:4===kind&&(value=desc.set),"function"==typeof decs)void 0!==(newValue=memberDec(decs,name,desc,initializers,kind,isStatic,isPrivate,value))&&(assertValidReturnValue(kind,newValue),0===kind?init=newValue:1===kind?(init=newValue.init,get=newValue.get||value.get,set=newValue.set||value.set,value={get:get,set:set}):value=newValue);else for(var i=decs.length-1;i>=0;i--){var newInit;if(void 0!==(newValue=memberDec(decs[i],name,desc,initializers,kind,isStatic,isPrivate,value)))assertValidReturnValue(kind,newValue),0===kind?newInit=newValue:1===kind?(newInit=newValue.init,get=newValue.get||value.get,set=newValue.set||value.set,value={get:get,set:set}):value=newValue,void 0!==newInit&&(void 0===init?init=newInit:"function"==typeof init?init=[init,newInit]:init.push(newInit))}if(0===kind||1===kind){if(void 0===init)init=function(instance,init){return init};else if("function"!=typeof init){var ownInitializers=init;init=function(instance,init){for(var value=init,i=0;i3,isStatic=kind>=5;if(isStatic?(base=Class,0!=(kind-=5)&&(initializers=staticInitializers=staticInitializers||[])):(base=Class.prototype,0!==kind&&(initializers=protoInitializers=protoInitializers||[])),0!==kind&&!isPrivate){var existingNonFields=isStatic?existingStaticNonFields:existingProtoNonFields,existingKind=existingNonFields.get(name)||0;if(!0===existingKind||3===existingKind&&4!==kind||4===existingKind&&3!==kind)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+name);!existingKind&&kind>2?existingNonFields.set(name,kind):existingNonFields.set(name,!0)}applyMemberDec(ret,base,decInfo,name,kind,isStatic,isPrivate,initializers)}}pushInitializers(ret,protoInitializers),pushInitializers(ret,staticInitializers)}(ret,targetClass,memberDecs),function(ret,targetClass,classDecs){if(classDecs.length>0){for(var initializers=[],newClass=targetClass,name=targetClass.name,i=classDecs.length-1;i>=0;i--){var decoratorFinishedRef={v:!1};try{var nextNewClass=classDecs[i](newClass,{kind:"class",name:name,addInitializer:createAddInitializerMethod(initializers,decoratorFinishedRef)})}finally{decoratorFinishedRef.v=!0}void 0!==nextNewClass&&(assertValidReturnValue(10,nextNewClass),newClass=nextNewClass)}ret.push(newClass,(function(){for(var i=0;i=0;i--){var newInit;if(void 0!==(newValue=memberDec(decs[i],name,desc,initializers,kind,isStatic,isPrivate,value)))assertValidReturnValue(kind,newValue),0===kind?newInit=newValue:1===kind?(newInit=newValue.init,get=newValue.get||value.get,set=newValue.set||value.set,value={get:get,set:set}):value=newValue,void 0!==newInit&&(void 0===init?init=newInit:"function"==typeof init?init=[init,newInit]:init.push(newInit))}if(0===kind||1===kind){if(void 0===init)init=function(instance,init){return init};else if("function"!=typeof init){var ownInitializers=init;init=function(instance,init){for(var value=init,i=0;i3,isStatic=kind>=5;if(isStatic?(base=Class,0!==(kind-=5)&&(initializers=staticInitializers=staticInitializers||[])):(base=Class.prototype,0!==kind&&(initializers=protoInitializers=protoInitializers||[])),0!==kind&&!isPrivate){var existingNonFields=isStatic?existingStaticNonFields:existingProtoNonFields,existingKind=existingNonFields.get(name)||0;if(!0===existingKind||3===existingKind&&4!==kind||4===existingKind&&3!==kind)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+name);!existingKind&&kind>2?existingNonFields.set(name,kind):existingNonFields.set(name,!0)}applyMemberDec(ret,base,decInfo,name,kind,isStatic,isPrivate,initializers)}}return pushInitializers(ret,protoInitializers),pushInitializers(ret,staticInitializers),ret}function pushInitializers(ret,initializers){initializers&&ret.push((function(instance){for(var i=0;i0){for(var initializers=[],newClass=targetClass,name=targetClass.name,i=classDecs.length-1;i>=0;i--){var decoratorFinishedRef={v:!1};try{var nextNewClass=classDecs[i](newClass,{kind:"class",name:name,addInitializer:createAddInitializerMethod(initializers,decoratorFinishedRef)})}finally{decoratorFinishedRef.v=!0}void 0!==nextNewClass&&(assertValidReturnValue(10,nextNewClass),newClass=nextNewClass)}return[newClass,function(){for(var i=0;i=0;i--){var newInit;if(void 0!==(newValue=memberDec(decs[i],name,desc,initializers,kind,isStatic,isPrivate,value)))assertValidReturnValue(kind,newValue),0===kind?newInit=newValue:1===kind?(newInit=newValue.init,get=newValue.get||value.get,set=newValue.set||value.set,value={get:get,set:set}):value=newValue,void 0!==newInit&&(void 0===init?init=newInit:"function"==typeof init?init=[init,newInit]:init.push(newInit))}if(0===kind||1===kind){if(void 0===init)init=function(instance,init){return init};else if("function"!=typeof init){var ownInitializers=init;init=function(instance,init){for(var value=init,i=0;i3,isStatic=kind>=5;if(isStatic?(base=Class,0!==(kind-=5)&&(initializers=staticInitializers=staticInitializers||[])):(base=Class.prototype,0!==kind&&(initializers=protoInitializers=protoInitializers||[])),0!==kind&&!isPrivate){var existingNonFields=isStatic?existingStaticNonFields:existingProtoNonFields,existingKind=existingNonFields.get(name)||0;if(!0===existingKind||3===existingKind&&4!==kind||4===existingKind&&3!==kind)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+name);!existingKind&&kind>2?existingNonFields.set(name,kind):existingNonFields.set(name,!0)}applyMemberDec(ret,base,decInfo,name,kind,isStatic,isPrivate,initializers)}}return pushInitializers(ret,protoInitializers),pushInitializers(ret,staticInitializers),ret}function pushInitializers(ret,initializers){initializers&&ret.push((function(instance){for(var i=0;i0){for(var initializers=[],newClass=targetClass,name=targetClass.name,i=classDecs.length-1;i>=0;i--){var decoratorFinishedRef={v:!1};try{var nextNewClass=classDecs[i](newClass,{kind:"class",name:name,addInitializer:createAddInitializerMethod(initializers,decoratorFinishedRef)})}finally{decoratorFinishedRef.v=!0}void 0!==nextNewClass&&(assertValidReturnValue(10,nextNewClass),newClass=nextNewClass)}return[newClass,function(){for(var i=0;i=0;i--){var newInit;if(void 0!==(newValue=memberDec(decs[i],name,desc,initializers,kind,isStatic,isPrivate,value,has)))assertValidReturnValue(kind,newValue),0===kind?newInit=newValue:1===kind?(newInit=newValue.init,get=newValue.get||value.get,set=newValue.set||value.set,value={get:get,set:set}):value=newValue,void 0!==newInit&&(void 0===init?init=newInit:"function"==typeof init?init=[init,newInit]:init.push(newInit))}if(0===kind||1===kind){if(void 0===init)init=function(instance,init){return init};else if("function"!=typeof init){var ownInitializers=init;init=function(instance,init){for(var value=init,i=0;i3,isStatic=kind>=5;if(isStatic?(base=Class,0!==(kind-=5)&&(initializers=staticInitializers=staticInitializers||[])):(base=Class.prototype,0!==kind&&(initializers=protoInitializers=protoInitializers||[])),0!==kind&&!isPrivate){var existingNonFields=isStatic?existingStaticNonFields:existingProtoNonFields,existingKind=existingNonFields.get(name)||0;if(!0===existingKind||3===existingKind&&4!==kind||4===existingKind&&3!==kind)throw new Error("Attempted to decorate a public method/accessor that has the same name as a previously decorated public method/accessor. This is not currently supported by the decorators plugin. Property name was: "+name);!existingKind&&kind>2?existingNonFields.set(name,kind):existingNonFields.set(name,!0)}applyMemberDec(ret,base,decInfo,name,kind,isStatic,isPrivate,initializers)}}return pushInitializers(ret,protoInitializers),pushInitializers(ret,staticInitializers),ret}function pushInitializers(ret,initializers){initializers&&ret.push((function(instance){for(var i=0;i0){for(var initializers=[],newClass=targetClass,name=targetClass.name,i=classDecs.length-1;i>=0;i--){var decoratorFinishedRef={v:!1};try{var nextNewClass=classDecs[i](newClass,{kind:"class",name:name,addInitializer:createAddInitializerMethod(initializers,decoratorFinishedRef)})}finally{decoratorFinishedRef.v=!0}void 0!==nextNewClass&&(assertValidReturnValue(10,nextNewClass),newClass=nextNewClass)}return[newClass,function(){for(var i=0;i ${t.cloneNode(targetKey)} in _ + ` as t.ArrowFunctionExpression), + ].filter(Boolean); } const FIELD = 0; @@ -299,7 +292,9 @@ interface DecoratorInfo { // The name of the decorator name: t.StringLiteral | t.Expression; - privateMethods: t.FunctionExpression | t.FunctionExpression[] | undefined; + privateMethods: + | (t.FunctionExpression | t.ArrowFunctionExpression)[] + | undefined; // The names of local variables that will be used/returned from the decoration locals: t.Identifier | t.Identifier[] | undefined; @@ -496,6 +491,8 @@ function transformClass( const classDecorators = path.node.decorators; let hasElementDecorators = false; + const injectHasChecks = version === "2023-01"; + const generateClassPrivateUid = createLazyPrivateUidGeneratorForClass(path); // Iterate over the class to see if we need to decorate it, and also to @@ -623,7 +620,9 @@ function transformClass( if (hasDecorators) { let locals: t.Identifier | t.Identifier[]; - let privateMethods: t.FunctionExpression | t.FunctionExpression[]; + let privateMethods: Array< + t.FunctionExpression | t.ArrowFunctionExpression + >; if (kind === ACCESSOR) { const { value } = element.node as t.ClassAccessorProperty; @@ -646,7 +645,7 @@ function transformClass( const [newPath] = element.replaceWith(newField); if (isPrivate) { - privateMethods = extractProxyAccessorsFor(newId); + privateMethods = extractProxyAccessorsFor(newId, injectHasChecks); const getId = newPath.scope.parent.generateDeclaredUidIdentifier( `get_${name}`, @@ -680,7 +679,7 @@ function transformClass( locals = initId; if (isPrivate) { - privateMethods = extractProxyAccessorsFor(key); + privateMethods = extractProxyAccessorsFor(key, injectHasChecks); } } else if (isPrivate) { locals = element.scope.parent.generateDeclaredUidIdentifier( @@ -704,12 +703,18 @@ function transformClass( async: isAsync, } = element.node as t.ClassPrivateMethod; - privateMethods = t.functionExpression( - undefined, - params.filter(isNotTsParameter), - body, - isAsync, - ); + privateMethods = [ + t.functionExpression( + undefined, + params.filter(isNotTsParameter), + body, + isAsync, + ), + injectHasChecks && + (template.expression.ast` + _ => ${t.cloneNode(key)} in _ + ` as t.ArrowFunctionExpression), + ].filter(Boolean); if (kind === GETTER || kind === SETTER) { movePrivateAccessor( diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/private/exec.js index 18348ee2966a..5aeee8a405dd 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/private/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/private/exec.js @@ -31,6 +31,10 @@ let foo = new Foo(); const aContext = foo['#aContext']; const bContext = foo['#bContext']; +expect(aContext.access.has(foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(foo))).toBe(false); + expect(aContext.access.get(foo)).toBe(2); aContext.access.set(foo, 123); expect(aContext.access.get(foo)).toBe(125); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/private/output.js index 1725ae1e8e66..2954fc4908ce 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/private/output.js @@ -40,8 +40,8 @@ function _get_b2() { return babelHelpers.classPrivateFieldGet(this, _A); }, function (value) { babelHelpers.classPrivateFieldSet(this, _A, value); -}], [dec, 1, "b", function () { +}, _ => _A.has(babelHelpers.checkInRHS(_))], [dec, 1, "b", function () { return babelHelpers.classPrivateFieldGet(this, _B); }, function (value) { babelHelpers.classPrivateFieldSet(this, _B, value); -}]], []).e; +}, _ => _B.has(babelHelpers.checkInRHS(_))]], []).e; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/public/exec.js index 53a51e64c02c..834c6deaecfe 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/public/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/public/exec.js @@ -35,6 +35,12 @@ const aContext = foo['aContext']; const bContext = foo['bContext']; const cContext = foo['cContext']; +expect(aContext.access.has(foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(foo))).toBe(true); +expect(aContext.access.has({ a: 1 })).toBe(true); +expect(aContext.access.has(Object.create({ a: 1 }))).toBe(true); + expect(foo.a).toBe(2); expect(aContext.access.get(foo)).toBe(2); foo.a = 123; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/static-private/exec.js index 96afe6ef6bc5..8f0c19a32571 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/static-private/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/static-private/exec.js @@ -29,6 +29,10 @@ class Foo { const aContext = Foo['#aContext']; const bContext = Foo['#bContext']; +expect(aContext.access.has(Foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(Foo))).toBe(false); + expect(aContext.access.get(Foo)).toBe(2); aContext.access.set(Foo, 123); expect(aContext.access.get(Foo)).toBe(125); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/static-private/output.js index 50f1f16799bf..dd58145e92de 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/static-private/output.js @@ -31,11 +31,11 @@ function _get_b2() { return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A); }, function (value) { babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _A, value); - }], [dec, 6, "b", function () { + }, _ => babelHelpers.checkInRHS(_) === Foo], [dec, 6, "b", function () { return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _B); }, function (value) { babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _B, value); - }]], []).e; + }, _ => babelHelpers.checkInRHS(_) === Foo]], []).e; _initStatic(Foo); })(); var _A = { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/static-public/exec.js index ead431c6c26e..402618d18490 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/static-public/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors--to-es2015/static-public/exec.js @@ -33,6 +33,12 @@ const aContext = Foo['aContext']; const bContext = Foo['bContext']; const cContext = Foo['cContext']; +expect(aContext.access.has(Foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(Foo))).toBe(true); +expect(aContext.access.has({ a: 1 })).toBe(true); +expect(aContext.access.has(Object.create({ a: 1 }))).toBe(true); + expect(Foo.a).toBe(2); expect(aContext.access.get(Foo)).toBe(2); Foo.a = 123; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors/private/output.js index 396e7086173f..b3e40dd0c4c5 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors/private/output.js @@ -6,11 +6,11 @@ class Foo { return this.#A; }, function (value) { this.#A = value; - }], [dec, 1, "b", function () { + }, _ => #A in _], [dec, 1, "b", function () { return this.#B; }, function (value) { this.#B = value; - }]], []).e; + }, _ => #B in _]], []).e; } #A = (_initProto(this), _init_a(this)); set #a(v) { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors/static-private/output.js index 120e64a5676d..5176e83bdef5 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-accessors/static-private/output.js @@ -6,11 +6,11 @@ class Foo { return this.#A; }, function (value) { this.#A = value; - }], [dec, 6, "b", function () { + }, _ => #A in _], [dec, 6, "b", function () { return this.#B; }, function (value) { this.#B = value; - }]], []).e; + }, _ => #B in _]], []).e; _initStatic(this); } static #A = _init_a(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-assumption-constantSuper/super-in-private-accessor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-assumption-constantSuper/super-in-private-accessor/output.js index bf289e960f96..389e1c65cd11 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-assumption-constantSuper/super-in-private-accessor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-assumption-constantSuper/super-in-private-accessor/output.js @@ -4,7 +4,7 @@ class Foo extends Bar { static { [_call_x, _initProto] = babelHelpers.applyDecs2301(this, [[dec, 3, "x", function () { return Bar.prototype.foo.call(this); - }]], []).e; + }, _ => #x in _]], []).e; } constructor(...args) { super(...args); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-assumption-constantSuper/super-in-private-method/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-assumption-constantSuper/super-in-private-method/output.js index 77e3d9f9047a..3148ecfd31fc 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-assumption-constantSuper/super-in-private-method/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-assumption-constantSuper/super-in-private-method/output.js @@ -4,7 +4,7 @@ class Foo extends Bar { static { [_call_x, _initProto] = babelHelpers.applyDecs2301(this, [[dec, 2, "x", function () { return Bar.prototype.foo.call(this); - }]], []).e; + }, _ => #x in _]], []).e; } constructor(...args) { super(...args); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/private/exec.js index 1cf676c76448..ce086fcf678a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/private/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/private/exec.js @@ -18,6 +18,10 @@ let foo = new Foo(); const aContext = foo['#aContext']; const bContext = foo['#bContext']; +expect(aContext.access.has(foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(foo))).toBe(false); + expect(aContext.access.get(foo)).toBe(2); aContext.access.set(foo, 123); expect(aContext.access.get(foo)).toBe(123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/private/output.js index dedad215c3db..839036d3d834 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/private/output.js @@ -18,8 +18,8 @@ class Foo { return babelHelpers.classPrivateFieldGet(this, _a); }, function (value) { babelHelpers.classPrivateFieldSet(this, _a, value); -}], [dec, 0, "b", function () { +}, _ => _a.has(babelHelpers.checkInRHS(_))], [dec, 0, "b", function () { return babelHelpers.classPrivateFieldGet(this, _b); }, function (value) { babelHelpers.classPrivateFieldSet(this, _b, value); -}]], []).e; +}, _ => _b.has(babelHelpers.checkInRHS(_))]], []).e; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/public/exec.js index 9654b4c94bdc..df182db7ac21 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/public/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/public/exec.js @@ -22,6 +22,12 @@ const aContext = foo['aContext']; const bContext = foo['bContext']; const cContext = foo['cContext']; +expect(aContext.access.has(foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(foo))).toBe(true); +expect(aContext.access.has({ a: 1 })).toBe(true); +expect(aContext.access.has(Object.create({ a: 1 }))).toBe(true); + expect(foo.a).toBe(2); expect(aContext.access.get(foo)).toBe(2); foo.a = 123; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/static-private/exec.js index 228482cb0269..8d0853963074 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/static-private/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/static-private/exec.js @@ -16,6 +16,10 @@ class Foo { const aContext = Foo['#aContext']; const bContext = Foo['#bContext']; +expect(aContext.access.has(Foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(Foo))).toBe(false); + expect(aContext.access.get(Foo)).toBe(2); aContext.access.set(Foo, 123); expect(aContext.access.get(Foo)).toBe(123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/static-private/output.js index 62441abec88b..fb59212f7c40 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/static-private/output.js @@ -5,11 +5,11 @@ class Foo {} return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _a); }, function (value) { babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _a, value); -}], [dec, 5, "b", function () { +}, _ => babelHelpers.checkInRHS(_) === Foo], [dec, 5, "b", function () { return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _b); }, function (value) { babelHelpers.classStaticPrivateFieldSpecSet(this, Foo, _b, value); -}]], []).e; +}, _ => babelHelpers.checkInRHS(_) === Foo]], []).e; var _a = { writable: true, value: _init_a(Foo) diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/static-public/exec.js index 72e94584065d..36113e23c702 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/static-public/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields--to-es2015/static-public/exec.js @@ -20,6 +20,12 @@ const aContext = Foo['aContext']; const bContext = Foo['bContext']; const cContext = Foo['cContext']; +expect(aContext.access.has(Foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(Foo))).toBe(true); +expect(aContext.access.has({ a: 1 })).toBe(true); +expect(aContext.access.has(Object.create({ a: 1 }))).toBe(true); + expect(Foo.a).toBe(2); expect(aContext.access.get(Foo)).toBe(2); Foo.a = 123; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields/private/output.js index 4676f4fa2093..227b9ad0c160 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields/private/output.js @@ -6,11 +6,11 @@ class Foo { return this.#a; }, function (value) { this.#a = value; - }], [dec, 0, "b", function () { + }, _ => #a in _], [dec, 0, "b", function () { return this.#b; }, function (value) { this.#b = value; - }]], []).e; + }, _ => #b in _]], []).e; } #a = _init_a(this); #b = _init_b(this, 123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields/static-private/output.js index f4277774d8ce..cdbfdf39a575 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-fields/static-private/output.js @@ -6,11 +6,11 @@ class Foo { return this.#a; }, function (value) { this.#a = value; - }], [dec, 5, "b", function () { + }, _ => #a in _], [dec, 5, "b", function () { return this.#b; }, function (value) { this.#b = value; - }]], []).e; + }, _ => #b in _]], []).e; } static #a = _init_a(this); static #b = _init_b(this, 123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/private/exec.js index 44fc431c9518..c3f723737452 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/private/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/private/exec.js @@ -25,6 +25,10 @@ let foo = new Foo(); const aContext = foo['#aContext']; +expect(aContext.access.has(foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(foo))).toBe(false); + expect(aContext.access.get(foo)).toBe(2); expect(foo.getA()).toBe(2); foo.value = 123; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/private/output.js index 525955051b6b..77d74e975ecb 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/private/output.js @@ -19,4 +19,4 @@ function _get_a() { } [_call_a, _initProto] = babelHelpers.applyDecs2301(Foo, [[dec, 3, "a", function () { return this.value; -}]], []).e; +}, _ => _a.has(babelHelpers.checkInRHS(_))]], []).e; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/public/exec.js index 556e4eb369ed..1e2bbfd6f644 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/public/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/public/exec.js @@ -27,6 +27,12 @@ let foo = new Foo(); const aContext = foo['aContext']; const bContext = foo['bContext']; +expect(aContext.access.has(foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(foo))).toBe(true); +expect(aContext.access.has({ a: 1 })).toBe(true); +expect(aContext.access.has(Object.create({ a: 1 }))).toBe(true); + expect(foo.a).toBe(2); expect(foo.b).toBe(2); expect(aContext.access.get(foo)).toBe(2); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/static-private/exec.js index 674792cb333d..2353030e50f2 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/static-private/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/static-private/exec.js @@ -23,6 +23,10 @@ class Foo { const aContext = Foo['#aContext']; +expect(aContext.access.has(Foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(Foo))).toBe(false); + expect(aContext.access.get(Foo)).toBe(2); expect(Foo.getA()).toBe(2); Foo.value = 123; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/static-private/output.js index 98ae05095661..01b21f3c7303 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/static-private/output.js @@ -15,7 +15,7 @@ var _a = { (() => { [_call_a, _initStatic] = babelHelpers.applyDecs2301(Foo, [[dec, 8, "a", function () { return this.value; - }]], []).e; + }, _ => babelHelpers.checkInRHS(_) === Foo]], []).e; _initStatic(Foo); })(); babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/static-public/exec.js index 5e41d08440a2..aaebed1470da 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/static-public/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters--to-es2015/static-public/exec.js @@ -25,6 +25,12 @@ class Foo { const aContext = Foo['aContext']; const bContext = Foo['bContext']; +expect(aContext.access.has(Foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(Foo))).toBe(true); +expect(aContext.access.has({ a: 1 })).toBe(true); +expect(aContext.access.has(Object.create({ a: 1 }))).toBe(true); + expect(Foo.a).toBe(2); expect(Foo.b).toBe(2); expect(aContext.access.get(Foo)).toBe(2); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/private/exec.js index f3ecef6a7800..9ba718f84924 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/private/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/private/exec.js @@ -41,6 +41,14 @@ let foo = new Foo(); const a_getterContext = foo['#a_getterContext']; const a_setterContext = foo['#a_setterContext']; +expect(a_getterContext.access.has(foo)).toBe(true); +expect(a_getterContext.access.has({})).toBe(false); +expect(a_getterContext.access.has(Object.create(foo))).toBe(false); +expect(a_setterContext.access.has(foo)).toBe(true); +expect(a_setterContext.access.has({})).toBe(false); +expect(a_setterContext.access.has(Object.create(foo))).toBe(false); +expect(a_getterContext.access.has).not.toBe(a_setterContext.access.has); + expect(a_getterContext.access.get(foo)).toBe(2); expect(foo.getA()).toBe(2); a_setterContext.access.set(foo, 123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/private/output.js index 05e33ee72d78..e7f1972d195e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/private/output.js @@ -25,6 +25,6 @@ function _set_a(v) { } [_call_a, _call_a2, _initProto] = babelHelpers.applyDecs2301(Foo, [[dec, 3, "a", function () { return this.value; -}], [dec, 4, "a", function (v) { +}, _ => _a.has(babelHelpers.checkInRHS(_))], [dec, 4, "a", function (v) { this.value = v; -}]], []).e; +}, _ => _a.has(babelHelpers.checkInRHS(_))]], []).e; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/public/exec.js index b4c1ff19a3cf..fa548d8d5c40 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/public/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/public/exec.js @@ -46,6 +46,18 @@ const a_setterContext = foo['a_setterContext']; const b_getterContext = foo['b_getterContext']; const b_setterContext = foo['b_setterContext']; +expect(a_getterContext.access.has(foo)).toBe(true); +expect(a_getterContext.access.has({})).toBe(false); +expect(a_getterContext.access.has(Object.create(foo))).toBe(true); +expect(a_getterContext.access.has({ a: 1 })).toBe(true); +expect(a_getterContext.access.has(Object.create({ a: 1 }))).toBe(true); +expect(a_setterContext.access.has(foo)).toBe(true); +expect(a_setterContext.access.has({})).toBe(false); +expect(a_setterContext.access.has(Object.create(foo))).toBe(true); +expect(a_setterContext.access.has({ a: 1 })).toBe(true); +expect(a_setterContext.access.has(Object.create({ a: 1 }))).toBe(true); +expect(a_getterContext.access.has).not.toBe(a_setterContext.access.has); + expect(foo.a).toBe(2); expect(foo.b).toBe(2); expect(a_getterContext.access.get(foo)).toBe(2); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/static-private/exec.js index a30fc3fb1b1e..6d67c3f42375 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/static-private/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/static-private/exec.js @@ -39,6 +39,14 @@ class Foo { const a_getterContext = Foo['#a_getterContext']; const a_setterContext = Foo['#a_setterContext']; +expect(a_getterContext.access.has(Foo)).toBe(true); +expect(a_getterContext.access.has({})).toBe(false); +expect(a_getterContext.access.has(Object.create(Foo))).toBe(false); +expect(a_setterContext.access.has(Foo)).toBe(true); +expect(a_setterContext.access.has({})).toBe(false); +expect(a_setterContext.access.has(Object.create(Foo))).toBe(false); +expect(a_getterContext.access.has).not.toBe(a_setterContext.access.has); + expect(a_getterContext.access.get(Foo)).toBe(2); expect(Foo.getA()).toBe(2); a_setterContext.access.set(Foo, 123); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/static-private/output.js index c36e28d689f6..f98b7cf38449 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/static-private/output.js @@ -21,9 +21,9 @@ var _a = { (() => { [_call_a, _call_a2, _initStatic] = babelHelpers.applyDecs2301(Foo, [[dec, 8, "a", function () { return this.value; - }], [dec, 9, "a", function (v) { + }, _ => babelHelpers.checkInRHS(_) === Foo], [dec, 9, "a", function (v) { this.value = v; - }]], []).e; + }, _ => babelHelpers.checkInRHS(_) === Foo]], []).e; _initStatic(Foo); })(); babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/static-public/exec.js index bb20d7c8ba3c..9b4f9539e2e4 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/static-public/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters--to-es2015/static-public/exec.js @@ -44,6 +44,18 @@ const a_setterContext = Foo['a_setterContext']; const b_getterContext = Foo['b_getterContext']; const b_setterContext = Foo['b_setterContext']; +expect(a_getterContext.access.has(Foo)).toBe(true); +expect(a_getterContext.access.has({})).toBe(false); +expect(a_getterContext.access.has(Object.create(Foo))).toBe(true); +expect(a_getterContext.access.has({ a: 1 })).toBe(true); +expect(a_getterContext.access.has(Object.create({ a: 1 }))).toBe(true); +expect(a_setterContext.access.has(Foo)).toBe(true); +expect(a_setterContext.access.has({})).toBe(false); +expect(a_setterContext.access.has(Object.create(Foo))).toBe(true); +expect(a_setterContext.access.has({ a: 1 })).toBe(true); +expect(a_setterContext.access.has(Object.create({ a: 1 }))).toBe(true); +expect(a_getterContext.access.has).not.toBe(a_setterContext.access.has); + expect(Foo.a).toBe(2); expect(Foo.b).toBe(2); expect(a_getterContext.access.get(Foo)).toBe(2); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters/private/output.js index a25e08b9d748..a3143704a39a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters/private/output.js @@ -4,9 +4,9 @@ class Foo { static { [_call_a, _call_a2, _initProto] = babelHelpers.applyDecs2301(this, [[dec, 3, "a", function () { return this.value; - }], [dec, 4, "a", function (v) { + }, _ => #a in _], [dec, 4, "a", function (v) { this.value = v; - }]], []).e; + }, _ => #a in _]], []).e; } constructor(...args) { _initProto(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters/static-private/output.js index 6ab3c888227b..bf9c4d33801c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters-and-setters/static-private/output.js @@ -4,9 +4,9 @@ class Foo { static { [_call_a, _call_a2, _initStatic] = babelHelpers.applyDecs2301(this, [[dec, 8, "a", function () { return this.value; - }], [dec, 9, "a", function (v) { + }, _ => #a in _], [dec, 9, "a", function (v) { this.value = v; - }]], []).e; + }, _ => #a in _]], []).e; _initStatic(this); } static value = 1; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters/private/output.js index 86b323e049ea..25830a14452c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters/private/output.js @@ -4,7 +4,7 @@ class Foo { static { [_call_a, _initProto] = babelHelpers.applyDecs2301(this, [[dec, 3, "a", function () { return this.value; - }]], []).e; + }, _ => #a in _]], []).e; } constructor(...args) { _initProto(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters/static-private/output.js index 16853b029714..f44de79d021a 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-getters/static-private/output.js @@ -4,7 +4,7 @@ class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2301(this, [[dec, 8, "a", function () { return this.value; - }]], []).e; + }, _ => #a in _]], []).e; _initStatic(this); } static value = 1; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/private-with-initializers/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/private-with-initializers/exec.js index 3713a3cd46ca..ccd18dab0a96 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/private-with-initializers/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/private-with-initializers/exec.js @@ -25,6 +25,10 @@ let foo = new Foo(); const aContext = foo['#aContext']; +expect(aContext.access.has(foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(foo))).toBe(false); + // First call gets the method, second call calls the method with correct `this` expect(aContext.access.get(foo).call(foo)).toBe(2); expect(foo.callA()).toBe(2); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/private/output.js index a6a95dea8964..3074a64136c2 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/private/output.js @@ -16,4 +16,4 @@ class Foo { } [_call_a, _initProto] = babelHelpers.applyDecs2301(Foo, [[dec, 2, "a", function () { return this.value; -}]], []).e; +}, _ => _a.has(babelHelpers.checkInRHS(_))]], []).e; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/public-with-initializers/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/public-with-initializers/exec.js index 94f3b2436fa0..d7f969ca466e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/public-with-initializers/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/public-with-initializers/exec.js @@ -27,6 +27,12 @@ let foo = new Foo(); const aContext = foo['aContext']; const bContext = foo['bContext']; +expect(aContext.access.has(foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(foo))).toBe(true); +expect(aContext.access.has({ a: 1 })).toBe(true); +expect(aContext.access.has(Object.create({ a: 1 }))).toBe(true); + expect(foo.a()).toBe(2); expect(aContext.access.get(foo).call(foo)).toBe(2); expect(foo.b()).toBe(2); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/static-private-with-initializers/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/static-private-with-initializers/exec.js index e6eddb097ece..29f46febd4d9 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/static-private-with-initializers/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/static-private-with-initializers/exec.js @@ -23,6 +23,10 @@ class Foo { const aContext = Foo['#aContext']; +expect(aContext.access.has(Foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(Foo))).toBe(false); + // First call gets the method, second call calls the method with correct `this` expect(aContext.access.get(Foo).call(Foo)).toBe(2); expect(Foo.callA()).toBe(2); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/static-private/output.js index 37add57acdd1..86176c435fd2 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/static-private/output.js @@ -8,7 +8,7 @@ class Foo { (() => { [_call_a, _initStatic] = babelHelpers.applyDecs2301(Foo, [[dec, 7, "a", function () { return this.value; - }]], []).e; + }, _ => babelHelpers.checkInRHS(_) === Foo]], []).e; _initStatic(Foo); })(); var _a = { diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/static-public-with-initializers/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/static-public-with-initializers/exec.js index 390e37ac53b8..910dae50598e 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/static-public-with-initializers/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods--to-es2015/static-public-with-initializers/exec.js @@ -25,6 +25,12 @@ class Foo { const aContext = Foo['aContext']; const bContext = Foo['bContext']; +expect(aContext.access.has(Foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(Foo))).toBe(true); +expect(aContext.access.has({ a: 1 })).toBe(true); +expect(aContext.access.has(Object.create({ a: 1 }))).toBe(true); + expect(Foo.a()).toBe(2); expect(aContext.access.get(Foo).call(Foo)).toBe(2); expect(Foo.b()).toBe(2); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods/private/output.js index c2a5e09ff571..5792be67795d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods/private/output.js @@ -4,7 +4,7 @@ class Foo { static { [_call_a, _initProto] = babelHelpers.applyDecs2301(this, [[dec, 2, "a", function () { return this.value; - }]], []).e; + }, _ => #a in _]], []).e; } constructor(...args) { _initProto(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods/static-private/output.js index ee2073fb7892..b59f975820bf 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-methods/static-private/output.js @@ -4,7 +4,7 @@ class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2301(this, [[dec, 7, "a", function () { return this.value; - }]], []).e; + }, _ => #a in _]], []).e; _initStatic(this); } static #a = _call_a; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/all-decorators/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/all-decorators/output.js index 88fd33e6628b..d31796ad665c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/all-decorators/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/all-decorators/output.js @@ -8,23 +8,23 @@ new class extends babelHelpers.identity { ({ e: [_init_m, _call_o, _call_p, _call_q, _init_r, _get_r, _set_r, _init_d, _call_f, _call_g, _call_g2, _init_h, _get_h, _set_h, _init_i, _init_n, _init_a, _init_e, _initProto, _initStatic], c: [_Class, _initClass] - } = babelHelpers.applyDecs2301(this, [[dec, 7, "j"], [dec, 8, "k"], [dec, 9, "l"], [dec, 6, "m"], [dec, 7, "o", function () {}], [dec, 8, "p", function () {}], [dec, 9, "q", function (v) {}], [dec, 6, "r", function () { + } = babelHelpers.applyDecs2301(this, [[dec, 7, "j"], [dec, 8, "k"], [dec, 9, "l"], [dec, 6, "m"], [dec, 7, "o", function () {}, _ => #o in _], [dec, 8, "p", function () {}, _ => #p in _], [dec, 9, "q", function (v) {}, _ => #q in _], [dec, 6, "r", function () { return this.#D; }, function (value) { this.#D = value; - }], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 2, "f", function () {}], [dec, 3, "g", function () {}], [dec, 4, "g", function (v) {}], [dec, 1, "h", function () { + }, _ => #D in _], [dec, 2, "b"], [dec, 3, "c"], [dec, 4, "c"], [dec, 1, "d"], [dec, 2, "f", function () {}, _ => #f in _], [dec, 3, "g", function () {}, _ => #g in _], [dec, 4, "g", function (v) {}, _ => #g in _], [dec, 1, "h", function () { return this.#B; }, function (value) { this.#B = value; - }], [dec, 5, "i"], [dec, 5, "n", function () { + }, _ => #B in _], [dec, 5, "i"], [dec, 5, "n", function () { return this.#n; }, function (value) { this.#n = value; - }], [dec, 0, "a"], [dec, 0, "e", function () { + }, _ => #n in _], [dec, 0, "a"], [dec, 0, "e", function () { return this.#e; }, function (value) { this.#e = value; - }]], [dec])); + }, _ => #e in _]], [dec])); _initStatic(this); } #f = _call_f; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/super-in-private-accessor/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/super-in-private-accessor/output.js index c37398defee8..36144a8b744f 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/super-in-private-accessor/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/super-in-private-accessor/output.js @@ -4,7 +4,7 @@ class Foo extends Bar { static { [_call_x, _initProto] = babelHelpers.applyDecs2301(this, [[dec, 3, "x", function () { return babelHelpers.get(babelHelpers.getPrototypeOf(Foo), "foo", this).call(this); - }]], []).e; + }, _ => #x in _]], []).e; } constructor(...args) { super(...args); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/super-in-private-method/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/super-in-private-method/output.js index 05121710be7f..a2265789b3c8 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/super-in-private-method/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-misc/super-in-private-method/output.js @@ -4,7 +4,7 @@ class Foo extends Bar { static { [_call_x, _initProto] = babelHelpers.applyDecs2301(this, [[dec, 2, "x", function () { return babelHelpers.get(babelHelpers.getPrototypeOf(Foo), "foo", this).call(this); - }]], []).e; + }, _ => #x in _]], []).e; } constructor(...args) { super(...args); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/private/exec.js index 126e6b4cc832..ef45904ffdb5 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/private/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/private/exec.js @@ -25,6 +25,10 @@ let foo = new Foo(); const aContext = foo['#aContext']; +expect(aContext.access.has(foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(foo))).toBe(false); + expect(foo.value).toBe(1); aContext.access.set(foo, 123); expect(foo.value).toBe(124); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/private/output.js index 93bb9c9806a6..949f0980592f 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/private/output.js @@ -19,4 +19,4 @@ function _set_a(v) { } [_call_a, _initProto] = babelHelpers.applyDecs2301(Foo, [[dec, 4, "a", function (v) { return this.value = v; -}]], []).e; +}, _ => _a.has(babelHelpers.checkInRHS(_))]], []).e; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/public/exec.js index 963fc1c350c2..f82fb5e637da 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/public/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/public/exec.js @@ -27,6 +27,12 @@ let foo = new Foo(); const aContext = foo['aContext']; const bContext = foo['bContext']; +expect(aContext.access.has(foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(foo))).toBe(true); +expect(aContext.access.has({ a: 1 })).toBe(true); +expect(aContext.access.has(Object.create({ a: 1 }))).toBe(true); + expect(foo.value).toBe(1); foo.a = 123; expect(foo.value).toBe(124); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/static-private/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/static-private/exec.js index e96db12689c7..94a92023b093 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/static-private/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/static-private/exec.js @@ -23,6 +23,10 @@ class Foo { const aContext = Foo['#aContext']; +expect(aContext.access.has(Foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(Foo))).toBe(false); + expect(Foo.value).toBe(1); aContext.access.set(Foo, 123); expect(Foo.value).toBe(124); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/static-private/output.js index 81b70713008f..50049f8e9728 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/static-private/output.js @@ -15,7 +15,7 @@ var _a = { (() => { [_call_a, _initStatic] = babelHelpers.applyDecs2301(Foo, [[dec, 9, "a", function (v) { return this.value = v; - }]], []).e; + }, _ => babelHelpers.checkInRHS(_) === Foo]], []).e; _initStatic(Foo); })(); babelHelpers.defineProperty(Foo, "value", 1); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/static-public/exec.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/static-public/exec.js index 50e7580b7b13..e6c67fe0217d 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/static-public/exec.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters--to-es2015/static-public/exec.js @@ -25,6 +25,11 @@ class Foo { const aContext = Foo['aContext']; const bContext = Foo['bContext']; +expect(aContext.access.has(Foo)).toBe(true); +expect(aContext.access.has({})).toBe(false); +expect(aContext.access.has(Object.create(Foo))).toBe(true); +expect(aContext.access.has({ a: 1 })).toBe(true); +expect(aContext.access.has(Object.create({ a: 1 }))).toBe(true); expect(Foo.value).toBe(1); Foo.a = 123; diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters/private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters/private/output.js index fffa05e5e058..8daaac2ce161 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters/private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters/private/output.js @@ -4,7 +4,7 @@ class Foo { static { [_call_a, _initProto] = babelHelpers.applyDecs2301(this, [[dec, 4, "a", function (v) { return this.value = v; - }]], []).e; + }, _ => #a in _]], []).e; } constructor(...args) { _initProto(this); diff --git a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters/static-private/output.js b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters/static-private/output.js index 2ec483f1d1f4..1e626133aa4c 100644 --- a/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters/static-private/output.js +++ b/packages/babel-plugin-proposal-decorators/test/fixtures/2023-01-setters/static-private/output.js @@ -4,7 +4,7 @@ class Foo { static { [_call_a, _initStatic] = babelHelpers.applyDecs2301(this, [[dec, 9, "a", function (v) { return this.value = v; - }]], []).e; + }, _ => #a in _]], []).e; _initStatic(this); } static value = 1;