Frontmatter
| id | 467 |
| title | ES2020: Add optional chaining once possible (Webpack issue) |
| state | Closed |
| labels | enhancement |
| assignees | [] |
| createdAt | Apr 13, 2020, 12:43 PM |
| updatedAt | Jun 28, 2021, 10:39 AM |
| githubUrl | https://github.com/neomjs/neo/issues/467 |
| author | tobiu |
| commentsCount | 4 |
| parentIssue | null |
| subIssues | [] |
| subIssuesCompleted | 0 |
| subIssuesTotal | 0 |
| blockedBy | [] |
| blocking | [] |
| closedAt | Jun 28, 2021, 10:39 AM |
ES2020: Add optional chaining once possible (Webpack issue)

tobiu
Apr 13, 2020, 1:03 PM

dreyks
Jun 11, 2020, 9:46 AM
https://github.com/acornjs/acorn/pull/891 is merged, let's keep an eye on the releases

tobiu
Jun 11, 2020, 10:17 AM
Thanks for the heads up!
There are probably many spots inside the neo.mjs framework & demo apps code base where we can use it. Optional chaining can definitely help removing some boiler plate code (smaller file-size) as well as making the spots cleaner & easier to read.
Looking forward to it.

tobiu
Jun 28, 2021, 10:39 AM
just double-checked this one again and we are now finally good to use optional chaining.
will create new tickets in case i see spots.
tobiu closed this issue on Jun 28, 2021, 10:39 AM
In short:
const obj = { prop1: { prop2: { prop3: { prop4: { prop5: 5 } } } } } obj.prop1 && obj.prop1.prop2 && obj.prop1.prop2 && obj.prop1.prop2.prop3 && obj.prop1.prop2.prop3.prop4 && console.log(obj.prop1.prop2.prop3.prop4.prop5);VS
const obj = { prop1: { prop2: { prop3: { prop4: { prop5: 5 } } } } } console.log(obj?.prop1?.prop2?.prop3?.prop4?.prop5);This can some boiler-plate code, but unfortunately, webpack can not handle it yet. Browsers already support it, but webpack wants to parse it.
Since Babel is not an option for neo, we need to wait for this PR:
https://github.com/acornjs/acorn/pull/891
(Webpack relies on acornjs)