Skip to content

Commit

Permalink
fix: move insertBefore after path queries
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Feb 7, 2022
1 parent 46214a1 commit 3f5e0c6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
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 {
static {
[_init_bar] = babelHelpers.applyDecs(this, [[this.#a, 0, "bar"]], []);
[_init_bar] = babelHelpers.applyDecs(this, [[_dec9, 0, "bar"]], []);
}
bar = _init_bar(this);
};
Expand Down

0 comments on commit 3f5e0c6

Please sign in to comment.