@@ -10,7 +10,7 @@ var ccount = require('ccount')
1010var all = require ( './all' )
1111var constants = require ( './constants' )
1212
13- module . exports = element
13+ module . exports = serializeElement
1414
1515var space = ' '
1616var quotationMark = '"'
@@ -20,9 +20,8 @@ var lessThan = '<'
2020var greaterThan = '>'
2121var slash = '/'
2222
23- // Stringify an element `node`.
2423// eslint-disable-next-line complexity
25- function element ( ctx , node , index , parent ) {
24+ function serializeElement ( ctx , node , index , parent ) {
2625 var parentSchema = ctx . schema
2726 var name = node . tagName
2827 var value = ''
@@ -38,7 +37,7 @@ function element(ctx, node, index, parent) {
3837 ctx . schema = svg
3938 }
4039
41- attrs = attributes ( ctx , node . properties )
40+ attrs = serializeAttributes ( ctx , node . properties )
4241
4342 if ( ctx . schema . space === 'svg' ) {
4443 omit = false
@@ -95,8 +94,7 @@ function element(ctx, node, index, parent) {
9594 return value
9695}
9796
98- // Stringify all attributes.
99- function attributes ( ctx , props ) {
97+ function serializeAttributes ( ctx , props ) {
10098 var values = [ ]
10199 var key
102100 var value
@@ -108,11 +106,11 @@ function attributes(ctx, props) {
108106 for ( key in props ) {
109107 value = props [ key ]
110108
111- if ( value == null ) {
109+ if ( value === null || value === undefined ) {
112110 continue
113111 }
114112
115- result = attribute ( ctx , key , value )
113+ result = serializeAttribute ( ctx , key , value )
116114
117115 if ( result ) {
118116 values . push ( result )
@@ -139,8 +137,7 @@ function attributes(ctx, props) {
139137 return values . join ( '' )
140138}
141139
142- // Stringify one attribute.
143- function attribute ( ctx , key , value ) {
140+ function serializeAttribute ( ctx , key , value ) {
144141 var schema = ctx . schema
145142 var info = find ( schema , key )
146143 var name = info . attribute
@@ -155,14 +152,15 @@ function attribute(ctx, key, value) {
155152 }
156153
157154 if (
158- value == null ||
155+ value === null ||
156+ value === undefined ||
159157 value === false ||
160158 ( typeof value === 'number' && isNaN ( value ) )
161159 ) {
162160 return ''
163161 }
164162
165- name = attributeName ( ctx , name )
163+ name = serializeAttributeName ( ctx , name )
166164
167165 if ( value === true ) {
168166 // There is currently only one boolean property in SVG: `[download]` on
@@ -184,20 +182,18 @@ function attribute(ctx, key, value) {
184182 return name
185183 }
186184
187- return name + attributeValue ( ctx , key , value , info )
185+ return name + serializeAttributeValue ( ctx , key , value , info )
188186}
189187
190- // Stringify the attribute name.
191- function attributeName ( ctx , name ) {
188+ function serializeAttributeName ( ctx , name ) {
192189 // Always encode without parse errors in non-HTML.
193190 var valid = ctx . schema . space === 'html' ? ctx . valid : 1
194191 var subset = constants . name [ valid ] [ ctx . safe ]
195192
196193 return entities ( name , xtend ( ctx . entities , { subset : subset } ) )
197194}
198195
199- // Stringify the attribute value.
200- function attributeValue ( ctx , key , value , info ) {
196+ function serializeAttributeValue ( ctx , key , value , info ) {
201197 var options = ctx . entities
202198 var quote = ctx . quote
203199 var alternative = ctx . alternative
0 commit comments