Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Apr 9, 2020
1 parent e784265 commit cc02ce5
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions packages/packagers/html/src/HTMLPackager.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,8 @@ function insertBundleReferences(siblingBundles, tree) {
}

function addBundlesToTree(bundles, tree) {
const head = find(tree, 'head');
if (head) {
const content = head.content || (head.content = []);
content.push(...bundles);
return;
}

const html = find(tree, 'html');
const content = html ? html.content || (html.content = []) : tree;
const main = find(tree, 'head') || find(tree, 'html');
const content = main ? main.content || (main.content = []) : tree;
const index = findBundleInsertIndex(content);

content.splice(index, 0, ...bundles);
Expand All @@ -216,7 +209,7 @@ function findBundleInsertIndex(content) {
//
// -> Insert before first non-metadata element; if none was found, after the doctype

let doctypeIndex = 0;
let doctypeIndex;
for (let index = 0; index < content.length; index++) {
const node = content[index];
if (node && node.tag && !metadataContent.has(node.tag)) {
Expand All @@ -230,5 +223,5 @@ function findBundleInsertIndex(content) {
}
}

return doctypeIndex + 1;
return doctypeIndex ? doctypeIndex + 1 : 0;
}

0 comments on commit cc02ce5

Please sign in to comment.