| 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. |
| 11 | 11 |
| 12 let options = { | 12 let options = { |
| 13 filename: null, | 13 filename: null, |
| 14 module: false, | 14 module: false, |
| 15 autoload: "", | 15 autoload: "", |
| 16 varIndex: 0, | 16 varIndex: 0, |
| 17 indent_size: 2, | 17 indent_size: 2, |
| 18 preserve_newlines: false, | 18 preserve_newlines: false, |
| 19 brace_style: "expand", | 19 brace_style: "expand", |
| 20 source_repo: "" | 20 source_repo: "" |
| 21 }; | 21 }; |
| 22 let global = this; | |
| 23 | 22 |
| 24 function Literal(value) | 23 function Literal(value) |
| 25 { | 24 { |
| 26 return { | 25 return { |
| 27 type: "Literal", | 26 type: "Literal", |
| 28 value: value | 27 value: value |
| 29 }; | 28 }; |
| 30 } | 29 } |
| 31 | 30 |
| 32 function Identifier(varname) | 31 function Identifier(varname) |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 } | 428 } |
| 430 | 429 |
| 431 return ast; | 430 return ast; |
| 432 } | 431 } |
| 433 | 432 |
| 434 function modifyFunctionDeclaration(ast) | 433 function modifyFunctionDeclaration(ast) |
| 435 { | 434 { |
| 436 return modifyFunctionExpression(ast); | 435 return modifyFunctionExpression(ast); |
| 437 } | 436 } |
| 438 | 437 |
| 439 function modifyArrowExpression(ast) | 438 function modifyArrowFunctionExpression(ast) |
| 440 { | 439 { |
| 441 if (ast.body.type != "BlockStatement") { | 440 if (ast.body.type != "BlockStatement") { |
| 442 // Convert expressions to block statements. | 441 // Convert expressions to block statements. |
| 443 // (a) => a + 1 | 442 // (a) => a + 1 |
| 444 // | 443 // |
| 445 // Change into: | 444 // Change into: |
| 446 // (a) => { return a + 1; } | 445 // (a) => { return a + 1; } |
| 447 ast.body = { | 446 ast.body = { |
| 448 type: "BlockStatement", | 447 type: "BlockStatement", |
| 449 body: [ | 448 body: [ |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 _print(decompileAST({ | 579 _print(decompileAST({ |
| 581 type: "ExpressionStatement", | 580 type: "ExpressionStatement", |
| 582 expression: { | 581 expression: { |
| 583 type: "CallExpression", | 582 type: "CallExpression", |
| 584 callee: Identifier("require"), | 583 callee: Identifier("require"), |
| 585 arguments: [Literal(module)] | 584 arguments: [Literal(module)] |
| 586 } | 585 } |
| 587 })); | 586 })); |
| 588 } | 587 } |
| 589 }; | 588 }; |
| OLD | NEW |