feat(es/testing): Use __swc_snapshots__ for test! macro (#8191)

**Description:**

This implements something similar to `__snapshots__` of `jest`. Instead of storing the expected result as a string literal, we now store it in `$crate/tests/__swc_snapshots__/$path_to_test__$test_name.js`.

**Related issue:**

 - Closes #4509
This commit is contained in:
Donny/강동윤 2023-10-30 10:38:59 +09:00 committed by GitHub
parent 769bc5b725
commit 0aafa75fef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1177 changed files with 12210 additions and 17626 deletions

View File

@ -128,18 +128,6 @@ mod tests {
bar() {
(async () => { })();
}
}"#,
r#"
class Foo {
constructor() {
this.x = async function () {
return await 1;
};
}
bar() {
(async function () {})();
}
}"#
);
@ -152,14 +140,6 @@ mod tests {
foo() {
bar(async () => await 1);
}
}"#,
r#"
class Foo {
foo() {
bar(async function () {
return await 1;
});
}
}"#
);
@ -172,15 +152,6 @@ mod tests {
constructor() {
this.x = () => async () => await this;
}
}"#,
r#"
class Foo {
constructor() {
var _this = this;
this.x = () => async function () {
return await _this;
};
}
}"#
);
@ -192,12 +163,6 @@ mod tests {
|_| tr(),
non_async_arrow,
r#"
class Foo {
constructor() {
this.x = () => {};
}
}"#,
r#"
class Foo {
constructor() {
this.x = () => {};
@ -209,7 +174,6 @@ mod tests {
::swc_ecma_parser::Syntax::default(),
|_| tr(),
non_class_async_arrow,
"let x = async () => await 1;",
"let x = async () => await 1;"
);
}

View File

@ -76,15 +76,13 @@ mod tests {
::swc_ecma_parser::Syntax::default(),
|_| tr(),
destructured_default_value,
"const f = ({ a = 1 }) => a;",
"const f = ({ a: a = 1 }) => a;"
"const f = ({ a = 1 }) => a;"
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| tr(),
destructured_no_default_value,
"const f = ({ a }) => a;",
"const f = ({ a }) => a;"
);
@ -92,15 +90,13 @@ mod tests {
::swc_ecma_parser::Syntax::default(),
|_| tr(),
nested_default_value,
"const f = ({ a: { b = 1 } }) => [a, b];",
"const f = ({ a: { b: b = 1 } }) => [a, b];"
"const f = ({ a: { b = 1 } }) => [a, b];"
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| tr(),
non_arguments,
"const f = () => { const { a = 1 } = {}; };",
"const f = () => { const { a = 1 } = {}; };"
);
}

View File

@ -118,36 +118,28 @@ mod tests {
basic,
"(function a ([a]) { a });
(function a({ ...a }) { a });
(function a({ a }) { a });",
"(function a([_a]) { _a; });
(function a({ ..._a }) { _a; });
(function a({ a: _a }) { _a; });"
(function a({ a }) { a });"
);
test!(
Syntax::default(),
|_| tr(),
avoid_collision_1,
"(function a([a, _a]) { a + _a })",
"(function a([_a1, _a]) {
_a1 + _a;
});"
"(function a([a, _a]) { a + _a })"
);
test!(
Syntax::default(),
|_| tr(),
use_duplicated_id,
"(function a([a]) { console.log(_a); })",
"(function a([_a1]) { console.log(_a); });"
"(function a([a]) { console.log(_a); })"
);
test!(
Syntax::default(),
|_| tr(),
avoid_collision_2,
"(function _a([_a]) { console.log(_a); })",
"(function _a([__a]) { console.log(__a); });"
"(function _a([_a]) { console.log(_a); })"
);
test!(
@ -157,10 +149,6 @@ mod tests {
"let _a;
(function a([a]) {
_a = 3;
})",
"let _a;
(function a([_a1]) {
_a = 3;
})"
);
@ -168,8 +156,7 @@ mod tests {
Syntax::default(),
|_| tr(),
assignment_expr_in_default_value,
"(function a([a = a = 3]) {})",
"(function a([_a = _a = 3]) {})"
"(function a([a = a = 3]) {})"
);
test!(
@ -190,20 +177,6 @@ mod tests {
return _type_of();
}
",
"
export default function _type_of__2() {
if (Date__1.now() > 0) {
_type_of__2 = function _type_of__5() {
console__1.log(0);
};
} else {
_type_of__2 = function _type_of__8() {
console__1.log(2);
};
}
return _type_of__2();
}
"
);
}

