Re: AW: Efficient representation for Web formats; javascript Abstract Syntax Tree (AST) round trip considerations

The following page is interesting for displaying Abstract Syntax Tree (AST) of a JavaScript program.

 http://resources.jointjs.com/demos/javascript-ast

 http://resources.jointjs.com/demos/rappid/apps/Ast/index.html

It uses Esprima, ECMAScript parsing infrastructure for multipurpose analysis.

 http://esprima.org

Wondering, is this the same AST you are using? Presumably yes...

Has that been standardized by ECMAScript, or are there multiple possible results when building a javascript AST?  Not finding it in

 ECMA-262, 7ᵗʰ Edition / June 2016
 ECMAScript® 2016 Language Specification
 http://www.ecma-international.org/ecma-262/7.0/index.html

The Esprima site says

- "Sensible syntax tree format as standardized by EStree project" though no indicators of being an actual standard...

- "Esprima runs on many popular web browsers, as well as other ECMAScript platforms such as Rhino, Nashorn, and Node.js. It is distributed under the BSD license."

Also wondering, how to return-trip from AST to Javascript source?  Presumably the result is a bit different but functionally equivalent to original source.  The following page provides a form to do that:

- Esprima site says "Regenerating the code from the syntax tree permits a few different types of code transformation, from a simple rewriting (with specific formatting) to a more complicated minification."

 Source Rewrite cleans up and reformats everything
 http://esprima.org/demo/rewrite.html

- "Rewriting is a two-step process: parse the code to get the syntax tree and then regenerate a new code from the syntax tree following the specified formatting.  Note: Only syntatically valid input is accepted.  Code regeneration is carried out using escodegen project."

Also provided:

 Minify and Obfuscate to cover your tracks
 http://esprima.org/demo/minify.html

- "Minification reduces the size of the code without affecting its execution. Further compression is achieved by compacting the syntax tree, shortening variable names, and removing other unnecessary clutter.  Minification is carried out using escodegen and esmangle projects."

all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman@nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman

Received on Tuesday, 15 November 2016 18:29:38 UTC