Skip to content

Commit

Permalink
fix(es/compat): Preserve comment for arrow body (#8427)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8419
  • Loading branch information
Austaras committed Dec 17, 2023
1 parent 45f62f7 commit 56992e3
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
22 changes: 22 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8419/input/.swcrc
@@ -0,0 +1,22 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"transform": {
"react": {
"runtime": "automatic",
"refresh": true,
"importSource": "@emotion/react"
}
},
"target": "es2015",
"loose": true
},
"isModule": true,
"module": {
"type": "es6"
},
"minify": false
}
9 changes: 9 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8419/input/index.js
@@ -0,0 +1,9 @@
export const SearchLayoutRoot = ({
children,
sx,
...others
}: SearchLayoutRootProps) => (
<Box sx={[styles, ...packSX(sx)]} {...others}>
{children}
</Box>
);
17 changes: 17 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8419/output/index.js
@@ -0,0 +1,17 @@
import { _ as _extends } from "@swc/helpers/_/_extends";
import { _ as _object_without_properties_loose } from "@swc/helpers/_/_object_without_properties_loose";
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
export const SearchLayoutRoot = (_param)=>{
var { children, sx } = _param, others = _object_without_properties_loose(_param, [
"children",
"sx"
]);
return /*#__PURE__*/ _jsx(Box, _extends({
sx: [
styles,
...packSX(sx)
]
}, others, {
children: children
}));
};
Expand Up @@ -39,11 +39,11 @@ export default function Home() {
lineNumber: 15,
columnNumber: 17
}, this),
icon.map(function(_param) /*#__PURE__*/ {
icon.map(function(_param) {
var href = _param.href, linkProps = _object_without_properties(_param, [
"href"
]);
return _createElement("link", _object_spread_props(_object_spread({
return /*#__PURE__*/ _createElement("link", _object_spread_props(_object_spread({
href: href
}, linkProps), {
rel: "icon",
Expand Down
Expand Up @@ -48,11 +48,11 @@ export default function Home() {
columnNumber: 17
},
__self: this
}), icon.map(function(_param) /*#__PURE__*/ {
}), icon.map(function(_param) {
var href = _param.href, linkProps = _object_without_properties(_param, [
"href"
]);
return React.createElement("link", _object_spread_props(_object_spread({
return /*#__PURE__*/ React.createElement("link", _object_spread_props(_object_spread({
href: href
}, linkProps), {
rel: "icon",
Expand Down
3 changes: 1 addition & 2 deletions crates/swc_ecma_compat_common/src/macros.rs
Expand Up @@ -24,7 +24,6 @@ macro_rules! impl_visit_mut_fn {
BlockStmtOrExpr::Expr(..) => true,
_ => false,
};
let body_span = f.body.span();
let (params, mut body) = self.visit_mut_fn_like(
&mut f
.params
Expand All @@ -39,7 +38,7 @@ macro_rules! impl_visit_mut_fn {
&mut match &mut *f.body {
BlockStmtOrExpr::BlockStmt(block) => block.take(),
BlockStmtOrExpr::Expr(expr) => BlockStmt {
span: body_span,
span: DUMMY_SP,
stmts: vec![Stmt::Return(ReturnStmt {
span: DUMMY_SP,
arg: Some(expr.take()),
Expand Down

0 comments on commit 56992e3

Please sign in to comment.