2019-11-15 08:34:48 +03:00
|
|
|
use swc_ecma_parser::{Syntax, TsConfig};
|
2021-01-05 08:29:52 +03:00
|
|
|
use swc_ecma_transforms_compat::es2020::optional_chaining;
|
2021-08-13 13:03:04 +03:00
|
|
|
use swc_ecma_transforms_testing::{test, test_exec};
|
2020-07-23 20:18:22 +03:00
|
|
|
use swc_ecma_visit::Fold;
|
2019-12-24 16:53:48 +03:00
|
|
|
|
2020-07-23 20:18:22 +03:00
|
|
|
fn tr(_: ()) -> impl Fold {
|
2019-11-15 08:34:48 +03:00
|
|
|
optional_chaining()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn syntax() -> Syntax {
|
|
|
|
Syntax::Typescript(TsConfig {
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// general_memoize_loose
|
|
|
|
|
|
|
|
// general_lhs_assignment_read_and_update
|
|
|
|
|
|
|
|
// general_function_call_loose
|
|
|
|
|
|
|
|
// regression_7642
|
|
|
|
|
|
|
|
// general_super_method_call_loose
|
|
|
|
|
|
|
|
// general_lhs_update
|
|
|
|
|
|
|
|
// general_assignment
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
general_assignment,
|
|
|
|
r#"
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const obj = {
|
|
|
|
a: {
|
|
|
|
b: {
|
|
|
|
c: {
|
|
|
|
d: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const a = obj?.a;
|
|
|
|
|
|
|
|
const b = obj?.a?.b;
|
|
|
|
|
|
|
|
const bad = obj?.b?.b;
|
|
|
|
|
|
|
|
let val;
|
|
|
|
val = obj?.a?.b;
|
|
|
|
|
|
|
|
"#,
|
|
|
|
r#"
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var ref, ref1, ref2;
|
|
|
|
|
|
|
|
const obj = {
|
|
|
|
a: {
|
|
|
|
b: {
|
|
|
|
c: {
|
|
|
|
d: 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const a = obj === null || obj === void 0 ? void 0 : obj.a;
|
|
|
|
const b = obj === null || obj === void 0 ? void 0 : (ref = obj.a) === null || ref === void 0 ? void 0 : ref.b;
|
|
|
|
const bad = obj === null || obj === void 0 ? void 0 : (ref1 = obj.b) === null || ref1 === void 0 ? void 0 : ref1.b;
|
|
|
|
let val;
|
|
|
|
val = obj === null || obj === void 0 ? void 0 : (ref2 = obj.a) === null || ref2 === void 0 ? void 0 : ref2.b;
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// general_memoize
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
general_memoize,
|
|
|
|
r#"
|
|
|
|
function test(foo) {
|
|
|
|
foo?.bar;
|
|
|
|
|
|
|
|
foo?.bar?.baz;
|
|
|
|
|
|
|
|
foo?.(foo);
|
|
|
|
|
|
|
|
foo?.bar()
|
|
|
|
|
|
|
|
foo.bar?.(foo.bar, false)
|
|
|
|
|
|
|
|
foo?.bar?.(foo.bar, true)
|
|
|
|
|
|
|
|
foo.bar?.baz(foo.bar, false)
|
|
|
|
|
|
|
|
foo?.bar?.baz(foo.bar, true)
|
|
|
|
|
|
|
|
foo.bar?.baz?.(foo.bar, false)
|
|
|
|
|
|
|
|
foo?.bar?.baz?.(foo.bar, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
"#,
|
|
|
|
r#"
|
|
|
|
function test(foo) {
|
|
|
|
var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8;
|
|
|
|
foo === null || foo === void 0 ? void 0 : foo.bar;
|
|
|
|
foo === null || foo === void 0 ? void 0 : (ref = foo.bar) === null || ref === void 0 ? void 0 : ref.baz;
|
|
|
|
foo === null || foo === void 0 ? void 0 : foo(foo);
|
|
|
|
foo === null || foo === void 0 ? void 0 : foo.bar();
|
2020-09-06 13:47:15 +03:00
|
|
|
(ref1 = foo.bar) === null || ref1 === void 0 ? void 0 : ref1.call(foo, foo.bar, false);
|
|
|
|
foo === null || foo === void 0 ? void 0 : (ref2 = foo.bar) === null || ref2 === void 0 ? void 0 : ref2.call(foo, foo.bar, true);
|
2019-11-15 08:34:48 +03:00
|
|
|
(ref3 = foo.bar) === null || ref3 === void 0 ? void 0 : ref3.baz(foo.bar, false);
|
|
|
|
foo === null || foo === void 0 ? void 0 : (ref4 = foo.bar) === null || ref4 === void 0 ? void 0 : ref4.baz(foo.bar, true);
|
2020-09-06 13:47:15 +03:00
|
|
|
(ref5 = foo.bar) === null || ref5 === void 0 ? void 0 : (ref6 = ref5.baz) === null || ref6 === void 0 ? void 0 : ref6.call(ref5, foo.bar, false);
|
|
|
|
foo === null || foo === void 0 ? void 0 : (ref7 = foo.bar) === null || ref7 === void 0 ? void 0 : (ref8 = ref7.baz) === null || ref8 === void 0 ? void 0 : ref8.call(ref7, foo.bar, true);
|
2019-11-15 08:34:48 +03:00
|
|
|
}
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// general_containers
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
general_containers,
|
|
|
|
r#"
|
|
|
|
var street = user.address?.street
|
|
|
|
street = user.address?.street
|
|
|
|
|
|
|
|
test(a?.b, 1);
|
|
|
|
|
|
|
|
(a?.b, 2);
|
|
|
|
|
|
|
|
"#,
|
|
|
|
r#"
|
|
|
|
var ref, ref1;
|
|
|
|
|
|
|
|
var street = (ref = user.address) === null || ref === void 0 ? void 0 : ref.street;
|
|
|
|
street = (ref1 = user.address) === null || ref1 === void 0 ? void 0 : ref1.street;
|
|
|
|
test(a === null || a === void 0 ? void 0 : a.b, 1);
|
|
|
|
a === null || a === void 0 ? void 0 : a.b, 2;
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// general_function_call_spread
|
|
|
|
|
|
|
|
// general_lhs_assignment
|
|
|
|
|
|
|
|
// general_delete_exec
|
|
|
|
test_exec!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
general_delete_exec,
|
|
|
|
r#"
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const obj = {
|
|
|
|
a: {
|
|
|
|
b: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let test = delete obj?.a?.b;
|
|
|
|
expect(obj.a.b).toBeUndefined();
|
|
|
|
expect(test).toBe(true);
|
|
|
|
|
|
|
|
test = delete obj?.a.b;
|
|
|
|
expect(obj.a.b).toBeUndefined();
|
|
|
|
expect(test).toBe(true);
|
|
|
|
|
|
|
|
test = delete obj?.b?.b;
|
|
|
|
expect(obj.b).toBeUndefined();
|
|
|
|
expect(test).toBeUndefined();
|
|
|
|
|
|
|
|
delete obj?.a;
|
|
|
|
expect(obj.a).toBeUndefined();
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// general_member_access
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
general_member_access,
|
|
|
|
r#"
|
|
|
|
foo?.bar;
|
|
|
|
|
|
|
|
a?.b.c?.d.e;
|
|
|
|
|
|
|
|
a.b?.c.d?.e;
|
|
|
|
|
|
|
|
a.b.c?.d?.e;
|
|
|
|
|
|
|
|
orders?.[0].price;
|
|
|
|
|
|
|
|
orders?.[0]?.price;
|
|
|
|
|
|
|
|
orders[client?.key].price;
|
|
|
|
|
|
|
|
orders[client.key]?.price;
|
|
|
|
|
|
|
|
(0, a?.b).c;
|
|
|
|
|
|
|
|
(0, (0, a?.b).c?.d).e;
|
|
|
|
|
|
|
|
"#,
|
|
|
|
r#"
|
|
|
|
var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7;
|
|
|
|
foo === null || foo === void 0 ? void 0 : foo.bar;
|
|
|
|
(ref = a === null || a === void 0 ? void 0 : a.b.c) === null || ref === void 0 ? void 0 : ref.d.e;
|
2021-07-07 11:41:03 +03:00
|
|
|
(ref2 = (ref1 = a.b) === null || ref1 === void 0 ? void 0 : ref1.c.d) === null || ref2 === void 0 ? void 0 : ref2.e;
|
2019-11-15 08:34:48 +03:00
|
|
|
(ref3 = a.b.c) === null || ref3 === void 0 ? void 0 : (ref4 = ref3.d) === null || ref4 === void 0 ? void 0 : ref4.e;
|
|
|
|
orders === null || orders === void 0 ? void 0 : orders[0].price;
|
|
|
|
orders === null || orders === void 0 ? void 0 : (ref5 = orders[0]) === null || ref5 === void 0 ? void 0 : ref5.price;
|
|
|
|
orders[client === null || client === void 0 ? void 0 : client.key].price;
|
|
|
|
(ref6 = orders[client.key]) === null || ref6 === void 0 ? void 0 : ref6.price;
|
2021-04-13 18:18:24 +03:00
|
|
|
(0, a === null || a === void 0 ? void 0 : a.b).c;
|
|
|
|
(0, (ref7 = (0, a === null || a === void 0 ? void 0 : a.b).c) === null || ref7 === void 0 ? void 0 : ref7.d).e;
|
2019-11-15 08:34:48 +03:00
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// general_unary
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
general_unary,
|
|
|
|
r#"
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const obj = {
|
|
|
|
a: {
|
|
|
|
b: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let test = +obj?.a?.b;
|
|
|
|
|
|
|
|
test = +obj?.a.b;
|
|
|
|
|
|
|
|
test = +obj?.b?.b;
|
|
|
|
|
|
|
|
test = +obj?.b?.b;
|
|
|
|
|
|
|
|
"#,
|
|
|
|
r#"
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var ref, ref1, ref2;
|
|
|
|
|
|
|
|
const obj = {
|
|
|
|
a: {
|
|
|
|
b: 0
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let test = +(obj === null || obj === void 0 ? void 0 : (ref = obj.a) === null || ref === void 0 ? void 0 : ref.b);
|
|
|
|
test = +(obj === null || obj === void 0 ? void 0 : obj.a.b);
|
|
|
|
test = +(obj === null || obj === void 0 ? void 0 : (ref1 = obj.b) === null || ref1 === void 0 ? void 0 : ref1.b);
|
|
|
|
test = +(obj === null || obj === void 0 ? void 0 : (ref2 = obj.b) === null || ref2 === void 0 ? void 0 : ref2.b);
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// regression_8354
|
|
|
|
|
|
|
|
// general_function_call
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
general_function_call,
|
|
|
|
r#"
|
|
|
|
foo?.(foo);
|
|
|
|
|
|
|
|
foo?.bar()
|
|
|
|
|
|
|
|
foo.bar?.(foo.bar, false)
|
|
|
|
|
|
|
|
foo?.bar?.(foo.bar, true)
|
|
|
|
|
|
|
|
foo?.().bar
|
|
|
|
|
|
|
|
foo?.()?.bar
|
|
|
|
|
|
|
|
foo.bar?.().baz
|
|
|
|
|
|
|
|
foo.bar?.()?.baz
|
|
|
|
|
|
|
|
foo?.bar?.().baz
|
|
|
|
|
|
|
|
foo?.bar?.()?.baz
|
|
|
|
|
2021-07-07 11:41:03 +03:00
|
|
|
foo?.bar()?.()
|
|
|
|
|
2019-11-15 08:34:48 +03:00
|
|
|
"#,
|
|
|
|
r#"
|
2021-07-07 11:41:03 +03:00
|
|
|
var ref, ref1, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9;
|
2019-11-15 08:34:48 +03:00
|
|
|
foo === null || foo === void 0 ? void 0 : foo(foo);
|
|
|
|
foo === null || foo === void 0 ? void 0 : foo.bar();
|
2020-09-06 13:47:15 +03:00
|
|
|
(ref = foo.bar) === null || ref === void 0 ? void 0 : ref.call(foo, foo.bar, false);
|
|
|
|
foo === null || foo === void 0 ? void 0 : (ref1 = foo.bar) === null || ref1 === void 0 ? void 0 : ref1.call(foo, foo.bar, true);
|
2019-11-15 08:34:48 +03:00
|
|
|
foo === null || foo === void 0 ? void 0 : foo().bar;
|
|
|
|
foo === null || foo === void 0 ? void 0 : (ref2 = foo()) === null || ref2 === void 0 ? void 0 : ref2.bar;
|
2020-09-06 13:47:15 +03:00
|
|
|
(ref3 = foo.bar) === null || ref3 === void 0 ? void 0 : ref3.call(foo).baz;
|
|
|
|
(ref4 = foo.bar) === null || ref4 === void 0 ? void 0 : (ref5 = ref4.call(foo)) === null || ref5 === void 0 ? void 0 : ref5.baz;
|
|
|
|
foo === null || foo === void 0 ? void 0 : (ref6 = foo.bar) === null || ref6 === void 0 ? void 0 : ref6.call(foo).baz;
|
2021-07-07 11:41:03 +03:00
|
|
|
foo === null || foo === void 0 ? void 0 : (ref7 = foo.bar) === null || ref7 === void 0 ? void 0 : (ref8 = ref7.call(foo)) === null || ref8 === void 0 ? void 0 : ref8.baz;
|
|
|
|
var _obj = foo === null || foo === void 0 ? void 0 : foo.bar();
|
|
|
|
(ref9 = _obj) === null || ref9 === void 0 ? void 0 : ref9.call(_obj);"#
|
2019-11-15 08:34:48 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
// general_unary_exec
|
|
|
|
test_exec!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
general_unary_exec,
|
|
|
|
r#"
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const obj = {
|
|
|
|
a: {
|
|
|
|
b: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let test = +obj?.a?.b;
|
|
|
|
expect(test).toBe(0);
|
|
|
|
|
|
|
|
test = +obj?.a.b;
|
|
|
|
expect(test).toBe(0);
|
|
|
|
|
|
|
|
test = +obj?.b?.b;
|
|
|
|
expect(test).toBe(NaN);
|
|
|
|
|
|
|
|
test = +obj?.b?.b;
|
|
|
|
expect(test).toBe(NaN);
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// general_call_exec
|
|
|
|
test_exec!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
general_call_exec,
|
|
|
|
r#"
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// general_delete
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
general_delete,
|
|
|
|
r#"
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const obj = {
|
|
|
|
a: {
|
|
|
|
b: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let test = delete obj?.a?.b;
|
|
|
|
|
|
|
|
test = delete obj?.a.b;
|
|
|
|
|
|
|
|
test = delete obj?.b?.b;
|
|
|
|
|
|
|
|
delete obj?.a;
|
|
|
|
|
|
|
|
"#,
|
|
|
|
r#"
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var ref, ref1;
|
|
|
|
|
|
|
|
const obj = {
|
|
|
|
a: {
|
|
|
|
b: 0
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let test = obj === null || obj === void 0 ? void 0 : (ref = obj.a) === null || ref === void 0 ? void 0 : delete ref.b;
|
|
|
|
test = obj === null || obj === void 0 ? void 0 : delete obj.a.b;
|
|
|
|
test = obj === null || obj === void 0 ? void 0 : (ref1 = obj.b) === null || ref1 === void 0 ? void 0 : delete ref1.b;
|
|
|
|
obj === null || obj === void 0 ? void 0 : delete obj.a;
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// regression_8354_exec
|
|
|
|
test_exec!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
regression_8354_exec,
|
|
|
|
r#"
|
|
|
|
const foo = undefined;
|
|
|
|
const bar = 'bar';
|
|
|
|
const foobar = foo?.replace(`foo${bar}`, '');
|
|
|
|
|
|
|
|
expect(foobar).toBe(undefined);
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// general_assignment_exec
|
|
|
|
test_exec!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
general_assignment_exec,
|
|
|
|
r#"
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const obj = {
|
|
|
|
a: {
|
|
|
|
b: {
|
|
|
|
c: {
|
|
|
|
d: 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const a = obj?.a;
|
|
|
|
expect(a).toBe(obj.a);
|
|
|
|
|
|
|
|
const b = obj?.a?.b;
|
|
|
|
expect(b).toBe(obj.a.b);
|
|
|
|
|
|
|
|
const bad = obj?.b?.b;
|
|
|
|
expect(bad).toBeUndefined();
|
|
|
|
|
|
|
|
let val;
|
|
|
|
val = obj?.a?.b;
|
|
|
|
expect(val).toBe(obj.a.b);
|
|
|
|
|
|
|
|
expect(() => {
|
|
|
|
const bad = obj?.b.b;
|
|
|
|
}).toThrow();
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
// general_super_method_call
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
general_super_method_call,
|
|
|
|
r#"
|
|
|
|
"use strict";
|
|
|
|
class Base {
|
|
|
|
method() {
|
|
|
|
return 'Hello!';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class Derived extends Base {
|
|
|
|
method() {
|
|
|
|
return super.method?.()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
"#,
|
|
|
|
r#"
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
class Base {
|
|
|
|
method() {
|
|
|
|
return 'Hello!';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class Derived extends Base {
|
|
|
|
method() {
|
|
|
|
var ref;
|
|
|
|
|
|
|
|
return (ref = super.method) === null || ref === void 0 ? void 0 : ref.call(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
"#
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
simple_1,
|
|
|
|
"obj?.a",
|
|
|
|
"obj === null || obj === void 0 ? void 0 : obj.a;"
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
simple_2,
|
|
|
|
"obj?.a?.b",
|
|
|
|
"var ref;
|
|
|
|
obj === null || obj === void 0 ? void 0 : (ref = obj.a) === null || ref === void 0 ? void 0 : \
|
|
|
|
ref.b;"
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
simple_3,
|
|
|
|
"obj?.a?.b.c",
|
|
|
|
"var ref;
|
|
|
|
obj === null || obj === void 0 ? void 0 : (ref = obj.a) === null || ref === void 0 ? void 0 : \
|
|
|
|
ref.b.c;"
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
call_1,
|
|
|
|
"obj?.a?.b()",
|
|
|
|
"var ref;
|
|
|
|
obj === null || obj === void 0 ? void 0 : (ref = obj.a) === null || ref === void 0 ? void 0 : \
|
|
|
|
ref.b();",
|
|
|
|
ok_if_code_eq
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
2019-11-17 07:21:53 +03:00
|
|
|
|_| tr(()),
|
2019-11-15 08:34:48 +03:00
|
|
|
call_2,
|
|
|
|
"a?.b?.c?.()",
|
|
|
|
"var ref, ref1;
|
|
|
|
|
|
|
|
a === null || a === void 0
|
|
|
|
? void 0
|
|
|
|
: (ref = a.b) === null || ref === void 0
|
|
|
|
? void 0
|
|
|
|
: (ref1 = ref.c) === null || ref1 === void 0
|
|
|
|
? void 0
|
2020-09-06 13:47:15 +03:00
|
|
|
: ref1.call(ref);"
|
2019-11-15 08:34:48 +03:00
|
|
|
);
|
2020-03-28 05:59:45 +03:00
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
issue_732_1,
|
|
|
|
"test.a?.b.c.d",
|
|
|
|
"var ref;
|
|
|
|
(ref = test.a) === null || ref === void 0 ? void 0 : ref.b.c.d"
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
issue_732_2,
|
|
|
|
"test.a?.b.c",
|
|
|
|
"var ref;
|
|
|
|
(ref = test.a) === null || ref === void 0 ? void 0 : ref.b.c;"
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
issue_732_3,
|
|
|
|
"test.a?.b.c.d.e.f.g.h.i",
|
|
|
|
"var ref;
|
|
|
|
(ref = test.a) === null || ref === void 0 ? void 0 : ref.b.c.d.e.f.g.h.i"
|
|
|
|
);
|
2020-09-06 13:47:15 +03:00
|
|
|
|
|
|
|
// https://github.com/Brooooooklyn/swc-node/issues/62
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
swc_node_issue_62,
|
|
|
|
"a.focus?.()",
|
|
|
|
"var ref;
|
|
|
|
(ref = a.focus) === null || ref === void 0 ? void 0 : ref.call(a);"
|
|
|
|
);
|
2020-09-22 10:39:00 +03:00
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
issue_1092_1,
|
|
|
|
"a?.b.c()",
|
|
|
|
"a === null || a === void 0 ? void 0 : a.b.c();"
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
issue_1092_2,
|
|
|
|
"a?.b.c.d.e.f.g.h()",
|
|
|
|
"a === null || a === void 0 ? void 0 : a.b.c.d.e.f.g.h();"
|
|
|
|
);
|
2020-09-23 15:44:51 +03:00
|
|
|
|
|
|
|
test_exec!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
swc_node_95,
|
|
|
|
"
|
|
|
|
const obj = {
|
|
|
|
a: {
|
|
|
|
b: {
|
|
|
|
c: function () {
|
|
|
|
return this.foo
|
|
|
|
},
|
|
|
|
foo: 2,
|
|
|
|
},
|
|
|
|
foo: 1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(obj?.a?.b?.c()).toBe(2)
|
|
|
|
"
|
|
|
|
);
|
2020-09-24 09:14:30 +03:00
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
swc_node_95_2,
|
|
|
|
"
|
|
|
|
obj?.a?.b?.c()
|
|
|
|
",
|
|
|
|
"
|
|
|
|
var ref, ref1;
|
|
|
|
obj === null || obj === void 0 ? void 0 : (ref = obj.a) === null || ref === void 0 ? void 0 : \
|
|
|
|
(ref1 = ref.b) === null || ref1 === void 0 ? void 0 : ref1.c();"
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
swc_node_95_3,
|
|
|
|
"
|
|
|
|
expect(obj?.a?.b?.c()).toBe(2)
|
|
|
|
",
|
|
|
|
"
|
2020-10-04 15:59:19 +03:00
|
|
|
var ref, ref1;
|
2020-09-24 09:14:30 +03:00
|
|
|
expect(obj === null || obj === void 0 ? void 0 : (ref = obj.a) === null || ref === void 0 ? void 0 \
|
|
|
|
: (ref1 = ref.b) === null || ref1 === void 0 ? void 0 : ref1.c()).toBe(2);
|
|
|
|
"
|
|
|
|
);
|
2020-10-04 15:59:19 +03:00
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
issue_1130_1,
|
|
|
|
"
|
|
|
|
const result = data?.filter(item => Math.random() > 0.5).map(item => JSON.stringify(item));
|
|
|
|
",
|
|
|
|
"
|
|
|
|
const result = data === null || data === void 0 ? void 0 : data.filter(item => Math.random() > \
|
|
|
|
0.5).map(item => JSON.stringify(item));
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
issue_1130_2,
|
|
|
|
"
|
|
|
|
const r = d?.filter(i => Math.random() > 0.5).map(i => JSON.stringify(i));
|
|
|
|
",
|
|
|
|
"
|
|
|
|
const r = d === null || d === void 0 ? void 0 : d.filter(i => Math.random() > 0.5).map(i => \
|
|
|
|
JSON.stringify(i));
|
|
|
|
"
|
|
|
|
);
|
2020-10-06 17:27:23 +03:00
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
issue_1133_1,
|
|
|
|
"
|
|
|
|
async function foo() {
|
|
|
|
const item = await data?.foo();
|
|
|
|
}
|
|
|
|
",
|
|
|
|
"
|
|
|
|
async function foo() {
|
|
|
|
const item = await (data === null || data === void 0 ? void 0 : data.foo());
|
|
|
|
}
|
|
|
|
"
|
|
|
|
);
|
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
issue_1136_1,
|
|
|
|
"
|
|
|
|
const PATCHES = new Map();
|
|
|
|
|
|
|
|
const ident = 'foo';
|
|
|
|
const patch = PATCHES.get(ident)?.();
|
|
|
|
",
|
|
|
|
"
|
|
|
|
var ref;
|
|
|
|
const PATCHES = new Map();
|
|
|
|
const ident = \"foo\";
|
|
|
|
var _obj = PATCHES.get(ident);
|
|
|
|
const patch = (ref = _obj) === null || ref === void 0 ? void 0 : ref.call(_obj);
|
|
|
|
"
|
|
|
|
);
|
2021-07-08 07:54:57 +03:00
|
|
|
|
|
|
|
test!(
|
|
|
|
syntax(),
|
|
|
|
|_| tr(()),
|
|
|
|
issue_1836_1,
|
|
|
|
"
|
|
|
|
function bug() {
|
|
|
|
const arrowFn = (arg) => this.object[arg]?.();
|
|
|
|
}
|
|
|
|
|
|
|
|
bug();
|
|
|
|
",
|
|
|
|
"
|
|
|
|
function bug() {
|
|
|
|
const arrowFn = (arg)=>{
|
|
|
|
var ref;
|
|
|
|
var _object = this.object[arg];
|
|
|
|
return (ref = _object) === null || ref === void 0 ? void 0 : ref.call(_object);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
bug();
|
|
|
|
"
|
|
|
|
);
|