svelte-docinfo 0.1.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.
Files changed (97) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +349 -0
  3. package/dist/analyze-core.d.ts +1386 -0
  4. package/dist/analyze-core.d.ts.map +1 -0
  5. package/dist/analyze-core.js +324 -0
  6. package/dist/analyze.d.ts +137 -0
  7. package/dist/analyze.d.ts.map +1 -0
  8. package/dist/analyze.js +148 -0
  9. package/dist/cli.d.ts +102 -0
  10. package/dist/cli.d.ts.map +1 -0
  11. package/dist/cli.js +206 -0
  12. package/dist/concurrency.d.ts +38 -0
  13. package/dist/concurrency.d.ts.map +1 -0
  14. package/dist/concurrency.js +57 -0
  15. package/dist/declaration-build.d.ts +164 -0
  16. package/dist/declaration-build.d.ts.map +1 -0
  17. package/dist/declaration-build.js +15 -0
  18. package/dist/declaration-helpers.d.ts +169 -0
  19. package/dist/declaration-helpers.d.ts.map +1 -0
  20. package/dist/declaration-helpers.js +239 -0
  21. package/dist/dep-resolver.d.ts +166 -0
  22. package/dist/dep-resolver.d.ts.map +1 -0
  23. package/dist/dep-resolver.js +144 -0
  24. package/dist/diagnostics.d.ts +650 -0
  25. package/dist/diagnostics.d.ts.map +1 -0
  26. package/dist/diagnostics.js +377 -0
  27. package/dist/discovery.d.ts +115 -0
  28. package/dist/discovery.d.ts.map +1 -0
  29. package/dist/discovery.js +126 -0
  30. package/dist/exports.d.ts +105 -0
  31. package/dist/exports.d.ts.map +1 -0
  32. package/dist/exports.js +274 -0
  33. package/dist/files.d.ts +77 -0
  34. package/dist/files.d.ts.map +1 -0
  35. package/dist/files.js +95 -0
  36. package/dist/index.d.ts +32 -0
  37. package/dist/index.d.ts.map +1 -0
  38. package/dist/index.js +30 -0
  39. package/dist/log.d.ts +32 -0
  40. package/dist/log.d.ts.map +1 -0
  41. package/dist/log.js +11 -0
  42. package/dist/logo.d.ts +8 -0
  43. package/dist/logo.d.ts.map +1 -0
  44. package/dist/logo.js +9 -0
  45. package/dist/main.d.ts +11 -0
  46. package/dist/main.d.ts.map +1 -0
  47. package/dist/main.js +18 -0
  48. package/dist/paths.d.ts +35 -0
  49. package/dist/paths.d.ts.map +1 -0
  50. package/dist/paths.js +34 -0
  51. package/dist/postprocess.d.ts +145 -0
  52. package/dist/postprocess.d.ts.map +1 -0
  53. package/dist/postprocess.js +305 -0
  54. package/dist/session.d.ts +248 -0
  55. package/dist/session.d.ts.map +1 -0
  56. package/dist/session.js +496 -0
  57. package/dist/source-config.d.ts +330 -0
  58. package/dist/source-config.d.ts.map +1 -0
  59. package/dist/source-config.js +356 -0
  60. package/dist/source.d.ts +126 -0
  61. package/dist/source.d.ts.map +1 -0
  62. package/dist/source.js +68 -0
  63. package/dist/svelte.d.ts +179 -0
  64. package/dist/svelte.d.ts.map +1 -0
  65. package/dist/svelte.js +898 -0
  66. package/dist/tsdoc.d.ts +145 -0
  67. package/dist/tsdoc.d.ts.map +1 -0
  68. package/dist/tsdoc.js +262 -0
  69. package/dist/types.d.ts +3381 -0
  70. package/dist/types.d.ts.map +1 -0
  71. package/dist/types.js +588 -0
  72. package/dist/typescript-exports.d.ts +91 -0
  73. package/dist/typescript-exports.d.ts.map +1 -0
  74. package/dist/typescript-exports.js +656 -0
  75. package/dist/typescript-extract-class.d.ts +29 -0
  76. package/dist/typescript-extract-class.d.ts.map +1 -0
  77. package/dist/typescript-extract-class.js +251 -0
  78. package/dist/typescript-extract-function.d.ts +47 -0
  79. package/dist/typescript-extract-function.d.ts.map +1 -0
  80. package/dist/typescript-extract-function.js +108 -0
  81. package/dist/typescript-extract-shared.d.ts +166 -0
  82. package/dist/typescript-extract-shared.d.ts.map +1 -0
  83. package/dist/typescript-extract-shared.js +528 -0
  84. package/dist/typescript-extract-type-properties.d.ts +34 -0
  85. package/dist/typescript-extract-type-properties.d.ts.map +1 -0
  86. package/dist/typescript-extract-type-properties.js +241 -0
  87. package/dist/typescript-extract-type.d.ts +48 -0
  88. package/dist/typescript-extract-type.d.ts.map +1 -0
  89. package/dist/typescript-extract-type.js +238 -0
  90. package/dist/typescript-program.d.ts +211 -0
  91. package/dist/typescript-program.d.ts.map +1 -0
  92. package/dist/typescript-program.js +290 -0
  93. package/dist/vite.d.ts +116 -0
  94. package/dist/vite.d.ts.map +1 -0
  95. package/dist/vite.js +418 -0
  96. package/package.json +131 -0
  97. package/virtual-svelte-docinfo.d.ts +49 -0
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Per-declaration extractor for TypeScript classes.
3
+ *
4
+ * `extractClassInfo` mutates a `DeclarationJsonBuild` with rich metadata
5
+ * derived from the class declaration: heritage clauses, generic parameters,
6
+ * properties, methods, constructors, and accessor pairs (getters/setters
7
+ * merged by name). Called by `analyzeDeclaration` in `typescript-exports.ts`
8
+ * once kind dispatch is settled.
9
+ *
10
+ * @see `typescript-extract-shared.ts` for shared helpers
11
+ *
12
+ * @module
13
+ */
14
+ import ts from 'typescript';
15
+ import type { DeclarationJsonBuild } from './declaration-build.js';
16
+ import { type Diagnostic } from './diagnostics.js';
17
+ /**
18
+ * Extract class information with rich member metadata.
19
+ *
20
+ * @internal Used by `analyzeDeclaration` — not part of the public barrel export.
21
+ *
22
+ * @param node - the declaration AST node
23
+ * @param checker - TypeScript type checker
24
+ * @param declaration - the declaration to populate
25
+ * @param diagnostics - diagnostics collector for non-fatal issues
26
+ * @mutates declaration - adds extends, implements, genericParams, members
27
+ */
28
+ export declare const extractClassInfo: (node: ts.Node, checker: ts.TypeChecker, declaration: DeclarationJsonBuild, diagnostics: Array<Diagnostic>) => void;
29
+ //# sourceMappingURL=typescript-extract-class.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript-extract-class.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/typescript-extract-class.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAC;AAG5B,OAAO,KAAK,EAAC,oBAAoB,EAAkB,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAC,KAAK,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAUjD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,gBAAgB,GAC5B,MAAM,EAAE,CAAC,IAAI,EACb,SAAS,EAAE,CAAC,WAAW,EACvB,aAAa,oBAAoB,EACjC,aAAa,KAAK,CAAC,UAAU,CAAC,KAC5B,IAwPF,CAAC"}
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Per-declaration extractor for TypeScript classes.
3
+ *
4
+ * `extractClassInfo` mutates a `DeclarationJsonBuild` with rich metadata
5
+ * derived from the class declaration: heritage clauses, generic parameters,
6
+ * properties, methods, constructors, and accessor pairs (getters/setters
7
+ * merged by name). Called by `analyzeDeclaration` in `typescript-exports.ts`
8
+ * once kind dispatch is settled.
9
+ *
10
+ * @see `typescript-extract-shared.ts` for shared helpers
11
+ *
12
+ * @module
13
+ */
14
+ import ts from 'typescript';
15
+ import {} from './diagnostics.js';
16
+ import { parseComment, applyToDeclaration } from './tsdoc.js';
17
+ import { detectReactivity, extractModifiers, getNodeLocation, parseGenericParam, populateCallableMember, } from './typescript-extract-shared.js';
18
+ /**
19
+ * Extract class information with rich member metadata.
20
+ *
21
+ * @internal Used by `analyzeDeclaration` — not part of the public barrel export.
22
+ *
23
+ * @param node - the declaration AST node
24
+ * @param checker - TypeScript type checker
25
+ * @param declaration - the declaration to populate
26
+ * @param diagnostics - diagnostics collector for non-fatal issues
27
+ * @mutates declaration - adds extends, implements, genericParams, members
28
+ */
29
+ export const extractClassInfo = (node, checker, declaration, diagnostics) => {
30
+ if (!ts.isClassDeclaration(node))
31
+ return;
32
+ if (node.heritageClauses) {
33
+ const extendsClause = node.heritageClauses.find((hc) => hc.token === ts.SyntaxKind.ExtendsKeyword);
34
+ if (extendsClause?.types[0]) {
35
+ declaration.extends = extendsClause.types[0].getText();
36
+ }
37
+ declaration.implements = node.heritageClauses
38
+ .filter((hc) => hc.token === ts.SyntaxKind.ImplementsKeyword)
39
+ .flatMap((hc) => hc.types.map((t) => t.getText()));
40
+ }
41
+ if (node.typeParameters?.length) {
42
+ declaration.genericParams = node.typeParameters.map(parseGenericParam);
43
+ }
44
+ // Extract members with full metadata
45
+ // Track processed constructors and methods to deduplicate overloads
46
+ let constructorProcessed = false;
47
+ const processedMethods = new Set();
48
+ for (const member of node.members) {
49
+ if (ts.isPropertyDeclaration(member) ||
50
+ ts.isMethodDeclaration(member) ||
51
+ ts.isConstructorDeclaration(member)) {
52
+ const isConstructor = ts.isConstructorDeclaration(member);
53
+ const memberName = isConstructor
54
+ ? 'constructor'
55
+ : ts.isIdentifier(member.name)
56
+ ? member.name.text
57
+ : member.name.getText();
58
+ if (!memberName)
59
+ continue;
60
+ // Skip private fields (those starting with #)
61
+ if (memberName.startsWith('#'))
62
+ continue;
63
+ // Skip private members - protected members are part of the extension API
64
+ const modifiers = ts.getModifiers(member);
65
+ if (modifiers) {
66
+ const isPrivate = modifiers.some((m) => m.kind === ts.SyntaxKind.PrivateKeyword);
67
+ if (isPrivate)
68
+ continue;
69
+ }
70
+ // Skip duplicate overload declarations — only process first occurrence
71
+ if (isConstructor) {
72
+ if (constructorProcessed)
73
+ continue;
74
+ constructorProcessed = true;
75
+ }
76
+ else if (ts.isMethodDeclaration(member)) {
77
+ if (processedMethods.has(memberName))
78
+ continue;
79
+ processedMethods.add(memberName);
80
+ }
81
+ const memberKind = isConstructor
82
+ ? 'constructor'
83
+ : ts.isMethodDeclaration(member)
84
+ ? 'function'
85
+ : 'variable';
86
+ const memberDeclaration = {
87
+ name: memberName,
88
+ kind: memberKind,
89
+ };
90
+ if (ts.isPropertyDeclaration(member) && member.questionToken) {
91
+ memberDeclaration.optional = true;
92
+ }
93
+ // Extract modifiers (reuse already-extracted modifiers array)
94
+ const modifierFlags = extractModifiers(modifiers);
95
+ if (modifierFlags.length > 0) {
96
+ memberDeclaration.modifiers = modifierFlags;
97
+ }
98
+ // Extract TSDoc (applies docComment, examples, deprecated, seeAlso, since, mutates)
99
+ const memberTsdoc = parseComment(member, node.getSourceFile());
100
+ applyToDeclaration(memberDeclaration, memberTsdoc);
101
+ // Extract type information and parameters for methods and constructors
102
+ try {
103
+ if (ts.isPropertyDeclaration(member)) {
104
+ if (member.type) {
105
+ memberDeclaration.typeSignature = member.type.getText();
106
+ }
107
+ else {
108
+ // Fall back to inferred type for unannotated fields (e.g., `count = $state(0)`).
109
+ const memberSymbol = checker.getSymbolAtLocation(member.name);
110
+ if (memberSymbol) {
111
+ const t = checker.getTypeOfSymbolAtLocation(memberSymbol, member);
112
+ memberDeclaration.typeSignature = checker.typeToString(t);
113
+ }
114
+ }
115
+ }
116
+ else if (ts.isMethodDeclaration(member) || ts.isConstructorDeclaration(member)) {
117
+ let signatures = [];
118
+ if (isConstructor) {
119
+ // Direct AST→signature path. Mirrors how methods (below) operate via
120
+ // the member node, but constructors lack a `member.name` to detour
121
+ // through. Works for both named and anonymous classes (the previous
122
+ // `getSymbolAtLocation(node.name)` detour silently dropped signatures
123
+ // for `export default class { ... }`).
124
+ const ctorDecls = node.members.filter(ts.isConstructorDeclaration);
125
+ // When overload signatures (no body) exist, only those count as
126
+ // public signatures — the implementation is hidden. Mirrors what
127
+ // `getConstructSignatures()` returns on the class type.
128
+ const overloadDecls = ctorDecls.filter((c) => !c.body);
129
+ const ctorsToUse = overloadDecls.length > 0 ? overloadDecls : ctorDecls;
130
+ signatures = ctorsToUse
131
+ .map((c) => checker.getSignatureFromDeclaration(c))
132
+ .filter((s) => s !== undefined);
133
+ }
134
+ else {
135
+ // For methods, get call signatures from the method symbol
136
+ const memberSymbol = checker.getSymbolAtLocation(member.name);
137
+ if (memberSymbol) {
138
+ const memberType = checker.getTypeOfSymbolAtLocation(memberSymbol, member);
139
+ signatures = memberType.getCallSignatures();
140
+ }
141
+ }
142
+ populateCallableMember(memberDeclaration, signatures, checker, memberTsdoc, member, memberName, diagnostics, !isConstructor);
143
+ }
144
+ }
145
+ catch (err) {
146
+ memberDeclaration.partial = true;
147
+ const loc = getNodeLocation(member);
148
+ const className = node.name?.text ?? '<anonymous>';
149
+ diagnostics.push({
150
+ kind: 'class_member_failed',
151
+ file: loc.file,
152
+ line: loc.line,
153
+ column: loc.column,
154
+ message: `Failed to analyze member "${memberName}" in class "${className}": ${err instanceof Error ? err.message : String(err)}`,
155
+ severity: 'warning',
156
+ className,
157
+ memberName,
158
+ });
159
+ }
160
+ // Outside the try so reactivity is still captured if type extraction throws.
161
+ if (ts.isPropertyDeclaration(member)) {
162
+ const reactivity = detectReactivity(member.initializer);
163
+ if (reactivity)
164
+ memberDeclaration.reactivity = reactivity;
165
+ }
166
+ (declaration.members ??= []).push(memberDeclaration);
167
+ }
168
+ }
169
+ // Extract accessors (getters/setters) - group by name to merge pairs
170
+ const accessors = new Map();
171
+ for (const member of node.members) {
172
+ if (ts.isGetAccessor(member) || ts.isSetAccessor(member)) {
173
+ const accessorName = ts.isIdentifier(member.name) ? member.name.text : member.name.getText();
174
+ if (!accessorName)
175
+ continue;
176
+ // Skip private accessors - protected are part of the extension API
177
+ const modifiers = ts.getModifiers(member);
178
+ if (modifiers) {
179
+ const isPrivate = modifiers.some((m) => m.kind === ts.SyntaxKind.PrivateKeyword);
180
+ if (isPrivate)
181
+ continue;
182
+ }
183
+ const existing = accessors.get(accessorName) ?? { getter: null, setter: null };
184
+ if (ts.isGetAccessor(member)) {
185
+ existing.getter = member;
186
+ }
187
+ else {
188
+ existing.setter = member;
189
+ }
190
+ accessors.set(accessorName, existing);
191
+ }
192
+ }
193
+ // Create declarations for accessor pairs
194
+ for (const [accessorName, { getter, setter }] of accessors) {
195
+ const accessorDeclaration = {
196
+ name: accessorName,
197
+ kind: 'variable',
198
+ };
199
+ // Build modifiers: getter/setter indicators + other modifiers (static, etc.)
200
+ const accessorModifiers = [];
201
+ if (getter)
202
+ accessorModifiers.push('getter');
203
+ if (setter)
204
+ accessorModifiers.push('setter');
205
+ // Extract other modifiers from getter (or setter if no getter)
206
+ const primaryAccessor = getter ?? setter;
207
+ const otherModifiers = extractModifiers(ts.getModifiers(primaryAccessor));
208
+ accessorModifiers.push(...otherModifiers);
209
+ if (accessorModifiers.length > 0) {
210
+ accessorDeclaration.modifiers = accessorModifiers;
211
+ }
212
+ // Extract TSDoc - prefer getter's, fall back to setter's
213
+ const getterTsdoc = getter ? parseComment(getter, node.getSourceFile()) : undefined;
214
+ const setterTsdoc = setter ? parseComment(setter, node.getSourceFile()) : undefined;
215
+ const accessorTsdoc = getterTsdoc ?? setterTsdoc;
216
+ applyToDeclaration(accessorDeclaration, accessorTsdoc);
217
+ // Extract type signature from getter's return type
218
+ try {
219
+ if (getter) {
220
+ const getterSymbol = checker.getSymbolAtLocation(getter.name);
221
+ if (getterSymbol) {
222
+ const getterType = checker.getTypeOfSymbolAtLocation(getterSymbol, getter);
223
+ accessorDeclaration.typeSignature = checker.typeToString(getterType);
224
+ }
225
+ }
226
+ else if (setter?.parameters.length) {
227
+ // Fall back to setter's parameter type if no getter
228
+ const param = setter.parameters[0];
229
+ if (param.type) {
230
+ accessorDeclaration.typeSignature = param.type.getText();
231
+ }
232
+ }
233
+ }
234
+ catch (err) {
235
+ accessorDeclaration.partial = true;
236
+ const loc = getNodeLocation(primaryAccessor);
237
+ const className = node.name?.text ?? '<anonymous>';
238
+ diagnostics.push({
239
+ kind: 'class_member_failed',
240
+ file: loc.file,
241
+ line: loc.line,
242
+ column: loc.column,
243
+ message: `Failed to analyze accessor "${accessorName}" in class "${className}": ${err instanceof Error ? err.message : String(err)}`,
244
+ severity: 'warning',
245
+ className,
246
+ memberName: accessorName,
247
+ });
248
+ }
249
+ (declaration.members ??= []).push(accessorDeclaration);
250
+ }
251
+ };
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Per-declaration extractors for TypeScript functions and variables.
3
+ *
4
+ * Both `extractFunctionInfo` and `extractVariableInfo` mutate a
5
+ * `DeclarationJsonBuild` with rich metadata derived from the TypeScript
6
+ * checker. Called by `analyzeDeclaration` in `typescript-exports.ts` once
7
+ * kind dispatch is settled.
8
+ *
9
+ * @see `typescript-extract-shared.ts` for shared helpers (signatures,
10
+ * overloads, generics, reactivity)
11
+ *
12
+ * @module
13
+ */
14
+ import ts from 'typescript';
15
+ import type { DeclarationJsonBuild } from './declaration-build.js';
16
+ import { type Diagnostic } from './diagnostics.js';
17
+ import type { TsdocParsedComment } from './tsdoc.js';
18
+ /**
19
+ * Extract function/method information including parameters
20
+ * with descriptions and default values.
21
+ *
22
+ * @internal Used by `analyzeDeclaration` — not part of the public barrel export.
23
+ *
24
+ * @param node - the declaration AST node
25
+ * @param symbol - the TypeScript symbol
26
+ * @param checker - TypeScript type checker
27
+ * @param declaration - the declaration to populate
28
+ * @param tsdoc - parsed TSDoc comment (if available)
29
+ * @param diagnostics - diagnostics collector for non-fatal issues
30
+ * @mutates declaration - adds typeSignature, returnType, returnDescription, parameters, genericParams, overloads (and `partial: true` on signature failure)
31
+ * @mutates diagnostics - adds `signature_analysis_failed` diagnostic on checker error
32
+ */
33
+ export declare const extractFunctionInfo: (node: ts.Node, symbol: ts.Symbol, checker: ts.TypeChecker, declaration: DeclarationJsonBuild, tsdoc: TsdocParsedComment | undefined, diagnostics: Array<Diagnostic>) => void;
34
+ /**
35
+ * Extract variable information.
36
+ *
37
+ * @internal Used by `analyzeDeclaration` — not part of the public barrel export.
38
+ *
39
+ * @param node - the declaration AST node
40
+ * @param symbol - the TypeScript symbol
41
+ * @param checker - TypeScript type checker
42
+ * @param declaration - the declaration to populate
43
+ * @param diagnostics - diagnostics collector for non-fatal issues
44
+ * @mutates declaration - adds typeSignature, reactivity (when initialized with a Svelte rune)
45
+ */
46
+ export declare const extractVariableInfo: (node: ts.Node, symbol: ts.Symbol, checker: ts.TypeChecker, declaration: DeclarationJsonBuild, diagnostics: Array<Diagnostic>) => void;
47
+ //# sourceMappingURL=typescript-extract-function.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript-extract-function.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/typescript-extract-function.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAC,KAAK,UAAU,EAAC,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,YAAY,CAAC;AAQnD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,GAC/B,MAAM,EAAE,CAAC,IAAI,EACb,QAAQ,EAAE,CAAC,MAAM,EACjB,SAAS,EAAE,CAAC,WAAW,EACvB,aAAa,oBAAoB,EACjC,OAAO,kBAAkB,GAAG,SAAS,EACrC,aAAa,KAAK,CAAC,UAAU,CAAC,KAC5B,IAuCF,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,mBAAmB,GAC/B,MAAM,EAAE,CAAC,IAAI,EACb,QAAQ,EAAE,CAAC,MAAM,EACjB,SAAS,EAAE,CAAC,WAAW,EACvB,aAAa,oBAAoB,EACjC,aAAa,KAAK,CAAC,UAAU,CAAC,KAC5B,IAuBF,CAAC"}
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Per-declaration extractors for TypeScript functions and variables.
3
+ *
4
+ * Both `extractFunctionInfo` and `extractVariableInfo` mutate a
5
+ * `DeclarationJsonBuild` with rich metadata derived from the TypeScript
6
+ * checker. Called by `analyzeDeclaration` in `typescript-exports.ts` once
7
+ * kind dispatch is settled.
8
+ *
9
+ * @see `typescript-extract-shared.ts` for shared helpers (signatures,
10
+ * overloads, generics, reactivity)
11
+ *
12
+ * @module
13
+ */
14
+ import ts from 'typescript';
15
+ import {} from './diagnostics.js';
16
+ import { detectReactivity, getNodeLocation, parseGenericParam, populateCallableMember, } from './typescript-extract-shared.js';
17
+ /**
18
+ * Extract function/method information including parameters
19
+ * with descriptions and default values.
20
+ *
21
+ * @internal Used by `analyzeDeclaration` — not part of the public barrel export.
22
+ *
23
+ * @param node - the declaration AST node
24
+ * @param symbol - the TypeScript symbol
25
+ * @param checker - TypeScript type checker
26
+ * @param declaration - the declaration to populate
27
+ * @param tsdoc - parsed TSDoc comment (if available)
28
+ * @param diagnostics - diagnostics collector for non-fatal issues
29
+ * @mutates declaration - adds typeSignature, returnType, returnDescription, parameters, genericParams, overloads (and `partial: true` on signature failure)
30
+ * @mutates diagnostics - adds `signature_analysis_failed` diagnostic on checker error
31
+ */
32
+ export const extractFunctionInfo = (node, symbol, checker, declaration, tsdoc, diagnostics) => {
33
+ try {
34
+ const type = checker.getTypeOfSymbolAtLocation(symbol, node);
35
+ const signatures = type.getCallSignatures();
36
+ populateCallableMember(declaration, signatures, checker, tsdoc, node, symbol.name, diagnostics);
37
+ }
38
+ catch (err) {
39
+ declaration.partial = true;
40
+ const loc = getNodeLocation(node);
41
+ diagnostics.push({
42
+ kind: 'signature_analysis_failed',
43
+ file: loc.file,
44
+ line: loc.line,
45
+ column: loc.column,
46
+ message: `Failed to analyze signature for "${symbol.name}": ${err instanceof Error ? err.message : String(err)}`,
47
+ severity: 'warning',
48
+ functionName: symbol.name,
49
+ });
50
+ }
51
+ // Extract generic type parameters
52
+ let typeParameters;
53
+ if (ts.isFunctionDeclaration(node) || ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
54
+ typeParameters = node.typeParameters;
55
+ }
56
+ else if (ts.isVariableDeclaration(node)) {
57
+ if (node.type && ts.isFunctionTypeNode(node.type)) {
58
+ // `export const fn: <T>(x: T) => T = (x) => x` — generics on the type annotation.
59
+ // Annotation wins over initializer when both carry generics: it's the public type.
60
+ typeParameters = node.type.typeParameters;
61
+ }
62
+ else if (node.initializer &&
63
+ (ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer))) {
64
+ // `export const foo = <T>(x: T) => x` — generics live on the initializer, not the variable.
65
+ typeParameters = node.initializer.typeParameters;
66
+ }
67
+ }
68
+ if (typeParameters?.length) {
69
+ declaration.genericParams = typeParameters.map(parseGenericParam);
70
+ }
71
+ };
72
+ /**
73
+ * Extract variable information.
74
+ *
75
+ * @internal Used by `analyzeDeclaration` — not part of the public barrel export.
76
+ *
77
+ * @param node - the declaration AST node
78
+ * @param symbol - the TypeScript symbol
79
+ * @param checker - TypeScript type checker
80
+ * @param declaration - the declaration to populate
81
+ * @param diagnostics - diagnostics collector for non-fatal issues
82
+ * @mutates declaration - adds typeSignature, reactivity (when initialized with a Svelte rune)
83
+ */
84
+ export const extractVariableInfo = (node, symbol, checker, declaration, diagnostics) => {
85
+ try {
86
+ const type = checker.getTypeOfSymbolAtLocation(symbol, node);
87
+ declaration.typeSignature = checker.typeToString(type);
88
+ }
89
+ catch (err) {
90
+ declaration.partial = true;
91
+ const loc = getNodeLocation(node);
92
+ diagnostics.push({
93
+ kind: 'type_extraction_failed',
94
+ file: loc.file,
95
+ line: loc.line,
96
+ column: loc.column,
97
+ message: `Failed to extract type for variable "${symbol.name}": ${err instanceof Error ? err.message : String(err)}`,
98
+ severity: 'warning',
99
+ symbolName: symbol.name,
100
+ });
101
+ }
102
+ // Outside the try so reactivity is still captured if type extraction throws.
103
+ if (ts.isVariableDeclaration(node)) {
104
+ const reactivity = detectReactivity(node.initializer);
105
+ if (reactivity)
106
+ declaration.reactivity = reactivity;
107
+ }
108
+ };
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Shared utilities for the per-declaration extractors in `typescript-extract-*.ts`.
3
+ *
4
+ * Holds helpers used across function, type, and class extraction: signature
5
+ * parameter extraction, overload detection, generic parsing, modifier
6
+ * extraction, location reporting, intersection-property filtering, and runes
7
+ * detection.
8
+ *
9
+ * @see `typescript-extract-function.ts`, `typescript-extract-type.ts`,
10
+ * `typescript-extract-class.ts` for the per-declaration extractors that
11
+ * build on these helpers
12
+ *
13
+ * @module
14
+ */
15
+ import ts from 'typescript';
16
+ import type { GenericParamJson, DeclarationKind, DeclarationModifier, ParameterJson, Reactivity } from './types.js';
17
+ import type { DeclarationJsonBuild, MemberJsonBuild } from './declaration-build.js';
18
+ import { type Diagnostic } from './diagnostics.js';
19
+ import { type TsdocParsedComment } from './tsdoc.js';
20
+ import { type IsExternalFile } from './typescript-program.js';
21
+ /**
22
+ * Infer declaration kind from symbol and node.
23
+ *
24
+ * Maps TypeScript constructs to `DeclarationKind`:
25
+ * - Classes → `'class'`
26
+ * - Functions (declarations, expressions, arrows) → `'function'`
27
+ * - Interfaces → `'interface'`
28
+ * - Type aliases → `'type'`
29
+ * - Enums (regular and const) → `'enum'`
30
+ * - Variables → `'variable'` (unless function-valued → `'function'`)
31
+ *
32
+ * Note: namespace re-exports (`export * as ns from './x'`) have no inline
33
+ * declaration form in TypeScript and are caught upstream in `analyzeExports`
34
+ * via `classifyNamespaceReExport`. They never reach this function. A direct
35
+ * call here on a `ValueModule` symbol would fall through to `'variable'` and
36
+ * leak `typeof import("/abs/path")` into the output — keep the namespace
37
+ * dispatch in `analyzeExports`.
38
+ */
39
+ export declare const inferDeclarationKind: (symbol: ts.Symbol, node: ts.Node) => DeclarationKind;
40
+ /**
41
+ * Extract parameters from a TypeScript signature with TSDoc descriptions and default values.
42
+ *
43
+ * Shared helper for extracting parameter information from both standalone functions
44
+ * and class methods/constructors.
45
+ *
46
+ * @param sig - the TypeScript signature to extract parameters from
47
+ * @param checker - TypeScript type checker for type resolution
48
+ * @param tsdocParams - record of parameter names to TSDoc descriptions (from `TsdocParsedComment.params`)
49
+ * @returns array of `ParameterJson` objects
50
+ */
51
+ export declare const extractSignatureParameters: (sig: ts.Signature, checker: ts.TypeChecker, tsdocParams: Record<string, string> | undefined) => Array<ParameterJson>;
52
+ /**
53
+ * Populate the callable fields of a declaration or member from its call/construct
54
+ * signatures: `typeSignature`, `parameters`, `overloads`, and (unless
55
+ * `includeReturn` is false) `returnType` / `returnDescription`.
56
+ *
57
+ * The shared core of every named-callable extractor — standalone functions,
58
+ * interface methods, class methods/constructors, and type-alias function
59
+ * properties. Callers differ in how they obtain `signatures` (symbol type,
60
+ * constructor declarations, property call signatures) and in their own
61
+ * try/catch + diagnostic kind, so those stay at the callsite; this captures
62
+ * only the identical projection from a resolved signature list onto the build
63
+ * target. No-op when `signatures` is empty.
64
+ *
65
+ * @param target - declaration or member build object (mutated)
66
+ * @param signatures - public call/construct signatures (`signatures[0]` is primary)
67
+ * @param tsdoc - parsed TSDoc for the target (supplies `@param`/`@returns`)
68
+ * @param paramValidationNode - node `validateParamKeys` reports `unknown_param` against
69
+ * @param name - target name, for diagnostic messages
70
+ * @param includeReturn - set `false` for constructors (no return type/description)
71
+ * @mutates target - sets typeSignature, parameters, overloads, returnType, returnDescription
72
+ * @mutates diagnostics - via `validateParamKeys` / `extractOverloads`
73
+ */
74
+ export declare const populateCallableMember: (target: DeclarationJsonBuild | MemberJsonBuild, signatures: ReadonlyArray<ts.Signature>, checker: ts.TypeChecker, tsdoc: TsdocParsedComment | undefined, paramValidationNode: ts.Node, name: string, diagnostics: Array<Diagnostic>, includeReturn?: boolean) => void;
75
+ /**
76
+ * Determine whether an intersection branch refers to a type whose declarations
77
+ * all live in external files (e.g., `HTMLAttributes<HTMLDivElement>` from svelte's
78
+ * d.ts). Inline object-literal branches and unrecognized node shapes return false
79
+ * (treated as local).
80
+ */
81
+ export declare const isExternalIntersectionBranch: (branchNode: ts.TypeNode, checker: ts.TypeChecker, isExternalFile: IsExternalFile) => boolean;
82
+ /**
83
+ * Resolve the `IntersectionTypeNode` for a type node, walking through type
84
+ * alias indirection. Returns `undefined` when the underlying type is an
85
+ * intersection but no AST node is recoverable (rare — synthesized intersections).
86
+ */
87
+ export declare const resolveIntersectionTypeNode: (type: ts.Type, typeNode: ts.Node) => ts.IntersectionTypeNode | undefined;
88
+ /**
89
+ * Filter intersection type properties to exclude those from external sources,
90
+ * and extract type names for branches whose properties are all external.
91
+ *
92
+ * Returns `null` for non-intersection types (caller should use unfiltered properties).
93
+ * For intersection types, returns filtered properties and external type names.
94
+ *
95
+ * Per-property filtering works through utility types (Partial, Pick, Readonly)
96
+ * because TypeScript preserves original declaration sources on mapped type properties.
97
+ */
98
+ export declare const filterIntersectionProperties: (type: ts.Type, typeNode: ts.Node, checker: ts.TypeChecker, isExternalFile: IsExternalFile) => {
99
+ properties: Array<ts.Symbol>;
100
+ intersectionTypes: Array<string>;
101
+ } | null;
102
+ /**
103
+ * Detect a Svelte 5 reactivity rune from a variable or property initializer.
104
+ *
105
+ * Inspects the AST since runes erase to their inner type after type-checking.
106
+ * Returns `undefined` for any non-rune expression. See the `Reactivity` enum
107
+ * in `types.ts` for the rationale on running this on every file regardless of
108
+ * extension.
109
+ */
110
+ export declare const detectReactivity: (initializer: ts.Expression | undefined) => Reactivity | undefined;
111
+ /**
112
+ * Extract line and column from a TypeScript node.
113
+ * Returns 1-based line and column numbers.
114
+ */
115
+ export declare const getNodeLocation: (node: ts.Node) => {
116
+ file: string;
117
+ line: number;
118
+ column: number;
119
+ };
120
+ /**
121
+ * Parse a TypeScript generic type parameter declaration into structured info.
122
+ *
123
+ * @param param - the TypeScript type parameter declaration node
124
+ * @returns structured `GenericParamJson` with name, constraint, and default type
125
+ */
126
+ export declare const parseGenericParam: (param: ts.TypeParameterDeclaration) => GenericParamJson;
127
+ /**
128
+ * Extract modifier keywords from a node's modifiers.
129
+ *
130
+ * Returns an array of modifier strings like `['public', 'readonly', 'static']`.
131
+ */
132
+ export declare const extractModifiers: (modifiers: ReadonlyArray<ts.ModifierLike> | undefined) => Array<DeclarationModifier>;
133
+ /**
134
+ * Append a `(call)` or `(construct)` signature member to a declaration.
135
+ *
136
+ * Captures the extraction logic shared by interface processing
137
+ * (`extractTypeInfo`) and type-alias property processing
138
+ * (`extractTypeAliasProperties`): type signature, parameters, generics,
139
+ * overloads, and TSDoc. The TSDoc source node is supplied by the caller —
140
+ * interfaces look it up in `node.members` (skipping TSDoc when no inline
141
+ * signature is declared, even if one is inherited), type aliases use
142
+ * `sig.getDeclaration()`.
143
+ *
144
+ * @param getSignatures - thunk to retrieve `getCallSignatures()` /
145
+ * `getConstructSignatures()`; called inside the try so checker errors are
146
+ * captured as diagnostics
147
+ * @param signatureKind - `'call'` (member kind: function, includes returnType)
148
+ * or `'construct'` (member kind: constructor, no returnType)
149
+ * @param resolveTsdocNode - callback returning the AST node to parse TSDoc
150
+ * from, or `undefined` to skip TSDoc resolution
151
+ * @param paramValidationFallbackNode - location used by `validateParamKeys`
152
+ * when `resolveTsdocNode` returns `undefined`
153
+ * @param declaration - parent declaration (mutated; appended to `members`)
154
+ * @param errorContext.node - parent node used to locate diagnostics
155
+ * @param errorContext.kindLabel - `'interface'` or `'type'`, included in the
156
+ * diagnostic message
157
+ *
158
+ * @mutates declaration - appends a member when signatures are present;
159
+ * sets `partial: true` on extraction failure
160
+ * @mutates diagnostics - adds `signature_analysis_failed` on checker error
161
+ */
162
+ export declare const emitCallOrConstructSignature: (getSignatures: () => ReadonlyArray<ts.Signature>, signatureKind: "call" | "construct", resolveTsdocNode: (sig: ts.Signature) => ts.Node | undefined, paramValidationFallbackNode: ts.Node, declaration: DeclarationJsonBuild, checker: ts.TypeChecker, diagnostics: Array<Diagnostic>, errorContext: {
163
+ node: ts.Node;
164
+ kindLabel: string;
165
+ }) => void;
166
+ //# sourceMappingURL=typescript-extract-shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typescript-extract-shared.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/typescript-extract-shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,OAAO,KAAK,EACX,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EAEnB,aAAa,EAEb,UAAU,EACV,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAC,oBAAoB,EAAE,eAAe,EAAC,MAAM,wBAAwB,CAAC;AAClF,OAAO,EAAC,KAAK,UAAU,EAA8B,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAmC,KAAK,kBAAkB,EAAC,MAAM,YAAY,CAAC;A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