From 8e07e9c3ed740977d6922a6d58e5113f1c09a0c2 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 21 Nov 2021 17:28:54 +0100 Subject: [PATCH] Refactor --- lib/ast-to-react.js | 20 ++++++++++---------- lib/react-markdown.js | 2 +- lib/rehype-filter.js | 4 ++-- test/test.jsx | 24 ++++++++++++------------ 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/ast-to-react.js b/lib/ast-to-react.js index d2b502b2..b0984c1c 100644 --- a/lib/ast-to-react.js +++ b/lib/ast-to-react.js @@ -27,7 +27,7 @@ * * @callback TransformLink * @param {string} href - * @param {Array.} children + * @param {Array} children * @param {string?} title * @returns {string} * @@ -37,11 +37,11 @@ * @param {string?} title * @returns {string} * - * @typedef {import("react").HTMLAttributeAnchorTarget} TransformLinkTargetType + * @typedef {import('react').HTMLAttributeAnchorTarget} TransformLinkTargetType * * @callback TransformLinkTarget * @param {string} href - * @param {Array.} children + * @param {Array} children * @param {string?} title * @returns {TransformLinkTargetType|undefined} * @@ -53,7 +53,7 @@ * @typedef {JSX.IntrinsicElements['h1'] & ReactMarkdownProps & {level: number}} HeadingProps * @typedef {JSX.IntrinsicElements['li'] & ReactMarkdownProps & {checked: boolean|null, index: number, ordered: boolean}} LiProps * @typedef {JSX.IntrinsicElements['ol'] & ReactMarkdownProps & {depth: number, ordered: true}} OrderedListProps - * @typedef {JSX.IntrinsicElements['table'] & ReactMarkdownProps & {style?: Object., isHeader: boolean}} TableCellProps + * @typedef {JSX.IntrinsicElements['table'] & ReactMarkdownProps & {style?: Record, isHeader: boolean}} TableCellProps * @typedef {JSX.IntrinsicElements['tr'] & ReactMarkdownProps & {isHeader: boolean}} TableRowProps * @typedef {JSX.IntrinsicElements['ul'] & ReactMarkdownProps & {depth: number, ordered: false}} UnorderedListProps * @@ -80,7 +80,7 @@ * @property {TableRowComponent|ReactMarkdownNames} tr * @property {UnorderedListComponent|ReactMarkdownNames} ul * - * @typedef {Partial & SpecialComponents>} Components + * @typedef {Partial & SpecialComponents>} Components * * @typedef Options * @property {boolean} [sourcePos=false] @@ -112,7 +112,7 @@ const tableElements = new Set(['table', 'thead', 'tbody', 'tfoot', 'tr']) * @param {Element|Root} node */ export function childrenToReact(context, node) { - /** @type {Array.} */ + /** @type {Array} */ const children = [] let childIndex = -1 /** @type {Comment|Doctype|Element|Raw|Text} */ @@ -159,7 +159,7 @@ function toReact(context, node, index, parent) { /** @type {ReactMarkdownNames} */ // @ts-expect-error assume a known HTML/SVG element. const name = node.tagName - /** @type {Object.} */ + /** @type {Record} */ const properties = {} let schema = parentSchema /** @type {string} */ @@ -355,7 +355,7 @@ function getElementsBeforeCount(parent, node) { } /** - * @param {Object.} props + * @param {Record} props * @param {string} prop * @param {unknown} value * @param {Context} ctx @@ -393,10 +393,10 @@ function addProperty(props, prop, value, ctx) { /** * @param {string} value - * @returns {Object.} + * @returns {Record} */ function parseStyle(value) { - /** @type {Object.} */ + /** @type {Record} */ const result = {} try { diff --git a/lib/react-markdown.js b/lib/react-markdown.js index 3da1cb69..da32d1e5 100644 --- a/lib/react-markdown.js +++ b/lib/react-markdown.js @@ -39,7 +39,7 @@ const own = {}.hasOwnProperty const changelog = 'https://github.com/remarkjs/react-markdown/blob/main/changelog.md' -/** @type {Object.} */ +/** @type {Record} */ const deprecated = { renderers: {to: 'components', id: 'change-renderers-to-components'}, astPlugins: {id: 'remove-buggy-html-in-markdown-parser'}, diff --git a/lib/rehype-filter.js b/lib/rehype-filter.js index ad027a59..3d6a00d8 100644 --- a/lib/rehype-filter.js +++ b/lib/rehype-filter.js @@ -12,8 +12,8 @@ import {visit} from 'unist-util-visit' * @returns {boolean|undefined} * * @typedef Options - * @property {Array.} [allowedElements] - * @property {Array.} [disallowedElements=[]] + * @property {Array} [allowedElements] + * @property {Array} [disallowedElements=[]] * @property {AllowElement} [allowElement] * @property {boolean} [unwrapDisallowed=false] */ diff --git a/test/test.jsx b/test/test.jsx index a270e6e7..71c1c491 100644 --- a/test/test.jsx +++ b/test/test.jsx @@ -915,7 +915,7 @@ test('should skip nodes that are defined as disallowed', () => { hr: {input: '\n-----\nAnd with that...', shouldNotContain: '} */ const inputs = [] /** @type {keyof samples} */ let key @@ -1008,7 +1008,7 @@ test('should be able to override components', () => { const heading = (level) => { /** * @param {object} props - * @param {ReactNode[]} props.children + * @param {Array} props.children */ const component = (props) => ( {props.children} @@ -1220,7 +1220,7 @@ test('should support formatting at the start of a GFM tasklist (GH-494)', () => test('should support aria properties', () => { const input = 'c' - /** @type {import('unified').Plugin} */ + /** @type {import('unified').Plugin, Root>} */ const plugin = () => (root) => { root.children.unshift({ type: 'element', @@ -1238,7 +1238,7 @@ test('should support aria properties', () => { test('should support data properties', () => { const input = 'b' - /** @type {import('unified').Plugin} */ + /** @type {import('unified').Plugin, Root>} */ const plugin = () => (root) => { root.children.unshift({ type: 'element', @@ -1256,7 +1256,7 @@ test('should support data properties', () => { test('should support comma separated properties', () => { const input = 'c' - /** @type {import('unified').Plugin} */ + /** @type {import('unified').Plugin, Root>} */ const plugin = () => (root) => { root.children.unshift({ type: 'element', @@ -1274,7 +1274,7 @@ test('should support comma separated properties', () => { test('should support `style` properties', () => { const input = 'a' - /** @type {import('unified').Plugin} */ + /** @type {import('unified').Plugin, Root>} */ const plugin = () => (root) => { root.children.unshift({ type: 'element', @@ -1292,7 +1292,7 @@ test('should support `style` properties', () => { test('should support `style` properties w/ vendor prefixes', () => { const input = 'a' - /** @type {import('unified').Plugin} */ + /** @type {import('unified').Plugin, Root>} */ const plugin = () => (root) => { root.children.unshift({ type: 'element', @@ -1310,7 +1310,7 @@ test('should support `style` properties w/ vendor prefixes', () => { test('should support broken `style` properties', () => { const input = 'a' - /** @type {import('unified').Plugin} */ + /** @type {import('unified').Plugin, Root>} */ const plugin = () => (root) => { root.children.unshift({ type: 'element', @@ -1328,7 +1328,7 @@ test('should support broken `style` properties', () => { test('should support SVG elements', () => { const input = 'a' - /** @type {import('unified').Plugin} */ + /** @type {import('unified').Plugin, Root>} */ const plugin = () => (root) => { root.children.unshift({ type: 'element', @@ -1367,7 +1367,7 @@ test('should support SVG elements', () => { test('should support (ignore) comments', () => { const input = 'a' - /** @type {import('unified').Plugin} */ + /** @type {import('unified').Plugin, Root>} */ const plugin = () => (root) => { root.children.unshift({type: 'comment', value: 'things!'}) } @@ -1380,7 +1380,7 @@ test('should support (ignore) comments', () => { test('should support table cells w/ style', () => { const input = '| a |\n| :- |' - /** @type {import('unified').Plugin} */ + /** @type {import('unified').Plugin, Root>} */ const plugin = () => (root) => { visit(root, {type: 'element', tagName: 'th'}, (node) => { node.properties = {...node.properties, style: 'color: red'} @@ -1398,7 +1398,7 @@ test('should support table cells w/ style', () => { test('should crash on a plugin replacing `root`', () => { const input = 'a' - /** @type {import('unified').Plugin} */ + /** @type {import('unified').Plugin, Root>} */ // @ts-expect-error: runtime. const plugin = () => () => ({type: 'comment', value: 'things!'}) assert.throws(() => {