Skip to content

Commit

Permalink
move decorator initializer list to after the class
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed May 15, 2024
1 parent 66b7c6d commit ba548df
Show file tree
Hide file tree
Showing 5 changed files with 192 additions and 192 deletions.
24 changes: 12 additions & 12 deletions internal/bundler_tests/snapshots/snapshots_lower.txt
Original file line number Diff line number Diff line change
Expand Up @@ -624,34 +624,33 @@ TestJavaScriptDecoratorsBundleIssue3768
---------- /out/base-instance-accessor.js ----------
// base-instance-accessor.js
var _foo_dec, _init, _foo;
_init = [, , ,];
_foo_dec = [dec];
var _Foo = class _Foo {
constructor() {
__privateAdd(this, _foo, __runInitializers(_init, 6, this, _Foo)), __runInitializers(_init, 9, this);
}
};
_init = [, , ,];
_foo = new WeakMap();
__decorateElement(_init, 4, "foo", _foo_dec, _Foo, _foo);
var Foo = _Foo;

---------- /out/base-instance-field.js ----------
// base-instance-field.js
var _foo_dec, _init;
_init = [, , ,];
_foo_dec = [dec];
var _Foo = class _Foo {
constructor() {
__publicField(this, "foo", __runInitializers(_init, 6, this, _Foo)), __runInitializers(_init, 9, this);
}
};
_init = [, , ,];
__decorateElement(_init, 5, "foo", _foo_dec, _Foo);
var Foo = _Foo;

---------- /out/base-instance-method.js ----------
// base-instance-method.js
var _foo_dec, _init;
_init = [, , ,];
_foo_dec = [dec];
var _Foo = class _Foo {
constructor() {
Expand All @@ -661,16 +660,17 @@ var _Foo = class _Foo {
return _Foo;
}
};
_init = [, , ,];
__decorateElement(_init, 1, "foo", _foo_dec, _Foo);
var Foo = _Foo;

---------- /out/base-static-accessor.js ----------
// base-static-accessor.js
var _foo_dec, _init, _foo;
_init = [, , ,];
_foo_dec = [dec];
var _Foo = class _Foo {
};
_init = [, , ,];
_foo = new WeakMap();
__decorateElement(_init, 12, "foo", _foo_dec, _Foo, _foo);
__privateAdd(_Foo, _foo, __runInitializers(_init, 6, _Foo, _Foo)), __runInitializers(_init, 9, _Foo);
Expand All @@ -679,59 +679,58 @@ var Foo = _Foo;
---------- /out/base-static-field.js ----------
// base-static-field.js
var _foo_dec, _init;
_init = [, , ,];
_foo_dec = [dec];
var _Foo = class _Foo {
};
_init = [, , ,];
__decorateElement(_init, 13, "foo", _foo_dec, _Foo);
__publicField(_Foo, "foo", __runInitializers(_init, 6, _Foo, _Foo)), __runInitializers(_init, 9, _Foo);
var Foo = _Foo;

---------- /out/base-static-method.js ----------
// base-static-method.js
var _foo_dec, _init;
_init = [, , ,];
_foo_dec = [dec];
var _Foo = class _Foo {
static foo() {
return _Foo;
}
};
_init = [, , ,];
__decorateElement(_init, 9, "foo", _foo_dec, _Foo);
__runInitializers(_init, 3, _Foo);
var Foo = _Foo;

---------- /out/derived-instance-accessor.js ----------
// derived-instance-accessor.js
var _foo_dec, _a, _init, _foo;
_init = [, , ,];
var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
constructor() {
super(...arguments);
__privateAdd(this, _foo, __runInitializers(_init, 6, this, _Foo)), __runInitializers(_init, 9, this);
}
};
_init = [, , ,];
_foo = new WeakMap();
__decorateElement(_init, 4, "foo", _foo_dec, _Foo, _foo);
var Foo = _Foo;

---------- /out/derived-instance-field.js ----------
// derived-instance-field.js
var _foo_dec, _a, _init;
_init = [, , ,];
var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
constructor() {
super(...arguments);
__publicField(this, "foo", __runInitializers(_init, 6, this, _Foo)), __runInitializers(_init, 9, this);
}
};
_init = [, , ,];
__decorateElement(_init, 5, "foo", _foo_dec, _Foo);
var Foo = _Foo;

