Skip to content

Commit 0bfcb2d

Browse files
authored
Fix css embed in JSX when using (only) a spread attribute (#15896)
1 parent 12ab548 commit 0bfcb2d

5 files changed

Lines changed: 27 additions & 1 deletion

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#### Fix crash when parsing template literal CSS in a JSX style tag using a spread attribute (#15896 by @eelco)
2+
3+
For example this code would crash before:
4+
5+
<!-- prettier-ignore -->
6+
```jsx
7+
<style {...spread}>{`.{}`}</style>
8+
```

src/language-js/embed/css.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ function isStyledJsx({ node, parent, grandparent }) {
7575
grandparent.type === "JSXElement" &&
7676
grandparent.openingElement.name.name === "style" &&
7777
grandparent.openingElement.attributes.some(
78-
(attribute) => attribute.name.name === "jsx",
78+
(attribute) =>
79+
attribute.type === "JSXAttribute" && attribute.name.name === "jsx",
7980
)) ||
8081
(parent?.type === "TaggedTemplateExpression" &&
8182
parent.tag.type === "Identifier" &&
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`css-embed.js format 1`] = `
4+
====================================options=====================================
5+
parsers: ["flow", "babel"]
6+
printWidth: 80
7+
| printWidth
8+
=====================================input======================================
9+
<style {...spread}>{\`.{}\`}</style>;
10+
11+
=====================================output=====================================
12+
<style {...spread}>{\`.{}\`}</style>;
13+
14+
================================================================================
15+
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<style {...spread}>{`.{}`}</style>;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
run_spec(import.meta, ["flow", "babel"]);

0 commit comments

Comments
 (0)