File tree 7 files changed +57
-0
lines changed
render_dom/wrappers/Element
test/custom-elements/samples/extended-builtin
7 files changed +57
-0
lines changed Original file line number Diff line number Diff line change @@ -415,6 +415,13 @@ export default class Element extends Node {
415
415
}
416
416
}
417
417
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
+
418
425
attribute_map . set ( attribute . name , attribute ) ;
419
426
} ) ;
420
427
Original file line number Diff line number Diff line change @@ -383,6 +383,11 @@ export default class ElementWrapper extends Wrapper {
383
383
return `@_document.createElementNS("${ namespace } ", "${ name } ")` ;
384
384
}
385
385
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
+
386
391
return `@element("${ name } ")` ;
387
392
}
388
393
Original file line number Diff line number Diff line change @@ -20,6 +20,10 @@ export function element<K extends keyof HTMLElementTagNameMap>(name: K) {
20
20
return document . createElement < K > ( name ) ;
21
21
}
22
22
23
+ export function element_is < K extends keyof HTMLElementTagNameMap > ( name : K , is : string ) {
24
+ return document . createElement < K > ( name , { is } ) ;
25
+ }
26
+
23
27
export function object_without_properties < T , K extends keyof T > ( obj : T , exclude : K [ ] ) {
24
28
// eslint-disable-next-line @typescript-eslint/no-object-literal-type-assertion
25
29
const target = { } as Pick < T , Exclude < keyof T , K > > ;
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
1
+ class FancyButton extends HTMLButtonElement { }
2
+ customElements . define ( 'fancy-button' , FancyButton , { extends : 'button' } ) ;
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments