swc/crates/swc_ecma_transforms_compat/tests
Justin Ridgewell 990e48e0e8
fix(es/compat): Fix optional chaining (#7530)
**Description:**

This fixes a few bugs with optional chaining:

-
[`a?.c()`](https://play.swc.rs/?version=1.3.64&code=H4sIAAAAAAAAA9PXVwjOyC%2FNSVFISrXi0tdXSFSwtVXIK83JUbBXKM1LSU3LzEtNUbBSSNRL1tC05kq0h9AAouc%2F7DgAAAA%3D&config=H4sIAAAAAAAAA2VSu27DMAzc8xUC5wAZii7ZWnRJgXTKDxAKkyrQwyDpNEbgf69kxI4jexAk3olH3fm%2BMgYoXsFszT3vywchHQm2pa7cwXos28T0LRl4m0qnxJY%2BvD8wRsmHUGDllibGsYsYnN2FJrHWoCKfScudUbsv2LDARewEgI4CM24uezqj7b4oj4aauOpf5EdoT4pHVFxSmNDqS1tjNhvDbVQXKNuAraaA6iysC5DYWI8izs4uwIMOC%2F6cpL%2Bc%2FnanHwwkDVpaDJM5rdBn67y6WHv5eNCVfGpCzibDJ%2FQyw%2Fv1qtqAT0lqHWiQhfjVSumi4m2I3QYUy65RmNl0kdtS8OlvPWxfhTw0lnd45pv%2FstbTLOKuGeyzKYQULwIT08l%2B5BaJVf8PfP2zz7YCAAA%3D)
-
[`a?.b.c()`](https://play.swc.rs/?version=1.3.64&code=H4sIAAAAAAAAA9PXVwjOyC%2FNSVFISrXi0tdXSFSwtVXIK83JUbBXKM1LSU3LzEtNUbBSSNRL0kvW0LTmSrSHsQBsP8xLPAAAAA%3D%3D&config=H4sIAAAAAAAAA2VSu27DMAzc8xUC5wAZii7ZWnRJgXTKDxAKkyrQwyDpNEbgf69kxI4jexAk3olH3fm%2BMgYoXsFszT3vywchHQm2pa7cwXos28T0LRl4m0qnxJY%2BvD8wRsmHUGDllibGsYsYnN2FJrHWoCKfScudUbsv2LDARewEgI4CM24uezqj7b4oj4aauOpf5EdoT4pHVFxSmNDqS1tjNhvDbVQXKNuAraaA6iysC5DYWI8izs4uwIMOC%2F6cpL%2Bc%2FnanHwwk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RsmHUGDllibGsYsYnN2FJrHWoCKfScudUbsv2LDARewEgI4CM24uezqj7b4oj4aauOpf5EdoT4pHVFxSmNDqS1tjNhvDbVQXKNuAraaA6iysC5DYWI8izs4uwIMOC%2F6cpL%2Bc%2FnanHwwkDVpaDJM5rdBn67y6WHv5eNCVfGpCzibDJ%2FQyw%2Fv1qtqAT0lqHWiQhfjVSumi4m2I3QYUy65RmNl0kdtS8OlvPWxfhTw0lnd45pv%2FstbTLOKuGeyzKYQULwIT08l%2B5BaJVf8PfP2zz7YCAAA%3D)
-
[`a?.b[c?.d]`](https://play.swc.rs/?version=1.3.64&code=H4sIAAAAAAAAA9PXVwjOyC%2FNSVFISrXi0tdX0IhPVLBVSNRUsLVVyCvNyVGwVyjLz0xRMFCwUohP1EuK1ohPBipIxq4gWS8l1por0R6oLtkezAYAJs%2FWxmEAAAA%3D&config=H4sIAAAAAAAAA2VSu27DMAzc8xUC5wAZii7ZWnRJgXTKDxAKkyrQwyDpNEbgf69kxI4jexAk3olH3fm%2BMgYoXsFszT3vywchHQm2pa7cwXos28T0LRl4m0qnxJY%2BvD8wRsmHUGDllibGsYsYnN2FJrHWoCKfScudUbsv2LDARewEgI4CM24uezqj7b4oj4aauOpf5EdoT4pHVFxSmNDqS1tjNhvDbVQXKNuAraaA6iysC5DYWI8izs4uwIMOC%2F6cpL%2Bc%2FnanHwwkDVpaDJM5rdBn67y6WHv5eNCVfGpCzibDJ%2FQyw%2Fv1qtqAT0lqHWiQhfjVSumi4m2I3QYUy65RmNl0kdtS8OlvPWxfhTw0lnd45pv%2FstbTLOKuGeyzKYQULwIT08l%2B5BaJVf8PfP2zz7YCAAA%3D)
- [`delete
foo?.bar`](https://play.swc.rs/?version=1.3.64&code=H4sIAAAAAAAAA9PXVwjOyC%2FNSVFISrXi0tdXSMvPV7C1VcgrzclRsFcoKSpNVbBSSEnNSS1JBcnpJSUWcSG49iA%2BAGcLTstEAAAA&config=H4sIAAAAAAAAA1WPSw7CMAxE9zlF5DULYIEEd%2BAQVnCrVPkpTiWqqncnTZMAO3vG42evQkqYWMFDrrnMTcDIFHufFV5cwndWgJRFVlGHBKfmTrxbAxqmIm2HAwnjSKmk%2BHq%2B3GsCjPdMWU5xpipZ7fSw%2FCKVtyESc9vcaRbdaOgfKCoUrH%2FNxayvpCXQccANvkMN1heD5mdL7leJ7QOQNa2NFgEAAA%3D%3D)
- [`function foo(a, b = a?.b)
{}`](https://play.swc.rs/?version=1.3.64&code=H4sIAAAAAAAAA9PXVwjOyC%2FNSVFISrXi0tdXSCvNSy7JzM9TSMvP10jUUUhSsFXQ0NBUsLVTqFYoSyxSiE%2B0VnjUsEyhVlNDU1OhupYLm45Ee70kkCQAp8DQOl8AAAA%3D&config=H4sIAAAAAAAAA22Rz07DMAzG73uKyOdJAw5I7Ii4cBjvYKXuyJQ%2Fle3AqmnvTltIm63cHH%2B%2F%2BPtkXzbGwEks7M1lKIeHMkZpE4e5NbU9HdH2b2QToyYeROVM2wVoinQgxQYV1wgTWr0Za8xuZzhHdYH2BjBrCqjOwnYUEhvrUcTZ6gP84bDia0g%2FOX2%2Ftx8YSDq0tAozMFnoNTuvLsp%2FckNf5FMXKI6ZW%2FRS6ddSzgX4lOTeBzpkIb5dpfRR8TzmJxtQLLtOoVrTSc5rw2W%2F92GXBIp8JJ0Gy9PD48s0dJIhpCZ7qq7cd%2FQLPsMMOTkUrBhAcNG1fcmzuf4AkV7gUzECAAA%3D)

It also optimizes the AST for runtime evaluation. Before, we constructed
a leftwards conditional tree (`(_a_b = (_a = a) == null ? void 0 : _a.b)
== null ? void 0 : _a_b.c`) instead of a rightward tree (`(_a = a) ==
null ? void 0 : (_a_b = _a.b) == null ? void 0 : _a_b.c`), which
required multiple `== null` checks after the first nullish is found.

**Related issue:**

 - Closes #7531.
2023-06-19 12:00:11 +09:00
..
arrow test(ts/compat): Migrate inline tests to fixture testing (#6475) 2022-11-28 04:54:38 +00:00
async-to-generator fix(es/compat): Fix finally handling of generator (#7215) 2023-04-06 09:37:21 +00:00
block-scoping fix(es/preset-env): Fix pass ordering (#7434) 2023-05-23 07:14:37 +00:00
class_fields_use_set/basic fix(es/compat): Handle useDefineForClassFields: false (#7055) 2023-03-12 12:56:10 +09:00
classes fix(es/compat): Fix stage 3 decorator pass (#7392) 2023-05-23 06:24:05 +00:00
for-of test(ts/compat): Migrate inline tests to fixture testing (#6475) 2022-11-28 04:54:38 +00:00
new-target fix(es/helpers): Use snake_case for helpers (#7147) 2023-03-31 15:15:21 +09:00
optional-chaining fix(es/compat): Fix optional chaining (#7530) 2023-06-19 12:00:11 +09:00
optional-chaining-loose fix(es/compat): Fix optional chaining (#7530) 2023-06-19 12:00:11 +09:00
parameters fix(es/compat): Fix is_setter in parameters pass (#7348) 2023-05-02 02:11:42 +00:00
private-in-object fix(es/helpers): Use snake_case for helpers (#7147) 2023-03-31 15:15:21 +09:00
static-blocks fix(es/helpers): Use snake_case for helpers (#7147) 2023-03-31 15:15:21 +09:00
class_fields_use_set.rs build(cargo): Update rustc to nightly-2023-03-20 (#7170) 2023-03-30 08:06:02 +00:00
es2015_arrow.rs test(ts/compat): Migrate inline tests to fixture testing (#6475) 2022-11-28 04:54:38 +00:00
es2015_block_scoping.rs fix(es/preset-env): Fix pass ordering (#7434) 2023-05-23 07:14:37 +00:00
es2015_classes.rs fix(es/helpers): Use snake_case for helpers (#7147) 2023-03-31 15:15:21 +09:00
es2015_computed_props.rs fix(es/helpers): Use snake_case for helpers (#7147) 2023-03-31 15:15:21 +09:00
es2015_destructuring.rs fix(es/compat): Fix destructuring handling of block_scoping (#7425) 2023-05-22 03:21:50 +00:00
es2015_duplicated_keys.rs fix(es/helpers): Use snake_case for helpers (#7147) 2023-03-31 15:15:21 +09:00
es2015_for_of.rs build(cargo): Update rustc to nightly-2023-03-20 (#7170) 2023-03-30 08:06:02 +00:00
es2015_generator.rs fix(es/helpers): Remove unnecessary parameters in helper_expr! macro (#7296) 2023-04-20 08:26:34 +00:00
es2015_new_target.rs fix(es/helpers): Use snake_case for helpers (#7147) 2023-03-31 15:15:21 +09:00
es2015_object_super.rs fix(es/helpers): Use snake_case for helpers (#7147) 2023-03-31 15:15:21 +09:00
es2015_parameters.rs fix(es/helpers): Use snake_case for helpers (#7147) 2023-03-31 15:15:21 +09:00
es2015_spread.rs fix(es/helpers): Use snake_case for helpers (#7147) 2023-03-31 15:15:21 +09:00
es2015_template_literals.rs fix(es/helpers): Use snake_case for helpers (#7147) 2023-03-31 15:15:21 +09:00
es2017_async_to_generator.rs fix(es/helpers): Remove unnecessary parameters in helper_expr! macro (#7296) 2023-04-20 08:26:34 +00:00
es2018_object_rest_spread.rs fix(es/compat): Fix variable scoping of object rest pass. (#7437) 2023-05-24 05:41:57 +00:00
es2020_nullish_coalescing.rs test(es/compat): Add a test for a wrong issue (#7300) 2023-04-20 11:10:25 +09:00
es2020_optional_chaining.rs fix(es/compat): Fix optional chaining (#7530) 2023-06-19 12:00:11 +09:00
es2021_logcal_assignments.rs fix(es/compat): Fix the position for temp var injection (#7171) 2023-03-30 17:41:55 +09:00
es2022_class_properties.rs fix(es/helpers): Use snake_case for helpers (#7147) 2023-03-31 15:15:21 +09:00
es2022_private_in_object.rs build(cargo): Update rustc to nightly-2023-03-20 (#7170) 2023-03-30 08:06:02 +00:00
es2022_static_blocks.rs build(cargo): Update rustc to nightly-2023-03-20 (#7170) 2023-03-30 08:06:02 +00:00