fix(mangler): upper-case JSX component names#21028
Open
gthb wants to merge 3 commits intooxc-project:mainfrom
Open
fix(mangler): upper-case JSX component names#21028gthb wants to merge 3 commits intooxc-project:mainfrom
gthb wants to merge 3 commits intooxc-project:mainfrom
Conversation
What --- Ensure mangled JSX component names start with an upper-case letter. In JSX, `<e />` is an HTML element while `<E />` is a component, so changing a component's name changes its meaning. Fixes oxc-project#13248 How --- Add `base54_upper_first()`, a name generator that uses upper-case letters for the first character and the full `BASE54_CHARS` for subsequent characters. If the source type is JSX, walk resolved references to find symbols whose parent node is `JSXOpeningElement` or `JSXClosingElement`. Partition the frequency table into a regular pool (using `base54`) and a JSX pool (using `base54_upper_first`). For non-JSX ones (`.js`, `.mjs`, `.ts`) just skip that component symbol scan. Extract reserved-name generation and assignment loops to their own functions.
Author
|
Used AI for an initial stab at this, then reviewed and iterated plenty, then squashed to spare you the commit noise. |
... and avoid the em-dashes which LLMs have induced everyone to revile
Mangling is deterministic, so assert the specific names rather than just checking originals are absent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Ensure mangled JSX component names start with an upper-case letter. In JSX,
<e />is an HTML element while<E />is a component, so changing a component's name changes its meaning.Fixes #13248
How
Add
base54_upper_first(), a name generator that uses upper-case letters for the first character and the fullBASE54_CHARSfor subsequent characters.If the source type is JSX, walk resolved references to find symbols whose parent node is
JSXOpeningElementorJSXClosingElement. Partition the frequency table into a regular pool (usingbase54) and a JSX pool (usingbase54_upper_first).For non-JSX ones (
.js,.mjs,.ts) just skip that component symbol scan.Extract reserved-name generation and assignment loops to their own functions.