Repository navigation
Use destructuring across JS library and runtime code - #28287
Conversation
There was a problem hiding this comment.
Code Review
This pull request modernizes various parts of the codebase by replacing multiple individual variable declarations with object destructuring for better readability and conciseness. Additionally, it updates regular expressions in the JSifier to better support async arrow functions, though the reviewer identified that the current regexes still require a space after 'async' and suggested using '\s*' instead to handle cases without a space.
fdf01db to
0fabb34
Compare
0fabb34 to
05702fb
Compare
| worker.onmessage = (e) => { | ||
| var d = e.data; | ||
| worker.onmessage = ({data: d}) => { | ||
| var cmd = d.cmd; |
There was a problem hiding this comment.
Why not these like
const {cmd, targetThread} = d;There was a problem hiding this comment.
better yet, put it straight in the param like ({ data: { cmd, targetThread } }) => { - the d stringifcation below is useless anyway and would result in "[object Object]".
| var canvas = Browser.getCanvas(); | ||
| var width = canvas.width; | ||
| var height = canvas.height; | ||
| const {width, height} = canvas; |
There was a problem hiding this comment.
Destructuring can eliminate quite a few variables as they are now single-use:
const {width, height} = Browser.getCanvas();| var registeredClass = wrapperType.registeredClass; | ||
| var wrapperPrototype = registeredClass.instancePrototype; | ||
| var baseClass = registeredClass.baseClass; | ||
| const {instancePrototype: wrapperPrototype, baseClass} = registeredClass; |
There was a problem hiding this comment.
| const {instancePrototype: wrapperPrototype, baseClass} = registeredClass; | |
| const {instancePrototype: wrapperPrototype, baseClass: {instancePrototype: baseClassPrototype, constructor: baseConstructor, pureVirtualFunctions}} = registeredClass; |
RReverser
left a comment
There was a problem hiding this comment.
Looks good, but there's definitely more places where 2nd pass could nest even more property accesses into the pattern or variables into the RHS expression.
|
If it OK with you I'll land this change then then we and propose a followup taking it all the next level? |
05702fb to
ec88e75
Compare
ec88e75 to
238e429
Compare
Followup to emscripten-core#28286 Use object and parameter destructuring for multi-property reads and unused event parameters across `src/lib/` and `src/pthread_esm_startup.mjs`, using `const` for declarations so Closure Compiler lowers them cleanly without extra bindings. Update affected `test/codesize/` expectations. See: emscripten-core#28272
238e429 to
1fbe902
Compare
Followup to #28286
Depends on #28288
Use object and parameter destructuring for multi-property reads and
unused event parameters across
src/lib/andsrc/pthread_esm_startup.mjs, usingconstfor declarations soClosure Compiler lowers them cleanly without extra bindings.
Update affected
test/codesize/expectations.See: #28272