Skip to content

Commit

Permalink
fix(es/fixer): Wrap object tagged templates (#9991)
Browse files Browse the repository at this point in the history
**Related issue:**

- Closes: #9930
  • Loading branch information
magic-akari authored Feb 5, 2025
1 parent 3ca23ec commit 963c3a5
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changeset/twenty-elephants-peel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
swc_core: patch
swc_ecma_transforms_base: patch
---

fix(es/fixer): Wrap object tagged templates
8 changes: 8 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9930/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"jsc": {
"target": "es2022",
"parser": {
"syntax": "ecmascript"
}
}
}
7 changes: 7 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9930/input/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
try {
( { 0 : 0 } ``);
} catch {}

try {
1 + { 0 : 0 } ``;
} catch {}
10 changes: 10 additions & 0 deletions crates/swc/tests/fixture/issues-9xxx/9930/output/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try {
({
0: 0
})``;
} catch {}
try {
1 + {
0: 0
}``;
} catch {}
3 changes: 3 additions & 0 deletions crates/swc_ecma_transforms_base/src/fixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,9 @@ impl VisitMut for Fixer<'_> {
e.visit_mut_children_with(self);

match &*e.tag {
Expr::Object(..) if self.ctx == Context::Default => {
self.wrap(&mut e.tag);
}
Expr::OptChain(..)
| Expr::Arrow(..)
| Expr::Cond(..)
Expand Down

0 comments on commit 963c3a5

Please sign in to comment.