Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2021-12 decorators application order #14244

Merged
merged 15 commits into from Feb 8, 2022
Expand Up @@ -753,8 +753,6 @@ function transformClass(
}
}

path.insertBefore(assignments);

const elementDecorations = generateDecorationExprs(elementDecoratorInfo);
const classDecorations = t.arrayExpression(
(classDecorators || []).map(d => d.expression),
Expand Down Expand Up @@ -976,6 +974,10 @@ function transformClass(
),
);

// When path is a ClassExpression, path.insertBefore will convert `path`
// into a SequenceExpression
path.insertBefore(assignments);

// Recrawl the scope to make sure new identifiers are properly synced
path.scope.crawl();

Expand Down
@@ -1,7 +1,18 @@
var _initClass, _initProto;
var _initClass, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _initProto;

const dec = () => {};

let _Foo;

_dec = call()
_dec2 = chain.expr()
_dec3 = arbitrary + expr
_dec4 = array[expr]
_dec5 = call()
_dec6 = chain.expr()
_dec7 = arbitrary + expr
_dec8 = array[expr]

var _a = /*#__PURE__*/new WeakMap();

class Foo {
Expand All @@ -17,22 +28,22 @@ class Foo {
method() {}

makeClass() {
var _init_bar, _class, _temp;
var _dec9, _init_bar, _class, _temp;

return _temp = _class = class Nested {
return _dec9 = babelHelpers.classPrivateFieldGet(this, _a), (_temp = _class = class Nested {
constructor() {
babelHelpers.defineProperty(this, "bar", _init_bar(this));
}

}, (() => {
[_init_bar] = babelHelpers.applyDecs(_class, [[babelHelpers.classPrivateFieldGet(_class, _a), 0, "bar"]], []);
})(), _temp;
[_init_bar] = babelHelpers.applyDecs(_class, [[_dec9, 0, "bar"]], []);
})(), _temp);
}

}

(() => {
[_initProto, _Foo, _initClass] = babelHelpers.applyDecs(Foo, [[[dec, call(), chain.expr(), arbitrary + expr, array[expr]], 2, "method"]], [dec, call(), chain.expr(), arbitrary + expr, array[expr]]);
[_initProto, _Foo, _initClass] = babelHelpers.applyDecs(Foo, [[[dec, _dec5, _dec6, _dec7, _dec8], 2, "method"]], [dec, _dec, _dec2, _dec3, _dec4]);
})();

(() => {
Expand Down
@@ -1,10 +1,21 @@
var _initClass, _initProto;
var _initClass, _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _initProto;

const dec = () => {};

let _Foo;

_dec = call()
_dec2 = chain.expr()
_dec3 = arbitrary + expr
_dec4 = array[expr]
_dec5 = call()
_dec6 = chain.expr()
_dec7 = arbitrary + expr
_dec8 = array[expr]

class Foo {
static {
[_initProto, _Foo, _initClass] = babelHelpers.applyDecs(this, [[[dec, call(), chain.expr(), arbitrary + expr, array[expr]], 2, "method"]], [dec, call(), chain.expr(), arbitrary + expr, array[expr]]);
[_initProto, _Foo, _initClass] = babelHelpers.applyDecs(this, [[[dec, _dec5, _dec6, _dec7, _dec8], 2, "method"]], [dec, _dec, _dec2, _dec3, _dec4]);
}

constructor(...args) {
Expand All @@ -16,11 +27,11 @@ class Foo {
method() {}

makeClass() {
var _init_bar;
var _dec9, _init_bar;

return class Nested {
return _dec9 = this.#a, class Nested {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The evaluation scope issue is also captured in this test. this.#a should be evaluated under makeClass.

static {
[_init_bar] = babelHelpers.applyDecs(this, [[this.#a, 0, "bar"]], []);
[_init_bar] = babelHelpers.applyDecs(this, [[_dec9, 0, "bar"]], []);
}
bar = _init_bar(this);
};
Expand Down