-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(es/react): Make jsx with single spread child static (#8339)
**Description:** Example: ```js <h1>{...a}</h1> ``` Before: ```js _jsx("h1", { children: [ ...a ] }) ``` After: ```js _jsxs("h1", { children: [ ...a ] }) ``` Following the implementation in [Typescript](https://github.com/microsoft/TypeScript/blob/d4fbc9b57d9aa7d02faac9b1e9bb7b37c687f6e9/src/compiler/transformers/jsx.ts#L340), jsx with a single spread child should also be considered as static jsx. Live examples: [Typescript](https://www.typescriptlang.org/play?target=99&jsx=4#code/MYewdgzgLgBAhjAvDAPACwIwD4DeA6AgbQwCYBmAXQF8UB6TLAKCA) [Esbuild](https://esbuild.github.io/try/#dAAwLjE5LjcAewogIGxvYWRlcjogJ2pzeCcsCiAganN4OiAnYXV0b21hdGljJywKfQA8ZGl2PnsuLi5bXX08L2Rpdj4) [SWC](https://play.swc.rs/?version=1.3.100-nightly-20231124.1&code=H4sIAAAAAAAAA0vOzysuUUhUsFWwSckss6vW09OLjq210QdxAHOBudocAAAA&config=H4sIAAAAAAAAA1WOMQrDMAxF95zCaO5QPPY2wijFIbaDJENL8N0rO2lJN%2F33kPT3yTlYJMDD7TZa2JCF%2BJeNyDsrvowAhYQSOG4Kt69dpCvlSoO0Q8BaipCJGVehkyljlrlwul5nwqAX0FHNGlPfBqxaEmoMcOr290WRn6Sjmvi796NWm9oHTYlQ69cAAAA%3D)
- Loading branch information
Showing
4 changed files
with
34 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...ecma_transforms_react/tests/jsx/fixture/react-automatic/should-detect-static-jsx/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const h1 = <h1></h1> | ||
const h2 = <h2>{}</h2> | ||
const h3 = <h3>{a}</h3> | ||
const h4 = <h4>{a}b</h4> | ||
const h5 = <h5>{...a}</h5> |
17 changes: 17 additions & 0 deletions
17
...ma_transforms_react/tests/jsx/fixture/react-automatic/should-detect-static-jsx/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; | ||
const h1 = /*#__PURE__*/ _jsx("h1", {}); | ||
const h2 = /*#__PURE__*/ _jsx("h2", {}); | ||
const h3 = /*#__PURE__*/ _jsx("h3", { | ||
children: a | ||
}); | ||
const h4 = /*#__PURE__*/ _jsxs("h4", { | ||
children: [ | ||
a, | ||
"b" | ||
] | ||
}); | ||
const h5 = /*#__PURE__*/ _jsxs("h5", { | ||
children: [ | ||
...a | ||
] | ||
}); |
4 changes: 2 additions & 2 deletions
4
...sforms_react/tests/jsx/fixture/react-automatic/should-disallow-spread-children/output.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters