sveld 0.24.6 → 0.24.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -60,6 +60,7 @@ interface ComponentInlineElement {
60
60
  interface ComponentElement {
61
61
  type: "Element";
62
62
  name: string;
63
+ thisValue?: string;
63
64
  }
64
65
  type RestProps = undefined | ComponentInlineElement | ComponentElement;
65
66
  interface Extends {
@@ -783,10 +783,20 @@ class ComponentParser {
783
783
  }
784
784
  if (node.type === "Spread" && node?.expression.name === "$$restProps") {
785
785
  if (this.rest_props === undefined && (parent?.type === "InlineComponent" || parent?.type === "Element")) {
786
- this.rest_props = {
786
+ const restProps = {
787
787
  type: parent.type,
788
788
  name: parent.name,
789
789
  };
790
+ // Handle svelte:element - check if this attribute is hardcoded
791
+ if (parent.type === "Element" && parent.name === "svelte:element") {
792
+ // The 'this' value is stored in the 'tag' property of the Element node
793
+ // If tag is a string, it's hardcoded; if undefined/null, it's dynamic
794
+ if (typeof parent.tag === "string") {
795
+ restProps.thisValue = parent.tag;
796
+ }
797
+ // If tag is undefined or not a string, thisValue remains undefined (dynamic)
798
+ }
799
+ this.rest_props = restProps;
790
800
  }
791
801
  }
792
802
  if (node.type === "VariableDeclaration") {
@@ -89,13 +89,29 @@ function genPropDef(def) {
89
89
  let prop_def = EMPTY_STR;
90
90
  const genericsName = def.generics ? `<${def.generics[0]}>` : "";
91
91
  if (def.rest_props?.type === "Element") {
92
- const extend_tag_map = def.rest_props.name
93
- .split("|")
94
- .map((name) => {
95
- const element = name.trim();
96
- return `SvelteHTMLElements["${element}"]`;
97
- })
98
- .join("&");
92
+ let extend_tag_map;
93
+ // Handle svelte:element specially
94
+ if (def.rest_props.name === "svelte:element") {
95
+ // If thisValue is provided (hardcoded element tag), use that element type
96
+ // Otherwise, fallback to HTMLElement for dynamic this attribute
97
+ if (def.rest_props.thisValue) {
98
+ extend_tag_map = `SvelteHTMLElements["${def.rest_props.thisValue}"]`;
99
+ }
100
+ else {
101
+ // Dynamic this attribute - use generic HTMLElement
102
+ extend_tag_map = "HTMLAttributes<HTMLElement>";
103
+ }
104
+ }
105
+ else {
106
+ // Regular element - use existing logic
107
+ extend_tag_map = def.rest_props.name
108
+ .split("|")
109
+ .map((name) => {
110
+ const element = name.trim();
111
+ return `SvelteHTMLElements["${element}"]`;
112
+ })
113
+ .join("&");
114
+ }
99
115
  /**
100
116
  * Components that extend HTML elements should allow for `data-*` attributes.
101
117
  * @see https://github.com/sveltejs/language-tools/issues/1825
@@ -423,8 +439,12 @@ function writeTsDefinition(component) {
423
439
  });
424
440
  const generic = generics ? `<${generics[1]}>` : "";
425
441
  const genericProps = generics ? `${props_name}<${generics[0]}>` : props_name;
442
+ // Determine imports needed for rest_props
443
+ const needsSvelteHTMLElements = rest_props?.type === "Element" &&
444
+ (rest_props.name !== "svelte:element" || (rest_props.name === "svelte:element" && rest_props.thisValue));
445
+ const needsHTMLAttributes = rest_props?.type === "Element" && rest_props.name === "svelte:element" && !rest_props.thisValue;
426
446
  return `
427
- import type { SvelteComponentTyped } from "svelte";${rest_props?.type === "Element" ? `import type { SvelteHTMLElements } from "svelte/elements";\n` : ""}
447
+ import type { SvelteComponentTyped } from "svelte";${needsSvelteHTMLElements ? `import type { SvelteHTMLElements } from "svelte/elements";\n` : ""}${needsHTMLAttributes ? `import type { HTMLAttributes } from "svelte/elements";\n` : ""}
428
448
  ${genImports({ extends: _extends })}
429
449
  ${genModuleExports({ moduleExports })}
430
450
  ${getTypeDefs({ typedefs })}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sveld",
3
- "version": "0.24.6",
3
+ "version": "0.24.7",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Generate TypeScript definitions for your Svelte components.",
6
6
  "main": "./lib/index.js",