swc-project / swc

Rust-based platform for the Web
https://swc.rs
Apache License 2.0
31.2k stars 1.23k forks source link

One more case for optional chaining #7627

Closed krasnoperov closed 1 year ago

krasnoperov commented 1 year ago

Describe the bug

Nested optional chaining is not removed from ES2018 code

Input code

arr.find(el => el?.a)?.b

Config

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "target": "es2018",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "commonjs"
  },
  "minify": false,
  "isModule": true
}

Playground link

https://play.swc.rs/?version=1.3.66&code=H4sIAAAAAAAAA1NILCrSS8vMS9FIzVGwtVNIzbHXS9S010sCAP9xSjkZAAAA&config=H4sIAAAAAAAAA1VPSQ7DIAy85xXI5x7anqr%2BoY9A1ImI2IQdqVGUvwcI0PZmz%2BIZb4MQMJOCp9jSmJYgI2Hse0JodSw%2FCQFeA5KKOjBcGsuUKY4LFmQ%2FCWAZJ%2BRsQrpfb49qAOM9YYJHaQgrZrXT4%2FobqbwNEYn%2BhVkq3WS6%2F0wcaipY%2F14KWV%2FJdXODdM16NxN8lS2xXwdNr2Yvz%2BwHqlCzbBsBAAA%3D

Expected behavior

"use strict"; var _arr_find; (_arr_find = arr.find((el)=>{ return el === null || el === void 0 ? void 0 : el.a; })) === null || _arr_find === void 0 ? void 0 : _arr_find.b;

Actual behavior

"use strict"; var _arr_find; (_arr_find = arr.find((el)=>el?.a)) === null || _arr_find === void 0 ? void 0 : _arr_find.b;

Version

1.3.66

Additional context

No response

kdy1 commented 1 year ago

Closing as already fixed (duplicate)

jridgewell commented 1 year ago

Fixed by https://github.com/swc-project/swc/pull/7614

swc-bot commented 1 year ago

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.