mirror of
https://github.com/swc-project/swc.git
synced 2024-11-25 22:34:04 +03:00
fix(es/minifier): Avoid decl name when mangle with eval (#9546)
Some checks failed
CI / Cargo fmt (push) Has been cancelled
CI / Cargo clippy (push) Has been cancelled
CI / Check license of dependencies (push) Has been cancelled
CI / Check (macos-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / Test wasm (binding_core_wasm) (push) Has been cancelled
CI / Test wasm (binding_minifier_wasm) (push) Has been cancelled
CI / Test wasm (binding_typescript_wasm) (push) Has been cancelled
CI / List crates (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Has been cancelled
CI / Test with @swc/cli (push) Has been cancelled
CI / Miri (better_scoped_tls) (push) Has been cancelled
CI / Miri (string_enum) (push) Has been cancelled
CI / Miri (swc) (push) Has been cancelled
CI / Miri (swc_bundler) (push) Has been cancelled
CI / Miri (swc_ecma_codegen) (push) Has been cancelled
CI / Miri (swc_ecma_minifier) (push) Has been cancelled
Benchmark / Bench everything (push) Has been cancelled
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Has been cancelled
CI / Done (push) Has been cancelled
Some checks failed
CI / Cargo fmt (push) Has been cancelled
CI / Cargo clippy (push) Has been cancelled
CI / Check license of dependencies (push) Has been cancelled
CI / Check (macos-latest) (push) Has been cancelled
CI / Check (ubuntu-latest) (push) Has been cancelled
CI / Check (windows-latest) (push) Has been cancelled
CI / Test wasm (binding_core_wasm) (push) Has been cancelled
CI / Test wasm (binding_minifier_wasm) (push) Has been cancelled
CI / Test wasm (binding_typescript_wasm) (push) Has been cancelled
CI / List crates (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (macos-latest) (push) Has been cancelled
CI / Test node bindings - ${{ matrix.os }} (windows-latest) (push) Has been cancelled
CI / Test with @swc/cli (push) Has been cancelled
CI / Miri (better_scoped_tls) (push) Has been cancelled
CI / Miri (string_enum) (push) Has been cancelled
CI / Miri (swc) (push) Has been cancelled
CI / Miri (swc_bundler) (push) Has been cancelled
CI / Miri (swc_ecma_codegen) (push) Has been cancelled
CI / Miri (swc_ecma_minifier) (push) Has been cancelled
Benchmark / Bench everything (push) Has been cancelled
CI / Test - ${{ matrix.settings.crate }} - ${{ matrix.settings.os }} (push) Has been cancelled
CI / Done (push) Has been cancelled
**Related issue:** - Closes https://github.com/swc-project/swc/issues/9542
This commit is contained in:
parent
48bb8f4277
commit
e2242c41c4
6
.changeset/warm-lies-work.md
Normal file
6
.changeset/warm-lies-work.md
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
swc_core: patch
|
||||
swc_ecma_minifier: patch
|
||||
---
|
||||
|
||||
fix(es/minifier): Avoid decl name when mangle with eval
|
@ -3,7 +3,7 @@ function _templateObject() {
|
||||
var data = _tagged_template_literal([
|
||||
"\n position: absolute;\n"
|
||||
]);
|
||||
_templateObject = function _templateObject() {
|
||||
_templateObject = function _templateObject1() {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
@ -12,7 +12,7 @@ function _templateObject1() {
|
||||
var data = _tagged_template_literal([
|
||||
"\n position: absolute;\n"
|
||||
]);
|
||||
_templateObject1 = function _templateObject() {
|
||||
_templateObject1 = function _templateObject1() {
|
||||
return data;
|
||||
};
|
||||
return data;
|
||||
|
16
crates/swc_ecma_minifier/tests/mangle/issue-9542/input.js
Normal file
16
crates/swc_ecma_minifier/tests/mangle/issue-9542/input.js
Normal file
@ -0,0 +1,16 @@
|
||||
function test() {
|
||||
(function (module) {
|
||||
function FormatSendData(data) {}
|
||||
eval();
|
||||
})();
|
||||
|
||||
function n(i) {
|
||||
var r1 = t[i];
|
||||
if (void 0 !== r1) return r1.exports;
|
||||
var o1 = (t[i] = {
|
||||
exports: {},
|
||||
});
|
||||
return e[i](o1, o1.exports, n), o1.exports;
|
||||
}
|
||||
}
|
||||
test();
|
15
crates/swc_ecma_minifier/tests/mangle/issue-9542/output.js
Normal file
15
crates/swc_ecma_minifier/tests/mangle/issue-9542/output.js
Normal file
@ -0,0 +1,15 @@
|
||||
function test() {
|
||||
(function(module) {
|
||||
function FormatSendData(n) {}
|
||||
eval();
|
||||
})();
|
||||
function n(r) {
|
||||
var o = t[r];
|
||||
if (void 0 !== o) return o.exports;
|
||||
var i = (t[r] = {
|
||||
exports: {}
|
||||
});
|
||||
return e[r](i, i.exports, n), i.exports;
|
||||
}
|
||||
}
|
||||
test();
|
@ -282,9 +282,41 @@ where
|
||||
|
||||
unit!(visit_mut_private_method, PrivateMethod);
|
||||
|
||||
unit!(visit_mut_fn_decl, FnDecl, true);
|
||||
fn visit_mut_fn_decl(&mut self, n: &mut FnDecl) {
|
||||
if !self.config.ignore_eval && contains_eval(n, true) {
|
||||
n.visit_mut_children_with(self);
|
||||
} else {
|
||||
let id = n.ident.to_id();
|
||||
let inserted = self.preserved.insert(id.clone());
|
||||
let map = self.get_map(n, true, false, false);
|
||||
|
||||
unit!(visit_mut_class_decl, ClassDecl, true);
|
||||
if inserted {
|
||||
self.preserved.remove(&id);
|
||||
}
|
||||
|
||||
if !map.is_empty() {
|
||||
n.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_class_decl(&mut self, n: &mut ClassDecl) {
|
||||
if !self.config.ignore_eval && contains_eval(n, true) {
|
||||
n.visit_mut_children_with(self);
|
||||
} else {
|
||||
let id = n.ident.to_id();
|
||||
let inserted = self.preserved.insert(id.clone());
|
||||
let map = self.get_map(n, true, false, false);
|
||||
|
||||
if inserted {
|
||||
self.preserved.remove(&id);
|
||||
}
|
||||
|
||||
if !map.is_empty() {
|
||||
n.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_default_decl(&mut self, n: &mut DefaultDecl) {
|
||||
match n {
|
||||
|
Loading…
Reference in New Issue
Block a user