1- 'use strict'
2-
3- var html = require ( 'property-information/html' )
4- var svg = require ( 'property-information/svg' )
5- var find = require ( 'property-information/find' )
6- var hastToReact = require ( 'property-information/hast-to-react.json' )
7- var spaces = require ( 'space-separated-tokens' )
8- var commas = require ( 'comma-separated-tokens' )
9- var style = require ( 'style-to-object' )
10- var ns = require ( 'web-namespaces' )
11- var convert = require ( 'unist-util-is/convert' )
1+ import { html , svg , find , hastToReact } from 'property-information'
2+ import { stringify as spaces } from 'space-separated-tokens'
3+ import { stringify as commas } from 'comma-separated-tokens'
4+ import style from 'style-to-object'
5+ import { webNamespaces as ns } from 'web-namespaces'
6+ import { convert } from 'unist-util-is'
7+
8+ var own = { } . hasOwnProperty
129
1310var root = convert ( 'root' )
1411var element = convert ( 'element' )
1512var text = convert ( 'text' )
1613
17- module . exports = wrapper
18-
19- function wrapper ( h , node , options ) {
14+ export function toH ( h , node , options ) {
2015 var settings = options || { }
2116 var r = react ( h )
2217 var v = vue ( h )
2318 var vd = vdom ( h )
2419 var prefix
2520
2621 if ( typeof h !== 'function' ) {
27- throw new Error ( 'h is not a function' )
22+ throw new TypeError ( 'h is not a function' )
2823 }
2924
3025 if ( typeof settings === 'string' || typeof settings === 'boolean' ) {
@@ -50,9 +45,14 @@ function wrapper(h, node, options) {
5045 )
5146 }
5247
53- return toH ( h , node , {
48+ return transform ( h , node , {
5449 schema : settings . space === 'svg' ? svg : html ,
55- prefix : prefix == null ? ( r || v || vd ? 'h-' : null ) : prefix ,
50+ prefix :
51+ prefix === undefined || prefix === null
52+ ? r || v || vd
53+ ? 'h-'
54+ : null
55+ : prefix ,
5656 key : 0 ,
5757 react : r ,
5858 vue : v ,
@@ -62,7 +62,7 @@ function wrapper(h, node, options) {
6262}
6363
6464// Transform a hast node through a hyperscript interface to *anything*!
65- function toH ( h , node , ctx ) {
65+ function transform ( h , node , ctx ) {
6666 var parentSchema = ctx . schema
6767 var schema = parentSchema
6868 var name = node . tagName
@@ -78,7 +78,9 @@ function toH(h, node, ctx) {
7878 }
7979
8080 for ( key in node . properties ) {
81- addAttribute ( attributes , key , node . properties [ key ] , ctx , name )
81+ if ( own . call ( node . properties , key ) ) {
82+ addAttribute ( attributes , key , node . properties [ key ] , ctx , name )
83+ }
8284 }
8385
8486 if ( ctx . vdom ) {
@@ -99,7 +101,7 @@ function toH(h, node, ctx) {
99101 value = node . children [ index ]
100102
101103 if ( element ( value ) ) {
102- nodes . push ( toH ( h , value , ctx ) )
104+ nodes . push ( transform ( h , value , ctx ) )
103105 } else if ( text ( value ) ) {
104106 nodes . push ( value . value )
105107 }
@@ -111,20 +113,22 @@ function toH(h, node, ctx) {
111113
112114 // Ensure no React warnings are triggered for void elements having children
113115 // passed in.
114- return nodes . length
116+ return nodes . length > 0
115117 ? h . call ( node , name , attributes , nodes )
116118 : h . call ( node , name , attributes )
117119}
118120
121+ // eslint-disable-next-line complexity, max-params
119122function addAttribute ( props , prop , value , ctx , name ) {
120123 var info = find ( ctx . schema , prop )
121124 var subprop
122125
123126 // Ignore nullish and `NaN` values.
124127 // Ignore `false` and falsey known booleans for hyperlike DSLs.
125128 if (
126- value == null ||
127- value !== value ||
129+ value === undefined ||
130+ value === null ||
131+ ( typeof value === 'number' && Number . isNaN ( value ) ) ||
128132 ( value === false && ( ctx . vue || ctx . vdom || ctx . hyperscript ) ) ||
129133 ( ! value && info . boolean && ( ctx . vue || ctx . vdom || ctx . hyperscript ) )
130134 ) {
@@ -134,7 +138,7 @@ function addAttribute(props, prop, value, ctx, name) {
134138 if ( value && typeof value === 'object' && 'length' in value ) {
135139 // Accept `array`.
136140 // Most props are space-separated.
137- value = ( info . commaSeparated ? commas : spaces ) . stringify ( value )
141+ value = info . commaSeparated ? commas ( value ) : spaces ( value )
138142 }
139143
140144 // Treat `true` and truthy known booleans.
@@ -175,7 +179,9 @@ function addAttribute(props, prop, value, ctx, name) {
175179function react ( h ) {
176180 var node = h && h ( 'div' )
177181 return Boolean (
178- node && ( '_owner' in node || '_store' in node ) && node . key == null
182+ node &&
183+ ( '_owner' in node || '_store' in node ) &&
184+ ( node . key === undefined || node . key === null )
179185 )
180186}
181187
0 commit comments