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 done_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)] |
+ } |
+ })); |
+ } |
+}; |