2021-06-11 10:55:34 +03:00
|
|
|
use swc_ecma_parser::{Syntax, TsConfig};
|
2021-06-26 10:02:15 +03:00
|
|
|
use swc_ecma_transforms_compat::es2021;
|
2021-06-11 10:55:34 +03:00
|
|
|
use swc_ecma_transforms_testing::test;
|
|
|
|
use swc_ecma_visit::Fold;
|
|
|
|
|
|
|
|
fn tr() -> impl Fold {
|
2021-06-26 10:02:15 +03:00
|
|
|
es2021::logical_assignments()
|
2021-06-11 10:55:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"
|
|
|
|
);
|
2021-06-12 09:39:39 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
"
|
|
|
|
);
|