Skip to content

Commit 95687c8

Browse files
committed
Refactor to use @imports
1 parent fa3d482 commit 95687c8

File tree

2 files changed

+16
-32
lines changed

2 files changed

+16
-32
lines changed

lib/index.js

+15-31
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
11
/**
2-
* @typedef {import('hast').Comment} Comment
3-
* @typedef {import('hast').Doctype} Doctype
4-
* @typedef {import('hast').Element} Element
5-
* @typedef {import('hast').Nodes} Nodes
6-
* @typedef {import('hast').Root} Root
7-
* @typedef {import('hast').RootContent} RootContent
8-
* @typedef {import('hast').Text} Text
9-
*
10-
* @typedef {import('hast-util-raw').Options} Options
11-
*
12-
* @typedef {import('mdast-util-to-hast').Raw} Raw
13-
*
14-
* @typedef {import('parse5').DefaultTreeAdapterMap} DefaultTreeAdapterMap
15-
* @typedef {import('parse5').ParserOptions<DefaultTreeAdapterMap>} ParserOptions
16-
* @typedef {import('parse5').Token.CharacterToken} CharacterToken
17-
* @typedef {import('parse5').Token.CommentToken} CommentToken
18-
* @typedef {import('parse5').Token.DoctypeToken} DoctypeToken
19-
* @typedef {import('parse5').Token.Location} Location
20-
* @typedef {import('parse5').Token.TagToken} TagToken
21-
*
22-
* @typedef {import('unist').Point} Point
2+
* @import {Comment, Doctype, Element, Nodes, RootContent, Root, Text} from 'hast'
3+
* @import {Options} from 'hast-util-raw'
4+
* @import {Raw} from 'mdast-util-to-hast'
5+
* @import {DefaultTreeAdapterMap, ParserOptions} from 'parse5'
6+
* @import {Point} from 'unist'
237
*/
248

259
/**
@@ -65,7 +49,7 @@ const knownMdxNames = new Set([
6549
'mdxjsEsm'
6650
])
6751

68-
/** @type {ParserOptions} */
52+
/** @type {ParserOptions<DefaultTreeAdapterMap>} */
6953
const parseOptions = {sourceCodeLocationInfo: true, scriptingEnabled: false}
7054

7155
/**
@@ -206,7 +190,7 @@ function text(node, state) {
206190
state.parser.tokenizer.state = 0
207191
}
208192

209-
/** @type {CharacterToken} */
193+
/** @type {Token.CharacterToken} */
210194
const token = {
211195
type: Token.TokenType.CHARACTER,
212196
chars: node.value,
@@ -233,7 +217,7 @@ function text(node, state) {
233217
* Nothing.
234218
*/
235219
function doctype(node, state) {
236-
/** @type {DoctypeToken} */
220+
/** @type {Token.DoctypeToken} */
237221
const token = {
238222
type: Token.TokenType.DOCTYPE,
239223
name: 'html',
@@ -300,7 +284,7 @@ function comment(node, state) {
300284
// @ts-expect-error: we pass stitches through.
301285
const data = node.value
302286

303-
/** @type {CommentToken} */
287+
/** @type {Token.CommentToken} */
304288
const token = {
305289
type: Token.TokenType.COMMENT,
306290
data,
@@ -427,7 +411,7 @@ function resetTokenizer(state, point) {
427411
setPoint(state, point)
428412

429413
// Process final characters if they’re still there after hibernating.
430-
/** @type {CharacterToken} */
414+
/** @type {Token.CharacterToken} */
431415
// @ts-expect-error: private.
432416
// type-coverage:ignore-next-line
433417
const token = state.parser.tokenizer.currentCharacterToken
@@ -496,7 +480,7 @@ function resetTokenizer(state, point) {
496480
*/
497481
function setPoint(state, point) {
498482
if (point && point.offset !== undefined) {
499-
/** @type {Location} */
483+
/** @type {Token.Location} */
500484
const location = {
501485
startLine: point.line,
502486
startCol: point.column,
@@ -548,7 +532,7 @@ function startTag(node, state) {
548532
{space: ns === webNamespaces.svg ? 'svg' : 'html'}
549533
)
550534

551-
/** @type {TagToken} */
535+
/** @type {Token.TagToken} */
552536
const tag = {
553537
type: Token.TokenType.START_TAG,
554538
tagName,
@@ -608,7 +592,7 @@ function endTag(node, state) {
608592

609593
resetTokenizer(state, pointEnd(node))
610594

611-
/** @type {TagToken} */
595+
/** @type {Token.TagToken} */
612596
const tag = {
613597
type: Token.TokenType.END_TAG,
614598
tagName,
@@ -672,7 +656,7 @@ function documentMode(node) {
672656
*
673657
* @param {Nodes | Stitch} node
674658
* hast node.
675-
* @returns {Location}
659+
* @returns {Token.Location}
676660
* `parse5` location.
677661
*/
678662
function createParse5Location(node) {
@@ -687,7 +671,7 @@ function createParse5Location(node) {
687671
offset: undefined
688672
}
689673

690-
/** @type {Record<keyof Location, number | undefined>} */
674+
/** @type {Record<keyof Token.Location, number | undefined>} */
691675
const location = {
692676
startLine: start.line,
693677
startCol: start.column,

test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* @typedef {import('./test-types.js')} DoNotTouchAsThisImportIncludesCustomNodesInTree
2+
* @import {} from './test-types.js'
33
*/
44

55
import assert from 'node:assert/strict'

0 commit comments

Comments
 (0)