Skip to content
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

Merged
merged 9 commits into from Aug 23, 2018
Merged

Conversation

DeMoorJasper
Copy link
Member

Closes #1863

@chiefGui
Copy link

chiefGui commented Aug 8, 2018

This looks great. Excited to see it implemented. 🗡

if (!isSourceModule && asset.contents.includes('@flow')) {
if (
!isSourceModule &&
asset.contents.substring(0, 20).indexOf('@flow') > -1
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DeMoorJasper DeMoorJasper changed the title WIP: Detect and apply stripping flow types Detect and apply stripping flow types Aug 10, 2018
*/
function getFlowConfig(asset, isSourceModule) {
if (
!isSourceModule &&
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

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

function getFlowConfig(asset, isSourceModule) {
if (
!isSourceModule &&
asset.contents.substring(0, 20).indexOf('@flow') > -1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we ensure that this is inside a comment? like look for // @flow or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that it can be // @flow or /* @flow */ or any other variation of comment. So either we'd have to use a regex or do a babel walk to just detect this. Which would probably slow things down.

I can change it to a regex or babel walk just not sure about performance (Probably regex).

Copy link
Member

Choose a reason for hiding this comment

The 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.

@@ -148,6 +149,11 @@ async function getBabelConfig(asset) {
return jsxConfig;
}

// If there is a Flow config, return that
if (flowConfig) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we also need to merge the flow config with the generated env/jsx configs above right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, fixed it

@devongovett devongovett merged commit 28df546 into master Aug 23, 2018
@devongovett devongovett deleted the feature/strip-flow-types branch August 23, 2018 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants