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(es/proposal): Fix var placement for using transform #8732

Merged
merged 22 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8629/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"target": "es2015",
"loose": false,
"minify": {
"compress": false,
"mangle": false
},
"transform": {
"decoratorVersion": "2022-03"
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}
9 changes: 9 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8629/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export class Disposable {
[Symbol.dispose]() {
console.log('dispose')
}
}

using _disposable = new Disposable()

console.log('ok')
5 changes: 5 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8629/input/2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export var Disposable = 1334

using _disposable = new Disposable()

console.log('ok')
22 changes: 22 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8629/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { _ as _dispose } from "@swc/helpers/_/_dispose";
import { _ as _using } from "@swc/helpers/_/_using";
var _Disposable;
try {
var _stack = [];
var _computedKey;
_computedKey = Symbol.dispose;
class Disposable {
[_computedKey]() {
console.log('dispose');
}
}
_Disposable = Disposable;
var _disposable = _using(_stack, new Disposable());
console.log('ok');
} catch (_) {
var _error = _;
var _hasError = true;
} finally{
_dispose(_stack, _error, _hasError);
}
export { _Disposable as Disposable };
16 changes: 16 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8629/output/2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { _ as _dispose } from "@swc/helpers/_/_dispose";
import { _ as _using } from "@swc/helpers/_/_using";
var _Disposable;
try {
var _stack = [];
var Disposable = 1334;
_Disposable = Disposable;
var _disposable = _using(_stack, new Disposable());
console.log('ok');
} catch (_) {
var _error = _;
var _hasError = true;
} finally{
_dispose(_stack, _error, _hasError);
}
export { _Disposable as Disposable };
1 change: 0 additions & 1 deletion crates/swc_ecma_compat_es2015/src/classes/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ pub(super) fn replace_this_in_constructor(mark: Mark, c: &mut Constructor) -> bo
wrap_with_assertion: bool,
}

