Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 23, 2021
1 parent 2a1f5b2 commit 8e07e9c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 25 deletions.
20 changes: 10 additions & 10 deletions lib/ast-to-react.js
Expand Up @@ -27,7 +27,7 @@
*
* @callback TransformLink
* @param {string} href
* @param {Array.<ElementContent>} children
* @param {Array<ElementContent>} children
* @param {string?} title
* @returns {string}
*
Expand All @@ -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.<ElementContent>} children
* @param {Array<ElementContent>} children
* @param {string?} title
* @returns {TransformLinkTargetType|undefined}
*
Expand All @@ -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.<string, unknown>, isHeader: boolean}} TableCellProps
* @typedef {JSX.IntrinsicElements['table'] & ReactMarkdownProps & {style?: Record<string, unknown>, isHeader: boolean}} TableCellProps
* @typedef {JSX.IntrinsicElements['tr'] & ReactMarkdownProps & {isHeader: boolean}} TableRowProps
* @typedef {JSX.IntrinsicElements['ul'] & ReactMarkdownProps & {depth: number, ordered: false}} UnorderedListProps
*
Expand All @@ -80,7 +80,7 @@
* @property {TableRowComponent|ReactMarkdownNames} tr
* @property {UnorderedListComponent|ReactMarkdownNames} ul
*
* @typedef {Partial<Omit<import("./complex-types").NormalComponents, keyof SpecialComponents> & SpecialComponents>} Components
* @typedef {Partial<Omit<import('./complex-types').NormalComponents, keyof SpecialComponents> & SpecialComponents>} Components
*
* @typedef Options
* @property {boolean} [sourcePos=false]
Expand Down Expand Up @@ -112,7 +112,7 @@ const tableElements = new Set(['table', 'thead', 'tbody', 'tfoot', 'tr'])
* @param {Element|Root} node
*/
export function childrenToReact(context, node) {
/** @type {Array.<ReactNode>} */
/** @type {Array<ReactNode>} */
const children = []
let childIndex = -1
/** @type {Comment|Doctype|Element|Raw|Text} */
Expand Down Expand Up @@ -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.<string, unknown>} */
/** @type {Record<string, unknown>} */
const properties = {}
let schema = parentSchema
/** @type {string} */
Expand Down Expand Up @@ -355,7 +355,7 @@ function getElementsBeforeCount(parent, node) {
}

/**
* @param {Object.<string, unknown>} props
* @param {Record<string, unknown>} props
* @param {string} prop
* @param {unknown} value
* @param {Context} ctx
Expand Down Expand Up @@ -393,10 +393,10 @@ function addProperty(props, prop, value, ctx) {

/**
* @param {string} value
* @returns {Object.<string, string>}
* @returns {Record<string, string>}
*/
function parseStyle(value) {
/** @type {Object.<string, string>} */
/** @type {Record<string, string>} */
const result = {}

try {
Expand Down
2 changes: 1 addition & 1 deletion lib/react-markdown.js
Expand Up @@ -39,7 +39,7 @@ const own = {}.hasOwnProperty
const changelog =
'https://github.com/remarkjs/react-markdown/blob/main/changelog.md'

/** @type {Object.<string, Deprecation>} */
/** @type {Record<string, Deprecation>} */
const deprecated = {
renderers: {to: 'components', id: 'change-renderers-to-components'},
astPlugins: {id: 'remove-buggy-html-in-markdown-parser'},
Expand Down
4 changes: 2 additions & 2 deletions lib/rehype-filter.js
Expand Up @@ -12,8 +12,8 @@ import {visit} from 'unist-util-visit'
* @returns {boolean|undefined}
*
* @typedef Options
* @property {Array.<string>} [allowedElements]
* @property {Array.<string>} [disallowedElements=[]]
* @property {Array<string>} [allowedElements]
* @property {Array<string>} [disallowedElements=[]]
* @property {AllowElement} [allowElement]
* @property {boolean} [unwrapDisallowed=false]
*/
Expand Down
24 changes: 12 additions & 12 deletions test/test.jsx
Expand Up @@ -915,7 +915,7 @@ test('should skip nodes that are defined as disallowed', () => {
hr: {input: '\n-----\nAnd with that...', shouldNotContain: '<hr'}
}

/** @type {string[]} */
/** @type {Array<string>} */
const inputs = []
/** @type {keyof samples} */
let key
Expand Down Expand Up @@ -1008,7 +1008,7 @@ test('should be able to override components', () => {
const heading = (level) => {
/**
* @param {object} props
* @param {ReactNode[]} props.children
* @param {Array<ReactNode>} props.children
*/
const component = (props) => (
<span className={`heading level-${level}`}>{props.children}</span>
Expand Down Expand Up @@ -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<void[], Root>} */
/** @type {import('unified').Plugin<Array<void>, Root>} */
const plugin = () => (root) => {
root.children.unshift({
type: 'element',
Expand All @@ -1238,7 +1238,7 @@ test('should support aria properties', () => {
test('should support data properties', () => {
const input = 'b'

/** @type {import('unified').Plugin<void[], Root>} */
/** @type {import('unified').Plugin<Array<void>, Root>} */
const plugin = () => (root) => {
root.children.unshift({
type: 'element',
Expand All @@ -1256,7 +1256,7 @@ test('should support data properties', () => {
test('should support comma separated properties', () => {
const input = 'c'

/** @type {import('unified').Plugin<void[], Root>} */
/** @type {import('unified').Plugin<Array<void>, Root>} */
const plugin = () => (root) => {
root.children.unshift({
type: 'element',
Expand All @@ -1274,7 +1274,7 @@ test('should support comma separated properties', () => {
test('should support `style` properties', () => {
const input = 'a'

/** @type {import('unified').Plugin<void[], Root>} */
/** @type {import('unified').Plugin<Array<void>, Root>} */
const plugin = () => (root) => {
root.children.unshift({
type: 'element',
Expand All @@ -1292,7 +1292,7 @@ test('should support `style` properties', () => {
test('should support `style` properties w/ vendor prefixes', () => {
const input = 'a'

/** @type {import('unified').Plugin<void[], Root>} */
/** @type {import('unified').Plugin<Array<void>, Root>} */
const plugin = () => (root) => {
root.children.unshift({
type: 'element',
Expand All @@ -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<void[], Root>} */
/** @type {import('unified').Plugin<Array<void>, Root>} */
const plugin = () => (root) => {
root.children.unshift({
type: 'element',
Expand All @@ -1328,7 +1328,7 @@ test('should support broken `style` properties', () => {
test('should support SVG elements', () => {
const input = 'a'

/** @type {import('unified').Plugin<void[], Root>} */
/** @type {import('unified').Plugin<Array<void>, Root>} */
const plugin = () => (root) => {
root.children.unshift({
type: 'element',
Expand Down Expand Up @@ -1367,7 +1367,7 @@ test('should support SVG elements', () => {
test('should support (ignore) comments', () => {
const input = 'a'

/** @type {import('unified').Plugin<void[], Root>} */
/** @type {import('unified').Plugin<Array<void>, Root>} */
const plugin = () => (root) => {
root.children.unshift({type: 'comment', value: 'things!'})
}
Expand All @@ -1380,7 +1380,7 @@ test('should support (ignore) comments', () => {
test('should support table cells w/ style', () => {
const input = '| a |\n| :- |'

/** @type {import('unified').Plugin<void[], Root>} */
/** @type {import('unified').Plugin<Array<void>, Root>} */
const plugin = () => (root) => {
visit(root, {type: 'element', tagName: 'th'}, (node) => {
node.properties = {...node.properties, style: 'color: red'}
Expand All @@ -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<void[], Root>} */
/** @type {import('unified').Plugin<Array<void>, Root>} */
// @ts-expect-error: runtime.
const plugin = () => () => ({type: 'comment', value: 'things!'})
assert.throws(() => {
Expand Down

0 comments on commit 8e07e9c

Please sign in to comment.