View File

@ -169,22 +169,14 @@ mod tests {
::swc_ecma_parser::Syntax::default(),
|_| tr(),
single_tag,
"t`a`;",
r#"
let _ = t1 => t1, t1;
t(t1 || (t1 = _`a`));
"#
"t`a`;"
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| tr(),
single_tag_empty,
"x``;",
r#"
let _ = t => t, t;
x(t || (t = _``));
"#
"x``;"
);
test!(
@ -194,11 +186,6 @@ mod tests {
r#"
t`a`;
x``;
"#,
r#"
let _ = t1 => t1, t1, t2;
t(t1 || (t1 = _`a`));
x(t2 || (t2 = _``));
"#
);
@ -206,55 +193,35 @@ mod tests {
::swc_ecma_parser::Syntax::default(),
|_| tr(),
function_scoped_tag,
"const f = t => t`a`;",
r#"
let _ = t => t, t;
const f = t1 => t1(t || (t = _`a`));
"#
"const f = t => t`a`;"
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| tr(),
dynamic_tag,
"fn()``;",
r#"
let _ = t => t, t;
fn()(t || (t = _``));
"#
"fn()``;"
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| tr(),
dynamic_expressions,
"const f = t => t`a${1}b${t}${[\"hello\"]}`;",
r#"
let _ = t => t, t;
const f = t1 => t1(t || (t = _`a${0}b${0}${0}`), 1, t1, ["hello"]);
"#
"const f = t => t`a${1}b${t}${[\"hello\"]}`;"
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| tr(),
same_tag_safari_11,
"x`a` === x`a`;",
r#"
let _ = t => t, t, t1;
x(t || (t = _`a`)) === x(t1 || (t1 = _`a`));
"#
"x`a` === x`a`;"
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| tr(),
shared_strings_safari_11,
"x`a` === y`a`;",
r#"
let _ = t => t, t, t1;
x(t || (t = _`a`)) === y(t1 || (t1 = _`a`));
"#
"x`a` === y`a`;"
);
test!(
@ -266,12 +233,6 @@ mod tests {
t(`a`);
t;
`a`;
"#,
r#"
`a`;
t(`a`);
t;
`a`;
"#
);
@ -282,12 +243,6 @@ mod tests {
r#"
const _ = 1;
t``;
"#,
r#"
let _ = t1 => t1, t1;
const _1 = 1;
t(t1 || (t1 = _``));
"#
);
@ -295,10 +250,6 @@ mod tests {
::swc_ecma_parser::Syntax::default(),
|_| tr(),
block_scoped_tag,
"for (let t of []) t`a`;",
r#"
let _ = t => t, t;
for (let t1 of []) t1(t || (t = _`a`));
"#
"for (let t of []) t`a`;"
);
}

View File

@ -0,0 +1,10 @@
class Foo {
constructor(){
this.x = async function() {
return await 1;
};
}
bar() {
(async function() {})();
}
}

View File

@ -0,0 +1,7 @@
class Foo {
foo() {
bar(async function() {
return await 1;
});
}
}

View File

@ -0,0 +1,5 @@
class Foo {
constructor(){
this.x = ()=>{};
}
}

View File

@ -0,0 +1,8 @@
class Foo {
constructor(){
var _this = this;
this.x = ()=>async function() {
return await _this;
};
}
}

View File

@ -0,0 +1,4 @@
const f = ({ a: { b: b = 1 } })=>[
a,
b
];

View File

@ -0,0 +1,3 @@
const f = ()=>{
const { a = 1 } = {};
};

View File

@ -0,0 +1,9 @@
(function a([_a]) {
_a;
});
(function a({ ..._a }) {
_a;
});
(function a({ a: _a }) {
_a;
});

View File

@ -0,0 +1,12 @@
export default function _type_of__2() {
if (Date__1.now() > 0) {
_type_of__2 = function _type_of__5() {
console__1.log(0);
};
} else {
_type_of__2 = function _type_of__8() {
console__1.log(2);
};
}
return _type_of__2();
}

View File

@ -0,0 +1,2 @@
let _ = (t)=>t, t;
for (let t1 of [])t1(t || (t = _`a`));

View File

@ -0,0 +1,4 @@
let _ = (t)=>t, t;
const f = (t1)=>t1(t || (t = _`a${0}b${0}${0}`), 1, t1, [
"hello"
]);

View File

@ -0,0 +1,2 @@
let _ = (t)=>t, t;
fn()(t || (t = _``));

View File

@ -0,0 +1,2 @@
let _ = (t)=>t, t;
const f = (t1)=>t1(t || (t = _`a`));

View File

@ -0,0 +1,3 @@
let _ = (t1)=>t1, t1, t2;
t(t1 || (t1 = _`a`));
x(t2 || (t2 = _``));

View File

@ -0,0 +1,3 @@
let _ = (t1)=>t1, t1;
const _1 = 1;
t(t1 || (t1 = _``));

View File

@ -0,0 +1,2 @@
let _ = (t)=>t, t, t1;
x(t || (t = _`a`)) === x(t1 || (t1 = _`a`));

View File

@ -0,0 +1,2 @@
let _ = (t)=>t, t, t1;
x(t || (t = _`a`)) === y(t1 || (t1 = _`a`));

View File

@ -0,0 +1,2 @@
let _ = (t1)=>t1, t1;
t(t1 || (t1 = _`a`));

View File

@ -0,0 +1,2 @@
let _ = (t)=>t, t;
x(t || (t = _``));

View File

@ -89,16 +89,6 @@ mod tests {
function fn2() { }
}
"#,
r#"
{
let fn1 = function fn1() {
fn2();
};
let fn2 = function fn2() {
};
fn1();
}
"#
);
@ -112,14 +102,7 @@ mod tests {
}
}
name("Steve");"#,
r#"{
let name = function name(n) {
return n;
};
}
name("Steve");
"#
name("Steve");"#
);
test!(
@ -143,24 +126,6 @@ name("Steve");
}
}
}
"#,
r#"
{
let foo = function foo() {
return function bar() {
{
let baz = function baz() {};
}
};
function baz() {}
{
let bar = function bar() {};
{
let bar = function bar() {};
}
}
};
}
"#
);
@ -176,14 +141,6 @@ function foo(scope) {
scope.agentOperation = operation;
}
}
",
"
function foo(scope) {
scope.startOperation = startOperation;
function startOperation(operation) {
scope.agentOperation = operation;
}
}
"
);
@ -197,13 +154,6 @@ function foo(scope) {
target[key] = source[key]; } } } return target; }; return \
components_Link_extends.apply(this, arguments); }
",
"function components_Link_extends() { components_Link_extends = Object.assign || function \
(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for \
(var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { \
target[key] = source[key]; } } } return target; }; return \
components_Link_extends.apply(this, arguments); }
"
);
@ -228,24 +178,6 @@ function foo(scope) {
return _extends.apply(this, arguments);
}
",
"function _extends() {
module.exports = _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
"
);
@ -260,13 +192,6 @@ function foo(scope) {
default: obj
};
}
}",
"function foo() {
'use strict';
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : { default: obj };
}
}
"
}"
);
}

