Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: scripts/abprewrite.js

Issue 29350158: Issue 4353 - Update Js Shell to version 45 (Closed)
Patch Set: Created Aug. 24, 2016, 11:16 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | scripts/astDecompile.js » ('j') | utils.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 return ast; 121 return ast;
123 else 122 else
124 return {type: "BlockStatement", body: (ast.type == "EmptyStatement" ? [] : [ ast])}; 123 return {type: "BlockStatement", body: (ast.type == "EmptyStatement" ? [] : [ ast])};
125 } 124 }
126 125
127 function modifyAST(ast) 126 function modifyAST(ast)
128 { 127 {
129 // Do the necessary modifications 128 // Do the necessary modifications
130 let func = "modify" + ast.type; 129 let func = "modify" + ast.type;
131 if (typeof global[func] == "function") 130 if (typeof global[func] == "function")
132 ast = global[func](ast); 131 ast = global[func](ast);
Wladimir Palant 2016/08/24 14:08:36 How is this working now? You removed the `global`
kzar 2016/08/24 14:25:20 `global` is already defined in astDecompile.js whi
Wladimir Palant 2016/08/24 14:45:17 Ok, this is really awkward... This should really b
kzar 2016/09/13 13:35:20 I agree this is awkward, but I don't understand wh
Wladimir Palant 2016/09/13 14:22:59 I'm not actually suggesting anything at this point
133 132
134 // Recursive calls for any AST in properties of the current one 133 // Recursive calls for any AST in properties of the current one
135 if (ast) 134 if (ast)
136 { 135 {
137 let props = []; 136 let props = [];
138 for (let prop in ast) 137 for (let prop in ast)
139 props.push(prop); 138 props.push(prop);
140 for (let i = 0; i < props.length; i++) 139 for (let i = 0; i < props.length; i++)
141 { 140 {
142 let value = ast[props[i]]; 141 let value = ast[props[i]];
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 };
OLDNEW
« no previous file with comments | « no previous file | scripts/astDecompile.js » ('j') | utils.py » ('J')

Powered by Google App Engine
This is Rietveld