---------- /out/derived-instance-method.js ----------
// derived-instance-method.js
var _foo_dec, _a, _init;
_init = [, , ,];
var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
constructor() {
super(...arguments);
Expand All @@ -741,15 +740,16 @@ var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
return _Foo;
}
};
_init = [, , ,];
__decorateElement(_init, 1, "foo", _foo_dec, _Foo);
var Foo = _Foo;

---------- /out/derived-static-accessor.js ----------
// derived-static-accessor.js
var _foo_dec, _a, _init, _foo;
_init = [, , ,];
var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
};
_init = [, , ,];
_foo = new WeakMap();
__decorateElement(_init, 12, "foo", _foo_dec, _Foo, _foo);
__privateAdd(_Foo, _foo, __runInitializers(_init, 6, _Foo, _Foo)), __runInitializers(_init, 9, _Foo);
Expand All @@ -758,22 +758,22 @@ var Foo = _Foo;
---------- /out/derived-static-field.js ----------
// derived-static-field.js
var _foo_dec, _a, _init;
_init = [, , ,];
var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
};
_init = [, , ,];
__decorateElement(_init, 13, "foo", _foo_dec, _Foo);
__publicField(_Foo, "foo", __runInitializers(_init, 6, _Foo, _Foo)), __runInitializers(_init, 9, _Foo);
var Foo = _Foo;

