Skip to content
Prev Previous commit
Next Next commit
Fix type-coverage issues
  • Loading branch information
remcohaszing committed Mar 1, 2024
commit 79ad7d1d173afd0c284faeedfd44806cc09fcff1
8 changes: 6 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,9 @@ function productionCreate(_, jsx, jsxs) {
/** @type {Create<JsxFunction>} */
function create(_, type, props, key) {
// Only an array when there are 2 or more children.
const isStaticChildren = Array.isArray(props.children)
const isStaticChildren = Array.isArray(
/** @type {Record<String, unknown>} */ (props).children
)
const fn = isStaticChildren ? jsxs : jsx
return key ? fn(type, props, key) : fn(type, props)
}
Expand All @@ -780,7 +782,9 @@ function developmentCreate(filePath, jsxDEV) {
/** @type {Create<JsxFunction>} */
function create(node, type, props, key) {
// Only an array when there are 2 or more children.
const isStaticChildren = Array.isArray(props.children)
const isStaticChildren = Array.isArray(
/** @type {Record<String, unknown>} */ (props).children
)
const point = pointStart(node)
return jsxDEV(
type,
Expand Down
7 changes: 7 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* @typedef {import('estree').Program} Program
* @typedef {import('hast').Nodes} Nodes
*
* @typedef {import('hast-util-to-jsx-runtime').CreateEvaluater<typeof production.jsx>} CreateEvaluater
*
Expand Down Expand Up @@ -549,6 +550,9 @@ test('components', async function (t) {
...production,
passNode: true,
components: {
/**
* @param {{ node: Nodes }} props
*/
b(props) {
assert.ok(props.node)
return 'a'
Expand All @@ -567,6 +571,9 @@ test('components', async function (t) {
toJsxRuntime(h('b'), {
...production,
components: {
/**
* @param {{ node: Nodes }} props
*/
b(props) {
assert.equal(props.node, undefined)
return 'a'
Expand Down