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

Side by Side Diff: scripts/astDecompile.js

Issue 5417063522762752: Issue 427 - Desugar arrow functions to normal or bound functions (Closed)
Patch Set: Created May 10, 2014, 12:46 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« scripts/abprewrite.js ('K') | « scripts/abprewrite.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 let global = this; 1 let global = this;
2 function decompileAST(ast) { 2 function decompileAST(ast) {
3 let func = global["decompile" + ast.type]; 3 let func = global["decompile" + ast.type];
4 if (!func) 4 if (!func)
5 throw "Unknown type " + ast.type; 5 throw "Unknown type " + ast.type;
6 return func(ast); 6 return func(ast);
7 } 7 }
8 8
9 function decompileProgram(ast) { 9 function decompileProgram(ast) {
10 return [decompileAST(stmt) for each (stmt in ast.body)].join('\n'); 10 return [decompileAST(stmt) for each (stmt in ast.body)].join('\n');
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 else 242 else
243 throw "Unknown kind " + prop.kind; 243 throw "Unknown kind " + prop.kind;
244 } 244 }
245 return "{\n" + props.join(",\n") + "}"; 245 return "{\n" + props.join(",\n") + "}";
246 } 246 }
247 247
248 function decompileFunctionExpression(ast) { 248 function decompileFunctionExpression(ast) {
249 return decompileFunctionDeclaration(ast); 249 return decompileFunctionDeclaration(ast);
250 } 250 }
251 251
252 function decompileArrowExpression(ast) {
253 str = "(" + ast.params.map(decompileAST).join(",") + ")";
Wladimir Palant 2014/05/15 06:53:44 Declare this variable? Also a nit: .join(", ") fo
254 str += " => " + decompileAST(ast.body);
255 return str;
256 }
257
252 function decompileSequenceExpression(ast) { 258 function decompileSequenceExpression(ast) {
253 return "(" + [decompileExpr(e, ast) for each (e in ast.expressions)].join(", " ) + ")"; 259 return "(" + [decompileExpr(e, ast) for each (e in ast.expressions)].join(", " ) + ")";
254 } 260 }
255 261
256 function decompileUnaryExpression(ast) { 262 function decompileUnaryExpression(ast) {
257 if (ast.prefix) 263 if (ast.prefix)
258 return ast.operator + " " + decompileExpr(ast.argument, ast); 264 return ast.operator + " " + decompileExpr(ast.argument, ast);
259 throw "ER, wtf?"; 265 throw "ER, wtf?";
260 } 266 }
261 267
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 return "<!--" + ast.comment + "-->"; 494 return "<!--" + ast.comment + "-->";
489 } 495 }
490 496
491 function decompileXMLProcessingInstruction(ast) { 497 function decompileXMLProcessingInstruction(ast) {
492 return "<?" + ast.target + (ast.contents ? " " + ast.contents : "") + "?>"; 498 return "<?" + ast.target + (ast.contents ? " " + ast.contents : "") + "?>";
493 } 499 }
494 500
495 function process_js(ast) { 501 function process_js(ast) {
496 _print(decompileAST(ast)); 502 _print(decompileAST(ast));
497 } 503 }
OLDNEW
« scripts/abprewrite.js ('K') | « scripts/abprewrite.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld