fix corner case in keep_fargs (#5477)

fixes #5476
This commit is contained in:
Alex Lam S.L
2022-05-29 05:10:19 +01:00
committed by GitHub
parent 2152f00de2
commit 8bc03dc6c4
4 changed files with 45 additions and 7 deletions

View File

@@ -64,19 +64,20 @@ SymbolDef.prototype = {
this.references.forEach(fn);
},
mangle: function(options) {
var cache = options.cache && options.cache.props;
if (this.global && cache && cache.has(this.name)) {
if (this.mangled_name) return;
var cache = this.global && options.cache && options.cache.props;
if (cache && cache.has(this.name)) {
this.mangled_name = cache.get(this.name);
} else if (!this.mangled_name && !this.unmangleable(options)) {
} else if (this.unmangleable(options)) {
names_in_use(this.scope, options).set(this.name, true);
} else {
var def = this.redefined();
if (def) {
this.mangled_name = def.mangled_name || def.name;
} else {
this.mangled_name = next_mangled_name(this, options);
}
if (this.global && cache) {
cache.set(this.name, this.mangled_name);
}
if (cache) cache.set(this.name, this.mangled_name);
}
},
redefined: function() {

View File

@@ -1855,3 +1855,20 @@ issue_5338: {
}
expect_stdout: true
}
issue_5476: {
mangle = {
keep_fargs: true,
}
input: {
console.log(function(n) {
const a = 42;
}());
}
expect: {
console.log(function(n) {
const o = 42;
}());
}
expect_stdout: "undefined"
}

View File

@@ -2020,3 +2020,23 @@ issue_5338: {
expect_stdout: ReferenceError("a is not defined")
node_version: ">=4"
}
issue_5476: {
mangle = {
keep_fargs: true,
}
input: {
"use strict";
console.log(function(n) {
let a;
}());
}
expect: {
"use strict";
console.log(function(n) {
let o;
}());
}
expect_stdout: "undefined"
node_version: ">=4"
}

View File

@@ -2329,7 +2329,7 @@ function is_error_tdz(ex) {
}
function is_error_spread(ex) {
return ex.name == "TypeError" && /Found non-callable @@iterator| is not iterable| not a function/.test(ex.message);
return ex.name == "TypeError" && /Found non-callable @@iterator| is not iterable| not a function|Symbol\(Symbol\.iterator\)/.test(ex.message);
}
function is_error_recursion(ex) {