1
- /**
2
- * @author Titus Wormer
3
- * @copyright 2016 Titus Wormer
4
- * @license MIT
5
- * @module hast-util-from-parse5
6
- * @fileoverview Transform Parse5’s AST to HAST.
7
- */
8
-
9
1
'use strict' ;
10
2
11
3
/* Dependencies. */
@@ -27,13 +19,7 @@ var map = {
27
19
'#documentType' : doctype
28
20
} ;
29
21
30
- /**
31
- * Wrapper to normalise options.
32
- *
33
- * @param {ASTNode } ast - Parse5 node.
34
- * @param {VFile|Object? } [options] - Configuration.
35
- * @return {HASTNode } - HAST node.
36
- */
22
+ /* Wrapper to normalise options. */
37
23
function wrapper ( ast , options ) {
38
24
var settings = options || { } ;
39
25
var file ;
@@ -53,13 +39,7 @@ function wrapper(ast, options) {
53
39
} ) ;
54
40
}
55
41
56
- /**
57
- * Transform a node.
58
- *
59
- * @param {ASTNode } ast - Parse5 node.
60
- * @param {Object } config - Configuration.
61
- * @return {HASTNode } - HAST node.
62
- */
42
+ /* Transform a node. */
63
43
function transform ( ast , config ) {
64
44
var fn = has ( map , ast . nodeName ) ? map [ ast . nodeName ] : element ;
65
45
var children ;
@@ -84,13 +64,7 @@ function transform(ast, config) {
84
64
return node ;
85
65
}
86
66
87
- /**
88
- * Transform children.
89
- *
90
- * @param {Array.<ASTNode> } children - Parse5 nodes.
91
- * @param {Object } config - Configuration.
92
- * @return {Array.<HASTNode> } - HAST nodes.
93
- */
67
+ /* Transform children. */
94
68
function nodes ( children , config ) {
95
69
var length = children . length ;
96
70
var index = - 1 ;
@@ -103,16 +77,8 @@ function nodes(children, config) {
103
77
return result ;
104
78
}
105
79
106
- /**
107
- * Transform a document.
108
- *
109
- * Stores `ast.quirksMode` in `node.data.quirksMode`.
110
- *
111
- * @param {ASTNode.<Document> } ast - Parse5 document.
112
- * @param {Array.<ASTNode> } children - Children of `ast`.
113
- * @param {Object } config - Configuration.
114
- * @return {HASTRoot } - Root node.
115
- */
80
+ /* Transform a document.
81
+ * Stores `ast.quirksMode` in `node.data.quirksMode`. */
116
82
function root ( ast , children , config ) {
117
83
var node = {
118
84
type : 'root' ,
@@ -132,12 +98,7 @@ function root(ast, children, config) {
132
98
return node ;
133
99
}
134
100
135
- /**
136
- * Transform a doctype.
137
- *
138
- * @param {ASTNode.<DocumentType> } ast - Parse5 doctype.
139
- * @return {HASTDoctype } - Doctype node.
140
- */
101
+ /* Transform a doctype. */
141
102
function doctype ( ast ) {
142
103
return {
143
104
type : 'doctype' ,
@@ -147,33 +108,17 @@ function doctype(ast) {
147
108
} ;
148
109
}
149
110
150
- /**
151
- * Transform a text.
152
- *
153
- * @param {ASTNode.<Text> } ast - Parse5 text.
154
- * @return {HASTText } - Text node.
155
- */
111
+ /* Transform a text. */
156
112
function text ( ast ) {
157
113
return { type : 'text' , value : ast . value } ;
158
114
}
159
115
160
- /**
161
- * Transform a comment.
162
- *
163
- * @param {ASTNode.<Comment> } ast - Parse5 comment.
164
- * @return {HASTComment } - Comment node.
165
- */
116
+ /* Transform a comment. */
166
117
function comment ( ast ) {
167
118
return { type : 'comment' , value : ast . data } ;
168
119
}
169
120
170
- /**
171
- * Transform an element.
172
- *
173
- * @param {ASTNode.<Element> } ast - Parse5 element.
174
- * @param {Array.<ASTNode> } children - Children of `ast`.
175
- * @return {HASTElement } - Element node.
176
- */
121
+ /* Transform an element. */
177
122
function element ( ast , children ) {
178
123
var props = { } ;
179
124
var values = ast . attrs ;
@@ -189,29 +134,15 @@ function element(ast, children) {
189
134
return h ( ast . tagName , props , children ) ;
190
135
}
191
136
192
- /**
193
- * Create clean positional information.
194
- *
195
- * @param {Function } toPosition - Offset to position.
196
- * @param {Object? } [dirty] - Parse5 location information.
197
- * @return {Location } - Start and end positions.
198
- */
137
+ /* Create clean positional information. */
199
138
function loc ( toPosition , dirty ) {
200
139
return {
201
140
start : toPosition ( dirty . startOffset ) ,
202
141
end : toPosition ( dirty . endOffset )
203
142
} ;
204
143
}
205
144
206
- /**
207
- * Create clean positional information.
208
- *
209
- * @param {Object } info - Parse5 location information.
210
- * @param {HASTNode } node - HAST node.
211
- * @param {Object } ast - Parse5 node.
212
- * @param {Object } config - Options.
213
- * @return {Location } - Start and end positions.
214
- */
145
+ /* Create clean positional information. */
215
146
function location ( info , ast , node , config ) {
216
147
var start = info . startOffset ;
217
148
var end = info . endOffset ;
0 commit comments