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

Strip Flow's new shorthand import-type specifiers #5035

Merged
merged 1 commit into from Jan 14, 2017

Conversation

jeffmo
Copy link
Contributor

@jeffmo jeffmo commented Dec 24, 2016

Q A
Patch: Bug Fix? N
Major: Breaking Change? N
Minor: New Feature? Y
Deprecations? N
Spec Compliancy? Y
Tests Added/Pass? Y
Fixed Tickets
License MIT
Doc PR
Dependency Changes

This adds support to the flow-strip-types transform so that it strips type/typeof specifiers per the new syntax shorthand (details on the shorthand here).

This depends on parsing support in Babylon, which is addressed by babel/babylon#267


ImportSpecifier(path) {
const { node } = path;
if (node.importKind !== null) {
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'd be safer to explicitly check the types we want to exclude. Sound good?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure I can do that. Update coming right up!

The only kinds are "type", "typeof" and null. I don't expect we'll add a "value" since that's implied by null -- AKA leaving off any kind of keyword modifier.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah totally, just trying to be as future-proof as possible.

}
},

ImportSpecifier(path) {
Copy link
Member

Choose a reason for hiding this comment

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

I was looking into something unrelated today and came across something that may be a more general fix for this. How would you feel about moving this logic into

Then the Flow(path){ path.remove(); } above will automatically do this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do that.

FWIW: I wasn't able to actually find this virtual-types file while trying to find where import type was stripped (that file seems to be the magical file). I wonder if splitting these up like this is more confusing than it's worth?

(I'll defer to whichever you prefer)

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'd be more consistent with what we do now, but yeah the current architecture is pretty tough to follow, no disagreement there. Definitely something we can fix.

@jeffmo
Copy link
Contributor Author

jeffmo commented Jan 6, 2017

(assuming the code is acceptable): What's the procedure for pushing PRs like this that depend on other Babel-oriented packages getting published (i.e. babel/babylon#267)?

@danez
Copy link
Member

danez commented Jan 10, 2017

I think the procedure right now is exactly what you are doing, it is a little bit tedious, but this is one of the drawbacks of moving babylon out of the monorepo.

The test seems to fail.

@babel-bot
Copy link
Collaborator

Hey @jeffmo! It looks like one or more of your builds have failed. I've copied the relevant info below to save you some time.

OS: linux
node.js version: 6
Started at: 2017-01-13T17:06:56Z
Failed at: 2017-01-13T17:12:50Z
Logs: Click Here

OS: linux
node.js version: 5
Started at: 2017-01-13T17:07:21Z
Failed at: 2017-01-13T17:13:50Z
Logs: Click Here

OS: linux
node.js version: 4
Started at: 2017-01-13T17:06:59Z
Failed at: 2017-01-13T17:14:00Z
Logs: Click Here

OS: linux
node.js version: 0.12
Started at: 2017-01-13T17:07:01Z
Failed at: 2017-01-13T17:16:59Z
Logs: Click Here

@@ -113,6 +113,8 @@ export let Flow = {
return node.importKind === "type" || node.importKind === "typeof";
} else if (t.isExportDeclaration(node)) {
return node.exportKind === "type";
} else if (t.isImportSpecifier(node)) {
Copy link
Member

Choose a reason for hiding this comment

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

This is failing because you'll need to add ImportSpecifier to the types: ["Flow", "ImportDeclaration", "ExportDeclaration"], list just above here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I assumed it was failing due to the parser -- didn't look closely. Thanks for the heads up!

@rmacklin
Copy link
Contributor

@jeffmo The test passes now but we should also bump babel-traverse to depend strictly on babylon ^6.15.0 (rmacklin@883af44#diff-af2efa0aecdd6cb7790cd55ef11c04e6L15)

@jeffmo
Copy link
Contributor Author

jeffmo commented Jan 13, 2017

Done!

@codecov-io
Copy link

codecov-io commented Jan 13, 2017

Current coverage is 89.20% (diff: 100%)

Merging #5035 into master will increase coverage by <.01%

@@             master      #5035   diff @@
==========================================
  Files           203        203          
  Lines          9817       9819     +2   
  Methods        1071       1071          
  Messages          0          0          
  Branches       2613       2615     +2   
==========================================
+ Hits           8757       8759     +2   
  Misses         1060       1060          
  Partials          0          0          

Powered by Codecov. Last update d2113d4...b820d8e

@loganfsmyth loganfsmyth merged commit 2e67132 into babel:master Jan 14, 2017
@hzoo hzoo added the PR: New Feature 🚀 A type of pull request used for our changelog categories label Jan 16, 2017
@jeffmo jeffmo deleted the import_type_shorthand branch January 16, 2017 19:14
@hzoo
Copy link
Member

hzoo commented Jan 20, 2017

@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 6, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: flow outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: New Feature 🚀 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants