Skip to content

Commit 560d61a

Browse files
committed
Update @types/hast, utilities
1 parent c229dda commit 560d61a

File tree

11 files changed

+79
-88
lines changed

11 files changed

+79
-88
lines changed

lib/handlers/comment.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
* @typedef {import('estree').Comment} Comment
33
* @typedef {import('estree-jsx').JSXExpressionContainer} JsxExpressionContainer
44
* @typedef {import('estree-jsx').JSXEmptyExpression} JsxEmptyExpression
5+
* @typedef {import('hast').Comment} HastComment
56
* @typedef {import('../state.js').State} State
67
*/
78

9+
// Make VS Code show references to the above types.
10+
''
11+
812
/**
913
* Turn a hast comment into an estree node.
1014
*
11-
* @param {import('hast').Comment} node
15+
* @param {HastComment} node
1216
* hast node to transform.
1317
* @param {State} state
1418
* Info passed around about the current state.

lib/handlers/element.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
/**
2-
* @typedef {import('hast').Element} Element
32
* @typedef {import('estree').Property} Property
43
* @typedef {import('estree-jsx').JSXElement} JsxElement
54
* @typedef {import('estree-jsx').JSXSpreadAttribute} JsxSpreadAttribute
65
* @typedef {import('estree-jsx').JSXAttribute} JsxAttribute
6+
* @typedef {import('hast').Element} HastElement
77
* @typedef {import('../state.js').State} State
88
*/
99

@@ -28,7 +28,7 @@ const dashSomething = /-([a-z])/g
2828
/**
2929
* Turn a hast element into an estree node.
3030
*
31-
* @param {Element} node
31+
* @param {HastElement} node
3232
* hast node to transform.
3333
* @param {State} state
3434
* Info passed around about the current state.

lib/handlers/mdx-expression.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @typedef {import('mdast-util-mdx-expression').MdxFlowExpression} MdxFlowExpression
3-
* @typedef {import('mdast-util-mdx-expression').MdxTextExpression} MdxTextExpression
2+
* @typedef {import('mdast-util-mdx-expression').MdxFlowExpressionHast} MdxFlowExpression
3+
* @typedef {import('mdast-util-mdx-expression').MdxFlowExpressionHast} MdxTextExpression
44
* @typedef {import('estree').Expression} Expression
55
* @typedef {import('estree-jsx').JSXEmptyExpression} JsxEmptyExpression
66
* @typedef {import('estree-jsx').JSXExpressionContainer} JsxExpressionContainer

lib/handlers/mdx-jsx-element.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* @typedef {import('mdast-util-mdx-jsx').MdxJsxFlowElement} MdxJsxFlowElement
3-
* @typedef {import('mdast-util-mdx-jsx').MdxJsxTextElement} MdxJsxTextElement
2+
* @typedef {import('mdast-util-mdx-jsx').MdxJsxFlowElementHast} MdxJsxFlowElement
3+
* @typedef {import('mdast-util-mdx-jsx').MdxJsxTextElementHast} MdxJsxTextElement
44
* @typedef {import('estree').Expression} Expression
55
* @typedef {import('estree-jsx').JSXElement} JsxElement
66
* @typedef {import('estree-jsx').JSXFragment} JsxFragment

lib/handlers/mdxjs-esm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import('mdast-util-mdxjs-esm').MdxjsEsm} MdxjsEsm
2+
* @typedef {import('mdast-util-mdxjs-esm').MdxjsEsmHast} MdxjsEsm
33
* @typedef {import('../state.js').State} State
44
*/
55

lib/handlers/root.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import('hast').Root} Root
2+
* @typedef {import('hast').Root} HastRoot
33
* @typedef {import('estree-jsx').JSXFragment} JsxFragment
44
* @typedef {JsxFragment['children'][number]} JsxChild
55
* @typedef {import('../state.js').State} State
@@ -10,7 +10,7 @@ import {whitespace} from 'hast-util-whitespace'
1010
/**
1111
* Turn a hast root node into an estree node.
1212
*
13-
* @param {Root} node
13+
* @param {HastRoot} node
1414
* hast node to transform.
1515
* @param {State} state
1616
* Info passed around about the current state.
@@ -32,7 +32,7 @@ export function root(node, state) {
3232
if (
3333
child.type === 'JSXExpressionContainer' &&
3434
child.expression.type === 'Literal' &&
35-
whitespace(child.expression.value)
35+
whitespace(String(child.expression.value))
3636
) {
3737
if (queue) queue.push(child)
3838
} else {

lib/handlers/text.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
/**
2-
* @typedef {import('hast').Text} Text
2+
* @typedef {import('hast').Text} HastText
33
* @typedef {import('estree').Literal} Literal
44
* @typedef {import('estree-jsx').JSXExpressionContainer} JsxExpressionContainer
55
* @typedef {import('../state.js').State} State
66
*/
77

8+
// Make VS Code show references to the above types.
9+
''
10+
811
/**
912
* Turn a hast text node into an estree node.
1013
*
11-
* @param {Text} node
14+
* @param {HastText} node
1215
* hast node to transform.
1316
* @param {State} state
1417
* Info passed around about the current state.

lib/index.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
11
/**
2-
* @typedef {import('hast').Content} Content
3-
* @typedef {import('hast').Root} Root
2+
* Register MDX nodes in tree:
3+
*
4+
* @typedef {import('mdast-util-mdx-expression')}
5+
* @typedef {import('mdast-util-mdx-jsx')}
6+
* @typedef {import('mdast-util-mdxjs-esm')}
7+
*/
8+
9+
/**
10+
* @typedef {import('hast').Nodes} HastNodes
411
*
512
* @typedef {import('estree').ExpressionStatement} ExpressionStatement
613
* @typedef {import('estree').Program} Program
714
*
8-
* @typedef {import('mdast-util-mdx-jsx').MdxJsxAttribute} MdxJsxAttribute
9-
* @typedef {import('mdast-util-mdx-jsx').MdxJsxAttributeValueExpression} MdxJsxAttributeValueExpression
10-
* @typedef {import('mdast-util-mdx-jsx').MdxJsxExpressionAttribute} MdxJsxExpressionAttribute
11-
* @typedef {import('mdast-util-mdx-jsx').MdxJsxFlowElement} MdxJsxFlowElement
12-
* @typedef {import('mdast-util-mdx-jsx').MdxJsxTextElement} MdxJsxTextElement
13-
*
14-
* @typedef {import('mdast-util-mdx-expression').MdxFlowExpression} MdxFlowExpression
15-
* @typedef {import('mdast-util-mdx-expression').MdxTextExpression} MdxTextExpression
16-
*
1715
* @typedef {import('./state.js').Options} Options
1816
*/
1917

20-
/**
21-
* @typedef {Root | Content | MdxJsxAttributeValueExpression | MdxJsxAttribute | MdxJsxExpressionAttribute | MdxJsxFlowElement | MdxJsxTextElement | MdxFlowExpression | MdxTextExpression} Node
22-
*/
23-
2418
import {createState} from './state.js'
2519

2620
/**
@@ -52,7 +46,7 @@ import {createState} from './state.js'
5246
* | Solid | `'html'` | `'css'` |
5347
* | Vue | `'html'` | `'dom'` |
5448
*
55-
* @param {Node} tree
49+
* @param {HastNodes} tree
5650
* hast tree.
5751
* @param {Options | null | undefined} [options]
5852
* Configuration.

lib/state.js

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,17 @@
1111
* @typedef {import('estree-jsx').JSXMemberExpression} JsxMemberExpression
1212
* @typedef {import('estree-jsx').JSXNamespacedName} JsxNamespacedName
1313
*
14-
* @typedef {import('hast').Content} Content
15-
* @typedef {import('hast').Root} Root
16-
*
17-
* @typedef {import('mdast-util-mdx-expression').MdxFlowExpression} MdxFlowExpression
18-
* @typedef {import('mdast-util-mdx-expression').MdxTextExpression} MdxTextExpression
19-
*
2014
* @typedef {import('mdast-util-mdx-jsx').MdxJsxAttribute} MdxJsxAttribute
2115
* @typedef {import('mdast-util-mdx-jsx').MdxJsxAttributeValueExpression} MdxJsxAttributeValueExpression
2216
* @typedef {import('mdast-util-mdx-jsx').MdxJsxExpressionAttribute} MdxJsxExpressionAttribute
23-
* @typedef {import('mdast-util-mdx-jsx').MdxJsxFlowElement} MdxJsxFlowElement
24-
* @typedef {import('mdast-util-mdx-jsx').MdxJsxTextElement} MdxJsxTextElement
2517
*
26-
* @typedef {import('property-information').Schema} Schema
18+
* @typedef {import('hast').Nodes} HastNodes
19+
* @typedef {import('hast').Parents} HastParents
2720
*
28-
* @typedef {import('unist').Parent} UnistParent
21+
* @typedef {import('property-information').Schema} Schema
2922
*/
3023

