LEFT | RIGHT |
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 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 ast.consequent = ensureBlock(ast.consequent); | 313 ast.consequent = ensureBlock(ast.consequent); |
314 if (ast.alternate && ast.alternate.type != "IfStatement") | 314 if (ast.alternate && ast.alternate.type != "IfStatement") |
315 ast.alternate = ensureBlock(ast.alternate); | 315 ast.alternate = ensureBlock(ast.alternate); |
316 return ast; | 316 return ast; |
317 } | 317 } |
318 | 318 |
319 function modifyForInStatement(ast) | 319 function modifyForInStatement(ast) |
320 { | 320 { |
321 if (ast.each) | 321 if (ast.each) |
322 { | 322 { |
323 print("Use for (.. of ..)!\n"); | 323 print("Use for (.. of ..) instead of for each (..)!\n"); |
324 throw new Error("Use for (.. of ..)!"); | 324 throw new Error("Use for (.. of ..) instead of for each (..)!"); |
325 } | 325 } |
326 | 326 |
327 // Make sure that the loop body is always wrapped in a block | 327 // Make sure that the loop body is always wrapped in a block |
328 ast.body = ensureBlock(ast.body); | 328 ast.body = ensureBlock(ast.body); |
329 | 329 |
330 return ast; | 330 return ast; |
331 } | 331 } |
332 | 332 |
333 function modifyForOfStatement(ast) | 333 function modifyForOfStatement(ast) |
334 { | 334 { |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 callee: Member(options.generatorVar, "push"), | 474 callee: Member(options.generatorVar, "push"), |
475 arguments: [ast.argument] | 475 arguments: [ast.argument] |
476 }; | 476 }; |
477 } | 477 } |
478 else | 478 else |
479 return null; | 479 return null; |
480 } | 480 } |
481 | 481 |
482 process_js = function(ast, filename, args) | 482 process_js = function(ast, filename, args) |
483 { | 483 { |
484 for each (let arg in args.split(/\s+/)) | 484 for (let arg of args.split(/\s+/)) |
485 { | 485 { |
486 let match = /^(\w+)\s*=\s*(.*)/.exec(arg); | 486 let match = /^(\w+)\s*=\s*(.*)/.exec(arg); |
487 if (match && typeof options[match[1]] == "boolean") | 487 if (match && typeof options[match[1]] == "boolean") |
488 options[match[1]] = (match[2] == "true"); | 488 options[match[1]] = (match[2] == "true"); |
489 else if (match && typeof options[match[1]] == "string") | 489 else if (match && typeof options[match[1]] == "string") |
490 options[match[1]] = match[2]; | 490 options[match[1]] = match[2]; |
491 } | 491 } |
492 | 492 |
493 if (!headerPrinted) | 493 if (!headerPrinted) |
494 { | 494 { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 let code = 'require.scopes["' + options.filename + '"] = (function() {\n' + | 543 let code = 'require.scopes["' + options.filename + '"] = (function() {\n' + |
544 'var exports = {};\n' + | 544 'var exports = {};\n' + |
545 decompileAST(ast) + | 545 decompileAST(ast) + |
546 'return exports;\n' + | 546 'return exports;\n' + |
547 '})();\n'; | 547 '})();\n'; |
548 _print(js_beautify(code, options)); | 548 _print(js_beautify(code, options)); |
549 } | 549 } |
550 else | 550 else |
551 _print(js_beautify(decompileAST(ast), options)); | 551 _print(js_beautify(decompileAST(ast), options)); |
552 } | 552 } |
LEFT | RIGHT |