feat(es/minifier): Optimize typeof x == "undefined" to typeof x > "u"#11367
feat(es/minifier): Optimize typeof x == "undefined" to typeof x > "u"#11367kdy1 merged 3 commits intoswc-project:mainfrom
typeof x == "undefined" to typeof x > "u"#11367Conversation
🦋 Changeset detectedLatest commit: dba8dbb The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Binary Sizes
Commit: 4a5b705 |
CodSpeed Performance ReportMerging #11367 will not alter performanceComparing Summary
Footnotes |
There was a problem hiding this comment.
Pull request overview
This PR optimizes typeof x == "undefined" comparisons in the minifier to reduce output size. The optimization transforms:
typeof x == "undefined"→typeof x > "u"(undeclared variables)typeof x != "undefined"→typeof x < "u"(undeclared variables)typeof x == "undefined"→void 0 === x(declared variables)
The > "u" optimization leverages the fact that "undefined" is the only typeof result lexicographically greater than "u".
Reviewed changes
Copilot reviewed 90 out of 91 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
bools.rs |
Implements the typeof optimization logic with proper handling of declared/undeclared variables and operator reversal |
| Test output files | Consistently apply the optimization across numerous test snapshots including terser, react-dom, vue, moment, jquery, etc. |
| Size snapshots | Show modest size reductions from the optimization (e.g., backbone reduced from 18.33 to 18.29 KiB) |
The implementation correctly distinguishes between declared and undeclared variables, properly handles reversed operands, and flips operators appropriately for inequality comparisons.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
d223c78 to
46979be
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 89 out of 90 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description:
Optimize
typeof x == "undefined"comparisons to shorter forms:typeof x == "undefined"→typeof x > "u"(for undeclared variables)typeof x != "undefined"→typeof x < "u"(for undeclared variables)typeof x == "undefined"→void 0 === x(for declared variables)The
> "u"optimization works because"undefined"is the only typeof result greater than"u"in lexicographic order:Performance
There were performance concerns with string comparison vs equality check, but these have been or are being addressed
BREAKING CHANGE:
Related issue:
"undefined" == typeof xto"u" < typeof x#8144op_typeof_is_undefinedfortypeof x>"u"WebKit/WebKit#50101op_notandop_typeof_is_undefinedfortypeof x<"u"WebKit/WebKit#50116