Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is in element attributes/props counts as custom element #348

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/babel-plugin-jsx-dom-expressions/src/dom/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function transformElement(path, info) {
config = getConfig(path),
wrapSVG = info.topLevel && tagName != "svg" && SVGElements.has(tagName),
voidTag = VoidElements.indexOf(tagName) > -1,
isCustomElement = tagName.indexOf("-") > -1 || !!path.get("openingElement").get("attributes").find(a => a.node.name?.name === "is"),
isCustomElement = tagName.indexOf("-") > -1 || path.get("openingElement").get("attributes").some(a => a.node?.name?.name === "is" || a.name?.name === "is"),
results = {
template: `<${tagName}`,
declarations: [],
Expand Down Expand Up @@ -270,7 +270,7 @@ function transformAttributes(path, results) {
attributes = path.get("openingElement").get("attributes");
const tagName = getTagName(path.node),
isSVG = SVGElements.has(tagName),
isCE = tagName.includes("-"),
isCE = tagName.includes("-") || attributes.some(a => a.node.name?.name === 'is'),
hasChildren = path.node.children.length > 0,
config = getConfig(path);

Expand Down Expand Up @@ -980,7 +980,7 @@ function detectExpressions(children, index, config) {
} else if (t.isJSXElement(child)) {
const tagName = getTagName(child);
if (isComponent(tagName)) return true;
if (config.contextToCustomElements && (tagName === "slot" || tagName.indexOf("-") > -1))
if (config.contextToCustomElements && (tagName === "slot" || tagName.indexOf("-") > -1 || child.openingElement.attributes.some(a => a.name?.name === 'is')))
return true;
if (
child.openingElement.attributes.some(
Expand Down
8 changes: 4 additions & 4 deletions packages/dom-expressions/src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export function assign(node, props, isSVG, skipChildren, prevProps = {}, skipRef
for (const prop in prevProps) {
if (!(prop in props)) {
if (prop === "children") continue;
prevProps[prop] = assignProp(node, prop, null, prevProps[prop], isSVG, skipRef);
prevProps[prop] = assignProp(node, prop, null, prevProps[prop], isSVG, skipRef, props);
}
}
for (const prop in props) {
Expand All @@ -223,7 +223,7 @@ export function assign(node, props, isSVG, skipChildren, prevProps = {}, skipRef
continue;
}
const value = props[prop];
prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG, skipRef);
prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG, skipRef, props);
}
}

Expand Down Expand Up @@ -323,7 +323,7 @@ function toggleClassKey(node, key, value) {
node.classList.toggle(classNames[i], value);
}

function assignProp(node, prop, value, prev, isSVG, skipRef) {
function assignProp(node, prop, value, prev, isSVG, skipRef, props) {
let isCE, isProp, isChildProp, propAlias, forceProp;
if (prop === "style") return style(node, value, prev);
if (prop === "classList") return classList(node, value, prev);
Expand Down Expand Up @@ -356,7 +356,7 @@ function assignProp(node, prop, value, prev, isSVG, skipRef) {
(isChildProp = ChildProperties.has(prop)) ||
(!isSVG &&
((propAlias = getPropAlias(prop, node.tagName)) || (isProp = Properties.has(prop)))) ||
(isCE = node.nodeName.includes("-"))
(isCE = (node.nodeName.includes("-") || 'is' in props))
) {
if (forceProp) {
prop = prop.slice(5);
Expand Down
2 changes: 1 addition & 1 deletion packages/lit-dom-expressions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ export function createHTML(r: Runtime, { delegateEvents = true, functionBuilder
topDecl ? "" : `${tag} = ${options.path}.${options.first ? "firstChild" : "nextSibling"}`
);
const isSVG = r.SVGElements.has(node.name);
const isCE = node.name.includes("-");
const isCE = node.name.includes("-") || node.attrs.some((e) => e.name === "is");
options.hasCustomElement = isCE;
if (node.attrs.some(e => e.name === "###")) {
const spreadArgs = [];
Expand Down
Loading