re-introduce enclose (#3163)

fixes #2443
This commit is contained in:
Jiavan
2018-06-01 16:47:11 +08:00
committed by Alex Lam S.L
parent caf96acb08
commit b39043f3ab
7 changed files with 104 additions and 2 deletions

View File

@@ -335,6 +335,23 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
}
}));
return wrapped_tl;
},
wrap_enclose: function(args_values) {
if (typeof args_values != "string") args_values = "";
var index = args_values.indexOf(":");
if (index < 0) index = args_values.length;
var body = this.body;
return parse([
"(function(",
args_values.slice(0, index),
'){"$ORIG"})(',
args_values.slice(index + 1),
")"
].join("")).transform(new TreeTransformer(function(node) {
if (node instanceof AST_Directive && node.value == "$ORIG") {
return MAP.splice(body);
}
}));
}
}, AST_Scope);