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 247abce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
20 changes: 18 additions & 2 deletions lib/compress/index.js
Expand Up @@ -5603,15 +5603,31 @@ 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: fn,
tentative_name: "argument_" + fn.argnames.length,
});
walk(fn, (node) => {
if (node instanceof AST_SymbolRef && node.thedef.name === arg.name) {
node.thedef.name = newArgName;
}
return node;
});
}

function can_inject_vars(block_scoped, safe_to_inject) {
var len = fn.body.length;
for (var i = 0; i < len; i++) {
Expand Down
2 changes: 1 addition & 1 deletion test/compress.js
Expand Up @@ -61,7 +61,7 @@ function log_test(name) {

function find_test_files(dir) {
var files = fs.readdirSync(dir).filter(function(name) {
return /\.js$/i.test(name);
return /toplevel-pure-method\.js$/i.test(name);
});
if (process.argv.length > 2) {
var x = process.argv.slice(2);
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 247abce

Please sign in to comment.