-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Detect and apply stripping flow types #1864
Changes from 1 commit
98dbe99
9511e97
9301f5e
48bff7e
3e5a158
d10df94
ac94de4
73c46c0
e74e92e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -312,7 +312,10 @@ async function getJSXConfig(asset, isSourceModule) { | |
* Generates a babel config for stripping away Flow types. | ||
*/ | ||
function getFlowConfig(asset, isSourceModule) { | ||
if (!isSourceModule && asset.contents.includes('@flow')) { | ||
if ( | ||
!isSourceModule && | ||
asset.contents.substring(0, 20).indexOf('@flow') > -1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://jsperf.com/includes-vs-substring-includes-vs-indexof/1 Performance test for this line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we ensure that this is inside a comment? like look for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue is that it can be I can change it to a regex or babel walk just not sure about performance (Probably regex). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah a regex would be ok (on the substring). Should be fast enough. |
||
) { | ||
return { | ||
plugins: [[require('babel-plugin-transform-flow-strip-types')]], | ||
internal: 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.
Should this be the inverse? Wouldn't we want to enable flow on app code and locally linked modules? I'm not sure enabling it on published node_modules is a good idea. WDYT?
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.
The issue is published code, as they shouldn't ship with flow types, local code should follow babelrc.
Shipped code should probably use flow comments or seperate .flow files
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.
I think it would be a nice feature to enable flow automatically on source code just like we do for JSX.
Shipped code should generally be pre-transpiled to remove the types I thought... Not sure, I guess it doesn't hurt to automatically do it for everything.
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.
It should, but apparently not every module does it as you can see in the linked issue