diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2017-05-22 01:38:43 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-22 01:38:43 +0800 |
commit | efdb65913b45fc9a64fc65df3a03c8c5a7827e53 (patch) | |
tree | 6f380f405ce6eba6a3f715c4e0bbbc9c5593c17d /lib | |
parent | a1dedeb3ceb41b6419f877d34228cf0ba4b040a2 (diff) | |
download | tracifyjs-efdb65913b45fc9a64fc65df3a03c8c5a7827e53.tar.gz tracifyjs-efdb65913b45fc9a64fc65df3a03c8c5a7827e53.zip |
improve usability of `global_defs` in `minify()` (#1987)
Use `@key` to `parse()` string value as `AST_Node`.
fixes #1986
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/compress.js b/lib/compress.js index 73ab21f4..a2f8f267 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -87,6 +87,17 @@ function Compressor(options, false_by_default) { unused : !false_by_default, warnings : false, }, true); + var global_defs = this.options["global_defs"]; + if (typeof global_defs == "object") for (var key in global_defs) { + if (/^@/.test(key) && HOP(global_defs, key)) { + var ast = parse(global_defs[key]); + if (ast.body.length == 1 && ast.body[0] instanceof AST_SimpleStatement) { + global_defs[key.slice(1)] = ast.body[0].body; + } else throw new Error(string_template("Can't handle expression: {value}", { + value: global_defs[key] + })); + } + } var pure_funcs = this.options["pure_funcs"]; if (typeof pure_funcs == "function") { this.pure_funcs = pure_funcs; |