3124
/**
32-
* @typedef {Content | MdxJsxAttributeValueExpression | MdxJsxAttribute | MdxJsxExpressionAttribute | MdxJsxFlowElement | MdxJsxTextElement | MdxFlowExpression | MdxTextExpression | Root} Node
33-
* @typedef {Extract<Node, UnistParent>} Parent
3425
* @typedef {JsxElement['openingElement']['name']} JsxElementName
3526
* @typedef {JsxAttribute['name']} JsxAttributeName
3627
* @typedef {JsxElement['children'][number]} JsxChild
@@ -94,11 +85,11 @@
9485
* List of top-level estree nodes.
9586
* @property {(node: any) => JsxChild | null | undefined | void} handle
9687
* Transform a hast node to estree.
97-
* @property {(parent: Parent) => Array<JsxChild>} all
88+
* @property {(parent: HastParents) => Array<JsxChild>} all
9889
* Transform children of a hast parent to estree.
99-
* @property {(from: Node, to: EstreeNode | Comment) => void} patch
90+
* @property {(from: HastNodes, to: Comment | EstreeNode) => void} patch
10091
* Take positional info from `from` (use `inherit` if you also want data).
101-
* @property {(from: Node, to: EstreeNode | Comment) => void} inherit
92+
* @property {(from: HastNodes | MdxJsxAttribute | MdxJsxAttributeValueExpression | MdxJsxExpressionAttribute, to: Comment | EstreeNode) => void} inherit
10293
* Take positional info and data from `from` (use `patch` if you don’t want data).
10394
* @property {(name: string) => JsxAttributeName} createJsxAttributeName
10495
* Create a JSX attribute name.
@@ -199,7 +190,7 @@ function unknown(node) {
199190
/**
200191
* @this {State} state
201192
* Info passed around about the current state.
202-
* @param {Parent | MdxJsxFlowElement | MdxJsxTextElement} parent
193+
* @param {HastParents} parent
203194
* hast node whose children to transform.
204195
* @returns {Array<JsxChild>}
205196
* estree nodes.
@@ -238,16 +229,15 @@ function all(parent) {
238229
*
239230
* Use `patch` if you don’t want data.
240231
*
241-
* @param {Node | MdxJsxAttributeValueExpression | MdxJsxAttribute | MdxJsxExpressionAttribute | MdxJsxFlowElement | MdxJsxTextElement | MdxFlowExpression | MdxTextExpression} from
232+
* @param {HastNodes | MdxJsxAttribute | MdxJsxAttributeValueExpression | MdxJsxExpressionAttribute} from
242233
* hast node to take positional info and data from.
243-
* @param {EstreeNode | Comment} to
234+
* @param {Comment | EstreeNode} to
244235
* estree node to add positional info and data to.
245236
* @returns {void}
246237
* Nothing.
247238
*/
248239
function inherit(from, to) {
249-
/** @type {Record<string, unknown> | undefined} */
250-
const left = from.data
240+
const left = /** @type {Record<string, unknown> | undefined} */ (from.data)
251241
/** @type {Record<string, unknown> | undefined} */
252242
let right
253243
/** @type {string} */
@@ -275,7 +265,7 @@ function inherit(from, to) {
275265
*
276266
* Use `inherit` if you also want data.
277267
*
278-
* @param {Node | MdxJsxAttributeValueExpression | MdxJsxAttribute | MdxJsxExpressionAttribute | MdxJsxFlowElement | MdxJsxTextElement | MdxFlowExpression | MdxTextExpression} from
268+
* @param {HastNodes | MdxJsxAttributeValueExpression | MdxJsxAttribute | MdxJsxExpressionAttribute} from
279269
* hast node to take positional info from.
280270
* @param {EstreeNode | Comment} to
281271
* estree node to add positional info to.
@@ -285,11 +275,7 @@ function inherit(from, to) {
285275
function patch(from, to) {
286276
const p = position(from)
287277

288-
if (
289-
p.start.line &&
290-
p.start.offset !== undefined &&
291-
p.end.offset !== undefined
292-
) {
278+
if (p && p.start.offset !== undefined && p.end.offset !== undefined) {
293279
// @ts-expect-error acorn-style.
294280
to.start = p.start.offset
295281
// @ts-expect-error acorn-style.

package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,18 @@
4242
"dependencies": {
4343
"@types/estree": "^1.0.0",
4444
"@types/estree-jsx": "^1.0.0",
45-
"@types/hast": "^2.0.0",
46-
"@types/unist": "^2.0.0",
45+
"@types/hast": "^3.0.0",
4746
"comma-separated-tokens": "^2.0.0",
48-
"estree-util-attach-comments": "^2.0.0",
49-
"estree-util-is-identifier-name": "^2.0.0",
50-
"hast-util-whitespace": "^2.0.0",
51-
"mdast-util-mdx-expression": "^1.0.0",
52-
"mdast-util-mdxjs-esm": "^1.0.0",
47+
"estree-util-attach-comments": "^3.0.0",
48+
"estree-util-is-identifier-name": "^3.0.0",
49+
"hast-util-whitespace": "^3.0.0",
50+
"mdast-util-mdx-expression": "^2.0.0",
51+
"mdast-util-mdx-jsx": "^3.0.0",
52+
"mdast-util-mdxjs-esm": "^2.0.0",
5353
"property-information": "^6.0.0",
5454
"space-separated-tokens": "^2.0.0",
55-
"style-to-object": "^0.4.1",
56-
"unist-util-position": "^4.0.0",
55+
"style-to-object": "^0.4.0",
56+
"unist-util-position": "^5.0.0",
5757
"zwitch": "^2.0.0"
5858
},
5959
"devDependencies": {
@@ -66,21 +66,21 @@
6666
"@vue/babel-plugin-jsx": "^1.0.0",
6767
"acorn-jsx": "^5.0.0",
6868
"c8": "^8.0.0",
69-
"esast-util-from-js": "^1.0.0",
70-
"estree-to-babel": "^5.0.0",
71-
"estree-util-to-js": "^1.0.0",
69+
"esast-util-from-js": "^2.0.0",
70+
"estree-to-babel": "^6.0.0",
71+
"estree-util-to-js": "^2.0.0",
7272
"estree-walker": "^3.0.0",
73-
"hastscript": "^7.0.0",
74-
"mdast-util-from-markdown": "^1.0.0",
75-
"mdast-util-mdx": "^2.0.0",
76-
"mdast-util-to-hast": "^12.0.0",
77-
"micromark-extension-mdxjs": "^1.0.0",
73+
"hastscript": "^8.0.0",
74+
"mdast-util-from-markdown": "^2.0.0",
75+
"mdast-util-mdx": "^3.0.0",
76+
"mdast-util-to-hast": "^13.0.0",
77+
"micromark-extension-mdxjs": "^2.0.0",
7878
"prettier": "^3.0.0",
7979
"remark-cli": "^11.0.0",
8080
"remark-preset-wooorm": "^9.0.0",
8181
"type-coverage": "^2.0.0",
8282
"typescript": "^5.0.0",
83-
"unist-util-visit": "^4.0.0",
83+
"unist-util-visit": "^5.0.0",
8484
"xo": "^0.55.0"
8585
},
8686
"scripts": {

0 commit comments

Comments
 (0)