Skip to content

Commit

Permalink
Preserve static on decorated private accessor (#16266)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Feb 26, 2024
1 parent b78f864 commit 1b3e183
Show file tree
Hide file tree
Showing 26 changed files with 133 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,9 @@ function addProxyAccessorsFor(
originalKey: t.PrivateName | t.Expression,
targetKey: t.PrivateName,
version: DecoratorVersionKind,
isComputed = false,
isComputed: boolean,
isStatic: boolean,
): void {
const { static: isStatic } = element.node;

const thisArg =
(version === "2023-11" ||
(!process.env.BABEL_8_BREAKING && version === "2023-05")) &&
Expand Down Expand Up @@ -610,6 +609,7 @@ function addCallAccessorsFor(
key: t.PrivateName,
getId: t.Identifier,
setId: t.Identifier,
isStatic: boolean,
) {
element.insertAfter(
t.classPrivateMethod(
Expand All @@ -621,6 +621,7 @@ function addCallAccessorsFor(
t.callExpression(t.cloneNode(getId), [t.thisExpression()]),
),
]),
isStatic,
),
);

Expand All @@ -637,6 +638,7 @@ function addCallAccessorsFor(
]),
),
]),
isStatic,
),
);
}
Expand Down Expand Up @@ -885,6 +887,7 @@ function transformClass(
newId,
version,
computed,
isStatic,
);
}
}
Expand Down Expand Up @@ -1099,7 +1102,7 @@ function transformClass(
`set_${name}`,
);

addCallAccessorsFor(newPath, key, getId, setId);
addCallAccessorsFor(newPath, key, getId, setId, isStatic);

locals = [newFieldInitId, getId, setId];
} else {
Expand All @@ -1110,6 +1113,7 @@ function transformClass(
newId,
version,
isComputed,
isStatic,
);
locals = [newFieldInitId];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ const f = () => {
};
};
_computedKey = babelHelpers.toPropertyKey(f());
var _a = /*#__PURE__*/new WeakMap();
class Foo {
constructor() {
babelHelpers.classPrivateFieldInitSpec(this, _a, {
get: _get_a2,
set: _set_a2
});
}
static get a() {
return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A);
}
Expand Down Expand Up @@ -74,6 +67,10 @@ function _set_a2(v) {
function _get_a2() {
return _get_a(this);
}
var _a = {
get: _get_a2,
set: _set_a2
};
(() => {
[_init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _initStatic] = babelHelpers.applyDecs(_Foo, [[dec, 6, "a"], [dec, 6, "a", function () {
return babelHelpers.classStaticPrivateFieldSpecGet(this, _Foo, _B);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
var _initStatic, _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _Foo;
const dec = () => {};
var _a = /*#__PURE__*/new WeakMap();
var _b = /*#__PURE__*/new WeakMap();
class Foo {
constructor() {
babelHelpers.classPrivateFieldInitSpec(this, _b, {
get: _get_b2,
set: _set_b2
});
babelHelpers.classPrivateFieldInitSpec(this, _a, {
get: _get_a2,
set: _set_a2
});
}
}
class Foo {}
_Foo = Foo;
function _set_a2(v) {
_set_a(this, v);
Expand All @@ -27,6 +14,14 @@ function _set_b2(v) {
function _get_b2() {
return _get_b(this);
}
var _b = {
get: _get_b2,
set: _set_b2
};
var _a = {
get: _get_a2,
set: _set_a2
};
(() => {
[_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic] = babelHelpers.applyDecs(_Foo, [[dec, 6, "a", function () {
return babelHelpers.classStaticPrivateFieldSpecGet(this, _Foo, _A);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class Foo {
this.#A = v;
}
static #B = _init_a2(this);
set #a(v) {
static set #a(v) {
_set_a(this, v);
}
get #a() {
static get #a() {
return _get_a(this);
}
static #C = _init_computedKey(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ class Foo {
_initStatic(this);
}
static #A = _init_a(this);
set #a(v) {
static set #a(v) {
_set_a(this, v);
}
get #a() {
static get #a() {
return _get_a(this);
}
static #B = _init_b(this, 123);
set #b(v) {
static set #b(v) {
_set_b(this, v);
}
get #b() {
static get #b() {
return _get_b(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ new class extends babelHelpers.identity {
static set m(v) {
this.#C = v;
}
set #r(v) {
_set_r(this, v);
}
get #r() {
return _get_r(this);
}
}
}
#o = _call_o;
Expand All @@ -78,6 +72,12 @@ new class extends babelHelpers.identity {
_call_q(this, v);
}
#D = _init_r(this);
set #r(v) {
_set_r(this, v);
}
get #r() {
return _get_r(this);
}
constructor() {
super(_Class), _initClass();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ const f = () => {
};
};
_computedKey = babelHelpers.toPropertyKey(f());
var _a = /*#__PURE__*/new WeakMap();
class Foo {
constructor() {
babelHelpers.classPrivateFieldInitSpec(this, _a, {
get: _get_a2,
set: _set_a2
});
}
static get a() {
return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A);
}
Expand Down Expand Up @@ -74,6 +67,10 @@ function _set_a2(v) {
function _get_a2() {
return _get_a(this);
}
var _a = {
get: _get_a2,
set: _set_a2
};
(() => {
[_init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _initStatic] = babelHelpers.applyDecs2203R(_Foo, [[dec, 6, "a"], [dec, 6, "a", function () {
return babelHelpers.classStaticPrivateFieldSpecGet(this, _Foo, _B);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
var _initStatic, _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _Foo;
const dec = () => {};
var _a = /*#__PURE__*/new WeakMap();
var _b = /*#__PURE__*/new WeakMap();
class Foo {
constructor() {
babelHelpers.classPrivateFieldInitSpec(this, _b, {
get: _get_b2,
set: _set_b2
});
babelHelpers.classPrivateFieldInitSpec(this, _a, {
get: _get_a2,
set: _set_a2
});
}
}
class Foo {}
_Foo = Foo;
function _set_a2(v) {
_set_a(this, v);
Expand All @@ -27,6 +14,14 @@ function _set_b2(v) {
function _get_b2() {
return _get_b(this);
}
var _b = {
get: _get_b2,
set: _set_b2
};
var _a = {
get: _get_a2,
set: _set_a2
};
(() => {
[_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic] = babelHelpers.applyDecs2203R(_Foo, [[dec, 6, "a", function () {
return babelHelpers.classStaticPrivateFieldSpecGet(this, _Foo, _A);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ class Foo {
this.#A = v;
}
static #B = _init_a2(this);
set #a(v) {
static set #a(v) {
_set_a(this, v);
}
get #a() {
static get #a() {
return _get_a(this);
}
static #C = _init_computedKey(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ class Foo {
_initStatic(this);
}
static #A = _init_a(this);
set #a(v) {
static set #a(v) {
_set_a(this, v);
}
get #a() {
static get #a() {
return _get_a(this);
}
static #B = _init_b(this, 123);
set #b(v) {
static set #b(v) {
_set_b(this, v);
}
get #b() {
static get #b() {
return _get_b(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ new class extends babelHelpers.identity {
static set m(v) {
this.#C = v;
}
set #r(v) {
_set_r(this, v);
}
get #r() {
return _get_r(this);
}
}
}
#o = _call_o;
Expand All @@ -81,6 +75,12 @@ new class extends babelHelpers.identity {
_call_q(this, v);
}
#D = _init_r(this);
set #r(v) {
_set_r(this, v);
}
get #r() {
return _get_r(this);
}
constructor() {
super(_Class), _initClass();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,7 @@ const f = () => {
};
};
_computedKey = babelHelpers.toPropertyKey(f());
var _a = /*#__PURE__*/new WeakMap();
class Foo {
constructor() {
babelHelpers.classPrivateFieldInitSpec(this, _a, {
get: _get_a2,
set: _set_a2
});
}
static get a() {
return babelHelpers.classStaticPrivateFieldSpecGet(this, Foo, _A);
}
Expand Down Expand Up @@ -74,6 +67,10 @@ function _set_a2(v) {
function _get_a2() {
return _get_a(this);
}
var _a = {
get: _get_a2,
set: _set_a2
};
(() => {
[_init_a, _init_a2, _get_a, _set_a, _init_computedKey, _init_computedKey2, _init_computedKey3, _init_computedKey4, _init_computedKey5, _init_computedKey6, _init_computedKey7, _initStatic] = babelHelpers.applyDecs2301(_Foo, [[dec, 6, "a"], [dec, 6, "a", o => babelHelpers.classStaticPrivateFieldSpecGet(o, _Foo, _B), (o, v) => babelHelpers.classStaticPrivateFieldSpecSet(o, _Foo, _B, v)], [dec, 6, "b"], [dec, 6, "c"], [dec, 6, 0], [dec, 6, 1], [dec, 6, 2n], [dec, 6, 3n], [dec, 6, _computedKey]], []).e;
_initStatic(_Foo);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
var _initStatic, _init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _Foo;
const dec = () => {};
var _a = /*#__PURE__*/new WeakMap();
var _b = /*#__PURE__*/new WeakMap();
class Foo {
constructor() {
babelHelpers.classPrivateFieldInitSpec(this, _b, {
get: _get_b2,
set: _set_b2
});
babelHelpers.classPrivateFieldInitSpec(this, _a, {
get: _get_a2,
set: _set_a2
});
}
}
class Foo {}
_Foo = Foo;
function _set_a2(v) {
_set_a(this, v);
Expand All @@ -27,6 +14,14 @@ function _set_b2(v) {
function _get_b2() {
return _get_b(this);
}
var _b = {
get: _get_b2,
set: _set_b2
};
var _a = {
get: _get_a2,
set: _set_a2
};
(() => {
[_init_a, _get_a, _set_a, _init_b, _get_b, _set_b, _initStatic] = babelHelpers.applyDecs2301(_Foo, [[dec, 6, "a", o => babelHelpers.classStaticPrivateFieldSpecGet(o, _Foo, _A), (o, v) => babelHelpers.classStaticPrivateFieldSpecSet(o, _Foo, _A, v)], [dec, 6, "b", o => babelHelpers.classStaticPrivateFieldSpecGet(o, _Foo, _B), (o, v) => babelHelpers.classStaticPrivateFieldSpecSet(o, _Foo, _B, v)]], []).e;
_initStatic(_Foo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ class Foo {
this.#A = v;
}
static #B = _init_a2(this);
set #a(v) {
static set #a(v) {
_set_a(this, v);
}
get #a() {
static get #a() {
return _get_a(this);
}
static #C = _init_computedKey(this);
Expand Down

0 comments on commit 1b3e183

Please sign in to comment.