fix(es/renamer): Use a separate scope for the name of FnExpr (#6008)

This commit is contained in:
Austaras 2022-10-01 11:33:19 +08:00 committed by GitHub
parent 628b1a8455
commit 31ffd5a01d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 139 additions and 134 deletions

View File

@ -0,0 +1,10 @@
global._processChunk = function r(r, c, i) {
if (r) {
if (!c) {
return true;
}
var i = this.write();
return (i.callback = callback), void 0;
}
cb();
};

View File

@ -1,10 +0,0 @@
global._processChunk = function r(c, i, a) {
if (c) {
if (!i) {
return true;
}
var a = this.write();
return (a.callback = callback), void 0;
}
cb();
};

View File

@ -120,12 +120,12 @@ var TypeScript;
}
var _proto = AstPath.prototype;
_proto.clone = function clone() {
var clone1 = new AstPath();
clone1.asts = this.asts.map(function(value) {
var clone = new AstPath();
clone.asts = this.asts.map(function(value) {
return value;
});
clone1.top = this.top;
return clone1;
clone.top = this.top;
return clone;
};
_proto.pop = function pop() {
var head = this.ast();

View File

@ -1,7 +1,7 @@
//// [typeParametersAvailableInNestedScope3.ts]
function foo(v) {
var a = function a(a1) {
return a1;
var a = function a(a) {
return a;
};
var b = function b() {
return v;

View File

@ -1,5 +1,5 @@
var b = 1;
(function f(f1) {
(f1 = b)[b] = 0;
(function f(f) {
(f = b)[b] = 0;
})();
console.log("PASS");

View File

@ -1,6 +1,6 @@
var o = 1;
(function n(c) {
c = o;
c[o] = 0;
(function n(n) {
n = o;
n[o] = 0;
})();
console.log("PASS");

View File

@ -3,8 +3,8 @@
var o = n;
var n = o++;
try {
!(function o(n) {
n[1] = "foo";
!(function o(o) {
o[1] = "foo";
})();
console.log("FAIL");
} catch (c) {

View File

@ -1,7 +1,7 @@
var c = 0;
!function a() {
a1 && c++;
var a1 = 0;
a1 && c++;
a && c++;
var a = 0;
a && c++;
}();
console.log(c);

View File

@ -1,7 +1,7 @@
var o = 0;
!(function n() {
a && o++;
var a = 0;
a && o++;
n && o++;
var n = 0;
n && o++;
})();
console.log(o);

View File

@ -1,8 +1,8 @@
var n = "PASS";
(function() {
function o(o) {
(function n(o) {
var o = o && (o.null = "FAIL");
(function n(n) {
var n = n && (n.null = "FAIL");
})(n);
}
o();

View File

@ -1,7 +1,7 @@
var o = 1;
try {
var r = (function o(r) {
throw r;
var r = (function o(o) {
throw o;
})(2);
var a = --o + r;
} catch (c) {}

View File

@ -1,10 +1,10 @@
var l = 0;
(function n(o) {
var u = 2;
(function n(n) {
var o = 2;
do {
o && o[o];
o && (o.null = -4);
n && n[n];
n && (n.null = -4);
l++;
}while (o.null && --u > 0)
}while (n.null && --o > 0)
})(true);
console.log(l);

View File

@ -1,8 +1,8 @@
console.log((function n(o) {
console.log((function n(n) {
return (function(n) {
if (n) {
const o = n;
if (o) return o;
}
})(o);
})(n);
})("PASS"));

View File

@ -1,10 +1,10 @@
console.log((function n() {
var o = 1;
return o;
var n = 1;
return n;
})(), (function n() {
const o = 2;
return o;
const n = 2;
return n;
})(), (function n() {
function o() {}
return o;
function n() {}
return n;
})());

View File

@ -1,10 +1,10 @@
var c = 1;
!(function c() {
o++;
c++;
try {
x();
} catch (o) {
var o;
} catch (c) {
var c;
}
})();
console.log(c);

View File

@ -1,3 +1,3 @@
function n() {
return function n(t) {};
return function n(n) {};
}

View File

@ -4,7 +4,7 @@
console.log((function n() {
return "okay";
})());
console.log((function n(o, r, t) {
console.log((function n(n, o, r) {
return 123;
})());
console.log((function(n, o, r) {

View File

@ -4,7 +4,7 @@
console.log((function n() {
return "okay";
})());
console.log((function n(o, r, t) {
console.log((function n(n, o, r) {
return 123;
})());
console.log((function(n, o, r) {

View File

@ -7,7 +7,7 @@ var n = 0;
length: (n = 1 + n)
},
typeof void (function o() {
var t = (function n(o) {})(t && (t.b += ((n = n + 1), 0)));
var o = (function n(n) {})(o && (o.b += ((n = n + 1), 0)));
})()
]);
console.log(n);

View File

@ -7,7 +7,7 @@ var n = 0;
length: (n = 1 + n)
},
typeof void (function o() {
var t = (function n(o) {})(t && (t.b += ((n = n + 1), 0)));
var o = (function n(n) {})(o && (o.b += ((n = n + 1), 0)));
})()
]);
console.log(n);

View File

@ -3,8 +3,8 @@ var o = "FAIL";
try {
throw 1;
} catch (c) {
(function o(c) {
c && c();
(function o(o) {
o && o();
})();
c && (o = "PASS");
}

View File

@ -3,8 +3,8 @@ var o = "FAIL";
try {
throw 1;
} catch (c) {
(function o(c) {
c && c();
(function o(o) {
o && o();
})();
c && (o = "PASS");
}

View File

@ -1,8 +1,8 @@
var n = "FAIL";
(function() {
function o(o) {
var c = (function n(o) {
o && o();
var c = (function n(n) {
n && n();
})();
if (o) {
var f = (n = "PASS");

View File

@ -1,8 +1,8 @@
var n = "FAIL";
(function() {
function o(o) {
var c = (function n(o) {
o && o();
var c = (function n(n) {
n && n();
})();
if (o) {
var f = (n = "PASS");

View File

@ -1,11 +1,11 @@
"use strict";
console.log((function n() {
return r;
function t(n) {
return t;
function n(n) {
return n || n();
}
function r(n) {
t(n);
return n;
function t(t) {
n(t);
return t;
}
})()(42));

View File

@ -1,3 +1,3 @@
function n(n) {}
function c(n) {}
(function n(c) {})();
(function n(n) {})();

View File

@ -1,6 +1,6 @@
var p = {
p: function p(n) {
return 10 * n;
p: function p(p) {
return 10 * p;
},
x: 1,
y: 2

View File

@ -1,10 +1,10 @@
var n = 0;
(function(o, c) {
(function o(i) {
var l = 2;
while(--c + (i = {
(function o(o) {
var i = 2;
while(--c + (o = {
p: n++
}) && --l > 0);
}) && --i > 0);
})();
})();
console.log(n);

View File

@ -1,6 +1,6 @@
"use strict";
function total() {
return function t(n, r, u) {
return n + r + u;
return function t(t, n, r) {
return t + n + r;
};
}

View File

@ -1,6 +1,6 @@
"use strict";
function n() {
return function n(t, r, u) {
return t + r + u;
return function n(n, t, r) {
return n + t + r;
};
}

View File

@ -1,6 +1,6 @@
"use strict";
function n() {
return function n(t, r, u) {
return t + r + u;
return function n(n, t, r) {
return n + t + r;
};
}

View File

@ -1,6 +1,6 @@
!(function n(r) {
return r && n(r - 1) + r;
})(42);
!(function n(r) {
return r;
!(function n(n) {
return n;
})(42);

View File

@ -1,3 +1,3 @@
(function n(r) {
return g(r + 1);
(function n(n) {
return g(n + 1);
})(2);

View File

@ -1,9 +1,9 @@
global.t = "ttttttttttttttttttttt";
(function t() {
var n = "PASS";
var t = "PASS";
return ()=>{
console.log(n);
var t = function() {};
return t;
console.log(t);
var n = function() {};
return n;
};
})()();

View File

@ -4,9 +4,9 @@ new (function(n) {
new (function(n) {
this.foo = n;
})();
new (function n(o) {
this.foo = o;
new (function n(n) {
this.foo = n;
})(1);
new (function n(o) {
this.foo = o;
new (function n(n) {
this.foo = n;
})();

View File

@ -1,4 +1,4 @@
console.log((function n(o) {
function t() {}
return t.length;
console.log((function n(n) {
function o() {}
return o.length;
})());

View File

@ -1,4 +1,4 @@
console.log((function n(o) {
function t() {}
return t.length;
console.log((function n(n) {
function o() {}
return o.length;
})());

View File

@ -20,9 +20,9 @@ console.log((function() {
n = 6;
return n;
})(), (function n() {
r = 7;
return r;
var r;
n = 7;
return n;
var n;
})(), (function() {
n = 8;
return n;

View File

@ -1,3 +1,3 @@
(function n(r) {
return g(r + 1);
(function n(n) {
return g(n + 1);
})(2);

View File

@ -1,3 +1,3 @@
(function n(r) {
return g(r + 1);
(function n(n) {
return g(n + 1);
})(2);

View File

@ -1,10 +1,10 @@
(function e() {
switch(1){
case 0:
var o = true;
var e = true;
break;
default:
if (typeof o === "undefined") console.log("PASS");
if (typeof e === "undefined") console.log("PASS");
else console.log("FAIL");
}
})();

View File

@ -1,10 +1,10 @@
(function e() {
switch(1){
case 0:
var o = true;
var e = true;
break;
default:
if (typeof o === "undefined") console.log("PASS");
if (typeof e === "undefined") console.log("PASS");
else console.log("FAIL");
}
})();

View File

@ -1,10 +1,10 @@
(function e() {
switch(1){
case 0:
var o = true;
var e = true;
break;
case 1:
if (typeof o === "undefined") console.log("PASS");
if (typeof e === "undefined") console.log("PASS");
else console.log("FAIL");
}
})();

View File

@ -1,10 +1,10 @@
(function e() {
switch(1){
case 0:
var o = true;
var e = true;
break;
case 1:
if (typeof o === "undefined") console.log("PASS");
if (typeof e === "undefined") console.log("PASS");
else console.log("FAIL");
}
})();

View File

@ -1,9 +1,9 @@
var c = "PASS";
(function o(s) {
(function o(o) {
switch(0){
case 0:
case (s = 1):
s && (c = "FAIL");
case (o = 1):
o && (c = "FAIL");
}
})();
console.log(c);

View File

@ -1,7 +1,7 @@
var A = 1;
(function o() {
var n = 2;
console.log(n - 5);
var o = 2;
console.log(o - 5);
console.log(A - 5);
})();
(function f1() {
@ -15,9 +15,9 @@ var A = 1;
eval("console.log(a);");
})(eval);
(function o() {
var n = typeof C !== "undefined";
var e = 4;
if (n) {
var o = typeof C !== "undefined";
var n = 4;
if (o) {
return "yes";
} else {
return "no";

View File

@ -1,3 +1,3 @@
console.log(function long_name(long_name1) {
return typeof long_name1;
console.log(function long_name(long_name) {
return typeof long_name;
}());

View File

@ -1,3 +1,3 @@
console.log((function o(n) {
return typeof n;
console.log((function o(o) {
return typeof o;
})());

View File

@ -896,8 +896,8 @@ function search({search}) {
"#,
r#"
var obj = {
search: function search({ search: search1 }) {
console.log(search1);
search: function search({ search }) {
console.log(search);
}
};

View File

@ -161,13 +161,18 @@ impl Visit for Analyzer {
}
fn visit_fn_expr(&mut self, f: &FnExpr) {
self.with_scope(|v| {
if let Some(id) = &f.ident {
if let Some(id) = &f.ident {
self.with_scope(|v| {
v.add_decl(id.to_id());
}
f.function.visit_with(v);
})
v.with_scope(|v| {
f.function.visit_with(v);
});
})
} else {
self.with_scope(|v| {
f.function.visit_with(v);
})
}
}
fn visit_import_default_specifier(&mut self, n: &ImportDefaultSpecifier) {

View File

@ -3476,7 +3476,7 @@ function A() {
_createClass(A, [{
key: "foo",
value: function foo() {
const foo1 = 2;
const foo = 2;
}
}]);
return A;