Skip to content

Commit

Permalink
prep: add rename_arg
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Apr 26, 2021
1 parent 208e584 commit 79c1c43
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
24 changes: 22 additions & 2 deletions lib/compress/index.js
Expand Up @@ -5603,15 +5603,35 @@ def_optimize(AST_Call, function(self, compressor) {
if (has_flag(arg, UNUSED)) continue;
if (!safe_to_inject
|| block_scoped.has(arg.name)
|| identifier_atom.has(arg.name)
|| scope.conflicting_def(arg.name)) {
|| identifier_atom.has(arg.name)) {
return false;
}
if (scope.conflicting_def(arg.name)) {
rename_arg(arg);
}
if (in_loop) in_loop.push(arg.definition());
}
return true;
}

function rename_arg(arg) {
const newArgName = fn.create_symbol(AST_SymbolFunarg, {
source: fn,
scope: scope,
tentative_name: "argument_" + fn.argnames.length,
});

const cb = (node) => {
if (node instanceof AST_SymbolRef && node.thedef.name === arg.name) {
node.thedef.name = newArgName;
return node;
} else {
return walk(node, cb);
}
};
walk(fn.body[0], cb);
}

function can_inject_vars(block_scoped, safe_to_inject) {
var len = fn.body.length;
for (var i = 0; i < len; i++) {
Expand Down
1 change: 0 additions & 1 deletion test/compress/toplevel-pure-method.js
Expand Up @@ -45,7 +45,6 @@ inline_different_name: {
}
}

// TODO:
rename_and_inline: {
options = {
toplevel: true,
Expand Down

0 comments on commit 79c1c43

Please sign in to comment.