Skip to content

Commit

Permalink
Remove unneeded dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 26, 2023
1 parent de252e8 commit 8b1ff41
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 4 additions & 4 deletions lib/ast-to-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
*/

import React from 'react'
import ReactIs from 'react-is'
import {stringify as commas} from 'comma-separated-tokens'
import {whitespace} from 'hast-util-whitespace'
import {find, hastToReact, svg} from 'property-information'
Expand Down Expand Up @@ -185,14 +184,15 @@ function toReact(state, node, index, parent) {
// Restore parent schema.
state.schema = parentSchema

/** @type {ComponentType<any> | string} */
const component =
options.components && own.call(options.components, name)
? options.components[name]
? options.components[name] || name
: name
const basic = typeof component === 'string' || component === React.Fragment

if (!ReactIs.isValidElementType(component)) {
throw new TypeError(
if (!basic && typeof component !== 'function') {
throw new Error(
`Component for name \`${name}\` not defined or is not renderable`
)
}
Expand Down
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@
"@types/unist": "^3.0.0",
"comma-separated-tokens": "^2.0.0",
"hast-util-whitespace": "^3.0.0",
"mdast-util-to-hast": "^13.0.2",
"mdast-util-to-hast": "^13.0.0",
"prop-types": "^15.0.0",
"property-information": "^6.0.0",
"react-is": "^18.0.0",
"remark-parse": "^11.0.0",
"remark-rehype": "^11.0.0",
"space-separated-tokens": "^2.0.0",
Expand All @@ -105,7 +104,6 @@
"@types/node": "^20.0.0",
"@types/react": "^18.0.0",
"@types/react-dom": "^18.0.0",
"@types/react-is": "^18.0.0",
"c8": "^8.0.0",
"esbuild": "^0.19.0",
"eslint-plugin-es": "^4.0.0",
Expand Down
16 changes: 16 additions & 0 deletions test/test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,22 @@ test('react-markdown', async function (t) {
}, /Component for name `h1`/)
})

await t.test('should support `null`, `undefined` in components', function () {
assert.equal(
asHtml(
<Markdown
children="# *a*"
components={{
// @ts-expect-error: code allows `null` but TS does not.
h1: null,
em: undefined
}}
/>
),
'<h1><em>a</em></h1>'
)
})

await t.test('should support `components` (headings; `level`)', function () {
let calls = 0

Expand Down

0 comments on commit 8b1ff41

Please sign in to comment.