2021-01-05 08:29:52 +03:00
|
|
|
#![cfg(all(
|
|
|
|
feature = "swc_ecma_transforms_compat",
|
|
|
|
feature = "swc_ecma_transforms_module",
|
|
|
|
feature = "swc_ecma_transforms_optimization",
|
|
|
|
feature = "swc_ecma_transforms_proposal",
|
|
|
|
))]
|
|
|
|
|
2020-04-30 17:48:52 +03:00
|
|
|
use swc_common::{chain, Mark};
|
2019-12-24 16:53:48 +03:00
|
|
|
use swc_ecma_parser::Syntax;
|
2022-04-26 10:38:50 +03:00
|
|
|
use swc_ecma_transforms_base::resolver;
|
2021-08-13 13:03:04 +03:00
|
|
|
use swc_ecma_transforms_compat::{
|
|
|
|
es2015::{arrow, block_scoping, classes, function_name, shorthand},
|
2021-10-23 17:25:14 +03:00
|
|
|
es2022::class_properties,
|
2021-08-13 13:03:04 +03:00
|
|
|
};
|
2021-01-05 08:29:52 +03:00
|
|
|
use swc_ecma_transforms_module::common_js::common_js;
|
|
|
|
use swc_ecma_transforms_proposal::decorators;
|
|
|
|
use swc_ecma_transforms_testing::test;
|
2020-07-23 20:18:22 +03:00
|
|
|
use swc_ecma_visit::Fold;
|
2019-12-24 16:53:48 +03:00
|
|
|
|
2019-12-09 15:02:51 +03:00
|
|
|
fn syntax() -> Syntax {
|
|
|
|
Default::default()
|
|
|
|
}
|
2019-01-29 17:56:16 +03:00
|
|
|
|
2020-07-23 20:18:22 +03:00
|
|
|
fn tr() -> impl Fold {
|
2022-04-26 10:38:50 +03:00
|
|
|
let unresolved_mark = Mark::new();
|
|
|
|
let top_level_mark = Mark::new();
|
|
|
|
|
|
|
|
chain!(
|
|
|
|
resolver(unresolved_mark, top_level_mark, false),
|
|
|
|
function_name(),
|
2022-07-13 13:29:03 +03:00
|
|
|
block_scoping(unresolved_mark)
|
2022-04-26 10:38:50 +03:00
|
|
|
)
|
2019-02-28 10:30:56 +03:00
|
|
|
}
|
|
|
|
|
2020-01-30 17:29:12 +03:00
|
|
|
//macro_rules! identical {
|
|
|
|
// ($name:ident, $src:literal) => {
|
|
|
|
// test!(syntax(), |_| tr(), $name, $src, $src);
|
|
|
|
// };
|
|
|
|
//}
|
2018-12-24 04:58:40 +03:00
|
|
|
|
|
|
|
test!(
|
2019-12-09 15:02:51 +03:00
|
|
|
syntax(),
|
2019-02-28 13:25:38 +03:00
|
|
|
|_| tr(),
|
|
|
|
basic,
|
|
|
|
r#"var number = function (x) {
|
2018-12-24 04:58:40 +03:00
|
|
|
return x;
|
|
|
|
};"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-12-09 15:02:51 +03:00
|
|
|
syntax(),
|
2019-02-28 13:25:38 +03:00
|
|
|
|_| tr(),
|
|
|
|
assign,
|
|
|
|
r#"number = function (x) {
|
2018-12-24 04:58:40 +03:00
|
|
|
return x;
|
|
|
|
};"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
2019-12-09 15:02:51 +03:00
|
|
|
syntax(),
|
2019-02-28 13:25:38 +03:00
|
|
|
|_| 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-01-29 17:56:16 +03:00
|
|
|
|
|
|
|
test!(
|
2019-12-09 15:02:51 +03:00
|
|
|
syntax(),
|
2019-02-28 13:25:38 +03:00
|
|
|
|_| tr(),
|
|
|
|
class_simple,
|
|
|
|
r#"
|
2019-01-29 17:56:16 +03:00
|
|
|
var Foo = function() {
|
|
|
|
var Foo = function () {
|
2023-03-31 09:15:21 +03:00
|
|
|
_class_call_check(this, Foo);
|
2019-01-29 17:56:16 +03:00
|
|
|
};
|
2023-03-31 09:15:21 +03:00
|
|
|
_define_property(Foo, 'num', 0);
|
2019-01-29 17:56:16 +03:00
|
|
|
return Foo;
|
|
|
|
}();
|
|
|
|
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-12-09 15:02:51 +03:00
|
|
|
syntax(),
|
2019-02-28 13:25:38 +03:00
|
|
|
|_| 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];
|
|
|
|
};
|
|
|
|
|
2022-06-15 17:36:57 +03:00
|
|
|
return extendStatics(d, b);
|
2019-02-28 10:30:56 +03:00
|
|
|
};"
|
|
|
|
);
|
|
|
|
|
2020-01-24 15:29:57 +03:00
|
|
|
//identical!(
|
|
|
|
// issue_288_02,
|
|
|
|
// "function components_Link_extends() {
|
2020-01-29 09:24:35 +03:00
|
|
|
// 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; };
|
2020-01-24 15:29:57 +03:00
|
|
|
// return components_Link_extends.apply(this, arguments); }"
|
|
|
|
//);
|
2019-12-09 15:02:51 +03:00
|
|
|
|
|
|
|
// issues_5004
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| function_name(),
|
|
|
|
issues_5004,
|
|
|
|
r#"
|
|
|
|
export const x = ({x}) => x;
|
|
|
|
export const y = function () {};
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
//// function_name_export_default_arrow_renaming_module_system
|
|
|
|
//test!(syntax(),|_| tr("{
|
|
|
|
// "plugins": [
|
|
|
|
// function_name(),
|
2020-08-18 19:29:49 +03:00
|
|
|
// shorthand(),
|
2019-12-09 15:02:51 +03:00
|
|
|
// arrow(),
|
|
|
|
// "transform-modules-systemjs"
|
|
|
|
// ]
|
|
|
|
//}
|
|
|
|
//"), function_name_export_default_arrow_renaming_module_system, r#"
|
|
|
|
//export default (a) => {
|
|
|
|
// return { a() { return a } };
|
|
|
|
//}
|
|
|
|
//
|
2023-10-30 04:38:59 +03:00
|
|
|
//"# r#"
|
2019-12-09 15:02:51 +03:00
|
|
|
//System.register([], function (_export, _context) {
|
|
|
|
// "use strict";
|
|
|
|
//
|
|
|
|
// return {
|
|
|
|
// setters: [],
|
|
|
|
// execute: function () {
|
|
|
|
// _export("default", function (_a) {
|
|
|
|
// return {
|
|
|
|
// a: function a() {
|
|
|
|
// return _a;
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
//});
|
|
|
|
//
|
|
|
|
//"#);
|
|
|
|
|
|
|
|
//// function_name_export_default_arrow_renaming_2
|
|
|
|
//test!(syntax(),|_| tr("{
|
|
|
|
// "presets": ["env"]
|
|
|
|
//}
|
|
|
|
//"), function_name_export_default_arrow_renaming_2, r#"
|
|
|
|
//export default () => ({
|
|
|
|
// x: ({x}) => {}
|
|
|
|
//})
|
|
|
|
//
|
2023-10-30 04:38:59 +03:00
|
|
|
//"# r#"
|
2019-12-09 15:02:51 +03:00
|
|
|
//"use strict";
|
|
|
|
//
|
|
|
|
//Object.defineProperty(exports, "__esModule", {
|
|
|
|
// value: true
|
|
|
|
//});
|
|
|
|
//exports["default"] = void 0;
|
|
|
|
//
|
|
|
|
//var _default = function _default() {
|
|
|
|
// return {
|
|
|
|
// x: function x(_ref) {
|
|
|
|
// var _x = _ref.x;
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
//};
|
|
|
|
//
|
|
|
|
//exports["default"] = _default;
|
|
|
|
//
|
|
|
|
//"#);
|
|
|
|
|
|
|
|
// function_name_with_arrow_functions_transform
|
|
|
|
test!(
|
|
|
|
ignore,
|
|
|
|
syntax(),
|
2022-07-13 13:29:03 +03:00
|
|
|
|_| chain!(arrow(Mark::new()), function_name()),
|
2019-12-09 15:02:51 +03:00
|
|
|
function_name_with_arrow_functions_transform,
|
|
|
|
r#"
|
|
|
|
const x = () => x;
|
|
|
|
const y = x => x();
|
|
|
|
const z = { z: () => y(x) }.z;
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// function_name_modules_3
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2022-04-26 10:38:50 +03:00
|
|
|
|t| {
|
|
|
|
let unresolved_mark = Mark::new();
|
|
|
|
let top_level_mark = Mark::new();
|
|
|
|
|
|
|
|
chain!(
|
|
|
|
resolver(unresolved_mark, top_level_mark, true),
|
|
|
|
function_name(),
|
|
|
|
classes(Some(t.comments.clone()), Default::default()),
|
|
|
|
decorators(decorators::Config {
|
|
|
|
legacy: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
2022-07-03 08:54:07 +03:00
|
|
|
common_js(
|
|
|
|
unresolved_mark,
|
|
|
|
Default::default(),
|
|
|
|
Default::default(),
|
|
|
|
Some(t.comments.clone())
|
|
|
|
)
|
2022-04-26 10:38:50 +03:00
|
|
|
)
|
|
|
|
},
|
2019-12-09 15:02:51 +03:00
|
|
|
function_name_modules_3,
|
|
|
|
r#"
|
|
|
|
import {getForm} from "./store"
|
|
|
|
|
|
|
|
export default class Login extends React.Component {
|
|
|
|
getForm() {
|
|
|
|
return getForm().toJS()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// function_name_basic
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2022-04-26 10:38:50 +03:00
|
|
|
|t| {
|
|
|
|
let unresolved_mark = Mark::new();
|
|
|
|
let top_level_mark = Mark::new();
|
|
|
|
|
|
|
|
chain!(
|
|
|
|
resolver(unresolved_mark, top_level_mark, true),
|
|
|
|
decorators(decorators::Config {
|
|
|
|
legacy: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
classes(Some(t.comments.clone()), Default::default()),
|
|
|
|
function_name(),
|
|
|
|
)
|
|
|
|
},
|
2019-12-09 15:02:51 +03:00
|
|
|
function_name_basic,
|
|
|
|
r#"
|
|
|
|
var g = function () {
|
|
|
|
doSmth();
|
|
|
|
};
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// function_name_export_default_arrow_renaming
|
|
|
|
test!(
|
|
|
|
ignore,
|
|
|
|
syntax(),
|
2022-07-13 13:29:03 +03:00
|
|
|
|t| {
|
|
|
|
let unresolved_mark = Mark::new();
|
|
|
|
chain!(
|
|
|
|
arrow(unresolved_mark),
|
|
|
|
shorthand(),
|
|
|
|
function_name(),
|
|
|
|
common_js(
|
|
|
|
unresolved_mark,
|
|
|
|
Default::default(),
|
|
|
|
Default::default(),
|
|
|
|
Some(t.comments.clone())
|
|
|
|
)
|
2022-06-27 15:32:06 +03:00
|
|
|
)
|
2022-07-13 13:29:03 +03:00
|
|
|
},
|
2019-12-09 15:02:51 +03:00
|
|
|
function_name_export_default_arrow_renaming,
|
|
|
|
r#"
|
|
|
|
export default (a) => {
|
|
|
|
return { a() { return a } };
|
|
|
|
}
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// issues_7199
|
|
|
|
test!(
|
|
|
|
// Not important
|
|
|
|
ignore,
|
|
|
|
syntax(),
|
|
|
|
|_| function_name(),
|
|
|
|
issues_7199,
|
|
|
|
r#"
|
|
|
|
const x = {
|
|
|
|
[null]: function () {},
|
|
|
|
[/regex/gi]: function () {},
|
|
|
|
[`y`]: function () {},
|
|
|
|
[`abc${y}def`]: function () {},
|
|
|
|
[0]: function () {},
|
|
|
|
[false]: function () {},
|
|
|
|
};
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
//// function_name_export_default_arrow_renaming_3
|
|
|
|
//test!(syntax(),|_| tr("{
|
|
|
|
// "presets": ["env", "react"]
|
|
|
|
//}
|
|
|
|
//"), function_name_export_default_arrow_renaming_3, r#"
|
|
|
|
//export default ({ onClick }) => (
|
|
|
|
// <div onClick={() => onClick()} />
|
|
|
|
//)
|
|
|
|
//
|
|
|
|
//
|
2023-10-30 04:38:59 +03:00
|
|
|
//"# r#"
|
2019-12-09 15:02:51 +03:00
|
|
|
//"use strict";
|
|
|
|
//
|
|
|
|
//Object.defineProperty(exports, "__esModule", {
|
|
|
|
// value: true
|
|
|
|
//});
|
|
|
|
//exports["default"] = void 0;
|
|
|
|
//
|
|
|
|
//var _default = function _default(_ref) {
|
|
|
|
// var _onClick = _ref.onClick;
|
|
|
|
// return React.createElement("div", {
|
|
|
|
// onClick: function onClick() {
|
|
|
|
// return _onClick();
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
//};
|
|
|
|
//
|
|
|
|
//exports["default"] = _default;
|
|
|
|
//
|
|
|
|
//"#);
|
|
|
|
|
|
|
|
//// function_name_export_default_arrow_renaming_es3
|
|
|
|
//test!(syntax(),|_| tr("{
|
|
|
|
// "presets": ["env"],
|
|
|
|
// "plugins": [
|
|
|
|
// "transform-member-expression-literals",
|
|
|
|
// "transform-property-literals"
|
|
|
|
// ]
|
|
|
|
//}
|
|
|
|
//"), function_name_export_default_arrow_renaming_es3, r#"
|
|
|
|
//export default (a) => {
|
|
|
|
// return { a() { return a } };
|
|
|
|
//}
|
|
|
|
//
|
2023-10-30 04:38:59 +03:00
|
|
|
//"# r#"
|
2019-12-09 15:02:51 +03:00
|
|
|
//"use strict";
|
|
|
|
//
|
|
|
|
//Object.defineProperty(exports, "__esModule", {
|
|
|
|
// value: true
|
|
|
|
//});
|
|
|
|
//exports["default"] = void 0;
|
|
|
|
//
|
|
|
|
//var _default = function _default(_a) {
|
|
|
|
// return {
|
|
|
|
// a: function a() {
|
|
|
|
// return _a;
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
//};
|
|
|
|
//
|
|
|
|
//exports["default"] = _default;
|
|
|
|
//
|
|
|
|
//"#);
|
|
|
|
|
|
|
|
// function_name_self_reference
|
|
|
|
test!(
|
|
|
|
// not important
|
|
|
|
ignore,
|
|
|
|
syntax(),
|
2022-04-26 10:38:50 +03:00
|
|
|
|t| {
|
|
|
|
let unresolved_mark = Mark::new();
|
|
|
|
let top_level_mark = Mark::new();
|
|
|
|
|
|
|
|
chain!(
|
|
|
|
resolver(unresolved_mark, top_level_mark, true),
|
|
|
|
decorators(decorators::Config {
|
|
|
|
legacy: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
function_name(),
|
|
|
|
classes(Some(t.comments.clone()), Default::default())
|
|
|
|
)
|
|
|
|
},
|
2019-12-09 15:02:51 +03:00
|
|
|
function_name_self_reference,
|
|
|
|
r#"
|
|
|
|
var f = function () {
|
|
|
|
console.log(f, g);
|
|
|
|
};
|
|
|
|
|
|
|
|
f = null;
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// function_name_with_arrow_functions_transform_spec
|
|
|
|
test!(
|
|
|
|
ignore,
|
|
|
|
syntax(),
|
2022-07-13 13:29:03 +03:00
|
|
|
|_| chain!(arrow(Mark::new()), function_name()),
|
2019-12-09 15:02:51 +03:00
|
|
|
function_name_with_arrow_functions_transform_spec,
|
|
|
|
r#"
|
|
|
|
// These are actually handled by transform-arrow-functions
|
|
|
|
const x = () => x;
|
|
|
|
const y = x => x();
|
|
|
|
const z = { z: () => y(x) }.z;
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// function_name_method_definition
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2022-04-26 10:38:50 +03:00
|
|
|
|t| {
|
|
|
|
let unresolved_mark = Mark::new();
|
|
|
|
let top_level_mark = Mark::new();
|
|
|
|
|
|
|
|
chain!(
|
|
|
|
resolver(unresolved_mark, top_level_mark, true),
|
|
|
|
decorators(decorators::Config {
|
|
|
|
legacy: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
classes(Some(t.comments.clone()), Default::default()),
|
|
|
|
function_name(),
|
|
|
|
)
|
|
|
|
},
|
2019-12-09 15:02:51 +03:00
|
|
|
function_name_method_definition,
|
|
|
|
r#"
|
|
|
|
({ x() {} });
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2021-01-05 08:29:52 +03:00
|
|
|
// function_name_export_default_arrow_renaming_module_es6
|
|
|
|
test!(
|
|
|
|
ignore,
|
|
|
|
syntax(),
|
2022-07-13 13:29:03 +03:00
|
|
|
|_| chain!(arrow(Mark::new()), shorthand(), function_name()),
|
2021-01-05 08:29:52 +03:00
|
|
|
function_name_export_default_arrow_renaming_module_es6,
|
|
|
|
r#"
|
|
|
|
export default (a) => {
|
|
|
|
return { a() { return a } };
|
|
|
|
}
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// function_name_assignment
|
|
|
|
test!(
|
|
|
|
// not important
|
|
|
|
ignore,
|
|
|
|
syntax(),
|
|
|
|
|_| tr(),
|
|
|
|
function_name_assignment,
|
|
|
|
r#"
|
|
|
|
var i = function () {
|
|
|
|
i = 5;
|
|
|
|
};
|
|
|
|
|
|
|
|
var j = function () {
|
|
|
|
({ j } = 5);
|
|
|
|
({ y: j } = 5);
|
|
|
|
;
|
|
|
|
};
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2019-12-09 15:02:51 +03:00
|
|
|
// function_name_own_bindings
|
|
|
|
test!(
|
|
|
|
// not important
|
|
|
|
ignore,
|
|
|
|
syntax(),
|
2022-04-26 10:38:50 +03:00
|
|
|
|t| {
|
|
|
|
let unresolved_mark = Mark::new();
|
|
|
|
let top_level_mark = Mark::new();
|
|
|
|
|
|
|
|
chain!(
|
|
|
|
resolver(unresolved_mark, top_level_mark, true),
|
|
|
|
decorators(decorators::Config {
|
|
|
|
legacy: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
classes(Some(t.comments.clone()), Default::default()),
|
|
|
|
function_name(),
|
|
|
|
)
|
|
|
|
},
|
2019-12-09 15:02:51 +03:00
|
|
|
function_name_own_bindings,
|
|
|
|
r#"
|
|
|
|
var f = function () {
|
2021-01-05 08:29:52 +03:00
|
|
|
var f = 2;
|
2019-12-09 15:02:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
var g = function (g) {
|
2021-01-05 08:29:52 +03:00
|
|
|
g;
|
2019-12-09 15:02:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
var obj = {
|
2021-01-05 08:29:52 +03:00
|
|
|
f: function (f) {
|
|
|
|
f;
|
|
|
|
}
|
2019-12-09 15:02:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2021-01-05 08:29:52 +03:00
|
|
|
// decorators_legacy_interop_strict
|
2019-12-09 15:02:51 +03:00
|
|
|
test!(
|
2021-01-05 08:29:52 +03:00
|
|
|
// See: https://github.com/swc-project/swc/issues/421
|
2019-12-09 15:02:51 +03:00
|
|
|
ignore,
|
|
|
|
syntax(),
|
2023-11-03 01:18:17 +03:00
|
|
|
|t| {
|
|
|
|
let unresolved_mark = Mark::new();
|
|
|
|
let top_level_mark = Mark::new();
|
|
|
|
|
|
|
|
chain!(
|
|
|
|
resolver(unresolved_mark, top_level_mark, true),
|
|
|
|
decorators(decorators::Config {
|
|
|
|
legacy: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
class_properties(
|
|
|
|
Some(t.comments.clone()),
|
|
|
|
Default::default(),
|
|
|
|
unresolved_mark
|
|
|
|
),
|
|
|
|
classes(Some(t.comments.clone()), Default::default()),
|
|
|
|
)
|
|
|
|
},
|
2021-01-05 08:29:52 +03:00
|
|
|
decorators_legacy_interop_strict,
|
2019-12-09 15:02:51 +03:00
|
|
|
r#"
|
2021-01-05 08:29:52 +03:00
|
|
|
function dec() {}
|
|
|
|
|
|
|
|
class A {
|
|
|
|
@dec a;
|
|
|
|
|
|
|
|
@dec b = 123;
|
|
|
|
|
|
|
|
c = 456;
|
2019-12-09 15:02:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
2021-01-05 08:29:52 +03:00
|
|
|
// function_name_function_collision
|
2019-12-09 15:02:51 +03:00
|
|
|
test!(
|
|
|
|
ignore,
|
|
|
|
syntax(),
|
2022-04-26 10:38:50 +03:00
|
|
|
|t| {
|
|
|
|
let unresolved_mark = Mark::new();
|
|
|
|
let top_level_mark = Mark::new();
|
|
|
|
|
|
|
|
chain!(
|
|
|
|
resolver(unresolved_mark, top_level_mark, true),
|
|
|
|
decorators(decorators::Config {
|
|
|
|
legacy: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
classes(Some(t.comments.clone()), Default::default()),
|
|
|
|
function_name(),
|
|
|
|
)
|
|
|
|
},
|
2021-01-05 08:29:52 +03:00
|
|
|
function_name_function_collision,
|
2019-12-09 15:02:51 +03:00
|
|
|
r#"
|
2021-01-05 08:29:52 +03:00
|
|
|
function f() {
|
|
|
|
f;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
let obj = {
|
|
|
|
f: function () {
|
|
|
|
f;
|
|
|
|
}
|
2019-12-09 15:02:51 +03:00
|
|
|
};
|
2021-01-05 08:29:52 +03:00
|
|
|
}
|
2019-12-09 15:02:51 +03:00
|
|
|
|
2021-01-05 08:29:52 +03:00
|
|
|
(function b() {
|
|
|
|
var obj = {
|
|
|
|
b: function () {
|
|
|
|
b;
|
|
|
|
}
|
2019-12-09 15:02:51 +03:00
|
|
|
};
|
|
|
|
|
2021-01-05 08:29:52 +03:00
|
|
|
function commit(b) {
|
|
|
|
b();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// function_name_collisions
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2022-04-26 10:38:50 +03:00
|
|
|
|t| {
|
|
|
|
let unresolved_mark = Mark::new();
|
|
|
|
let top_level_mark = Mark::new();
|
|
|
|
|
|
|
|
chain!(
|
|
|
|
resolver(unresolved_mark, top_level_mark, true),
|
|
|
|
decorators(decorators::Config {
|
|
|
|
legacy: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
classes(Some(t.comments.clone()), Default::default()),
|
|
|
|
function_name(),
|
|
|
|
)
|
|
|
|
},
|
2021-01-05 08:29:52 +03:00
|
|
|
function_name_collisions,
|
|
|
|
r#"
|
|
|
|
var obj = {
|
2021-12-03 19:55:27 +03:00
|
|
|
search: function({search}) {
|
|
|
|
console.log(search);
|
|
|
|
}
|
2021-01-05 08:29:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
function search({search}) {
|
2021-12-03 19:55:27 +03:00
|
|
|
console.log(search);
|
2021-01-05 08:29:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// function_name_modules_2
|
|
|
|
test!(
|
|
|
|
ignore,
|
|
|
|
Default::default(),
|
2022-04-26 10:38:50 +03:00
|
|
|
|t| {
|
|
|
|
let unresolved_mark = Mark::new();
|
|
|
|
let top_level_mark = Mark::new();
|
|
|
|
|
|
|
|
chain!(
|
|
|
|
resolver(unresolved_mark, top_level_mark, true),
|
|
|
|
decorators(decorators::Config {
|
|
|
|
legacy: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
classes(Some(t.comments.clone()), Default::default()),
|
|
|
|
function_name(),
|
2022-07-03 08:54:07 +03:00
|
|
|
common_js(
|
|
|
|
unresolved_mark,
|
|
|
|
Default::default(),
|
|
|
|
Default::default(),
|
|
|
|
Some(t.comments.clone())
|
|
|
|
)
|
2022-04-26 10:38:50 +03:00
|
|
|
)
|
|
|
|
},
|
2021-01-05 08:29:52 +03:00
|
|
|
function_name_modules_2,
|
|
|
|
r#"
|
|
|
|
import last from "lodash/last"
|
|
|
|
|
|
|
|
export default class Container {
|
|
|
|
last(key) {
|
|
|
|
if (!this.has(key)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return last(this.tokens.get(key))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// function_name_await
|
|
|
|
test!(
|
|
|
|
Default::default(),
|
2022-04-26 10:38:50 +03:00
|
|
|
|t| {
|
|
|
|
let unresolved_mark = Mark::new();
|
|
|
|
let top_level_mark = Mark::new();
|
|
|
|
|
|
|
|
chain!(
|
|
|
|
resolver(unresolved_mark, top_level_mark, true),
|
|
|
|
decorators(decorators::Config {
|
|
|
|
legacy: true,
|
|
|
|
..Default::default()
|
|
|
|
}),
|
|
|
|
classes(Some(t.comments.clone()), Default::default()),
|
|
|
|
function_name(),
|
|
|
|
)
|
|
|
|
},
|
2021-01-05 08:29:52 +03:00
|
|
|
function_name_await,
|
|
|
|
r#"
|
|
|
|
export {};
|
|
|
|
|
|
|
|
var obj = { await: function () {} };
|
|
|
|
|
2019-12-09 15:02:51 +03:00
|
|
|
"#
|
|
|
|
);
|