Skip to content

Commit

Permalink
fix(es/compat): Use dummy span for blocks in parameters (#8202)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8199
  • Loading branch information
kdy1 committed Nov 1, 2023
1 parent d4e21fc commit c1b255a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
26 changes: 26 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8199/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true
},
"externalHelpers": true,
"transform": {
"react": {
"runtime": "automatic"
}
},
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"minify": false,
"module": {
"type": "es6"
},
"env": {
"targets": "safari>15"
}
}
2 changes: 2 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8199/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const IconSpecHotkey = ({ icon }) =>
<div>{icon}</div>
7 changes: 7 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8199/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { jsx as _jsx } from "react/jsx-runtime";
export const IconSpecHotkey = (param)=>{
let { icon } = param;
return /*#__PURE__*/ _jsx("div", {
children: icon
});
};
5 changes: 2 additions & 3 deletions crates/swc_ecma_compat_es2015/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl Params {
arg: Box::new(idx_ident.clone().into()),
}))),
body: Box::new(Stmt::Block(BlockStmt {
span,
span: DUMMY_SP,
stmts: vec![{
let prop = Box::new(Expr::Ident(idx_ident.clone()));
// a1[_key - i] = arguments[_key];
Expand Down Expand Up @@ -582,7 +582,6 @@ impl VisitMut for Params {
}
}

let body_span = f.body.span();
let mut params = f
.params
.take()
Expand All @@ -597,7 +596,7 @@ impl VisitMut for Params {
let mut body = match *f.body.take() {
BlockStmtOrExpr::BlockStmt(block) => block,
BlockStmtOrExpr::Expr(expr) => BlockStmt {
span: body_span,
span: DUMMY_SP,
stmts: vec![Stmt::Return(ReturnStmt {
span: DUMMY_SP,
arg: Some(expr),
Expand Down

0 comments on commit c1b255a

Please sign in to comment.