[compiler] Fix enableJsxOutlining with hyphenated JSX attribute names#36221
Open
sleitor wants to merge 1 commit intofacebook:mainfrom
Open
[compiler] Fix enableJsxOutlining with hyphenated JSX attribute names#36221sleitor wants to merge 1 commit intofacebook:mainfrom
sleitor wants to merge 1 commit intofacebook:mainfrom
Conversation
Contributor
Contributor
Author
|
Thanks @dimaMachina! 😊 I took a look at #36151 — there's already a competing PR #36153 open for that issue, so I'll let that one proceed. |
Contributor
This PR was closed 😞 #36153 (review) |
Contributor
Author
|
True.... Sorry my bad. :) |
… and SequenceExpression variable declarations
Fixes two issues with enableJsxOutlining:
1. JSX attributes with hyphens (e.g. aria-label, data-testid) were used
directly as JavaScript identifier names in the outlined component's
props destructuring, producing invalid code like:
`const { "aria-label": aria-label } = t0;`
Fix: sanitize attribute names to valid JS identifiers by converting
hyphens to camelCase (e.g. aria-label -> ariaLabel).
2. When a VariableDeclaration appeared inside a SequenceExpression value
block during codegen, it would emit a Todo error or produce invalid JS.
Fix: convert VariableDeclarations to assignment expressions within
SequenceExpression contexts.
Fixes facebook#36217
Fixes facebook#36218
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.
Summary
Fixes two issues with
enableJsxOutlining: true:1. Hyphenated JSX attribute names produce invalid JS (#36218)
JSX attributes with hyphens (e.g.
aria-label,data-testid) were used directly as JavaScript identifier names in the outlined component's props destructuring, producing invalid code:Fix: sanitize attribute names to valid JS identifiers by converting to camelCase:
The original attribute name is preserved in the inner JSX (
<Switch aria-label={ariaLabel} />).2. VariableDeclaration inside SequenceExpression value block (#36217)
When a
VariableDeclarationappeared inside aSequenceExpressionvalue block during codegen, it emitted a Todo error (Cannot declare variables in a value block) or produced invalid JS output.Fix: convert
VariableDeclarations to assignment expressions withinSequenceExpressioncontexts, since JS sequence expressions ((a, b, c)) only accept expressions.Test
Added fixture:
jsx-outlining-variable-declaration-in-sequence-expressionCloses #36217
Closes #36218