sveld 0.25.7 → 0.25.8
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ComponentDocApi } from "../rollup-plugin";
|
|
2
2
|
export declare function formatTsProps(props?: string): string;
|
|
3
3
|
export declare function getTypeDefs(def: Pick<ComponentDocApi, "typedefs">): string;
|
|
4
|
-
export declare function getContextDefs(def: Pick<ComponentDocApi, "contexts">): string;
|
|
4
|
+
export declare function getContextDefs(def: Pick<ComponentDocApi, "contexts" | "generics">): string;
|
|
5
5
|
export declare function writeTsDefinition(component: ComponentDocApi): string;
|
|
@@ -38,6 +38,10 @@ function getTypeDefs(def) {
|
|
|
38
38
|
function getContextDefs(def) {
|
|
39
39
|
if (!def.contexts || def.contexts.length === 0)
|
|
40
40
|
return EMPTY_STR;
|
|
41
|
+
// Extract generic parameter for context types if generics are defined
|
|
42
|
+
// and the context properties reference the generic type
|
|
43
|
+
const genericsName = def.generics ? def.generics[0] : null;
|
|
44
|
+
const genericsType = def.generics ? def.generics[1] : null;
|
|
41
45
|
return def.contexts
|
|
42
46
|
.map((context) => {
|
|
43
47
|
const props = context.properties
|
|
@@ -48,11 +52,15 @@ function getContextDefs(def) {
|
|
|
48
52
|
})
|
|
49
53
|
.join("\n ");
|
|
50
54
|
const contextComment = context.description ? `/**\n * ${context.description}\n */\n` : "";
|
|
55
|
+
// Check if any context property types reference the generic type name
|
|
56
|
+
const referencesGeneric = genericsName && context.properties.some((prop) => prop.type.includes(genericsName));
|
|
57
|
+
// Build the generic suffix for the context type if it references generics
|
|
58
|
+
const genericSuffix = referencesGeneric && genericsType ? `<${genericsType}>` : "";
|
|
51
59
|
// Use Record<string, never> for empty context objects instead of {}
|
|
52
60
|
if (context.properties.length === 0) {
|
|
53
61
|
return `${contextComment}export type ${context.typeName} = Record<string, never>;`;
|
|
54
62
|
}
|
|
55
|
-
return `${contextComment}export type ${context.typeName} = {\n ${props}\n};`;
|
|
63
|
+
return `${contextComment}export type ${context.typeName}${genericSuffix} = {\n ${props}\n};`;
|
|
56
64
|
})
|
|
57
65
|
.join("\n\n");
|
|
58
66
|
}
|
|
@@ -487,7 +495,7 @@ function writeTsDefinition(component) {
|
|
|
487
495
|
${genImports({ extends: _extends })}
|
|
488
496
|
${genModuleExports({ moduleExports })}
|
|
489
497
|
${getTypeDefs({ typedefs })}
|
|
490
|
-
${getContextDefs({ contexts })}
|
|
498
|
+
${contexts && contexts.length > 0 ? "\n" : ""}${getContextDefs({ contexts, generics })}
|
|
491
499
|
${prop_def}
|
|
492
500
|
${genComponentComment({ componentComment })}
|
|
493
501
|
export default class ${moduleName === "default" ? "" : moduleName}${generic} extends SvelteComponentTyped<
|