| OLD | NEW |
| 1 // This script rewrites AST to be compatible with JavaScript 1.5 and decompiles | 1 // This script rewrites AST to be compatible with JavaScript 1.5 and decompiles |
| 2 // the modified tree then | 2 // the modified tree then |
| 3 | 3 |
| 4 include("../scripts/astDecompile.js"); | 4 include("../scripts/astDecompile.js"); |
| 5 include("../utils/beautify.js"); | 5 include("../utils/beautify.js"); |
| 6 | 6 |
| 7 let headerPrinted = false; | 7 let headerPrinted = false; |
| 8 | 8 |
| 9 // See https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API for | 9 // See https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API for |
| 10 // AST structure. | 10 // AST structure. |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 for (let i = 0; i < vars.length; i++) | 205 for (let i = 0; i < vars.length; i++) |
| 206 if (vars[i]) | 206 if (vars[i]) |
| 207 block.body.push(Assignment(vars[i], Member(tempVar, i, true))); | 207 block.body.push(Assignment(vars[i], Member(tempVar, i, true))); |
| 208 return block; | 208 return block; |
| 209 } | 209 } |
| 210 return ast; | 210 return ast; |
| 211 } | 211 } |
| 212 | 212 |
| 213 function modifyVariableDeclaration(ast) | 213 function modifyVariableDeclaration(ast) |
| 214 { | 214 { |
| 215 // Convert let variables: | 215 // Convert let and const variables: |
| 216 // let foo = bar; | 216 // let foo = bar; |
| 217 // const bas = 4; |
| 217 // | 218 // |
| 218 // Change into: | 219 // Change into: |
| 219 // var foo = bar; | 220 // var foo = bar; |
| 220 if (ast.kind == "let") | 221 // var bas = 4; |
| 222 if (ast.kind == "let" || ast.kind == "const") |
| 221 ast.kind = "var"; | 223 ast.kind = "var"; |
| 222 | 224 |
| 223 if (ast.declarations.length == 1 && ast.declarations[0].type == "VariableDecla
rator") | 225 if (ast.declarations.length == 1 && ast.declarations[0].type == "VariableDecla
rator") |
| 224 { | 226 { |
| 225 let declarator = ast.declarations[0]; | 227 let declarator = ast.declarations[0]; |
| 226 | 228 |
| 227 // Remove timeline requires: | 229 // Remove timeline requires: |
| 228 // let {Timeline} = require("timeline"); | 230 // let {Timeline} = require("timeline"); |
| 229 if (declarator.init && decompileAST(declarator.init) == 'require("timeline")
') | 231 if (declarator.init && decompileAST(declarator.init) == 'require("timeline")
') |
| 230 return null; | 232 return null; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 568 let code = 'require.scopes["' + options.filename + '"] = (function() {\n' + | 570 let code = 'require.scopes["' + options.filename + '"] = (function() {\n' + |
| 569 'var exports = {};\n' + | 571 'var exports = {};\n' + |
| 570 decompileAST(ast) + | 572 decompileAST(ast) + |
| 571 'return exports;\n' + | 573 'return exports;\n' + |
| 572 '})();\n'; | 574 '})();\n'; |
| 573 _print(js_beautify(code, options)); | 575 _print(js_beautify(code, options)); |
| 574 } | 576 } |
| 575 else | 577 else |
| 576 _print(js_beautify(decompileAST(ast), options)); | 578 _print(js_beautify(decompileAST(ast), options)); |
| 577 } | 579 } |
| OLD | NEW |