feat(es/minifier): Improve compatibility of arrows with terser (#6862)

**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/6123.
This commit is contained in:
Donny/강동윤 2023-01-27 14:36:12 +09:00 committed by GitHub
parent 49d9237e64
commit d1687d8e01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 14 deletions

View File

@ -41,10 +41,6 @@ impl Pure<'_> {
}
pub(super) fn optimize_arrow_body(&mut self, b: &mut BlockStmtOrExpr) {
if !self.options.arrows {
return;
}
match b {
BlockStmtOrExpr::BlockStmt(s) => {
if s.stmts.len() == 1 {

View File

@ -1,6 +1,6 @@
function n(n, e, t, r, o, u, i) {
function n(n, e, t, r, o, i, u) {
try {
var a = n[u](i);
var a = n[i](u);
var c = a.value;
} catch (n) {
t(n);
@ -12,20 +12,19 @@ function n(n, e, t, r, o, u, i) {
function e(e) {
return function() {
var t = this, r = arguments;
return new Promise(function(o, u) {
var i = e.apply(t, r);
return new Promise(function(o, i) {
var u = e.apply(t, r);
function a(e) {
n(i, o, u, a, c, "next", e);
n(u, o, i, a, c, "next", e);
}
function c(e) {
n(i, o, u, a, c, "throw", e);
n(u, o, i, a, c, "throw", e);
}
a(void 0);
});
};
}
export const styleLoader = ()=>{
return {
export const styleLoader = ()=>({
name: 'style-loader',
setup (n) {
n.onLoad({
@ -38,5 +37,4 @@ export const styleLoader = ()=>{
};
}());
}
};
};
});

View File

@ -0,0 +1,6 @@
{
"defaults": false,
"conditionals": true,
"dead_code": true,
"arrows": false
}

View File

@ -0,0 +1,12 @@
const arrow = (param) => {
return Boolean(param);
}
const obj = {
method1() {
return "hello";
},
method2() {
return "goodbye"
}
}

View File

@ -0,0 +1,9 @@
const arrow = (param)=>Boolean(param);
const obj = {
method1 () {
return "hello";
},
method2 () {
return "goodbye";
}
};