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

Side by Side Diff: scripts/abprewrite.js

Issue 4935066966818816: Issue 1772 - [JSHydra] Convert const to var for Chrome (Closed)
Patch Set: Created Jan. 10, 2015, 12:03 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
« no previous file with comments | « autotest/test_abprewrite_module.js.expected ('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 // This script rewrites AST to be compatible with JavaScript 1.5 and decompiles 1 // This script rewrites AST to be compatible with JavaScript 1.5 and decompiles
2 // the modified tree then 2 // the modified tree then
3 3
4 include("../scripts/astDecompile.js"); 4 include("../scripts/astDecompile.js");
5 include("../utils/beautify.js"); 5 include("../utils/beautify.js");
6 6
7 let headerPrinted = false; 7 let headerPrinted = false;
8 8
9 // See https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API for 9 // See https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API for
10 // AST structure. 10 // AST structure.
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 for (let i = 0; i < vars.length; i++) 205 for (let i = 0; i < vars.length; i++)
206 if (vars[i]) 206 if (vars[i])
207 block.body.push(Assignment(vars[i], Member(tempVar, i, true))); 207 block.body.push(Assignment(vars[i], Member(tempVar, i, true)));
208 return block; 208 return block;
209 } 209 }
210 return ast; 210 return ast;
211 } 211 }
212 212
213 function modifyVariableDeclaration(ast) 213 function modifyVariableDeclaration(ast)
214 { 214 {
215 // Convert let variables: 215 // Convert let and const variables:
216 // let foo = bar; 216 // let foo = bar;
217 // const bas = 4;
217 // 218 //
218 // Change into: 219 // Change into:
219 // var foo = bar; 220 // var foo = bar;
220 if (ast.kind == "let") 221 // var bas = 4;
222 if (ast.kind == "let" || ast.kind == "const")
221 ast.kind = "var"; 223 ast.kind = "var";
222 224
223 if (ast.declarations.length == 1 && ast.declarations[0].type == "VariableDecla rator") 225 if (ast.declarations.length == 1 && ast.declarations[0].type == "VariableDecla rator")
224 { 226 {
225 let declarator = ast.declarations[0]; 227 let declarator = ast.declarations[0];
226 228
227 // Remove timeline requires: 229 // Remove timeline requires:
228 // let {Timeline} = require("timeline"); 230 // let {Timeline} = require("timeline");
229 if (declarator.init && decompileAST(declarator.init) == 'require("timeline") ') 231 if (declarator.init && decompileAST(declarator.init) == 'require("timeline") ')
230 return null; 232 return null;
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 let code = 'require.scopes["' + options.filename + '"] = (function() {\n' + 570 let code = 'require.scopes["' + options.filename + '"] = (function() {\n' +
569 'var exports = {};\n' + 571 'var exports = {};\n' +
570 decompileAST(ast) + 572 decompileAST(ast) +
571 'return exports;\n' + 573 'return exports;\n' +
572 '})();\n'; 574 '})();\n';
573 _print(js_beautify(code, options)); 575 _print(js_beautify(code, options));
574 } 576 }
575 else 577 else
576 _print(js_beautify(decompileAST(ast), options)); 578 _print(js_beautify(decompileAST(ast), options));
577 } 579 }
OLDNEW
« no previous file with comments | « autotest/test_abprewrite_module.js.expected ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld