Skip to content

Commit ba548df

Browse files
committed
move decorator initializer list to after the class
1 parent 66b7c6d commit ba548df

File tree

5 files changed

+192
-192
lines changed

5 files changed

+192
-192
lines changed

internal/bundler_tests/snapshots/snapshots_lower.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -624,34 +624,33 @@ TestJavaScriptDecoratorsBundleIssue3768
624624
---------- /out/base-instance-accessor.js ----------
625625
// base-instance-accessor.js
626626
var _foo_dec, _init, _foo;
627-
_init = [, , ,];
628627
_foo_dec = [dec];
629628
var _Foo = class _Foo {
630629
constructor() {
631630
__privateAdd(this, _foo, __runInitializers(_init, 6, this, _Foo)), __runInitializers(_init, 9, this);
632631
}
633632
};
633+
_init = [, , ,];
634634
_foo = new WeakMap();
635635
__decorateElement(_init, 4, "foo", _foo_dec, _Foo, _foo);
636636
var Foo = _Foo;
637637

638638
---------- /out/base-instance-field.js ----------
639639
// base-instance-field.js
640640
var _foo_dec, _init;
641-
_init = [, , ,];
642641
_foo_dec = [dec];
643642
var _Foo = class _Foo {
644643
constructor() {
645644
__publicField(this, "foo", __runInitializers(_init, 6, this, _Foo)), __runInitializers(_init, 9, this);
646645
}
647646
};
647+
_init = [, , ,];
648648
__decorateElement(_init, 5, "foo", _foo_dec, _Foo);
649649
var Foo = _Foo;
650650

651651
---------- /out/base-instance-method.js ----------
652652
// base-instance-method.js
653653
var _foo_dec, _init;
654-
_init = [, , ,];
655654
_foo_dec = [dec];
656655
var _Foo = class _Foo {
657656
constructor() {
@@ -661,16 +660,17 @@ var _Foo = class _Foo {
661660
return _Foo;
662661
}
663662
};
663+
_init = [, , ,];
664664
__decorateElement(_init, 1, "foo", _foo_dec, _Foo);
665665
var Foo = _Foo;
666666

667667
---------- /out/base-static-accessor.js ----------
668668
// base-static-accessor.js
669669
var _foo_dec, _init, _foo;
670-
_init = [, , ,];
671670
_foo_dec = [dec];
672671
var _Foo = class _Foo {
673672
};
673+
_init = [, , ,];
674674
_foo = new WeakMap();
675675
__decorateElement(_init, 12, "foo", _foo_dec, _Foo, _foo);
676676
__privateAdd(_Foo, _foo, __runInitializers(_init, 6, _Foo, _Foo)), __runInitializers(_init, 9, _Foo);
@@ -679,59 +679,58 @@ var Foo = _Foo;
679679
---------- /out/base-static-field.js ----------
680680
// base-static-field.js
681681
var _foo_dec, _init;
682-
_init = [, , ,];
683682
_foo_dec = [dec];
684683
var _Foo = class _Foo {
685684
};
685+
_init = [, , ,];
686686
__decorateElement(_init, 13, "foo", _foo_dec, _Foo);
687687
__publicField(_Foo, "foo", __runInitializers(_init, 6, _Foo, _Foo)), __runInitializers(_init, 9, _Foo);
688688
var Foo = _Foo;
689689

690690
---------- /out/base-static-method.js ----------
691691
// base-static-method.js
692692
var _foo_dec, _init;
693-
_init = [, , ,];
694693
_foo_dec = [dec];
695694
var _Foo = class _Foo {
696695
static foo() {
697696
return _Foo;
698697
}
699698
};
699+
_init = [, , ,];
700700
__decorateElement(_init, 9, "foo", _foo_dec, _Foo);
701701
__runInitializers(_init, 3, _Foo);
702702
var Foo = _Foo;
703703

704704
---------- /out/derived-instance-accessor.js ----------
705705
// derived-instance-accessor.js
706706
var _foo_dec, _a, _init, _foo;
707-
_init = [, , ,];
708707
var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
709708
constructor() {
710709
super(...arguments);
711710
__privateAdd(this, _foo, __runInitializers(_init, 6, this, _Foo)), __runInitializers(_init, 9, this);
712711
}
713712
};
713+
_init = [, , ,];
714714
_foo = new WeakMap();
715715
__decorateElement(_init, 4, "foo", _foo_dec, _Foo, _foo);
716716
var Foo = _Foo;
717717

718718
---------- /out/derived-instance-field.js ----------
719719
// derived-instance-field.js
720720
var _foo_dec, _a, _init;
721-
_init = [, , ,];
722721
var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
723722
constructor() {
724723
super(...arguments);
725724
__publicField(this, "foo", __runInitializers(_init, 6, this, _Foo)), __runInitializers(_init, 9, this);
726725
}
727726
};
727+
_init = [, , ,];
728728
__decorateElement(_init, 5, "foo", _foo_dec, _Foo);
729729
var Foo = _Foo;
730730

731731
---------- /out/derived-instance-method.js ----------
732732
// derived-instance-method.js
733733
var _foo_dec, _a, _init;
734-
_init = [, , ,];
735734
var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
736735
constructor() {
737736
super(...arguments);
@@ -741,15 +740,16 @@ var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
741740
return _Foo;
742741
}
743742
};
743+
_init = [, , ,];
744744
__decorateElement(_init, 1, "foo", _foo_dec, _Foo);
745745
var Foo = _Foo;
746746

747747
---------- /out/derived-static-accessor.js ----------
748748
// derived-static-accessor.js
749749
var _foo_dec, _a, _init, _foo;
750-
_init = [, , ,];
751750
var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
752751
};
752+
_init = [, , ,];
753753
_foo = new WeakMap();
754754
__decorateElement(_init, 12, "foo", _foo_dec, _Foo, _foo);
755755
__privateAdd(_Foo, _foo, __runInitializers(_init, 6, _Foo, _Foo)), __runInitializers(_init, 9, _Foo);
@@ -758,22 +758,22 @@ var Foo = _Foo;
758758
---------- /out/derived-static-field.js ----------
759759
// derived-static-field.js
760760
var _foo_dec, _a, _init;
761-
_init = [, , ,];
762761
var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
763762
};
763+
_init = [, , ,];
764764
__decorateElement(_init, 13, "foo", _foo_dec, _Foo);
765765
__publicField(_Foo, "foo", __runInitializers(_init, 6, _Foo, _Foo)), __runInitializers(_init, 9, _Foo);
766766
var Foo = _Foo;
767767

768768
---------- /out/derived-static-method.js ----------
769769
// derived-static-method.js
770770
var _foo_dec, _a, _init;
771-
_init = [, , ,];
772771
var _Foo = class _Foo extends (_a = Bar, _foo_dec = [dec], _a) {
773772
static foo() {
774773
return _Foo;
775774
}
776775
};
776+
_init = [, , ,];
777777
__decorateElement(_init, 9, "foo", _foo_dec, _Foo);
778778
__runInitializers(_init, 3, _Foo);
779779
var Foo = _Foo;