View File

@ -143,25 +143,6 @@ export class Foo {
return {a};
}
}
"#,
r#"
export var Foo = function() {
"use strict";
function Foo() {
_class_call_check(this, Foo);
}
_create_class(Foo, [{
key: "func",
value: function func(a) {
var b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Date.now();
return {
a: a
};
}
}]);
return Foo;
}();
"#
);
@ -175,22 +156,6 @@ export var Foo = function() {
issue_189,
r#"
class HomePage extends React.Component {}
"#,
r#"
var HomePage = /*#__PURE__*/function (_React_Component) {
"use strict";
_inherits(HomePage, _React_Component);
var _super = _create_super(HomePage);
function HomePage() {
_class_call_check(this, HomePage);
return _super.apply(this, arguments);
}
return HomePage;
}(React.Component);
"#
);
@ -204,15 +169,7 @@ class HomePage extends React.Component {}
issue_227,
"export default function fn1(...args) {
fn2(...args);
}",
"
export default function fn1() {
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
args[_key] = arguments[_key];
}
fn2.apply(void 0, _to_consumable_array(args));
}
"
}"
);
test!(
@ -230,14 +187,6 @@ function foo(scope) {
scope.agentOperation = operation;
}
}
",
"
function foo(scope) {
scope.startOperation = startOperation;
function startOperation(operation) {
scope.agentOperation = operation;
}
}
"
);
@ -279,13 +228,7 @@ function foo(scope) {
r#"
export const getBadgeBorderRadius = (text, color) => {
return (text && style) || {}
}"#,
r#"
export var getBadgeBorderRadius = function(text, color) {
return text && style || {
};
};
"#
}"#
);
test!(
@ -317,41 +260,7 @@ class B extends A {
super.print();
}
}
",
"var A = function() {
\"use strict\";
function A() {
_class_call_check(this, A);
this.a_num = 10;
}
_create_class(A, [{
key: \"print\",
value: function print() {
expect(this.a_num).toBe(10);
}
}]);
return A;
}();
var B = function(A) {
\"use strict\";
_inherits(B, A);
var _super = _create_super(B);
function B(num) {
_class_call_check(this, B);
var _this;
_this = _super.call(this);
_this.b_num = num;
return _this;
}
_create_class(B, [{
key: \"print\",
value: function print() {
expect(this.b_num).toBe(20);
_get(_get_prototype_of(B.prototype), \"print\", this).call(this);
}
}]);
return B;
}(A);"
"
);
test_exec!(
@ -397,22 +306,6 @@ return new B(20).print()"
issue_1660_1,
"
console.log(class {run(){}});
",
"
console.log(function() {
\"use strict\";
function _class() {
_class_call_check(this, _class);
}
_create_class(_class, [
{
key: \"run\",
value: function run() {
}
}
]);
return _class;
}());
"
);
@ -452,17 +345,6 @@ return new B(20).print()"
export class Foo {
let() {}
}
"#,
r#"
export var Foo = function() {
"use strict";
function Foo() {
_class_call_check(this, Foo);
}
var _proto = Foo.prototype;
_proto.let = function _let() {};
return Foo;
}();
"#
);
}

View File

@ -509,13 +509,7 @@ mod tests {
a(){
let c = super.x;
}
}",
r#"var _obj;
let obj = _obj = {
a: function a() {
let c = _get(_get_prototype_of(_obj), "x", this);
}
};"#
}"
);
test!(
::swc_ecma_parser::Syntax::default(),
@ -532,13 +526,7 @@ mod tests {
a(){
super.y(1,2,3);
}
}",
r#"var _obj;
let obj = _obj = {
a: function a() {
_get(_get_prototype_of(_obj), "y", this).call(this,1,2,3);
}
};"#
}"
);
test!(
::swc_ecma_parser::Syntax::default(),
@ -555,14 +543,7 @@ mod tests {
a(){
super.x = 1;
}
}",
r#"
var _obj;
let obj = _obj = {
a: function a() {
_set(_get_prototype_of(_obj), "x", 1, this, true);
}
};"#
}"
);
test!(
::swc_ecma_parser::Syntax::default(),
@ -584,19 +565,7 @@ mod tests {
}
}
},
}",
r#"var _obj;
let obj = _obj = {
b: function b() {
var _obj1;
_get(_get_prototype_of(_obj), "bar", this).call(this);
let o = _obj1 = {
d: function d() {
_get(_get_prototype_of(_obj1), "d", this).call(this);
}
};
}
};"#
}"
);
test!(
Syntax::Es(EsConfig {
@ -620,15 +589,6 @@ mod tests {
}
}
},
}",
r#"let outer = {
b: function b() {
let inner = {
d: function d() {
super.d();
}
};
}
};"#
}"
);
}

View File

@ -62,15 +62,13 @@ mod tests {
::swc_ecma_parser::Syntax::default(),
|_| sticky_regex(),
babel_basic,
"var re = /o\"'+/y;",
"var re = new RegExp(\"o\\\"'+\", \"y\");"
"var re = /o\"'+/y;"
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| sticky_regex(),
babel_ignore_non_sticky,
"var re = /o+/;",
"var re = /o+/;"
);
}

View File

