mirror of
https://github.com/swc-project/swc.git
synced 2024-12-20 20:22:26 +03:00
d3944f5203
swc_ecma_preset_env: - [x] Rename directory to be consistant. - [x] Add es2020::operators. (#1812) swc_ecma_transforms_react: - [x] Don't escpae unicodes. (#1782)
67 lines
978 B
Rust
67 lines
978 B
Rust
use swc_ecma_parser::{Syntax, TsConfig};
|
|
use swc_ecma_transforms_compat::es2020;
|
|
use swc_ecma_transforms_testing::test;
|
|
use swc_ecma_visit::Fold;
|
|
|
|
fn tr() -> impl Fold {
|
|
es2020::operators()
|
|
}
|
|
|
|
fn syntax() -> Syntax {
|
|
Syntax::Typescript(TsConfig {
|
|
..Default::default()
|
|
})
|
|
}
|
|
|
|
test!(syntax(), |_| tr(), logical_ident, "a ||= b", "a || (a = b)");
|
|
|
|
test!(
|
|
syntax(),
|
|
|_| tr(),
|
|
logical_member,
|
|
"a.b ||= b",
|
|
"
|
|
var _a;
|
|
(_a = a).b || (_a.b = b);
|
|
"
|
|
);
|
|
|
|
test!(
|
|
syntax(),
|
|
|_| tr(),
|
|
logical_super,
|
|
"
|
|
class Foo {
|
|
method() {
|
|
return super.f ||= b
|
|
}
|
|
}
|
|
",
|
|
"
|
|
class Foo {
|
|
method() {
|
|
return super.f || (super.f = b);
|
|
}
|
|
}
|
|
"
|
|
);
|
|
|
|
test!(
|
|
syntax(),
|
|
|_| tr(),
|
|
nullish_ident,
|
|
"a ??= b",
|
|
"a ?? (a = b);"
|
|
);
|
|
|
|
test!(
|
|
syntax(),
|
|
|_| tr(),
|
|
nullish_member,
|
|
"a.b ??= b",
|
|
"
|
|
var _a;
|
|
(_a = a).b ?? (_a.b = b);
|
|
"
|
|
);
|