-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[compiler] Fix FBT whitespace handling again (again (again)) #30451
Conversation
[ghstack-poisoned]
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
ghstack-source-id: a24a48e0a42e243b6c72481cd82cee819ccea309 Pull Request resolved: #30451
[ghstack-poisoned]
ghstack-source-id: ca54bce9346508e19680bd3b09f98e26fa059f3d Pull Request resolved: #30451
Fbt whitespace rules apply to their entire jsx subtrees, not just direct children (testing internally in progress) [ghstack-poisoned]
ghstack-source-id: 452185559d61e6742102c9945fe2c56eb5d69802 Pull Request resolved: #30451
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall approach makes sense! Nice find! I’ll let other review more thoroughly
tag.kind === 'BuiltinTag' && | ||
(tag.name === 'fbt' || tag.name === 'fbs') | ||
) { | ||
true && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
true &&
- remove?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops, removed!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very reasonable to me! What a messy transform lol.
* whitespace as is. | ||
* https://github.com/facebook/fbt/blob/0b4e0d13c30bffd0daa2a75715d606e3587b4e40/packages/babel-plugin-fbt/src/FbtUtil.js#L76-L87 | ||
*/ | ||
// text = exprPath.node.value.replace(/[^\S\u00A0]+/g, ' '); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cleanup?
* Increment fbt counter before traversing into children, as whitespace | ||
* in jsx text is handled differently for fbt subtrees. | ||
*/ | ||
isFbt && builder.fbtDepth++; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe include in the isFbt conditional block directly above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I figured this might be cleaner (keeping the increment / decrement next the recursive call), but I don't have strong opinions here. Happy to fix forward if you think that's a cleaner pattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No strong opinions here :)
Fbt whitespace rules apply to their entire jsx subtrees, not just direct children (testing internally in progress) [ghstack-poisoned]
Fbt whitespace rules apply to their entire jsx subtrees, not just direct children. Since fbt transform runs after react-compiler, let's just retain all whitespace as is. Tested internally by diffing fbt compilation tables (with and without react-compiler in the pipeline). See results here https://fburl.com/diff/t43dopfg. Note there are no differences except for 2 edge cases in which `babel-transform-fbt` fails to dedupe some table entries. [ghstack-poisoned]
ghstack-source-id: 00a86e41cfb8a6fb56b7fcd811740d1d9b89a611 Pull Request resolved: #30451
Stack from ghstack (oldest at bottom):
Fbt whitespace rules apply to their entire jsx subtrees, not just direct children. Since fbt transform runs after react-compiler, let's just retain all whitespace as is.
Tested internally by diffing fbt compilation tables (with and without react-compiler in the pipeline). See results here https://fburl.com/diff/t43dopfg. Note there are no differences except for 2 edge cases in which
babel-transform-fbt
fails to dedupe some table entries. This can help us be more confident that this fix covers all edge cases (without adding all permutations of fbt whitespace / elements to test fixtures)