1- 'use strict'
2-
3- var xtend = require ( 'xtend' )
4- var html = require ( 'property-information/html' )
5- var svg = require ( 'property-information/svg' )
6- var find = require ( 'property-information/find' )
7- var toH = require ( 'hast-to-hyperscript' )
8- var ns = require ( 'web-namespaces' )
9- var zwitch = require ( 'zwitch' )
10-
11- module . exports = toParse5
12-
13- var one = zwitch ( 'type' , {
14- handlers : {
15- root : root ,
16- element : element ,
17- text : text ,
18- comment : comment ,
19- doctype : doctype
20- }
21- } )
1+ import { html , svg , find } from 'property-information'
2+ import { toH } from 'hast-to-hyperscript'
3+ import { webNamespaces } from 'web-namespaces'
4+ import { zwitch } from 'zwitch'
5+
6+ var own = { } . hasOwnProperty
7+
8+ var one = zwitch ( 'type' , { handlers : { root, element, text, comment, doctype} } )
229
2310// Transform a tree from hast to Parse5’s AST.
24- function toParse5 ( tree , space ) {
11+ export function toParse5 ( tree , space ) {
2512 return one ( tree , space === 'svg' ? svg : html )
2613}
2714
@@ -62,7 +49,7 @@ function comment(node, schema) {
6249}
6350
6451function element ( node , schema ) {
65- return toH ( h , xtend ( node , { children : [ ] } ) , { space : schema . space } )
52+ return toH ( h , Object . assign ( { } , node , { children : [ ] } ) , { space : schema . space } )
6653
6754 function h ( name , attrs ) {
6855 var values = [ ]
@@ -73,9 +60,13 @@ function element(node, schema) {
7360 var p5
7461
7562 for ( key in attrs ) {
63+ if ( ! own . call ( attrs , key ) || attrs [ key ] === false ) {
64+ continue
65+ }
66+
7667 info = find ( schema , key )
7768
78- if ( attrs [ key ] === false || ( info . boolean && ! attrs [ key ] ) ) {
69+ if ( info . boolean && ! attrs [ key ] ) {
7970 continue
8071 }
8172
@@ -91,7 +82,7 @@ function element(node, schema) {
9182 value . prefix = key . slice ( 0 , index )
9283 }
9384
94- value . namespace = ns [ info . space ]
85+ value . namespace = webNamespaces [ info . space ]
9586 }
9687
9788 values . push ( value )
@@ -115,7 +106,7 @@ function patch(node, p5, parentSchema) {
115106
116107 if ( node . type === 'element' ) {
117108 if ( schema . space === 'html' && node . tagName === 'svg' ) schema = svg
118- p5 . namespaceURI = ns [ schema . space ]
109+ p5 . namespaceURI = webNamespaces [ schema . space ]
119110 }
120111
121112 if ( node . type === 'element' || node . type === 'root' ) {
0 commit comments