Skip to content

Commit

Permalink
don't allow DocumentFragments as the morph target
Browse files Browse the repository at this point in the history
  • Loading branch information
finnp committed Mar 21, 2018
1 parent 47f9055 commit 7752406
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ function nanomorph (oldTree, newTree) {
// }
assert.equal(typeof oldTree, 'object', 'nanomorph: oldTree should be an object')
assert.equal(typeof newTree, 'object', 'nanomorph: newTree should be an object')
assert.notEqual(
newTree.nodeType,
11,
'nanomorph: newTree should have one root node (which is not a DocumentFragment)'
)

var tree = walk(newTree, oldTree)
// if (DEBUG) console.log('=> morphed\n %s', tree.outerHTML)
return tree
Expand Down
8 changes: 8 additions & 0 deletions test/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,3 +440,11 @@ tape('use id as a key hint', function (t) {
t.end()
})
})

tape('disallow document fragments', function (t) {
var a = html`<div><div>a</div></div>`
var b = html`<div>a</div><div>b</div>`

t.throws(nanomorph.bind(null, a, b), /newTree should have one root node/, 'no fragments')
t.end()
})

0 comments on commit 7752406

Please sign in to comment.