| OLD | NEW |
| 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 Loading... |
| 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 let str = "(" + ast.params.map(decompileAST).join(", ") + ")"; |
| 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 Loading... |
| 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 } |
| OLD | NEW |