diff --git a/src/vdom/vdom.ts b/src/vdom/vdom.ts index 6d45521b..39bc6e7e 100644 --- a/src/vdom/vdom.ts +++ b/src/vdom/vdom.ts @@ -176,18 +176,10 @@ export function init(modules: Array>, domApi?: DOMAPI) { } vnode.elm = api.createComment(vnode.text as string); } else if (sel !== undefined) { - // Parse selector - const hashIdx = sel.indexOf("#"); - const dotIdx = sel.indexOf(".", hashIdx); - const hash = hashIdx > 0 ? hashIdx : sel.length; - const dot = dotIdx > 0 ? dotIdx : sel.length; - const tag = hashIdx !== -1 || dotIdx !== -1 ? sel.slice(0, Math.min(hash, dot)) : sel; const elm = (vnode.elm = isDef(data) && isDef((i = (data as VNodeData).ns)) - ? api.createElementNS(i, tag) - : api.createElement(tag)); - if (hash < dot) elm.setAttribute("id", sel.slice(hash + 1, dot)); - if (dotIdx > 0) elm.setAttribute("class", sel.slice(dot + 1).replace(/\./g, " ")); + ? api.createElementNS(i, sel) + : api.createElement(sel)); for (i = 0, iLen = cbs.create.length; i < iLen; ++i) cbs.create[i](emptyNode, vnode); if (array(children)) { for (i = 0, iLen = children.length; i < iLen; ++i) { diff --git a/tests/vdom.test.ts b/tests/vdom.test.ts index 8803a6c9..1c66a955 100644 --- a/tests/vdom.test.ts +++ b/tests/vdom.test.ts @@ -185,20 +185,6 @@ describe("snabbdom", function() { expect(elm.tagName).toBe("DIV"); }); - test("has different tag and id", function() { - let elm: any = document.createElement("div"); - vnode0.appendChild(elm); - const vnode1 = h("span#id"); - elm = patch(elm, vnode1).elm; - expect(elm.tagName).toBe("SPAN"); - expect(elm.id).toBe("id"); - }); - - test("has id", function() { - elm = patch(vnode0, h("div", [h("div#unique")])).elm; - expect(elm.firstChild.id).toBe("unique"); - }); - test("has correct namespace", function() { const SVGNamespace = "http://www.w3.org/2000/svg"; const XHTMLNamespace = "http://www.w3.org/1999/xhtml"; @@ -218,20 +204,6 @@ describe("snabbdom", function() { expect(elm.firstChild.firstChild.namespaceURI).toBe(XHTMLNamespace); }); - test("receives classes in selector", function() { - elm = patch(vnode0, h("div", [h("i.am.a.class")])).elm; - expect(elm.firstChild.classList.contains("am")).toBeTruthy(); - expect(elm.firstChild.classList.contains("a")).toBeTruthy(); - expect(elm.firstChild.classList.contains("class")).toBeTruthy(); - }); - - test("receives classes in selector when namespaced", function() { - elm = patch(vnode0, h("svg", [h("g.am.a.class.too")])).elm; - expect(elm.firstChild.classList.contains("am")).toBeTruthy(); - expect(elm.firstChild.classList.contains("a")).toBeTruthy(); - expect(elm.firstChild.classList.contains("class")).toBeTruthy(); - }); - test("can create elements with text content", function() { elm = patch(vnode0, h("div", ["I am a string"])).elm; expect(elm.innerHTML).toBe("I am a string"); @@ -268,26 +240,6 @@ describe("snabbdom", function() { }); describe("patching an element", function() { - test("changes the elements classes", function() { - const vnode1 = h("i.i.am.horse"); - const vnode2 = h("i.i.am"); - patch(vnode0, vnode1); - elm = patch(vnode1, vnode2).elm; - expect(elm.classList.contains("i")).toBeTruthy(); - expect(elm.classList.contains("am")).toBeTruthy(); - expect(!elm.classList.contains("horse")).toBeTruthy(); - }); - - test("removes missing classes", function() { - const vnode1 = h("i.i.am.horse"); - const vnode2 = h("i.i.am"); - patch(vnode0, vnode1); - elm = patch(vnode1, vnode2).elm; - expect(elm.classList.contains("i")).toBeTruthy(); - expect(elm.classList.contains("am")).toBeTruthy(); - expect(!elm.classList.contains("horse")).toBeTruthy(); - }); - test("changes an elements props", function() { const vnode1 = h("a", { props: { src: "http://other/" } }); const vnode2 = h("a", { props: { src: "http://localhost/" } });