File tree Expand file tree Collapse file tree 5 files changed +43
-3
lines changed
src/compiler/phases/1-parse
tests/runtime-browser/custom-elements-samples/extend-with-ts Expand file tree Collapse file tree 5 files changed +43
-3
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' svelte ' : patch
3+ ---
4+
5+ fix: allow using typescript in ` customElement.extend ` option
Original file line number Diff line number Diff line change @@ -143,7 +143,7 @@ export class Parser {
143143 if ( options_index !== - 1 ) {
144144 const options = /** @type {AST.SvelteOptionsRaw } */ ( this . root . fragment . nodes [ options_index ] ) ;
145145 this . root . fragment . nodes . splice ( options_index , 1 ) ;
146- this . root . options = read_options ( options ) ;
146+ this . root . options = read_options ( options , this . ts ) ;
147147
148148 disallow_children ( options ) ;
149149
Original file line number Diff line number Diff line change 22/** @import { AST } from '#compiler' */
33import { NAMESPACE_MATHML , NAMESPACE_SVG } from '../../../../constants.js' ;
44import * as e from '../../../errors.js' ;
5+ import { remove_typescript_nodes } from '../remove_typescript_nodes.js' ;
56
67/**
78 * @param {AST.SvelteOptionsRaw } node
9+ * @param {boolean } ts
810 * @returns {AST.Root['options'] }
911 */
10- export default function read_options ( node ) {
12+ export default function read_options ( node , ts ) {
1113 /** @type {AST.SvelteOptions } */
1214 const component_options = {
1315 start : node . start ,
@@ -142,7 +144,7 @@ export default function read_options(node) {
142144
143145 const extend = properties . find ( ( [ name ] ) => name === 'extend' ) ?. [ 1 ] ;
144146 if ( extend ) {
145- ce . extend = extend ;
147+ ce . extend = ts ? remove_typescript_nodes ( extend ) : extend ;
146148 }
147149
148150 component_options . customElement = ce ;
Original file line number Diff line number Diff line change 1+ import { test } from '../../assert' ;
2+ const tick = ( ) => Promise . resolve ( ) ;
3+
4+ export default test ( {
5+ async test ( { assert, target } ) {
6+ target . innerHTML = '<custom-element name="world"></custom-element>' ;
7+ await tick ( ) ;
8+ /** @type {any } */
9+ const el = target . querySelector ( 'custom-element' ) ;
10+
11+ assert . htmlEqual (
12+ el . shadowRoot . innerHTML ,
13+ `
14+ <p>name: world</p>
15+ `
16+ ) ;
17+ assert . equal ( el . test , `test` ) ;
18+ }
19+ } ) ;
Original file line number Diff line number Diff line change 1+ <svelte:options customElement ={{
2+ tag : " custom-element" ,
3+ extend : (customClass )=> {
4+ return class extends customClass {
5+ public test: string = " test" ;
6+ }
7+ },
8+ }}/>
9+
10+ <script lang =" ts" >
11+ let { name } = $props ();
12+ </script >
13+
14+ <p >name: {name }</p >
You can’t perform that action at this time.
0 commit comments