From b5daafe205b3eb069e91bafc0e1cda10beb317fe Mon Sep 17 00:00:00 2001 From: Titus Date: Tue, 23 Apr 2019 15:54:01 +0200 Subject: [PATCH] Add support for `false`, falsey boolean props Closes GH-14. Closes GH-16. Reviewed-by: Christian Murphy --- index.js | 8 +++++--- package.json | 3 ++- test.js | 4 ++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index cdfdcda..55758fe 100644 --- a/index.js +++ b/index.js @@ -140,17 +140,19 @@ function toH(h, node, ctx) { } function addAttribute(props, prop, value, ctx) { + var hyperlike = ctx.hyperscript || ctx.vdom var schema = ctx.schema var info = find(schema, prop) var subprop - // Ignore nully, `false`, `NaN`, and falsey known booleans. + // Ignore nully and `NaN` values. + // Ignore `false` and falsey known booleans for hyperlike DSLs. if ( value === null || value === undefined || - value === false || value !== value || - (info.boolean && !value) + (hyperlike && value === false) || + (hyperlike && info.boolean && !value) ) { return } diff --git a/package.json b/package.json index 0cd6317..3737d63 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,8 @@ "rules": { "unicorn/prefer-type-error": "off", "guard-for-in": "off", - "no-self-compare": "off" + "no-self-compare": "off", + "complexity": "off" } }, "remarkConfig": { diff --git a/test.js b/test.js index e959512..9c175e4 100644 --- a/test.js +++ b/test.js @@ -275,6 +275,8 @@ test('hast-to-hyperscript', function(t) { { key: 'h-3', style: {color: 'red'}, + ignored: false, + disabled: 0, foo: 'bar', camelCase: 'on off', 'data-123': '456', @@ -341,6 +343,8 @@ test('hast-to-hyperscript', function(t) { { key: 'h-3', style: {color: 'red'}, + ignored: false, + disabled: 0, foo: 'bar', camelCase: 'on off', 'data-123': '456',