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

Side by Side Diff: scripts/decompile.js

Issue 29350140: Issue 4353 - Remove non standard for each syntax (Closed)
Patch Set: Created Aug. 24, 2016, 11:08 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
OLDNEW
1 // Decompile a JS file. This will be painful. 1 // Decompile a JS file. This will be painful.
Wladimir Palant 2016/08/24 14:21:50 I don't consider it a good measure to modify files
kzar 2016/08/24 14:43:20 Done.
2 include("../utils/dumpast.js"); 2 include("../utils/dumpast.js");
3 include("../utils/astml.js"); 3 include("../utils/astml.js");
4 4
5 let visitor = { 5 let visitor = {
6 _visitArray: function (arr, pre, post, comma) { 6 _visitArray: function (arr, pre, post, comma) {
7 if (pre === undefined) pre = '('; 7 if (pre === undefined) pre = '(';
8 if (post === undefined) post = ')'; 8 if (post === undefined) post = ')';
9 if (comma === undefined) comma = ', '; 9 if (comma === undefined) comma = ', ';
10 output(pre); 10 output(pre);
11 for each (let arg in arr) { 11 for (let arg of arr) {
12 arg.visit(this); 12 arg.visit(this);
13 output(comma); 13 output(comma);
14 } 14 }
15 if (arr.length > 0) 15 if (arr.length > 0)
16 unwrite(comma.length); 16 unwrite(comma.length);
17 output(post); 17 output(post);
18 }, 18 },
19 _visitMaybeBlock: function (body) { 19 _visitMaybeBlock: function (body) {
20 if (body.type == "BlockStatement") { 20 if (body.type == "BlockStatement") {
21 output(" "); 21 output(" ");
22 body.visit(this); 22 body.visit(this);
23 } else { 23 } else {
24 flush().indent(); 24 flush().indent();
25 body.visit(this); 25 body.visit(this);
26 unindent(); 26 unindent();
27 } 27 }
28 }, 28 },
29 _visitNeedBlock: function (stmt, noFlush) { 29 _visitNeedBlock: function (stmt, noFlush) {
30 if (stmt.type == "EmptyStatement") { 30 if (stmt.type == "EmptyStatement") {
31 output("{}") 31 output("{}");
32 if (!noFlush) 32 if (!noFlush)
33 flush(); 33 flush();
34 } 34 }
35 else if (stmt.type == "ReturnStatement") { 35 else if (stmt.type == "ReturnStatement") {
36 output("{").flush().indent(); 36 output("{").flush().indent();
37 stmt.visit(this); 37 stmt.visit(this);
38 unindent().output("}"); 38 unindent().output("}");
39 if (!noFlush) 39 if (!noFlush)
40 flush(); 40 flush();
41 } 41 }
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 function sanitize(str, q) { 439 function sanitize(str, q) {
440 function replace(x) { 440 function replace(x) {
441 if (x == q) return '\\' + q; 441 if (x == q) return '\\' + q;
442 if (x == '\\') return '\\\\'; 442 if (x == '\\') return '\\\\';
443 if (x == '\b') return '\\b'; 443 if (x == '\b') return '\\b';
444 if (x == '\f') return '\\f'; 444 if (x == '\f') return '\\f';
445 if (x == '\n') return '\\n'; 445 if (x == '\n') return '\\n';
446 if (x == '\r') return '\\r'; 446 if (x == '\r') return '\\r';
447 if (x == '\t') return '\\t'; 447 if (x == '\t') return '\\t';
448 if (x == '\v') return '\\v'; 448 if (x == '\v') return '\\v';
449 let val = x.charCodeAt(0) 449 let val = x.charCodeAt(0);
450 if (x < ' ') return '\\x' + (val - val % 16) / 16 + (val % 16); 450 if (x < ' ') return '\\x' + (val - val % 16) / 16 + (val % 16);
451 return x; 451 return x;
452 } 452 }
453 return [replace(x) for each (x in str)].join(''); 453
454 let result = "";
455 for (let char of str)
456 result += replace(char);
457 return result;
454 } 458 }
OLDNEW
« scripts/astDecompile.js ('K') | « scripts/astDecompile.js ('k') | scripts/doxygen.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld