From 63f491db88b975c0e5f6bd69545e4e12a5076dfb Mon Sep 17 00:00:00 2001 From: Barney Carroll Date: Sat, 19 Nov 2016 17:32:36 +0000 Subject: [PATCH 1/2] Initial test case: can't declare class as an attribute in hyperscript selector --- render/tests/test-hyperscript.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/render/tests/test-hyperscript.js b/render/tests/test-hyperscript.js index 07d70281..8237d0ea 100644 --- a/render/tests/test-hyperscript.js +++ b/render/tests/test-hyperscript.js @@ -184,6 +184,11 @@ o.spec("hyperscript", function() { o(vnode.attrs.className).equals("a") }) + o("handles 'class' as a verbose attribute declaration", function() { + var vnode = m("[class=a]") + + o(vnode.attrs.className).equals("a") + }) o("handles merging classes w/ class property", function() { var vnode = m(".a", {class: "b"}) From 6cb9a5cc804155db638fbf3d7df1d090ef342d0f Mon Sep 17 00:00:00 2001 From: Barney Carroll Date: Sat, 19 Nov 2016 17:44:36 +0000 Subject: [PATCH 2/2] Handle [class] selector properly --- render/hyperscript.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/render/hyperscript.js b/render/hyperscript.js index 12fcf0be..28ce0d35 100644 --- a/render/hyperscript.js +++ b/render/hyperscript.js @@ -19,7 +19,8 @@ function hyperscript(selector) { else if (match[3][0] === "[") { var attrValue = match[6] if (attrValue) attrValue = attrValue.replace(/\\(["'])/g, "$1").replace(/\\\\/g, "\\") - attributes[match[4]] = attrValue || true + if (match[4] === "class") classes.push(attrValue) + else attributes[match[4]] = attrValue || true } } if (classes.length > 0) attributes.className = classes.join(" ")