mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
feat(es/minifier): Support PURE
comment of seq exprs (#7245)
**Related issue:** - Closes https://github.com/swc-project/swc/issues/7241.
This commit is contained in:
parent
a0e193d177
commit
559d1202bc
18
crates/swc/tests/fixture/issues-7xxx/7241/input/.swcrc
Normal file
18
crates/swc/tests/fixture/issues-7xxx/7241/input/.swcrc
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript",
|
||||
"jsx": false
|
||||
},
|
||||
"target": "es2022",
|
||||
"loose": false,
|
||||
"minify": {
|
||||
"compress": true,
|
||||
"mangle": true
|
||||
}
|
||||
},
|
||||
"module": {
|
||||
"type": "es6"
|
||||
},
|
||||
"isModule": true
|
||||
}
|
18
crates/swc/tests/fixture/issues-7xxx/7241/input/index.js
Normal file
18
crates/swc/tests/fixture/issues-7xxx/7241/input/index.js
Normal file
@ -0,0 +1,18 @@
|
||||
(function () {
|
||||
function forwardRef() {
|
||||
return something();
|
||||
}
|
||||
|
||||
function Test() {
|
||||
return 'Test';
|
||||
}
|
||||
const _Test = /*#__PURE__*/ (0, forwardRef)(Test);
|
||||
function Other() {
|
||||
return 'Other';
|
||||
}
|
||||
const _Other = /*#__PURE__*/ (0, forwardRef)(Other);
|
||||
|
||||
|
||||
console.log((0, _Test));
|
||||
|
||||
})();
|
@ -0,0 +1,4 @@
|
||||
!function() {
|
||||
let o = something();
|
||||
console.log(o);
|
||||
}();
|
@ -132,7 +132,17 @@ impl VisitMut for InfoMarker<'_> {
|
||||
n.span = n.span.apply_mark(self.marks.noinline);
|
||||
}
|
||||
|
||||
if self.has_pure(n.span) {
|
||||
// We check callee in some cases because we move comments
|
||||
// See https://github.com/swc-project/swc/issues/7241
|
||||
if self.has_pure(n.span)
|
||||
|| match &n.callee {
|
||||
Callee::Expr(e) => match &**e {
|
||||
Expr::Seq(callee) => self.has_pure(callee.span),
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
}
|
||||
{
|
||||
n.span = n.span.apply_mark(self.marks.pure);
|
||||
} else if let Some(pure_fns) = &self.pure_funcs {
|
||||
if let Callee::Expr(e) = &n.callee {
|
||||
@ -146,14 +156,6 @@ impl VisitMut for InfoMarker<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_new_expr(&mut self, n: &mut NewExpr) {
|
||||
n.visit_mut_children_with(self);
|
||||
|
||||
if self.has_pure(n.span) {
|
||||
n.span = n.span.apply_mark(self.marks.pure);
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_export_default_decl(&mut self, e: &mut ExportDefaultDecl) {
|
||||
self.state.is_in_export = true;
|
||||
e.visit_mut_children_with(self);
|
||||
@ -199,7 +201,7 @@ impl VisitMut for InfoMarker<'_> {
|
||||
|
||||
fn visit_mut_lit(&mut self, _: &mut Lit) {}
|
||||
|
||||
fn visit_mut_script(&mut self, n: &mut Script) {
|
||||
fn visit_mut_module(&mut self, n: &mut Module) {
|
||||
n.visit_mut_children_with(self);
|
||||
|
||||
if self.state.is_bundle {
|
||||
@ -210,7 +212,15 @@ impl VisitMut for InfoMarker<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_module(&mut self, n: &mut Module) {
|
||||
fn visit_mut_new_expr(&mut self, n: &mut NewExpr) {
|
||||
n.visit_mut_children_with(self);
|
||||
|
||||
if self.has_pure(n.span) {
|
||||
n.span = n.span.apply_mark(self.marks.pure);
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_mut_script(&mut self, n: &mut Script) {
|
||||
n.visit_mut_children_with(self);
|
||||
|
||||
if self.state.is_bundle {
|
||||
|
18
crates/swc_ecma_minifier/tests/fixture/issues/7241/input.js
Normal file
18
crates/swc_ecma_minifier/tests/fixture/issues/7241/input.js
Normal file
@ -0,0 +1,18 @@
|
||||
(function () {
|
||||
function forwardRef() {
|
||||
return something();
|
||||
}
|
||||
|
||||
function Test() {
|
||||
return 'Test';
|
||||
}
|
||||
const _Test = /*#__PURE__*/ (0, forwardRef)(Test);
|
||||
function Other() {
|
||||
return 'Other';
|
||||
}
|
||||
const _Other = /*#__PURE__*/ (0, forwardRef)(Other);
|
||||
|
||||
|
||||
console.log((0, _Test));
|
||||
|
||||
})();
|
@ -0,0 +1,4 @@
|
||||
!function() {
|
||||
const _Test = something();
|
||||
console.log(_Test);
|
||||
}();
|
Loading…
Reference in New Issue
Block a user