1
1
/**
2
- * @typedef {import('hast').Element } Element
3
- * @typedef {import('hast').ElementData } ElementData
4
- * @typedef {import('hast').Nodes } Nodes
5
- * @typedef {import('hast').Root } Root
6
- * @typedef {import('hast').RootContent } RootContent
7
- *
8
- * @typedef {import('parse5').DefaultTreeAdapterMap } DefaultTreeAdapterMap
9
- * @typedef {import('parse5').Token.ElementLocation } P5ElementLocation
10
- * @typedef {import('parse5').Token.Location } P5Location
11
- *
12
- * @typedef {import('property-information').Schema } Schema
13
- *
14
- * @typedef {import('unist').Point } Point
15
- * @typedef {import('unist').Position } Position
16
- *
17
- * @typedef {import('vfile').VFile } VFile
18
- */
19
-
20
- /**
21
- * @typedef {DefaultTreeAdapterMap['document'] } P5Document
22
- * @typedef {DefaultTreeAdapterMap['documentFragment'] } P5DocumentFragment
23
- * @typedef {DefaultTreeAdapterMap['documentType'] } P5DocumentType
24
- * @typedef {DefaultTreeAdapterMap['commentNode'] } P5Comment
25
- * @typedef {DefaultTreeAdapterMap['textNode'] } P5Text
26
- * @typedef {DefaultTreeAdapterMap['element'] } P5Element
27
- * @typedef {DefaultTreeAdapterMap['node'] } P5Node
28
- * @typedef {DefaultTreeAdapterMap['template'] } P5Template
2
+ * @import {ElementData, Element, Nodes, RootContent, Root} from 'hast'
3
+ * @import {DefaultTreeAdapterMap, Token} from 'parse5'
4
+ * @import {Schema} from 'property-information'
5
+ * @import {Point, Position} from 'unist'
6
+ * @import {VFile} from 'vfile'
29
7
*/
30
8
31
9
/**
@@ -76,7 +54,7 @@ const proto = Object.prototype
76
54
/**
77
55
* Transform a `parse5` AST to hast.
78
56
*
79
- * @param {P5Node } tree
57
+ * @param {DefaultTreeAdapterMap['node'] } tree
80
58
* `parse5` tree to transform.
81
59
* @param {Options | null | undefined } [options]
82
60
* Configuration (optional).
@@ -102,7 +80,7 @@ export function fromParse5(tree, options) {
102
80
*
103
81
* @param {State } state
104
82
* Info passed around about the current state.
105
- * @param {P5Node } node
83
+ * @param {DefaultTreeAdapterMap['node'] } node
106
84
* p5 node.
107
85
* @returns {Nodes }
108
86
* hast node.
@@ -113,15 +91,20 @@ function one(state, node) {
113
91
114
92
switch ( node . nodeName ) {
115
93
case '#comment' : {
116
- const reference = /** @type {P5Comment } */ ( node )
94
+ const reference = /** @type {DefaultTreeAdapterMap['commentNode'] } */ (
95
+ node
96
+ )
117
97
result = { type : 'comment' , value : reference . data }
118
98
patch ( state , reference , result )
119
99
return result
120
100
}
121
101
122
102
case '#document' :
123
103
case '#document-fragment' : {
124
- const reference = /** @type {P5Document | P5DocumentFragment } */ ( node )
104
+ const reference =
105
+ /** @type {DefaultTreeAdapterMap['document'] | DefaultTreeAdapterMap['documentFragment'] } */ (
106
+ node
107
+ )
125
108
const quirksMode =
126
109
'mode' in reference
127
110
? reference . mode === 'quirks' || reference . mode === 'limited-quirks'
@@ -148,22 +131,24 @@ function one(state, node) {
148
131
}
149
132
150
133
case '#documentType' : {
151
- const reference = /** @type {P5DocumentType } */ ( node )
134
+ const reference = /** @type {DefaultTreeAdapterMap['documentType'] } */ (
135
+ node
136
+ )
152
137
result = { type : 'doctype' }
153
138
patch ( state , reference , result )
154
139
return result
155
140
}
156
141
157
142
case '#text' : {
158
- const reference = /** @type {P5Text } */ ( node )
143
+ const reference = /** @type {DefaultTreeAdapterMap['textNode'] } */ ( node )
159
144
result = { type : 'text' , value : reference . value }
160
145
patch ( state , reference , result )
161
146
return result
162
147
}
163
148
164
149
// Element.
165
150
default : {
166
- const reference = /** @type {P5Element } */ ( node )
151
+ const reference = /** @type {DefaultTreeAdapterMap['element'] } */ ( node )
167
152
result = element ( state , reference )
168
153
return result
169
154
}
@@ -175,7 +160,7 @@ function one(state, node) {
175
160
*
176
161
* @param {State } state
177
162
* Info passed around about the current state.
178
- * @param {Array<P5Node > } nodes
163
+ * @param {Array<DefaultTreeAdapterMap['node'] > } nodes
179
164
* Nodes.
180
165
* @returns {Array<RootContent> }
181
166
* hast nodes.
@@ -199,7 +184,7 @@ function all(state, nodes) {
199
184
*
200
185
* @param {State } state
201
186
* Info passed around about the current state.
202
- * @param {P5Element } node
187
+ * @param {DefaultTreeAdapterMap['element'] } node
203
188
* `parse5` node to transform.
204
189
* @returns {Element }
205
190
* hast node.
@@ -230,7 +215,7 @@ function element(state, node) {
230
215
231
216
// Switch content.
232
217
if ( result . tagName === 'template' ) {
233
- const reference = /** @type {P5Template } */ ( node )
218
+ const reference = /** @type {DefaultTreeAdapterMap['template'] } */ ( node )
234
219
const pos = reference . sourceCodeLocation
235
220
const startTag = pos && pos . startTag && position ( pos . startTag )
236
221
const endTag = pos && pos . endTag && position ( pos . endTag )
@@ -255,7 +240,7 @@ function element(state, node) {
255
240
*
256
241
* @param {State } state
257
242
* Info passed around about the current state.
258
- * @param {P5Node } from
243
+ * @param {DefaultTreeAdapterMap['node'] } from
259
244
* p5 node.
260
245
* @param {Nodes } to
261
246
* hast node.
@@ -280,7 +265,7 @@ function patch(state, from, to) {
280
265
* Info passed around about the current state.
281
266
* @param {Nodes } node
282
267
* hast node.
283
- * @param {P5ElementLocation } location
268
+ * @param {Token.ElementLocation } location
284
269
* p5 location info.
285
270
* @returns {Position | undefined }
286
271
* Position, or nothing.
@@ -337,7 +322,7 @@ function createLocation(state, node, location) {
337
322
/**
338
323
* Turn a p5 location into a position.
339
324
*
340
- * @param {P5Location } loc
325
+ * @param {Token.Location } loc
341
326
* Location.
342
327
* @returns {Position | undefined }
343
328
* Position or nothing.
0 commit comments