Skip to content

Commit 0f46f7f

Browse files
committed
Definir constantes de domElement.nodeType e usar domElement.attributes.item(index) para compatibilidade com @remote-dom/polyfill
1 parent 01b20ac commit 0f46f7f

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

src/element/dom.mjs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
import {arrayFrom, arrayConcat} from '../collection.mjs';
22

33
export default (apiDom) => {
4+
// @remote-dom/polyfill does not define these constants
5+
// so we define them here manually
6+
// other dom implementations for the server could have the same constraint
7+
const
8+
ELEMENT_NODE = 1,
9+
ATTRIBUTE_NODE = 2,
10+
TEXT_NODE = 3,
11+
CDATA_SECTION_NODE = 4,
12+
PROCESSING_INSTRUCTION_NODE = 7,
13+
COMMENT_NODE = 8,
14+
DOCUMENT_NODE = 9,
15+
DOCUMENT_TYPE_NODE = 10,
16+
DOCUMENT_FRAGMENT_NODE = 11,
17+
ENTITY_REFERENCE_NODE = 5,
18+
ENTITY_NODE = 6,
19+
NOTATION_NODE = 12;
420
const child = (el, child) => void el.appendChild(child);
521
const childCount = (el) => el.childNodes.length;
622
const childIndexGet = (el, index) => el.childNodes[index];
@@ -22,16 +38,16 @@ export default (apiDom) => {
2238
}
2339
}
2440
const textNode = (text) => apiDom.createTextNode(text);
25-
const isFragment = (el) => el.nodeType === apiDom.DOCUMENT_FRAGMENT_NODE;
26-
const isComment = (el) => el.nodeType === apiDom.COMMENT_NODE;
41+
const isFragment = (el) => el.nodeType === DOCUMENT_FRAGMENT_NODE;
42+
const isComment = (el) => el.nodeType === COMMENT_NODE;
2743
const isChildren = (ch) => ch && ch.constructor === apiDom.childNodes.constructor;
2844
// const splice = Array.prototype.splice;
2945
return {
30-
isText: (el) => el.nodeType === apiDom.TEXT_NODE,
46+
isText: (el) => el.nodeType === TEXT_NODE,
3147
isFragment,
3248
isComment,
33-
isDeclaration: (el) => el.nodeType === apiDom.NOTATION_NODE,
34-
isInstruction: (el) => el.nodeType === apiDom.PROCESSING_INSTRUCTION_NODE,
49+
isDeclaration: (el) => el.nodeType === NOTATION_NODE,
50+
isInstruction: (el) => el.nodeType === PROCESSING_INSTRUCTION_NODE,
3551
isChildren,
3652
initRoot: () => apiDom.createDocumentFragment(),
3753
initName: (name) => apiDom.createElement(name),
@@ -50,7 +66,7 @@ export default (apiDom) => {
5066
};
5167
var count = list && list.length || 0;
5268
for (var i = 0; i < count; i++) {
53-
var a = list[i];
69+
var a = list[i] || list.item(i);
5470
var ret = handler.call(ctx, a.name, a.value, a, i);
5571
if (ret & ctx._remove) el.removeAttribute(a.name);
5672
if (ret & ctx._break) break;

test/examples/map.svg

Lines changed: 5 additions & 0 deletions
Loading

test/runner.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,5 +333,17 @@ module.exports.broken = function() {
333333
return parseTree(__dirname+'/examples/broken.html');
334334
};
335335

336+
module.exports.mapSvgStream = function() {
337+
return parseFile(__dirname+'/examples/map.svg');
338+
};
339+
340+
module.exports.mapSvg = function() {
341+
return parseTree(__dirname+'/examples/map.svg');
342+
};
343+
344+
module.exports.mapSvgPrint = function() {
345+
return printTree(__dirname+'/examples/map.svg');
346+
};
347+
336348
module.exports.testList = testList;
337349
module.exports.printerTransform = printerTransform;

0 commit comments

Comments
 (0)