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

Unified Diff: scripts/astDecompile.js

Issue 29350140: Issue 4353 - Remove non standard for each syntax (Closed)
Patch Set: Created Aug. 24, 2016, 11:08 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | scripts/decompile.js » ('j') | scripts/decompile.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/astDecompile.js
diff --git a/scripts/astDecompile.js b/scripts/astDecompile.js
index 49143a6631c8bf463d8f7037ac3b37714d30bac9..3bf3bb0605285516b84896fa3b41b6c56d052b45 100644
--- a/scripts/astDecompile.js
+++ b/scripts/astDecompile.js
@@ -7,7 +7,7 @@ function decompileAST(ast) {
}
function decompileProgram(ast) {
- return [decompileAST(stmt) for each (stmt in ast.body)].join('\n');
+ return ast.body.map(decompileAST).join('\n');
}
/* Statements */
@@ -15,8 +15,7 @@ function decompileEmptyStatement(ast) {
return ";"
}
function decompileBlockStatement(ast) {
- return '{\n' + [decompileAST(stmt) for each (stmt in ast.body)].join('\n') +
- '\n}\n';
+ return '{\n' + ast.body.map(decompileAST).join('\n') + '\n}\n';
}
function decompileExpressionStatement(ast) {
@@ -50,11 +49,10 @@ function decompileWithStatement(ast) {
function decompileSwitchStatement(ast) {
let str = "switch (" + decompileAST(ast.discriminant) + ") {\n";
let cases = [];
- for each (let scase in ast.cases) {
+ for (let scase of ast.cases) {
let casestr = scase.test ? "case " + decompileAST(scase.test) : "default";
casestr += ":\n";
- casestr += [decompileAST(stmt) for each (stmt in scase.consequent)]
- .join('\n');
+ casestr += scase.consequent.map(decompileAST).join('\n');
cases.push(casestr);
}
str += cases.join('\n') + '\n}\n';
@@ -80,7 +78,7 @@ function decompileTryStatement(ast) {
handlers = ast.handlers;
let handler_strs = [];
- for each (let handler in handlers) {
+ for (let handler of handlers) {
let handler_str = "catch (" + decompileAST(handler.param);
if (handler.guard)
handler_str += " if " + decompileAST(handler.guard);
@@ -147,7 +145,7 @@ function decompileForOfStatement(ast) {
function decompileLetStatement(ast) {
let str = "let (";
- str += [d ? decompileAST(d) : ' ' for each (d in ast.head)].join(', ');
+ str += ast.head.map(d => d ? decompileAST(d) : ' ').join(', ');
str += ") " + decompileAST(ast.body);
return str;
}
@@ -163,14 +161,14 @@ function decompileFunctionDeclaration(ast, init, name_ast) {
else if (name_ast)
str += decompileAST(name_ast);
str += "(";
- str += [decompileAST(param) for each (param in ast.params)].join(', ');
+ str += ast.params.map(decompileAST).join(', ');
str += ") " + decompileAST(ast.body);
return str;
}
function decompileVariableDeclaration(ast, excludeSemi) {
let inits = [];
- for each (let initializer in ast.declarations) {
+ for (let initializer of ast.declarations) {
inits.push(decompileAST(initializer));
}
return ast.kind + " " + inits.join(', ') + (excludeSemi ? "" : ";");
@@ -227,14 +225,14 @@ function decompileThisExpression(ast) {
function decompileArrayExpression(ast) {
if (ast.elements)
- return "[" + [el ? decompileAST(el) : "" for each (el in ast.elements)].
+ return "[" + ast.elements.map(el => el ? decompileAST(el) : "").
join(", ") + "]";
return "[]";
}
function decompileObjectExpression(ast) {
let props = [];
- for each (let prop in ast.properties) {
+ for (let prop of ast.properties) {
if (prop.kind == "init")
props.push(decompileAST(prop.key) + ": " + decompileAST(prop.value));
else if (prop.kind == "get" || prop.kind == "set")
@@ -256,7 +254,7 @@ function decompileArrowExpression(ast) {
}
function decompileSequenceExpression(ast) {
- return "(" + [decompileExpr(e, ast) for each (e in ast.expressions)].join(", ") + ")";
+ return "(" + ast.expressions.map(e => decompileExpr(e, ast)).join(", ") + ")";
}
function decompileUnaryExpression(ast) {
@@ -298,14 +296,14 @@ function decompileConditionalExpression(ast) {
function decompileNewExpression(ast) {
let str = "new " + decompileAST(ast.callee, ast) + "(";
if (ast.arguments)
- str += [decompileAST(arg) for each (arg in ast.arguments)].join(", ");
+ str += ast.arguments.map(decompileAST).join(", ");
str += ")";
return str;
}
function decompileCallExpression(ast) {
return decompileExpr(ast.callee, ast) + "(" +
- [decompileAST(param) for each (param in ast.arguments)] + ")";
+ ast.arguments.map(decompileAST) + ")";
}
function decompileMemberExpression(ast) {
@@ -337,8 +335,8 @@ function decompileYieldExpression(ast) {
function decompileComprehensionExpression(ast, paren) {
let str = (paren ? paren.l : "[") + decompileAST(ast.body);
- for each (let block in ast.blocks) {
- str += (block.each ? " for each " : " for ")
+ for (let block of ast.blocks) {
+ str += (block.each ? " for each " : " for ");
str += "(" + decompileAST(block.left) + " in ";
str += decompileAST(block.right) + ")";
}
@@ -367,14 +365,13 @@ function decompileLetExpression(ast) {
function decompileObjectPattern(ast) {
let str = "{";
- str += [decompileAST(p.key) + ": " + decompileAST(p.value)
- for each (p in ast.properties)].join(', ');
+ str += ast.properties.map(p => decompileAST(p.key) + ": " +
+ decompileAST(p.value)).join(', ');
return str + "}";
}
function decompileArrayPattern(ast) {
- return "[" +
- [e ? decompileAST(e) : ' ' for each (e in ast.elements)].join(', ') + "]";
+ return "[" + ast.elements.map(e => e ? decompileAST(e) : ' ').join(', ') + "]";
}
function decompileIdentifier(ast) { return ast.name; }
@@ -389,11 +386,14 @@ function sanitize(str, q) {
if (x == '\r') return '\\r';
if (x == '\t') return '\\t';
if (x == '\v') return '\\v';
- let val = x.charCodeAt(0)
+ let val = x.charCodeAt(0);
if (x < ' ') return '\\x' + (val - val % 16) / 16 + (val % 16);
return x;
}
- return [replace(x) for each (x in str)].join('');
+ let result = "";
+ for (let char of str)
+ result += replace(char);
+ return result;
}
function decompileLiteral(ast) {
@@ -442,11 +442,11 @@ function decompileXMLFilterExpression(ast) {
}
function decompileXMLElement(ast) {
- return [decompileAST(xml) for each (xml in ast.contents)].join('');
+ return ast.contents.map(decompileAST).join('');
}
function decompileXMLList(ast) {
- return "<>" + [decompileAST(xml) for each (xml in ast.contents)].join("") + "</>";
+ return "<>" + ast.contents.map(decompileAST).join("") + "</>";
Wladimir Palant 2016/08/24 14:21:50 Nit: You've added unnecessary whitespace here.
kzar 2016/08/24 14:43:20 Done.
}
function decompileXMLEscape(ast) {
@@ -465,21 +465,21 @@ function tagJoin(strings) {
}
function decompileXMLStartTag(ast) {
- return "<" + tagJoin([decompileAST(xml) for each (xml in ast.contents)]) + ">";
+ return "<" + tagJoin(ast.contents.map(decompileAST)) + ">";
}
function decompileXMLEndTag(ast) {
- return "</" + tagJoin([decompileAST(xml) for each (xml in ast.contents)]) + ">";
+ return "</" + tagJoin(ast.contents.map(decompileAST)) + ">";
}
function decompileXMLPointTag(ast) {
- return "<" + tagJoin([decompileAST(xml) for each (xml in ast.contents)]) + "/>";
+ return "<" + tagJoin(ast.contents.map(decompileAST)) + "/>";
}
function decompileXMLName(ast) {
if (typeof ast.contents == "string")
return ast.contents + " ";
- return [decompileAST(xml) for each (xml in ast.contents)].join('');
+ return ast.contents.map(decompileAST).join('');
}
function decompileXMLAttribute(ast) {
« no previous file with comments | « no previous file | scripts/decompile.js » ('j') | scripts/decompile.js » ('J')

Powered by Google App Engine
This is Rietveld