swc/crates
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%2FnanHwwkDVpaDJM5rdBn67y6WH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FJrHWoCKfScudUbsv2LDARewEgI4CM24uezqj7b4oj4aauOpf5EdoT4pHVFxSmNDqS1tjNhvDbVQXKNuAraaA6iysC5DYWI8izs4uwIMOC%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
..
ast_node chore: Publish crates 2023-05-06 03:56:38 +00:00
better_scoped_tls
binding_macros chore: Publish crates 2023-06-16 06:46:25 +00:00
dbg-swc chore: Publish crates 2023-06-16 06:46:25 +00:00
from_variant chore(cargo): Refactor Cargo.toml to reduce merge conflict (#7139) 2023-03-24 13:46:42 +09:00
jsdoc chore: Publish crates 2023-06-12 08:04:50 +00:00
preset_env_base chore: Publish crates 2023-04-19 06:26:19 +00:00
string_enum chore: Publish crates 2023-03-27 04:31:35 +00:00
swc fix(es/compat): Fix optional chaining (#7530) 2023-06-19 12:00:11 +09:00
swc_atoms chore: Publish crates 2023-05-16 05:18:57 +00:00
swc_bundler chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_cached chore: Publish crates 2022-10-11 11:23:16 +00:00
swc_common perf(es/minifier): Make minifier not overly generic (#7483) 2023-06-03 00:22:30 +09:00
swc_config chore(cargo): Refactor Cargo.toml to reduce merge conflict (#7139) 2023-03-24 13:46:42 +09:00
swc_config_macro chore(cargo): Refactor Cargo.toml to reduce merge conflict (#7139) 2023-03-24 13:46:42 +09:00
swc_core chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_css chore: Publish crates 2023-06-08 03:28:07 +00:00
swc_css_ast chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_css_codegen chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_css_codegen_macros chore(cargo): Refactor Cargo.toml to reduce merge conflict (#7139) 2023-03-24 13:46:42 +09:00
swc_css_compat chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_css_lints chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_css_minifier chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_css_modules chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_css_parser chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_css_prefixer chore: Publish crates 2023-06-08 03:28:07 +00:00
swc_css_utils chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_css_visit chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_ecma_ast fix(es/compat): Fix optional chaining (#7530) 2023-06-19 12:00:11 +09:00
swc_ecma_codegen chore: Publish crates 2023-06-13 16:14:41 +00:00
swc_ecma_codegen_macros chore(cargo): Refactor Cargo.toml to reduce merge conflict (#7139) 2023-03-24 13:46:42 +09:00
swc_ecma_dep_graph chore: Publish crates 2023-06-12 08:04:50 +00:00
swc_ecma_ext_transforms chore: Publish crates 2023-06-16 02:59:35 +00:00
swc_ecma_lints chore: Publish crates 2023-06-16 02:59:35 +00:00
swc_ecma_loader chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_ecma_minifier chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_ecma_parser chore: Publish crates 2023-06-12 08:04:50 +00:00
swc_ecma_preset_env chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_ecma_quote chore: Publish crates 2023-06-12 08:04:50 +00:00
swc_ecma_quote_macros chore: Publish crates 2023-06-12 08:04:50 +00:00
swc_ecma_testing chore: Publish crates 2022-12-01 05:26:50 +09:00
swc_ecma_transforms chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_ecma_transforms_base chore: Publish crates 2023-06-16 02:59:35 +00:00
swc_ecma_transforms_classes chore: Publish crates 2023-06-16 02:59:35 +00:00
swc_ecma_transforms_compat fix(es/compat): Fix optional chaining (#7530) 2023-06-19 12:00:11 +09:00
swc_ecma_transforms_macros chore(cargo): Refactor Cargo.toml to reduce merge conflict (#7139) 2023-03-24 13:46:42 +09:00
swc_ecma_transforms_module chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_ecma_transforms_optimization chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_ecma_transforms_proposal chore: Publish crates 2023-06-16 02:59:35 +00:00
swc_ecma_transforms_react chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_ecma_transforms_testing chore: Publish crates 2023-06-16 02:59:35 +00:00
swc_ecma_transforms_typescript fix(es/compat): Fix optional chaining (#7530) 2023-06-19 12:00:11 +09:00
swc_ecma_usage_analyzer chore: Publish crates 2023-06-16 02:59:35 +00:00
swc_ecma_utils chore: Publish crates 2023-06-16 02:59:35 +00:00
swc_ecma_visit chore: Publish crates 2023-06-12 08:04:50 +00:00
swc_ecmascript chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_eq_ignore_macros
swc_error_reporters chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_estree_ast chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_estree_compat chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_fast_graph chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_graph_analyzer chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_html chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_html_ast chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_html_codegen chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_html_codegen_macros chore(cargo): Refactor Cargo.toml to reduce merge conflict (#7139) 2023-03-24 13:46:42 +09:00
swc_html_minifier chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_html_parser chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_html_utils chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_html_visit chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_macros_common chore: Publish crates 2023-03-23 09:19:33 +00:00
swc_node_base chore: Publish crates 2022-10-24 03:58:37 +00:00
swc_node_bundler chore: Publish crates 2023-06-16 06:46:25 +00:00
swc_node_comments chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_nodejs_common chore: Publish crates 2023-05-17 06:17:15 +00:00
swc_plugin feat(plugin/runner): Update wasmer to v3 (#7197) 2023-04-10 03:40:25 +00:00
swc_plugin_macro chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_plugin_proxy chore: Publish crates 2023-06-12 08:04:50 +00:00
swc_plugin_runner chore: Publish crates 2023-06-12 08:04:50 +00:00
swc_plugin_testing
swc_timer chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_trace_macro
swc_visit chore: Publish crates 2023-05-24 07:48:00 +00:00
swc_visit_macros chore: Publish crates 2023-05-24 07:48:00 +00:00
swc_xml chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_xml_ast chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_xml_codegen chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_xml_codegen_macros chore(cargo): Refactor Cargo.toml to reduce merge conflict (#7139) 2023-03-24 13:46:42 +09:00
swc_xml_parser chore: Publish crates 2023-05-30 05:18:06 +00:00
swc_xml_visit chore: Publish crates 2023-05-30 05:18:06 +00:00
testing fix(es/compat): Fix optional chaining (#7530) 2023-06-19 12:00:11 +09:00
testing_macros chore: Publish crates 2023-03-23 09:19:33 +00:00