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; var _proto = AstPath.prototype;
_proto.clone = function clone() { _proto.clone = function clone() {
var clone1 = new AstPath(); var clone = new AstPath();
clone1.asts = this.asts.map(function(value) { clone.asts = this.asts.map(function(value) {
return value; return value;
}); });
clone1.top = this.top; clone.top = this.top;
return clone1; return clone;
}; };
_proto.pop = function pop() { _proto.pop = function pop() {
var head = this.ast(); var head = this.ast();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -7,7 +7,7 @@ var n = 0;
length: (n = 1 + n) length: (n = 1 + n)
}, },
typeof void (function o() { 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); console.log(n);

View File

@ -7,7 +7,7 @@ var n = 0;
length: (n = 1 + n) length: (n = 1 + n)
}, },
typeof void (function o() { 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); console.log(n);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -161,14 +161,19 @@ impl Visit for Analyzer {
} }
fn visit_fn_expr(&mut self, f: &FnExpr) { 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()); v.add_decl(id.to_id());
} v.with_scope(|v| {
f.function.visit_with(v);
});
})
} else {
self.with_scope(|v| {
f.function.visit_with(v); f.function.visit_with(v);
}) })
} }
}
fn visit_import_default_specifier(&mut self, n: &ImportDefaultSpecifier) { fn visit_import_default_specifier(&mut self, n: &ImportDefaultSpecifier) {
self.add_decl(n.local.to_id()); self.add_decl(n.local.to_id());

View File

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