mirror of
https://github.com/swc-project/swc.git
synced 2024-11-27 13:38:33 +03:00
fix(es/renamer): Correctly check top level (#8456)
**Related issue:** - Closes #8451. - Closes #8185.
This commit is contained in:
parent
c39e75c61d
commit
1e44e57a09
19
crates/swc/tests/fixture/issues-8xxx/8185/input/.swcrc
Normal file
19
crates/swc/tests/fixture/issues-8xxx/8185/input/.swcrc
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"tsx": false
|
||||
},
|
||||
"target": "es5",
|
||||
"loose": false,
|
||||
"minify": {
|
||||
"compress": false,
|
||||
"mangle": false
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "es6"
|
||||
},
|
||||
"minify": false,
|
||||
"isModule": true
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
const a = () => {
|
||||
const _define_property = 1;
|
||||
const fn = () => console.log({ [prop]: 'test' });
|
||||
};
|
||||
|
||||
const b = () => eval('console.log()');
|
5
crates/swc/tests/fixture/issues-8xxx/8185/input/input.js
Normal file
5
crates/swc/tests/fixture/issues-8xxx/8185/input/input.js
Normal file
@ -0,0 +1,5 @@
|
||||
(function hello() {
|
||||
console.log('outer stack', new Error().stack)
|
||||
})();
|
||||
|
||||
eval("")
|
10
crates/swc/tests/fixture/issues-8xxx/8185/output/helper.js
Normal file
10
crates/swc/tests/fixture/issues-8xxx/8185/output/helper.js
Normal file
@ -0,0 +1,10 @@
|
||||
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
||||
var a = function() {
|
||||
var _define_property1 = 1;
|
||||
var fn = function() {
|
||||
return console.log(_define_property({}, prop, "test"));
|
||||
};
|
||||
};
|
||||
var b = function() {
|
||||
return eval("console.log()");
|
||||
};
|
@ -0,0 +1,4 @@
|
||||
(function hello() {
|
||||
console.log("outer stack", new Error().stack);
|
||||
})();
|
||||
eval("");
|
@ -1,10 +1,10 @@
|
||||
!function() {
|
||||
var CallbackType, Collector = function() {
|
||||
var u = function(u) {};
|
||||
return u.usePlugin = function(u, l, o) {}, u.plugins = [], u;
|
||||
var n = function(n) {};
|
||||
return n.usePlugin = function(n, u, l) {}, n.plugins = [], n;
|
||||
}();
|
||||
!function(u) {
|
||||
u[u.Var = 0] = "Var", u[u.All = 1] = "All";
|
||||
!function(n) {
|
||||
n[n.Var = 0] = "Var", n[n.All = 1] = "All";
|
||||
}(CallbackType || (CallbackType = {}));
|
||||
var CepRule = function() {
|
||||
eval();
|
||||
|
@ -1,6 +1,6 @@
|
||||
use(function(__unused_webpack_module, exports, __webpack_require__) {
|
||||
!function(n, c) {
|
||||
c(exports, __webpack_require__(7294), __webpack_require__(1321));
|
||||
!function(e, t) {
|
||||
t(exports, __webpack_require__(7294), __webpack_require__(1321));
|
||||
}(this, function(exports, React) {
|
||||
"use strict";
|
||||
var index_production = {
|
||||
@ -26,7 +26,7 @@ use(function(__unused_webpack_module, exports, __webpack_require__) {
|
||||
});
|
||||
});
|
||||
});
|
||||
(function n() {
|
||||
const n = 1;
|
||||
use(n);
|
||||
(function e() {
|
||||
const e = 1;
|
||||
use(e);
|
||||
});
|
||||
|
@ -6,28 +6,28 @@
|
||||
1973: function(module) {
|
||||
eval(module.code);
|
||||
},
|
||||
1985: function(c, o, f) {
|
||||
1985: function(n, t, e) {
|
||||
"use strict";
|
||||
var i = 0, l = (c)=>"checkbox" === c.type;
|
||||
var k = (c, o)=>{
|
||||
var f;
|
||||
return c.has((f = o).substring(0, f.search(/\.\d+(\.|$)/)) || f);
|
||||
}, v = ()=>{};
|
||||
function b(c, o, f) {}
|
||||
var g = (c)=>"radio" === c.type;
|
||||
function m(c = {}) {
|
||||
let o, f = {
|
||||
...c
|
||||
}, i = {}, l = 0, k = {}, v = {};
|
||||
const b = 0, g = async (c)=>{
|
||||
let o = c.target.name;
|
||||
const f = 0;
|
||||
var c = 0, r = (n)=>"checkbox" === n.type;
|
||||
var u = (n, t)=>{
|
||||
var e;
|
||||
return n.has((e = t).substring(0, e.search(/\.\d+(\.|$)/)) || e);
|
||||
}, o = ()=>{};
|
||||
function s(n, t, e) {}
|
||||
var a = (n)=>"radio" === n.type;
|
||||
function f(n = {}) {
|
||||
let t, e = {
|
||||
...n
|
||||
}, c = {}, r = 0, u = {}, o = {};
|
||||
const s = 0, a = async (n)=>{
|
||||
let t = n.target.name;
|
||||
const e = 0;
|
||||
};
|
||||
}
|
||||
o.useForm = function(c = {}) {
|
||||
const o = i.default.useRef();
|
||||
o.current ? o.current.control._options = c : o.current = {
|
||||
...m(c)
|
||||
t.useForm = function(n = {}) {
|
||||
const t = c.default.useRef();
|
||||
t.current ? t.current.control._options = n : t.current = {
|
||||
...f(n)
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
export function useSyncExternalStore$2(r,o,u){return o()}eval();
|
||||
export function useSyncExternalStore$2(e,n,r){return n()}eval();
|
||||
|
@ -1 +1 @@
|
||||
export function foo(){return eval(),function(o,l,c){return l()}}export function bar(){const o=Math.random()>.5?1:2;console.log(o),console.log(o),console.log(o),console.log(o),console.log(o),console.log(o)}
|
||||
export function foo(){return eval(),function(o,n,l){return n()}}export function bar(){const o=Math.random()>.5?1:2;console.log(o),console.log(o),console.log(o),console.log(o),console.log(o),console.log(o)}
|
||||
|
@ -9,8 +9,8 @@ function f1() {
|
||||
eval(x, y, z, e);
|
||||
}
|
||||
function p1() {
|
||||
var o = foo(), r = bar(), eval = baz();
|
||||
return o + r + eval;
|
||||
var a = foo(), o = bar(), eval = baz();
|
||||
return a + o + eval;
|
||||
}
|
||||
function p2() {
|
||||
var a = foo(), b = bar(), eval = baz;
|
||||
|
@ -1,4 +1,4 @@
|
||||
function f1(n, eval, r, t, u) {
|
||||
function f1(n, eval, c, r, t) {
|
||||
return n("c") + eval;
|
||||
}
|
||||
function f2(a, b, c, d, e) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
function f1(n, eval, r, t, u) {
|
||||
function f1(n, eval, c, r, t) {
|
||||
return n("c") + eval;
|
||||
}
|
||||
function f2(a, b, c, d, e) {
|
||||
|
@ -51,7 +51,7 @@ where
|
||||
is_pat_decl: bool,
|
||||
|
||||
/// [None] if there's no `eval`.
|
||||
pub top_level_mark_for_eval: Option<Mark>,
|
||||
pub top_level_for_eval: Option<SyntaxContext>,
|
||||
}
|
||||
|
||||
impl<I> CustomBindingCollector<I>
|
||||
@ -59,8 +59,8 @@ where
|
||||
I: IdentLike + Eq + Hash + Send + Sync,
|
||||
{
|
||||
fn add(&mut self, i: &Ident) {
|
||||
if let Some(top_level_mark) = self.top_level_mark_for_eval {
|
||||
if i.span.ctxt.outer().is_descendant_of(top_level_mark) {
|
||||
if let Some(top_level_ctxt) = self.top_level_for_eval {
|
||||
if i.span.ctxt == top_level_ctxt {
|
||||
self.preserved.insert(I::from_ident(i));
|
||||
return;
|
||||
}
|
||||
@ -201,7 +201,7 @@ where
|
||||
bindings: Default::default(),
|
||||
preserved: Default::default(),
|
||||
is_pat_decl: false,
|
||||
top_level_mark_for_eval,
|
||||
top_level_for_eval: top_level_mark_for_eval.map(|m| SyntaxContext::empty().apply_mark(m)),
|
||||
};
|
||||
n.visit_with(&mut v);
|
||||
(v.bindings, v.preserved)
|
||||
|
Loading…
Reference in New Issue
Block a user