– Client side – Server side – In databases • ECMAScript tools have been developed – Transpiler • Languages compiled into JavaScript – Analyzer – Minifier / OpHmizier
– line and column numbers don’t correspond to the original • SourceMap – holding locaHon mapping informaHon • But because current JS tools take source code as IO such informaHon is discarded in tools pipeline – ALL tools need to handle SourceMap & source code at the same Hme – OR construct all-‐in-‐one tools
become all-‐in-‐one • Transpilers do – Scanning – Parsing – OpHmizing – Minifying – GeneraHng code • Necessary to implement all above funcHonaliHes • The problem: an IR of current JS tools is source code
as an IR • This is an AST represented as a JavaScript object • Interfaces are corresponding to an internal AST of the real JavaScript engine, SpiderMonkey – At least, AST contains informaHon enough to execute JavaScript code • AST interfaces are well-‐documented and standardized – haps://developer.mozilla.org/en-‐US/docs/SpiderMonkey/Parser_API
consider about JS AST object – Not necessary to implement ECMAScript parser and unparser – Develop each modules independently – Make composable modules • Passing more informaHon than source code – LocaHon informaHon to original code – Generated flags (node inserted by tools) • AST is close to JavaScript code – GeneraHng efficient JavaScript from a SSA form is a hard job • arbitrary jumps – Keeping tracking of the JS code’s structure with SSA form is too heavy responsibility for JavaScript module developers
• AccepHng JS AST and generaHng JS code – And SourceMap • Escodegen is responsible to generate valid JavaScript code from AST – It guarantees “parse(generate(parse(code)))” structurally equals to “parse(code)” Escodegen JavaScript code OR SourceMap JS AST
wriaen in ECMAScript • AccepHng JS AST and generaHng opHmized JS AST • It executes small pass funcHons using fixed-‐point iteraHon over the AST • Because it preserves locaHon informaHon aaached to AST nodes, later, Escodegen can generate a SourceMap to original code Esmangle Optimized JS AST JS AST
& opHmizer) • Parser, opHmizer and unparser are independent and connected with an IR Escodegen Optimized JS code Esprima Optimized JS AST JS AST JS code Esmangle SourceMap
Transforming JS code and creaHng sandbox to make third party JS / HTML / CSS safe to embed • Acorn (ECMAScript parser) and Escodegen is used for code transformaHon • Acorn is not Esprima, but Because it also generates JS AST, there is no problem for Escodegen Escodegen JS code JS AST JS code Some pass of Caja Acorn (Parser) Rewriter Rewrited JS AST
IR • We contributed & created modules – Esprima – Escodegen – Esmangle • We present tools consist of modules using JS AST • We present the example applying modules to transpiled languages