aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2021-04-22 03:58:50 +0100
committerGitHub <noreply@github.com>2021-04-22 10:58:50 +0800
commitbddb5a01026e8295f9271f7d787e70937acba9d8 (patch)
treef1bc1ed5ea92a15b9cab8b6aaf485a8608a997d6 /lib/compress.js
parent3c161a666259389f96f9aa88a5b6d4e7579d50a4 (diff)
downloadtracifyjs-bddb5a01026e8295f9271f7d787e70937acba9d8.tar.gz
tracifyjs-bddb5a01026e8295f9271f7d787e70937acba9d8.zip
enhance `unused` (#4858)
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js29
1 files changed, 22 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 846c391b..8ec9ab88 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -5817,19 +5817,29 @@ merge(Compressor.prototype, {
} else if (node instanceof AST_Unary) {
if (node.write_only) sym = node.expression;
}
- if (/strict/.test(compressor.option("pure_getters"))) {
- while (sym instanceof AST_PropAccess && !sym.expression.may_throw_on_access(compressor)) {
- if (sym instanceof AST_Sub) props.unshift(sym.property);
- sym = sym.expression;
- nested = true;
- }
- }
+ if (/strict/.test(compressor.option("pure_getters"))) sym = extract_reference(sym, props);
if (!(sym instanceof AST_SymbolRef)) return;
var def = sym.definition();
if (export_defaults[def.id]) return;
if (compressor.exposed(def)) return;
if (!can_drop_symbol(sym, compressor, nested)) return;
return sym;
+
+ function extract_reference(node, props) {
+ if (node instanceof AST_PropAccess) {
+ var expr = node.expression;
+ if (!expr.may_throw_on_access(compressor)) {
+ nested = true;
+ if (props && node instanceof AST_Sub) props.unshift(node.property);
+ return extract_reference(expr, props);
+ }
+ } else if (node instanceof AST_Assign && node.operator == "=") {
+ var ref = extract_reference(node.right);
+ if (props) props.assign = node;
+ return ref;
+ }
+ return node;
+ }
};
var assign_in_use = Object.create(null);
var export_defaults = Object.create(null);
@@ -6648,6 +6658,11 @@ merge(Compressor.prototype, {
}
}, true);
}))) {
+ if (props.assign) {
+ props.assign.write_only = true;
+ props.assign.walk(tw);
+ delete props.assign.write_only;
+ }
props.forEach(function(prop) {
prop.walk(tw);
});