@@ -48,10 +48,10 @@ import {html, svg, find} from 'property-information'
48
48
import vfileLocation from 'vfile-location'
49
49
import { webNamespaces } from 'web-namespaces'
50
50
51
- var own = { } . hasOwnProperty
51
+ const own = { } . hasOwnProperty
52
52
53
53
// Handlers.
54
- var map = {
54
+ const map = {
55
55
'#document' : root ,
56
56
'#document-fragment' : root ,
57
57
'#text' : text ,
@@ -67,9 +67,9 @@ var map = {
67
67
*/
68
68
export function fromParse5 ( ast , options = { } ) {
69
69
/** @type {Options } */
70
- var settings
70
+ let settings
71
71
/** @type {VFile } */
72
- var file
72
+ let file
73
73
74
74
if ( isFile ( options ) ) {
75
75
file = options
@@ -98,15 +98,11 @@ export function fromParse5(ast, options = {}) {
98
98
* @returns {Node }
99
99
*/
100
100
function transform ( ctx , ast ) {
101
- var schema = ctx . schema
101
+ const schema = ctx . schema
102
102
/** @type {Handler } */
103
- var fn = own . call ( map , ast . nodeName ) ? map [ ast . nodeName ] : element
103
+ const fn = own . call ( map , ast . nodeName ) ? map [ ast . nodeName ] : element
104
104
/** @type {Array.<Child> } */
105
- var children
106
- /** @type {Node } */
107
- var result
108
- /** @type {Position } */
109
- var position
105
+ let children
110
106
111
107
// Element.
112
108
if ( 'tagName' in ast ) {
@@ -117,11 +113,11 @@ function transform(ctx, ast) {
117
113
children = nodes ( ctx , ast . childNodes )
118
114
}
119
115
120
- result = fn ( ctx , ast , children )
116
+ const result = fn ( ctx , ast , children )
121
117
122
118
if ( 'sourceCodeLocation' in ast && ast . sourceCodeLocation && ctx . file ) {
123
119
// @ts -ignore It’s fine.
124
- position = location ( ctx , result , ast . sourceCodeLocation )
120
+ const position = location ( ctx , result , ast . sourceCodeLocation )
125
121
126
122
if ( position ) {
127
123
ctx . location = true
@@ -142,9 +138,9 @@ function transform(ctx, ast) {
142
138
* @returns {Array.<Child> }
143
139
*/
144
140
function nodes ( ctx , children ) {
145
- var index = - 1
141
+ let index = - 1
146
142
/** @type {Array.<Child> } */
147
- var result = [ ]
143
+ const result = [ ]
148
144
149
145
while ( ++ index < children . length ) {
150
146
// @ts -ignore Assume no roots in children.
@@ -165,19 +161,15 @@ function nodes(ctx, children) {
165
161
*/
166
162
function root ( ctx , ast , children ) {
167
163
/** @type {Root } */
168
- var result = {
164
+ const result = {
169
165
type : 'root' ,
170
166
children,
171
167
data : { quirksMode : ast . mode === 'quirks' || ast . mode === 'limited-quirks' }
172
168
}
173
- /** @type {string } */
174
- var doc
175
- /** @type {VFileLocation } */
176
- var location
177
169
178
170
if ( ctx . file && ctx . location ) {
179
- doc = String ( ctx . file )
180
- location = vfileLocation ( doc )
171
+ const doc = String ( ctx . file )
172
+ const location = vfileLocation ( doc )
181
173
result . position = {
182
174
start : location . toPoint ( 0 ) ,
183
175
end : location . toPoint ( doc . length )
@@ -229,34 +221,24 @@ function comment(_, ast) {
229
221
* @returns {Element }
230
222
*/
231
223
function element ( ctx , ast , children ) {
232
- var fn = ctx . schema . space === 'svg' ? s : h
233
- var index = - 1
224
+ const fn = ctx . schema . space === 'svg' ? s : h
225
+ let index = - 1
234
226
/** @type {Object.<string, string> } */
235
- var props = { }
236
- /** @type {Element } */
237
- var result
238
- /** @type {P5Attribute } */
239
- var attribute
240
- /** @type {P5ElementLocation } */
241
- var pos
242
- /** @type {Point } */
243
- var start
244
- /** @type {Point } */
245
- var end
227
+ const props = { }
246
228
247
229
while ( ++ index < ast . attrs . length ) {
248
- attribute = ast . attrs [ index ]
230
+ const attribute = ast . attrs [ index ]
249
231
props [ ( attribute . prefix ? attribute . prefix + ':' : '' ) + attribute . name ] =
250
232
attribute . value
251
233
}
252
234
253
- result = fn ( ast . tagName , props , children )
235
+ const result = fn ( ast . tagName , props , children )
254
236
255
237
if ( result . tagName === 'template' && 'content' in ast ) {
256
238
// @ts -ignore Types are wrong.
257
- pos = ast . sourceCodeLocation
258
- start = pos && pos . startTag && position ( pos . startTag ) . end
259
- end = pos && pos . endTag && position ( pos . endTag ) . start
239
+ const pos = ast . sourceCodeLocation
240
+ const start = pos && pos . startTag && position ( pos . startTag ) . end
241
+ const end = pos && pos . endTag && position ( pos . endTag ) . start
260
242
261
243
// @ts -ignore Types are wrong.
262
244
result . content = transform ( ctx , ast . content )
@@ -278,16 +260,10 @@ function element(ctx, ast, children) {
278
260
* @returns {Position }
279
261
*/
280
262
function location ( ctx , node , location ) {
281
- var result = position ( location )
282
- /** @type {ElementChild } */
283
- var tail
284
- /** @type {string } */
285
- var key
286
- /** @type {Object.<string, Position> } */
287
- var props
263
+ const result = position ( location )
288
264
289
265
if ( node . type === 'element' ) {
290
- tail = node . children [ node . children . length - 1 ]
266
+ const tail = node . children [ node . children . length - 1 ]
291
267
292
268
// Bug for unclosed with children.
293
269
// See: <https://github.com/inikulin/parse5/issues/109>.
@@ -296,7 +272,10 @@ function location(ctx, node, location) {
296
272
}
297
273
298
274
if ( ctx . verbose ) {
299
- props = { }
275
+ /** @type {Object.<string, Position> } */
276
+ const props = { }
277
+ /** @type {string } */
278
+ let key
300
279
301
280
for ( key in location . attrs ) {
302
281
if ( own . call ( location . attrs , key ) ) {
@@ -322,12 +301,12 @@ function location(ctx, node, location) {
322
301
* @returns {Position|null }
323
302
*/
324
303
function position ( loc ) {
325
- var start = point ( {
304
+ const start = point ( {
326
305
line : loc . startLine ,
327
306
column : loc . startCol ,
328
307
offset : loc . startOffset
329
308
} )
330
- var end = point ( {
309
+ const end = point ( {
331
310
line : loc . endLine ,
332
311
column : loc . endCol ,
333
312
offset : loc . endOffset
0 commit comments