diff --git a/ecmascript/transforms/src/compat/es2015/mod.rs b/ecmascript/transforms/src/compat/es2015/mod.rs index ecc02a52ac6..e425e0b9097 100644 --- a/ecmascript/transforms/src/compat/es2015/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/mod.rs @@ -193,4 +193,92 @@ export var getBadgeBorderRadius = function(text, color) { "# ); + test!( + ::swc_ecma_parser::Syntax::default(), + |_| es2015(), + issue_400_1, + "class A { + constructor() { + this.a_num = 10; + } + + print() { + expect(this.a_num).toBe(10); + } +} + +class B extends A { + constructor(num) { + super(); + this.b_num = num; + } + + print() { + expect(this.b_num).toBe(20); + super.print(); + } +} +", + "var A = function() { + function A() { + _classCallCheck(this, A); + this.a_num = 10; + } + _createClass(A, [{ + key: 'print', + value: function print() { + expect(this.a_num).toBe(10); + } + }]); + return A; +}(); +var B = function(_A) { + _inherits(B, _A); + function B(num) { + var _this; + _classCallCheck(this, B); + _this = _possibleConstructorReturn(this, _getPrototypeOf(B).call(this)); + _this.b_num = num; + return _this; + } + _createClass(B, [{ + key: 'print', + value: function print() { + expect(this.b_num).toBe(20); + _get(_getPrototypeOf(B.prototype), 'print', this).call(this); + } + }]); + return B; +}(A);" + ); + + test_exec!( + ::swc_ecma_parser::Syntax::default(), + |_| es2015(), + issue_400_2, + "class A { + constructor() { + this.a_num = 10; + } + + print() { + expect(this.a_num).toBe(10); + } +} + +class B extends A { + constructor(num) { + super(); + this.b_num = num; + } + + print() { + expect(this.b_num).toBe(20); + super.print(); + } +} + +return new B(20).print()" + ); + } diff --git a/ecmascript/transforms/src/compat/es2015/spread/mod.rs b/ecmascript/transforms/src/compat/es2015/spread/mod.rs index a70ba65e5bd..d445dce9b75 100644 --- a/ecmascript/transforms/src/compat/es2015/spread/mod.rs +++ b/ecmascript/transforms/src/compat/es2015/spread/mod.rs @@ -134,7 +134,15 @@ impl Fold for ActualFolder { }), ) } - _ => (undefined(callee.span()), callee), + + // https://github.com/swc-project/swc/issues/400 + // _ => (undefined(callee.span()), callee), + _ => ( + box Expr::This(ThisExpr { + span: callee.span(), + }), + callee, + ), }; let args_array = concat_args(span, args.into_iter().map(Some), false); diff --git a/ecmascript/transforms/src/compat/es2017/async_to_generator/tests.rs b/ecmascript/transforms/src/compat/es2017/async_to_generator/tests.rs index 72ca37833b9..c832b75b518 100644 --- a/ecmascript/transforms/src/compat/es2017/async_to_generator/tests.rs +++ b/ecmascript/transforms/src/compat/es2017/async_to_generator/tests.rs @@ -1,6 +1,6 @@ use super::*; use crate::{ - compat::es2015::{arrow, destructuring, function_name, parameters}, + compat::es2015::{arrow, destructuring, es2015, function_name, parameters}, fixer::fixer, }; @@ -715,3 +715,79 @@ test!( }); " ); + +test_exec!( + ::swc_ecma_parser::Syntax::default(), + |_| chain_at!(Module, tr(), es2015()), + issue_400_1, + "class A { + constructor() { + this.a_num = 10; + } + + async print() { + expect(this.a_num).toBe(10); + } +} + +class B extends A { + constructor(num) { + super(); + this.b_num = num; + } + + async print() { + expect(this.b_num).toBe(20); + await super.print(); + } +} + +return (new B(20)).print().then(() => console.log('Done'));" +); + +test_exec!( + ::swc_ecma_parser::Syntax::default(), + |_| AsyncToGenerator, + issue_400_2, + "class A { + constructor() { + this.a_num = 10; + } + + async print() { + expect(this.a_num).toBe(10); + } +} + + +class B extends A { + constructor(num) { + super(); + this.b_num = num; + } + + async print() { + expect(this.b_num).toBe(20); + await super.print(); + } +} + +return (new B(20)).print().then(() => console.log('Done'));" +); + +test_exec!( + ::swc_ecma_parser::Syntax::default(), + |_| chain_at!(Module, AsyncToGenerator, es2015()), + issue_400_3, + "class A { + constructor() { + this.a_num = 10; + } + + async print() { + expect(this.a_num).toBe(10); + } +} + +return (new A()).print();" +); diff --git a/ecmascript/transforms/src/tests.rs b/ecmascript/transforms/src/tests.rs index 274b869f94b..e76ea6dbbc6 100644 --- a/ecmascript/transforms/src/tests.rs +++ b/ecmascript/transforms/src/tests.rs @@ -335,6 +335,7 @@ where if status.success() { return Ok(()); } + ::std::mem::forget(tmp_dir); panic!("Execution failed") }) }