@ -154,7 +154,6 @@ mod tests {
Syntax::default(),
|_| typeof_symbol(),
dont_touch_non_symbol_comparison,
"typeof window !== 'undefined'",
"typeof window !== 'undefined'"
);
@ -162,7 +161,6 @@ mod tests {
Syntax::default(),
|_| typeof_symbol(),
dont_touch_non_symbol_comparison_02,
"'undefined' !== typeof window",
"'undefined' !== typeof window"
);
@ -181,25 +179,6 @@ mod tests {
exports.isNode = isNode;
var isWeex = !isUndef(typeof WXEnvironment) && WXEnvironment.platform !== 'Web';
exports.isWeex = isWeex;
",
"
function isUndef(type) {
return type === 'undefined';
}
var isWeb =
!isUndef(typeof window === \"undefined\" ? \"undefined\" : _type_of(window)) &&
'onload' in window;
exports.isWeb = isWeb;
var isNode =
!isUndef(typeof process === \"undefined\" ? \"undefined\" : _type_of(process)) &&
!!(process.versions && process.versions.node);
exports.isNode = isNode;
var isWeex =
!isUndef(
typeof WXEnvironment === \"undefined\" ? \"undefined\" : _type_of(WXEnvironment)
) && WXEnvironment.platform !== 'Web';
exports.isWeex = isWeex;
"
);
}

View File

@ -0,0 +1,5 @@
{
let name = function name(n) {
return n;
};
}name("Steve");

View File

@ -0,0 +1,16 @@
{
let foo = function foo() {
return function bar() {
{
let baz = function baz() {};
}
};
function baz() {}
{
let bar = function bar() {};
{
let bar = function bar() {};
}
}
};
}

View File

@ -0,0 +1,7 @@
{
let fn1 = function fn1() {
fn2();
};
let fn2 = function fn2() {};
fn1();
}

View File

@ -0,0 +1,8 @@
function foo() {
'use strict';
function _interop_require_default(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
}

View File

@ -0,0 +1,6 @@
function foo(scope) {
scope.startOperation = startOperation;
function startOperation(operation) {
scope.agentOperation = operation;
}
}

View File

@ -0,0 +1,14 @@
function components_Link_extends() {
components_Link_extends = Object.assign || function(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i];
for(var key in source){
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return components_Link_extends.apply(this, arguments);
}

View File

@ -0,0 +1,14 @@
function _extends() {
module.exports = _extends = Object.assign || function(target) {
for(var i = 1; i < arguments.length; i++){
var source = arguments[i];
for(var key in source){
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}

View File

@ -0,0 +1,13 @@
console.log(/*#__PURE__*/ function() {
"use strict";
function _class() {
_class_call_check(this, _class);
}
_create_class(_class, [
{
key: "run",
value: function run() {}
}
]);
return _class;
}());

View File

@ -0,0 +1,18 @@
export var Foo = /*#__PURE__*/ function() {
"use strict";
function Foo() {
_class_call_check(this, Foo);
}
_create_class(Foo, [
{
key: "func",
value: function func(a) {
var b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Date.now();
return {
a: a
};
}
}
]);
return Foo;
}();

View File

@ -0,0 +1,10 @@
var HomePage = /*#__PURE__*/ function(_React_Component) {
"use strict";
_inherits(HomePage, _React_Component);
var _super = _create_super(HomePage);
function HomePage() {
_class_call_check(this, HomePage);
return _super.apply(this, arguments);
}
return HomePage;
}(React.Component);

View File

@ -0,0 +1,6 @@
export default function fn1() {
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
args[_key] = arguments[_key];
}
fn2.apply(void 0, _to_consumable_array(args));
}

View File

@ -0,0 +1,6 @@
function foo(scope) {
scope.startOperation = startOperation;
function startOperation(operation) {
scope.agentOperation = operation;
}
}

View File

@ -0,0 +1,38 @@
var A = /*#__PURE__*/ function() {
"use strict";
function A() {
_class_call_check(this, A);
this.a_num = 10;
}
_create_class(A, [
{
key: "print",
value: function print() {
expect(this.a_num).toBe(10);
}
}
]);
return A;
}();
var B = /*#__PURE__*/ function(A) {
"use strict";
_inherits(B, A);
var _super = _create_super(B);
function B(num) {
_class_call_check(this, B);
var _this;
_this = _super.call(this);
_this.b_num = num;
return _this;
}
_create_class(B, [
{
key: "print",
value: function print() {
expect(this.b_num).toBe(20);
_get(_get_prototype_of(B.prototype), "print", this).call(this);
}
}
]);
return B;
}(A);

View File

@ -0,0 +1,3 @@
export var getBadgeBorderRadius = function(text, color) {
return text && style || {};
};

View File

@ -0,0 +1,9 @@
export var Foo = /*#__PURE__*/ function() {
"use strict";
function Foo() {
_class_call_check(this, Foo);
}
var _proto = Foo.prototype;
_proto.let = function _let() {};
return Foo;
}();

View File

@ -0,0 +1,6 @@
var _obj;
let obj = _obj = {
a: function a() {
_get(_get_prototype_of(_obj), "y", this).call(this, 1, 2, 3);
}
};

View File

@ -0,0 +1,10 @@
let outer = {
b: function b() {
let inner = {
d: function d() {
super.d() // should not transform
;
}
};
}
};

View File

@ -0,0 +1,6 @@
var _obj;
let obj = _obj = {
a: function a() {
let c = _get(_get_prototype_of(_obj), "x", this);
}
};

View File

@ -0,0 +1,12 @@
var _obj;
let obj = _obj = {
b: function b() {
var _obj1;
_get(_get_prototype_of(_obj), "bar", this).call(this);
let o = _obj1 = {
d: function d() {
_get(_get_prototype_of(_obj1), "d", this).call(this);
}
};
}
};

View File

@ -0,0 +1,6 @@
var _obj;
let obj = _obj = {
a: function a() {
_set(_get_prototype_of(_obj), "x", 1, this, true);
}
};

View File

@ -0,0 +1 @@
var re = new RegExp("o\"'+", "y");

View File

@ -0,0 +1,9 @@
function isUndef(type) {
return type === 'undefined';
}
var isWeb = !isUndef(typeof window === "undefined" ? "undefined" : _type_of(window)) && 'onload' in window;
exports.isWeb = isWeb;
var isNode = !isUndef(typeof process === "undefined" ? "undefined" : _type_of(process)) && !!(process.versions && process.versions.node);
exports.isNode = isNode;
var isWeex = !isUndef(typeof WXEnvironment === "undefined" ? "undefined" : _type_of(WXEnvironment)) && WXEnvironment.platform !== 'Web';
exports.isWeex = isWeex;

View File

@ -155,8 +155,7 @@ mod tests {
::swc_ecma_parser::Syntax::default(),
|_| exponentiation(),
babel_binary,
"2 ** 2",
"Math.pow(2, 2)"
"2 ** 2"
);
test_exec!(
@ -210,7 +209,6 @@ expect(counters).toBe(1);"#
|_| exponentiation(),
assign,
r#"x **= 3"#,
r#"x = Math.pow(x, 3)"#,
ok_if_code_eq
);
@ -230,7 +228,6 @@ expect(counters).toBe(1);"#
|_| exponentiation(),
issue_740,
"self.a = 10 ** 2",
"self.a = Math.pow(10, 2)",
ok_if_code_eq
);
@ -240,8 +237,7 @@ expect(counters).toBe(1);"#
::swc_ecma_parser::Syntax::default(),
|_| exponentiation(),
babel_binary_member_assignment_expression,
"var x = {}; x.a = 2 ** 2",
"var x = {}; x.a = Math.pow(2, 2)"
"var x = {}; x.a = 2 ** 2"
);
test!(
@ -249,7 +245,6 @@ expect(counters).toBe(1);"#
|_| exponentiation(),
assign_to_object_property,
r#"var self = {}; self.x **= 3"#,
r#"var self = {}; var ref = self.x; self.x = Math.pow(ref, 3);"#,
ok_if_code_eq
);
}

View File

@ -0,0 +1 @@
x = Math.pow(x, 3);

View File

@ -0,0 +1,3 @@
var self = {};
var ref = self.x;
self.x = Math.pow(ref, 3);

View File

@ -0,0 +1 @@
self.a = Math.pow(10, 2);

View File

@ -43,23 +43,20 @@ mod tests {
::swc_ecma_parser::Syntax::default(),
|_| tr(),
issue_411,
"try {} catch {}",
"try {} catch(e) {}"
"try {} catch {}"
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| tr(),
catch_binding_name_collision_1,
"try { throw new Error(); } catch { log(e); }",
"try { throw new Error(); } catch (e1) { log(e); }"
"try { throw new Error(); } catch { log(e); }"
);
test!(
::swc_ecma_parser::Syntax::default(),
|_| tr(),
catch_binding_name_collision_2,
"var e; try {} catch { log(e); }",
"var e; try {} catch (e1) { log(e); }"
"var e; try {} catch { log(e); }"
);
}

View File

@ -0,0 +1,5 @@
try {
throw new Error();
} catch (e1) {
log(e);
}

View File

@ -0,0 +1,4 @@
var e;
try {} catch (e1) {
log(e);
}

View File

@ -75,10 +75,6 @@ mod tests {
r#"obj["foo"] = "isValid";
obj.const = "isKeyword";
obj["var"] = "isKeyword";"#,
r#"obj["foo"] = "isValid";
obj["const"] = "isKeyword";
obj["var"] = "isKeyword";"#,
ok_if_code_eq
);
@ -87,7 +83,6 @@ obj["var"] = "isKeyword";"#,
::swc_ecma_parser::Syntax::default(),
|_| MemberExprLit,
issue_206,
"const number = foo[bar1][baz1]",
"const number = foo[bar1][baz1]"
);
@ -95,7 +90,6 @@ obj["var"] = "isKeyword";"#,
::swc_ecma_parser::Syntax::default(),
|_| MemberExprLit,
issue_211,
"_query[idx]=$this.attr('data-ref');",
"_query[idx]=$this.attr('data-ref');"
);
}

