When compressing optional chains on values that won't be present at runtime, the identifier is replaced by (void 0) but this fails at runtime when there are nested accessors.
Input code
let missing = null;
console.log(missing?.thing.name ?? 'unknown')
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.
Describe the bug
When compressing optional chains on values that won't be present at runtime, the identifier is replaced by
(void 0)
but this fails at runtime when there are nested accessors.Input code
Config
Playground link
https://play.swc.rs/?version=1.3.42&code=H4sIAAAAAAAAA8tJLVHIzSwuzsxLV7BVyCvNybHm4krOzyvOz0nVy8lP14BK2uuVZAApvbzE3FQFe3sF9dK87Lz88jx1TQCsW9wjQgAAAA%3D%3D&config=H4sIAAAAAAAAA32UO3LjMAyG%2B5zCozrFjostcoDtcgYOTYIyvXxoCNCxJuO7L0TJj40hdRI%2B%2FAAJgPh%2B2%2B26E5ruY%2FfNn%2Fwz6IJQ7v9swTGRvrClAxM1muIH6t5v9IQTcjogNNN1Jh3p0gM1Fe5%2F7feLogs5I9wUiy365N34nNPkOBRAfLKxlUPWCInwf%2F3CSv6aAJX6bD%2FkHECnDaI0Kp8IeihSYJND0AOCOusiRJlOqovHLKWYYCWwaih5EHmynnxOnPOVWtBWmWxBQL6AIX8GSca5WJaQryfcp2ELh9r3rc8%2F1HDWoWoScsKltYRPK0Q9Zo%2BkXE1SCWe4UoMZLsX9qfROFaBa0qvulH1a6clfAK5A0IhJR5DiNg%2FH87SmdptKnxyPLI0C5%2FmWbpmg56Iq751Q2akyUMhL3Sxgq4GpskY6zoJXyofeggLneFaE0PjlyRylpDQOkJ0AuL%2FaSVM1A3V%2FhSt8ehAb%2BA%2FfkuQBWzyipuM6xTEecthIEIGO2W44cCsor%2BPCW%2BIyrPOaLPBogBVdKjbwugT4AVBWoe3Ll9ng58ERVR%2Fy4bEmFofrfQ9HnfrHe59X8dvi0MVsa4PLkp%2F6O6%2Fm393D6baF7wfvPH7elC3p9R%2BoYzQdMAYAAA%3D%3D
Expected behavior
Actual behavior
The nested property accessor is retained in the final code, where it errors trying to access a missing value on
(void 0)
.Version
1.3.42
Additional context
No response