1
1
/**
2
- * @typedef {import('../types.js ').State } State
3
- * @typedef {import('../types.js ').Parents } Parents
4
- * @typedef {import('../types.js ').Element } Element
5
- * @typedef { import('../types.js').Properties } Properties
6
- * @typedef {import('../types .js').PropertyValue } PropertyValue
2
+ * @typedef {import('hast ').Element } Element
3
+ * @typedef {import('hast ').Parents } Parents
4
+ * @typedef {import('hast ').Properties } Properties
5
+ *
6
+ * @typedef {import('../index .js').State } State
7
7
*/
8
8
9
9
import { ccount } from 'ccount'
10
10
import { stringify as commas } from 'comma-separated-tokens'
11
- import { svg , find } from 'property-information'
11
+ import { find , svg } from 'property-information'
12
12
import { stringify as spaces } from 'space-separated-tokens'
13
13
import { stringifyEntities } from 'stringify-entities'
14
- import { opening } from '../omission/opening.js'
15
14
import { closing } from '../omission/closing.js'
15
+ import { opening } from '../omission/opening.js'
16
16
17
17
/**
18
18
* Maps of subsets.
@@ -21,7 +21,7 @@ import {closing} from '../omission/closing.js'
21
21
* The value at `0` causes parse errors, the value at `1` is valid.
22
22
* Of both, the value at `0` is unsafe, and the value at `1` is safe.
23
23
*
24
- * @type {Record<'name ' | 'unquoted ' | 'single' | 'double ', Array<[Array<string>, Array<string>]>> }
24
+ * @type {Record<'double ' | 'name ' | 'single' | 'unquoted ', Array<[Array<string>, Array<string>]>> }
25
25
*/
26
26
const constants = {
27
27
// See: <https://html.spec.whatwg.org/#attribute-name-state>.
@@ -60,7 +60,6 @@ const constants = {
60
60
* @returns {string }
61
61
* Serialized node.
62
62
*/
63
- // eslint-disable-next-line complexity
64
63
export function element ( node , index , parent , state ) {
65
64
const schema = state . schema
66
65
const omit = schema . space === 'svg' ? false : state . settings . omitOptionalTags
@@ -138,7 +137,7 @@ function serializeAttributes(state, props) {
138
137
139
138
if ( props ) {
140
139
for ( key in props ) {
141
- if ( props [ key ] !== undefined && props [ key ] !== null ) {
140
+ if ( props [ key ] !== null && props [ key ] !== undefined ) {
142
141
const value = serializeAttribute ( state , key , props [ key ] )
143
142
if ( value ) values . push ( value )
144
143
}
@@ -148,7 +147,7 @@ function serializeAttributes(state, props) {
148
147
while ( ++ index < values . length ) {
149
148
const last = state . settings . tightAttributes
150
149
? values [ index ] . charAt ( values [ index ] . length - 1 )
151
- : null
150
+ : undefined
152
151
153
152
// In tight mode, don’t add a space after quoted attributes.
154
153
if ( index !== values . length - 1 && last !== '"' && last !== "'" ) {
@@ -162,10 +161,9 @@ function serializeAttributes(state, props) {
162
161
/**
163
162
* @param {State } state
164
163
* @param {string } key
165
- * @param {PropertyValue } value
164
+ * @param {Properties[keyof Properties] } value
166
165
* @returns {string }
167
166
*/
168
- // eslint-disable-next-line complexity
169
167
function serializeAttribute ( state , key , value ) {
170
168
const info = find ( state . schema , key )
171
169
const x =
@@ -185,8 +183,8 @@ function serializeAttribute(state, key, value) {
185
183
}
186
184
187
185
if (
188
- value === undefined ||
189
186
value === null ||
187
+ value === undefined ||
190
188
value === false ||
191
189
( typeof value === 'number' && Number . isNaN ( value ) )
192
190
) {
@@ -235,8 +233,8 @@ function serializeAttribute(state, key, value) {
235
233
result = stringifyEntities (
236
234
value ,
237
235
Object . assign ( { } , state . settings . characterReferences , {
238
- subset : constants . unquoted [ x ] [ y ] ,
239
- attribute : true
236
+ attribute : true ,
237
+ subset : constants . unquoted [ x ] [ y ]
240
238
} )
241
239
)
242
240
}
0 commit comments