@@ -32,9 +32,9 @@ import {toH} from 'hast-to-hyperscript'
3232import { webNamespaces } from 'web-namespaces'
3333import { zwitch } from 'zwitch'
3434
35- var own = { } . hasOwnProperty
35+ const own = { } . hasOwnProperty
3636
37- var one = zwitch ( 'type' , { handlers : { root, element, text, comment, doctype} } )
37+ const one = zwitch ( 'type' , { handlers : { root, element, text, comment, doctype} } )
3838
3939/**
4040 * Transform a tree from hast to Parse5’s AST.
@@ -55,7 +55,7 @@ export function toParse5(tree, space) {
5555 */
5656function root ( node , schema ) {
5757 /** @type {P5Document } */
58- var p5 = {
58+ const p5 = {
5959 nodeName : '#document' ,
6060 mode : ( node . data || { } ) . quirksMode ? 'quirks' : 'no-quirks' ,
6161 childNodes : [ ]
@@ -72,7 +72,7 @@ function root(node, schema) {
7272 */
7373function fragment ( node , schema ) {
7474 /** @type {P5Fragment } */
75- var p5 = { nodeName : '#document-fragment' , childNodes : [ ] }
75+ const p5 = { nodeName : '#document-fragment' , childNodes : [ ] }
7676 // @ts -ignore Assume correct children.
7777 p5 . childNodes = all ( node . children , p5 , schema )
7878 return patch ( node , p5 )
@@ -127,7 +127,7 @@ function comment(node) {
127127function element ( node , schema ) {
128128 /** @type {Space } */
129129 // @ts -ignore Assume space.
130- var space = schema . space
130+ const space = schema . space
131131 return toH ( h , Object . assign ( { } , node , { children : [ ] } ) , { space} )
132132
133133 /**
@@ -136,33 +136,29 @@ function element(node, schema) {
136136 */
137137 function h ( name , attrs ) {
138138 /** @type {Array.<P5Attribute> } */
139- var values = [ ]
140- /** @type {Info } */
141- var info
142- /** @type {P5Attribute } */
143- var value
139+ const values = [ ]
144140 /** @type {string } */
145- var key
146- /** @type {number } */
147- var index
148- /** @type {P5Element } */
149- var p5
141+ let key
150142
151143 for ( key in attrs ) {
152144 if ( ! own . call ( attrs , key ) || attrs [ key ] === false ) {
153145 continue
154146 }
155147
156- info = find ( schema , key )
148+ const info = find ( schema , key )
157149
158150 if ( info . boolean && ! attrs [ key ] ) {
159151 continue
160152 }
161153
162- value = { name : key , value : attrs [ key ] === true ? '' : String ( attrs [ key ] ) }
154+ /** @type {P5Attribute } */
155+ const value = {
156+ name : key ,
157+ value : attrs [ key ] === true ? '' : String ( attrs [ key ] )
158+ }
163159
164160 if ( info . space && info . space !== 'html' && info . space !== 'svg' ) {
165- index = key . indexOf ( ':' )
161+ const index = key . indexOf ( ':' )
166162
167163 if ( index < 0 ) {
168164 value . prefix = ''
@@ -179,7 +175,8 @@ function element(node, schema) {
179175
180176 if ( schema . space === 'html' && node . tagName === 'svg' ) schema = svg
181177
182- p5 = patch ( node , {
178+ /** @type {P5Element } */
179+ const p5 = patch ( node , {
183180 nodeName : name ,
184181 tagName : name ,
185182 attrs : values ,
@@ -205,16 +202,15 @@ function element(node, schema) {
205202 * @returns {Array.<P5Child> }
206203 */
207204function all ( children , p5 , schema ) {
208- var index = - 1
205+ let index = - 1
209206 /** @type {Array.<P5Child> } */
210- var result = [ ]
211- /** @type {P5Child } */
212- var child
207+ const result = [ ]
213208
214209 if ( children ) {
215210 while ( ++ index < children . length ) {
211+ /** @type {P5Child } */
216212 // @ts -ignore Assume child.
217- child = one ( children [ index ] , schema )
213+ const child = one ( children [ index ] , schema )
218214
219215 // @ts -ignore types are wrong.
220216 child . parentNode = p5
@@ -235,7 +231,7 @@ function all(children, p5, schema) {
235231 * @returns {T }
236232 */
237233function patch ( node , p5 ) {
238- var position = node . position
234+ const position = node . position
239235
240236 if ( position && position . start && position . end ) {
241237 // @ts -ignore Types are wrong.
0 commit comments