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-
91'use strict' ;
102
113/* Dependencies. */
@@ -27,13 +19,7 @@ var map = {
2719 '#documentType' : doctype
2820} ;
2921
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. */
3723function wrapper ( ast , options ) {
3824 var settings = options || { } ;
3925 var file ;
@@ -53,13 +39,7 @@ function wrapper(ast, options) {
5339 } ) ;
5440}
5541
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. */
6343function transform ( ast , config ) {
6444 var fn = has ( map , ast . nodeName ) ? map [ ast . nodeName ] : element ;
6545 var children ;
@@ -84,13 +64,7 @@ function transform(ast, config) {
8464 return node ;
8565}
8666
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. */
9468function nodes ( children , config ) {
9569 var length = children . length ;
9670 var index = - 1 ;
@@ -103,16 +77,8 @@ function nodes(children, config) {
10377 return result ;
10478}
10579
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`. */
11682function root ( ast , children , config ) {
11783 var node = {
11884 type : 'root' ,
@@ -132,12 +98,7 @@ function root(ast, children, config) {
13298 return node ;
13399}
134100
135- /**
136- * Transform a doctype.
137- *
138- * @param {ASTNode.<DocumentType> } ast - Parse5 doctype.
139- * @return {HASTDoctype } - Doctype node.
140- */
101+ /* Transform a doctype. */
141102function doctype ( ast ) {
142103 return {
143104 type : 'doctype' ,
@@ -147,33 +108,17 @@ function doctype(ast) {
147108 } ;
148109}
149110
150- /**
151- * Transform a text.
152- *
153- * @param {ASTNode.<Text> } ast - Parse5 text.
154- * @return {HASTText } - Text node.
155- */
111+ /* Transform a text. */
156112function text ( ast ) {
157113 return { type : 'text' , value : ast . value } ;
158114}
159115
160- /**
161- * Transform a comment.
162- *
163- * @param {ASTNode.<Comment> } ast - Parse5 comment.
164- * @return {HASTComment } - Comment node.
165- */
116+ /* Transform a comment. */
166117function comment ( ast ) {
167118 return { type : 'comment' , value : ast . data } ;
168119}
169120
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. */
177122function element ( ast , children ) {
178123 var props = { } ;
179124 var values = ast . attrs ;
@@ -189,29 +134,15 @@ function element(ast, children) {
189134 return h ( ast . tagName , props , children ) ;
190135}
191136
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. */
199138function loc ( toPosition , dirty ) {
200139 return {
201140 start : toPosition ( dirty . startOffset ) ,
202141 end : toPosition ( dirty . endOffset )
203142 } ;
204143}
205144
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. */
215146function location ( info , ast , node , config ) {
216147 var start = info . startOffset ;
217148 var end = info . endOffset ;
0 commit comments