1- 'use strict'
2-
3- module . exports = x
4-
51// Creating xast elements.
6- function x ( name , attributes ) {
2+ export function x ( name , attributes ) {
73 var node =
8- name == null
4+ name === undefined || name === null
95 ? { type : 'root' , children : [ ] }
10- : { type : 'element' , name : name , attributes : { } , children : [ ] }
6+ : { type : 'element' , name, attributes : { } , children : [ ] }
117 var index = 1
128 var key
139
14- if ( name != null && typeof name !== 'string' ) {
10+ if ( name !== undefined && name !== null && typeof name !== 'string' ) {
1511 throw new Error ( 'Expected element name, got `' + name + '`' )
1612 }
1713
1814 // Handle props.
1915 if ( attributes ) {
2016 if (
21- name == null ||
17+ name === undefined ||
18+ name === null ||
2219 typeof attributes === 'string' ||
2320 typeof attributes === 'number' ||
2421 'length' in attributes
@@ -28,7 +25,12 @@ function x(name, attributes) {
2825 } else {
2926 for ( key in attributes ) {
3027 // Ignore nullish and NaN values.
31- if ( attributes [ key ] != null && attributes [ key ] === attributes [ key ] ) {
28+ if (
29+ attributes [ key ] !== undefined &&
30+ attributes [ key ] !== null &&
31+ ( typeof attributes [ key ] !== 'number' ||
32+ ! Number . isNaN ( attributes [ key ] ) )
33+ ) {
3234 node . attributes [ key ] = String ( attributes [ key ] )
3335 }
3436 }
@@ -46,7 +48,7 @@ function x(name, attributes) {
4648function addChild ( nodes , value ) {
4749 var index = - 1
4850
49- if ( value == null ) {
51+ if ( value === undefined || value === null ) {
5052 // Empty.
5153 } else if ( typeof value === 'string' || typeof value === 'number' ) {
5254 nodes . push ( { type : 'text' , value : String ( value ) } )
0 commit comments