From 8bf3669c4edc175c9912543f10ddb9113807f395 Mon Sep 17 00:00:00 2001 From: Michael Rawlings Date: Tue, 26 Nov 2019 13:51:22 -0800 Subject: [PATCH] fix: html normalization --- src/index.ts | 8 +++++--- test/components/container/fixtures/template.html | 5 +++++ test/components/container/fixtures/template.marko | 5 +++++ test/components/hello/index.marko | 1 + test/index.test.ts | 8 ++++++++ 5 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 test/components/container/fixtures/template.html create mode 100644 test/components/container/fixtures/template.marko diff --git a/src/index.ts b/src/index.ts index 15190c7..5d7185e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -103,17 +103,19 @@ export function defaultNormalizer(container: ContainerNode) { const document = container.ownerDocument!; const treeWalker = document.createTreeWalker( clone, - SHOW_ELEMENT & SHOW_COMMENT + SHOW_ELEMENT | SHOW_COMMENT ); let node: Comment | Element; - while ((node = treeWalker.nextNode() as Comment | Element)) { + let nextNode = treeWalker.nextNode(); + while ((node = nextNode as Comment | Element)) { + nextNode = treeWalker.nextNode(); if (node.nodeType === COMMENT_NODE) { (node as Comment).remove(); } else { Array.from((node as Element).attributes) .map(attr => attr.name) - .filter(attrName => /^data-(w-|widget$|marko$)/.test(attrName)) + .filter(attrName => /^data-(w-|widget$|marko(-|$))/.test(attrName)) .forEach(attrName => (node as Element).removeAttribute(attrName)); } } diff --git a/test/components/container/fixtures/template.html b/test/components/container/fixtures/template.html new file mode 100644 index 0000000..acf3beb --- /dev/null +++ b/test/components/container/fixtures/template.html @@ -0,0 +1,5 @@ +
+ Hello worldfoo +
\ No newline at end of file diff --git a/test/components/container/fixtures/template.marko b/test/components/container/fixtures/template.marko new file mode 100644 index 0000000..df4dc16 --- /dev/null +++ b/test/components/container/fixtures/template.marko @@ -0,0 +1,5 @@ +class {} + + + Hello world + \ No newline at end of file diff --git a/test/components/hello/index.marko b/test/components/hello/index.marko index cad8fcc..dc0efae 100644 --- a/test/components/hello/index.marko +++ b/test/components/hello/index.marko @@ -1 +1,2 @@ +class {}
Hello ${input.name}!
\ No newline at end of file diff --git a/test/index.test.ts b/test/index.test.ts index c9a121e..441b018 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -74,6 +74,14 @@ describe("findProjectFixtures", () => { "render": [Function], "toString": [Function], }, + "template": Object { + "ext": ".marko", + "fixture": [Component "(cwd)/test/components/container/fixtures/template.marko"], + "name": "template", + "path": "(cwd)/test/components/container/fixtures/template.marko", + "render": [Function], + "toString": [Function], + }, }, "fixturesPath": "(cwd)/test/components/container/fixtures", "name": "container",