|
40 | 40 | *
|
41 | 41 | * @typedef {'html'|'svg'} Space
|
42 | 42 | *
|
43 |
| - * @typedef {(node: any, context: Context) => EstreeJsxChild?} Handle |
| 43 | + * @typedef {(node: any, context: Context) => EstreeJsxChild|null|undefined|void} Handle |
44 | 44 | *
|
45 | 45 | * @typedef Options
|
46 | 46 | * @property {Space} [space='html']
|
@@ -90,28 +90,22 @@ export function toEstree(tree, options = {}) {
|
90 | 90 | schema: options.space === 'svg' ? svg : html,
|
91 | 91 | comments: [],
|
92 | 92 | esm: [],
|
93 |
| - // @ts-expect-error: hush. |
94 | 93 | handle: zwitch('type', {
|
95 | 94 | invalid,
|
96 |
| - // @ts-expect-error: hush. |
97 | 95 | unknown,
|
98 |
| - // @ts-expect-error: hush. |
99 |
| - handlers: Object.assign( |
100 |
| - {}, |
101 |
| - { |
102 |
| - comment, |
103 |
| - doctype: ignore, |
104 |
| - element, |
105 |
| - mdxjsEsm, |
106 |
| - mdxFlowExpression: mdxExpression, |
107 |
| - mdxJsxFlowElement: mdxJsxElement, |
108 |
| - mdxJsxTextElement: mdxJsxElement, |
109 |
| - mdxTextExpression: mdxExpression, |
110 |
| - root, |
111 |
| - text |
112 |
| - }, |
113 |
| - options.handlers |
114 |
| - ) |
| 96 | + handlers: { |
| 97 | + comment, |
| 98 | + doctype, |
| 99 | + element, |
| 100 | + mdxjsEsm, |
| 101 | + mdxFlowExpression: mdxExpression, |
| 102 | + mdxJsxFlowElement: mdxJsxElement, |
| 103 | + mdxJsxTextElement: mdxJsxElement, |
| 104 | + mdxTextExpression: mdxExpression, |
| 105 | + root, |
| 106 | + text, |
| 107 | + ...options.handlers |
| 108 | + } |
115 | 109 | })
|
116 | 110 | }
|
117 | 111 | let result = context.handle(tree, context)
|
@@ -147,13 +141,17 @@ function invalid(value) {
|
147 | 141 | }
|
148 | 142 |
|
149 | 143 | /**
|
150 |
| - * @param {Node} node |
| 144 | + * @param {unknown} node |
151 | 145 | */
|
152 | 146 | function unknown(node) {
|
| 147 | + // @ts-expect-error: JS guarantees there’s a `type`. |
153 | 148 | throw new Error('Cannot handle unknown node `' + node.type + '`')
|
154 | 149 | }
|
155 | 150 |
|
156 |
| -function ignore() {} |
| 151 | +/** |
| 152 | + * @param {import('hast').DocType} _node |
| 153 | + */ |
| 154 | +function doctype(_node) {} |
157 | 155 |
|
158 | 156 | /**
|
159 | 157 | * @param {Comment} node
|
|
0 commit comments