---------- /out/derived-static-method.js ----------
// derived-static-method.js
var _foo_dec, _a, _init;
_init = [, , ,];
var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
static foo() {
return _Foo;
}
};
_init = [, , ,];
__decorateElement(_init, 9, "foo", _foo_dec, _Foo);
__runInitializers(_init, 3, _Foo);
var Foo = _Foo;
Expand Down
2 changes: 1 addition & 1 deletion internal/js_parser/js_parser_lower_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -2145,7 +2145,7 @@ func (ctx *lowerClassContext) finishAndGenerateCode(p *parser, result visitClass

// If there are JavaScript decorators, start by allocating a context object
if ctx.decoratorContextRef != ast.InvalidRef {
prefixExprs = append(prefixExprs, js_ast.Assign(
suffixExprs = append(suffixExprs, js_ast.Assign(
js_ast.Expr{Loc: ctx.classLoc, Data: &js_ast.EIdentifier{Ref: ctx.decoratorContextRef}},
js_ast.Expr{Loc: ctx.classLoc, Data: &js_ast.EArray{IsSingleLine: true, Items: []js_ast.Expr{
{Loc: ctx.classLoc, Data: js_ast.EMissingShared}, // classExtraInitializers
Expand Down
14 changes: 7 additions & 7 deletions internal/js_parser/js_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2074,27 +2074,26 @@ func TestDecorators(t *testing.T) {

expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "@dec class Foo {}",
`var _Foo_decorators, _init;
_init = [, , ,];
_Foo_decorators = [dec];
class Foo {
}
_init = [, , ,];
Foo = __decorateElement(_init, 0, "Foo", _Foo_decorators, Foo);
__runInitializers(_init, 1, Foo);
`)
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "class Foo { @dec x }",
`var _x_dec, _init;
_init = [, , ,];
_x_dec = [dec];
class Foo {
constructor() {
__publicField(this, "x", __runInitializers(_init, 6, this)), __runInitializers(_init, 9, this);
}
}
_init = [, , ,];
__decorateElement(_init, 5, "x", _x_dec, Foo);
`)
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "class Foo { @dec x() {} }",
`var _x_dec, _init;
_init = [, , ,];
_x_dec = [dec];
class Foo {
constructor() {
Expand All @@ -2103,46 +2102,47 @@ class Foo {
x() {
}
}
_init = [, , ,];
__decorateElement(_init, 1, "x", _x_dec, Foo);
`)
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "class Foo { @dec accessor x }",
`var _x_dec, _init, _x;
_init = [, , ,];
_x_dec = [dec];
class Foo {
constructor() {
__privateAdd(this, _x, __runInitializers(_init, 6, this)), __runInitializers(_init, 9, this);
}
}
_init = [, , ,];
_x = new WeakMap();
__decorateElement(_init, 4, "x", _x_dec, Foo, _x);
`)
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "class Foo { @dec static x }",
`var _x_dec, _init;
_init = [, , ,];
_x_dec = [dec];
class Foo {
}
_init = [, , ,];
__decorateElement(_init, 13, "x", _x_dec, Foo);
__publicField(Foo, "x", __runInitializers(_init, 6, Foo)), __runInitializers(_init, 9, Foo);
`)
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "class Foo { @dec static x() {} }",
`var _x_dec, _init;
_init = [, , ,];
_x_dec = [dec];
class Foo {
static x() {
}
}
_init = [, , ,];
__decorateElement(_init, 9, "x", _x_dec, Foo);
__runInitializers(_init, 3, Foo);
`)
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "class Foo { @dec static accessor x }",
`var _x_dec, _init, _x;
_init = [, , ,];
_x_dec = [dec];
class Foo {
}
_init = [, , ,];
_x = new WeakMap();
__decorateElement(_init, 12, "x", _x_dec, Foo, _x);
__privateAdd(Foo, _x, __runInitializers(_init, 6, Foo)), __runInitializers(_init, 9, Foo);
Expand Down
14 changes: 7 additions & 7 deletions internal/js_parser/ts_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2119,27 +2119,26 @@ func TestTSDecorators(t *testing.T) {

expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "@dec class Foo {}",
`var _Foo_decorators, _init;
_init = [, , ,];
_Foo_decorators = [dec];
class Foo {
}
_init = [, , ,];
Foo = __decorateElement(_init, 0, "Foo", _Foo_decorators, Foo);
__runInitializers(_init, 1, Foo);
`)
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "class Foo { @dec x }",
`var _x_dec, _init;
_init = [, , ,];
_x_dec = [dec];
class Foo {
constructor() {
__publicField(this, "x", __runInitializers(_init, 6, this)), __runInitializers(_init, 9, this);
}
}
_init = [, , ,];
__decorateElement(_init, 5, "x", _x_dec, Foo);
`)
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "class Foo { @dec x() {} }",
`var _x_dec, _init;
_init = [, , ,];
_x_dec = [dec];
class Foo {
constructor() {
Expand All @@ -2148,46 +2147,47 @@ class Foo {
x() {
}
}
_init = [, , ,];
__decorateElement(_init, 1, "x", _x_dec, Foo);
`)
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "class Foo { @dec accessor x }",
`var _x_dec, _init, _x;
_init = [, , ,];
_x_dec = [dec];
class Foo {
constructor() {
__privateAdd(this, _x, __runInitializers(_init, 6, this)), __runInitializers(_init, 9, this);
}
}
_init = [, , ,];
_x = new WeakMap();
__decorateElement(_init, 4, "x", _x_dec, Foo, _x);
`)
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "class Foo { @dec static x }",
`var _x_dec, _init;
_init = [, , ,];
_x_dec = [dec];
class Foo {
}
_init = [, , ,];
__decorateElement(_init, 13, "x", _x_dec, Foo);
__publicField(Foo, "x", __runInitializers(_init, 6, Foo)), __runInitializers(_init, 9, Foo);
`)
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "class Foo { @dec static x() {} }",
`var _x_dec, _init;
_init = [, , ,];
_x_dec = [dec];
class Foo {
static x() {
}
}
_init = [, , ,];
__decorateElement(_init, 9, "x", _x_dec, Foo);
__runInitializers(_init, 3, Foo);
`)
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "class Foo { @dec static accessor x }",
`var _x_dec, _init, _x;
_init = [, , ,];
_x_dec = [dec];
class Foo {
}
_init = [, , ,];
_x = new WeakMap();
__decorateElement(_init, 12, "x", _x_dec, Foo, _x);
__privateAdd(Foo, _x, __runInitializers(_init, 6, Foo)), __runInitializers(_init, 9, Foo);
Expand Down
Loading

0 comments on commit ba548df

Please sign in to comment.