Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to keep_imports #1423

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/minify.js
Expand Up @@ -165,6 +165,7 @@ async function minify(files, options, _fs_module) {
ie8: false,
keep_classnames: false,
keep_fnames: false,
keep_imports: false,
module: false,
nth_identifier: base54,
properties: false,
Expand Down
3 changes: 2 additions & 1 deletion lib/scope.js
Expand Up @@ -168,7 +168,8 @@ class SymbolDef {
|| this.orig[0] instanceof AST_SymbolDefun) && keep_name(options.keep_fnames, this.orig[0].name)
|| this.orig[0] instanceof AST_SymbolMethod
|| (this.orig[0] instanceof AST_SymbolClass
|| this.orig[0] instanceof AST_SymbolDefClass) && keep_name(options.keep_classnames, this.orig[0].name);
|| this.orig[0] instanceof AST_SymbolDefClass) && keep_name(options.keep_classnames, this.orig[0].name)
|| (this.orig[0] instanceof AST_SymbolImport && options.keep_imports);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per your comment, maybe what's needed to solve the problem is a heuristic such as keeping imports that are used less than 2 or 3 times. this.references.length should contain this information.

}
mangle(options) {
const cache = options.cache && options.cache.props;
Expand Down