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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 body: block | 348 body: block |
349 }; | 349 }; |
350 } | 350 } |
351 | 351 |
352 // Make sure that the loop body is always wrapped in a block | 352 // Make sure that the loop body is always wrapped in a block |
353 ast.body = ensureBlock(ast.body); | 353 ast.body = ensureBlock(ast.body); |
354 | 354 |
355 return ast; | 355 return ast; |
356 } | 356 } |
357 | 357 |
| 358 function modifyLetStatement(ast) |
| 359 { |
| 360 if (ast.body.type == "ForStatement" && ast.body.init == null) |
| 361 { |
| 362 // Convert back "for" loops written as "let" statements: |
| 363 // let (foo = 0) for (; foo < bar; ++foo) |
| 364 // { |
| 365 // ... |
| 366 // } |
| 367 // |
| 368 // Change into: |
| 369 // for (let foo = 0; foo < bar; ++foo) |
| 370 // { |
| 371 // ... |
| 372 // } |
| 373 ast.body.init = { |
| 374 type: "VariableDeclaration", |
| 375 declarations: [], |
| 376 kind: "let" |
| 377 }; |
| 378 for (let i = 0; i < ast.head.length; i++) |
| 379 { |
| 380 ast.head[i].type = "VariableDeclarator"; |
| 381 ast.body.init.declarations.push(ast.head[i]); |
| 382 } |
| 383 return modifyForStatement(ast.body); |
| 384 } |
| 385 |
| 386 return ast; |
| 387 } |
| 388 |
358 function modifyFunctionExpression(ast) | 389 function modifyFunctionExpression(ast) |
359 { | 390 { |
360 if (ast.expression) | 391 if (ast.expression) |
361 { | 392 { |
362 // Convert expression closures: | 393 // Convert expression closures: |
363 // function() foo; | 394 // function() foo; |
364 // | 395 // |
365 // Change into: | 396 // Change into: |
366 // function() | 397 // function() |
367 // { | 398 // { |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 let code = 'require.scopes["' + options.filename + '"] = (function() {\n' + | 540 let code = 'require.scopes["' + options.filename + '"] = (function() {\n' + |
510 'var exports = {};\n' + | 541 'var exports = {};\n' + |
511 decompileAST(ast) + | 542 decompileAST(ast) + |
512 'return exports;\n' + | 543 'return exports;\n' + |
513 '})();\n'; | 544 '})();\n'; |
514 _print(js_beautify(code, options)); | 545 _print(js_beautify(code, options)); |
515 } | 546 } |
516 else | 547 else |
517 _print(js_beautify(decompileAST(ast), options)); | 548 _print(js_beautify(decompileAST(ast), options)); |
518 } | 549 } |
OLD | NEW |