Skip to content

Commit 8c118b1

Browse files
committed
Transform recma when using jsx dev runtime
1 parent a4b2ee9 commit 8c118b1

17 files changed

+5477
-7
lines changed

packages/codehike/src/mdx/3.transform-hike-props.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function forEachHikeElementMoveChildrenToHikeProp(root: any, jsxOn: boolean) {
137137
visit(root, (node: any) => {
138138
if (isElementWithHikeAttribute(node, jsxOn)) {
139139
if (jsxOn) {
140-
moveChildrenToHikePropJSX(node, jsxOn)
140+
moveChildrenToHikePropJSX(node)
141141
} else {
142142
moveChildrenToHikeProp(node)
143143
}
@@ -157,7 +157,7 @@ function isElementWithHikeAttribute(node: any, jsxOn: boolean) {
157157
)
158158
}
159159

160-
function moveChildrenToHikePropJSX(node: any, jsxOn: boolean) {
160+
function moveChildrenToHikePropJSX(node: any) {
161161
// dictionary of children by path
162162
const childrenByPath: any = {}
163163
node.children.forEach((slot: any) => {
@@ -252,8 +252,8 @@ function moveChildrenToHikeProp(node: any) {
252252
(p: any) => p.key.name !== "children",
253253
)
254254

255-
// jsxs calls can only have arrays as children, so we turn any jsxs without array into jsx call
256255
visit(node, function (node: any) {
256+
// jsxs calls can only have arrays as children, so we turn any jsxs without array into jsx call
257257
if (node.type === "CallExpression" && node.callee.name === "_jsxs") {
258258
const childrenProp = node.arguments[1].properties.find(
259259
(p: any) => p.key.value === "children",
@@ -262,6 +262,16 @@ function moveChildrenToHikeProp(node: any) {
262262
node.callee.name = "_jsx"
263263
}
264264
}
265+
266+
// same, but in dev mode the name is _jsxDEV, and we should change the `isStaticChildren` argument
267+
if (node.type === "CallExpression" && node.callee.name === "_jsxDEV") {
268+
const childrenProp = node.arguments[1].properties.find(
269+
(p: any) => p.key.value === "children",
270+
)
271+
if (childrenProp && childrenProp.value.type !== "ArrayExpression") {
272+
node.arguments[3] = { type: "Literal", value: false }
273+
}
274+
}
265275
})
266276
}
267277

packages/codehike/tests/md-suite/basic.0.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ snapshots:
77
- before-recma-compiled-jsx
88
- before-recma-compiled-function
99
- before-recma-js
10+
- before-recma-js-dev
1011
- before-recma-jsx
1112
- after-recma-js
13+
- after-recma-js-dev
1214
- after-recma-jsx
1315
- compiled-js
16+
- compiled-js-dev
1417
- compiled-jsx
1518
- compiled-function
1619
- parsed-jsx
1720
- rendered
21+
- rendered-dev
1822
---
1923

2024
# Lorem

0 commit comments

Comments
 (0)