internal/js_parser/js_parser_lower_class.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,7 @@ func (ctx *lowerClassContext) finishAndGenerateCode(p *parser, result visitClass
21452145

21462146
// If there are JavaScript decorators, start by allocating a context object
21472147
if ctx.decoratorContextRef != ast.InvalidRef {
2148-
prefixExprs = append(prefixExprs, js_ast.Assign(
2148+
suffixExprs = append(suffixExprs, js_ast.Assign(
21492149
js_ast.Expr{Loc: ctx.classLoc, Data: &js_ast.EIdentifier{Ref: ctx.decoratorContextRef}},
21502150
js_ast.Expr{Loc: ctx.classLoc, Data: &js_ast.EArray{IsSingleLine: true, Items: []js_ast.Expr{
21512151
{Loc: ctx.classLoc, Data: js_ast.EMissingShared}, // classExtraInitializers

internal/js_parser/js_parser_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,27 +2074,26 @@ func TestDecorators(t *testing.T) {
20742074

20752075
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "@dec class Foo {}",
20762076
`var _Foo_decorators, _init;
2077-
_init = [, , ,];
20782077
_Foo_decorators = [dec];
20792078
class Foo {
20802079
}
2080+
_init = [, , ,];
20812081
Foo = __decorateElement(_init, 0, "Foo", _Foo_decorators, Foo);
20822082
__runInitializers(_init, 1, Foo);
20832083
`)
20842084
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "class Foo { @dec x }",
20852085
`var _x_dec, _init;
2086-
_init = [, , ,];
20872086
_x_dec = [dec];
20882087
class Foo {
20892088
constructor() {
20902089
__publicField(this, "x", __runInitializers(_init, 6, this)), __runInitializers(_init, 9, this);
20912090
}
20922091
}
2092+
_init = [, , ,];
20932093
__decorateElement(_init, 5, "x", _x_dec, Foo);
20942094
`)
20952095
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "class Foo { @dec x() {} }",
20962096
`var _x_dec, _init;
2097-
_init = [, , ,];
20982097
_x_dec = [dec];
20992098
class Foo {
21002099
constructor() {
@@ -2103,46 +2102,47 @@ class Foo {
21032102
x() {
21042103
}
21052104
}
2105+
_init = [, , ,];
21062106
__decorateElement(_init, 1, "x", _x_dec, Foo);
21072107
`)
21082108
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "class Foo { @dec accessor x }",
21092109
`var _x_dec, _init, _x;
2110-
_init = [, , ,];
21112110
_x_dec = [dec];
21122111
class Foo {
21132112
constructor() {
21142113
__privateAdd(this, _x, __runInitializers(_init, 6, this)), __runInitializers(_init, 9, this);
21152114
}
21162115
}
2116+
_init = [, , ,];
21172117
_x = new WeakMap();
21182118
__decorateElement(_init, 4, "x", _x_dec, Foo, _x);
21192119
`)
21202120
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "class Foo { @dec static x }",
21212121
`var _x_dec, _init;
2122-
_init = [, , ,];
21232122
_x_dec = [dec];
21242123
class Foo {
21252124
}
2125+
_init = [, , ,];
21262126
__decorateElement(_init, 13, "x", _x_dec, Foo);
21272127
__publicField(Foo, "x", __runInitializers(_init, 6, Foo)), __runInitializers(_init, 9, Foo);
21282128
`)
21292129
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "class Foo { @dec static x() {} }",
21302130
`var _x_dec, _init;
2131-
_init = [, , ,];
21322131
_x_dec = [dec];
21332132
class Foo {
21342133
static x() {
21352134
}
21362135
}
2136+
_init = [, , ,];
21372137
__decorateElement(_init, 9, "x", _x_dec, Foo);
21382138
__runInitializers(_init, 3, Foo);
21392139
`)
21402140
expectPrintedWithUnsupportedFeatures(t, compat.Decorators, "class Foo { @dec static accessor x }",
21412141
`var _x_dec, _init, _x;
2142-
_init = [, , ,];
21432142
_x_dec = [dec];
21442143
class Foo {
21452144
}
2145+
_init = [, , ,];
21462146
_x = new WeakMap();
21472147
__decorateElement(_init, 12, "x", _x_dec, Foo, _x);
21482148
__privateAdd(Foo, _x, __runInitializers(_init, 6, Foo)), __runInitializers(_init, 9, Foo);

internal/js_parser/ts_parser_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,27 +2119,26 @@ func TestTSDecorators(t *testing.T) {
21192119

21202120
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "@dec class Foo {}",
21212121
`var _Foo_decorators, _init;
2122-
_init = [, , ,];
21232122
_Foo_decorators = [dec];
21242123
class Foo {
21252124
}
2125+
_init = [, , ,];
21262126
Foo = __decorateElement(_init, 0, "Foo", _Foo_decorators, Foo);
21272127
__runInitializers(_init, 1, Foo);
21282128
`)
21292129
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "class Foo { @dec x }",
21302130
`var _x_dec, _init;
2131-
_init = [, , ,];
21322131
_x_dec = [dec];
21332132
class Foo {
21342133
constructor() {
21352134
__publicField(this, "x", __runInitializers(_init, 6, this)), __runInitializers(_init, 9, this);
21362135
}
21372136
}
2137+
_init = [, , ,];
21382138
__decorateElement(_init, 5, "x", _x_dec, Foo);
21392139
`)
21402140
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "class Foo { @dec x() {} }",
21412141
`var _x_dec, _init;
2142-
_init = [, , ,];
21432142
_x_dec = [dec];
21442143
class Foo {
21452144
constructor() {
@@ -2148,46 +2147,47 @@ class Foo {
21482147
x() {
21492148
}
21502149
}
2150+
_init = [, , ,];
21512151
__decorateElement(_init, 1, "x", _x_dec, Foo);
21522152
`)
21532153
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "class Foo { @dec accessor x }",
21542154
`var _x_dec, _init, _x;
2155-
_init = [, , ,];
21562155
_x_dec = [dec];
21572156
class Foo {
21582157
constructor() {
21592158
__privateAdd(this, _x, __runInitializers(_init, 6, this)), __runInitializers(_init, 9, this);
21602159
}
21612160
}
2161+
_init = [, , ,];
21622162
_x = new WeakMap();
21632163
__decorateElement(_init, 4, "x", _x_dec, Foo, _x);
21642164
`)
21652165
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "class Foo { @dec static x }",
21662166
`var _x_dec, _init;
2167-
_init = [, , ,];
21682167
_x_dec = [dec];
21692168
class Foo {
21702169
}
2170+
_init = [, , ,];
21712171
__decorateElement(_init, 13, "x", _x_dec, Foo);
21722172
__publicField(Foo, "x", __runInitializers(_init, 6, Foo)), __runInitializers(_init, 9, Foo);
21732173
`)
21742174
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "class Foo { @dec static x() {} }",
21752175
`var _x_dec, _init;
2176-
_init = [, , ,];
21772176
_x_dec = [dec];
21782177
class Foo {
21792178
static x() {
21802179
}
21812180
}
2181+
_init = [, , ,];
21822182
__decorateElement(_init, 9, "x", _x_dec, Foo);
21832183
__runInitializers(_init, 3, Foo);
21842184
`)
21852185
expectPrintedWithUnsupportedFeaturesTS(t, compat.Decorators, "class Foo { @dec static accessor x }",
21862186
`var _x_dec, _init, _x;
2187-
_init = [, , ,];
21882187
_x_dec = [dec];
21892188
class Foo {
21902189
}
2190+
_init = [, , ,];
21912191
_x = new WeakMap();
21922192
__decorateElement(_init, 12, "x", _x_dec, Foo, _x);
21932193
__privateAdd(Foo, _x, __runInitializers(_init, 6, Foo)), __runInitializers(_init, 9, Foo);

0 commit comments

Comments
 (0)