@fuzdev/fuz_ui 0.194.0 → 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/declaration.svelte.d.ts +233 -25
- package/dist/declaration.svelte.d.ts.map +1 -1
- package/dist/declaration.svelte.js +71 -23
- package/dist/library.svelte.js +1 -1
- 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/module.svelte.d.ts +21 -7
- package/dist/module.svelte.d.ts.map +1 -1
- package/dist/module.svelte.js +26 -11
- 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 +10 -8
- package/src/lib/declaration.svelte.ts +90 -35
- package/src/lib/library.svelte.ts +1 -1
- package/src/lib/library_gen.ts +65 -42
- package/src/lib/library_output.ts +11 -8
- package/src/lib/module.svelte.ts +29 -16
- 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/tsdoc_helpers.ts
DELETED
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TSDoc/JSDoc parsing helpers using the TypeScript Compiler API.
|
|
3
|
-
*
|
|
4
|
-
* Provides `tsdoc_parse()` for extracting JSDoc/TSDoc from TypeScript nodes.
|
|
5
|
-
* Primarily designed for build-time code generation but can be used at runtime.
|
|
6
|
-
*
|
|
7
|
-
* ## Design
|
|
8
|
-
*
|
|
9
|
-
* Pure extraction approach: extracts documentation as-is with minimal transformation,
|
|
10
|
-
* preserving source intent. Works around TypeScript Compiler API quirks where needed.
|
|
11
|
-
*
|
|
12
|
-
* Supports both regular TypeScript and Svelte components (via svelte2tsx output).
|
|
13
|
-
*
|
|
14
|
-
* ## Tag support
|
|
15
|
-
*
|
|
16
|
-
* Supports a subset of standard TSDoc tags:
|
|
17
|
-
* `@param`, `@returns`, `@throws`, `@example`, `@deprecated`, `@see`, `@since`, `@nodocs`.
|
|
18
|
-
*
|
|
19
|
-
* The `@nodocs` tag excludes exports from documentation and flat namespace validation.
|
|
20
|
-
* The declaration is still exported and usable, just not documented.
|
|
21
|
-
*
|
|
22
|
-
* Also supports `@mutates` (non-standard) for documenting mutations to parameters or external state.
|
|
23
|
-
* Use format: `@mutates paramName - description of mutation`.
|
|
24
|
-
*
|
|
25
|
-
* Only `@returns` is supported (not `@return`).
|
|
26
|
-
*
|
|
27
|
-
* The `@see` tag supports multiple formats: plain URLs (`https://...`), `{@link}` syntax, and module names.
|
|
28
|
-
* Relative/absolute path support in `@see` is TBD.
|
|
29
|
-
*
|
|
30
|
-
* ## Behavioral notes
|
|
31
|
-
*
|
|
32
|
-
* Due to TS Compiler API limitations:
|
|
33
|
-
* - `@param` and `@mutates` descriptions have leading `- ` stripped for visual consistency
|
|
34
|
-
* (TSDoc spec uses `@param name - description` but the separator is aesthetic)
|
|
35
|
-
* - `@throws` tags have `{Type}` stripped by TS API; fallback regex extracts first word as error type
|
|
36
|
-
* - TS API strips URL protocols from `@see` tag text; we use `getText()` to preserve original format including `{@link}` syntax
|
|
37
|
-
*
|
|
38
|
-
* All functions are prefixed with `tsdoc_` for clarity.
|
|
39
|
-
*
|
|
40
|
-
* @module
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
import ts from 'typescript';
|
|
44
|
-
import type {DeclarationJson} from '@fuzdev/fuz_util/source_json.js';
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Parsed JSDoc/TSDoc comment with structured metadata.
|
|
48
|
-
*/
|
|
49
|
-
export interface TsdocParsedComment {
|
|
50
|
-
/** Comment text (excluding comment markers) */
|
|
51
|
-
text: string;
|
|
52
|
-
/** Parameter descriptions mapped by parameter name */
|
|
53
|
-
params: Map<string, string>;
|
|
54
|
-
/** Return value description from `@returns` */
|
|
55
|
-
returns?: string;
|
|
56
|
-
/** Thrown errors from `@throws` */
|
|
57
|
-
throws?: Array<{type?: string; description: string}>;
|
|
58
|
-
/** Code examples from `@example` */
|
|
59
|
-
examples?: Array<string>;
|
|
60
|
-
/** Deprecation message from `@deprecated` */
|
|
61
|
-
deprecated_message?: string;
|
|
62
|
-
/** Related references from `@see` */
|
|
63
|
-
see_also?: Array<string>;
|
|
64
|
-
/** Version information from `@since` */
|
|
65
|
-
since?: string;
|
|
66
|
-
/** Mutation documentation from `@mutates` (non-standard) */
|
|
67
|
-
mutates?: Array<string>;
|
|
68
|
-
/** Whether to exclude from documentation. From `@nodocs` tag. */
|
|
69
|
-
nodocs?: boolean;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Parse JSDoc comment from a TypeScript node.
|
|
74
|
-
*
|
|
75
|
-
* Extracts and parses all JSDoc tags including:
|
|
76
|
-
*
|
|
77
|
-
* - `@param` - parameter descriptions
|
|
78
|
-
* - `@returns` - return value description
|
|
79
|
-
* - `@throws` - error documentation
|
|
80
|
-
* - `@example` - code examples
|
|
81
|
-
* - `@deprecated` - deprecation warnings
|
|
82
|
-
* - `@see` - related references
|
|
83
|
-
* - `@since` - version information
|
|
84
|
-
* - `@mutates` - mutation documentation (non-standard)
|
|
85
|
-
*
|
|
86
|
-
* @param node - the TypeScript node to extract JSDoc from
|
|
87
|
-
* @param source_file - source file (used for extracting full ` @see` tag text)
|
|
88
|
-
*/
|
|
89
|
-
export const tsdoc_parse = (
|
|
90
|
-
node: ts.Node,
|
|
91
|
-
source_file: ts.SourceFile,
|
|
92
|
-
): TsdocParsedComment | undefined => {
|
|
93
|
-
const tsdoc_comments = ts.getJSDocCommentsAndTags(node);
|
|
94
|
-
if (tsdoc_comments.length === 0) return undefined;
|
|
95
|
-
|
|
96
|
-
let full_text = '';
|
|
97
|
-
const params: Map<string, string> = new Map();
|
|
98
|
-
let returns: string | undefined;
|
|
99
|
-
const throws: Array<{type?: string; description: string}> = [];
|
|
100
|
-
const examples: Array<string> = [];
|
|
101
|
-
let deprecated_message: string | undefined;
|
|
102
|
-
const see_also: Array<string> = [];
|
|
103
|
-
let since: string | undefined;
|
|
104
|
-
const mutates: Array<string> = [];
|
|
105
|
-
let nodocs = false;
|
|
106
|
-
|
|
107
|
-
// Extract main comment text
|
|
108
|
-
for (const comment of tsdoc_comments) {
|
|
109
|
-
if (ts.isJSDoc(comment) && comment.comment) {
|
|
110
|
-
full_text += tsdoc_comment_to_text(comment.comment, source_file) + '\n';
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Extract tags
|
|
115
|
-
const tags = ts.getJSDocTags(node);
|
|
116
|
-
for (const tag of tags) {
|
|
117
|
-
const tag_text = tag.comment ? tsdoc_comment_to_text(tag.comment, source_file) : undefined;
|
|
118
|
-
const tag_name = tag.tagName.text;
|
|
119
|
-
|
|
120
|
-
if (tag_name === 'param' && ts.isJSDocParameterTag(tag)) {
|
|
121
|
-
// Extract parameter name and description
|
|
122
|
-
const param_name = ts.isIdentifier(tag.name) ? tag.name.text : tag.name.getText();
|
|
123
|
-
if (param_name && tag_text) {
|
|
124
|
-
params.set(param_name, tag_text.trim().replace(/^-\s+/, ''));
|
|
125
|
-
}
|
|
126
|
-
} else if (tag_name === 'returns' && tag_text) {
|
|
127
|
-
returns = tag_text.trim();
|
|
128
|
-
} else if (tag_name === 'throws' && tag_text) {
|
|
129
|
-
// Try to extract error type and description
|
|
130
|
-
const match = /^\{?(\w+)\}?\s+(.+)/.exec(tag_text);
|
|
131
|
-
if (match) {
|
|
132
|
-
throws.push({type: match[1], description: match[2]!.trim()});
|
|
133
|
-
} else {
|
|
134
|
-
throws.push({description: tag_text.trim()});
|
|
135
|
-
}
|
|
136
|
-
} else if (tag_name === 'example' && tag_text) {
|
|
137
|
-
examples.push(tag_text.trim());
|
|
138
|
-
} else if (tag_name === 'deprecated' && tag_text) {
|
|
139
|
-
deprecated_message = tag_text.trim();
|
|
140
|
-
} else if (tag_name === 'see') {
|
|
141
|
-
// The TS API strips 'https' from URLs in @see tags, so get full text from source
|
|
142
|
-
const full_tag_text = tag.getText(source_file);
|
|
143
|
-
// Extract content after @see, handling JSDoc formatting artifacts
|
|
144
|
-
const see_content = full_tag_text
|
|
145
|
-
.replace(/^@see\s+/, '') // remove @see prefix
|
|
146
|
-
.replace(/\n\s*\*\s*/g, ' ') // remove JSDoc line continuations
|
|
147
|
-
.replace(/\s*\*\s*$/, '') // remove trailing asterisk artifacts
|
|
148
|
-
.trim();
|
|
149
|
-
|
|
150
|
-
if (see_content) {
|
|
151
|
-
see_also.push(see_content);
|
|
152
|
-
}
|
|
153
|
-
} else if (tag_name === 'since' && tag_text) {
|
|
154
|
-
since = tag_text.trim();
|
|
155
|
-
} else if (tag_name === 'mutates' && tag_text) {
|
|
156
|
-
mutates.push(tag_text.trim().replace(/^-\s+/, ''));
|
|
157
|
-
} else if (tag_name === 'nodocs') {
|
|
158
|
-
nodocs = true;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
full_text = full_text.trim();
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
text: full_text,
|
|
166
|
-
params,
|
|
167
|
-
returns,
|
|
168
|
-
...(throws.length && {throws}),
|
|
169
|
-
...(examples.length && {examples}),
|
|
170
|
-
deprecated_message,
|
|
171
|
-
...(see_also.length && {see_also}),
|
|
172
|
-
since,
|
|
173
|
-
...(mutates.length && {mutates}),
|
|
174
|
-
...(nodocs && {nodocs}),
|
|
175
|
-
};
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* Apply parsed TSDoc metadata to a declaration.
|
|
180
|
-
*
|
|
181
|
-
* Consolidates the common pattern of assigning TSDoc fields to declarations,
|
|
182
|
-
* with conditional assignment for array fields (only if non-empty).
|
|
183
|
-
*
|
|
184
|
-
* @param declaration - declaration object to update
|
|
185
|
-
* @param tsdoc - parsed TSDoc comment (if available)
|
|
186
|
-
* @mutates declaration - adds doc_comment, deprecated_message, examples, see_also, throws, since fields
|
|
187
|
-
*/
|
|
188
|
-
export const tsdoc_apply_to_declaration = (
|
|
189
|
-
declaration: DeclarationJson,
|
|
190
|
-
tsdoc: TsdocParsedComment | undefined,
|
|
191
|
-
): void => {
|
|
192
|
-
if (!tsdoc) return;
|
|
193
|
-
|
|
194
|
-
declaration.doc_comment = tsdoc.text;
|
|
195
|
-
declaration.deprecated_message = tsdoc.deprecated_message;
|
|
196
|
-
|
|
197
|
-
// Only assign arrays if they have content
|
|
198
|
-
if (tsdoc.examples?.length) {
|
|
199
|
-
declaration.examples = tsdoc.examples;
|
|
200
|
-
}
|
|
201
|
-
if (tsdoc.see_also?.length) {
|
|
202
|
-
declaration.see_also = tsdoc.see_also;
|
|
203
|
-
}
|
|
204
|
-
if (tsdoc.throws?.length) {
|
|
205
|
-
declaration.throws = tsdoc.throws;
|
|
206
|
-
}
|
|
207
|
-
if (tsdoc.since) {
|
|
208
|
-
declaration.since = tsdoc.since;
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Concatenates a JSDoc comment (string or node array) into plain text, preserving `{@link ...}`.
|
|
214
|
-
*
|
|
215
|
-
* `JSDocLink` / `JSDocLinkCode` / `JSDocLinkPlain` nodes have empty `.text` — the identifier
|
|
216
|
-
* lives on `.name`, not `.text`. Using `.text` alone silently drops link content; we fall back
|
|
217
|
-
* to the source-text representation for link nodes so `{@link Foo}` survives intact for downstream
|
|
218
|
-
* renderers (see `tsdoc_mdz.ts`).
|
|
219
|
-
*/
|
|
220
|
-
export const tsdoc_comment_to_text = (
|
|
221
|
-
comment: string | ts.NodeArray<ts.JSDocComment>,
|
|
222
|
-
source_file: ts.SourceFile,
|
|
223
|
-
): string => {
|
|
224
|
-
if (typeof comment === 'string') return comment;
|
|
225
|
-
return comment.map((c) => (ts.isJSDocLinkLike(c) ? c.getText(source_file) : c.text)).join('');
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Clean raw JSDoc comment text by removing comment markers and leading asterisks.
|
|
230
|
-
*
|
|
231
|
-
* Transforms `/** ... *\/` style comments into clean text.
|
|
232
|
-
*
|
|
233
|
-
* @param comment_text - the raw comment text including `/**` and `*\/` markers
|
|
234
|
-
* @returns cleaned comment text, or undefined if empty after cleaning
|
|
235
|
-
*/
|
|
236
|
-
export const tsdoc_clean_comment = (comment_text: string): string | undefined => {
|
|
237
|
-
const text = comment_text
|
|
238
|
-
.replace(/^\/\*\*/, '')
|
|
239
|
-
.replace(/\*\/$/, '')
|
|
240
|
-
.split('\n')
|
|
241
|
-
.map((line) => line.replace(/^\s*\*\s?/, ''))
|
|
242
|
-
.join('\n')
|
|
243
|
-
.trim();
|
|
244
|
-
|
|
245
|
-
return text || undefined;
|
|
246
|
-
};
|