diff options
Diffstat (limited to 'lib/ast.js')
-rw-r--r-- | lib/ast.js | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -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); } |