minifier: Duplicate parameter 'e' not allowed in function with destructuring parameter
yizhiyuyou opened this issue · comments
Describe the bug
use
import swc from '@swc/core';
swc.minify(code, { compress: true, mangle: true });
output code
Run this in Safari (iOS 16.2) throw error: Duplicate parameter 'e' not allowed in function with destructuring parameters
Input code
(function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
let _liteContractCode = null;
async function showPopup({ mallId }) {
try {
console.log({
mallId: mallId,
});
} catch (e) {
console.log(e);
}
}
const liteContractHelper = {
showPopup,
get liteContractCode () {
return _liteContractCode;
}
};
liteContractHelper.showPopup({ mallId: 1 });
})();
Link to the code that reproduces this issue
https://github.com/yizhiyuyou/swc-minify-demo/blob/main/index.mjs
SWC Info output
var __unused_webpack_module,__webpack_exports__,__webpack_require__;({showPopup:async function e({mallId:e}){try{console.log({mallId:e})}catch(e){console.log(e)}},get liteContractCode(){return null}}).showPopup({mallId:1});
Expected behavior
not error
Actual behavior
No response
Version
1.13.5
Additional context
No response
I have also encountered a similar problem
We haven't found a solution yet
Is this a safari-specific issue?
Is this a safari-specific issue?
Yes
Is this a safari-specific issue?
This seems to be the problem.
Both SWC and Babel take this into account when compiling. However, when only minifying, SWC does not seem to take this into account. The function name and the destructuring parameter name are different before minifying, but the function name and the destructuring parameter name are the same after minifying, which leads to this problem.
async function showPopup({ mallId }) {
Same input code, only remove async.
function showPopup({ mallId }) {
output code:
({showPopup:function({mallId:o}){try{console.log({mallId:o})}catch(o){console.log(o)}},get liteContractCode(){return null}}).showPopup({mallId:1});
the compression product is correct.