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 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 549 |
550 if (options.module) | 550 if (options.module) |
551 { | 551 { |
552 // Wrap the entire module into a function to give it an independent scope. | 552 // Wrap the entire module into a function to give it an independent scope. |
553 // Return exported symbols: | 553 // Return exported symbols: |
554 // | 554 // |
555 // require.scopes["foobar"] = (function() { | 555 // require.scopes["foobar"] = (function() { |
556 // var exports = {}; | 556 // var exports = {}; |
557 // ... | 557 // ... |
558 // return exports; | 558 // return exports; |
559 // })(); | 559 // }); |
560 let code = 'require.scopes["' + options.filename + '"] = (function() {\n' + | 560 let code = 'require.scopes["' + options.filename + '"] = (function() {\n' + |
561 decompileAST(ast).replace(/^("use strict";\n)?/, | 561 decompileAST(ast).replace(/^("use strict";\n)?/, |
562 "$1var exports = {};\n") + | 562 "$1var exports = {};\n") + |
563 'return exports;\n' + | 563 'return exports;\n' + |
564 '})();\n'; | 564 '});\n'; |
565 _print(js_beautify(code, options)); | 565 _print(js_beautify(code, options)); |
566 } | 566 } |
567 else | 567 else |
568 _print(js_beautify(decompileAST(ast), options)); | 568 _print(js_beautify(decompileAST(ast), options)); |
569 } | 569 } |
OLD | NEW |