Skip to content

Commit 7836f40

Browse files
committedAug 17, 2019
support is attribute, with a warning - fixes #3182
1 parent 120ee28 commit 7836f40

File tree

7 files changed

+57
-0
lines changed

7 files changed

+57
-0
lines changed
 

‎src/compiler/compile/nodes/Element.ts

+7
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,13 @@ export default class Element extends Node {
415415
}
416416
}
417417

418+
if (name === 'is') {
419+
component.warn(attribute, {
420+
code: 'avoid-is',
421+
message: `The 'is' attribute is not supported cross-browser and should be avoided`
422+
});
423+
}
424+
418425
attribute_map.set(attribute.name, attribute);
419426
});
420427

‎src/compiler/compile/render_dom/wrappers/Element/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,11 @@ export default class ElementWrapper extends Wrapper {
383383
return `@_document.createElementNS("${namespace}", "${name}")`;
384384
}
385385

386+
const is = this.attributes.find(attr => attr.node.name === 'is');
387+
if (is) {
388+
return `@element_is("${name}", ${is.render_chunks().join(' + ')});`
389+
}
390+
386391
return `@element("${name}")`;
387392
}
388393

‎src/runtime/internal/dom.ts

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export function element<K extends keyof HTMLElementTagNameMap>(name: K) {
2020
return document.createElement<K>(name);
2121
}
2222

23+
export function element_is<K extends keyof HTMLElementTagNameMap>(name: K, is: string) {
24+
return document.createElement<K>(name, { is });
25+
}
26+
2327
export function object_without_properties<T, K extends keyof T>(obj: T, exclude: K[]) {
2428
// eslint-disable-next-line @typescript-eslint/no-object-literal-type-assertion
2529
const target = {} as Pick<T, Exclude<keyof T, K>>;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export default {
2+
warnings: [{
3+
code: "avoid-is",
4+
message: "The 'is' attribute is not supported cross-browser and should be avoided",
5+
pos: 97,
6+
start: {
7+
character: 97,
8+
column: 8,
9+
line: 7
10+
},
11+
end: {
12+
character: 114,
13+
column: 25,
14+
line: 7
15+
}
16+
}]
17+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class FancyButton extends HTMLButtonElement {}
2+
customElements.define('fancy-button', FancyButton, { extends: 'button' });
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<svelte:options tag="custom-element"/>
2+
3+
<script>
4+
import './fancy-button.js';
5+
</script>
6+
7+
<button is="fancy-button">click me</button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as assert from 'assert';
2+
import CustomElement from './main.svelte';
3+
4+
export default function (target) {
5+
new CustomElement({
6+
target
7+
});
8+
9+
assert.equal(target.innerHTML, '<custom-element></custom-element>');
10+
11+
const el = target.querySelector('custom-element');
12+
const button = el.shadowRoot.querySelector('button');
13+
14+
assert.ok(button instanceof customElements.get('fancy-button'));
15+
}

0 commit comments

Comments
 (0)