@fuzdev/fuz_ui 0.194.0 → 0.195.1

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.
Files changed (61) hide show
  1. package/dist/DeclarationDetail.svelte +139 -64
  2. package/dist/DeclarationDetail.svelte.d.ts +9 -0
  3. package/dist/DeclarationDetail.svelte.d.ts.map +1 -1
  4. package/dist/LibraryDetail.svelte +14 -10
  5. package/dist/LibraryDetail.svelte.d.ts +7 -0
  6. package/dist/LibraryDetail.svelte.d.ts.map +1 -1
  7. package/dist/declaration.svelte.d.ts +233 -25
  8. package/dist/declaration.svelte.d.ts.map +1 -1
  9. package/dist/declaration.svelte.js +71 -23
  10. package/dist/library.svelte.js +1 -1
  11. package/dist/library_gen.d.ts +24 -17
  12. package/dist/library_gen.d.ts.map +1 -1
  13. package/dist/library_gen.js +52 -32
  14. package/dist/library_output.d.ts +5 -4
  15. package/dist/library_output.d.ts.map +1 -1
  16. package/dist/library_output.js +11 -8
  17. package/dist/module.svelte.d.ts +21 -7
  18. package/dist/module.svelte.d.ts.map +1 -1
  19. package/dist/module.svelte.js +26 -11
  20. package/dist/tsdoc_mdz.d.ts +6 -1
  21. package/dist/tsdoc_mdz.d.ts.map +1 -1
  22. package/dist/tsdoc_mdz.js +23 -2
  23. package/package.json +10 -8
  24. package/src/lib/declaration.svelte.ts +90 -35
  25. package/src/lib/library.svelte.ts +1 -1
  26. package/src/lib/library_gen.ts +65 -42
  27. package/src/lib/library_output.ts +11 -8
  28. package/src/lib/module.svelte.ts +29 -16
  29. package/src/lib/tsdoc_mdz.ts +25 -2
  30. package/dist/analysis_context.d.ts +0 -199
  31. package/dist/analysis_context.d.ts.map +0 -1
  32. package/dist/analysis_context.js +0 -138
  33. package/dist/library_analysis.d.ts +0 -112
  34. package/dist/library_analysis.d.ts.map +0 -1
  35. package/dist/library_analysis.js +0 -106
  36. package/dist/library_generate.d.ts +0 -94
  37. package/dist/library_generate.d.ts.map +0 -1
  38. package/dist/library_generate.js +0 -147
  39. package/dist/library_pipeline.d.ts +0 -113
  40. package/dist/library_pipeline.d.ts.map +0 -1
  41. package/dist/library_pipeline.js +0 -160
  42. package/dist/module_helpers.d.ts +0 -334
  43. package/dist/module_helpers.d.ts.map +0 -1
  44. package/dist/module_helpers.js +0 -317
  45. package/dist/svelte_helpers.d.ts +0 -92
  46. package/dist/svelte_helpers.d.ts.map +0 -1
  47. package/dist/svelte_helpers.js +0 -367
  48. package/dist/ts_helpers.d.ts +0 -181
  49. package/dist/ts_helpers.d.ts.map +0 -1
  50. package/dist/ts_helpers.js +0 -674
  51. package/dist/tsdoc_helpers.d.ts +0 -119
  52. package/dist/tsdoc_helpers.d.ts.map +0 -1
  53. package/dist/tsdoc_helpers.js +0 -207
  54. package/src/lib/analysis_context.ts +0 -254
  55. package/src/lib/library_analysis.ts +0 -168
  56. package/src/lib/library_generate.ts +0 -215
  57. package/src/lib/library_pipeline.ts +0 -221
  58. package/src/lib/module_helpers.ts +0 -501
  59. package/src/lib/svelte_helpers.ts +0 -539
  60. package/src/lib/ts_helpers.ts +0 -862
  61. package/src/lib/tsdoc_helpers.ts +0 -246
@@ -1,92 +0,0 @@
1
- /**
2
- * Svelte component analysis helpers.
3
- *
4
- * Extracts metadata from Svelte components using svelte2tsx transformations:
5
- *
6
- * - Component props with types and JSDoc
7
- * - Component-level documentation
8
- * - Type information
9
- *
10
- * Workflow: Transform Svelte to TypeScript via svelte2tsx, parse the transformed
11
- * TypeScript with the TS Compiler API, extract component-level JSDoc from original source.
12
- *
13
- * **Svelte 5 only**: The svelte2tsx output format changed significantly between versions.
14
- * This module requires Svelte 5+ and will throw a clear error if an older version is detected.
15
- * There is no Svelte 4 compatibility layer.
16
- *
17
- * All functions are prefixed with `svelte_` for clarity.
18
- *
19
- * @module
20
- */
21
- import ts from 'typescript';
22
- import { TraceMap } from '@jridgewell/trace-mapping';
23
- import type { DeclarationJson } from '@fuzdev/fuz_util/source_json.js';
24
- import { type SourceFileInfo, type ModuleSourceOptions } from './module_helpers.js';
25
- import type { AnalysisContext } from './analysis_context.js';
26
- import type { ModuleAnalysis } from './library_analysis.js';
27
- /** Result of analyzing a Svelte file. */
28
- export interface SvelteFileAnalysis {
29
- /** The component declaration metadata. */
30
- declaration: DeclarationJson;
31
- /** Module-level documentation comment, if present. */
32
- module_comment?: string;
33
- }
34
- /**
35
- * Analyze a Svelte component file and extract module metadata.
36
- *
37
- * Wraps `svelte_analyze_file` and adds dependency information
38
- * from the source file info if available.
39
- *
40
- * This is a high-level function suitable for building documentation or library metadata.
41
- * For lower-level analysis, use `svelte_analyze_file` directly.
42
- *
43
- * Returns raw analysis data matching `ModuleAnalysis` structure.
44
- * Consumer decides filtering policy (Svelte components are never nodocs).
45
- *
46
- * @param source_file - the source file info (from Gro filer, file system, or other source)
47
- * @param module_path - the module path (relative to source root)
48
- * @param checker - TypeScript type checker
49
- * @param options - module source options for path extraction
50
- * @param ctx - analysis context for collecting diagnostics
51
- * @returns module analysis matching `ModuleAnalysis` structure
52
- */
53
- export declare const svelte_analyze_module: (source_file: SourceFileInfo, module_path: string, checker: ts.TypeChecker, options: ModuleSourceOptions, ctx: AnalysisContext) => ModuleAnalysis;
54
- /**
55
- * Analyze a Svelte component file.
56
- *
57
- * This is a high-level function that handles the complete workflow:
58
- * 1. Transform Svelte source to TypeScript via svelte2tsx
59
- * 2. Extract component metadata (props, documentation)
60
- * 3. Extract module-level documentation
61
- *
62
- * Suitable for use in documentation generators, build tools, and analysis.
63
- *
64
- * @param source_file - source file info with path and content
65
- * @param module_path - module path relative to source root (e.g., 'Alert.svelte')
66
- * @param checker - TypeScript type checker for type resolution
67
- * @param ctx - analysis context for collecting diagnostics
68
- * @returns component declaration and optional module-level comment
69
- */
70
- export declare const svelte_analyze_file: (source_file: SourceFileInfo, module_path: string, checker: ts.TypeChecker, ctx: AnalysisContext) => SvelteFileAnalysis;
71
- /**
72
- * Analyze a Svelte component from its svelte2tsx transformation.
73
- */
74
- export declare const svelte_analyze_component: (ts_code: string, source_file: ts.SourceFile, checker: ts.TypeChecker, component_name: string, file_path: string, source_map: TraceMap | null, ctx: AnalysisContext) => DeclarationJson;
75
- /**
76
- * Extract the content of the main `<script>` tag from Svelte source.
77
- *
78
- * Matches `<script>` or `<script lang="ts">` but not `<script module>`.
79
- * Returns undefined if no matching script tag is found.
80
- */
81
- export declare const svelte_extract_script_content: (svelte_source: string) => string | undefined;
82
- /**
83
- * Extract module-level comment from Svelte script content.
84
- *
85
- * Requires `@module` tag to identify module comments. The tag line is stripped
86
- * from the output.
87
- *
88
- * @param script_content - the content of the `<script>` tag
89
- * @returns the cleaned module comment text, or undefined if none found
90
- */
91
- export declare const svelte_extract_module_comment: (script_content: string) => string | undefined;
92
- //# sourceMappingURL=svelte_helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"svelte_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/svelte_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,EAAC,QAAQ,EAAsB,MAAM,2BAA2B,CAAC;AAExE,OAAO,KAAK,EAAC,eAAe,EAAoB,MAAM,iCAAiC,CAAC;AAIxF,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,mBAAmB,EAGxB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAqB1D,yCAAyC;AACzC,MAAM,WAAW,kBAAkB;IAClC,0CAA0C;IAC1C,WAAW,EAAE,eAAe,CAAC;IAC7B,sDAAsD;IACtD,cAAc,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,qBAAqB,GACjC,aAAa,cAAc,EAC3B,aAAa,MAAM,EACnB,SAAS,EAAE,CAAC,WAAW,EACvB,SAAS,mBAAmB,EAC5B,KAAK,eAAe,KAClB,cAiBF,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,mBAAmB,GAC/B,aAAa,cAAc,EAC3B,aAAa,MAAM,EACnB,SAAS,EAAE,CAAC,WAAW,EACvB,KAAK,eAAe,KAClB,kBAqDF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GACpC,SAAS,MAAM,EACf,aAAa,EAAE,CAAC,UAAU,EAC1B,SAAS,EAAE,CAAC,WAAW,EACvB,gBAAgB,MAAM,EACtB,WAAW,MAAM,EACjB,YAAY,QAAQ,GAAG,IAAI,EAC3B,KAAK,eAAe,KAClB,eA0CF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,6BAA6B,GAAI,eAAe,MAAM,KAAG,MAAM,GAAG,SAM9E,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,6BAA6B,GAAI,gBAAgB,MAAM,KAAG,MAAM,GAAG,SAU/E,CAAC"}
@@ -1,367 +0,0 @@
1
- /**
2
- * Svelte component analysis helpers.
3
- *
4
- * Extracts metadata from Svelte components using svelte2tsx transformations:
5
- *
6
- * - Component props with types and JSDoc
7
- * - Component-level documentation
8
- * - Type information
9
- *
10
- * Workflow: Transform Svelte to TypeScript via svelte2tsx, parse the transformed
11
- * TypeScript with the TS Compiler API, extract component-level JSDoc from original source.
12
- *
13
- * **Svelte 5 only**: The svelte2tsx output format changed significantly between versions.
14
- * This module requires Svelte 5+ and will throw a clear error if an older version is detected.
15
- * There is no Svelte 4 compatibility layer.
16
- *
17
- * All functions are prefixed with `svelte_` for clarity.
18
- *
19
- * @module
20
- */
21
- import ts from 'typescript';
22
- import { svelte2tsx } from 'svelte2tsx';
23
- import { TraceMap, originalPositionFor } from '@jridgewell/trace-mapping';
24
- import { VERSION } from 'svelte/compiler';
25
- import { tsdoc_parse, tsdoc_apply_to_declaration } from './tsdoc_helpers.js';
26
- import { ts_extract_module_comment } from './ts_helpers.js';
27
- import { module_get_component_name, module_extract_dependencies, } from './module_helpers.js';
28
- /** Guard to ensure version check runs only once. */
29
- let svelte_version_checked = false;
30
- /**
31
- * Assert Svelte 5+ is installed (lazy, runs once on first use).
32
- * Throws a clear error message if an older version is detected.
33
- */
34
- const svelte_assert_version = () => {
35
- if (svelte_version_checked)
36
- return;
37
- svelte_version_checked = true;
38
- const [major] = VERSION.split('.');
39
- if (parseInt(major, 10) < 5) {
40
- throw new Error(`Svelte ${VERSION} detected but Svelte 5+ is required for source analysis. ` +
41
- `The svelte2tsx output format changed significantly between versions.`);
42
- }
43
- };
44
- /**
45
- * Analyze a Svelte component file and extract module metadata.
46
- *
47
- * Wraps `svelte_analyze_file` and adds dependency information
48
- * from the source file info if available.
49
- *
50
- * This is a high-level function suitable for building documentation or library metadata.
51
- * For lower-level analysis, use `svelte_analyze_file` directly.
52
- *
53
- * Returns raw analysis data matching `ModuleAnalysis` structure.
54
- * Consumer decides filtering policy (Svelte components are never nodocs).
55
- *
56
- * @param source_file - the source file info (from Gro filer, file system, or other source)
57
- * @param module_path - the module path (relative to source root)
58
- * @param checker - TypeScript type checker
59
- * @param options - module source options for path extraction
60
- * @param ctx - analysis context for collecting diagnostics
61
- * @returns module analysis matching `ModuleAnalysis` structure
62
- */
63
- export const svelte_analyze_module = (source_file, module_path, checker, options, ctx) => {
64
- // Use the existing helper for core analysis
65
- const { declaration, module_comment } = svelte_analyze_file(source_file, module_path, checker, ctx);
66
- // Extract dependencies and dependents if provided
67
- const { dependencies, dependents } = module_extract_dependencies(source_file, options);
68
- return {
69
- path: module_path,
70
- module_comment,
71
- // Wrap declaration in DeclarationAnalysis format (Svelte components are never nodocs)
72
- declarations: [{ declaration, nodocs: false }],
73
- dependencies,
74
- dependents,
75
- star_exports: [],
76
- re_exports: [],
77
- };
78
- };
79
- /**
80
- * Analyze a Svelte component file.
81
- *
82
- * This is a high-level function that handles the complete workflow:
83
- * 1. Transform Svelte source to TypeScript via svelte2tsx
84
- * 2. Extract component metadata (props, documentation)
85
- * 3. Extract module-level documentation
86
- *
87
- * Suitable for use in documentation generators, build tools, and analysis.
88
- *
89
- * @param source_file - source file info with path and content
90
- * @param module_path - module path relative to source root (e.g., 'Alert.svelte')
91
- * @param checker - TypeScript type checker for type resolution
92
- * @param ctx - analysis context for collecting diagnostics
93
- * @returns component declaration and optional module-level comment
94
- */
95
- export const svelte_analyze_file = (source_file, module_path, checker, ctx) => {
96
- svelte_assert_version();
97
- const svelte_source = source_file.content;
98
- // Check if component uses TypeScript
99
- const is_ts_file = svelte_source.includes('lang="ts"');
100
- // Transform Svelte to TS
101
- const ts_result = svelte2tsx(svelte_source, {
102
- filename: source_file.id,
103
- isTsFile: is_ts_file,
104
- emitOnTemplateError: true, // Handle malformed templates gracefully
105
- });
106
- // Create source map for position mapping back to original .svelte file
107
- let source_map = null;
108
- try {
109
- // svelte2tsx returns a magic-string SourceMap which is compatible with TraceMap
110
- // Cast to unknown first since the types don't perfectly align but are compatible
111
- source_map = new TraceMap(ts_result.map);
112
- }
113
- catch (_error) {
114
- // If source map parsing fails, diagnostics will use virtual file positions
115
- }
116
- // Get component name from filename
117
- const component_name = module_get_component_name(module_path);
118
- // Create a temporary source file from the original Svelte content for JSDoc extraction
119
- const temp_source = ts.createSourceFile(source_file.id, svelte_source, ts.ScriptTarget.Latest, true);
120
- // Analyze the component using the existing lower-level function
121
- const declaration = svelte_analyze_component(ts_result.code, temp_source, checker, component_name, module_path, source_map, ctx);
122
- // Extract module-level comment from the script content
123
- const script_content = svelte_extract_script_content(svelte_source);
124
- const module_comment = script_content ? svelte_extract_module_comment(script_content) : undefined;
125
- return { declaration, module_comment };
126
- };
127
- /**
128
- * Analyze a Svelte component from its svelte2tsx transformation.
129
- */
130
- export const svelte_analyze_component = (ts_code, source_file, checker, component_name, file_path, source_map, ctx) => {
131
- const result = {
132
- name: component_name,
133
- kind: 'component',
134
- };
135
- try {
136
- // Create a virtual source file from the svelte2tsx output
137
- // svelte2tsx generates plain TypeScript (not TSX/JSX)
138
- const virtual_source = ts.createSourceFile(source_file.fileName + '.ts', ts_code, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
139
- // Extract component-level TSDoc from svelte2tsx transformed output
140
- const component_tsdoc = svelte_extract_component_tsdoc(virtual_source);
141
- tsdoc_apply_to_declaration(result, component_tsdoc);
142
- // Extract props from svelte2tsx transformed output
143
- const props = svelte_extract_props(virtual_source, checker, component_name, file_path, source_map, ctx);
144
- if (props.length > 0) {
145
- result.props = props;
146
- }
147
- // Extract source line from original file
148
- const start_pos = source_file.getLineAndCharacterOfPosition(0);
149
- result.source_line = start_pos.line + 1;
150
- }
151
- catch (error) {
152
- throw new Error(`Failed to analyze Svelte component ${component_name}`, { cause: error });
153
- }
154
- return result;
155
- };
156
- /**
157
- * Extract the content of the main `<script>` tag from Svelte source.
158
- *
159
- * Matches `<script>` or `<script lang="ts">` but not `<script module>`.
160
- * Returns undefined if no matching script tag is found.
161
- */
162
- export const svelte_extract_script_content = (svelte_source) => {
163
- // Match <script> or <script lang="ts"> but not <script module>
164
- // Captures the content between opening and closing tags
165
- const script_regex = /<script(?:\s+lang=["']ts["'])?(?:\s*)>([^]*?)<\/script>/i;
166
- const match = script_regex.exec(svelte_source);
167
- return match?.[1];
168
- };
169
- /**
170
- * Extract module-level comment from Svelte script content.
171
- *
172
- * Requires `@module` tag to identify module comments. The tag line is stripped
173
- * from the output.
174
- *
175
- * @param script_content - the content of the `<script>` tag
176
- * @returns the cleaned module comment text, or undefined if none found
177
- */
178
- export const svelte_extract_module_comment = (script_content) => {
179
- // Parse the script content as TypeScript and reuse the shared extraction logic
180
- const source_file = ts.createSourceFile('script.ts', script_content, ts.ScriptTarget.Latest, true, ts.ScriptKind.TS);
181
- return ts_extract_module_comment(source_file);
182
- };
183
- /**
184
- * Extract component-level TSDoc comment from svelte2tsx transformed output.
185
- *
186
- * svelte2tsx places component-level JSDoc inside the $$render() function,
187
- * attached to a variable statement (usually before the props destructuring).
188
- * This function searches the AST recursively to find it.
189
- */
190
- const svelte_extract_component_tsdoc = (source_file) => {
191
- let found_tsdoc = undefined;
192
- // Recursively search for component-level JSDoc
193
- function visit(node) {
194
- if (found_tsdoc)
195
- return; // Already found, stop searching
196
- // Skip PropertySignature nodes - those are prop-level JSDoc, not component-level
197
- if (ts.isPropertySignature(node)) {
198
- return; // Don't recurse into property signatures
199
- }
200
- // Check for JSDoc on VariableStatement or VariableDeclaration
201
- // Component-level JSDoc is attached to these node types
202
- if (ts.isVariableStatement(node) || ts.isVariableDeclaration(node)) {
203
- const tsdoc = tsdoc_parse(node, source_file);
204
- if (tsdoc) {
205
- found_tsdoc = tsdoc;
206
- return;
207
- }
208
- }
209
- // Continue searching child nodes
210
- ts.forEachChild(node, visit);
211
- }
212
- visit(source_file);
213
- return found_tsdoc;
214
- };
215
- /**
216
- * Extract prop info from a property signature member.
217
- */
218
- const svelte_extract_prop_from_member = (member, source_file, checker, component_name, file_path, source_map, ctx) => {
219
- if (!ts.isIdentifier(member.name))
220
- return undefined;
221
- const prop_name = member.name.text;
222
- const optional = !!member.questionToken;
223
- // Get type string
224
- let type_string = 'any';
225
- if (member.type) {
226
- type_string = member.type.getText(source_file);
227
- }
228
- else {
229
- // Try to get type from type checker
230
- try {
231
- const prop_type = checker.getTypeAtLocation(member);
232
- type_string = checker.typeToString(prop_type);
233
- }
234
- catch (err) {
235
- // Fallback to 'any' but report diagnostic with mapped position
236
- const { line, character } = source_file.getLineAndCharacterOfPosition(member.getStart());
237
- // Map virtual position back to original .svelte file if source map available
238
- let final_line = line + 1;
239
- let final_column = character + 1;
240
- if (source_map) {
241
- const original = originalPositionFor(source_map, { line: line + 1, column: character });
242
- // When line is found, column is guaranteed to be present (same mapping entry)
243
- if (original.line !== null) {
244
- final_line = original.line;
245
- final_column = original.column + 1;
246
- }
247
- }
248
- ctx.add({
249
- kind: 'svelte_prop_failed',
250
- file: file_path,
251
- line: final_line,
252
- column: final_column,
253
- message: `Failed to resolve type for prop "${prop_name}" in ${component_name}, falling back to 'any': ${err instanceof Error ? err.message : String(err)}`,
254
- severity: 'warning',
255
- component_name,
256
- prop_name,
257
- });
258
- }
259
- }
260
- // Extract TSDoc description
261
- let description;
262
- const tsdoc = tsdoc_parse(member, source_file);
263
- if (tsdoc) {
264
- description = tsdoc.text;
265
- }
266
- // Extract default value (if available in TSDoc or initializer)
267
- let default_value;
268
- const default_match = description?.match(/@default\s+(.+)/);
269
- if (default_match) {
270
- default_value = default_match[1].trim();
271
- }
272
- return {
273
- name: prop_name,
274
- type: type_string,
275
- ...(optional && { optional }),
276
- description,
277
- default_value,
278
- };
279
- };
280
- /**
281
- * Extract bindable prop names from svelte2tsx transformed output.
282
- *
283
- * svelte2tsx marks bindable props with `__sveltets_$$bindings('prop1', 'prop2', ...)`.
284
- * This function extracts those prop names.
285
- */
286
- const svelte_extract_bindable_props = (virtual_source) => {
287
- const bindable_props = new Set();
288
- // Search for __sveltets_$$bindings call
289
- function visit(node) {
290
- if (ts.isCallExpression(node)) {
291
- const expr = node.expression;
292
- if (ts.isIdentifier(expr) && expr.text === '__sveltets_$$bindings') {
293
- // Extract string literal arguments
294
- for (const arg of node.arguments) {
295
- if (ts.isStringLiteral(arg)) {
296
- bindable_props.add(arg.text);
297
- }
298
- }
299
- }
300
- }
301
- ts.forEachChild(node, visit);
302
- }
303
- visit(virtual_source);
304
- return bindable_props;
305
- };
306
- /**
307
- * Extract props from a type node (handles type literals and intersection types).
308
- *
309
- * @mutates props - adds extracted prop info to the array
310
- */
311
- const svelte_extract_props_from_type = (type_node, virtual_source, checker, bindable_props, props, component_name, file_path, source_map, ctx) => {
312
- if (ts.isTypeLiteralNode(type_node)) {
313
- // Handle direct type literal: { prop1: type1, prop2: type2 }
314
- for (const member of type_node.members) {
315
- if (ts.isPropertySignature(member)) {
316
- const prop_info = svelte_extract_prop_from_member(member, virtual_source, checker, component_name, file_path, source_map, ctx);
317
- if (prop_info) {
318
- // Mark as bindable if found in bindings
319
- if (bindable_props.has(prop_info.name)) {
320
- prop_info.bindable = true;
321
- }
322
- props.push(prop_info);
323
- }
324
- }
325
- }
326
- }
327
- else if (ts.isIntersectionTypeNode(type_node)) {
328
- // Handle intersection type: TypeA & TypeB & { prop: type }
329
- for (const type_part of type_node.types) {
330
- svelte_extract_props_from_type(type_part, virtual_source, checker, bindable_props, props, component_name, file_path, source_map, ctx);
331
- }
332
- }
333
- // Skip other type references like SvelteHTMLElements['details'] since we can't easily resolve them
334
- };
335
- /**
336
- * Extract props from svelte2tsx transformed output.
337
- *
338
- * svelte2tsx generates a `$$ComponentProps` type alias containing the component props.
339
- * This function extracts prop metadata from that type.
340
- */
341
- const svelte_extract_props = (virtual_source, checker, component_name, file_path, source_map, ctx) => {
342
- const props = [];
343
- const bindable_props = svelte_extract_bindable_props(virtual_source);
344
- // Look for $$ComponentProps type alias or Props interface
345
- ts.forEachChild(virtual_source, (node) => {
346
- // Check for type alias ($$ComponentProps)
347
- if (ts.isTypeAliasDeclaration(node) && node.name.text === '$$ComponentProps') {
348
- svelte_extract_props_from_type(node.type, virtual_source, checker, bindable_props, props, component_name, file_path, source_map, ctx);
349
- }
350
- // Also check for Props interface (fallback/older format)
351
- else if (ts.isInterfaceDeclaration(node) && node.name.text === 'Props') {
352
- for (const member of node.members) {
353
- if (ts.isPropertySignature(member)) {
354
- const prop_info = svelte_extract_prop_from_member(member, virtual_source, checker, component_name, file_path, source_map, ctx);
355
- if (prop_info) {
356
- // Mark as bindable if found in bindings
357
- if (bindable_props.has(prop_info.name)) {
358
- prop_info.bindable = true;
359
- }
360
- props.push(prop_info);
361
- }
362
- }
363
- }
364
- }
365
- });
366
- return props;
367
- };
@@ -1,181 +0,0 @@
1
- /**
2
- * TypeScript compiler API helpers for extracting metadata from source code.
3
- *
4
- * All functions are prefixed with `ts_` for clarity.
5
- *
6
- * @module
7
- */
8
- import ts from 'typescript';
9
- import type { DeclarationJson, DeclarationKind } from '@fuzdev/fuz_util/source_json.js';
10
- import type { Logger } from '@fuzdev/fuz_util/log.js';
11
- import { tsdoc_parse } from './tsdoc_helpers.js';
12
- import { type ModuleSourceOptions, type SourceFileInfo } from './module_helpers.js';
13
- import type { AnalysisContext } from './analysis_context.js';
14
- import type { DeclarationAnalysis, ReExportInfo, ModuleAnalysis } from './library_analysis.js';
15
- /**
16
- * Options for creating a TypeScript program.
17
- */
18
- export interface TsProgramOptions {
19
- /** Project root directory. @default './' */
20
- root?: string;
21
- /** Path to `tsconfig.json` (relative to root). @default 'tsconfig.json' */
22
- tsconfig?: string;
23
- /** Override compiler options. */
24
- compiler_options?: ts.CompilerOptions;
25
- }
26
- /**
27
- * Result of creating a TypeScript program.
28
- */
29
- export interface TsProgram {
30
- program: ts.Program;
31
- checker: ts.TypeChecker;
32
- }
33
- /**
34
- * Result of analyzing a module's exports.
35
- */
36
- export interface ModuleExportsAnalysis {
37
- /** Module-level documentation comment. */
38
- module_comment?: string;
39
- /** All exported declarations with nodocs flags - consumer filters based on policy. */
40
- declarations: Array<DeclarationAnalysis>;
41
- /** Same-name re-exports (for building `also_exported_from` in post-processing). */
42
- re_exports: Array<ReExportInfo>;
43
- /** Star exports (`export * from './module'`) - module paths that are fully re-exported. */
44
- star_exports: Array<string>;
45
- }
46
- /**
47
- * Create TypeScript program for analysis.
48
- *
49
- * @param options - configuration options for program creation
50
- * @param log - optional logger for info messages
51
- * @returns the program and type checker
52
- * @throws Error if `tsconfig.json` is not found
53
- */
54
- export declare const ts_create_program: (options?: TsProgramOptions, log?: Logger) => TsProgram;
55
- /**
56
- * Analyze a TypeScript file and extract module metadata.
57
- *
58
- * Wraps `ts_analyze_module_exports` and adds dependency information
59
- * from the source file info if available.
60
- *
61
- * This is a high-level function suitable for building documentation or library metadata.
62
- * For lower-level analysis, use `ts_analyze_module_exports` directly.
63
- *
64
- * @param source_file_info - the source file info (from Gro filer, file system, or other source)
65
- * @param ts_source_file - TypeScript source file from the program
66
- * @param module_path - the module path (relative to source root)
67
- * @param checker - TypeScript type checker
68
- * @param options - module source options for path extraction
69
- * @param ctx - analysis context for collecting diagnostics
70
- * @returns module metadata and re-export information
71
- */
72
- export declare const ts_analyze_module: (source_file_info: SourceFileInfo, ts_source_file: ts.SourceFile, module_path: string, checker: ts.TypeChecker, options: ModuleSourceOptions, ctx: AnalysisContext) => ModuleAnalysis;
73
- /**
74
- * Analyze all exports from a TypeScript source file.
75
- *
76
- * Extracts the module-level comment and all exported declarations with
77
- * complete metadata. Handles re-exports by:
78
- * - Same-name re-exports: tracked in `re_exports` for `also_exported_from` building
79
- * - Renamed re-exports: included as new declarations with `alias_of` metadata
80
- * - Star exports (`export * from`): tracked in `star_exports` for namespace-level info
81
- *
82
- * This is a mid-level function (above `ts_extract_*`, below `library_gen`)
83
- * suitable for building documentation, API explorers, or analysis tools.
84
- * For standard SvelteKit library layouts, use `module_create_source_options(process.cwd())`.
85
- *
86
- * @param source_file - the TypeScript source file to analyze
87
- * @param checker - the TypeScript type checker
88
- * @param options - module source options for path extraction in re-exports
89
- * @param ctx - analysis context for collecting diagnostics
90
- * @returns module comment, declarations, re-exports, and star exports
91
- */
92
- export declare const ts_analyze_module_exports: (source_file: ts.SourceFile, checker: ts.TypeChecker, options: ModuleSourceOptions, ctx: AnalysisContext) => ModuleExportsAnalysis;
93
- /**
94
- * Analyze a TypeScript symbol and extract rich metadata.
95
- *
96
- * This is a high-level function that combines TSDoc parsing with TypeScript
97
- * type analysis to produce complete declaration metadata. Suitable for use
98
- * in documentation generators, IDE integrations, and other tooling.
99
- *
100
- * @param symbol - the TypeScript symbol to analyze
101
- * @param source_file - the source file containing the symbol
102
- * @param checker - the TypeScript type checker
103
- * @param ctx - optional analysis context for collecting diagnostics
104
- * @returns complete declaration metadata including docs, types, and parameters, plus nodocs flag
105
- */
106
- export declare const ts_analyze_declaration: (symbol: ts.Symbol, source_file: ts.SourceFile, checker: ts.TypeChecker, ctx: AnalysisContext) => DeclarationAnalysis;
107
- /**
108
- * Extract module-level comment.
109
- *
110
- * Requires `@module` tag to identify module comments. The tag line is stripped
111
- * from the output. Supports optional module renaming: `@module custom-name`.
112
- *
113
- * @see {@link https://typedoc.org/documents/Tags._module.html}
114
- */
115
- export declare const ts_extract_module_comment: (source_file: ts.SourceFile) => string | undefined;
116
- /**
117
- * Infer declaration kind from symbol and node.
118
- *
119
- * Maps TypeScript constructs to `DeclarationKind`:
120
- * - Classes → `'class'`
121
- * - Functions (declarations, expressions, arrows) → `'function'`
122
- * - Interfaces, type aliases → `'type'`
123
- * - Enums (regular and const) → `'type'`
124
- * - Variables → `'variable'` (unless function-valued → `'function'`)
125
- */
126
- export declare const ts_infer_declaration_kind: (symbol: ts.Symbol, node: ts.Node) => DeclarationKind;
127
- /**
128
- * Extract parameters from a TypeScript signature with TSDoc descriptions and default values.
129
- *
130
- * Shared helper for extracting parameter information from both standalone functions
131
- * and class methods/constructors.
132
- *
133
- * @param sig - the TypeScript signature to extract parameters from
134
- * @param checker - TypeScript type checker for type resolution
135
- * @param tsdoc_params - map of parameter names to TSDoc descriptions (from tsdoc.params)
136
- * @returns array of parameter info objects
137
- */
138
- export declare const ts_extract_signature_parameters: (sig: ts.Signature, checker: ts.TypeChecker, tsdoc_params: Map<string, string> | undefined) => Array<{
139
- name: string;
140
- type: string;
141
- optional?: boolean;
142
- description?: string;
143
- default_value?: string;
144
- }>;
145
- /**
146
- * Extract function/method information including parameters
147
- * with descriptions and default values.
148
- *
149
- * @internal Use `ts_analyze_declaration` for high-level analysis.
150
- * @mutates declaration - adds type_signature, return_type, return_description, throws, since, parameters, generic_params
151
- */
152
- export declare const ts_extract_function_info: (node: ts.Node, symbol: ts.Symbol, checker: ts.TypeChecker, declaration: DeclarationJson, tsdoc: ReturnType<typeof tsdoc_parse>, ctx: AnalysisContext) => void;
153
- /**
154
- * Extract type/interface information with rich property metadata.
155
- *
156
- * @internal Use `ts_analyze_declaration` for high-level analysis.
157
- * @mutates declaration - adds type_signature, generic_params, extends, properties
158
- */
159
- export declare const ts_extract_type_info: (node: ts.Node, _symbol: ts.Symbol, checker: ts.TypeChecker, declaration: DeclarationJson, ctx: AnalysisContext) => void;
160
- /**
161
- * Extract class information with rich member metadata.
162
- *
163
- * @internal Use `ts_analyze_declaration` for high-level analysis.
164
- * @mutates declaration - adds extends, implements, generic_params, members
165
- */
166
- export declare const ts_extract_class_info: (node: ts.Node, _symbol: ts.Symbol, checker: ts.TypeChecker, declaration: DeclarationJson, ctx: AnalysisContext) => void;
167
- /**
168
- * Extract variable information.
169
- *
170
- * @internal Use `ts_analyze_declaration` for high-level analysis.
171
- * @mutates declaration - adds type_signature
172
- */
173
- export declare const ts_extract_variable_info: (node: ts.Node, symbol: ts.Symbol, checker: ts.TypeChecker, declaration: DeclarationJson, ctx: AnalysisContext) => void;
174
- /**
175
- * TypeScript modifier keywords extracted from declarations.
176
- *
177
- * These are the access modifiers and other keywords that can appear
178
- * on class members, interface properties, etc.
179
- */
180
- export type TsModifier = 'public' | 'private' | 'protected' | 'readonly' | 'static' | 'abstract';
181
- //# sourceMappingURL=ts_helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ts_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/ts_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EACX,eAAe,EAEf,eAAe,EACf,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EAAC,WAAW,EAAkD,MAAM,oBAAoB,CAAC;AAChG,OAAO,EACN,KAAK,mBAAmB,EACxB,KAAK,cAAc,EAInB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAE3D,OAAO,KAAK,EAAC,mBAAmB,EAAE,YAAY,EAAE,cAAc,EAAC,MAAM,uBAAuB,CAAC;AAE7F;;GAEG;AACH,MAAM,WAAW,gBAAgB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