Skip to content

A proof-of-concept fix for Custom Element Overrides #3184

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

Closed
Closed
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
16 changes: 16 additions & 0 deletions src/compiler/compile/render_dom/wrappers/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Renderer from '../../Renderer';
import Element from '../../../nodes/Element';
import Wrapper from '../shared/Wrapper';
import Block from '../../Block';
import Text from '../../../nodes/Text';
import { is_void, quote_prop_if_necessary, quote_name_if_necessary, sanitize } from '../../../../utils/names';
import FragmentWrapper from '../Fragment';
import { stringify, escape_html, escape } from '../../../utils/stringify';
Expand Down Expand Up @@ -374,6 +375,17 @@ export default class ElementWrapper extends Wrapper {

get_render_statement() {
const { name, namespace } = this.node;
let isList = this.node.attributes.filter(attr => attr.type === 'Attribute' && attr.name === 'is');
let is = null;
if (isList.length === 1) {
let isAttribute = isList[0];

let chunk = isAttribute.chunks[0];
if (chunk.type === 'Text') {
let text = chunk as Text
is = text.data
}
}

if (namespace === 'http://www.w3.org/2000/svg') {
return `@svg_element("${name}")`;
Expand All @@ -383,6 +395,10 @@ export default class ElementWrapper extends Wrapper {
return `@_document.createElementNS("${namespace}", "${name}")`;
}

if (is) {
return `@element("${name}", "${is}")`;
}

return `@element("${name}")`;
}

Expand Down
5 changes: 4 additions & 1 deletion src/runtime/internal/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export function destroy_each(iterations, detaching) {
}
}

export function element<K extends keyof HTMLElementTagNameMap>(name: K) {
export function element<K extends keyof HTMLElementTagNameMap>(name: K, is=null) {
if (is) {
return document.createElement<K>(name, { is })
}
return document.createElement<K>(name);
}

Expand Down