aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJiavan <jiavan.com@gmail.com>2018-06-01 16:47:11 +0800
committerAlex Lam S.L <alexlamsl@gmail.com>2018-06-01 16:47:11 +0800
commitb39043f3ab0061f2db91514dbb69e85a49a99997 (patch)
tree5ab5756a1e6aa9a54c7912258739e6247439d997 /lib
parentcaf96acb08ad8113f03299a939b4a45ef44ffa42 (diff)
downloadtracifyjs-b39043f3ab0061f2db91514dbb69e85a49a99997.tar.gz
tracifyjs-b39043f3ab0061f2db91514dbb69e85a49a99997.zip
re-introduce `enclose` (#3163)
fixes #2443
Diffstat (limited to 'lib')
-rw-r--r--lib/ast.js17
-rw-r--r--lib/minify.js4
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/ast.js b/lib/ast.js
index 331d340b..1a77a59d 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -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);
diff --git a/lib/minify.js b/lib/minify.js
index 399b8615..d84f6825 100644
--- a/lib/minify.js
+++ b/lib/minify.js
@@ -55,6 +55,7 @@ function minify(files, options) {
try {
options = defaults(options, {
compress: {},
+ enclose: false,
ie8: false,
keep_fnames: false,
mangle: {},
@@ -157,6 +158,9 @@ function minify(files, options) {
if (options.wrap) {
toplevel = toplevel.wrap_commonjs(options.wrap);
}
+ if (options.enclose) {
+ toplevel = toplevel.wrap_enclose(options.enclose);
+ }
if (timings) timings.rename = Date.now();
if (options.rename) {
toplevel.figure_out_scope(options.mangle);