@fuzdev/fuz_ui 0.175.0 โ 0.176.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.
- package/README.md +1 -1
- package/dist/Alert.svelte +2 -0
- package/dist/Alert.svelte.d.ts.map +1 -1
- package/dist/ApiModule.svelte +5 -6
- package/dist/ApiModule.svelte.d.ts.map +1 -1
- package/dist/DeclarationDetail.svelte +2 -1
- package/dist/DeclarationDetail.svelte.d.ts.map +1 -1
- package/dist/Details.svelte +2 -0
- package/dist/Details.svelte.d.ts.map +1 -1
- package/dist/Themed.svelte +2 -0
- package/dist/Themed.svelte.d.ts.map +1 -1
- package/dist/analysis_context.d.ts +195 -0
- package/dist/analysis_context.d.ts.map +1 -0
- package/dist/analysis_context.js +134 -0
- package/dist/library_analysis.d.ts +112 -0
- package/dist/library_analysis.d.ts.map +1 -0
- package/dist/library_analysis.js +106 -0
- package/dist/library_gen.d.ts +88 -5
- package/dist/library_gen.d.ts.map +1 -1
- package/dist/library_gen.js +163 -69
- package/dist/library_gen_helpers.d.ts +81 -72
- package/dist/library_gen_helpers.d.ts.map +1 -1
- package/dist/library_gen_helpers.js +115 -156
- package/dist/library_gen_output.d.ts +34 -0
- package/dist/library_gen_output.d.ts.map +1 -0
- package/dist/library_gen_output.js +40 -0
- package/dist/mdz.d.ts +3 -0
- package/dist/mdz.d.ts.map +1 -1
- package/dist/mdz.js +12 -3
- package/dist/module_helpers.d.ts +246 -24
- package/dist/module_helpers.d.ts.map +1 -1
- package/dist/module_helpers.js +250 -42
- package/dist/svelte_helpers.d.ts +65 -10
- package/dist/svelte_helpers.d.ts.map +1 -1
- package/dist/svelte_helpers.js +171 -49
- package/dist/ts_helpers.d.ts +132 -61
- package/dist/ts_helpers.d.ts.map +1 -1
- package/dist/ts_helpers.js +423 -282
- package/dist/tsdoc_helpers.d.ts +11 -0
- package/dist/tsdoc_helpers.d.ts.map +1 -1
- package/dist/tsdoc_helpers.js +22 -47
- package/dist/tsdoc_mdz.d.ts +36 -0
- package/dist/tsdoc_mdz.d.ts.map +1 -0
- package/dist/tsdoc_mdz.js +56 -0
- package/dist/vite_plugin_library_well_known.js +5 -5
- package/package.json +11 -6
- package/src/lib/analysis_context.ts +250 -0
- package/src/lib/library_analysis.ts +168 -0
- package/src/lib/library_gen.ts +247 -84
- package/src/lib/library_gen_helpers.ts +148 -215
- package/src/lib/library_gen_output.ts +63 -0
- package/src/lib/mdz.ts +13 -4
- package/src/lib/module_helpers.ts +392 -47
- package/src/lib/svelte_helpers.ts +291 -55
- package/src/lib/ts_helpers.ts +538 -338
- package/src/lib/tsdoc_helpers.ts +24 -49
- package/src/lib/tsdoc_mdz.ts +62 -0
- package/src/lib/vite_plugin_library_well_known.ts +5 -5
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
> friendly user zystem ๐งถ [fuz.dev](https://ui.fuz.dev/)
|
|
6
6
|
|
|
7
7
|
Fuz UI is a [Svelte](https://svelte.dev/) UI library
|
|
8
|
-
with components and helpers for making
|
|
8
|
+
with components and helpers for making zippy websites.
|
|
9
9
|
It's in early alpha and it will go through many breaking changes.
|
|
10
10
|
|
|
11
11
|
Fuz UI is being made to support
|
package/dist/Alert.svelte
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Alert.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/Alert.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAuB,KAAK,WAAW,EAAC,MAAM,YAAY,CAAC;AAEjE,KAAK,gBAAgB,GAAI,kBAAkB,CAAC,KAAK,CAAC,GACjD,kBAAkB,CAAC,QAAQ,CAAC,GAAG;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,OAAO,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAC3D,QAAQ,EAAE,OAAO,CAAC;CAClB,CAAC;
|
|
1
|
+
{"version":3,"file":"Alert.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/Alert.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAExD,OAAO,EAAuB,KAAK,WAAW,EAAC,MAAM,YAAY,CAAC;AAEjE,KAAK,gBAAgB,GAAI,kBAAkB,CAAC,KAAK,CAAC,GACjD,kBAAkB,CAAC,QAAQ,CAAC,GAAG;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IAKf,OAAO,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;IAC3D,QAAQ,EAAE,OAAO,CAAC;CAClB,CAAC;AAgEJ,QAAA,MAAM,KAAK,sDAAwC,CAAC;AACpD,KAAK,KAAK,GAAG,UAAU,CAAC,OAAO,KAAK,CAAC,CAAC;AACtC,eAAe,KAAK,CAAC"}
|
package/dist/ApiModule.svelte
CHANGED
|
@@ -62,17 +62,16 @@
|
|
|
62
62
|
<p>Module not found: {module_path}</p>
|
|
63
63
|
</section>
|
|
64
64
|
{:else}
|
|
65
|
+
{#if module.module_comment}
|
|
66
|
+
<section>
|
|
67
|
+
<Mdz content={module.module_comment} />
|
|
68
|
+
</section>
|
|
69
|
+
{/if}
|
|
65
70
|
<!-- Declarations Section -->
|
|
66
71
|
<TomeSection>
|
|
67
72
|
<TomeSectionHeader text="Declarations" />
|
|
68
73
|
|
|
69
74
|
<section>
|
|
70
|
-
{#if module.module_comment}
|
|
71
|
-
<blockquote>
|
|
72
|
-
<Mdz content={module.module_comment} />
|
|
73
|
-
</blockquote>
|
|
74
|
-
{/if}
|
|
75
|
-
|
|
76
75
|
{#if search.all.length > 1}
|
|
77
76
|
<DocsSearch
|
|
78
77
|
placeholder="search declarations in this module..."
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiModule.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/ApiModule.svelte"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,OAAO,EAAC,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAmB,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAUrD,KAAK,gBAAgB,GAAI;IACxB;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;CACZ,CAAC;
|
|
1
|
+
{"version":3,"file":"ApiModule.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/ApiModule.svelte"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,OAAO,EAAC,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAmB,KAAK,IAAI,EAAC,MAAM,WAAW,CAAC;AAUrD,KAAK,gBAAgB,GAAI;IACxB;;OAEG;IACH,WAAW,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IACpC;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,IAAI,CAAC,EAAE,IAAI,CAAC;CACZ,CAAC;AA2GH,QAAA,MAAM,SAAS,sDAAwC,CAAC;AACxD,KAAK,SAAS,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC;AAC9C,eAAe,SAAS,CAAC"}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import TypeLink from './TypeLink.svelte';
|
|
7
7
|
import ModuleLink from './ModuleLink.svelte';
|
|
8
8
|
import Mdz from './Mdz.svelte';
|
|
9
|
+
import {tsdoc_see_to_mdz} from './tsdoc_mdz.js';
|
|
9
10
|
|
|
10
11
|
const {declaration}: {declaration: Declaration} = $props();
|
|
11
12
|
</script>
|
|
@@ -215,7 +216,7 @@
|
|
|
215
216
|
<ul>
|
|
216
217
|
{#each declaration.see_also as ref (ref)}
|
|
217
218
|
<li>
|
|
218
|
-
<Mdz content={ref} />
|
|
219
|
+
<Mdz content={tsdoc_see_to_mdz(ref)} />
|
|
219
220
|
</li>
|
|
220
221
|
{/each}
|
|
221
222
|
</ul>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeclarationDetail.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/DeclarationDetail.svelte"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"DeclarationDetail.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/DeclarationDetail.svelte"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AAOxD,KAAK,gBAAgB,GAAI;IAAC,WAAW,EAAE,WAAW,CAAA;CAAC,CAAC;AAiVrD,QAAA,MAAM,iBAAiB,sDAAwC,CAAC;AAChE,KAAK,iBAAiB,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC9D,eAAe,iBAAiB,CAAC"}
|
package/dist/Details.svelte
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Details.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/Details.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAGvD,KAAK,gBAAgB,GAAI,kBAAkB,CAAC,SAAS,CAAC,GAAG;IACxD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC9C,QAAQ,EAAE,OAAO,CAAC;CAClB,CAAC;
|
|
1
|
+
{"version":3,"file":"Details.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/Details.svelte"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,QAAQ,CAAC;AACpC,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,iBAAiB,CAAC;AAGvD,KAAK,gBAAgB,GAAI,kBAAkB,CAAC,SAAS,CAAC,GAAG;IACxD,IAAI,CAAC,EAAE,OAAO,CAAC;IACf;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,aAAa,CAAC,EAAE,kBAAkB,CAAC,SAAS,CAAC,CAAC;IAC9C,QAAQ,EAAE,OAAO,CAAC;CAClB,CAAC;AA4CH,QAAA,MAAM,OAAO,0DAAwC,CAAC;AACtD,KAAK,OAAO,GAAG,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC;AAC1C,eAAe,OAAO,CAAC"}
|
package/dist/Themed.svelte
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Themed.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/Themed.svelte"],"names":[],"mappings":"AAMA,OAAO,EAAU,KAAK,OAAO,EAAC,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAqB,KAAK,KAAK,EAAC,MAAM,0BAA0B,CAAC;AAIxE,OAAO,EACL,iBAAiB,IAAI,yBAAyB,EAC9C,iBAAiB,IAAI,yBAAyB,EAC9C,iBAAiB,IAAI,yBAAyB,EAC9C,UAAU,IAAI,kBAAkB,EAChC,UAAU,IAAI,kBAAkB,EAEhC,MAAM,EACN,MAAM,oBAAoB,CAAC;AAG5B,KAAK,gBAAgB,GAAI;IACxB,iBAAiB,CAAC,EAAE,OAAO,yBAAyB,CAAC;IACrD,iBAAiB,CAAC,EAAE,OAAO,yBAAyB,CAAC;IACrD,iBAAiB,CAAC,EAAE,OAAO,yBAAyB,CAAC;IACrD,UAAU,CAAC,EAAE,OAAO,kBAAkB,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,kBAAkB,CAAC;IACvC,cAAc,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IACnC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CAC3F,CAAC;
|
|
1
|
+
{"version":3,"file":"Themed.svelte.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/Themed.svelte"],"names":[],"mappings":"AAMA,OAAO,EAAU,KAAK,OAAO,EAAC,MAAM,QAAQ,CAAC;AAC7C,OAAO,EAAqB,KAAK,KAAK,EAAC,MAAM,0BAA0B,CAAC;AAIxE,OAAO,EACL,iBAAiB,IAAI,yBAAyB,EAC9C,iBAAiB,IAAI,yBAAyB,EAC9C,iBAAiB,IAAI,yBAAyB,EAC9C,UAAU,IAAI,kBAAkB,EAChC,UAAU,IAAI,kBAAkB,EAEhC,MAAM,EACN,MAAM,oBAAoB,CAAC;AAG5B,KAAK,gBAAgB,GAAI;IACxB,iBAAiB,CAAC,EAAE,OAAO,yBAAyB,CAAC;IACrD,iBAAiB,CAAC,EAAE,OAAO,yBAAyB,CAAC;IACrD,iBAAiB,CAAC,EAAE,OAAO,yBAAyB,CAAC;IACrD,UAAU,CAAC,EAAE,OAAO,kBAAkB,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,kBAAkB,CAAC;IACvC,cAAc,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IACnC;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,EAAE,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;CAC3F,CAAC;AAkFH,QAAA,MAAM,MAAM,sDAAwC,CAAC;AACrD,KAAK,MAAM,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,CAAC;AACxC,eAAe,MAAM,CAAC"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostic collection for source analysis.
|
|
3
|
+
*
|
|
4
|
+
* Provides structured error/warning collection during TypeScript and Svelte
|
|
5
|
+
* analysis, replacing silent catch blocks with actionable diagnostics.
|
|
6
|
+
*
|
|
7
|
+
* ## Error Handling Contract
|
|
8
|
+
*
|
|
9
|
+
* Analysis functions follow a two-tier error model:
|
|
10
|
+
*
|
|
11
|
+
* **Accumulated (non-fatal)** - Collected in AnalysisContext, analysis continues:
|
|
12
|
+
* - Type resolution failures (complex generics, circular refs)
|
|
13
|
+
* - Missing or unparseable JSDoc
|
|
14
|
+
* - Individual member/prop extraction failures
|
|
15
|
+
* - The return value is still valid but may have partial data
|
|
16
|
+
*
|
|
17
|
+
* **Thrown (fatal)** - Analysis cannot continue for this file:
|
|
18
|
+
* - File not found or unreadable
|
|
19
|
+
* - Syntax errors preventing parsing
|
|
20
|
+
* - svelte2tsx transformation failures
|
|
21
|
+
* - Svelte version incompatibility
|
|
22
|
+
*
|
|
23
|
+
* ## Usage Pattern
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* const ctx = new AnalysisContext();
|
|
27
|
+
* const results = files.map(f => {
|
|
28
|
+
* try {
|
|
29
|
+
* return library_analyze_module(f, program, options, ctx);
|
|
30
|
+
* } catch (e) {
|
|
31
|
+
* // Fatal error - log and skip this file
|
|
32
|
+
* console.error(`Failed to analyze ${f.id}: ${e}`);
|
|
33
|
+
* return null;
|
|
34
|
+
* }
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Results are valid even with accumulated errors
|
|
38
|
+
* // Check ctx for diagnostics to display to user
|
|
39
|
+
* if (ctx.has_errors()) {
|
|
40
|
+
* for (const err of ctx.errors()) {
|
|
41
|
+
* console.error(format_diagnostic(err));
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const ctx = new AnalysisContext();
|
|
48
|
+
* // ... analysis functions add diagnostics via ctx.add(...)
|
|
49
|
+
* if (ctx.has_errors()) {
|
|
50
|
+
* for (const err of ctx.errors()) {
|
|
51
|
+
* console.error(`${err.file}:${err.line}: ${err.message}`);
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* @module
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* Diagnostic severity levels.
|
|
59
|
+
*
|
|
60
|
+
* - `error`: Analysis failed, declaration may be incomplete or missing data
|
|
61
|
+
* - `warning`: Partial success, something seems off but analysis continued
|
|
62
|
+
*/
|
|
63
|
+
export type DiagnosticSeverity = 'error' | 'warning';
|
|
64
|
+
/**
|
|
65
|
+
* Discriminant for diagnostic types.
|
|
66
|
+
*/
|
|
67
|
+
export type DiagnosticKind = 'type_extraction_failed' | 'signature_analysis_failed' | 'class_member_failed' | 'svelte_prop_failed' | 'module_skipped';
|
|
68
|
+
/**
|
|
69
|
+
* Base diagnostic fields shared by all diagnostic types.
|
|
70
|
+
*/
|
|
71
|
+
export interface BaseDiagnostic {
|
|
72
|
+
kind: DiagnosticKind;
|
|
73
|
+
/** File path relative to project root (display with './' prefix). */
|
|
74
|
+
file: string;
|
|
75
|
+
/** Line number (1-based), or null if location unavailable. */
|
|
76
|
+
line: number | null;
|
|
77
|
+
/** Column number (1-based), or null if location unavailable. */
|
|
78
|
+
column: number | null;
|
|
79
|
+
/** Human-readable description of the issue. */
|
|
80
|
+
message: string;
|
|
81
|
+
severity: DiagnosticSeverity;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Type extraction failed (e.g., complex or recursive types).
|
|
85
|
+
*/
|
|
86
|
+
export interface TypeExtractionDiagnostic extends BaseDiagnostic {
|
|
87
|
+
kind: 'type_extraction_failed';
|
|
88
|
+
/** Name of the symbol whose type couldn't be extracted. */
|
|
89
|
+
symbol_name: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Function/method signature analysis failed.
|
|
93
|
+
*/
|
|
94
|
+
export interface SignatureAnalysisDiagnostic extends BaseDiagnostic {
|
|
95
|
+
kind: 'signature_analysis_failed';
|
|
96
|
+
/** Name of the function or method. */
|
|
97
|
+
function_name: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Class member analysis failed.
|
|
101
|
+
*/
|
|
102
|
+
export interface ClassMemberDiagnostic extends BaseDiagnostic {
|
|
103
|
+
kind: 'class_member_failed';
|
|
104
|
+
/** Name of the class. */
|
|
105
|
+
class_name: string;
|
|
106
|
+
/** Name of the member that failed. */
|
|
107
|
+
member_name: string;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Svelte prop type resolution failed.
|
|
111
|
+
*/
|
|
112
|
+
export interface SveltePropDiagnostic extends BaseDiagnostic {
|
|
113
|
+
kind: 'svelte_prop_failed';
|
|
114
|
+
/** Name of the component. */
|
|
115
|
+
component_name: string;
|
|
116
|
+
/** Name of the prop. */
|
|
117
|
+
prop_name: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Module was skipped during analysis.
|
|
121
|
+
* Could be due to missing source file in program or no analyzer available.
|
|
122
|
+
*/
|
|
123
|
+
export interface ModuleSkippedDiagnostic extends BaseDiagnostic {
|
|
124
|
+
kind: 'module_skipped';
|
|
125
|
+
/** Reason the module was skipped. */
|
|
126
|
+
reason: 'not_in_program' | 'no_analyzer';
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Union of all diagnostic types.
|
|
130
|
+
*/
|
|
131
|
+
export type Diagnostic = TypeExtractionDiagnostic | SignatureAnalysisDiagnostic | ClassMemberDiagnostic | SveltePropDiagnostic | ModuleSkippedDiagnostic;
|
|
132
|
+
/**
|
|
133
|
+
* Context for collecting diagnostics during source analysis.
|
|
134
|
+
*
|
|
135
|
+
* Thread an instance through analysis functions to collect errors and warnings
|
|
136
|
+
* without halting analysis. After analysis completes, check `has_errors()` and
|
|
137
|
+
* report collected diagnostics.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* const ctx = new AnalysisContext();
|
|
141
|
+
* ts_analyze_module_exports(source_file, checker, options, ctx);
|
|
142
|
+
* if (ctx.has_errors()) {
|
|
143
|
+
* console.error('Analysis completed with errors:');
|
|
144
|
+
* for (const d of ctx.errors()) {
|
|
145
|
+
* console.error(format_diagnostic(d));
|
|
146
|
+
* }
|
|
147
|
+
* }
|
|
148
|
+
*/
|
|
149
|
+
export declare class AnalysisContext {
|
|
150
|
+
readonly diagnostics: Array<Diagnostic>;
|
|
151
|
+
/**
|
|
152
|
+
* Add a diagnostic to the collection.
|
|
153
|
+
*/
|
|
154
|
+
add(diagnostic: Diagnostic): void;
|
|
155
|
+
/**
|
|
156
|
+
* Check if any errors were collected.
|
|
157
|
+
*/
|
|
158
|
+
has_errors(): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Check if any warnings were collected.
|
|
161
|
+
*/
|
|
162
|
+
has_warnings(): boolean;
|
|
163
|
+
/**
|
|
164
|
+
* Get all error diagnostics.
|
|
165
|
+
*/
|
|
166
|
+
errors(): Array<Diagnostic>;
|
|
167
|
+
/**
|
|
168
|
+
* Get all warning diagnostics.
|
|
169
|
+
*/
|
|
170
|
+
warnings(): Array<Diagnostic>;
|
|
171
|
+
/**
|
|
172
|
+
* Get diagnostics of a specific kind.
|
|
173
|
+
*/
|
|
174
|
+
by_kind<K extends DiagnosticKind>(kind: K): Array<Extract<Diagnostic, {
|
|
175
|
+
kind: K;
|
|
176
|
+
}>>;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Options for formatting diagnostics.
|
|
180
|
+
*/
|
|
181
|
+
export interface FormatDiagnosticOptions {
|
|
182
|
+
/** Prefix for file path (default: './'). */
|
|
183
|
+
prefix?: string;
|
|
184
|
+
/** Base path to strip from absolute file paths (e.g., process.cwd()). */
|
|
185
|
+
strip_base?: string;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Format a diagnostic for display.
|
|
189
|
+
*
|
|
190
|
+
* @param diagnostic The diagnostic to format
|
|
191
|
+
* @param options Formatting options
|
|
192
|
+
* @returns Formatted string like './file.ts:10:5: error: message'
|
|
193
|
+
*/
|
|
194
|
+
export declare const format_diagnostic: (diagnostic: Diagnostic, options?: FormatDiagnosticOptions) => string;
|
|
195
|
+
//# sourceMappingURL=analysis_context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analysis_context.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/analysis_context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AAEH;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,GAAG,SAAS,CAAC;AAErD;;GAEG;AACH,MAAM,MAAM,cAAc,GACvB,wBAAwB,GACxB,2BAA2B,GAC3B,qBAAqB,GACrB,oBAAoB,GACpB,gBAAgB,CAAC;AAEpB;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,IAAI,EAAE,cAAc,CAAC;IACrB,qEAAqE;IACrE,IAAI,EAAE,MAAM,CAAC;IACb,8DAA8D;IAC9D,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,gEAAgE;IAChE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,kBAAkB,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,wBAAyB,SAAQ,cAAc;IAC/D,IAAI,EAAE,wBAAwB,CAAC;IAC/B,2DAA2D;IAC3D,WAAW,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,2BAA4B,SAAQ,cAAc;IAClE,IAAI,EAAE,2BAA2B,CAAC;IAClC,sCAAsC;IACtC,aAAa,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC5D,IAAI,EAAE,qBAAqB,CAAC;IAC5B,yBAAyB;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,cAAc;IAC3D,IAAI,EAAE,oBAAoB,CAAC;IAC3B,6BAA6B;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,wBAAwB;IACxB,SAAS,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAwB,SAAQ,cAAc;IAC9D,IAAI,EAAE,gBAAgB,CAAC;IACvB,qCAAqC;IACrC,MAAM,EAAE,gBAAgB,GAAG,aAAa,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GACnB,wBAAwB,GACxB,2BAA2B,GAC3B,qBAAqB,GACrB,oBAAoB,GACpB,uBAAuB,CAAC;AAE3B;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,eAAe;IAC3B,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,UAAU,CAAC,CAAM;IAE7C;;OAEG;IACH,GAAG,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAIjC;;OAEG;IACH,UAAU,IAAI,OAAO;IAIrB;;OAEG;IACH,YAAY,IAAI,OAAO;IAIvB;;OAEG;IACH,MAAM,IAAI,KAAK,CAAC,UAAU,CAAC;IAI3B;;OAEG;IACH,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC;IAI7B;;OAEG;IACH,OAAO,CAAC,CAAC,SAAS,cAAc,EAAE,IAAI,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE;QAAC,IAAI,EAAE,CAAC,CAAA;KAAC,CAAC,CAAC;CAGjF;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACvC,4CAA4C;IAC5C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yEAAyE;IACzE,UAAU,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,GAC7B,YAAY,UAAU,EACtB,UAAU,uBAAuB,KAC/B,MAeF,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostic collection for source analysis.
|
|
3
|
+
*
|
|
4
|
+
* Provides structured error/warning collection during TypeScript and Svelte
|
|
5
|
+
* analysis, replacing silent catch blocks with actionable diagnostics.
|
|
6
|
+
*
|
|
7
|
+
* ## Error Handling Contract
|
|
8
|
+
*
|
|
9
|
+
* Analysis functions follow a two-tier error model:
|
|
10
|
+
*
|
|
11
|
+
* **Accumulated (non-fatal)** - Collected in AnalysisContext, analysis continues:
|
|
12
|
+
* - Type resolution failures (complex generics, circular refs)
|
|
13
|
+
* - Missing or unparseable JSDoc
|
|
14
|
+
* - Individual member/prop extraction failures
|
|
15
|
+
* - The return value is still valid but may have partial data
|
|
16
|
+
*
|
|
17
|
+
* **Thrown (fatal)** - Analysis cannot continue for this file:
|
|
18
|
+
* - File not found or unreadable
|
|
19
|
+
* - Syntax errors preventing parsing
|
|
20
|
+
* - svelte2tsx transformation failures
|
|
21
|
+
* - Svelte version incompatibility
|
|
22
|
+
*
|
|
23
|
+
* ## Usage Pattern
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* const ctx = new AnalysisContext();
|
|
27
|
+
* const results = files.map(f => {
|
|
28
|
+
* try {
|
|
29
|
+
* return library_analyze_module(f, program, options, ctx);
|
|
30
|
+
* } catch (e) {
|
|
31
|
+
* // Fatal error - log and skip this file
|
|
32
|
+
* console.error(`Failed to analyze ${f.id}: ${e}`);
|
|
33
|
+
* return null;
|
|
34
|
+
* }
|
|
35
|
+
* });
|
|
36
|
+
*
|
|
37
|
+
* // Results are valid even with accumulated errors
|
|
38
|
+
* // Check ctx for diagnostics to display to user
|
|
39
|
+
* if (ctx.has_errors()) {
|
|
40
|
+
* for (const err of ctx.errors()) {
|
|
41
|
+
* console.error(format_diagnostic(err));
|
|
42
|
+
* }
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* const ctx = new AnalysisContext();
|
|
48
|
+
* // ... analysis functions add diagnostics via ctx.add(...)
|
|
49
|
+
* if (ctx.has_errors()) {
|
|
50
|
+
* for (const err of ctx.errors()) {
|
|
51
|
+
* console.error(`${err.file}:${err.line}: ${err.message}`);
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
*
|
|
55
|
+
* @module
|
|
56
|
+
*/
|
|
57
|
+
/**
|
|
58
|
+
* Context for collecting diagnostics during source analysis.
|
|
59
|
+
*
|
|
60
|
+
* Thread an instance through analysis functions to collect errors and warnings
|
|
61
|
+
* without halting analysis. After analysis completes, check `has_errors()` and
|
|
62
|
+
* report collected diagnostics.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* const ctx = new AnalysisContext();
|
|
66
|
+
* ts_analyze_module_exports(source_file, checker, options, ctx);
|
|
67
|
+
* if (ctx.has_errors()) {
|
|
68
|
+
* console.error('Analysis completed with errors:');
|
|
69
|
+
* for (const d of ctx.errors()) {
|
|
70
|
+
* console.error(format_diagnostic(d));
|
|
71
|
+
* }
|
|
72
|
+
* }
|
|
73
|
+
*/
|
|
74
|
+
export class AnalysisContext {
|
|
75
|
+
diagnostics = [];
|
|
76
|
+
/**
|
|
77
|
+
* Add a diagnostic to the collection.
|
|
78
|
+
*/
|
|
79
|
+
add(diagnostic) {
|
|
80
|
+
this.diagnostics.push(diagnostic);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Check if any errors were collected.
|
|
84
|
+
*/
|
|
85
|
+
has_errors() {
|
|
86
|
+
return this.diagnostics.some((d) => d.severity === 'error');
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Check if any warnings were collected.
|
|
90
|
+
*/
|
|
91
|
+
has_warnings() {
|
|
92
|
+
return this.diagnostics.some((d) => d.severity === 'warning');
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get all error diagnostics.
|
|
96
|
+
*/
|
|
97
|
+
errors() {
|
|
98
|
+
return this.diagnostics.filter((d) => d.severity === 'error');
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Get all warning diagnostics.
|
|
102
|
+
*/
|
|
103
|
+
warnings() {
|
|
104
|
+
return this.diagnostics.filter((d) => d.severity === 'warning');
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Get diagnostics of a specific kind.
|
|
108
|
+
*/
|
|
109
|
+
by_kind(kind) {
|
|
110
|
+
return this.diagnostics.filter((d) => d.kind === kind);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Format a diagnostic for display.
|
|
115
|
+
*
|
|
116
|
+
* @param diagnostic The diagnostic to format
|
|
117
|
+
* @param options Formatting options
|
|
118
|
+
* @returns Formatted string like './file.ts:10:5: error: message'
|
|
119
|
+
*/
|
|
120
|
+
export const format_diagnostic = (diagnostic, options) => {
|
|
121
|
+
const prefix = options?.prefix ?? './';
|
|
122
|
+
const strip_base = options?.strip_base;
|
|
123
|
+
let file = diagnostic.file;
|
|
124
|
+
if (strip_base && file.startsWith(strip_base)) {
|
|
125
|
+
file = file.slice(strip_base.length);
|
|
126
|
+
// Remove leading slash if present
|
|
127
|
+
if (file.startsWith('/'))
|
|
128
|
+
file = file.slice(1);
|
|
129
|
+
}
|
|
130
|
+
const { line, column, severity, message } = diagnostic;
|
|
131
|
+
const location = line !== null ? (column !== null ? `${line}:${column}` : `${line}`) : '';
|
|
132
|
+
const file_part = location ? `${prefix}${file}:${location}` : `${prefix}${file}`;
|
|
133
|
+
return `${file_part}: ${severity}: ${message}`;
|
|
134
|
+
};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library source analysis - unified entry point and shared types.
|
|
3
|
+
*
|
|
4
|
+
* Provides a single function for analyzing TypeScript and Svelte source files,
|
|
5
|
+
* dispatching to the appropriate domain-specific analyzer.
|
|
6
|
+
*
|
|
7
|
+
* This module also exports shared types used by both analyzers:
|
|
8
|
+
* - `DeclarationAnalysis` - A declaration with its nodocs flag
|
|
9
|
+
* - `ReExportInfo` - Information about a same-name re-export
|
|
10
|
+
* - `ModuleAnalysis` - Result of analyzing a module (unified structure)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import {library_analyze_module} from './library_analysis.js';
|
|
15
|
+
* import {ts_create_program} from './ts_helpers.js';
|
|
16
|
+
* import {module_create_source_options} from './module_helpers.js';
|
|
17
|
+
* import {AnalysisContext} from './analysis_context.js';
|
|
18
|
+
*
|
|
19
|
+
* const {program} = ts_create_program({root: './my-project'});
|
|
20
|
+
* const ctx = new AnalysisContext();
|
|
21
|
+
* const options = module_create_source_options('/my-project');
|
|
22
|
+
*
|
|
23
|
+
* const result = library_analyze_module(
|
|
24
|
+
* {id: '/my-project/src/lib/file.ts', content: '...'},
|
|
25
|
+
* program,
|
|
26
|
+
* options,
|
|
27
|
+
* ctx,
|
|
28
|
+
* );
|
|
29
|
+
*
|
|
30
|
+
* if (result) {
|
|
31
|
+
* // Filter out @nodocs declarations
|
|
32
|
+
* const declarations = result.declarations
|
|
33
|
+
* .filter(d => !d.nodocs)
|
|
34
|
+
* .map(d => d.declaration);
|
|
35
|
+
* console.log('Declarations:', declarations);
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @see ts_helpers.ts for TypeScript-specific analysis
|
|
40
|
+
* @see svelte_helpers.ts for Svelte component analysis
|
|
41
|
+
* @see module_helpers.ts for path utilities and SourceFileInfo
|
|
42
|
+
*
|
|
43
|
+
* @module
|
|
44
|
+
*/
|
|
45
|
+
import ts from 'typescript';
|
|
46
|
+
import type { Logger } from '@fuzdev/fuz_util/log.js';
|
|
47
|
+
import type { DeclarationJson } from '@fuzdev/fuz_util/source_json.js';
|
|
48
|
+
import { type SourceFileInfo, type ModuleSourceOptions } from './module_helpers.js';
|
|
49
|
+
import type { AnalysisContext } from './analysis_context.js';
|
|
50
|
+
/**
|
|
51
|
+
* Result of analyzing a single declaration.
|
|
52
|
+
* Used by both TypeScript and Svelte analyzers for uniform handling.
|
|
53
|
+
*/
|
|
54
|
+
export interface DeclarationAnalysis {
|
|
55
|
+
/** The analyzed declaration metadata. */
|
|
56
|
+
declaration: DeclarationJson;
|
|
57
|
+
/** Whether the declaration is marked @nodocs (should be excluded from documentation). */
|
|
58
|
+
nodocs: boolean;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Information about a same-name re-export.
|
|
62
|
+
* Used for post-processing to build `also_exported_from` arrays.
|
|
63
|
+
*/
|
|
64
|
+
export interface ReExportInfo {
|
|
65
|
+
/** Name of the re-exported declaration. */
|
|
66
|
+
name: string;
|
|
67
|
+
/** Module path (relative to src/lib) where the declaration is originally declared. */
|
|
68
|
+
original_module: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Result of analyzing a module (TypeScript or Svelte).
|
|
72
|
+
* Both analyzers return this same structure for uniform handling.
|
|
73
|
+
*/
|
|
74
|
+
export interface ModuleAnalysis {
|
|
75
|
+
/** Module path relative to source root. */
|
|
76
|
+
path: string;
|
|
77
|
+
/** Module-level documentation comment. */
|
|
78
|
+
module_comment?: string;
|
|
79
|
+
/** All declarations with nodocs flags - consumer filters based on policy. */
|
|
80
|
+
declarations: Array<DeclarationAnalysis>;
|
|
81
|
+
/** Dependencies (other source modules this module imports). Empty if none. */
|
|
82
|
+
dependencies: Array<string>;
|
|
83
|
+
/** Dependents (other source modules that import this module). Empty if none. */
|
|
84
|
+
dependents: Array<string>;
|
|
85
|
+
/** Star exports (`export * from './module'`). Empty for Svelte components. */
|
|
86
|
+
star_exports: Array<string>;
|
|
87
|
+
/** Re-exports discovered during analysis. Empty for Svelte components. */
|
|
88
|
+
re_exports: Array<ReExportInfo>;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Analyze a source file and extract module metadata.
|
|
92
|
+
*
|
|
93
|
+
* Unified entry point that dispatches to the appropriate analyzer based on file type:
|
|
94
|
+
* - TypeScript/JavaScript files โ `ts_analyze_module`
|
|
95
|
+
* - Svelte components โ `svelte_analyze_module`
|
|
96
|
+
*
|
|
97
|
+
* Returns raw analysis data including `nodocs` flags on declarations.
|
|
98
|
+
* Consumer is responsible for filtering based on their policy.
|
|
99
|
+
*
|
|
100
|
+
* This function can be called incrementally - consumers may cache results and
|
|
101
|
+
* only re-analyze changed files. The TypeScript program should include all files
|
|
102
|
+
* for accurate type resolution, but only changed files need re-analysis.
|
|
103
|
+
*
|
|
104
|
+
* @param source_file The source file info with content and optional dependency data
|
|
105
|
+
* @param program TypeScript program (used for type checking and source file lookup)
|
|
106
|
+
* @param options Module source options for path extraction
|
|
107
|
+
* @param ctx Analysis context for collecting diagnostics
|
|
108
|
+
* @param log Optional logger for warnings
|
|
109
|
+
* @returns Module metadata and re-exports, or undefined if source file not found in program
|
|
110
|
+
*/
|
|
111
|
+
export declare const library_analyze_module: (source_file: SourceFileInfo, program: ts.Program, options: ModuleSourceOptions, ctx: AnalysisContext, log?: Logger) => ModuleAnalysis | undefined;
|
|
112
|
+
//# sourceMappingURL=library_analysis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"library_analysis.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/library_analysis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAC;AAC5B,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAIrE,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,mBAAmB,EAExB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,uBAAuB,CAAC;AAE3D;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC,yCAAyC;IACzC,WAAW,EAAE,eAAe,CAAC;IAC7B,yFAAyF;IACzF,MAAM,EAAE,OAAO,CAAC;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC5B,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,sFAAsF;IACtF,eAAe,EAAE,MAAM,CAAC;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,2CAA2C;IAC3C,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,6EAA6E;IAC7E,YAAY,EAAE,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACzC,8EAA8E;IAC9E,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,gFAAgF;IAChF,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC1B,8EAA8E;IAC9E,YAAY,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC5B,0EAA0E;IAC1E,UAAU,EAAE,KAAK,CAAC,YAAY,CAAC,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,sBAAsB,GAClC,aAAa,cAAc,EAC3B,SAAS,EAAE,CAAC,OAAO,EACnB,SAAS,mBAAmB,EAC5B,KAAK,eAAe,EACpB,MAAM,MAAM,KACV,cAAc,GAAG,SAuCnB,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library source analysis - unified entry point and shared types.
|
|
3
|
+
*
|
|
4
|
+
* Provides a single function for analyzing TypeScript and Svelte source files,
|
|
5
|
+
* dispatching to the appropriate domain-specific analyzer.
|
|
6
|
+
*
|
|
7
|
+
* This module also exports shared types used by both analyzers:
|
|
8
|
+
* - `DeclarationAnalysis` - A declaration with its nodocs flag
|
|
9
|
+
* - `ReExportInfo` - Information about a same-name re-export
|
|
10
|
+
* - `ModuleAnalysis` - Result of analyzing a module (unified structure)
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* import {library_analyze_module} from './library_analysis.js';
|
|
15
|
+
* import {ts_create_program} from './ts_helpers.js';
|
|
16
|
+
* import {module_create_source_options} from './module_helpers.js';
|
|
17
|
+
* import {AnalysisContext} from './analysis_context.js';
|
|
18
|
+
*
|
|
19
|
+
* const {program} = ts_create_program({root: './my-project'});
|
|
20
|
+
* const ctx = new AnalysisContext();
|
|
21
|
+
* const options = module_create_source_options('/my-project');
|
|
22
|
+
*
|
|
23
|
+
* const result = library_analyze_module(
|
|
24
|
+
* {id: '/my-project/src/lib/file.ts', content: '...'},
|
|
25
|
+
* program,
|
|
26
|
+
* options,
|
|
27
|
+
* ctx,
|
|
28
|
+
* );
|
|
29
|
+
*
|
|
30
|
+
* if (result) {
|
|
31
|
+
* // Filter out @nodocs declarations
|
|
32
|
+
* const declarations = result.declarations
|
|
33
|
+
* .filter(d => !d.nodocs)
|
|
34
|
+
* .map(d => d.declaration);
|
|
35
|
+
* console.log('Declarations:', declarations);
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*
|
|
39
|
+
* @see ts_helpers.ts for TypeScript-specific analysis
|
|
40
|
+
* @see svelte_helpers.ts for Svelte component analysis
|
|
41
|
+
* @see module_helpers.ts for path utilities and SourceFileInfo
|
|
42
|
+
*
|
|
43
|
+
* @module
|
|
44
|
+
*/
|
|
45
|
+
import ts from 'typescript';
|
|
46
|
+
import { ts_analyze_module } from './ts_helpers.js';
|
|
47
|
+
import { svelte_analyze_module } from './svelte_helpers.js';
|
|
48
|
+
import { module_extract_path, } from './module_helpers.js';
|
|
49
|
+
/**
|
|
50
|
+
* Analyze a source file and extract module metadata.
|
|
51
|
+
*
|
|
52
|
+
* Unified entry point that dispatches to the appropriate analyzer based on file type:
|
|
53
|
+
* - TypeScript/JavaScript files โ `ts_analyze_module`
|
|
54
|
+
* - Svelte components โ `svelte_analyze_module`
|
|
55
|
+
*
|
|
56
|
+
* Returns raw analysis data including `nodocs` flags on declarations.
|
|
57
|
+
* Consumer is responsible for filtering based on their policy.
|
|
58
|
+
*
|
|
59
|
+
* This function can be called incrementally - consumers may cache results and
|
|
60
|
+
* only re-analyze changed files. The TypeScript program should include all files
|
|
61
|
+
* for accurate type resolution, but only changed files need re-analysis.
|
|
62
|
+
*
|
|
63
|
+
* @param source_file The source file info with content and optional dependency data
|
|
64
|
+
* @param program TypeScript program (used for type checking and source file lookup)
|
|
65
|
+
* @param options Module source options for path extraction
|
|
66
|
+
* @param ctx Analysis context for collecting diagnostics
|
|
67
|
+
* @param log Optional logger for warnings
|
|
68
|
+
* @returns Module metadata and re-exports, or undefined if source file not found in program
|
|
69
|
+
*/
|
|
70
|
+
export const library_analyze_module = (source_file, program, options, ctx, log) => {
|
|
71
|
+
const checker = program.getTypeChecker();
|
|
72
|
+
const module_path = module_extract_path(source_file.id, options);
|
|
73
|
+
const analyzer_type = options.get_analyzer(source_file.id);
|
|
74
|
+
if (analyzer_type === 'svelte') {
|
|
75
|
+
return svelte_analyze_module(source_file, module_path, checker, options, ctx);
|
|
76
|
+
}
|
|
77
|
+
if (analyzer_type === 'typescript') {
|
|
78
|
+
const ts_source_file = program.getSourceFile(source_file.id);
|
|
79
|
+
if (!ts_source_file) {
|
|
80
|
+
ctx.add({
|
|
81
|
+
kind: 'module_skipped',
|
|
82
|
+
file: module_path,
|
|
83
|
+
line: null,
|
|
84
|
+
column: null,
|
|
85
|
+
message: `Could not get source file from program: ${source_file.id}`,
|
|
86
|
+
severity: 'warning',
|
|
87
|
+
reason: 'not_in_program',
|
|
88
|
+
});
|
|
89
|
+
log?.warn(`Could not get source file from program: ${source_file.id}`);
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
return ts_analyze_module(source_file, ts_source_file, module_path, checker, options, ctx);
|
|
93
|
+
}
|
|
94
|
+
// analyzer_type is null - skip this file
|
|
95
|
+
ctx.add({
|
|
96
|
+
kind: 'module_skipped',
|
|
97
|
+
file: module_path,
|
|
98
|
+
line: null,
|
|
99
|
+
column: null,
|
|
100
|
+
message: `No analyzer for file type: ${source_file.id}`,
|
|
101
|
+
severity: 'warning',
|
|
102
|
+
reason: 'no_analyzer',
|
|
103
|
+
});
|
|
104
|
+
log?.warn(`No analyzer for file: ${source_file.id}`);
|
|
105
|
+
return undefined;
|
|
106
|
+
};
|