Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/minifier): Fix a bug about eval of name mangler #7615

Merged
merged 91 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
1b18fe7
Add tests
kdy1 Jul 3, 2023
2f81c1b
Rename
kdy1 Jul 3, 2023
516768f
Rename
kdy1 Jul 3, 2023
64dc794
Reduce
kdy1 Jul 3, 2023
e6a2415
Reduce
kdy1 Jul 3, 2023
6bc8e6e
external helpers
kdy1 Jul 3, 2023
5efcb70
Reduce
kdy1 Jul 3, 2023
25010b1
Reduce
kdy1 Jul 3, 2023
bd91293
beutify
kdy1 Jul 3, 2023
cb420b2
Remove
kdy1 Jul 3, 2023
f00754b
Reduce
kdy1 Jul 3, 2023
30e241a
Reduce
kdy1 Jul 4, 2023
f9df427
Reduce
kdy1 Jul 4, 2023
d91bd8b
Reduce
kdy1 Jul 4, 2023
7a6aa82
Reduce
kdy1 Jul 4, 2023
71bce8a
Reduce
kdy1 Jul 4, 2023
fd812b1
Reduce
kdy1 Jul 4, 2023
c817147
Reduce
kdy1 Jul 4, 2023
cd78787
Reduce
kdy1 Jul 4, 2023
854e879
Reduce
kdy1 Jul 4, 2023
dbe32ae
Reduce
kdy1 Jul 4, 2023
5b9c872
Reduce
kdy1 Jul 4, 2023
2f980d2
Reduce
kdy1 Jul 4, 2023
4d8f220
Reduce
kdy1 Jul 4, 2023
995957a
Reduce
kdy1 Jul 4, 2023
ad17440
Reduce
kdy1 Jul 4, 2023
410c447
Reduce
kdy1 Jul 4, 2023
b5e7309
Reduce
kdy1 Jul 4, 2023
a021b03
Reduce
kdy1 Jul 4, 2023
19f815e
Reduce
kdy1 Jul 4, 2023
5e4a0e0
Reduce
kdy1 Jul 4, 2023
4b6cc50
Reduce
kdy1 Jul 4, 2023
04bebbe
Reduce
kdy1 Jul 4, 2023
b44f637
Reduce
kdy1 Jul 4, 2023
db21bcf
Reduce
kdy1 Jul 4, 2023
d23d1a7
Reduce
kdy1 Jul 4, 2023
c78abd8
Reduce
kdy1 Jul 4, 2023
1d4ed42
Reduce
kdy1 Jul 4, 2023
84a8fd3
Reduce
kdy1 Jul 4, 2023
9038cca
Reduce
kdy1 Jul 4, 2023
f35d300
Reduce
kdy1 Jul 4, 2023
2ae2aa7
Reduce
kdy1 Jul 4, 2023
46da779
Reduce
kdy1 Jul 4, 2023
2db90d4
Reduce
kdy1 Jul 4, 2023
2472fb6
Reduce
kdy1 Jul 4, 2023
3e39c3c
Reduce
kdy1 Jul 4, 2023
4ff4737
Reduce
kdy1 Jul 4, 2023
00c16cb
Reduce
kdy1 Jul 4, 2023
2af30e7
Reduce
kdy1 Jul 4, 2023
2adc820
Reduce
kdy1 Jul 4, 2023
2ee968c
Reduce
kdy1 Jul 4, 2023
b9f14da
Reduce
kdy1 Jul 4, 2023
b8b5d97
Reduce
kdy1 Jul 4, 2023
8968f23
Reduce
kdy1 Jul 4, 2023
d0c6542
Reduce
kdy1 Jul 4, 2023
6e874f7
Reduce
kdy1 Jul 4, 2023
6eefbb2
Reduce
kdy1 Jul 4, 2023
5e045f3
Reduce
kdy1 Jul 4, 2023
ae743e2
Reduce
kdy1 Jul 4, 2023
a349a3e
Reduce
kdy1 Jul 4, 2023
93afb39
Reduce
kdy1 Jul 4, 2023
70679e1
Reduce
kdy1 Jul 5, 2023
b9db788
Reduce
kdy1 Jul 5, 2023
c3fea3b
Reduce
kdy1 Jul 5, 2023
3a6bcda
Reduce
kdy1 Jul 5, 2023
2405813
Reduce
kdy1 Jul 5, 2023
57870cc
Reduce
kdy1 Jul 5, 2023
3f3f92e
Reduce
kdy1 Jul 5, 2023
7fbdc1c
Reduce
kdy1 Jul 5, 2023
6f0b083
Reduce
kdy1 Jul 5, 2023
134e773
Reduce
kdy1 Jul 5, 2023
3901031
Reduce
kdy1 Jul 5, 2023
639a583
Reduce
kdy1 Jul 5, 2023
758b8fc
Reduce
kdy1 Jul 5, 2023
ecd3fe4
Reduce
kdy1 Jul 5, 2023
37ddd16
Reduce
kdy1 Jul 5, 2023
ad3549e
Reduce
kdy1 Jul 5, 2023
3b059de
Reduce
kdy1 Jul 5, 2023
f9c56fb
Reduce
kdy1 Jul 5, 2023
9e9757b
Reduce with config.json
kdy1 Jul 5, 2023
d824927
Disable UPDATE=1
kdy1 Jul 5, 2023
9b00764
Reduce with config.json
kdy1 Jul 5, 2023
45e1866
Reduce with config.json
kdy1 Jul 5, 2023
4d6e6c3
Reduce with config.json
kdy1 Jul 5, 2023
52d8626
Reduce with config.json
kdy1 Jul 5, 2023
92bc544
fix order
kdy1 Jul 5, 2023
d3df78b
Update test refs
kdy1 Jul 5, 2023
a18edd8
Real fix
kdy1 Jul 5, 2023
a0a11c2
What the hell
kdy1 Jul 17, 2023
c481fde
Comment
kdy1 Jul 17, 2023
9e7fdf2
Update test refs
kdy1 Jul 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/swc_ecma_minifier/scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


export DIFF=0
export UPDATE=1
# export UPDATE=1
export SWC_CHECK=0
export SWC_RUN=0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"defaults": true,
"conditionals": false,
"collapse_vars": false,
"properties": false,
"join_vars": false,
"passes": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
(self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test case is too large for me to really understand what's changed, and the diff between this and playground doesn't really help

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added comments for this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I don't know the exact cause of the problem.

[285], {
1973:
(function (module) {
eval(module.code)
}),

1985:
(function (__unused_webpack_module, exports, __webpack_require__) {
"use strict";

var t = 0,
r = e => "checkbox" === e.type;
var u = (e, t) => e.has((e => e.substring(0, e.search(/\.\d+(\.|$)/)) || e)(t)),
d = () => {
};

function H(e, t, r) {
}
var ee = e => "radio" === e.type;

function Me(e = {}) {
let t, n = {
...e
},
y = {},
h = 0,
p = {
},
_ = {
};
const E = 0, $ = async e => {
const r = e.target;
let s = r.name;
const a = 0;
if (a) {
let l, c;
const p = 0;
p ? (a._f.onBlur && a._f.onBlur(e), t && t(0)) : a._f.onChange && a._f.onChange(e);
const A = 0;

a._f.deps && E(s, c, l, A)
}
}, te = (e, t = {}) => {
let s = 0;
const a = 0;
return s ? a && H(h, e, t.disabled ? void 0 : 0) : 0, {
onChange: $,
onBlur: $,
ref: a => {
if (a) {
te(e, t), s = d(y, e);
const n = 0;
(e => ee(e) || r(e))(n),
s._f.refs;
} else s = d(y, e, {}), s._f && (s._f.mount = !1), (n.shouldUnregister || t.shouldUnregister) && (!u(_.array, e) || !p.action) && _.unMount.add(e)
}
}
};

}
exports.useForm = function (e = {}) {
const r = t.default.useRef();
r.current ? r.current.control._options = e : r.current = {
...Me(e),
};

};
}),


}
]);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
(self["webpackChunk_N_E"] = self["webpackChunk_N_E"] || []).push([
[
285
],
{
1973: function(module) {
eval(module.code);
},
1985: function(o, f, i) {
"use strict";
var k = 0, v = (o)=>"checkbox" === o.type;
var b = (o, f)=>{
var i;
return o.has((i = f, i.substring(0, i.search(/\.\d+(\.|$)/)) || i));
}, g = ()=>{};
function C(o, f, i) {}
var m = (o)=>"radio" === o.type;
function w(o = {}) {
let f, i = {
...o
}, k = {}, v = 0, b = {}, g = {};
const C = 0, m = async (o)=>{
const i = o.target;
let k = i.name;
const v = 0;
if (v) {
let i, b;
const g = 0;
g ? (v._f.onBlur && v._f.onBlur(o), f && f(0)) : v._f.onChange && v._f.onChange(o);
const m = 0;
v._f.deps && C(k, b, i, m);
}
};
}
f.useForm = function(o = {}) {
const f = k.default.useRef();
f.current ? f.current.control._options = o : f.current = {
...w(o)
};
};
}
}
]);
39 changes: 28 additions & 11 deletions crates/swc_ecma_transforms_base/src/rename/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,34 @@ where

self.unresolved = self.get_unresolved(m, has_eval);

{
let map = self.get_map(m, false, true, has_eval);

m.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
}

let map = self.get_map(m, false, true, has_eval);

// If we have eval, we cannot rename a whole program at once.
//
// Still, we can, and should rename some identifiers, if the containing scope
// (function-like nodes) does not have eval. This `eval` check includes
// `eval` in children.
//
// We calculate the top level map first, rename children, and then rename the
// top level.
//
//
// Order:
//
// 1. Top level map calculation
// 2. Per-unit map calculation
// 3. Per-unit renaming
// 4. Top level renaming
//
// This is because the the top level map may contain a mapping which conflicts
// with a map from one of the children.
//
// See https://github.com/swc-project/swc/pull/7615
if has_eval {
m.visit_mut_children_with(self);
}

m.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
}

fn visit_mut_script(&mut self, m: &mut Script) {
Expand All @@ -261,15 +280,13 @@ where

self.unresolved = self.get_unresolved(m, has_eval);

{
let map = self.get_map(m, false, true, has_eval);

m.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
}
let map = self.get_map(m, false, true, has_eval);

if has_eval {
m.visit_mut_children_with(self);
}

m.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
}
}

Expand Down