Babel 6 types#162
Conversation
| @@ -0,0 +1,117 @@ | |||
| module.exports = function (fork) { | |||
| fork.use(require("./babel")); | |||
| fork.use(require("./flow")); | |||
There was a problem hiding this comment.
Do I need to fork both? or should babel fork flow instead of es7?
There was a problem hiding this comment.
I think you should fork both. It's conceivable people will want to use the types defined in ./babel without those defined in ./flow, right? If ./babel forks ./flow, it should imply that those type definitions somehow depend on ./flow.
|
General question - is it better to just define a new type with everything from scratch (base, build, field)? Some of the changes are literally just a name change so that probably doesn't have to be. |
|
Should I be modifying main.js? |
That was so long ago, there are probably changes that should have been merged more carefully. I can take a look at #145 again tonight. |
My gut says just redefine. Babel has moved far enough away from esprima compatibility, that attempting to share base types seems likely to create some amount of pain, and I don't really see much of an upside. We are to the point of needing a custom fork anyways, so might as well just make the entire tree conform to the Babel way of doing things. That said, simple name changes can probably just be accomplished with: def('newName').bases('oldName')(you might need to redefine build in that case, not sure) |
|
Rebased again |
def/babel6.js
Outdated
| // Split Literal | ||
| def("StringLiteral") | ||
| .bases("Literal") | ||
| .bases("Node", "Expression") |
There was a problem hiding this comment.
Node is not important here, nor for the other Babel *Literal types, because Expression <: Node.
|
def/babel6.js
Outdated
| def("ObjectPattern") | ||
| .bases("Pattern") | ||
| .build("properties") | ||
| .field("properties", [or(def("RestProperty"), def("ObjectProperty"))]) |
There was a problem hiding this comment.
it should be Property, not ObjectProperty, per https://github.com/estree/estree/blob/f32646033ed12e6aaa7f5cd496d936a8f8de194e/es2015.md#objectpattern
There are a couple of places in ESTree where nodes have different type values like this, but I don't think ast-types has a way to represent this.
There was a problem hiding this comment.
What do you mean here though? I'm defining all the different types from ESTree (including ObjectProperty above) - I thought we would be forking to support the different AST types in babel (6).
There was a problem hiding this comment.
Note how ObjectPattern.properties is an array of ObjectProperty's, like you have, but ObjectProperty's type field is "Property", not "ObjectProperty." def("ObjectProperty") requires an ast with { type: "ObjectProperty" }, but estree says it should be { type: "Property" }
There was a problem hiding this comment.
After v6, Babel isn't following ESTree completely so I had to make this PR to make it work with recast. Yeah it's totally correct it should be Property but Babylon won't produce a type of Property anymore so I'm using ObjectProperty if that makes sense (unless I'm misunderstanding something)
|
I'd like to see this merged... how can I contribute? What needs to be done to fix the tests? I'm not familiar enough with the forking model in this codebase to understand how to fix failures. |
|
Looked through https://github.com/babel/babel/commits/master/packages/babel-generator to find new syntax. |
| .build("argument") | ||
| .field("argument", def("Expression")); | ||
|
|
||
| def("ForAwaitStatement") |
| .bases("Type") | ||
| .build(); | ||
|
|
||
| def("EmptyTypeAnnotation") |
| .field("value", def("Type")) | ||
| .field("optional", Boolean); | ||
| .field("optional", Boolean) | ||
| .field("variance", |
| .field("id", or(def("Identifier"), def("Literal"))) | ||
| .field("body", def("BlockStatement")); | ||
|
|
||
| def("DeclareModuleExports") |
|
Finally got around to fixing these.. @suchipi (I didn't understand the forking either). Tested with benjamn/recast#299 (would error that node isn't printable, etc) |
|
Thanks @benjamn!!! much excite 😍 |
Fixes #132
For babel pr: babel/babel#3561
Also ref benjamn/recast#298
First 3 commits are from #145 (fixed merge conflicts by preferring the changes in the PR).
You can review that PR or this one with whitespace off for a better diff https://github.com/benjamn/ast-types/pull/162/files?w=1.
My commit adds the babel 6 types (not sure if it's right though, so please review!).
References:
cc @jamestalmage @benjamn