2018-12-24 04:58:40 +03:00
|
|
|
use super::*;
|
2019-03-14 09:54:33 +03:00
|
|
|
use crate::{compat::es2015::block_scoping, resolver};
|
2019-12-02 11:10:06 +03:00
|
|
|
use swc_common::chain;
|
2019-01-29 17:56:16 +03:00
|
|
|
|
2019-02-05 08:15:38 +03:00
|
|
|
fn tr() -> impl Fold<Module> {
|
2019-02-28 13:25:38 +03:00
|
|
|
chain!(resolver(), function_name(), block_scoping())
|
2019-02-28 10:30:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! identical {
|
2019-02-28 13:25:38 +03:00
|
|
|
($name:ident, $src:literal) => {
|
|
|
|
test!(
|
|
|
|
::swc_ecma_parser::Syntax::default(),
|
|
|
|
|_| tr(),
|
|
|
|
$name,
|
|
|
|
$src,
|
|
|
|
$src
|
|
|
|
);
|
|
|
|
};
|
2019-01-29 17:56:16 +03:00
|
|
|
}
|
2018-12-24 04:58:40 +03:00
|
|
|
|
|
|
|
test!(
|
2019-02-28 13:25:38 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
|
|
|
|_| tr(),
|
|
|
|
basic,
|
|
|
|
r#"var number = function (x) {
|
2018-12-24 04:58:40 +03:00
|
|
|
return x;
|
|
|
|
};"#,
|
2019-02-28 13:25:38 +03:00
|
|
|
r#"var number = function number(x) {
|
2018-12-24 04:58:40 +03:00
|
|
|
return x;
|
|
|
|
};"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-02-28 13:25:38 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
|
|
|
|_| tr(),
|
|
|
|
assign,
|
|
|
|
r#"number = function (x) {
|
2018-12-24 04:58:40 +03:00
|
|
|
return x;
|
|
|
|
};"#,
|
2019-02-28 13:25:38 +03:00
|
|
|
r#"number = function number(x) {
|
2018-12-24 04:58:40 +03:00
|
|
|
return x;
|
|
|
|
};"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-02-28 13:25:38 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
|
|
|
|_| tr(),
|
|
|
|
let_complex,
|
|
|
|
r#"
|
2018-12-24 04:58:40 +03:00
|
|
|
let TestClass = {
|
|
|
|
name: "John Doe",
|
|
|
|
|
|
|
|
testMethodFailure() {
|
|
|
|
return new Promise(async function(resolve) {
|
|
|
|
console.log(this);
|
|
|
|
setTimeout(resolve, 1000);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
"#,
|
2019-02-28 13:25:38 +03:00
|
|
|
r#"
|
2019-01-29 17:56:16 +03:00
|
|
|
var TestClass = {
|
2018-12-24 04:58:40 +03:00
|
|
|
name: "John Doe",
|
|
|
|
|
|
|
|
testMethodFailure() {
|
|
|
|
return new Promise(async function(resolve) {
|
|
|
|
console.log(this);
|
|
|
|
setTimeout(resolve, 1000);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#
|
|
|
|
);
|
2019-01-29 17:56:16 +03:00
|
|
|
|
|
|
|
test!(
|
2019-02-28 13:25:38 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
|
|
|
|_| tr(),
|
|
|
|
class_simple,
|
|
|
|
r#"
|
2019-01-29 17:56:16 +03:00
|
|
|
var Foo = function() {
|
|
|
|
var Foo = function () {
|
|
|
|
_classCallCheck(this, Foo);
|
|
|
|
};
|
|
|
|
_defineProperty(Foo, 'num', 0);
|
|
|
|
return Foo;
|
|
|
|
}();
|
|
|
|
expect(Foo.num).toBe(0);
|
|
|
|
expect(Foo.num = 1).toBe(1);
|
|
|
|
expect(Foo.name).toBe('Foo');
|
|
|
|
"#,
|
2019-02-28 13:25:38 +03:00
|
|
|
r#"
|
2019-01-29 17:56:16 +03:00
|
|
|
var Foo = function() {
|
2019-11-10 12:21:28 +03:00
|
|
|
var Foo1 = function() {
|
|
|
|
_classCallCheck(this, Foo1);
|
2019-01-29 17:56:16 +03:00
|
|
|
};
|
2019-11-10 12:21:28 +03:00
|
|
|
_defineProperty(Foo1, 'num', 0);
|
|
|
|
return Foo1;
|
2019-01-29 17:56:16 +03:00
|
|
|
}();
|
|
|
|
expect(Foo.num).toBe(0);
|
|
|
|
expect(Foo.num = 1).toBe(1);
|
|
|
|
expect(Foo.name).toBe('Foo');
|
|
|
|
"#
|
|
|
|
);
|
2019-02-28 10:30:56 +03:00
|
|
|
|
|
|
|
test!(
|
2019-02-28 13:25:38 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
|
|
|
|_| tr(),
|
|
|
|
issue_288_01,
|
|
|
|
"var extendStatics = function (d, b) {
|
2019-02-28 10:30:56 +03:00
|
|
|
extendStatics = Object.setPrototypeOf || {
|
|
|
|
__proto__: []
|
|
|
|
} instanceof Array && function (d, b) {
|
|
|
|
d.__proto__ = b;
|
|
|
|
} || function (d, b) {
|
|
|
|
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
|
|
|
};
|
|
|
|
|
|
|
|
return extendStatics(d, b);
|
|
|
|
};",
|
2019-02-28 13:25:38 +03:00
|
|
|
"var extendStatics = function (d, b) {
|
2019-02-28 10:30:56 +03:00
|
|
|
extendStatics = Object.setPrototypeOf || {
|
|
|
|
__proto__: []
|
|
|
|
} instanceof Array && function (d1, b1) {
|
|
|
|
d1.__proto__ = b1;
|
|
|
|
} || function (d1, b1) {
|
|
|
|
for (var p in b1) if (b1.hasOwnProperty(p)) d1[p] = b1[p];
|
|
|
|
};
|
|
|
|
|
|
|
|
return extendStatics(d, b);
|
|
|
|
};"
|
|
|
|
);
|
|
|
|
|
|
|
|
identical!(
|
2019-02-28 13:25:38 +03:00
|
|
|
issue_288_02,
|
|
|
|
"function components_Link_extends() {
|
2019-02-28 10:30:56 +03:00
|
|
|
components_Link_extends = Object.assign || function (target) { for (var i = 1; i < \
|
2019-02-28 13:25:38 +03:00
|
|
|
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; };
|
2019-02-28 10:30:56 +03:00
|
|
|
return components_Link_extends.apply(this, arguments); }"
|
|
|
|
);
|