Skip to content
This repository was archived by the owner on Aug 9, 2023. It is now read-only.

Commit 54a9aa7

Browse files
committed
Add support for false, falsey boolean props
Closes GH-14.
1 parent 75849d1 commit 54a9aa7

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,19 @@ function toH(h, node, ctx) {
140140
}
141141

142142
function addAttribute(props, prop, value, ctx) {
143+
var hyperlike = ctx.hyperscript || ctx.vdom
143144
var schema = ctx.schema
144145
var info = find(schema, prop)
145146
var subprop
146147

147-
// Ignore nully, `false`, `NaN`, and falsey known booleans.
148+
// Ignore nully and `NaN` values.
149+
// Ignore `false` and falsey known booleans for hyperlike DSLs.
148150
if (
149151
value === null ||
150152
value === undefined ||
151-
value === false ||
152153
value !== value ||
153-
(info.boolean && !value)
154+
(hyperlike && value === false) ||
155+
(hyperlike && info.boolean && !value)
154156
) {
155157
return
156158
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
"rules": {
7979
"unicorn/prefer-type-error": "off",
8080
"guard-for-in": "off",
81-
"no-self-compare": "off"
81+
"no-self-compare": "off",
82+
"complexity": "off"
8283
}
8384
},
8485
"remarkConfig": {

test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ test('hast-to-hyperscript', function(t) {
275275
{
276276
key: 'h-3',
277277
style: {color: 'red'},
278+
ignored: false,
279+
disabled: 0,
278280
foo: 'bar',
279281
camelCase: 'on off',
280282
'data-123': '456',
@@ -341,6 +343,8 @@ test('hast-to-hyperscript', function(t) {
341343
{
342344
key: 'h-3',
343345
style: {color: 'red'},
346+
ignored: false,
347+
disabled: 0,
344348
foo: 'bar',
345349
camelCase: 'on off',
346350
'data-123': '456',

0 commit comments

Comments
 (0)