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

Delta Between Two Patch Sets: scripts/astDecompile.js

Issue 29350140: Issue 4353 - Remove non standard for each syntax (Closed)
Left Patch Set: Created Aug. 24, 2016, 11:08 a.m.
Right Patch Set: Removed unused code Created Aug. 24, 2016, 2:40 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « scripts/ast.js ('k') | scripts/basic.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 ast.body.map(decompileAST).join('\n'); 10 return ast.body.map(decompileAST).join('\n');
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 } 397 }
398 398
399 function decompileLiteral(ast) { 399 function decompileLiteral(ast) {
400 if (typeof ast.value == "string") 400 if (typeof ast.value == "string")
401 return '"' + sanitize(ast.value, '"') + '"'; 401 return '"' + sanitize(ast.value, '"') + '"';
402 if (ast.value === null) 402 if (ast.value === null)
403 return "null"; 403 return "null";
404 return ast.value; 404 return ast.value;
405 } 405 }
406 406
407 /* E4X */
408 function decompileXMLDefaultDeclaration(ast) {
409 return "default xml namespace = " + decompileAST(ast.namespace) + ";";
410 }
411
412 function decompileXMLAnyName(ast) {
413 return "*";
414 }
415
416 function decompileXMLQualifiedIdentifier(ast) {
417 let str = decompileAST(ast.left) + "::";
418 if (ast.computed)
419 str += "[";
420 str += decompileAST(ast.right);
421 if (ast.computed)
422 str += "]";
423 return str;
424 }
425
426 function decompileXMLFunctionQualifiedIdentifier(ast) {
427 let str = "function::";
428 if (ast.computed)
429 str += "[";
430 str += decompileAST(ast.right);
431 if (ast.computed)
432 str += "]";
433 return str;
434 }
435
436 function decompileXMLAttributeSelector(ast) {
437 return "@" + decompileAST(ast.attribute);
438 }
439
440 function decompileXMLFilterExpression(ast) {
441 return decompileAST(ast.left) + ".(" + decompileAST(ast.right) + ")";
442 }
443
444 function decompileXMLElement(ast) {
445 return ast.contents.map(decompileAST).join('');
446 }
447
448 function decompileXMLList(ast) {
449 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.
450 }
451
452 function decompileXMLEscape(ast) {
453 return "{" + decompileAST(ast.expression) + "}";
454 }
455
456 function decompileXMLText(ast) {
457 return ast.text;
458 }
459
460 function tagJoin(strings) {
461 let str = strings[0];
462 for (let i = 1; i < strings.length; i++)
463 str += (i % 2 ? ' ' : '=') + strings[i];
464 return str;
465 }
466
467 function decompileXMLStartTag(ast) {
468 return "<" + tagJoin(ast.contents.map(decompileAST)) + ">";
469 }
470
471 function decompileXMLEndTag(ast) {
472 return "</" + tagJoin(ast.contents.map(decompileAST)) + ">";
473 }
474
475 function decompileXMLPointTag(ast) {
476 return "<" + tagJoin(ast.contents.map(decompileAST)) + "/>";
477 }
478
479 function decompileXMLName(ast) {
480 if (typeof ast.contents == "string")
481 return ast.contents + " ";
482 return ast.contents.map(decompileAST).join('');
483 }
484
485 function decompileXMLAttribute(ast) {
486 return '"' + ast.value + '"';
487 }
488
489 function decompileXMLCdata(ast) {
490 return "<![CDATA[" + ast.contents + "]]>";
491 }
492
493 function decompileXMLComment(ast) {
494 return "<!--" + ast.comment + "-->";
495 }
496
497 function decompileXMLProcessingInstruction(ast) {
498 return "<?" + ast.target + (ast.contents ? " " + ast.contents : "") + "?>";
499 }
Wladimir Palant 2016/08/24 14:21:50 It's probably better to just remove all functions
kzar 2016/08/24 14:43:20 Done.
500
501 function process_js(ast) { 407 function process_js(ast) {
502 _print(decompileAST(ast)); 408 _print(decompileAST(ast));
503 } 409 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld