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

[flow] Add support for parsing _ as implicit instantiation in call/new #8883

Merged

Conversation

jbrown215
Copy link
Contributor

@jbrown215 jbrown215 commented Oct 16, 2018

Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change? Yes? (unlikely to cause new parse errors when using flow, but may)
Minor: New Feature? Yes
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes? No
License MIT

In facebook/flow@fb23b93, flow started to treat "_" used as type arguments to calls/new (test<_>() or new test<_>()) to mean to implicitly instantiate a type variable for that type parameter.

In that change, Flow disallowed the use of _ as a type identifier and it can only be used as a type argument in call/new. The estree AST flow outputs still prints _ in call/new type arguments as a GenericTypeAnnotation with Identifier _, which this change mimics.

No old tests had to be re-recorded, since the output AST did not change. Any programs using "_" as a type identifier name will now have a parse error when using the flow parser after this change. As an example, every use of "_" in the following code would cause a parse error in flow:

var x: Generic<_> = 3;
(x: Generic<_>);
var y: _ = 3;
(y: _);
type _ = number;
opaque type _ = number;
type HasUnderscore<_> = _;

This feature will be released in flow v0.84.0

@babel-bot
Copy link
Collaborator

babel-bot commented Oct 16, 2018

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/9327/

@existentialism existentialism added area: flow PR: New Feature 🚀 A type of pull request used for our changelog categories pkg: parser labels Oct 18, 2018
Copy link
Member

@danez danez left a comment

Choose a reason for hiding this comment

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

Just one little thing, otherwise looks good.

checkReservedType(word: string, startLoc: number) {
this.checkNotUnderscore(word);
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove this, I covered this case in #8965 by adding _ to the primitiveTypes array.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, adding to primitiveTypes sounds like a much better way to go.

@danez
Copy link
Member

danez commented Nov 5, 2018

Thanks.

The remaining travis failure has nothing to do with this PR.

@danez danez merged commit f216a7b into babel:master Nov 5, 2018
@jbrown215
Copy link
Contributor Author

Thanks for the help!

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 pkg: parser 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

5 participants