JavaScript generation from the JSLINT parsing tree

Using Crockford JSLINT after calling JSLINT() to parse some JavaScript source, it provides access to the parse tree through JSLINT.tree

It would be very useful to analyze 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, providing a conversion from the parsing tree to JavaScript?

(Is this possible, i.e. is JSLINT really storing enough complete information from parsing to roundabout, all significant?)

+6
source share
2 answers

I don’t know if JSLint can do this (looking at some of the forum posts, it doesn’t seem like preserving the tree is their goal, but its by-product for the casting process).

The uglifyjs project can help create AST from javascript and re-convert AST to code. See this method for AST for javascript.

+3
source

Not open source, but exactly fulfills OP requests: our JavaScript Front End .

This external interface is based on our DMS Software Reengineering Toolkit , which is a universal customizable compiler technology useful for creating arbitrary code analyzers and transformers. DMS has many interfaces for many languages ​​(COBOL, Java, C ++, ...)

In particular, DMS-based parsers (including their JavaScript code) collect complete information for restoring the source tree, including information about the beginning of the column and end information for tokens, the radius of numeric literals, differences in the rules for quoting strings, etc. let him do fidelity to the press if no conversions are applied. DMS also provides many other useful tree processing services, such as visitors, support for building symbol tables, support for stream analysis, pattern matching, and source-to-source conversion.

He can provide all of these services because the development cost has been amortized in many languages ​​and in different applications.

We did this because, as Daniel said, "the possibilities are endless." He provides an example of a toolkit for viewing runtime failures; this tool is a very useful idea, and we build testing tools based on this very thought.

+1
source

Source: https://habr.com/ru/post/907636/


All Articles