fix(es/compat): Fix the position of inserted statements in class_properties (#4511)

This commit is contained in:
Austaras 2022-05-04 11:13:38 +08:00 committed by GitHub
parent 97e0e271d5
commit 9e45882b84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 100 additions and 93 deletions

View File

@ -1,4 +1,5 @@
import * as swcHelpers from "@swc/helpers";
var _Reflect, __, _Reflect1, __1;
class Reflect1 {
}
// @target: es5, es2015, es2021, es2022, esnext
@ -66,7 +67,7 @@ C._ = [
swcHelpers.get(swcHelpers.getPrototypeOf(C), "w", C).call(C);
})(),
];
var __32 = {
var __2 = {
writable: true,
value: (()=>{
var { Reflect } = {
@ -75,7 +76,7 @@ var __32 = {
super.w();
})()
};
var __1 = {
var __111 = {
writable: true,
value: (()=>{
var [Reflect] = [
@ -410,21 +411,20 @@ _Reflect = class Reflect {
C1._ = swcHelpers.get(swcHelpers.getPrototypeOf(C1), "w", C1).call(C1);
})()
}, _Reflect;
_Reflect = class Reflect {
}, __ = {
_Reflect1 = class Reflect {
}, __1 = {
writable: true,
value: (()=>{
var _Reflect, __;
class C extends B {
}
var __33 = {
var __ = {
writable: true,
value: (()=>{
super.w();
})()
};
})()
}, _Reflect;
}, _Reflect1;
(function Reflect() {}); // no collision
class C extends B {
}
@ -439,7 +439,6 @@ var __31 = {
})()
};
(function Reflect() {
var _Reflect, __;
class C2 extends B {
}
C2._ = swcHelpers.get(swcHelpers.getPrototypeOf(C2), "w", C2).call(C2);

View File

@ -171,22 +171,11 @@ class C extends B {
C._ = swcHelpers.get(swcHelpers.getPrototypeOf(C), "w", C).call(C);
class C extends B {
}
super.w(), _Reflect = class {
}, __ = {
writable: !0,
value: (()=>{
class C1 extends B {
}
C1._ = swcHelpers.get(swcHelpers.getPrototypeOf(C1), "w", C1).call(C1);
})()
}, _Reflect = class {
}, __ = {
writable: !0,
value: (()=>{
var _Reflect, __;
super.w();
})()
};
super.w(), (()=>{
class C1 extends B {
}
C1._ = swcHelpers.get(swcHelpers.getPrototypeOf(C1), "w", C1).call(C1);
})(), super.w();
class C extends B {
}
C._ = swcHelpers.get(swcHelpers.getPrototypeOf(C), "w", C).call(C);

View File

@ -1,6 +1,7 @@
import * as swcHelpers from "@swc/helpers";
var _this = this, _superprop_get_w = ()=>super.w
;
var _Reflect, __, _Reflect1, __1;
// @target: es5, es2015, es2021, es2022, esnext
// @noTypesAndSymbols: true
// @filename: external.ts
@ -83,7 +84,7 @@ C._ = [
swcHelpers.get(swcHelpers.getPrototypeOf(C), "w", C).call(C);
}(),
];
var _$__22 = {
var __2 = {
writable: true,
value: function() {
var Reflect = {
@ -92,7 +93,7 @@ var _$__22 = {
_superprop_get_w().call(_this);
}()
};
var __1 = {
var __111 = {
writable: true,
value: function() {
var Reflect = null; // collision (es2015-es2021 only)
@ -223,7 +224,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__1 = {
var __11 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -242,7 +243,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__2 = {
var __12 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -259,7 +260,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__3 = {
var __13 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -296,7 +297,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__4 = {
var __14 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -325,7 +326,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__5 = {
var __15 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -352,7 +353,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__6 = {
var __16 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -381,7 +382,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__7 = {
var __17 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -410,7 +411,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__8 = {
var __18 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -437,7 +438,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__9 = {
var __19 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -464,7 +465,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__10 = {
var __20 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -491,7 +492,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__11 = {
var __21 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -518,7 +519,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__12 = {
var __22 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -545,7 +546,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__13 = {
var __23 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -572,7 +573,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__14 = {
var __24 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -599,7 +600,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__15 = {
var __25 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -626,7 +627,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__16 = {
var __26 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -653,7 +654,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__17 = {
var __27 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -680,7 +681,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__18 = {
var __28 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -707,7 +708,7 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__19 = {
var __29 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
@ -742,16 +743,16 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__20 = {
var __30 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
}()
};
_$_Reflect = function Reflect() {
_Reflect = function Reflect() {
"use strict";
swcHelpers.classCallCheck(this, Reflect);
}, _$__ = {
}, __ = {
writable: true,
value: function() {
var C = /*#__PURE__*/ function(B) {
@ -766,16 +767,15 @@ _$_Reflect = function Reflect() {
}(B);
C._ = swcHelpers.get(swcHelpers.getPrototypeOf(C), "w", C).call(C);
}()
}, _$_Reflect;
_$_Reflect = function Reflect() {
}, _Reflect;
_Reflect1 = function Reflect() {
"use strict";
swcHelpers.classCallCheck(this, Reflect);
}, _$__ = {
}, __1 = {
writable: true,
value: function() {
var _this1 = _this, _superprop_get_w1 = ()=>_superprop_get_w()
;
var _$_Reflect, _$__;
var C = /*#__PURE__*/ function(B) {
"use strict";
swcHelpers.inherits(C, B);
@ -786,14 +786,14 @@ _$_Reflect = function Reflect() {
}
return C;
}(B);
var _$__23 = {
var __ = {
writable: true,
value: function() {
_superprop_get_w1().call(_this1);
}()
};
}()
}, _$_Reflect;
}, _Reflect1;
(function Reflect() {}); // no collision
var C = /*#__PURE__*/ function(B) {
"use strict";
@ -817,14 +817,13 @@ var C = /*#__PURE__*/ function(B) {
}
return C;
}(B);
var _$__21 = {
var __31 = {
writable: true,
value: function() {
_superprop_get_w().call(_this);
}()
};
(function Reflect() {
var _$_Reflect, _$__;
var C = /*#__PURE__*/ function(B) {
"use strict";
swcHelpers.inherits(C, B);
@ -850,7 +849,7 @@ var _$__21 = {
}
return C;
}(B);
var _$__ = {
var __ = {
writable: true,
value: function() {
_superprop_get_w2().call(_this2);

View File

@ -464,41 +464,29 @@ var C = function(B) {
}
return C;
}(B);
_superprop_get_w().call(_this), _$_Reflect = function Reflect7() {
"use strict";
swcHelpers.classCallCheck(this, Reflect7);
}, _$__ = {
writable: !0,
value: function() {
var C = function(B) {
"use strict";
swcHelpers.inherits(C, B);
var _super = swcHelpers.createSuper(C);
function C() {
return swcHelpers.classCallCheck(this, C), _super.apply(this, arguments);
}
return C;
}(B);
C._ = swcHelpers.get(swcHelpers.getPrototypeOf(C), "w", C).call(C);
}()
}, _$_Reflect = function Reflect8() {
"use strict";
swcHelpers.classCallCheck(this, Reflect8);
}, _$__ = {
writable: !0,
value: function() {
var _$_Reflect, _$__, C = function(B) {
"use strict";
swcHelpers.inherits(C, B);
var _super = swcHelpers.createSuper(C);
function C() {
return swcHelpers.classCallCheck(this, C), _super.apply(this, arguments);
}
return C;
}(B);
_superprop_get_w().call(_this);
}()
};
_superprop_get_w().call(_this), function() {
var C = function(B) {
"use strict";
swcHelpers.inherits(C, B);
var _super = swcHelpers.createSuper(C);
function C() {
return swcHelpers.classCallCheck(this, C), _super.apply(this, arguments);
}
return C;
}(B);
C._ = swcHelpers.get(swcHelpers.getPrototypeOf(C), "w", C).call(C);
}(), function() {
var C = function(B) {
"use strict";
swcHelpers.inherits(C, B);
var _super = swcHelpers.createSuper(C);
function C() {
return swcHelpers.classCallCheck(this, C), _super.apply(this, arguments);
}
return C;
}(B);
_superprop_get_w().call(_this);
}();
var C = function(B) {
"use strict";
swcHelpers.inherits(C, B);

View File

@ -157,9 +157,12 @@ impl<C: Comments> VisitMut for ClassProperties<C> {
}
fn visit_mut_stmts(&mut self, n: &mut Vec<Stmt>) {
let old = self.extra.take();
self.visit_mut_stmt_like(n);
self.extra.take().prepend_with(n)
self.extra.take().prepend_with(n);
self.extra = old;
}
fn visit_mut_block_stmt_or_expr(&mut self, body: &mut BlockStmtOrExpr) {

View File

@ -5965,6 +5965,35 @@ var _prop2 = {
"
);
test!(
syntax(),
|t| class_properties(Some(t.comments.clone()), Default::default()),
issue_4473,
"
var test1 = class X {
[Symbol.toStringTag]() {}
}
function a() {
const b = class Y {
x() {
}
}
}
",
"
let _toStringTag;
var test1 = (_toStringTag = Symbol.toStringTag, class X {
[_toStringTag]() {}
});
function a() {
const b = class Y {
x() {}
};
}
"
);
test!(
syntax(),
|t| class_properties(