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

Unified Diff: scripts/abprewrite.js

Issue 29345403: Issue 4088 - JSHydra-generated module scopes shouldn't be called immediately (Closed)
Patch Set: Renamed callback Created May 31, 2016, 2:53 p.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 | « jshydra.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/abprewrite.js
===================================================================
--- a/scripts/abprewrite.js
+++ b/scripts/abprewrite.js
@@ -7,16 +7,17 @@ include("../utils/beautify.js");
let headerPrinted = false;
// See https://developer.mozilla.org/en-US/docs/SpiderMonkey/Parser_API for
// AST structure.
let options = {
filename: null,
module: false,
+ autoload: "",
varIndex: 0,
indent_size: 2,
preserve_newlines: false,
brace_style: "expand",
source_repo: ""
};
let global = this;
@@ -491,17 +492,17 @@ function modifyYieldExpression(ast)
callee: Member(options.generatorVar, "push"),
arguments: [ast.argument]
};
}
else
return null;
}
-process_js = function(ast, filename, args)
+var process_js = function(ast, filename, args)
{
for (let arg of args.split(/\s+/))
{
let match = /^(\w+)\s*=\s*(.*)/.exec(arg);
if (match && typeof options[match[1]] == "boolean")
options[match[1]] = (match[2] == "true");
else if (match && typeof options[match[1]] == "string")
options[match[1]] = match[2];
@@ -551,19 +552,38 @@ process_js = function(ast, filename, arg
{
// Wrap the entire module into a function to give it an independent scope.
// Return exported symbols:
//
// require.scopes["foobar"] = (function() {
// var exports = {};
// ...
// return exports;
- // })();
+ // });
let code = 'require.scopes["' + options.filename + '"] = (function() {\n' +
decompileAST(ast).replace(/^("use strict";\n)?/,
"$1var exports = {};\n") +
'return exports;\n' +
- '})();\n';
+ '});\n';
_print(js_beautify(code, options));
}
else
_print(js_beautify(decompileAST(ast), options));
-}
+};
+
+var post_processing = function()
+{
+ let autoloadModules = options.autoload.split(/[\s,]+/);
+ for (let module of autoloadModules)
+ {
+ if (module == "")
+ continue;
+
+ _print(decompileAST({
+ type: "ExpressionStatement",
+ expression: {
+ type: "CallExpression",
+ callee: Identifier("require"),
+ arguments: [Literal(module)]
+ }
+ }));
+ }
+};
« no previous file with comments | « jshydra.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld