From 8b1ff41d1c70bd4f751dbe5b4658e4cb425792d6 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 26 Sep 2023 18:47:23 +0200 Subject: [PATCH] Remove unneeded dependency --- lib/ast-to-react.js | 8 ++++---- package.json | 4 +--- test/test.jsx | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/ast-to-react.js b/lib/ast-to-react.js index 9076b38e..07b6a3ce 100644 --- a/lib/ast-to-react.js +++ b/lib/ast-to-react.js @@ -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' @@ -185,14 +184,15 @@ function toReact(state, node, index, parent) { // Restore parent schema. state.schema = parentSchema + /** @type {ComponentType | 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` ) } diff --git a/package.json b/package.json index 459523e5..c6df64f6 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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", diff --git a/test/test.jsx b/test/test.jsx index fbc38f6c..e2c31d30 100644 --- a/test/test.jsx +++ b/test/test.jsx @@ -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( + + ), + '

a

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