From 66936c1d892dcdb5c0ccd955be1da99ddd3f9607 Mon Sep 17 00:00:00 2001 From: Owen Buckley Date: Wed, 29 Jun 2022 17:09:02 -0400 Subject: [PATCH 1/2] refactor definitions away from being global and shared within CLI --- src/wcc.js | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/wcc.js b/src/wcc.js index 4e2e481c..428ba809 100644 --- a/src/wcc.js +++ b/src/wcc.js @@ -6,8 +6,6 @@ import * as walk from 'acorn-walk'; import { parse, parseFragment, serialize } from 'parse5'; import fs from 'fs/promises'; -let definitions; - function getParse(html) { return html.indexOf('') >= 0 || html.indexOf('') >= 0 || html.indexOf('') >= 0 ? parse @@ -22,12 +20,12 @@ function isCustomElementDefinitionNode(node) { && expression.callee.property.name === 'define'; } -async function renderComponentRoots(tree) { +async function renderComponentRoots(tree, definitions) { for (const node of tree.childNodes) { if (node.tagName && node.tagName.indexOf('-') > 0) { const { tagName } = node; const { moduleURL } = definitions[tagName]; - const elementInstance = await initializeCustomElement(moduleURL, tagName, node.attrs); + const elementInstance = await initializeCustomElement(moduleURL, tagName, node.attrs, definitions); const elementHtml = elementInstance.shadowRoot ? elementInstance.getInnerHTML({ includeShadowRoots: true }) : elementInstance.innerHTML; @@ -39,19 +37,19 @@ async function renderComponentRoots(tree) { } if (node.childNodes && node.childNodes.length > 0) { - await renderComponentRoots(node); + await renderComponentRoots(node, definitions); } // does this only apply to `