Not usable with babylon parser's custom nodes
See original GitHub issueBecause Babylon’s output format differs from ESTree, when using babylon as the parser, there are cases where unfamiliarity with nodes not present in ast-types
causes an error to be thrown:
jscodeshift output
$ jscodeshift ./src --parser babylon
Processing 1 files...
Spawning 1 workers...
Sending 1 files to free worker...
ERR src/target.js Transformation error
Error: did not recognize object of type "ObjectProperty"
at Object.getFieldNames (/home/suchipi/Code/jscodeshift-babylon-issue-repro/node_modules/recast/node_modules/ast-types/lib/types.js:663:19)
at getSortedChildNodes (/home/suchipi/Code/jscodeshift-babylon-issue-repro/node_modules/recast/lib/comments.js:50:23)
at getSortedChildNodes (/home/suchipi/Code/jscodeshift-babylon-issue-repro/node_modules/recast/lib/comments.js:63:9)
at getSortedChildNodes (/home/suchipi/Code/jscodeshift-babylon-issue-repro/node_modules/recast/lib/comments.js:63:9)
at decorateComment (/home/suchipi/Code/jscodeshift-babylon-issue-repro/node_modules/recast/lib/comments.js:73:22)
at decorateComment (/home/suchipi/Code/jscodeshift-babylon-issue-repro/node_modules/recast/lib/comments.js:84:13)
at decorateComment (/home/suchipi/Code/jscodeshift-babylon-issue-repro/node_modules/recast/lib/comments.js:84:13)
at decorateComment (/home/suchipi/Code/jscodeshift-babylon-issue-repro/node_modules/recast/lib/comments.js:84:13)
at /home/suchipi/Code/jscodeshift-babylon-issue-repro/node_modules/recast/lib/comments.js:129:9
at Array.forEach (native)
All done.
Results:
1 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 1.178seconds
I have created a repro case at suchipi/jscodeshift-babylon-issue-repro.
To test, clone the repo, run npm install
, then run npm start
.
Expected Behavior
jscodeshift either (in order of desirability):
- uses babel-types instead of ast-types when
babylon
is the selected parser - lets the user provide their own visitor keys, builders, etc to use
- completely ignores nodes whose types are unique to the Babel AST Format
- does not support babylon as a parser by default
Current Behavior
An error is thrown when encountering a node type not present in ast-types
.
I recognize that the ast-types
dependency is within recast
, so addressing this issue may require a change there.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
GLTF Parser Hooks - Questions - Babylon.js Forum
Im am trying to create a GLTF Extension but i am not to sure about the the promises and the call chain for...
Read more >babel/parser
The Babel parser (previously Babylon) is a JavaScript parser used in Babel. ... attachComment: By default, Babel attaches comments to adjacent AST nodes....
Read more >Adding Custom Syntax to Babel - Medium
The package we're looking at here is Babylon. It reads text, translates it to a series of tokens, and then to a series...
Read more >@omneedia/parse-function - npm package | Snyk
Parse a function into an object using espree, acorn or babylon parsers. ... Extensible: using plugins for working directly on AST nodes, see...
Read more >Custom Nodes in the Node Material Editor: Part 1 - YouTube
That's not all, he also shows you how you can add them to the node ... Helpful links to dive into Babylon.js: https://www.babylonjs.com/ ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
landed ^ so ast-types/recast is supported now (might have some bugs)
Sorry I never got back on this. I still haven’t tested it but with @hzoo’s updates it should work