W3C home > Mailing lists > Public > public-exi@w3.org > November 2016

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

From: Peintner, Daniel (ext) <daniel.peintner.ext@siemens.com>
Date: Wed, 16 Nov 2016 09:48:11 +0000
To: Don Brutzman <brutzman@nps.edu>, Takuki Kamiya <tkamiya@us.fujitsu.com>
CC: "public-exi@w3.org" <public-exi@w3.org>, "member-exi-wg@w3.org" <member-exi-wg@w3.org>
Message-ID: <D94F68A44EB1954A91DE4AE9659C5A980FF6E5E3@DEFTHW99EH1MSX.ww902.siemens.net>
Hi Don,

as far as I can tell there is just one AST for JavaScript and many platforms (JavaScript, Java, ...) use it.

That said, I don't think it is a standard/specification though.

-- Daniel





________________________________
Von: Don Brutzman [brutzman@nps.edu]
Gesendet: Dienstag, 15. November 2016 19:28
An: Peintner, Daniel (ext) (CT RDA NEC EMB-DE); Takuki Kamiya
Cc: public-exi@w3.org; member-exi-wg@w3.org
Betreff: 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<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 Wednesday, 16 November 2016 09:48:57 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 16 November 2016 09:48:58 UTC