@fuzdev/fuz_ui 0.193.1 → 0.195.0
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/dist/DeclarationDetail.svelte +139 -64
- package/dist/DeclarationDetail.svelte.d.ts +9 -0
- package/dist/DeclarationDetail.svelte.d.ts.map +1 -1
- package/dist/LibraryDetail.svelte +14 -10
- package/dist/LibraryDetail.svelte.d.ts +7 -0
- package/dist/LibraryDetail.svelte.d.ts.map +1 -1
- package/dist/Spiders.svelte +4 -2
- package/dist/Spiders.svelte.d.ts +2 -1
- package/dist/Spiders.svelte.d.ts.map +1 -1
- package/dist/StyleVariableButton.svelte +1 -1
- package/dist/contextmenu_state.svelte.d.ts +14 -14
- package/dist/contextmenu_state.svelte.d.ts.map +1 -1
- package/dist/contextmenu_state.svelte.js +3 -3
- package/dist/declaration.svelte.d.ts +233 -25
- package/dist/declaration.svelte.d.ts.map +1 -1
- package/dist/declaration.svelte.js +71 -23
- package/dist/docs_helpers.svelte.d.ts +5 -5
- package/dist/docs_helpers.svelte.d.ts.map +1 -1
- package/dist/docs_helpers.svelte.js +1 -1
- package/dist/library.svelte.d.ts +5 -5
- package/dist/library.svelte.d.ts.map +1 -1
- package/dist/library.svelte.js +2 -2
- package/dist/library_gen.d.ts +24 -17
- package/dist/library_gen.d.ts.map +1 -1
- package/dist/library_gen.js +52 -32
- package/dist/library_output.d.ts +5 -4
- package/dist/library_output.d.ts.map +1 -1
- package/dist/library_output.js +11 -8
- package/dist/mdz_components.d.ts +16 -16
- package/dist/mdz_components.d.ts.map +1 -1
- package/dist/module.svelte.d.ts +21 -7
- package/dist/module.svelte.d.ts.map +1 -1
- package/dist/module.svelte.js +26 -11
- package/dist/style_variable_helpers.svelte.d.ts +4 -4
- package/dist/style_variable_helpers.svelte.d.ts.map +1 -1
- package/dist/style_variable_helpers.svelte.js +1 -1
- package/dist/tome.d.ts +10 -10
- package/dist/tome.d.ts.map +1 -1
- package/dist/tome.js +2 -2
- package/dist/tsdoc_mdz.d.ts +6 -1
- package/dist/tsdoc_mdz.d.ts.map +1 -1
- package/dist/tsdoc_mdz.js +23 -2
- package/package.json +11 -9
- package/src/lib/contextmenu_state.svelte.ts +6 -6
- package/src/lib/declaration.svelte.ts +90 -35
- package/src/lib/docs_helpers.svelte.ts +2 -2
- package/src/lib/library.svelte.ts +3 -3
- package/src/lib/library_gen.ts +65 -42
- package/src/lib/library_output.ts +11 -8
- package/src/lib/mdz_components.ts +18 -18
- package/src/lib/module.svelte.ts +29 -16
- package/src/lib/style_variable_helpers.svelte.ts +2 -2
- package/src/lib/tome.ts +4 -4
- package/src/lib/tsdoc_mdz.ts +25 -2
- package/dist/analysis_context.d.ts +0 -199
- package/dist/analysis_context.d.ts.map +0 -1
- package/dist/analysis_context.js +0 -138
- package/dist/library_analysis.d.ts +0 -112
- package/dist/library_analysis.d.ts.map +0 -1
- package/dist/library_analysis.js +0 -106
- package/dist/library_generate.d.ts +0 -94
- package/dist/library_generate.d.ts.map +0 -1
- package/dist/library_generate.js +0 -147
- package/dist/library_pipeline.d.ts +0 -113
- package/dist/library_pipeline.d.ts.map +0 -1
- package/dist/library_pipeline.js +0 -160
- package/dist/module_helpers.d.ts +0 -334
- package/dist/module_helpers.d.ts.map +0 -1
- package/dist/module_helpers.js +0 -317
- package/dist/svelte_helpers.d.ts +0 -92
- package/dist/svelte_helpers.d.ts.map +0 -1
- package/dist/svelte_helpers.js +0 -367
- package/dist/ts_helpers.d.ts +0 -181
- package/dist/ts_helpers.d.ts.map +0 -1
- package/dist/ts_helpers.js +0 -674
- package/dist/tsdoc_helpers.d.ts +0 -119
- package/dist/tsdoc_helpers.d.ts.map +0 -1
- package/dist/tsdoc_helpers.js +0 -207
- package/src/lib/analysis_context.ts +0 -254
- package/src/lib/library_analysis.ts +0 -168
- package/src/lib/library_generate.ts +0 -215
- package/src/lib/library_pipeline.ts +0 -221
- package/src/lib/module_helpers.ts +0 -501
- package/src/lib/svelte_helpers.ts +0 -539
- package/src/lib/ts_helpers.ts +0 -862
- package/src/lib/tsdoc_helpers.ts +0 -246
package/src/lib/module.svelte.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {ModuleJsonInput} from 'svelte-docinfo/types.js';
|
|
2
2
|
|
|
3
3
|
import {Declaration} from './declaration.svelte.js';
|
|
4
4
|
import type {Library} from './library.svelte.js';
|
|
@@ -6,13 +6,30 @@ import {url_github_file} from './package_helpers.js';
|
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Rich runtime representation of a module with computed properties.
|
|
9
|
+
*
|
|
10
|
+
* Wraps svelte-docinfo's `ModuleJson` with reactive derivations,
|
|
11
|
+
* URL generation, and `Declaration` instances.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://github.com/ryanatkn/svelte-docinfo svelte-docinfo} for the analysis library
|
|
14
|
+
* @see `declaration.svelte.ts` for the `Declaration` wrapper class
|
|
9
15
|
*/
|
|
10
16
|
export class Module {
|
|
11
17
|
readonly library: Library = $state.raw()!;
|
|
12
|
-
|
|
18
|
+
// `library.json` is compacted (svelte-docinfo's `compactReplacer` strips empty
|
|
19
|
+
// default arrays), so the on-disk data is the `*Input` shape. Typing it as
|
|
20
|
+
// input makes TypeScript force guards on defaulted-array reads.
|
|
21
|
+
readonly module_json: ModuleJsonInput = $state.raw()!;
|
|
13
22
|
|
|
14
23
|
/**
|
|
15
|
-
* Canonical module path
|
|
24
|
+
* Canonical module path — `src/lib/`-relative, with source extension
|
|
25
|
+
* (`.ts`, `.svelte`, etc.). Examples: `'Alert.ts'`, `'helpers/foo.ts'`,
|
|
26
|
+
* `'actions/composables.ts'`.
|
|
27
|
+
*
|
|
28
|
+
* This is the key `Library.module_by_path` indexes, so it's also the
|
|
29
|
+
* exact string TSDoc backtick references must use to auto-link to a
|
|
30
|
+
* module via `DocsLink.svelte` (e.g., `` `actions/composables.ts` ``).
|
|
31
|
+
* A leading `./` or a `.js` runtime extension will not match. Top-level
|
|
32
|
+
* files match by bare filename; nested files require the full sub-path.
|
|
16
33
|
*/
|
|
17
34
|
path = $derived(this.module_json.path);
|
|
18
35
|
|
|
@@ -21,17 +38,15 @@ export class Module {
|
|
|
21
38
|
*/
|
|
22
39
|
path_import = $derived('./' + this.path);
|
|
23
40
|
|
|
24
|
-
module_comment = $derived(this.module_json.
|
|
41
|
+
module_comment = $derived(this.module_json.moduleComment);
|
|
25
42
|
|
|
26
43
|
/**
|
|
27
44
|
* Array of `Declaration` instances. Filters out default exports.
|
|
28
45
|
*/
|
|
29
46
|
declarations = $derived(
|
|
30
|
-
this.module_json.declarations
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
.map((declaration_json) => new Declaration(this, declaration_json))
|
|
34
|
-
: [],
|
|
47
|
+
(this.module_json.declarations ?? [])
|
|
48
|
+
.filter((declaration_json) => declaration_json.name !== 'default')
|
|
49
|
+
.map((declaration_json) => new Declaration(this, declaration_json)),
|
|
35
50
|
);
|
|
36
51
|
|
|
37
52
|
/**
|
|
@@ -48,23 +63,21 @@ export class Module {
|
|
|
48
63
|
: undefined,
|
|
49
64
|
);
|
|
50
65
|
|
|
51
|
-
has_declarations: boolean = $derived(
|
|
52
|
-
!!(this.module_json.declarations && this.module_json.declarations.length > 0),
|
|
53
|
-
);
|
|
66
|
+
has_declarations: boolean = $derived((this.module_json.declarations?.length ?? 0) > 0);
|
|
54
67
|
|
|
55
|
-
has_module_comment: boolean = $derived(!!this.
|
|
68
|
+
has_module_comment: boolean = $derived(!!this.module_comment);
|
|
56
69
|
|
|
57
70
|
/**
|
|
58
71
|
* Modules this imports (paths relative to src/lib).
|
|
59
72
|
*/
|
|
60
|
-
dependencies = $derived(this.module_json.dependencies);
|
|
73
|
+
dependencies = $derived(this.module_json.dependencies ?? []);
|
|
61
74
|
|
|
62
75
|
/**
|
|
63
76
|
* Modules that import this (paths relative to src/lib).
|
|
64
77
|
*/
|
|
65
|
-
dependents = $derived(this.module_json.dependents);
|
|
78
|
+
dependents = $derived(this.module_json.dependents ?? []);
|
|
66
79
|
|
|
67
|
-
constructor(library: Library, module_json:
|
|
80
|
+
constructor(library: Library, module_json: ModuleJsonInput) {
|
|
68
81
|
this.library = library;
|
|
69
82
|
this.module_json = module_json;
|
|
70
83
|
}
|
|
@@ -2,6 +2,8 @@ import type {StyleVariable} from '@fuzdev/fuz_css/variable.js';
|
|
|
2
2
|
|
|
3
3
|
import {create_context} from './context_helpers.js';
|
|
4
4
|
|
|
5
|
+
export const selected_variable_context = create_context(() => new SelectedStyleVariable(null));
|
|
6
|
+
|
|
5
7
|
// TODO maybe change this to a generic wrapper class for any value?
|
|
6
8
|
export class SelectedStyleVariable {
|
|
7
9
|
value: StyleVariable | null = $state.raw()!;
|
|
@@ -10,5 +12,3 @@ export class SelectedStyleVariable {
|
|
|
10
12
|
this.value = initial;
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
|
-
|
|
14
|
-
export const selected_variable_context = create_context(() => new SelectedStyleVariable(null));
|
package/src/lib/tome.ts
CHANGED
|
@@ -6,6 +6,10 @@ import {ensure_start} from '@fuzdev/fuz_util/string.js';
|
|
|
6
6
|
import {create_context} from './context_helpers.js';
|
|
7
7
|
import {DOCS_PATH_DEFAULT} from './docs_helpers.svelte.js';
|
|
8
8
|
|
|
9
|
+
export const tomes_context = create_context<() => Map<string, Tome>>();
|
|
10
|
+
|
|
11
|
+
export const tome_context = create_context<() => Tome>();
|
|
12
|
+
|
|
9
13
|
export const Tome = z.object({
|
|
10
14
|
/**
|
|
11
15
|
* Stable identifier and URL path segment — must be a URL-safe slug
|
|
@@ -47,13 +51,9 @@ export const tome_to_pathname = (
|
|
|
47
51
|
*/
|
|
48
52
|
export const tome_to_title = (tome: Tome): string => tome.title ?? tome.slug;
|
|
49
53
|
|
|
50
|
-
export const tomes_context = create_context<() => Map<string, Tome>>();
|
|
51
|
-
|
|
52
54
|
export const tome_get_by_slug = (slug: string): Tome => {
|
|
53
55
|
const get_tomes = tomes_context.get();
|
|
54
56
|
const tome = get_tomes().get(slug);
|
|
55
57
|
if (!tome) throw Error(`unable to find tome "${slug}"`);
|
|
56
58
|
return tome;
|
|
57
59
|
};
|
|
58
|
-
|
|
59
|
-
export const tome_context = create_context<() => Tome>();
|
package/src/lib/tsdoc_mdz.ts
CHANGED
|
@@ -17,10 +17,12 @@ const format_reference = (ref: string): string => (mdz_is_url(ref) ? ref : `\`${
|
|
|
17
17
|
* Convert raw TSDoc `@see` content to mdz format for rendering.
|
|
18
18
|
*
|
|
19
19
|
* Handles TSDoc link syntax:
|
|
20
|
-
* - `{@link url|text}` → `[text](url)` (markdown link)
|
|
20
|
+
* - `{@link url|text}` → `[text](url)` (markdown link, TSDoc canonical form)
|
|
21
|
+
* - `{@link url text}` → `[text](url)` (TS-lenient space-separated form)
|
|
21
22
|
* - `{@link https://...}` → `https://...` (bare URL, auto-linked by mdz)
|
|
22
23
|
* - `{@link identifier}` → `` `identifier` `` (code formatting)
|
|
23
24
|
* - Bare URLs → returned as-is
|
|
25
|
+
* - Bare markdown links (`[text](url)` ...) → returned as-is
|
|
24
26
|
* - Bare identifiers → wrapped in backticks
|
|
25
27
|
* - `identifier description text` → `` `identifier` description text `` (first token is the reference)
|
|
26
28
|
*
|
|
@@ -38,6 +40,9 @@ const format_reference = (ref: string): string => (mdz_is_url(ref) ? ref : `\`${
|
|
|
38
40
|
* tsdoc_see_to_mdz('https://example.com')
|
|
39
41
|
* // → 'https://example.com'
|
|
40
42
|
*
|
|
43
|
+
* tsdoc_see_to_mdz('[svelte-docinfo](https://github.com/ryanatkn/svelte-docinfo) for the analysis library')
|
|
44
|
+
* // → '[svelte-docinfo](https://github.com/ryanatkn/svelte-docinfo) for the analysis library'
|
|
45
|
+
*
|
|
41
46
|
* tsdoc_see_to_mdz('library_gen.ts for Gro-specific integration')
|
|
42
47
|
* // → '`library_gen.ts` for Gro-specific integration'
|
|
43
48
|
* ```
|
|
@@ -51,7 +56,7 @@ export const tsdoc_see_to_mdz = (content: string): string => {
|
|
|
51
56
|
if (link_match) {
|
|
52
57
|
const inner = link_match[1]!.trim();
|
|
53
58
|
|
|
54
|
-
//
|
|
59
|
+
// Pipe separator takes precedence (TSDoc canonical form)
|
|
55
60
|
const pipe_index = inner.indexOf('|');
|
|
56
61
|
if (pipe_index !== -1) {
|
|
57
62
|
const reference = inner.slice(0, pipe_index).trim();
|
|
@@ -59,9 +64,27 @@ export const tsdoc_see_to_mdz = (content: string): string => {
|
|
|
59
64
|
return `[${display_text}](${reference})`;
|
|
60
65
|
}
|
|
61
66
|
|
|
67
|
+
// Space-separated form: TS accepts `{@link url text}` as equivalent to `{@link url|text}`.
|
|
68
|
+
// Only treat space as a separator when the first token looks like a link target (URL),
|
|
69
|
+
// so identifier-style references like `module.function` aren't split.
|
|
70
|
+
const space_index = inner.indexOf(' ');
|
|
71
|
+
if (space_index !== -1) {
|
|
72
|
+
const reference = inner.slice(0, space_index);
|
|
73
|
+
if (mdz_is_url(reference)) {
|
|
74
|
+
const display_text = inner.slice(space_index + 1).trim();
|
|
75
|
+
return `[${display_text}](${reference})`;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
62
79
|
return format_reference(inner);
|
|
63
80
|
}
|
|
64
81
|
|
|
82
|
+
// Pass through bare markdown links (`[text](url)` optionally followed by description)
|
|
83
|
+
// so authors can write `@see [text](url) for context` directly.
|
|
84
|
+
if (trimmed.charCodeAt(0) === 91 /* [ */ && /^\[[^\]]+\]\([^)\s]+\)/.test(trimmed)) {
|
|
85
|
+
return trimmed;
|
|
86
|
+
}
|
|
87
|
+
|
|
65
88
|
// Split at first whitespace: first token is the reference, rest is description
|
|
66
89
|
const space_index = trimmed.indexOf(' ');
|
|
67
90
|
if (space_index === -1) {
|
|
@@ -1,199 +0,0 @@
|
|
|
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
|
-
* ```ts
|
|
48
|
-
* const ctx = new AnalysisContext();
|
|
49
|
-
* // ... analysis functions add diagnostics via ctx.add(...)
|
|
50
|
-
* if (ctx.has_errors()) {
|
|
51
|
-
* for (const err of ctx.errors()) {
|
|
52
|
-
* console.error(`${err.file}:${err.line}: ${err.message}`);
|
|
53
|
-
* }
|
|
54
|
-
* }
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* @module
|
|
58
|
-
*/
|
|
59
|
-
/**
|
|
60
|
-
* Diagnostic severity levels.
|
|
61
|
-
*
|
|
62
|
-
* - `error`: Analysis failed, declaration may be incomplete or missing data
|
|
63
|
-
* - `warning`: Partial success, something seems off but analysis continued
|
|
64
|
-
*/
|
|
65
|
-
export type DiagnosticSeverity = 'error' | 'warning';
|
|
66
|
-
/**
|
|
67
|
-
* Discriminant for diagnostic types.
|
|
68
|
-
*/
|
|
69
|
-
export type DiagnosticKind = 'type_extraction_failed' | 'signature_analysis_failed' | 'class_member_failed' | 'svelte_prop_failed' | 'module_skipped';
|
|
70
|
-
/**
|
|
71
|
-
* Base diagnostic fields shared by all diagnostic types.
|
|
72
|
-
*/
|
|
73
|
-
export interface BaseDiagnostic {
|
|
74
|
-
kind: DiagnosticKind;
|
|
75
|
-
/** File path relative to project root (display with './' prefix). */
|
|
76
|
-
file: string;
|
|
77
|
-
/** Line number (1-based), or null if location unavailable. */
|
|
78
|
-
line: number | null;
|
|
79
|
-
/** Column number (1-based), or null if location unavailable. */
|
|
80
|
-
column: number | null;
|
|
81
|
-
/** Human-readable description of the issue. */
|
|
82
|
-
message: string;
|
|
83
|
-
severity: DiagnosticSeverity;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Type extraction failed (e.g., complex or recursive types).
|
|
87
|
-
*/
|
|
88
|
-
export interface TypeExtractionDiagnostic extends BaseDiagnostic {
|
|
89
|
-
kind: 'type_extraction_failed';
|
|
90
|
-
/** Name of the symbol whose type couldn't be extracted. */
|
|
91
|
-
symbol_name: string;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Function/method signature analysis failed.
|
|
95
|
-
*/
|
|
96
|
-
export interface SignatureAnalysisDiagnostic extends BaseDiagnostic {
|
|
97
|
-
kind: 'signature_analysis_failed';
|
|
98
|
-
/** Name of the function or method. */
|
|
99
|
-
function_name: string;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Class member analysis failed.
|
|
103
|
-
*/
|
|
104
|
-
export interface ClassMemberDiagnostic extends BaseDiagnostic {
|
|
105
|
-
kind: 'class_member_failed';
|
|
106
|
-
/** Name of the class. */
|
|
107
|
-
class_name: string;
|
|
108
|
-
/** Name of the member that failed. */
|
|
109
|
-
member_name: string;
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Svelte prop type resolution failed.
|
|
113
|
-
*/
|
|
114
|
-
export interface SveltePropDiagnostic extends BaseDiagnostic {
|
|
115
|
-
kind: 'svelte_prop_failed';
|
|
116
|
-
/** Name of the component. */
|
|
117
|
-
component_name: string;
|
|
118
|
-
/** Name of the prop. */
|
|
119
|
-
prop_name: string;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Module was skipped during analysis.
|
|
123
|
-
* Could be due to missing source file in program or no analyzer available.
|
|
124
|
-
*/
|
|
125
|
-
export interface ModuleSkippedDiagnostic extends BaseDiagnostic {
|
|
126
|
-
kind: 'module_skipped';
|
|
127
|
-
/** Reason the module was skipped. */
|
|
128
|
-
reason: 'not_in_program' | 'no_analyzer';
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Union of all diagnostic types.
|
|
132
|
-
*/
|
|
133
|
-
export type Diagnostic = TypeExtractionDiagnostic | SignatureAnalysisDiagnostic | ClassMemberDiagnostic | SveltePropDiagnostic | ModuleSkippedDiagnostic;
|
|
134
|
-
/**
|
|
135
|
-
* Context for collecting diagnostics during source analysis.
|
|
136
|
-
*
|
|
137
|
-
* Thread an instance through analysis functions to collect errors and warnings
|
|
138
|
-
* without halting analysis. After analysis completes, check `has_errors()` and
|
|
139
|
-
* report collected diagnostics.
|
|
140
|
-
*
|
|
141
|
-
* @example
|
|
142
|
-
* ```ts
|
|
143
|
-
* const ctx = new AnalysisContext();
|
|
144
|
-
* ts_analyze_module_exports(source_file, checker, options, ctx);
|
|
145
|
-
* if (ctx.has_errors()) {
|
|
146
|
-
* console.error('Analysis completed with errors:');
|
|
147
|
-
* for (const d of ctx.errors()) {
|
|
148
|
-
* console.error(format_diagnostic(d));
|
|
149
|
-
* }
|
|
150
|
-
* }
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
export declare class AnalysisContext {
|
|
154
|
-
readonly diagnostics: Array<Diagnostic>;
|
|
155
|
-
/**
|
|
156
|
-
* Add a `Diagnostic` to the collection.
|
|
157
|
-
*/
|
|
158
|
-
add(diagnostic: Diagnostic): void;
|
|
159
|
-
/**
|
|
160
|
-
* Check if any errors were collected.
|
|
161
|
-
*/
|
|
162
|
-
has_errors(): boolean;
|
|
163
|
-
/**
|
|
164
|
-
* Check if any warnings were collected.
|
|
165
|
-
*/
|
|
166
|
-
has_warnings(): boolean;
|
|
167
|
-
/**
|
|
168
|
-
* Get all error diagnostics.
|
|
169
|
-
*/
|
|
170
|
-
errors(): Array<Diagnostic>;
|
|
171
|
-
/**
|
|
172
|
-
* Get all warning diagnostics.
|
|
173
|
-
*/
|
|
174
|
-
warnings(): Array<Diagnostic>;
|
|
175
|
-
/**
|
|
176
|
-
* Get diagnostics of a specific `DiagnosticKind`.
|
|
177
|
-
*/
|
|
178
|
-
by_kind<K extends DiagnosticKind>(kind: K): Array<Extract<Diagnostic, {
|
|
179
|
-
kind: K;
|
|
180
|
-
}>>;
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Options for formatting diagnostics.
|
|
184
|
-
*/
|
|
185
|
-
export interface FormatDiagnosticOptions {
|
|
186
|
-
/** Prefix for file path (default: './'). */
|
|
187
|
-
prefix?: string;
|
|
188
|
-
/** Base path to strip from absolute file paths (e.g., process.cwd()). */
|
|
189
|
-
strip_base?: string;
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Format a diagnostic for display.
|
|
193
|
-
*
|
|
194
|
-
* @param diagnostic - the diagnostic to format
|
|
195
|
-
* @param options - formatting options
|
|
196
|
-
* @returns formatted string like './file.ts:10:5: error: message'
|
|
197
|
-
*/
|
|
198
|
-
export declare const format_diagnostic: (diagnostic: Diagnostic, options?: FormatDiagnosticOptions) => string;
|
|
199
|
-
//# sourceMappingURL=analysis_context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analysis_context.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/analysis_context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;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;;;;;;;;;;;;;;;;;;GAkBG;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"}
|
package/dist/analysis_context.js
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
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
|
-
* ```ts
|
|
48
|
-
* const ctx = new AnalysisContext();
|
|
49
|
-
* // ... analysis functions add diagnostics via ctx.add(...)
|
|
50
|
-
* if (ctx.has_errors()) {
|
|
51
|
-
* for (const err of ctx.errors()) {
|
|
52
|
-
* console.error(`${err.file}:${err.line}: ${err.message}`);
|
|
53
|
-
* }
|
|
54
|
-
* }
|
|
55
|
-
* ```
|
|
56
|
-
*
|
|
57
|
-
* @module
|
|
58
|
-
*/
|
|
59
|
-
/**
|
|
60
|
-
* Context for collecting diagnostics during source analysis.
|
|
61
|
-
*
|
|
62
|
-
* Thread an instance through analysis functions to collect errors and warnings
|
|
63
|
-
* without halting analysis. After analysis completes, check `has_errors()` and
|
|
64
|
-
* report collected diagnostics.
|
|
65
|
-
*
|
|
66
|
-
* @example
|
|
67
|
-
* ```ts
|
|
68
|
-
* const ctx = new AnalysisContext();
|
|
69
|
-
* ts_analyze_module_exports(source_file, checker, options, ctx);
|
|
70
|
-
* if (ctx.has_errors()) {
|
|
71
|
-
* console.error('Analysis completed with errors:');
|
|
72
|
-
* for (const d of ctx.errors()) {
|
|
73
|
-
* console.error(format_diagnostic(d));
|
|
74
|
-
* }
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
export class AnalysisContext {
|
|
79
|
-
diagnostics = [];
|
|
80
|
-
/**
|
|
81
|
-
* Add a `Diagnostic` to the collection.
|
|
82
|
-
*/
|
|
83
|
-
add(diagnostic) {
|
|
84
|
-
this.diagnostics.push(diagnostic);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Check if any errors were collected.
|
|
88
|
-
*/
|
|
89
|
-
has_errors() {
|
|
90
|
-
return this.diagnostics.some((d) => d.severity === 'error');
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Check if any warnings were collected.
|
|
94
|
-
*/
|
|
95
|
-
has_warnings() {
|
|
96
|
-
return this.diagnostics.some((d) => d.severity === 'warning');
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Get all error diagnostics.
|
|
100
|
-
*/
|
|
101
|
-
errors() {
|
|
102
|
-
return this.diagnostics.filter((d) => d.severity === 'error');
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Get all warning diagnostics.
|
|
106
|
-
*/
|
|
107
|
-
warnings() {
|
|
108
|
-
return this.diagnostics.filter((d) => d.severity === 'warning');
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Get diagnostics of a specific `DiagnosticKind`.
|
|
112
|
-
*/
|
|
113
|
-
by_kind(kind) {
|
|
114
|
-
return this.diagnostics.filter((d) => d.kind === kind);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Format a diagnostic for display.
|
|
119
|
-
*
|
|
120
|
-
* @param diagnostic - the diagnostic to format
|
|
121
|
-
* @param options - formatting options
|
|
122
|
-
* @returns formatted string like './file.ts:10:5: error: message'
|
|
123
|
-
*/
|
|
124
|
-
export const format_diagnostic = (diagnostic, options) => {
|
|
125
|
-
const prefix = options?.prefix ?? './';
|
|
126
|
-
const strip_base = options?.strip_base;
|
|
127
|
-
let file = diagnostic.file;
|
|
128
|
-
if (strip_base && file.startsWith(strip_base)) {
|
|
129
|
-
file = file.slice(strip_base.length);
|
|
130
|
-
// Remove leading slash if present
|
|
131
|
-
if (file.startsWith('/'))
|
|
132
|
-
file = file.slice(1);
|
|
133
|
-
}
|
|
134
|
-
const { line, column, severity, message } = diagnostic;
|
|
135
|
-
const location = line !== null ? (column !== null ? `${line}:${column}` : `${line}`) : '';
|
|
136
|
-
const file_part = location ? `${prefix}${file}:${location}` : `${prefix}${file}`;
|
|
137
|
-
return `${file_part}: ${severity}: ${message}`;
|
|
138
|
-
};
|
|
@@ -1,112 +0,0 @@
|
|
|
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/JS 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
|
|
@@ -1 +0,0 @@
|
|
|
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,2FAA2F;IAC3F,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"}
|