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/renamer): Don't use symbols used by declarations if eval exists #7116

Merged
merged 14 commits into from Mar 22, 2023
19 changes: 19 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6871/input/.swcrc
@@ -0,0 +1,19 @@
{
"jsc": {
"parser": {
"syntax": "ecmascript",
"jsx": false
},
"target": "es2015",
"loose": true,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true
}
3 changes: 3 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6871/input/index.js
@@ -0,0 +1,3 @@
async function fromTokenizer() { }
async function _fromTokenizer() { }
eval()
16 changes: 16 additions & 0 deletions crates/swc/tests/fixture/issues-6xxx/6871/output/index.js
@@ -0,0 +1,16 @@
import _async_to_generator from "@swc/helpers/src/_async_to_generator.mjs";
function fromTokenizer() {
return _fromTokenizer1.apply(this, arguments);
}
function _fromTokenizer1() {
_fromTokenizer1 = _async_to_generator(function*() {});
return _fromTokenizer1.apply(this, arguments);
}
function _fromTokenizer() {
return __fromTokenizer.apply(this, arguments);
}
function __fromTokenizer() {
__fromTokenizer = _async_to_generator(function*() {});
return __fromTokenizer.apply(this, arguments);
}
eval();
@@ -1,10 +1,10 @@
!function() {
var CallbackType, Collector = function() {
var n = function(n) {};
return n.usePlugin = function(n, u, l) {}, n.plugins = [], n;
var u = function(u) {};
return u.usePlugin = function(u, l, o) {}, u.plugins = [], u;
}();
!function(n) {
n[n.Var = 0] = "Var", n[n.All = 1] = "All";
!function(u) {
u[u.Var = 0] = "Var", u[u.All = 1] = "All";
}(CallbackType || (CallbackType = {}));
var CepRule = function() {
eval();
Expand Down
Expand Up @@ -15,7 +15,7 @@ push({
}();
},
"App.jsx": function() {
var ShaderChunk = {
var ShaderChunk1 = {
shadowmap_pars_vertex: "",
shadowmap_vertex: "",
shadowmask_pars_fragment: "",
Expand Down Expand Up @@ -47,7 +47,7 @@ push({
meshphong_frag: ""
};
ShaderLib.physical = {
x: ShaderChunk.meshphysical_frag
x: ShaderChunk1.meshphysical_frag
};
}
});
10 changes: 5 additions & 5 deletions crates/swc_ecma_minifier/tests/fixture/next/43052/output.js
@@ -1,6 +1,6 @@
use(function(__unused_webpack_module, exports, __webpack_require__) {
!function(e, t) {
t(exports, __webpack_require__(7294), __webpack_require__(1321));
!function(n, c) {
c(exports, __webpack_require__(7294), __webpack_require__(1321));
}(this, function(exports, React) {
"use strict";
var index_production = {
Expand All @@ -26,7 +26,7 @@ use(function(__unused_webpack_module, exports, __webpack_require__) {
});
});
});
(function e() {
const e = 1;
use(e);
(function n() {
const n = 1;
use(n);
});
30,052 changes: 15,026 additions & 15,026 deletions crates/swc_ecma_minifier/tests/fixture/next/wrap-contracts/output.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions crates/swc_ecma_minifier/tests/full/issues/7094/1/input.js
@@ -0,0 +1,5 @@
export function useSyncExternalStore$2(e, n, t) {
let a = n(); // any variable expect `e`
return a;
}
eval();
@@ -0,0 +1 @@
export function useSyncExternalStore$2(r,o,u){return o()}eval();
19 changes: 19 additions & 0 deletions crates/swc_ecma_minifier/tests/full/issues/7094/2/input.js
@@ -0,0 +1,19 @@

export function foo() {
eval();
return function useSyncExternalStore$2(e, n, t) {
let a = n(); // any variable expect `e`
return a;
}
}

export function bar() {

const shouldBeMangled = Math.random() > 0.5 ? 1 : 2;
console.log(shouldBeMangled)
console.log(shouldBeMangled)
console.log(shouldBeMangled)
console.log(shouldBeMangled)
console.log(shouldBeMangled)
console.log(shouldBeMangled)
}
@@ -0,0 +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)}