aboutsummaryrefslogtreecommitdiff
path: root/lib/minify.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-05-08 02:11:45 +0800
committerGitHub <noreply@github.com>2017-05-08 02:11:45 +0800
commite54748365cba0509c82c089cdc2ef6a8bb1a724b (patch)
tree8c251cb9dae341483a5fa4eea8491bf25f0a72ec /lib/minify.js
parent2d99d06601013ab996d574d122b31df400055302 (diff)
downloadtracifyjs-e54748365cba0509c82c089cdc2ef6a8bb1a724b.tar.gz
tracifyjs-e54748365cba0509c82c089cdc2ef6a8bb1a724b.zip
support `minify()` output as AST (#1878)
- `options.output.ast` (default `false`) - `options.output.code` (default `true`)
Diffstat (limited to 'lib/minify.js')
-rw-r--r--lib/minify.js54
1 files changed, 30 insertions, 24 deletions
diff --git a/lib/minify.js b/lib/minify.js
index fe762db6..27cc9118 100644
--- a/lib/minify.js
+++ b/lib/minify.js
@@ -108,32 +108,38 @@ function minify(files, options) {
toplevel = mangle_properties(toplevel, options.mangle.properties);
}
}
- if (options.sourceMap) {
- if (typeof options.sourceMap.content == "string") {
- options.sourceMap.content = JSON.parse(options.sourceMap.content);
- }
- options.output.source_map = SourceMap({
- file: options.sourceMap.filename,
- orig: options.sourceMap.content,
- root: options.sourceMap.root
- });
- if (options.sourceMap.includeSources) {
- for (var name in files) {
- options.output.source_map.get().setSourceContent(name, files[name]);
+ var result = {};
+ if (options.output.ast) {
+ result.ast = toplevel;
+ }
+ if (!HOP(options.output, "code") || options.output.code) {
+ if (options.sourceMap) {
+ if (typeof options.sourceMap.content == "string") {
+ options.sourceMap.content = JSON.parse(options.sourceMap.content);
+ }
+ options.output.source_map = SourceMap({
+ file: options.sourceMap.filename,
+ orig: options.sourceMap.content,
+ root: options.sourceMap.root
+ });
+ if (options.sourceMap.includeSources) {
+ for (var name in files) {
+ options.output.source_map.get().setSourceContent(name, files[name]);
+ }
}
}
- }
- var stream = OutputStream(options.output);
- toplevel.print(stream);
- var result = {
- code: stream.get()
- };
- if (options.sourceMap) {
- result.map = options.output.source_map.toString();
- if (options.sourceMap.url == "inline") {
- result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
- } else if (options.sourceMap.url) {
- result.code += "\n//# sourceMappingURL=" + options.sourceMap.url;
+ delete options.output.ast;
+ delete options.output.code;
+ var stream = OutputStream(options.output);
+ toplevel.print(stream);
+ result.code = stream.get();
+ if (options.sourceMap) {
+ result.map = options.output.source_map.toString();
+ if (options.sourceMap.url == "inline") {
+ result.code += "\n//# sourceMappingURL=data:application/json;charset=utf-8;base64," + to_base64(result.map);
+ } else if (options.sourceMap.url) {
+ result.code += "\n//# sourceMappingURL=" + options.sourceMap.url;
+ }
}
}
if (warnings.length) {