Skip to content

Commit

Permalink
Fix type-coverage issues
Browse files Browse the repository at this point in the history
  • Loading branch information
remcohaszing committed Mar 1, 2024
1 parent c4ed721 commit 79ad7d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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

0 comments on commit 79ad7d1

Please sign in to comment.