question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not usable with babylon parser's custom nodes

See original GitHub issue

Because 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:closed
  • Created 7 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hzoocommented, Nov 8, 2016

landed ^ so ast-types/recast is supported now (might have some bugs)

0reactions
suchipicommented, Jan 18, 2017

Sorry I never got back on this. I still haven’t tested it but with @hzoo’s updates it should work

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found