aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJake Harding <jharding@twitter.com>2013-02-28 21:21:14 -0800
committerMihai Bazon <mihai@bazon.net>2013-03-24 11:11:23 +0200
commit478bf4dbdde27f1110e36a56a2f9be6c11847b68 (patch)
treee9a6f6412cc9696af6054a3ce602a7afb6132cc5 /lib
parente0f67baf2d73d80685781b55b9fbfa41539e0f37 (diff)
downloadtracifyjs-478bf4dbdde27f1110e36a56a2f9be6c11847b68.tar.gz
tracifyjs-478bf4dbdde27f1110e36a56a2f9be6c11847b68.zip
Add support for enclose option. Closes #139.
Diffstat (limited to 'lib')
-rw-r--r--lib/ast.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/ast.js b/lib/ast.js
index 62bdd8db..a1301da8 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -285,6 +285,27 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
$propdoc: {
globals: "[Object/S] a map of name -> SymbolDef for all undeclared names",
},
+ wrap_enclose: function(arg_parameter_pairs) {
+ var self = this;
+ var args = [];
+ var parameters = [];
+
+ arg_parameter_pairs.forEach(function(pair) {
+ var split = pair.split(":");
+
+ args.push(split[0]);
+ parameters.push(split[1]);
+ });
+
+ var wrapped_tl = "(function(" + parameters.join(",") + "){ '$ORIG'; })(" + args.join(",") + ")";
+ wrapped_tl = parse(wrapped_tl);
+ wrapped_tl = wrapped_tl.transform(new TreeTransformer(function before(node){
+ if (node instanceof AST_Directive && node.value == "$ORIG") {
+ return MAP.splice(self.body);
+ }
+ }));
+ return wrapped_tl;
+ },
wrap_commonjs: function(name, export_all) {
var self = this;
var to_export = [];