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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loosen requirements discovering identity functions #1121

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 1 addition & 3 deletions lib/compress/index.js
Expand Up @@ -2375,9 +2375,7 @@ def_optimize(AST_Call, function(self, compressor) {
}

// optimize identity function
if (
fn.argnames.length === 1
&& (fn.argnames[0] instanceof AST_SymbolFunarg)
if (fn.argnames[0] instanceof AST_SymbolFunarg
&& self.args.length < 2
&& returned instanceof AST_SymbolRef
&& returned.name === fn.argnames[0].name
Expand Down
13 changes: 13 additions & 0 deletions test/compress/identity.js
Expand Up @@ -249,3 +249,16 @@ inline_identity_dont_lose_this_when_arg: {
}
}

inline_identity_with_scope_conflict: {
options = { defaults: true, toplevel: true }
input: {
function identity(a, _b, _c, _d) {
return a;
}
console.log(identity(a));
}

expect: {
console.log(a);
}
}