View File

@ -86,14 +86,6 @@ mod tests {
"1": function () {},
// not changed
"default": 1,
[a]: 2,
foo: 1
};"#,
r#"var foo = {
bar: function () {},
"1": function () {},
"default": 1,
[a]: 2,
foo: 1
@ -108,10 +100,6 @@ mod tests {
r#"'use strict';
var x = {
'foo.bar': true
};"#,
r#"'use strict';
var x = {
'foo.bar': true
};"#,
ok_if_code_eq
);

View File

@ -134,7 +134,6 @@ mod tests {
::swc_ecma_parser::Syntax::default(),
|_| reserved_words(false),
$name,
$src,
$src
);
};
@ -152,15 +151,6 @@ function utf8CheckByte(byte) {
else if (byte >> 3 === 0x1E) return 4;
return -1;
}
"#,
r#"
function utf8CheckByte(_byte) {
if (_byte <= 0x7F) return 0;
else if (_byte >> 5 === 0x06) return 2;
else if (_byte >> 4 === 0x0E) return 3;
else if (_byte >> 3 === 0x1E) return 4;
return -1;
}
"#
);
@ -174,11 +164,6 @@ function utf8CheckByte(_byte) {
import { int } from './a.js'
console.log(int)
export { int };
"#,
r#"
import { int as _int } from './a.js';
console.log(_int);
export { _int as int };
"#
);
@ -191,13 +176,6 @@ function utf8CheckByte(_byte) {
console.log("char====char");
return "";
}
"#,
r#"
function _char() {
console.log("char====char");
return "";
}
export { _char as char };
"#
);
}

View File

@ -0,0 +1,3 @@
obj["foo"] = "isValid";
obj["const"] = "isKeyword";
obj["var"] = "isKeyword";

View File

@ -0,0 +1 @@
const number = foo[bar1][baz1];

View File

@ -0,0 +1 @@
_query[idx] = $this.attr('data-ref');

View File

@ -0,0 +1,9 @@
var foo = {
// changed
bar: function() {},
"1": function() {},
// not changed
"default": 1,
[a]: 2,
foo: 1
};

View File

@ -0,0 +1,4 @@
'use strict';
var x = {
'foo.bar': true
};

View File

@ -0,0 +1,7 @@
function utf8CheckByte(_byte) {
if (_byte <= 0x7F) return 0;
else if (_byte >> 5 === 0x06) return 2;
else if (_byte >> 4 === 0x0E) return 3;
else if (_byte >> 3 === 0x1E) return 4;
return -1;
}

View File

@ -0,0 +1 @@
export { Foo as default };

View File

@ -0,0 +1,3 @@
import { int as _int } from './a.js';
console.log(_int);
export { _int as int };

View File

@ -0,0 +1,5 @@
function _char() {
console.log("char====char");
return "";
}
export { _char as char };

View File

@ -0,0 +1,28 @@
let Foo = _decorate([
(_)=>desc = _
], function(_initialize) {
class Foo {
constructor(){
_initialize(this);
}
}
return {
F: Foo,
d: [
{
kind: "method",
key: getKey(),
value: function() {
return 1;
}
},
{
kind: "method",
key: getKey(),
value: function() {
return 2;
}
}
]
};
});

View File

@ -0,0 +1,28 @@
let Foo = _decorate([
(_)=>desc = _
], function(_initialize) {
class Foo {
constructor(){
_initialize(this);
}
}
return {
F: Foo,
d: [
{
kind: "method",
key: getKeyI(),
value: function() {
return 1;
}
},
{
kind: "method",
key: getKeyJ(),
value: function() {
return 2;
}
}
]
};
});

View File

@ -0,0 +1,5 @@
var a = {
eval: function _eval() {
return eval;
}
};

View File

@ -0,0 +1,21 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _events = /*#__PURE__*/ _interop_require_default(require("events"));
let Template = /*#__PURE__*/ function() {
"use strict";
function Template() {
_class_call_check(this, Template);
}
_create_class(Template, [
{
key: "events",
value: function events() {
return _events.default;
}
}
]);
return Template;
}();
console.log(new Template().events());

View File

@ -0,0 +1,16 @@
"use strict";
var _moduleA = require("./moduleA.js");
let Demo = _decorate([
(0, _moduleA.default)('0.0.1')
], function(_initialize) {
class Demo {
constructor(){
_initialize(this);
this.author = 'alan';
}
}
return {
F: Demo,
d: []
};
});

View File

@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "default", {
enumerable: true,
get: function() {
return _default;
}
});
const Test = (version)=>{
return (target)=>{
target.version = version;
};
};
var _default = Test;

View File

@ -0,0 +1,43 @@
let SomeClass = _decorate([], function(_initialize) {
class SomeClass {
constructor(){
_initialize(this);
}
}
return {
F: SomeClass,
d: [
{
kind: "method",
decorators: [
dec
],
key: "someMethod",
value: function someMethod() {}
}
]
};
});
let OtherClass = _decorate([], function(_initialize, _SomeClass) {
class OtherClass extends _SomeClass {
constructor(...args){
super(...args);
_initialize(this);
}
}
return {
F: OtherClass,
d: [
{
kind: "method",
decorators: [
dec
],
key: "anotherMethod",
value: function anotherMethod() {
_get(_get_prototype_of(OtherClass.prototype), "someMethod", this).call(this);
}
}
]
};
}, SomeClass);

View File

@ -0,0 +1,22 @@
var method = 1;
let Foo = _decorate([
decorator
], function(_initialize) {
class Foo {
constructor(){
_initialize(this);
}
}
return {
F: Foo,
d: [
{
kind: "method",
key: "method",
value: function method1() {
return method;
}
}
]
};
});

View File

@ -0,0 +1,22 @@
let A = _decorate([
dec(a, b, ...c)
], function(_initialize) {
class A {
constructor(){
_initialize(this);
}
}
return {
F: A,
d: [
{
kind: "method",
decorators: [
dec(a, b, ...c)
],
key: "method",
value: function method() {}
}
]
};
});

View File

@ -0,0 +1,13 @@
let A = _decorate([
dec()
], function(_initialize) {
class A {
constructor(){
_initialize(this);
}
}
return {
F: A,
d: []
};
});

View File

@ -0,0 +1,13 @@
export default _decorate([
dec()
], function(_initialize) {
class _class {
constructor(){
_initialize(this);
}
}
return {
F: _class,
d: []
};
});

View File

@ -0,0 +1,14 @@
let Foo = _decorate([
dec()
], function(_initialize) {
class Foo {
constructor(){
_initialize(this);
}
}
return {
F: Foo,
d: []
};
});
export { Foo as default };

View File

@ -0,0 +1,13 @@
_decorate([
dec()
], function(_initialize) {
class _class {
constructor(){
_initialize(this);
}
}
return {
F: _class,
d: []
};
});

View File

@ -0,0 +1,14 @@
let A = _decorate([
dec
], function(_initialize, _B) {
class A extends _B {
constructor(...args){
super(...args);
_initialize(this);
}
}
return {
F: A,
d: []
};
}, B);

View File

@ -0,0 +1,16 @@
async function g() {
let A = _decorate([
dec
], function(_initialize, _super) {
class A extends _super {
constructor(...args){
super(...args);
_initialize(this);
}
}
return {
F: A,
d: []
};
}, await B);
}

View File

@ -0,0 +1,16 @@
function* g() {
let A = _decorate([
dec
], function(_initialize, _super) {
class A extends _super {
constructor(...args){
super(...args);
_initialize(this);
}
}
return {
F: A,
d: []
};
}, (yield B));
}

View File

@ -0,0 +1,14 @@
let Sub = _decorate([
decorator(parameter)
], function(_initialize, _Super) {
class Sub extends _Super {
constructor(){
var _temp;
(_temp = super(), _initialize(this), _temp).method();
}
}
return {
F: Sub,
d: []
};
}, Super);

Some files were not shown because too many files have changed in this diff Show More