WebReflection / basicHTML

A NodeJS based, standard oriented, HTML implementation.
ISC License
126 stars 10 forks source link

Text and Comment classes should implement `ChildNode` interface? #54

Closed coreyfarrell closed 3 years ago

coreyfarrell commented 3 years ago

I found this while using basichtml for some testing. Minimal failing test case:

const assert = require('assert');
const {body} = require('basichtml').init().document;

body.innerHTML = 'Text<!--comment-->';
[...body.childNodes].forEach(node => node.remove());
assert.strictEqual(body.innerHTML, '');

This throws TypeError: node.remove is not a function where I expected the test to silently succeed. I realize the whatwg standard doesn't show Text or Comment implementing ChildNode but https://developer.mozilla.org/en-US/docs/Web/API/CharacterData#Browser_compatibility shows that CharacterData implements ChildNode in most browsers.

WebReflection commented 3 years ago

yes, it looks like by standards these should be allowed in CharacterData: https://dom.spec.whatwg.org/#childnode

coreyfarrell commented 3 years ago

I had asked about the spec vs MDN docs in the #whatwg IRC channel and was just told that it was listed under childnode (somehow I didn't see this when reading the specs).

WebReflection commented 3 years ago

ChracterData includes ChildNodes

Screenshot from 2020-11-22 14-24-56

WebReflection commented 3 years ago

It's in the patch 👋