Skip to content

Commit

Permalink
use getRootNode for this references in JSX for DSD
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Jan 4, 2024
1 parent d41ceb8 commit 8fe5f02
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/jsx-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function getParser(moduleURL) {
};
}

// replace all instances of __this__ marker with relative reference to the custom element parent node
function applyDomDepthSubstitutions(tree, currentDepth = 1, hasShadowRoot = false) {
try {
for (const node of tree.childNodes) {
Expand All @@ -50,9 +51,9 @@ function applyDomDepthSubstitutions(tree, currentDepth = 1, hasShadowRoot = fals
const { value } = attrs[attr];

if (value.indexOf('__this__.') >= 0) {
const root = hasShadowRoot ? 'parentNode.host' : 'parentElement';

node.attrs[attr].value = value.replace(/__this__/g, `this${'.parentElement'.repeat(currentDepth - 1)}.${root}`);
const root = hasShadowRoot ? '.getRootNode().host' : `${'.parentElement'.repeat(currentDepth)}`;
node.attrs[attr].value = value.replace(/__this__/g, `this${root}`);
}
}
}
Expand Down

0 comments on commit 8fe5f02

Please sign in to comment.