2019-12-24 16:53:48 +03:00
|
|
|
#![feature(test)]
|
|
|
|
use swc_ecma_transforms::compat::es2015::arrow;
|
|
|
|
|
|
|
|
#[macro_use]
|
|
|
|
mod common;
|
2018-11-21 12:59:17 +03:00
|
|
|
|
2019-02-19 06:52:03 +03:00
|
|
|
test!(
|
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-12-24 16:53:48 +03:00
|
|
|
|_| arrow(),
|
2019-02-19 06:52:03 +03:00
|
|
|
issue_233,
|
|
|
|
"const foo = () => ({ x, ...y }) => y",
|
|
|
|
"const foo = function() {
|
|
|
|
return function({ x , ...y }) {
|
|
|
|
return y;
|
|
|
|
};
|
|
|
|
};"
|
|
|
|
);
|
|
|
|
|
2018-11-21 12:59:17 +03:00
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-12-24 16:53:48 +03:00
|
|
|
|_| arrow(),
|
2018-11-21 12:59:17 +03:00
|
|
|
destructuring,
|
|
|
|
r#"let foo = ({bar}) => undefined;"#,
|
|
|
|
r#"let foo = function ({bar}) {
|
|
|
|
return undefined;
|
|
|
|
}"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-12-24 16:53:48 +03:00
|
|
|
|_| arrow(),
|
2018-11-21 12:59:17 +03:00
|
|
|
basic,
|
|
|
|
r#"let echo = (bar) => bar"#,
|
|
|
|
r#"let echo = function(bar) {
|
|
|
|
return bar;
|
|
|
|
}"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-12-24 16:53:48 +03:00
|
|
|
|_| arrow(),
|
2018-11-21 12:59:17 +03:00
|
|
|
empty_arguments,
|
|
|
|
r#"var t = () => 5 + 5;"#,
|
|
|
|
r#"var t = function () {
|
|
|
|
return 5 + 5;
|
|
|
|
};"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-12-24 16:53:48 +03:00
|
|
|
|_| arrow(),
|
2018-11-21 12:59:17 +03:00
|
|
|
expression,
|
|
|
|
r#"arr.map(x => x * x);"#,
|
|
|
|
r#"arr.map(function (x) {
|
|
|
|
return x * x;
|
|
|
|
});"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-12-24 16:53:48 +03:00
|
|
|
|_| arrow(),
|
2018-11-21 12:59:17 +03:00
|
|
|
inside_call,
|
|
|
|
r#"arr.map(i => i + 1);"#,
|
|
|
|
r#"arr.map(function (i) {
|
|
|
|
return i + 1;
|
|
|
|
});"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-12-24 16:53:48 +03:00
|
|
|
|_| arrow(),
|
2018-11-21 12:59:17 +03:00
|
|
|
multiple_arguments,
|
|
|
|
r#"var t = (i, x) => i * x;"#,
|
|
|
|
r#"var t = function (i, x) {
|
|
|
|
return i * x;
|
|
|
|
};"#
|
|
|
|
);
|
|
|
|
|
2019-01-08 10:34:35 +03:00
|
|
|
// test!(::swc_ecma_parser::Syntax::default(),
|
2019-12-24 16:53:48 +03:00
|
|
|
// |_| arrow(),
|
2018-11-21 12:59:17 +03:00
|
|
|
// nested,
|
|
|
|
// r#"module.exports = {
|
|
|
|
// init: function () {
|
|
|
|
// return new Promise((resolve, reject) => {
|
|
|
|
// MongoClient.connect(config.mongodb, (err, db) => {
|
|
|
|
// if (err) {
|
|
|
|
// return reject(err);
|
|
|
|
// }
|
|
|
|
// this.db = db;
|
|
|
|
// resolve(this);
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// };"#,
|
|
|
|
// r#"module.exports = {
|
|
|
|
// init: function () {
|
|
|
|
// var _this = this;
|
|
|
|
|
|
|
|
// return new Promise(function (resolve, reject) {
|
|
|
|
// MongoClient.connect(config.mongodb, function (err, db) {
|
|
|
|
// if (err) {
|
|
|
|
// return reject(err);
|
|
|
|
// }
|
|
|
|
|
|
|
|
// _this.db = db;
|
|
|
|
// resolve(_this);
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// };"#
|
|
|
|
// );
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-12-24 16:53:48 +03:00
|
|
|
|_| arrow(),
|
2018-11-21 12:59:17 +03:00
|
|
|
paren_insertion,
|
|
|
|
r#"var t = i => i * 5;"#,
|
|
|
|
r#"var t = function (i) {
|
|
|
|
return i * 5;
|
|
|
|
};"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-12-24 16:53:48 +03:00
|
|
|
|_| arrow(),
|
2018-11-21 12:59:17 +03:00
|
|
|
single_argument,
|
|
|
|
r#"var t = (i) => i * 5;"#,
|
|
|
|
r#"var t = function (i) {
|
|
|
|
return i * 5;
|
|
|
|
};"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-01-08 10:34:35 +03:00
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-12-24 16:53:48 +03:00
|
|
|
|_| arrow(),
|
2018-11-21 12:59:17 +03:00
|
|
|
statement,
|
|
|
|
r#"nums.forEach(v => {
|
|
|
|
if (v % 5 === 0) {
|
|
|
|
fives.push(v);
|
|
|
|
}
|
|
|
|
});"#,
|
|
|
|
r#"nums.forEach(function (v) {
|
|
|
|
if (v % 5 === 0) {
|
|
|
|
fives.push(v);
|
|
|
|
}
|
|
|
|
});"#
|
|
|
|
);
|
2019-09-20 07:20:37 +03:00
|
|
|
|
|
|
|
test!(
|
|
|
|
::swc_ecma_parser::Syntax::default(),
|
2019-12-24 16:53:48 +03:00
|
|
|
|_| arrow(),
|
2019-09-20 07:20:37 +03:00
|
|
|
issue_413,
|
|
|
|
r#"
|
|
|
|
export const getBadgeBorderRadius = (text, color) => {
|
|
|
|
return (text && style) || {}
|
|
|
|
}"#,
|
|
|
|
r#"
|
|
|
|
export const getBadgeBorderRadius = function(text, color) {
|
|
|
|
return text && style || {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
"#
|
|
|
|
);
|