– 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
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
represented as follows, { "type": "Program", "body": [{ "type": "VariableDeclaraHon", "declaraHons": [{ "type": "VariableDeclarator", "id": { "type": "IdenHfier", "name": "a" }, "init": { "type": "Literal", "value": 42, "raw": "42” } }], "kind": "var” }] }
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
CoffeeScript compiler – To provide modules for CoffeeScript compiler itself • Parsing CoffeeScript, generaHng CS AST, transforming it into JS AST and emit JS code by Escodegen • Esmangle is now combined into this pipeline Preprocessor Parser Optimizer Compiler Escodegen JavaScript code OR SourceMap CoffeeScript code Context Free CS CS AST Optimized CS AST JS AST Esmangle Optimized JS AST JS AST
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
and runHme wriaen in JS • Parsing bytecode, construcHng CFG, transforming JS AST, emiung JS code and execuHng it • GeneraHng JS on-‐the-‐fly gains faster performance than a tradiHonal switch-‐based VM Bytecode Parser Normalize Bytecode CFG Restructuring Interpreter (switch based) Verifier Compiler Escodegen JavaScript code
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4