From 10dc90c2e898cf273248235440b911ce07b62b6a Mon Sep 17 00:00:00 2001 From: Andrea Giammarchi Date: Fri, 20 Nov 2020 18:05:17 +0100 Subject: [PATCH] Fix #28 - rename IE to isImportNodeLengthWrong --- cjs/node.js | 6 +++--- esm/node.js | 6 +++--- index.js | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/cjs/node.js b/cjs/node.js index 547a9e6..e0f031c 100644 --- a/cjs/node.js +++ b/cjs/node.js @@ -26,14 +26,14 @@ exports.createTreeWalker = createTreeWalker; exports.importNode = importNode; // this "hack" tells the library if the browser is IE11 or old Edge -const IE = importNode.length != 1; +const isImportNodeLengthWrong = importNode.length != 1; // IE11 and old Edge discard empty nodes when cloning, potentially // resulting in broken paths to find updates. The workaround here // is to import once, upfront, the fragment that will be cloned // later on, so that paths are retrieved from one already parsed, // hence without missing child nodes once re-cloned. -const createFragment = IE ? +const createFragment = isImportNodeLengthWrong ? (text, type) => importNode.call( document, createContent(text, type), @@ -45,7 +45,7 @@ exports.createFragment = createFragment; // IE11 and old Edge have a different createTreeWalker signature that // has been deprecated in other browsers. This export is needed only // to guarantee the TreeWalker doesn't show warnings and, ultimately, works -const createWalker = IE ? +const createWalker = isImportNodeLengthWrong ? fragment => createTreeWalker.call(document, fragment, 1 | 128, null, false) : fragment => createTreeWalker.call(document, fragment, 1 | 128); exports.createWalker = createWalker; diff --git a/esm/node.js b/esm/node.js index 5a3d339..1c766ec 100644 --- a/esm/node.js +++ b/esm/node.js @@ -22,14 +22,14 @@ const {createTreeWalker, importNode} = document; export {createTreeWalker, importNode}; // this "hack" tells the library if the browser is IE11 or old Edge -const IE = importNode.length != 1; +const isImportNodeLengthWrong = importNode.length != 1; // IE11 and old Edge discard empty nodes when cloning, potentially // resulting in broken paths to find updates. The workaround here // is to import once, upfront, the fragment that will be cloned // later on, so that paths are retrieved from one already parsed, // hence without missing child nodes once re-cloned. -export const createFragment = IE ? +export const createFragment = isImportNodeLengthWrong ? (text, type) => importNode.call( document, createContent(text, type), @@ -40,6 +40,6 @@ export const createFragment = IE ? // IE11 and old Edge have a different createTreeWalker signature that // has been deprecated in other browsers. This export is needed only // to guarantee the TreeWalker doesn't show warnings and, ultimately, works -export const createWalker = IE ? +export const createWalker = isImportNodeLengthWrong ? fragment => createTreeWalker.call(document, fragment, 1 | 128, null, false) : fragment => createTreeWalker.call(document, fragment, 1 | 128); diff --git a/index.js b/index.js index 732b77a..c57a970 100644 --- a/index.js +++ b/index.js @@ -401,19 +401,19 @@ window.uhtml = (function (exports) { createTreeWalker = _document.createTreeWalker, importNode = _document.importNode; - var IE = importNode.length != 1; // IE11 and old Edge discard empty nodes when cloning, potentially + var isImportNodeLengthWrong = importNode.length != 1; // IE11 and old Edge discard empty nodes when cloning, potentially // resulting in broken paths to find updates. The workaround here // is to import once, upfront, the fragment that will be cloned // later on, so that paths are retrieved from one already parsed, // hence without missing child nodes once re-cloned. - var createFragment = IE ? function (text, type) { + var createFragment = isImportNodeLengthWrong ? function (text, type) { return importNode.call(document, createContent(text, type), true); } : createContent; // IE11 and old Edge have a different createTreeWalker signature that // has been deprecated in other browsers. This export is needed only // to guarantee the TreeWalker doesn't show warnings and, ultimately, works - var createWalker = IE ? function (fragment) { + var createWalker = isImportNodeLengthWrong ? function (fragment) { return createTreeWalker.call(document, fragment, 1 | 128, null, false); } : function (fragment) { return createTreeWalker.call(document, fragment, 1 | 128);