Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating JavaScript from a JSLINT parse tree

With Crockford's JSLINT, after calling JSLINT() to parse some JavaScript source, it provides access to the parse tree via JSLINT.tree

It would be really powerful to be able to analyse the tree, make structural changes to it based on the analysis and then generate new JavaScript from the modified tree.

Is there an open source project that builds on JSLINT by providing a conversion from a parse tree back to JavaScript?

(Is this even possible, i.e. does JSLINT keep complete enough information from the parse to round-trip everything significant?)

like image 986
Daniel Earwicker Avatar asked Feb 04 '12 09:02

Daniel Earwicker


1 Answers

I dont know if JSLint can do it (looking at some of the forum postings, it doesnt look like maintaining the tree is their goal but its a by-product for doing the linting process).

The uglifyjs project may help with generating an AST from javascript and re-converting a AST to code. See this method for AST to javascript.

like image 173
rajasaur Avatar answered Sep 20 '22 10:09

rajasaur