Skip to content

Commit

Permalink
Fix super in decorators
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Apr 16, 2023
1 parent cc101de commit a8e3d69
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 4 deletions.
Expand Up @@ -585,10 +585,19 @@ function transformClass(
const maybeExtractDecorator = (decorator: t.Decorator) => {
const { expression } = decorator;
if (version === "2023-03" && t.isMemberExpression(expression)) {
if (!scopeParent.isStatic(expression)) {
expression.object = memoiseExpression(expression.object, "obj");
let object;
if (
t.isSuper(expression.object) ||
t.isThisExpression(expression.object)
) {
object = memoiseExpression(t.thisExpression(), "obj");
} else if (!scopeParent.isStatic(expression)) {
object = memoiseExpression(expression.object, "obj");
expression.object = object;
} else {
object = expression.object;
}
decoratorsThis.set(decorator, t.cloneNode(expression.object));
decoratorsThis.set(decorator, t.cloneNode(object));
}
if (!scopeParent.isStatic(expression)) {
decorator.expression = memoiseExpression(expression, "dec");
Expand Down
@@ -0,0 +1,9 @@
class A extends B {
m() {
@(super.dec1)
class C {
@(super.dec2)
m2() {}
}
}
}
@@ -0,0 +1,21 @@
class A extends B {
m() {
var _initClass, _obj, _dec, _obj2, _dec2, _initProto;
let _C;
_obj = this;
_dec = super.dec1;
_obj2 = this;
_dec2 = super.dec2;
class C {
constructor(...args) {
_initProto(this);
}
m2() {}
}
({
e: [_initProto],
c: [_C, _initClass]
} = babelHelpers.applyDecs2303(C, [[[1, _obj2, _dec2], 2, "m2"]], [1, _obj, _dec]));
_initClass();
}
}
@@ -0,0 +1,9 @@
class A extends B {
m() {
@(super.dec1)
class C {
@(super.dec2)
m2() {}
}
}
}
@@ -0,0 +1,25 @@
class A extends B {
m() {
var _initClass, _obj, _dec, _obj2, _dec2, _initProto;
let _C;
_obj = this;
_dec = super.dec1;
_obj2 = this;
_dec2 = super.dec2;
class C {
static {
({
e: [_initProto],
c: [_C, _initClass]
} = babelHelpers.applyDecs2303(this, [[[1, _obj2, _dec2], 2, "m2"]], [1, _obj, _dec]));
}
constructor(...args) {
_initProto(this);
}
m2() {}
static {
_initClass();
}
}
}
}
Expand Up @@ -25,7 +25,7 @@ class Foo {
method() {}
makeClass() {
var _obj3, _dec9, _init_bar;
return _obj3 = this, _dec9 = _obj3.#a, class Nested {
return _obj3 = this, _dec9 = this.#a, class Nested {
static {
[_init_bar] = babelHelpers.applyDecs2303(this, [[[1, _obj3, _dec9], 0, "bar"]], []).e;
}
Expand Down

0 comments on commit a8e3d69

Please sign in to comment.