Skip to content

Commit

Permalink
Don’t destructure DOM collections
Browse files Browse the repository at this point in the history
In Chrome 38, DOM collections have particularly buggy behavior with
respect to iteration—specifically, `Symbol.iterator in domCollection`
evaluates to `true`, but `domCollection[Symbol.iterator]` is undefined!
This bug is [mentioned in a `core-js` issue from around that
time](zloirock/core-js#37 (comment)).

Transpiled array destructuring uses iteration in its implementation, and
thus breaks when attempting to destructure a DOM collection in the
affected Chrome version(s). Because of the inconsistent feedback given
by the runtime, `core-js` isn’t able to effectively polyfill iteration
on this version.

So, just don’t destructure DOM collections—instead, do it the old
fashioned way.
  • Loading branch information
Mat Brown committed Mar 4, 2018
1 parent ff4dee2 commit e35c4b3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/util/compileProject.js
Expand Up @@ -90,7 +90,8 @@ function attachJavascriptLibrary(doc, javascript) {
const scriptTag = doc.createElement('script');
const javascriptText = String(javascript);
scriptTag.innerHTML = javascriptText.replace(/<\/script>/g, '<\\/script>');
const [firstScriptTag] = doc.scripts;
// eslint-disable-next-line prefer-destructuring
const firstScriptTag = doc.scripts[0];
if (firstScriptTag) {
firstScriptTag.parentNode.insertBefore(scriptTag, firstScriptTag);
} else {
Expand Down Expand Up @@ -126,7 +127,8 @@ function addBase(doc) {
const {head} = doc;
const baseTag = doc.createElement('base');
baseTag.target = '_top';
const [firstChild] = head.childNodes;
// eslint-disable-next-line prefer-destructuring
const firstChild = head.childNodes[0];
if (firstChild) {
head.insertBefore(baseTag, firstChild);
} else {
Expand Down

0 comments on commit e35c4b3

Please sign in to comment.