-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
fix(build): clean up of build-www rewriteImports (follow-up to #5995) #5999
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
scripts/www/rewriteImports.js
Outdated
// This is mutated in-place because I couldn't find a mutation that | ||
// did not fail for replacing the Program node. | ||
node.docblock.comment.value = node.docblock.comment.value.replace( | ||
/ \* @flow strict/g, | ||
' * @flow strict\n * @generated\n * @oncall lexical_web_text_editor', | ||
); | ||
// Let the transform know we actually did something. | ||
// Could not figure out the right way to update the | ||
// docblock without an in-place update | ||
context.addLeadingComments(node, ''); | ||
// We need the mutations array to be non-empty, so remove something | ||
// that is not there. The AST traversals use object identity in a | ||
// Set so we don't have to worry about some other line changing. | ||
context.removeComments(t.LineComment({value: ''})); |
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.
Yeah sorry mutating the program node is not really supported atm, i have a task to fix it. Your solution looks roughly reasonable. The other maybe more correct (but still not ideal) solution is to find the doc block comment within the program. It will be attached to the first statement of the program, then you can use the standard comment remove and add API's.
I'll take a look at that approach and write some unit tests |
…tement constraint
Description
Follow-up to #5995, while this fix worked it was not as clean as it should be and probably shouldn't pass flow type checks if it was analyzed. I did a little more digging and I found a more correct incantation, but it could probably still use some improvement if there is a hermes-transform expert around.
Test plan
Before
node ./scripts/www/rewriteImports.js rewrites flow files correctly (using sketchy code)
After
node ./scripts/www/rewriteImports.js rewrites flow files correctly (using slightly better code)