aboutsummaryrefslogtreecommitdiff
path: root/lib/ast.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ast.js')
-rw-r--r--lib/ast.js23
1 files changed, 16 insertions, 7 deletions
diff --git a/lib/ast.js b/lib/ast.js
index f75670e6..1ced7631 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -337,18 +337,25 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
$propdoc: {
globals: "[Object/S] a map of name -> SymbolDef for all undeclared names",
},
- wrap_commonjs: function(name) {
+ wrap: function(name) {
var body = this.body;
- var wrapped_tl = "(function(exports){'$ORIG';})(typeof " + name + "=='undefined'?(" + name + "={}):" + name + ");";
- wrapped_tl = parse(wrapped_tl);
- wrapped_tl = wrapped_tl.transform(new TreeTransformer(function(node) {
+ return parse([
+ "(function(exports){'$ORIG';})(typeof ",
+ name,
+ "=='undefined'?(",
+ name,
+ "={}):",
+ name,
+ ");"
+ ].join(""), {
+ filename: "wrap=" + JSON.stringify(name)
+ }).transform(new TreeTransformer(function(node) {
if (node instanceof AST_Directive && node.value == "$ORIG") {
return MAP.splice(body);
}
}));
- return wrapped_tl;
},
- wrap_enclose: function(args_values) {
+ enclose: function(args_values) {
if (typeof args_values != "string") args_values = "";
var index = args_values.indexOf(":");
if (index < 0) index = args_values.length;
@@ -359,7 +366,9 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
'){"$ORIG"})(',
args_values.slice(index + 1),
")"
- ].join("")).transform(new TreeTransformer(function(node) {
+ ].join(""), {
+ filename: "enclose=" + JSON.stringify(args_values)
+ }).transform(new TreeTransformer(function(node) {
if (node instanceof AST_Directive && node.value == "$ORIG") {
return MAP.splice(body);
}