Skip to content

Commit

Permalink
Fix protoInit call injection timing (babel#16235)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung authored and liuxingbaoyu committed Mar 5, 2024
1 parent 1f64359 commit 74dcb8c
Show file tree
Hide file tree
Showing 82 changed files with 402 additions and 240 deletions.
Expand Up @@ -1138,20 +1138,20 @@ function transformClass(
if (element.node) {
element.node.decorators = null;
}
}

if (
fieldInitializerAssignments.length > 0 &&
!isStatic &&
(kind === FIELD || kind === ACCESSOR)
) {
prependExpressionsToFieldInitializer(
fieldInitializerAssignments,
element as NodePath<
t.ClassProperty | t.ClassPrivateProperty | t.ClassAccessorProperty
>,
);
fieldInitializerAssignments = [];
}
if (
fieldInitializerAssignments.length > 0 &&
!isStatic &&
(kind === FIELD || kind === ACCESSOR)
) {
prependExpressionsToFieldInitializer(
fieldInitializerAssignments,
element as NodePath<
t.ClassProperty | t.ClassPrivateProperty | t.ClassAccessorProperty
>,
);
fieldInitializerAssignments = [];
}
}
}
Expand Down
Expand Up @@ -7,8 +7,7 @@ class Foo {
get: _get_a,
set: void 0
});
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
getA() {
return babelHelpers.classPrivateFieldGet(this, _a);
Expand Down
Expand Up @@ -2,8 +2,7 @@ var _initProto, _Foo;
const dec = () => {};
class Foo {
constructor() {
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
get a() {
return this.value;
Expand Down
Expand Up @@ -7,8 +7,7 @@ class Foo {
get: _get_a,
set: _set_a
});
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
getA() {
return babelHelpers.classPrivateFieldGet(this, _a);
Expand Down
Expand Up @@ -2,8 +2,7 @@ var _initProto, _Foo;
const dec = () => {};
class Foo {
constructor() {
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
get a() {
return this.value;
Expand Down
Expand Up @@ -8,10 +8,7 @@ class Foo {
this.value = v;
}]], []);
}
constructor() {
_initProto(this);
}
value = 1;
value = (_initProto(this), 1);
get #a() {
return _call_a(this);
}
Expand Down
Expand Up @@ -4,10 +4,7 @@ class Foo {
static {
[_initProto] = babelHelpers.applyDecs(this, [[dec, 3, "a"], [dec, 4, "a"], [dec, 3, 'b'], [dec, 4, 'b']], []);
}
constructor() {
_initProto(this);
}
value = 1;
value = (_initProto(this), 1);
get a() {
return this.value;
}
Expand Down
Expand Up @@ -6,10 +6,7 @@ class Foo {
return this.value;
}]], []);
}
constructor() {
_initProto(this);
}
value = 1;
value = (_initProto(this), 1);
get #a() {
return _call_a(this);
}
Expand Down
Expand Up @@ -4,10 +4,7 @@ class Foo {
static {
[_initProto] = babelHelpers.applyDecs(this, [[dec, 3, "a"], [dec, 3, 'b']], []);
}
constructor() {
_initProto(this);
}
value = 1;
value = (_initProto(this), 1);
get a() {
return this.value;
}
Expand Down
Expand Up @@ -7,8 +7,7 @@ class Foo {
writable: true,
value: _call_a
});
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
callA() {
return babelHelpers.classPrivateFieldGet(this, _a).call(this);
Expand Down
Expand Up @@ -2,8 +2,7 @@ var _initProto, _Foo;
const dec = () => {};
class Foo {
constructor() {
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
a() {
return this.value;
Expand Down
Expand Up @@ -6,11 +6,8 @@ class Foo {
return this.value;
}]], []);
}
constructor() {
_initProto(this);
}
#a = _call_a;
value = 1;
value = (_initProto(this), 1);
callA() {
return this.#a();
}
Expand Down
Expand Up @@ -4,10 +4,7 @@ class Foo {
static {
[_initProto] = babelHelpers.applyDecs(this, [[dec, 2, "a"], [dec, 2, 'b']], []);
}
constructor() {
_initProto(this);
}
value = 1;
value = (_initProto(this), 1);
a() {
return this.value;
}
Expand Down
Expand Up @@ -11,9 +11,8 @@ class Foo {
constructor() {
babelHelpers.classPrivateFieldInitSpec(this, _a, {
writable: true,
value: void 0
value: void _initProto(this)
});
_initProto(this);
}
method() {}
makeClass() {
Expand Down
Expand Up @@ -76,12 +76,12 @@
[_initProto3] = babelHelpers.applyDecs(this, [[dec, 2, "method"]], []);
}
constructor() {
log.push(_initProto3(super(6)).method());
log.push(super(6).method());
}
method() {
return this.a;
}
[_computedKey];
[_computedKey] = void _initProto3(this);
}
new A();
}
Expand Down
Expand Up @@ -10,10 +10,7 @@ class Foo {
static {
[_initProto, _Foo, _initClass] = babelHelpers.applyDecs(this, [[[dec, _dec, _dec2, _dec3, _dec4], 2, "method"]], _classDecs);
}
constructor() {
_initProto(this);
}
#a;
#a = void _initProto(this);
method() {}
makeClass() {
var _dec5, _init_bar;
Expand Down
Expand Up @@ -7,8 +7,7 @@ class Foo {
get: void 0,
set: _set_a
});
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
setA(v) {
babelHelpers.classPrivateFieldSet(this, _a, v);
Expand Down
Expand Up @@ -2,8 +2,7 @@ var _initProto, _Foo;
const dec = () => {};
class Foo {
constructor() {
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
set a(v) {
return this.value = v;
Expand Down
Expand Up @@ -6,10 +6,7 @@ class Foo {
return this.value = v;
}]], []);
}
constructor() {
_initProto(this);
}
value = 1;
value = (_initProto(this), 1);
set #a(v) {
_call_a(this, v);
}
Expand Down
Expand Up @@ -4,10 +4,7 @@ class Foo {
static {
[_initProto] = babelHelpers.applyDecs(this, [[dec, 4, "a"], [dec, 4, 'b']], []);
}
constructor() {
_initProto(this);
}
value = 1;
value = (_initProto(this), 1);
set a(v) {
return this.value = v;
}
Expand Down
Expand Up @@ -7,8 +7,7 @@ class Foo {
get: _get_a,
set: void 0
});
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
getA() {
return babelHelpers.classPrivateFieldGet(this, _a);
Expand Down
Expand Up @@ -2,8 +2,7 @@ var _initProto, _Foo;
const dec = () => {};
class Foo {
constructor() {
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
get a() {
return this.value;
Expand Down
Expand Up @@ -7,8 +7,7 @@ class Foo {
get: _get_a,
set: _set_a
});
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
getA() {
return babelHelpers.classPrivateFieldGet(this, _a);
Expand Down
Expand Up @@ -2,8 +2,7 @@ var _initProto, _Foo;
const dec = () => {};
class Foo {
constructor() {
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
get a() {
return this.value;
Expand Down
Expand Up @@ -8,10 +8,7 @@ class Foo {
this.value = v;
}]], []).e;
}
constructor() {
_initProto(this);
}
value = 1;
value = (_initProto(this), 1);
get #a() {
return _call_a(this);
}
Expand Down
Expand Up @@ -4,10 +4,7 @@ class Foo {
static {
[_initProto] = babelHelpers.applyDecs2203R(this, [[dec, 3, "a"], [dec, 4, "a"], [dec, 3, 'b'], [dec, 4, 'b']], []).e;
}
constructor() {
_initProto(this);
}
value = 1;
value = (_initProto(this), 1);
get a() {
return this.value;
}
Expand Down
Expand Up @@ -6,10 +6,7 @@ class Foo {
return this.value;
}]], []).e;
}
constructor() {
_initProto(this);
}
value = 1;
value = (_initProto(this), 1);
get #a() {
return _call_a(this);
}
Expand Down
Expand Up @@ -4,10 +4,7 @@ class Foo {
static {
[_initProto] = babelHelpers.applyDecs2203R(this, [[dec, 3, "a"], [dec, 3, 'b']], []).e;
}
constructor() {
_initProto(this);
}
value = 1;
value = (_initProto(this), 1);
get a() {
return this.value;
}
Expand Down
Expand Up @@ -7,8 +7,7 @@ class Foo {
writable: true,
value: _call_a
});
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
callA() {
return babelHelpers.classPrivateFieldGet(this, _a).call(this);
Expand Down
Expand Up @@ -2,8 +2,7 @@ var _initProto, _Foo;
const dec = () => {};
class Foo {
constructor() {
babelHelpers.defineProperty(this, "value", 1);
_initProto(this);
babelHelpers.defineProperty(this, "value", (_initProto(this), 1));
}
a() {
return this.value;
Expand Down
Expand Up @@ -6,11 +6,8 @@ class Foo {
return this.value;
}]], []).e;
}
constructor() {
_initProto(this);
}
#a = _call_a;
value = 1;
value = (_initProto(this), 1);
callA() {
return this.#a();
}
Expand Down
Expand Up @@ -4,10 +4,7 @@ class Foo {
static {
[_initProto] = babelHelpers.applyDecs2203R(this, [[dec, 2, "a"], [dec, 2, 'b']], []).e;
}
constructor() {
_initProto(this);
}
value = 1;
value = (_initProto(this), 1);
a() {
return this.value;
}
Expand Down
Expand Up @@ -71,7 +71,7 @@
_computedKey = babelHelpers.toPropertyKey((key = super(5).method(), log.push(key), key));
class A extends B {
constructor() {
log.push(_initProto3((super(6), babelHelpers.defineProperty(this, _computedKey, void 0))).method());
log.push((super(6), babelHelpers.defineProperty(this, _computedKey, void _initProto3(this))).method());
}
method() {
return this.a;
Expand Down

0 comments on commit 74dcb8c

Please sign in to comment.