#[swc_trace]
impl VisitMut for Replacer {
noop_visit_mut_type!();

Expand Down
253 changes: 0 additions & 253 deletions crates/swc_ecma_transforms_compat/tests/es2015_classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2617,141 +2617,6 @@ class Foo extends Bar {
"#
);

//// regression_3028
//test!(
// syntax(),
// |_| tr(r#"{
// "plugins": [ "proposal-class-properties"],
// "presets": ["env" "react"]
//}
//"#),
// regression_3028,
// r#"
//class b {
//}
//
//class a1 extends b {
// constructor() {
// super();
// this.x = () => this;
// }
//}
//
//export default class a2 extends b {
// constructor() {
// super();
// this.x = () => this;
// }
//}
//
//"#
// r#"
//"use strict";
//
//Object.defineProperty(exports, "__esModule" {
// value: true
//});
//exports["default"] = void 0;
//
//var b = function b() {
// _class_call_check(this, b);
//};
//
//var a1 =
// /*#__PURE__*/
//function (_b) {
// _inherits(a1, _b);
//
// function a1() {
// var _this;
//
// _class_call_check(this, a1);
// _this = _possible_constructor_return(this,
// _get_prototype_of(a1).call(this));
//
// _this.x = function () {
// return _assert_this_initialized(_this);
// };
//
// return _this;
// }
//
// return a1;
//}(b);
//
//var a2 =
// /*#__PURE__*/
//function (_b2) {
// _inherits(a2, _b2);
//
// function a2() {
// var _this2;
//
// _class_call_check(this, a2);
// _this2 = _possible_constructor_return(this,
// _get_prototype_of(a2).call(this));
//
// _this2.x = function () {
// return _assert_this_initialized(_this2);
// };
//
// return _this2;
// }
//
// return a2;
//}(b);
//
//exports["default"] = a2;
//
//"#
//);

//// regression_t2997
//test!(
// syntax(),
// |_| tr(r#"{
// "plugins": [ "proposal-class-properties"],
// "presets": ["env" "react"]
//}
//"#),
// regression_t2997,
// r#"
//class A {}
//
//class B extends A {
// constructor() {
// return super();
// }
//}
//
//"#
// r#"
//var A = function A() {
// "use strict";
//
// _class_call_check(this, A);
//};
//
//var B =
// /*#__PURE__*/
//function (A) {
// "use strict";
//
// _inherits(B, A);
//
// function B() {
// var _this;
//
// _class_call_check(this, B);
// return _possible_constructor_return(_this, _this =
// _possible_constructor_return(this, _get_prototype_of(B).call(this))); }
//
// return B;
//}(A);
//
//"#
//);

// extend_builtins_shadowed
test!(
// Cost is too high while being useless
Expand Down Expand Up @@ -3263,42 +3128,6 @@ expect(obj[1]).toBe(2);
"#
);

//// regression_5769
//test_exec!(
// syntax(),
// |_| tr(r#"{
// "plugins": [ "proposal-class-properties"],
// "presets": ["env" "react"]
//}
//"#),
// regression_5769_exec,
// r#"
//class Point {
// getX() {
// expect(this.x).toBe(3); // C
// }
//}
//
//class ColorPoint extends Point {
// constructor() {
// super();
// this.x = 2;
// super.x = 3;
// expect(this.x).toBe(3); // A
// expect(super.x).toBeUndefined(); // B
// }
//
// m() {
// this.getX()
// }
//}
//
//const cp = new ColorPoint();
//cp.m();
//
//"#
//);

// get_set_get_semantics_setter_defined_on_parent
test_exec!(
syntax(),
Expand Down Expand Up @@ -3330,88 +3159,6 @@ expect(obj.get()).toBeUndefined();
"#
);

//// regression_t7537
//test!(
// syntax(),
// |_| tr(r#"{
// "plugins": ["transform-exponentiation-operator"],
// "presets": ["env"]
//}
//"#),
// regression_t7537,
// r#"
//class B{}
//class A extends B{
// constructor(track){
// if (track !== undefined) super(track);
// else super();
// }
//}
//
//"#
// r#"
//function _typeof(obj) { if (typeof Symbol === "function" && typeof
// Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return
// typeof obj; }; } else { _typeof = function _typeof(obj) { return obj &&
// typeof Symbol === "function" && obj.constructor === Symbol && obj !==
// Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
//
//function _possible_constructor_return(self, call) { if (call &&
// (_typeof(call) === "object" || typeof call === "function")) { return call; }
// return _assert_this_initialized(self); }
//
//function _assert_this_initialized(self) { if (self === void 0) { throw new
// ReferenceError("this hasn't been initialised - super() hasn't been called");
// } return self; }
//
//function _get_prototype_of(o) { _get_prototype_of = Object.setPrototypeOf ?
// Object.getPrototypeOf : function _get_prototype_of(o) { return o.__proto__ ||
// Object.getPrototypeOf(o); }; return _get_prototype_of(o); }
//
//function _inherits(subClass, superClass) { if (typeof superClass !==
// "function" && superClass !== null) { throw new TypeError("Super expression
// must either be null or a function"); } subClass.prototype =
// Object.create(superClass && superClass.prototype, { constructor: { value:
// subClass, writable: true, configurable: true } }); if (superClass)
// _set_prototype_of(subClass, superClass); }
//
//function _set_prototype_of(o, p) { _set_prototype_of = Object.setPrototypeOf
// || function _set_prototype_of(o, p) { o.__proto__ = p; return o; }; return
// _set_prototype_of(o, p); }
//
//function _class_call_check(instance, Constructor) { if (!(instance instanceof
// Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
//
//var B = function B() {
// "use strict";
//
// _class_call_check(this, B);
//};
//
//var A =
// /*#__PURE__*/
//function (_B) {
// "use strict";
//
// _inherits(A, _B);
//
// function A(track) {
// var _this;
//
// _class_call_check(this, A);
//
// if (track !== undefined) _this = _possible_constructor_return(this,
// _get_prototype_of(A).call(this, track));else _this =
// _possible_constructor_return(this, _get_prototype_of(A).call(this));
// return _possible_constructor_return(_this);
// }
//
// return A;
//}(B);
//
//"#
//);

// regression_t7010
test!(
// TODO: Unignore this
Expand Down
Loading
Loading