Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Mar 25, 2024
1 parent 87ec4fc commit 4d53402
Show file tree
Hide file tree
Showing 7 changed files with 194 additions and 20 deletions.
Expand Up @@ -475,26 +475,28 @@ function optimizeSuperCallAndExpressions(
expressions: t.Expression[],
protoInitLocal: t.Identifier,
) {
// Merge `super(), protoInit(this)` into `protoInit(super())`
if (
expressions.length >= 2 &&
isProtoInitCallExpression(expressions[1], protoInitLocal)
) {
const mergedSuperCall = t.callExpression(t.cloneNode(protoInitLocal), [
expressions[0],
]);
expressions.splice(0, 2, mergedSuperCall);
}
// Merge `protoInit(super()), this` into `protoInit(super())`
if (
expressions.length >= 2 &&
t.isThisExpression(expressions[expressions.length - 1]) &&
isProtoInitCallExpression(
expressions[expressions.length - 2],
protoInitLocal,
)
) {
expressions.splice(expressions.length - 1, 1);
if (protoInitLocal) {
if (
expressions.length >= 2 &&
isProtoInitCallExpression(expressions[1], protoInitLocal)
) {
// Merge `super(), protoInit(this)` into `protoInit(super())`
const mergedSuperCall = t.callExpression(t.cloneNode(protoInitLocal), [
expressions[0],
]);
expressions.splice(0, 2, mergedSuperCall);
}
// Merge `protoInit(super()), this` into `protoInit(super())`
if (
expressions.length >= 2 &&
t.isThisExpression(expressions[expressions.length - 1]) &&
isProtoInitCallExpression(
expressions[expressions.length - 2],
protoInitLocal,
)
) {
expressions.splice(expressions.length - 1, 1);
}
}
return maybeSequenceExpression(expressions);
}
Expand Down
@@ -0,0 +1,24 @@
function decorate() {
return function (target, context) {}
}

class Test {
@decorate()
accessor foo = 42;

constructor() {
}
}

new Test()

class TestChild extends Test {
@decorate()
accessor bar = 1;

constructor() {
super();
}
}

const r = new TestChild();
@@ -0,0 +1,25 @@
function decorate() {
return function (target, context) {}
}

class Test {
@decorate()
accessor foo = 42;

constructor() {
console.log('hello');
}
}

new Test()

class TestChild extends Test {
@decorate()
accessor bar = 1;

constructor() {
super();
}
}

const r = new TestChild();
@@ -0,0 +1,37 @@
let _init_foo, _init_extra_foo, _init_bar, _init_extra_bar;
function decorate() {
return function (target, context) {};
}
class Test {
static {
[_init_foo, _init_extra_foo] = babelHelpers.applyDecs2311(this, [], [[decorate(), 1, "foo"]]).e;
}
#A = _init_foo(this, 42);
get foo() {
return this.#A;
}
set foo(v) {
this.#A = v;
}
constructor() {
_init_extra_foo(this);
console.log('hello');
}
}
new Test();
class TestChild extends Test {
static {
[_init_bar, _init_extra_bar] = babelHelpers.applyDecs2311(this, [], [[decorate(), 1, "bar"]], 0, void 0, Test).e;
}
#A = _init_bar(this, 1);
get bar() {
return this.#A;
}
set bar(v) {
this.#A = v;
}
constructor() {
super(), _init_extra_bar(this);
}
}
const r = new TestChild();
@@ -0,0 +1,24 @@
function decorate() {
return function (target, context) {}
}

class Test {
@decorate()
accessor foo = 42;

constructor() {
}
}

new Test()

class TestChild extends Test {
@decorate()
accessor bar = 1;

constructor() {
super();
}
}

const r = new TestChild();
@@ -0,0 +1,25 @@
function decorate() {
return function (target, context) {}
}

class Test {
@decorate()
accessor foo = 42;

constructor() {
console.log('hello');
}
}

new Test()

class TestChild extends Test {
@decorate()
accessor bar = 1;

constructor() {
super();
}
}

const r = new TestChild();
@@ -0,0 +1,37 @@
let _init_foo, _init_extra_foo, _init_bar, _init_extra_bar;
function decorate() {
return function (target, context) {};
}
class Test {
static {
[_init_foo, _init_extra_foo] = babelHelpers.applyDecs2311(this, [], [[decorate(), 1, "foo"]]).e;
}
#A = _init_foo(this, 42);
get foo() {
return this.#A;
}
set foo(v) {
this.#A = v;
}
constructor() {
_init_extra_foo(this);
console.log('hello');
}
}
new Test();
class TestChild extends Test {
static {
[_init_bar, _init_extra_bar] = babelHelpers.applyDecs2311(this, [], [[decorate(), 1, "bar"]], 0, void 0, Test).e;
}
#A = _init_bar(this, 1);
get bar() {
return this.#A;
}
set bar(v) {
this.#A = v;
}
constructor() {
super(), _init_extra_bar(this);
}
}
const r = new TestChild();

0 comments on commit 4d53402

Please sign in to comment.