Comments (16)
This should be implemented now with #119.
from jscodeshift.
This would require a change to recast/ast-types benjamn/ast-types#132 right?
from jscodeshift.
Yeah, and I believe a change in how recast accepts its parser option, as Babel 6 now exposes the babylon
project which doesn't read options from a .babelrc
file, if I'm reading the source correctly.
from jscodeshift.
Using babel6 primarily depends on support from recast / ast-types, yes. However, it may not be as simple as adding new types, depending on how far babel6/babylon will diverge from the ESTree spec.
That said, it's probably possible to ditch recast completely and directly use babel6 for traversal and other mutations.
No work has been done in this direction, ideas / opinions / help are welcome :)
from jscodeshift.
Sounds like fun, have any suggestions for where to start figuring out how this integration might work?
from jscodeshift.
I added the transforms for babel 6 in babel-eslint (beta) https://github.com/babel/acorn-to-esprima/blob/744f2a986d31700d8e9f24fd5487fb71ab6ca9e0/src/toAST.js#L56-L153 - there are some bugs to fix though and it can be a pain to do so (not fun 😄)
from jscodeshift.
Adding babylon
's non-standard AST types to ast-types
should be much more straightforward than abandoning ast-types
or recast
. The ast-types
definition format is general enough to support any sort of AST, not just JavaScript, and certainly not just ~Esprima.
There's already a file for Babel-specific types: https://github.com/benjamn/ast-types/blob/master/def/babel.js
Happy to help.
from jscodeshift.
@benjamn Sure! I was more concerned with things that may impact other parts, like scope evaluation (e.g. if Babel adds new types around Identifier
that distinguish between bar
and foo.bar
). I guess that's not the case yet, but just something to keep in mind.
from jscodeshift.
@fkling There's nothing like that as far as I understand
from jscodeshift.
this is a cool idea. If jscodeshift can use multiple parsers it will essentially be http://astexplorer.net and will be able to migrate legacy code better. I can support with some development on this.
from jscodeshift.
Just wanted to add a note for those Googling. Currently, trying to run jscodeshift with Babel 6 returns this error:
/usr/local/lib/node_modules/jscodeshift/node_modules/babel-core/lib/transformation/file/options/option-manager.js:126
if (!option) this.log.error("Unknown option: " + alias + "." + key, ReferenceError);
^
TypeError: Cannot read property 'error' of undefined
at OptionManager.mergeOptions (/usr/local/lib/node_modules/jscodeshift/node_modules/babel-core/lib/transformation/file/options/option-manager.js:126:28)
at OptionManager.addConfig (/usr/local/lib/node_modules/jscodeshift/node_modules/babel-core/lib/transformation/file/options/option-manager.js:107:10)
at OptionManager.findConfigs (/usr/local/lib/node_modules/jscodeshift/node_modules/babel-core/lib/transformation/file/options/option-manager.js:168:35)
at OptionManager.init (/usr/local/lib/node_modules/jscodeshift/node_modules/babel-core/lib/transformation/file/options/option-manager.js:229:12)
at compile (/usr/local/lib/node_modules/jscodeshift/node_modules/babel-core/lib/api/register/node.js:117:22)
at normalLoader (/usr/local/lib/node_modules/jscodeshift/node_modules/babel-core/lib/api/register/node.js:199:14)
at Object.require.extensions.(anonymous function) [as .js] (/usr/local/lib/node_modules/jscodeshift/node_modules/babel-core/lib/api/register/node.js:216:7)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
from jscodeshift.
@globexdesigns: Did you really install the development version of jscodeshift and upgraded jscodeshift's dependency from Babel v5 to Babel v6, or is that some other strange error that happens when using jscodeshift alongside Babel v6?
from jscodeshift.
@fkling This was a result of using jscodeshift (installed globally) on a code base that uses Babel 6. I did NOT install jscodeshift's development version or do any manual upgrades.
from jscodeshift.
@globexdesigns: This seems to be a different problem and has nothing to do with the topic discussed here. This topic is about upgrading jscodeshift's internal / ownl version of Babel to v6.
jscodeshift shouldn't care whether the files it transforms happen to be converted with Babel or not, that's complete irrelevant. However, there might be an issue with jscodeshift's Babel version picking up the .babelrc
file of the project. If that's the case, please open a new issue with more information to reproduce the problem.
from jscodeshift.
@fkling I can confirm that the issue @globexdesigns identified was indeed jscodeshift picking up the project's .babelrc. I will open an issue for that now.
from jscodeshift.
I would prefer fixing recast
/ast-types
to make this work. I think ast-types
provides a better generalized type system than babel-types
does.
I am toying with auto-generating a babel-6
definition for ast-types
by simply recursing the values exported by babel-types
, similar to how the babel-types
docs are generated.
It's currently blocked awaiting benjamn/ast-types#145 or other similar solution to benjamn/ast-types#57 .
Sample output:
...
def("ArrayExpression")
.bases("Expression")
.build("elements");
def("AssignmentExpression")
.bases("Expression")
.build("operator", "left", "right")
.field("operator", String)
.field("left", def("LVal"))
.field("right", def("Expression"));
...
from jscodeshift.
Related Issues (20)
- Can't see file in current working directory - "Skipping path which does not exist." HOT 2
- Ignore pattern doesn't work with relative paths starting with two dots (../) HOT 1
- Automatically publish latest dev version to npm HOT 1
- Declaration has "null" loc field when inside export HOT 1
- missing semicolon how to fix this HOT 9
- how can I add @babel/plugin-proposal-private-methods to jscodeshift ? HOT 5
- extensions cli option not respected when passing individual file paths
- cannot replace JSX nodes within render props
- Added parenthesis around await expression in if statement HOT 4
- Updating setter function's parameter cause invalid output HOT 4
- Easiest way to insert a comment at the beginning of a file? HOT 3
- Generics are being removed from JSX Elements HOT 2
- Unit Tests Broken? HOT 1
- Last npm release (0.15) is ~6 months old HOT 2
- how to remove empty line using jscodeshift? HOT 1
- WSL2 - Can't install project with jscodeshift in dependencies HOT 1
- Enable parsing of `accessor` keyword HOT 6
- testOptions aren't propagated through some of the test methods
- [Bug] [email protected] ignores the files not starting with `.js` extension by default HOT 5
- `Error: null does not match type Pattern` when scanning scope of optional catch
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jscodeshift.