@storybook/angular-vite 10.6.0-alpha.6 → 10.6.0-alpha.8
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/build-schema.json +33 -5
- package/dist/_browser-chunks/{chunk-CHMLOECK.js → chunk-AL7GEPYM.js} +15 -26
- package/dist/_browser-chunks/{chunk-HBLYOJ22.js → chunk-THQDNKQS.js} +3 -3
- package/dist/_browser-chunks/{chunk-ECGMCGUZ.js → chunk-UJ3I56EP.js} +6 -6
- package/dist/_browser-chunks/{chunk-BUNW7ROM.js → chunk-VP3W5GY3.js} +4 -4
- package/dist/_node-chunks/{chunk-ORVVXDOZ.js → chunk-5GTDRCMW.js} +18 -8
- package/dist/_node-chunks/{chunk-6P3TQP4W.js → chunk-DQYSVBAE.js} +7 -7
- package/dist/_node-chunks/chunk-FLU3HTGB.js +42 -0
- package/dist/_node-chunks/story-docs-template-analysis-LGFOFAHO.js +163 -0
- package/dist/builders/build-storybook/index.js +15 -10
- package/dist/builders/start-storybook/index.js +15 -10
- package/dist/chunk-Bv2XDHY-.d.ts +64 -0
- package/dist/client/config.js +2 -2
- package/dist/client/docs/config.js +2 -2
- package/dist/client/index.js +4 -4
- package/dist/docgen/docgen-worker.js +784 -286
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -4
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +6 -6
- package/dist/node/vitest.js +6 -6
- package/dist/preset.js +770 -197
- package/package.json +6 -6
- package/start-schema.json +33 -5
- package/dist/_node-chunks/chunk-5LXEVSHB.js +0 -35
- package/dist/chunk-D8_SR6hI.d.ts +0 -31
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_z1ub7mlv0j from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_z1ub7mlv0j from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_z1ub7mlv0j from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_z1ub7mlv0j.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_z1ub7mlv0j.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_z1ub7mlv0j.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
11
11
|
// ------------------------------------------------------------
|
|
12
12
|
import {
|
|
13
13
|
resolveStoryComponent
|
|
14
|
-
} from "../_node-chunks/chunk-
|
|
14
|
+
} from "../_node-chunks/chunk-FLU3HTGB.js";
|
|
15
15
|
|
|
16
16
|
// src/docgen/docgen-worker.ts
|
|
17
17
|
import { STORY_FILE_TEST_REGEXP, getStoryImportPathFromEntry as getStoryImportPathFromEntry2 } from "storybook/internal/common";
|
|
18
18
|
import { logger as logger4 } from "storybook/internal/node-logger";
|
|
19
19
|
|
|
20
20
|
// ../../lib/angular-cm/dist/index.js
|
|
21
|
-
import
|
|
22
|
-
import
|
|
23
|
-
import
|
|
21
|
+
import CJS_COMPAT_NODE_URL_zejiuct5sdn from "node:url";
|
|
22
|
+
import CJS_COMPAT_NODE_PATH_zejiuct5sdn from "node:path";
|
|
23
|
+
import CJS_COMPAT_NODE_MODULE_zejiuct5sdn from "node:module";
|
|
24
24
|
import {
|
|
25
25
|
ComponentMetaManager,
|
|
26
26
|
parseTsconfigCommandLine
|
|
27
27
|
} from "storybook/internal/component-meta";
|
|
28
28
|
import { isInNodeModules, slash } from "storybook/internal/common";
|
|
29
29
|
import {
|
|
30
|
+
extractComponentJsDocInfo,
|
|
30
31
|
ProgramBackedProject,
|
|
31
32
|
ProjectFileTracker
|
|
32
33
|
} from "storybook/internal/component-meta";
|
|
@@ -34,7 +35,7 @@ import { logger as logger3 } from "storybook/internal/node-logger";
|
|
|
34
35
|
import * as path from "node:path";
|
|
35
36
|
import { logger as logger2 } from "storybook/internal/node-logger";
|
|
36
37
|
import { logger } from "storybook/internal/node-logger";
|
|
37
|
-
var __filename =
|
|
38
|
+
var __filename = CJS_COMPAT_NODE_URL_zejiuct5sdn.fileURLToPath(import.meta.url), __dirname = CJS_COMPAT_NODE_PATH_zejiuct5sdn.dirname(__filename), require2 = CJS_COMPAT_NODE_MODULE_zejiuct5sdn.createRequire(import.meta.url), NOOP_LOGGER = {
|
|
38
39
|
warn: () => {
|
|
39
40
|
},
|
|
40
41
|
debug: () => {
|
|
@@ -48,7 +49,7 @@ var __filename = CJS_COMPAT_NODE_URL_ctyo0js0zv6.fileURLToPath(import.meta.url),
|
|
|
48
49
|
"view children",
|
|
49
50
|
"content child",
|
|
50
51
|
"content children"
|
|
51
|
-
], isMethod = (methodOrProp) => methodOrProp.args !== void 0, isRequired = (item) => (item.required ??
|
|
52
|
+
], isMethod = (methodOrProp) => methodOrProp.args !== void 0, isRequired = (item) => (item.required ?? item.initializer === void 0) && !item.optional, hasDecorator = (item, decoratorName) => item.decorators && item.decorators.find((x) => x.name === decoratorName), mapPropertyToSection = (item) => hasDecorator(item, "ViewChild") ? "view child" : hasDecorator(item, "ViewChildren") ? "view children" : hasDecorator(item, "ContentChild") ? "content child" : hasDecorator(item, "ContentChildren") ? "content children" : "properties", mapItemToSection = (key, item) => {
|
|
52
53
|
switch (key) {
|
|
53
54
|
case "methods":
|
|
54
55
|
case "methodsClass":
|
|
@@ -70,7 +71,12 @@ var __filename = CJS_COMPAT_NODE_URL_ctyo0js0zv6.fileURLToPath(import.meta.url),
|
|
|
70
71
|
).join(", ")}) => ${item.returnType}`, extractTypeFromValue = (defaultValue) => {
|
|
71
72
|
let valueType = typeof defaultValue;
|
|
72
73
|
return defaultValue || valueType === "number" || valueType === "boolean" || valueType === "string" ? valueType : null;
|
|
73
|
-
}, pickDeclaration = (candidates, componentFile) => candidates.length <= 1 ? candidates[0] : (componentFile ? candidates.find((candidate) => candidate.file === componentFile) : void 0) ?? [...candidates].sort((a, b) => (a.file ?? "").localeCompare(b.file ?? ""))[0], selectableUnionMembers = (type) => type.split("|").map((member) => member.trim()).filter((member) => member !== "undefined" && member !== "null"),
|
|
74
|
+
}, pickDeclaration = (candidates, componentFile) => candidates.length <= 1 ? candidates[0] : (componentFile ? candidates.find((candidate) => candidate.file === componentFile) : void 0) ?? [...candidates].sort((a, b) => (a.file ?? "").localeCompare(b.file ?? ""))[0], selectableUnionMembers = (type) => type.split("|").map((member) => member.trim()).filter((member) => member !== "undefined" && member !== "null"), CONTROL_PRIMITIVES = ["boolean", "number", "string"], primitiveUnionControl = (members) => {
|
|
75
|
+
let narrowest = CONTROL_PRIMITIVES.find((name) => members.includes(name)), allPrimitive = members.every(
|
|
76
|
+
(member) => CONTROL_PRIMITIVES.includes(member)
|
|
77
|
+
);
|
|
78
|
+
return narrowest !== void 0 && allPrimitive ? { name: narrowest } : void 0;
|
|
79
|
+
}, hasEnumValue = (child) => !!child.value, extractEnumValues = (type, metadataJson, componentFile) => {
|
|
74
80
|
let childs = pickDeclaration(
|
|
75
81
|
metadataJson?.miscellaneous?.enumerations?.filter((x) => x.name === type) ?? [],
|
|
76
82
|
componentFile
|
|
@@ -95,7 +101,7 @@ var __filename = CJS_COMPAT_NODE_URL_ctyo0js0zv6.fileURLToPath(import.meta.url),
|
|
|
95
101
|
componentFile
|
|
96
102
|
);
|
|
97
103
|
return typeAlias ? (seen.add(type), resolveTypealias(typeAlias.rawtype, metadataJson, componentFile, seen)) : type;
|
|
98
|
-
}, isFunctionTypeString = (type) => type === "function" ||
|
|
104
|
+
}, isFunctionTypeString = (type) => type === "function" || /^(new\s+)?(<.*>\s*)?\(.*\)\s*=>/.test(type), extractType = (property, defaultValue, metadataJson, componentFile) => {
|
|
99
105
|
let type = property.type || extractTypeFromValue(defaultValue);
|
|
100
106
|
switch (type) {
|
|
101
107
|
case "string":
|
|
@@ -109,9 +115,9 @@ var __filename = CJS_COMPAT_NODE_URL_ctyo0js0zv6.fileURLToPath(import.meta.url),
|
|
|
109
115
|
return { name: "function" };
|
|
110
116
|
let resolvedType = resolveTypealias(type, metadataJson, componentFile);
|
|
111
117
|
if (typeof resolvedType == "string" && resolvedType.indexOf("|") !== -1) {
|
|
112
|
-
let
|
|
113
|
-
if (
|
|
114
|
-
return
|
|
118
|
+
let control = primitiveUnionControl([...new Set(selectableUnionMembers(resolvedType))]);
|
|
119
|
+
if (control)
|
|
120
|
+
return control;
|
|
115
121
|
}
|
|
116
122
|
let enumValues = extractEnumValues(resolvedType, metadataJson, componentFile);
|
|
117
123
|
return enumValues ? { name: "enum", value: enumValues } : { name: "other", value: "empty-enum" };
|
|
@@ -146,18 +152,48 @@ var __filename = CJS_COMPAT_NODE_URL_ctyo0js0zv6.fileURLToPath(import.meta.url),
|
|
|
146
152
|
default:
|
|
147
153
|
return castUntypedDefault(defaultValue);
|
|
148
154
|
}
|
|
149
|
-
}, unquote = (value) => value.replace(/^
|
|
150
|
-
let
|
|
151
|
-
|
|
152
|
-
let tagName = tag.tagName
|
|
153
|
-
(tagName === "default" || tagName === "defaultvalue") && tag.comment !== void 0 && (
|
|
154
|
-
}
|
|
155
|
+
}, unquote = (value) => value.replace(/^(['"`])([\s\S]*)\1$/, "$2"), authoredDefault = (property) => {
|
|
156
|
+
let value;
|
|
157
|
+
for (let tag of property.jsdoctags ?? []) {
|
|
158
|
+
let tagName = tag.tagName?.escapedText?.toLowerCase();
|
|
159
|
+
(tagName === "default" || tagName === "defaultvalue") && tag.comment !== void 0 && (value = unquote(commentText(tag.comment).trim()));
|
|
160
|
+
}
|
|
161
|
+
return value;
|
|
162
|
+
}, analyzerDefault = (initializer) => {
|
|
163
|
+
switch (initializer.literalKind) {
|
|
164
|
+
case "string":
|
|
165
|
+
return unquote(initializer.text);
|
|
166
|
+
case "number": {
|
|
167
|
+
let parsed = Number(initializer.text);
|
|
168
|
+
return Number.isNaN(parsed) ? initializer.text : parsed;
|
|
169
|
+
}
|
|
170
|
+
case "boolean":
|
|
171
|
+
return initializer.text === "true";
|
|
172
|
+
case "null":
|
|
173
|
+
return null;
|
|
174
|
+
case "undefined":
|
|
175
|
+
return;
|
|
176
|
+
case "bigint":
|
|
177
|
+
case "enum":
|
|
178
|
+
case "composite":
|
|
179
|
+
return initializer.text;
|
|
180
|
+
}
|
|
155
181
|
}, extractDefaultValue = (property, logger42) => {
|
|
156
182
|
try {
|
|
157
|
-
let
|
|
158
|
-
|
|
183
|
+
let authored = authoredDefault(property);
|
|
184
|
+
if (authored !== void 0)
|
|
185
|
+
return castDefaultValue(property, authored);
|
|
186
|
+
if (property.initializer === void 0)
|
|
187
|
+
return;
|
|
188
|
+
if (property.initializer.kind === "expression") {
|
|
189
|
+
logger42.debug(
|
|
190
|
+
`${property.name}: non-literal default '${property.initializer.text}' not shown`
|
|
191
|
+
);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
return analyzerDefault(property.initializer);
|
|
159
195
|
} catch {
|
|
160
|
-
logger42.debug(`Error extracting ${property.name}: ${property.
|
|
196
|
+
logger42.debug(`Error extracting ${property.name}: ${property.initializer?.text}`);
|
|
161
197
|
return;
|
|
162
198
|
}
|
|
163
199
|
}, extractMemberJsDocTags = (member) => {
|
|
@@ -171,7 +207,7 @@ var __filename = CJS_COMPAT_NODE_URL_ctyo0js0zv6.fileURLToPath(import.meta.url),
|
|
|
171
207
|
...deprecated !== void 0 ? { deprecated } : {},
|
|
172
208
|
...returns !== void 0 ? { returns } : {}
|
|
173
209
|
};
|
|
174
|
-
}, readMembers = (componentData, key) => componentData[key] || [], isDirectiveEntry = (componentData) => componentData.type === "component" || componentData.type === "directive", getModelProperties = (componentData) => {
|
|
210
|
+
}, documentedInMode = (item, section2, propsTable) => propsTable === "all" ? !0 : item.internal === !0 || item.name.startsWith("#") ? !1 : section2 === "inputs" || section2 === "outputs" || item.visibility !== "private", readMembers = (componentData, key) => componentData[key] || [], isDirectiveEntry = (componentData) => componentData.type === "component" || componentData.type === "directive", getModelProperties = (componentData) => {
|
|
175
211
|
if (!isDirectiveEntry(componentData))
|
|
176
212
|
return [];
|
|
177
213
|
let inputsByName = new Map(componentData.inputsClass.map((item) => [item.name, item]));
|
|
@@ -179,22 +215,26 @@ var __filename = CJS_COMPAT_NODE_URL_ctyo0js0zv6.fileURLToPath(import.meta.url),
|
|
|
179
215
|
let input = inputsByName.get(item.name);
|
|
180
216
|
return input?.line !== void 0 && input.line === item.line;
|
|
181
217
|
});
|
|
182
|
-
}, extractArgTypesFromData = (componentData, { metadataJson,
|
|
183
|
-
let sectionToItems = {}, componentClasses =
|
|
218
|
+
}, extractArgTypesFromData = (componentData, { metadataJson, propsTable, logger: logger42 = NOOP_LOGGER }) => {
|
|
219
|
+
let sectionToItems = {}, componentClasses = propsTable === "inputs" ? ["inputsClass"] : ["propertiesClass", "methodsClass", "inputsClass", "outputsClass"], memberKeys = isDirectiveEntry(componentData) ? componentClasses : ["properties", "methods"], modelProperties = getModelProperties(componentData), modelPropertyNames = new Set(modelProperties.map((item) => item.name));
|
|
184
220
|
memberKeys.forEach((key) => {
|
|
185
221
|
readMembers(componentData, key).forEach((item) => {
|
|
186
|
-
|
|
187
|
-
return;
|
|
188
|
-
let section = mapItemToSection(key, item);
|
|
222
|
+
let section2 = mapItemToSection(key, item);
|
|
189
223
|
if (key === "outputsClass" && !isMethod(item) && modelPropertyNames.has(item.name))
|
|
190
224
|
return;
|
|
191
|
-
|
|
225
|
+
if (!documentedInMode(item, section2, propsTable)) {
|
|
226
|
+
logger42.debug(
|
|
227
|
+
`${componentData.name}.${item.name} left out of the props table: propsTable '${propsTable}'`
|
|
228
|
+
);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
let defaultValue = isMethod(item) ? void 0 : extractDefaultValue(item, logger42), type = isMethod(item) || section2 !== "inputs" && section2 !== "properties" ? { name: "other", value: "void" } : extractType(item, defaultValue, metadataJson, componentData.file), action = section2 === "outputs" ? { action: item.name } : {}, jsDocTags = extractMemberJsDocTags(item), argType = {
|
|
192
232
|
name: item.name,
|
|
193
233
|
description: item.rawdescription || item.description,
|
|
194
234
|
type,
|
|
195
235
|
...action,
|
|
196
236
|
table: {
|
|
197
|
-
category:
|
|
237
|
+
category: section2,
|
|
198
238
|
...jsDocTags !== void 0 ? { jsDocTags } : {},
|
|
199
239
|
type: {
|
|
200
240
|
summary: isMethod(item) ? displaySignature(item) : item.type,
|
|
@@ -203,9 +243,9 @@ var __filename = CJS_COMPAT_NODE_URL_ctyo0js0zv6.fileURLToPath(import.meta.url),
|
|
|
203
243
|
defaultValue: { summary: defaultValue }
|
|
204
244
|
}
|
|
205
245
|
};
|
|
206
|
-
sectionToItems[
|
|
246
|
+
sectionToItems[section2] || (sectionToItems[section2] = []), sectionToItems[section2].push(argType);
|
|
207
247
|
});
|
|
208
|
-
}), modelProperties.forEach((item) => {
|
|
248
|
+
}), modelProperties.filter((item) => documentedInMode(item, "inputs", propsTable)).forEach((item) => {
|
|
209
249
|
let changeName = `${item.name}Change`, argType = {
|
|
210
250
|
name: changeName,
|
|
211
251
|
description: item.rawdescription || item.description,
|
|
@@ -222,20 +262,26 @@ var __filename = CJS_COMPAT_NODE_URL_ctyo0js0zv6.fileURLToPath(import.meta.url),
|
|
|
222
262
|
sectionToItems.outputs || (sectionToItems.outputs = []), sectionToItems.outputs.push(argType);
|
|
223
263
|
});
|
|
224
264
|
let argTypes = {};
|
|
225
|
-
return SECTION_ORDER.forEach((
|
|
226
|
-
let items = sectionToItems[
|
|
265
|
+
return SECTION_ORDER.forEach((section2) => {
|
|
266
|
+
let items = sectionToItems[section2];
|
|
227
267
|
items && items.forEach((argType) => {
|
|
228
268
|
argTypes[argType.name] = argType;
|
|
229
269
|
});
|
|
230
270
|
}), argTypes;
|
|
271
|
+
}, resolvedSymbol = (ctx, node) => {
|
|
272
|
+
let symbol = ctx.checker.getSymbolAtLocation(node);
|
|
273
|
+
return symbol && symbol.flags & ctx.ts.SymbolFlags.Alias ? ctx.checker.getAliasedSymbol(symbol) : symbol;
|
|
231
274
|
}, isAngularCoreOrUnresolved = (ctx, node) => {
|
|
232
|
-
let
|
|
275
|
+
let symbol = resolvedSymbol(ctx, node);
|
|
233
276
|
if (!symbol)
|
|
234
277
|
return !0;
|
|
235
|
-
let declarations =
|
|
278
|
+
let declarations = symbol.declarations;
|
|
236
279
|
return declarations?.length ? declarations.some(
|
|
237
280
|
(declaration) => declaration.getSourceFile().fileName.includes("@angular/core")
|
|
238
281
|
) : !0;
|
|
282
|
+
}, importedName = (ctx, target) => {
|
|
283
|
+
let symbol = resolvedSymbol(ctx, target);
|
|
284
|
+
return symbol?.declarations?.length ? symbol.name : ctx.ts.isIdentifier(target) ? ctx.checker.getSymbolAtLocation(target)?.declarations?.find(ctx.ts.isImportSpecifier)?.propertyName?.text ?? target.text : target.name.text;
|
|
239
285
|
}, getDecorators = (ctx, node) => {
|
|
240
286
|
let { ts } = ctx;
|
|
241
287
|
if (!ts.canHaveDecorators(node))
|
|
@@ -245,7 +291,7 @@ var __filename = CJS_COMPAT_NODE_URL_ctyo0js0zv6.fileURLToPath(import.meta.url),
|
|
|
245
291
|
let expression = decorator.expression, call = ts.isCallExpression(expression) ? expression : void 0, target = call ? call.expression : expression;
|
|
246
292
|
if (!isAngularCoreOrUnresolved(ctx, target))
|
|
247
293
|
continue;
|
|
248
|
-
let name = ts.isIdentifier(target)
|
|
294
|
+
let name = ts.isIdentifier(target) || ts.isPropertyAccessExpression(target) ? importedName(ctx, target) : target.getText();
|
|
249
295
|
decorators.push({ name, call });
|
|
250
296
|
}
|
|
251
297
|
return decorators;
|
|
@@ -275,10 +321,11 @@ var __filename = CJS_COMPAT_NODE_URL_ctyo0js0zv6.fileURLToPath(import.meta.url),
|
|
|
275
321
|
let options = objectArgOf(ctx, decorator.call);
|
|
276
322
|
if (!options)
|
|
277
323
|
return {};
|
|
278
|
-
let alias = stringOption(ctx, options, "alias"), required = booleanOption(ctx, options, "required");
|
|
324
|
+
let alias = stringOption(ctx, options, "alias"), required = booleanOption(ctx, options, "required"), transform = objectProperty(ctx, options, "transform");
|
|
279
325
|
return {
|
|
280
326
|
...alias === void 0 ? {} : { alias },
|
|
281
|
-
...required === void 0 ? {} : { required }
|
|
327
|
+
...required === void 0 ? {} : { required },
|
|
328
|
+
...transform === void 0 ? {} : { transform }
|
|
282
329
|
};
|
|
283
330
|
}, readMetadataInputsOutputs = (ctx, classNode, decoratorName) => {
|
|
284
331
|
let { ts } = ctx, metadata = decoratorObjectArg(ctx, classNode, decoratorName);
|
|
@@ -309,22 +356,105 @@ var __filename = CJS_COMPAT_NODE_URL_ctyo0js0zv6.fileURLToPath(import.meta.url),
|
|
|
309
356
|
}
|
|
310
357
|
}
|
|
311
358
|
return entries;
|
|
359
|
+
}, unwrapInitializer = (ts, expression) => {
|
|
360
|
+
let unwrapped = expression;
|
|
361
|
+
for (; ts.isParenthesizedExpression(unwrapped) || ts.isAsExpression(unwrapped) || ts.isSatisfiesExpression(unwrapped) || ts.isTypeAssertionExpression(unwrapped) || ts.isNonNullExpression(unwrapped); )
|
|
362
|
+
unwrapped = unwrapped.expression;
|
|
363
|
+
return unwrapped;
|
|
364
|
+
}, isEnumMemberAccess = (ctx, expression) => {
|
|
365
|
+
let resolved = resolvedSymbol(ctx, expression.name);
|
|
366
|
+
return !!(resolved && resolved.flags & ctx.ts.SymbolFlags.EnumMember);
|
|
367
|
+
}, literalKind = (ctx, expression) => {
|
|
368
|
+
let { ts } = ctx, value = unwrapInitializer(ts, expression);
|
|
369
|
+
if (ts.isStringLiteral(value) || ts.isNoSubstitutionTemplateLiteral(value))
|
|
370
|
+
return "string";
|
|
371
|
+
if (ts.isNumericLiteral(value))
|
|
372
|
+
return "number";
|
|
373
|
+
if (ts.isBigIntLiteral(value))
|
|
374
|
+
return "bigint";
|
|
375
|
+
if (value.kind === ts.SyntaxKind.TrueKeyword || value.kind === ts.SyntaxKind.FalseKeyword)
|
|
376
|
+
return "boolean";
|
|
377
|
+
if (value.kind === ts.SyntaxKind.NullKeyword)
|
|
378
|
+
return "null";
|
|
379
|
+
if (ts.isIdentifier(value) && value.text === "undefined" && ctx.checker.getTypeAtLocation(value).flags & ts.TypeFlags.Undefined) {
|
|
380
|
+
let symbol = ctx.checker.getSymbolAtLocation(value);
|
|
381
|
+
if (!symbol?.valueDeclaration && (symbol?.declarations?.length ?? 0) === 0)
|
|
382
|
+
return "undefined";
|
|
383
|
+
}
|
|
384
|
+
if (ts.isPrefixUnaryExpression(value))
|
|
385
|
+
return (value.operator === ts.SyntaxKind.PlusToken || value.operator === ts.SyntaxKind.MinusToken) && ts.isNumericLiteral(value.operand) ? "number" : value.operator === ts.SyntaxKind.MinusToken && ts.isBigIntLiteral(value.operand) ? "bigint" : void 0;
|
|
386
|
+
if (ts.isPropertyAccessExpression(value))
|
|
387
|
+
return isEnumMemberAccess(ctx, value) ? "enum" : void 0;
|
|
388
|
+
if (ts.isArrayLiteralExpression(value))
|
|
389
|
+
return value.elements.every(
|
|
390
|
+
(element) => !ts.isSpreadElement(element) && !ts.isOmittedExpression(element) && literalKind(ctx, element) !== void 0
|
|
391
|
+
) ? "composite" : void 0;
|
|
392
|
+
if (ts.isObjectLiteralExpression(value))
|
|
393
|
+
return value.properties.every(
|
|
394
|
+
(property) => ts.isPropertyAssignment(property) && !ts.isComputedPropertyName(property.name) && literalKind(ctx, property.initializer) !== void 0
|
|
395
|
+
) ? "composite" : void 0;
|
|
396
|
+
}, defaultInitializer = (ctx, expression) => {
|
|
397
|
+
let unwrapped = unwrapInitializer(ctx.ts, expression), kind = literalKind(ctx, unwrapped);
|
|
398
|
+
return kind ? { kind: "literal", literalKind: kind, text: unwrapped.getText() } : { kind: "expression", text: expression.getText() };
|
|
399
|
+
}, analyzeInputTransform = (ctx, transform) => {
|
|
400
|
+
let { checker, ts } = ctx, signatures = checker.getTypeAtLocation(transform).getCallSignatures(), signature = signatures[signatures.length - 1], parameter = signature?.getParameters()[0], parameterType = parameter && checker.getTypeOfSymbolAtLocation(parameter, transform);
|
|
401
|
+
if (!parameterType || parameterType.flags & (ts.TypeFlags.Unknown | ts.TypeFlags.Any))
|
|
402
|
+
return;
|
|
403
|
+
let declaration = parameter?.valueDeclaration, node = declaration && ts.isParameter(declaration) ? declaration.type : void 0, unwrappedTransform = transform;
|
|
404
|
+
for (; ts.isParenthesizedExpression(unwrappedTransform) || ts.isSatisfiesExpression(unwrappedTransform) || ts.isNonNullExpression(unwrappedTransform); )
|
|
405
|
+
unwrappedTransform = unwrappedTransform.expression;
|
|
406
|
+
let typeArguments = ts.isCallExpression(unwrappedTransform) || ts.isExpressionWithTypeArguments(unwrappedTransform) ? unwrappedTransform.typeArguments : void 0, substitutions = /* @__PURE__ */ new Map(), typeParameters = ((ts.isCallExpression(unwrappedTransform) ? checker.getResolvedSignature(unwrappedTransform) : signature)?.declaration?.typeParameters ?? []).filter(
|
|
407
|
+
ts.isTypeParameterDeclaration
|
|
408
|
+
);
|
|
409
|
+
for (let [index, typeParameter] of typeParameters.entries()) {
|
|
410
|
+
let symbol = checker.getSymbolAtLocation(typeParameter.name), argument = typeArguments?.[index];
|
|
411
|
+
symbol && argument && substitutions.set(symbol, argument);
|
|
412
|
+
}
|
|
413
|
+
return {
|
|
414
|
+
type: ctx.types.renderValueType(parameterType, transform),
|
|
415
|
+
source: {
|
|
416
|
+
kind: "transform",
|
|
417
|
+
checkerType: parameterType,
|
|
418
|
+
...node ? { node } : {},
|
|
419
|
+
...substitutions.size > 0 ? { substitutions } : {}
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
}, decorationStripped = (line) => line.match(/^[ \t]*\*(?!\*)[ \t]?(.*)$/)?.[1], indentWidth = (line) => line.match(/^[ \t]*/)[0].length, cleanCommentText = (raw) => {
|
|
423
|
+
let lines = raw.split(`
|
|
424
|
+
`).map((line) => line.replace(/\r$/, "")), undecorated = lines.slice(1).filter((line) => line.trim() !== "" && decorationStripped(line) === void 0), margin = undecorated.length === 0 ? 0 : Math.min(...undecorated.map(indentWidth)), cleaned = lines.map((line, index) => {
|
|
425
|
+
if (line.trim() === "")
|
|
426
|
+
return "";
|
|
427
|
+
let stripped = decorationStripped(line);
|
|
428
|
+
return stripped !== void 0 ? stripped : index === 0 ? line.replace(/^[ \t]+/, "") : line.slice(margin);
|
|
429
|
+
});
|
|
430
|
+
for (; cleaned.length > 0 && cleaned[0] === ""; )
|
|
431
|
+
cleaned.shift();
|
|
432
|
+
return cleaned.join(`
|
|
433
|
+
`);
|
|
434
|
+
}, rawJsDocComment = (sourceText, jsDoc) => {
|
|
435
|
+
let end = jsDoc.tags?.length ? jsDoc.tags[0].pos : jsDoc.end;
|
|
436
|
+
return sourceText.slice(jsDoc.pos, end).replace(/^\/\*\*/, "").replace(/\*\/$/, "");
|
|
437
|
+
}, rawTagComment = (ts, sourceText, tag) => {
|
|
438
|
+
let start;
|
|
439
|
+
return ts.isJSDocSeeTag(tag) && tag.name ? start = tag.name.pos : tag.comment !== void 0 && (start = typeof tag.comment == "string" ? tag.getChildren().at(-1)?.end : tag.comment.pos, start ??= tag.tagName.end), start === void 0 ? void 0 : cleanCommentText(sourceText.slice(start, tag.end)).trimEnd();
|
|
312
440
|
};
|
|
313
441
|
function getJsDocDescription(ts, node) {
|
|
314
|
-
let
|
|
442
|
+
let sourceText = node.getSourceFile().text, jsDoc = ts.getJSDocCommentsAndTags(node).filter((doc) => ts.isJSDoc(doc)).at(-1), text = jsDoc?.comment === void 0 ? void 0 : cleanCommentText(rawJsDocComment(sourceText, jsDoc));
|
|
315
443
|
text = text?.replace(/^(?:[ \t]*\*+[ \t]*\n)+/, "").replace(/^[ \t]*\*+[ \t]*$/, "");
|
|
316
444
|
let descriptionTag = ts.getJSDocTags(node).find((tag) => tag.tagName.text === "description" && tag.comment !== void 0);
|
|
317
|
-
descriptionTag && (text =
|
|
445
|
+
descriptionTag && (text = cleanCommentText(sourceText.slice(descriptionTag.tagName.end, descriptionTag.end)));
|
|
318
446
|
let trimmed = text?.replace(/\s+$/, "");
|
|
319
447
|
return trimmed ? { description: trimmed, rawdescription: trimmed } : {};
|
|
320
448
|
}
|
|
321
449
|
function getJsDocTags(ts, node) {
|
|
322
450
|
let tags = ts.getJSDocTags(node);
|
|
323
|
-
if (tags.length
|
|
324
|
-
return
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
451
|
+
if (tags.length === 0)
|
|
452
|
+
return;
|
|
453
|
+
let sourceText = node.getSourceFile().text;
|
|
454
|
+
return tags.map((tag) => {
|
|
455
|
+
let name = tag.tagName.text, comment = rawTagComment(ts, sourceText, tag);
|
|
456
|
+
return { tagName: { text: name, escapedText: name }, ...comment === void 0 ? {} : { comment } };
|
|
457
|
+
});
|
|
328
458
|
}
|
|
329
459
|
function getJsDocTagsField(ts, node) {
|
|
330
460
|
let tags = getJsDocTags(ts, node);
|
|
@@ -333,136 +463,7 @@ function getJsDocTagsField(ts, node) {
|
|
|
333
463
|
function hasJsDocTag(ts, node, tagName) {
|
|
334
464
|
return ts.getJSDocTags(node).some((tag) => tag.tagName.text === tagName);
|
|
335
465
|
}
|
|
336
|
-
var memberName = (ts, name) => ts.isComputedPropertyName(name) ? name.getText() : name.text,
|
|
337
|
-
constructor(ts, checker) {
|
|
338
|
-
this.ts = ts, this.checker = checker, this.typealiases = /* @__PURE__ */ new Map(), this.enumerations = /* @__PURE__ */ new Map(), this.aliasCycleGuard = /* @__PURE__ */ new Set();
|
|
339
|
-
}
|
|
340
|
-
/**
|
|
341
|
-
* Render a type node to the spelling the props table shows.
|
|
342
|
-
*
|
|
343
|
-
* Syntactic on purpose, to match the spellings the argTypes extractor depends on: string
|
|
344
|
-
* literals double-quoted, unions joined with ` | `.
|
|
345
|
-
*/
|
|
346
|
-
render(typeNode) {
|
|
347
|
-
let { ts } = this;
|
|
348
|
-
if (ts.isLiteralTypeNode(typeNode)) {
|
|
349
|
-
let { literal } = typeNode;
|
|
350
|
-
return ts.isStringLiteral(literal) || ts.isNoSubstitutionTemplateLiteral(literal) ? JSON.stringify(literal.text) : literal.getText();
|
|
351
|
-
}
|
|
352
|
-
if (ts.isUnionTypeNode(typeNode))
|
|
353
|
-
return typeNode.types.map((type) => this.render(type)).join(" | ");
|
|
354
|
-
if (ts.isIntersectionTypeNode(typeNode))
|
|
355
|
-
return typeNode.types.map((type) => this.render(type)).join(" & ");
|
|
356
|
-
if (ts.isArrayTypeNode(typeNode))
|
|
357
|
-
return `${this.render(typeNode.elementType)}[]`;
|
|
358
|
-
if (ts.isTupleTypeNode(typeNode))
|
|
359
|
-
return `[${typeNode.elements.map((element) => this.render(element)).join(", ")}]`;
|
|
360
|
-
if (ts.isParenthesizedTypeNode(typeNode))
|
|
361
|
-
return `(${this.render(typeNode.type)})`;
|
|
362
|
-
if (ts.isFunctionTypeNode(typeNode) || ts.isConstructorTypeNode(typeNode)) {
|
|
363
|
-
let typeParameters = typeNode.typeParameters?.length ? `<${typeNode.typeParameters.map((parameter) => parameter.getText()).join(", ")}>` : "", parameters = typeNode.parameters.map((parameter) => {
|
|
364
|
-
let name = parameter.name.getText(), rest = parameter.dotDotDotToken ? "..." : "", optional = parameter.questionToken ? "?" : "", type = parameter.type ? this.render(parameter.type) : "any";
|
|
365
|
-
return `${rest}${name}${optional}: ${type}`;
|
|
366
|
-
}).join(", ");
|
|
367
|
-
return `${ts.isConstructorTypeNode(typeNode) ? "new " : ""}${typeParameters}(${parameters}) => ${this.render(typeNode.type)}`;
|
|
368
|
-
}
|
|
369
|
-
if (ts.isTypeOperatorNode(typeNode))
|
|
370
|
-
return `${typeNode.operator === ts.SyntaxKind.KeyOfKeyword ? "keyof" : typeNode.operator === ts.SyntaxKind.ReadonlyKeyword ? "readonly" : "unique"} ${this.render(typeNode.type)}`;
|
|
371
|
-
if (ts.isIndexedAccessTypeNode(typeNode))
|
|
372
|
-
return `${this.render(typeNode.objectType)}[${this.render(typeNode.indexType)}]`;
|
|
373
|
-
if (ts.isTypeReferenceNode(typeNode)) {
|
|
374
|
-
let name = typeNode.typeName.getText(), symbol = this.checker.getSymbolAtLocation(typeNode.typeName);
|
|
375
|
-
symbol && this.addFromSymbol(symbol, name);
|
|
376
|
-
let args = typeNode.typeArguments?.length ? `<${typeNode.typeArguments.map((arg) => this.render(arg)).join(", ")}>` : "";
|
|
377
|
-
return `${name}${args}`;
|
|
378
|
-
}
|
|
379
|
-
return collapseWhitespace(typeNode.getText());
|
|
380
|
-
}
|
|
381
|
-
/** Widen and render a declaration's inferred type, as the legacy pipeline did (`'v1'` to `string`). */
|
|
382
|
-
infer(node) {
|
|
383
|
-
let { checker, ts } = this;
|
|
384
|
-
if (!node.name)
|
|
385
|
-
return;
|
|
386
|
-
let symbol = checker.getSymbolAtLocation(node.name);
|
|
387
|
-
if (!symbol)
|
|
388
|
-
return;
|
|
389
|
-
let type = checker.getBaseTypeOfLiteralType(checker.getTypeOfSymbolAtLocation(symbol, node));
|
|
390
|
-
return this.addFromType(type), stripImportQualifiers(checker.typeToString(type, node, ts.TypeFormatFlags.NoTruncation));
|
|
391
|
-
}
|
|
392
|
-
// Checker-derived types have no TypeNode to walk, so the type's own symbol and each union
|
|
393
|
-
// constituent's are fed in directly.
|
|
394
|
-
addFromType(type) {
|
|
395
|
-
let feed = (candidate) => {
|
|
396
|
-
let symbol = candidate.aliasSymbol ?? candidate.getSymbol();
|
|
397
|
-
symbol && this.addFromSymbol(symbol);
|
|
398
|
-
};
|
|
399
|
-
if (feed(type), type.isUnion())
|
|
400
|
-
for (let constituent of type.types)
|
|
401
|
-
feed(constituent);
|
|
402
|
-
}
|
|
403
|
-
addDeclaration(declaration, referencedAs) {
|
|
404
|
-
declaration.getSourceFile().isDeclarationFile || (this.ts.isEnumDeclaration(declaration) ? this.addEnum(declaration, referencedAs ?? declaration.name.text) : this.ts.isTypeAliasDeclaration(declaration) && this.addTypeAlias(declaration, referencedAs ?? declaration.name.text));
|
|
405
|
-
}
|
|
406
|
-
toMiscellaneous() {
|
|
407
|
-
let byName = (a, b) => a.name.localeCompare(b.name);
|
|
408
|
-
return {
|
|
409
|
-
typealiases: [...this.typealiases.values()].sort(byName),
|
|
410
|
-
enumerations: [...this.enumerations.values()].sort(byName)
|
|
411
|
-
};
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* `referencedAs` is the spelling {@link render} produced, which an import rename makes differ from
|
|
415
|
-
* the declaration's own name.
|
|
416
|
-
*/
|
|
417
|
-
addFromSymbol(symbol, referencedAs) {
|
|
418
|
-
let target = symbol.flags & this.ts.SymbolFlags.Alias ? this.checker.getAliasedSymbol(symbol) : symbol;
|
|
419
|
-
for (let declaration of target.declarations ?? [])
|
|
420
|
-
this.addDeclaration(declaration, referencedAs);
|
|
421
|
-
}
|
|
422
|
-
addEnum(declaration, name) {
|
|
423
|
-
if (this.enumerations.has(name))
|
|
424
|
-
return;
|
|
425
|
-
let childs = declaration.members.map((member) => {
|
|
426
|
-
let value = this.enumMemberValue(member.initializer);
|
|
427
|
-
return {
|
|
428
|
-
name: memberName(this.ts, member.name),
|
|
429
|
-
...value === void 0 ? {} : { value }
|
|
430
|
-
};
|
|
431
|
-
});
|
|
432
|
-
this.enumerations.set(name, {
|
|
433
|
-
name,
|
|
434
|
-
childs,
|
|
435
|
-
ctype: "miscellaneous",
|
|
436
|
-
subtype: "enum",
|
|
437
|
-
file: declaration.getSourceFile().fileName
|
|
438
|
-
});
|
|
439
|
-
}
|
|
440
|
-
addTypeAlias(declaration, name) {
|
|
441
|
-
if (this.typealiases.has(name) || this.aliasCycleGuard.has(name))
|
|
442
|
-
return;
|
|
443
|
-
this.aliasCycleGuard.add(name);
|
|
444
|
-
let rawtype = this.render(declaration.type);
|
|
445
|
-
this.aliasCycleGuard.delete(name), this.typealiases.set(name, {
|
|
446
|
-
name,
|
|
447
|
-
ctype: "miscellaneous",
|
|
448
|
-
subtype: "typealias",
|
|
449
|
-
rawtype,
|
|
450
|
-
file: declaration.getSourceFile().fileName,
|
|
451
|
-
kind: declaration.type.kind
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
// Numeric initializers stay numbers, so a `0` member is falsy and correctly disables the
|
|
455
|
-
// extractor's enum path.
|
|
456
|
-
enumMemberValue(initializer) {
|
|
457
|
-
let { ts } = this;
|
|
458
|
-
if (initializer) {
|
|
459
|
-
if (ts.isStringLiteral(initializer) || ts.isNoSubstitutionTemplateLiteral(initializer))
|
|
460
|
-
return initializer.text;
|
|
461
|
-
if (ts.isNumericLiteral(initializer))
|
|
462
|
-
return Number(initializer.text);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
}, SIGNAL_INPUT_NAMES = /* @__PURE__ */ new Set(["input", "model"]), SIGNAL_NAMES = /* @__PURE__ */ new Set(["input", "output", "model"]), SIGNAL_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
466
|
+
var memberName = (ts, name) => ts.isComputedPropertyName(name) ? name.getText() : name.text, SIGNAL_INPUT_NAMES = /* @__PURE__ */ new Set(["input", "model"]), SIGNAL_NAMES = /* @__PURE__ */ new Set(["input", "output", "model"]), SIGNAL_TYPE_NAMES = /* @__PURE__ */ new Set([
|
|
466
467
|
"InputSignal",
|
|
467
468
|
"InputSignalWithTransform",
|
|
468
469
|
"ModelSignal",
|
|
@@ -484,7 +485,7 @@ var memberName = (ts, name) => ts.isComputedPropertyName(name) ? name.getText()
|
|
|
484
485
|
if (isAngularCoreOrUnresolved(ctx, base))
|
|
485
486
|
return { kind: base.text, required, call: initializer };
|
|
486
487
|
}, buildSignalEntry = (ctx, member, signal) => {
|
|
487
|
-
let { ts } = ctx, { call } = signal, hasValueArgument = !signal.required && signal.kind !== "output", valueArgument = hasValueArgument ? call.arguments[0] : void 0, optionsArgument = hasValueArgument ? call.arguments[1] : call.arguments[0], alias = optionsArgument && ts.isObjectLiteralExpression(optionsArgument) ? stringOption(ctx, optionsArgument, "alias") : void 0,
|
|
488
|
+
let { ts } = ctx, { call } = signal, hasValueArgument = !signal.required && signal.kind !== "output", valueArgument = hasValueArgument ? call.arguments[0] : void 0, optionsArgument = hasValueArgument ? call.arguments[1] : call.arguments[0], alias = optionsArgument && ts.isObjectLiteralExpression(optionsArgument) ? stringOption(ctx, optionsArgument, "alias") : void 0, writeTypeArgument = signal.kind === "input" && call.typeArguments?.length === 2 ? call.typeArguments[1] : void 0, explicitTypeArgument = writeTypeArgument !== void 0 && writeTypeArgument.kind !== ts.SyntaxKind.UnknownKeyword && writeTypeArgument.kind !== ts.SyntaxKind.AnyKeyword ? writeTypeArgument : call.typeArguments?.[0], type = (explicitTypeArgument ? ctx.types.render(explicitTypeArgument) : void 0) ?? signalValueTypeFromChecker(ctx, member) ?? (valueArgument ? literalTypeName(ctx, valueArgument) : void 0);
|
|
488
489
|
return {
|
|
489
490
|
name: alias ?? memberName(ctx.ts, member.name),
|
|
490
491
|
...type === void 0 ? {} : { type },
|
|
@@ -493,21 +494,21 @@ var memberName = (ts, name) => ts.isComputedPropertyName(name) ? name.getText()
|
|
|
493
494
|
// Downstream tells a `model()` apart from an `@Input('x')`/`@Output('x')` alias collision by
|
|
494
495
|
// the same name appearing in both arrays on the same declaration line.
|
|
495
496
|
line: ts.getLineAndCharacterOfPosition(member.getSourceFile(), member.getStart()).line + 1,
|
|
496
|
-
...valueArgument ? {
|
|
497
|
+
...valueArgument ? { initializer: defaultInitializer(ctx, valueArgument) } : {},
|
|
497
498
|
...getJsDocDescription(ts, member),
|
|
498
499
|
...getJsDocTagsField(ts, member)
|
|
499
500
|
};
|
|
500
|
-
}, signalValueTypeFromChecker = (ctx, member) => {
|
|
501
|
-
let { checker, ts } = ctx,
|
|
501
|
+
}, signalValueTypeFromChecker = (ctx, member) => signalValueTypeFromType(ctx, ctx.checker.getTypeAtLocation(member), member), signalValueTypeFromType = (ctx, type, node) => {
|
|
502
|
+
let { checker, ts } = ctx, symbolName = type.aliasSymbol?.name ?? type.getSymbol()?.name;
|
|
502
503
|
if (!symbolName || !SIGNAL_TYPE_NAMES.has(symbolName) || !(type.flags & ts.TypeFlags.Object && type.objectFlags & ts.ObjectFlags.Reference))
|
|
503
504
|
return;
|
|
504
|
-
let
|
|
505
|
-
if (
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
505
|
+
let typeArguments = checker.getTypeArguments(type), valueType = typeArguments[0];
|
|
506
|
+
if (symbolName === "InputSignalWithTransform") {
|
|
507
|
+
let writeType = typeArguments[1];
|
|
508
|
+
writeType && !(writeType.flags & (ts.TypeFlags.Unknown | ts.TypeFlags.Any)) && (valueType = writeType);
|
|
509
|
+
}
|
|
510
|
+
if (valueType)
|
|
511
|
+
return ctx.types.renderValueType(valueType, node);
|
|
511
512
|
}, literalTypeName = (ctx, expression) => {
|
|
512
513
|
let { ts } = ctx;
|
|
513
514
|
if (ts.isStringLiteralLike(expression))
|
|
@@ -516,21 +517,28 @@ var memberName = (ts, name) => ts.isComputedPropertyName(name) ? name.getText()
|
|
|
516
517
|
return "number";
|
|
517
518
|
if (expression.kind === ts.SyntaxKind.TrueKeyword || expression.kind === ts.SyntaxKind.FalseKeyword)
|
|
518
519
|
return "boolean";
|
|
519
|
-
},
|
|
520
|
+
}, sameMemberIdentity = (left, right) => left.declName === right.declName && left.isStatic === right.isStatic, owningClassName = (node) => {
|
|
520
521
|
let candidate = node.parent;
|
|
521
522
|
for (; candidate && !("members" in candidate); )
|
|
522
523
|
candidate = candidate.parent;
|
|
523
524
|
return candidate?.name?.text ?? "an anonymous class";
|
|
524
525
|
}, dropped = (node, name, reason) => {
|
|
525
526
|
logger.debug(`[angular-cm] ${owningClassName(node)}.${name} left out of docgen: ${reason}`);
|
|
526
|
-
}
|
|
527
|
-
function visitClassMembers(ctx, classNode) {
|
|
527
|
+
}, ANGULAR_GENERATED_STATIC = /^(ngAcceptInputType_|ɵ)/;
|
|
528
|
+
function visitClassMembers(ctx, classNode, kind) {
|
|
528
529
|
let { ts } = ctx, members = { inputs: [], outputs: [], properties: [], methods: [] }, visitedAccessors = /* @__PURE__ */ new Set();
|
|
529
530
|
for (let member of classNode.members) {
|
|
530
531
|
if (hasJsDocTag(ts, member, "ignore")) {
|
|
531
532
|
dropped(member, member.name ? memberName(ts, member.name) : "<unnamed>", "tagged @ignore");
|
|
532
533
|
continue;
|
|
533
534
|
}
|
|
535
|
+
if (isStatic(ctx, member)) {
|
|
536
|
+
let staticName = member.name ? memberName(ts, member.name) : "<unnamed>";
|
|
537
|
+
if (kind === "component" || kind === "directive" || ANGULAR_GENERATED_STATIC.test(staticName)) {
|
|
538
|
+
dropped(member, staticName, "a static member");
|
|
539
|
+
continue;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
534
542
|
ts.isConstructorDeclaration(member) ? visitConstructorProperties(ctx, member, members) : ts.isPropertyDeclaration(member) ? visitProperty(ctx, member, members) : ts.isMethodDeclaration(member) ? isPreferredMethodDeclaration(ctx, classNode, member) && members.methods.push(entryFor(ctx, member, visitMethod(ctx, member))) : (ts.isGetAccessor(member) || ts.isSetAccessor(member)) && visitAccessorPair(ctx, classNode, member, members, visitedAccessors);
|
|
535
543
|
}
|
|
536
544
|
return members;
|
|
@@ -556,14 +564,17 @@ function applyMetadataInputsOutputs(ctx, classNode, members) {
|
|
|
556
564
|
}) : members.outputs.push(renamed);
|
|
557
565
|
}
|
|
558
566
|
}
|
|
559
|
-
var entryFor = (ctx, member, value) => ({
|
|
567
|
+
var entryFor = (ctx, member, value, typeSource) => ({
|
|
560
568
|
declName: memberName(ctx.ts, member.name),
|
|
561
569
|
isStatic: isStatic(ctx, member),
|
|
570
|
+
declaration: member,
|
|
571
|
+
...typeSource ? { typeSource } : {},
|
|
562
572
|
value
|
|
563
573
|
}), visitProperty = (ctx, member, members) => {
|
|
564
574
|
let decorators = getDecorators(ctx, member), inputDecorator = decorators.find((decorator) => decorator.name === "Input");
|
|
565
575
|
if (inputDecorator) {
|
|
566
|
-
|
|
576
|
+
let input = buildDecoratorInput(ctx, member, inputDecorator);
|
|
577
|
+
members.inputs.push(entryFor(ctx, member, input.value, input.typeSource));
|
|
567
578
|
return;
|
|
568
579
|
}
|
|
569
580
|
let outputDecorator = decorators.find((decorator) => decorator.name === "Output");
|
|
@@ -573,28 +584,41 @@ var entryFor = (ctx, member, value) => ({
|
|
|
573
584
|
}
|
|
574
585
|
let signal = parseSignalCall(ctx, member);
|
|
575
586
|
if (signal) {
|
|
576
|
-
let entry = entryFor(
|
|
587
|
+
let entry = entryFor(
|
|
588
|
+
ctx,
|
|
589
|
+
member,
|
|
590
|
+
{
|
|
591
|
+
...buildSignalEntry(ctx, member, signal),
|
|
592
|
+
...memberApiFields(ctx, member)
|
|
593
|
+
},
|
|
594
|
+
{ kind: "signal", signalKind: signal.kind }
|
|
595
|
+
);
|
|
577
596
|
signal.kind !== "output" && members.inputs.push(entry), signal.kind !== "input" && members.outputs.push(entry);
|
|
578
597
|
return;
|
|
579
598
|
}
|
|
580
599
|
members.properties.push(entryFor(ctx, member, buildPlainProperty(ctx, member, decorators)));
|
|
581
600
|
}, buildDecoratorInput = (ctx, member, decorator) => {
|
|
582
|
-
let config = parseInputDecoratorConfig(ctx, decorator), type = typeOfPropertyish(ctx, member);
|
|
601
|
+
let config = parseInputDecoratorConfig(ctx, decorator), transform = config.transform ? analyzeInputTransform(ctx, config.transform) : void 0, type = transform?.type ?? typeOfPropertyish(ctx, member);
|
|
583
602
|
return {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
603
|
+
value: {
|
|
604
|
+
name: config.alias ?? memberName(ctx.ts, member.name),
|
|
605
|
+
...type === void 0 ? {} : { type },
|
|
606
|
+
optional: config.required !== void 0 ? !config.required : !!member.questionToken,
|
|
607
|
+
...config.required === void 0 ? {} : { required: config.required },
|
|
608
|
+
...member.initializer ? { initializer: defaultInitializer(ctx, member.initializer) } : {},
|
|
609
|
+
...memberApiFields(ctx, member),
|
|
610
|
+
...getJsDocDescription(ctx.ts, member),
|
|
611
|
+
...getJsDocTagsField(ctx.ts, member)
|
|
612
|
+
},
|
|
613
|
+
...transform ? { typeSource: transform.source } : {}
|
|
591
614
|
};
|
|
592
615
|
}, buildDecoratorOutput = (ctx, member, decorator) => {
|
|
593
616
|
let type = typeOfPropertyish(ctx, member);
|
|
594
617
|
return {
|
|
595
618
|
name: decoratorStringArg(ctx, decorator) ?? memberName(ctx.ts, member.name),
|
|
596
619
|
...type === void 0 ? {} : { type },
|
|
597
|
-
...member.initializer ? {
|
|
620
|
+
...member.initializer ? { initializer: defaultInitializer(ctx, member.initializer) } : {},
|
|
621
|
+
...memberApiFields(ctx, member),
|
|
598
622
|
...getJsDocDescription(ctx.ts, member),
|
|
599
623
|
...getJsDocTagsField(ctx.ts, member)
|
|
600
624
|
};
|
|
@@ -604,11 +628,25 @@ var entryFor = (ctx, member, value) => ({
|
|
|
604
628
|
name: memberName(ctx.ts, member.name),
|
|
605
629
|
...type === void 0 ? {} : { type },
|
|
606
630
|
optional: !!member.questionToken,
|
|
607
|
-
...member.initializer ? {
|
|
631
|
+
...member.initializer ? { initializer: defaultInitializer(ctx, member.initializer) } : {},
|
|
632
|
+
...memberApiFields(ctx, member),
|
|
608
633
|
...getJsDocDescription(ctx.ts, member),
|
|
609
634
|
...getJsDocTagsField(ctx.ts, member),
|
|
610
635
|
...names.length ? { decorators: names.map((name) => ({ name })) } : {}
|
|
611
636
|
};
|
|
637
|
+
}, accessibilityOf = (ctx, node) => {
|
|
638
|
+
for (let modifier of ctx.ts.getModifiers(node) ?? []) {
|
|
639
|
+
if (modifier.kind === ctx.ts.SyntaxKind.PrivateKeyword)
|
|
640
|
+
return "private";
|
|
641
|
+
if (modifier.kind === ctx.ts.SyntaxKind.ProtectedKeyword)
|
|
642
|
+
return "protected";
|
|
643
|
+
}
|
|
644
|
+
}, memberApiFields = (ctx, ...nodes) => {
|
|
645
|
+
let declared = nodes.filter((node) => node !== void 0), visibility = declared.map((node) => accessibilityOf(ctx, node)).find(Boolean);
|
|
646
|
+
return {
|
|
647
|
+
...visibility === void 0 ? {} : { visibility },
|
|
648
|
+
...declared.some((node) => hasJsDocTag(ctx.ts, node, "internal")) ? { internal: !0 } : {}
|
|
649
|
+
};
|
|
612
650
|
}, isStatic = (ctx, node) => (ctx.ts.getModifiers(node) ?? []).some(
|
|
613
651
|
(modifier) => modifier.kind === ctx.ts.SyntaxKind.StaticKeyword
|
|
614
652
|
), isSameMember = (ctx, a, b) => !!a.name && memberName(ctx.ts, a.name) === memberName(ctx.ts, b.name) && isStatic(ctx, a) === isStatic(ctx, b), isPreferredMethodDeclaration = (ctx, classNode, member) => {
|
|
@@ -626,69 +664,72 @@ var entryFor = (ctx, member, value) => ({
|
|
|
626
664
|
name: memberName(ctx.ts, member.name),
|
|
627
665
|
args,
|
|
628
666
|
returnType,
|
|
667
|
+
...memberApiFields(ctx, member),
|
|
629
668
|
...getJsDocDescription(ts, member),
|
|
630
669
|
...getJsDocTagsField(ts, member)
|
|
631
670
|
};
|
|
632
671
|
}, inferReturnType = (ctx, member) => {
|
|
633
672
|
let signature = ctx.checker.getSignatureFromDeclaration(member);
|
|
634
673
|
if (signature)
|
|
635
|
-
return
|
|
636
|
-
ctx.checker.typeToString(signature.getReturnType(), member, ctx.ts.TypeFormatFlags.NoTruncation)
|
|
637
|
-
);
|
|
674
|
+
return ctx.types.renderCheckerType(signature.getReturnType(), member);
|
|
638
675
|
}, visitConstructorProperties = (ctx, constructor, members) => {
|
|
639
676
|
let { ts } = ctx;
|
|
640
677
|
for (let parameter of constructor.parameters) {
|
|
641
|
-
|
|
642
|
-
(
|
|
643
|
-
)
|
|
644
|
-
(kind) => kind === ts.SyntaxKind.PrivateKeyword || kind === ts.SyntaxKind.ProtectedKeyword
|
|
645
|
-
);
|
|
646
|
-
if (!declaresField || isHidden) {
|
|
647
|
-
isHidden && dropped(constructor, parameter.name.getText(), "a private or protected parameter property");
|
|
678
|
+
if (!(ts.getModifiers(parameter) ?? []).some(
|
|
679
|
+
(modifier) => modifier.kind === ts.SyntaxKind.PublicKeyword || modifier.kind === ts.SyntaxKind.PrivateKeyword || modifier.kind === ts.SyntaxKind.ProtectedKeyword || modifier.kind === ts.SyntaxKind.ReadonlyKeyword
|
|
680
|
+
))
|
|
648
681
|
continue;
|
|
649
|
-
}
|
|
650
682
|
let type = parameter.type ? ctx.types.render(parameter.type) : ctx.types.infer(parameter);
|
|
651
683
|
members.properties.push({
|
|
652
684
|
declName: parameter.name.getText(),
|
|
653
685
|
isStatic: !1,
|
|
686
|
+
declaration: parameter,
|
|
654
687
|
value: {
|
|
655
688
|
name: parameter.name.getText(),
|
|
656
689
|
...type === void 0 ? {} : { type },
|
|
657
690
|
optional: !!parameter.questionToken,
|
|
658
|
-
...parameter.initializer ? {
|
|
691
|
+
...parameter.initializer ? { initializer: defaultInitializer(ctx, parameter.initializer) } : {},
|
|
692
|
+
...memberApiFields(ctx, parameter),
|
|
659
693
|
...getJsDocDescription(ts, parameter),
|
|
660
694
|
...getJsDocTagsField(ts, parameter)
|
|
661
695
|
}
|
|
662
696
|
});
|
|
663
697
|
}
|
|
664
698
|
}, visitAccessorPair = (ctx, classNode, member, members, visited) => {
|
|
665
|
-
let { ts } = ctx, name = memberName(ctx.ts, member.name)
|
|
666
|
-
if (visited.has(
|
|
699
|
+
let { ts } = ctx, name = memberName(ctx.ts, member.name);
|
|
700
|
+
if (visited.has(member))
|
|
667
701
|
return;
|
|
668
|
-
visited.add(visitKey);
|
|
669
702
|
let getter = classNode.members.find(
|
|
670
703
|
(candidate) => ts.isGetAccessor(candidate) && isSameMember(ctx, candidate, member)
|
|
671
704
|
), setter = classNode.members.find(
|
|
672
705
|
(candidate) => ts.isSetAccessor(candidate) && isSameMember(ctx, candidate, member)
|
|
673
|
-
)
|
|
706
|
+
);
|
|
707
|
+
getter && visited.add(getter), setter && visited.add(setter);
|
|
708
|
+
let typeNode = getter?.type ?? setter?.parameters[0]?.type, type = typeNode ? ctx.types.render(typeNode) : ctx.types.infer(getter ?? setter), getterDescription = getter ? getJsDocDescription(ts, getter) : {}, docSource = getterDescription.rawdescription !== void 0 || !setter ? getter : setter, description = docSource === getter ? getterDescription : getJsDocDescription(ts, setter), tags = docSource ? getJsDocTagsField(ts, docSource) : {}, decorators = [
|
|
674
709
|
...getter ? getDecorators(ctx, getter) : [],
|
|
675
710
|
...setter ? getDecorators(ctx, setter) : []
|
|
676
|
-
], accessorEntry = (value) => ({
|
|
711
|
+
], apiFields = memberApiFields(ctx, getter, setter), declaration = getter ?? setter, accessorEntry = (value, typeSource) => ({
|
|
677
712
|
declName: name,
|
|
678
|
-
isStatic: isStatic(ctx,
|
|
713
|
+
isStatic: isStatic(ctx, declaration),
|
|
714
|
+
declaration,
|
|
715
|
+
...typeSource ? { typeSource } : {},
|
|
679
716
|
value
|
|
680
717
|
}), inputDecorator = decorators.find((decorator) => decorator.name === "Input");
|
|
681
718
|
if (inputDecorator) {
|
|
682
|
-
let config = parseInputDecoratorConfig(ctx, inputDecorator);
|
|
719
|
+
let config = parseInputDecoratorConfig(ctx, inputDecorator), transform = config.transform ? analyzeInputTransform(ctx, config.transform) : void 0, inputType = transform?.type ?? type;
|
|
683
720
|
members.inputs.push(
|
|
684
|
-
accessorEntry(
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
721
|
+
accessorEntry(
|
|
722
|
+
{
|
|
723
|
+
name: config.alias ?? name,
|
|
724
|
+
...inputType === void 0 ? {} : { type: inputType },
|
|
725
|
+
optional: config.required !== void 0 ? !config.required : !1,
|
|
726
|
+
...config.required === void 0 ? {} : { required: config.required },
|
|
727
|
+
...apiFields,
|
|
728
|
+
...description,
|
|
729
|
+
...tags
|
|
730
|
+
},
|
|
731
|
+
transform?.source
|
|
732
|
+
)
|
|
692
733
|
);
|
|
693
734
|
return;
|
|
694
735
|
}
|
|
@@ -698,25 +739,19 @@ var entryFor = (ctx, member, value) => ({
|
|
|
698
739
|
accessorEntry({
|
|
699
740
|
name: decoratorStringArg(ctx, outputDecorator) ?? name,
|
|
700
741
|
...type === void 0 ? {} : { type },
|
|
742
|
+
...apiFields,
|
|
701
743
|
...description,
|
|
702
744
|
...tags
|
|
703
745
|
})
|
|
704
746
|
);
|
|
705
747
|
return;
|
|
706
748
|
}
|
|
707
|
-
if ([getter, setter].some(
|
|
708
|
-
(accessor) => (accessor ? ts.getModifiers(accessor) ?? [] : []).some(
|
|
709
|
-
(modifier) => modifier.kind === ts.SyntaxKind.PrivateKeyword || modifier.kind === ts.SyntaxKind.ProtectedKeyword
|
|
710
|
-
)
|
|
711
|
-
)) {
|
|
712
|
-
dropped(member, name, "an undecorated private or protected accessor");
|
|
713
|
-
return;
|
|
714
|
-
}
|
|
715
749
|
members.properties.push(
|
|
716
750
|
accessorEntry({
|
|
717
751
|
name,
|
|
718
752
|
...type === void 0 ? {} : { type },
|
|
719
753
|
optional: !1,
|
|
754
|
+
...apiFields,
|
|
720
755
|
...description,
|
|
721
756
|
...tags,
|
|
722
757
|
// The props table routes the view-child and content-child sections off this field, so an
|
|
@@ -725,11 +760,14 @@ var entryFor = (ctx, member, value) => ({
|
|
|
725
760
|
})
|
|
726
761
|
);
|
|
727
762
|
}, typeOfPropertyish = (ctx, member) => member.type ? ctx.types.render(member.type) : member.initializer && ctx.ts.isNewExpression(member.initializer) ? member.initializer.expression.getText() : ctx.types.infer(member);
|
|
728
|
-
function resolveClassMembers(ctx, classNode,
|
|
729
|
-
|
|
730
|
-
|
|
763
|
+
function resolveClassMembers(ctx, classNode, kind) {
|
|
764
|
+
return resolveWithBases(ctx, classNode, kind, /* @__PURE__ */ new Set([classNode]), /* @__PURE__ */ new Map());
|
|
765
|
+
}
|
|
766
|
+
function resolveWithBases(ctx, classNode, kind, visited, substitutions, instantiatedType) {
|
|
767
|
+
let members = visitClassMembers(ctx, classNode, kind);
|
|
768
|
+
return walkBases(ctx, classNode, members, kind, visited, substitutions), applyMetadataInputsOutputs(ctx, classNode, members), instantiatedType && instantiateMembers(ctx, instantiatedType, classNode, members, substitutions), members;
|
|
731
769
|
}
|
|
732
|
-
function walkBases(ctx, classNode, members, visited) {
|
|
770
|
+
function walkBases(ctx, classNode, members, kind, visited, substitutions) {
|
|
733
771
|
if (!classNode.name)
|
|
734
772
|
return;
|
|
735
773
|
let symbol = ctx.checker.getSymbolAtLocation(classNode.name), type = symbol && ctx.checker.getDeclaredTypeOfSymbol(symbol);
|
|
@@ -741,38 +779,169 @@ function walkBases(ctx, classNode, members, visited) {
|
|
|
741
779
|
if (!declaration || visited.has(declaration))
|
|
742
780
|
continue;
|
|
743
781
|
visited.add(declaration);
|
|
744
|
-
let
|
|
745
|
-
|
|
782
|
+
let inheritedSubstitutions = new Map(substitutions);
|
|
783
|
+
for (let [parameter, argument] of typeParameterSubstitutions(ctx, classNode, declaration))
|
|
784
|
+
inheritedSubstitutions.set(parameter, argument);
|
|
785
|
+
let baseMembers = resolveWithBases(
|
|
786
|
+
ctx,
|
|
787
|
+
declaration,
|
|
788
|
+
kind,
|
|
789
|
+
visited,
|
|
790
|
+
inheritedSubstitutions,
|
|
791
|
+
baseType
|
|
792
|
+
);
|
|
793
|
+
declaration.getSourceFile().isDeclarationFile || (mergeBucket(ctx, members, baseMembers, "inputs"), mergeBucket(ctx, members, baseMembers, "outputs")), mergeInto(members.properties, baseMembers.properties, members), mergeInto(members.methods, baseMembers.methods, members);
|
|
746
794
|
}
|
|
747
795
|
}
|
|
748
|
-
|
|
796
|
+
var extendsClauseFor = (ctx, classNode, declaration) => {
|
|
797
|
+
let { ts } = ctx, expression = classNode.heritageClauses?.find(
|
|
798
|
+
(candidate) => candidate.token === ts.SyntaxKind.ExtendsKeyword
|
|
799
|
+
)?.types[0], target = expression?.expression;
|
|
800
|
+
return !target || !ts.isIdentifier(target) && !ts.isPropertyAccessExpression(target) ? void 0 : resolvedSymbol(ctx, target)?.declarations?.includes(declaration) ? expression : void 0;
|
|
801
|
+
}, typeParameterSubstitutions = (ctx, classNode, declaration) => {
|
|
802
|
+
let substitutions = /* @__PURE__ */ new Map(), parameters = declaration.typeParameters ?? [];
|
|
803
|
+
if (parameters.length === 0)
|
|
804
|
+
return substitutions;
|
|
805
|
+
let clause = extendsClauseFor(ctx, classNode, declaration);
|
|
806
|
+
if (!clause)
|
|
807
|
+
return substitutions;
|
|
808
|
+
let args = clause.typeArguments ?? [];
|
|
809
|
+
for (let [index, parameter] of parameters.entries()) {
|
|
810
|
+
let argument = args[index] ?? parameter.default, symbol = ctx.checker.getSymbolAtLocation(parameter.name);
|
|
811
|
+
!argument || !symbol || substitutions.set(symbol, argument);
|
|
812
|
+
}
|
|
813
|
+
return substitutions;
|
|
814
|
+
}, declaredIn = (ctx, entry, classNode) => {
|
|
815
|
+
let node = entry.declaration;
|
|
816
|
+
for (; node && !ctx.ts.isClassLike(node); )
|
|
817
|
+
node = node.parent;
|
|
818
|
+
return node === classNode;
|
|
819
|
+
}, instantiateMembers = (ctx, instantiatedType, classNode, members, substitutions) => {
|
|
820
|
+
if (substitutions.size === 0)
|
|
821
|
+
return;
|
|
822
|
+
let properties = /* @__PURE__ */ new Set([...members.inputs, ...members.outputs, ...members.properties]);
|
|
823
|
+
for (let entry of properties)
|
|
824
|
+
instantiateProperty(ctx, instantiatedType, classNode, entry, substitutions);
|
|
825
|
+
for (let entry of members.methods)
|
|
826
|
+
instantiateMethod(ctx, instantiatedType, classNode, entry, substitutions);
|
|
827
|
+
}, instantiateProperty = (ctx, instantiatedType, classNode, entry, substitutions) => {
|
|
828
|
+
if (entry.isStatic)
|
|
829
|
+
return;
|
|
830
|
+
if (entry.typeSource?.kind === "transform") {
|
|
831
|
+
let checkerTypeSymbol = entry.typeSource.checkerType.getSymbol(), checkerReplacement = entry.typeSource.checkerType.flags & ctx.ts.TypeFlags.TypeParameter && checkerTypeSymbol ? substitutions.get(checkerTypeSymbol) : void 0;
|
|
832
|
+
if (checkerReplacement) {
|
|
833
|
+
entry.value.type = ctx.types.renderInstantiated(checkerReplacement, substitutions);
|
|
834
|
+
return;
|
|
835
|
+
}
|
|
836
|
+
if (entry.typeSource.node && declaredIn(ctx, entry, classNode)) {
|
|
837
|
+
let transformSubstitutions = new Map(entry.typeSource.substitutions);
|
|
838
|
+
for (let [symbol, replacement] of substitutions)
|
|
839
|
+
transformSubstitutions.set(symbol, replacement);
|
|
840
|
+
entry.value.type = ctx.types.renderInstantiated(
|
|
841
|
+
entry.typeSource.node,
|
|
842
|
+
transformSubstitutions
|
|
843
|
+
);
|
|
844
|
+
}
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
if (ctx.ts.isPropertyDeclaration(entry.declaration) && !entry.declaration.type && entry.declaration.initializer && ctx.ts.isNewExpression(entry.declaration.initializer))
|
|
848
|
+
return;
|
|
849
|
+
if (entry.typeSource?.kind !== "signal") {
|
|
850
|
+
let typeNode = declaredPropertyTypeNode(ctx, entry.declaration);
|
|
851
|
+
if (typeNode) {
|
|
852
|
+
declaredIn(ctx, entry, classNode) && (entry.value.type = ctx.types.renderInstantiated(typeNode, substitutions));
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
let type = propertyType(ctx, instantiatedType, entry);
|
|
857
|
+
if (!type)
|
|
858
|
+
return;
|
|
859
|
+
let rendered = entry.typeSource ? signalValueTypeFromType(ctx, type, entry.declaration) : ctx.types.renderCheckerType(type, entry.declaration);
|
|
860
|
+
rendered !== void 0 && (entry.value.type = rendered);
|
|
861
|
+
}, propertyType = (ctx, instantiatedType, entry) => {
|
|
862
|
+
let declarationSymbol = entry.declaration.name ? ctx.checker.getSymbolAtLocation(entry.declaration.name) : void 0, symbol = instantiatedType.getProperties().find(
|
|
863
|
+
(candidate) => candidate === declarationSymbol || candidate.declarations?.includes(entry.declaration)
|
|
864
|
+
) ?? ctx.checker.getPropertyOfType(instantiatedType, entry.declName);
|
|
865
|
+
return symbol && ctx.checker.getTypeOfSymbolAtLocation(symbol, entry.declaration);
|
|
866
|
+
}, declaredPropertyTypeNode = (ctx, declaration) => {
|
|
867
|
+
if (ctx.ts.isPropertyDeclaration(declaration) || ctx.ts.isParameter(declaration) || ctx.ts.isGetAccessorDeclaration(declaration))
|
|
868
|
+
return declaration.type;
|
|
869
|
+
if (ctx.ts.isSetAccessorDeclaration(declaration))
|
|
870
|
+
return declaration.parameters[0]?.type;
|
|
871
|
+
}, instantiateMethod = (ctx, instantiatedType, classNode, entry, substitutions) => {
|
|
872
|
+
if (entry.isStatic)
|
|
873
|
+
return;
|
|
874
|
+
let signatures = propertyType(ctx, instantiatedType, entry)?.getCallSignatures() ?? [], signature = signatures.length === 1 ? signatures[0] : void 0, declaredHere = declaredIn(ctx, entry, classNode);
|
|
875
|
+
if (ctx.ts.isMethodDeclaration(entry.declaration)) {
|
|
876
|
+
let parameters = entry.declaration.parameters.filter(
|
|
877
|
+
(parameter) => !ctx.ts.isIdentifier(parameter.name) || parameter.name.text !== "this"
|
|
878
|
+
);
|
|
879
|
+
for (let [index, argument] of entry.value.args.entries()) {
|
|
880
|
+
let declaredType = parameters[index]?.type;
|
|
881
|
+
if (declaredType)
|
|
882
|
+
declaredHere && (argument.type = ctx.types.renderInstantiated(declaredType, substitutions));
|
|
883
|
+
else {
|
|
884
|
+
let parameter = signature?.getParameters()[index];
|
|
885
|
+
if (!parameter)
|
|
886
|
+
continue;
|
|
887
|
+
argument.type = ctx.types.renderCheckerType(
|
|
888
|
+
ctx.checker.getTypeOfSymbolAtLocation(parameter, entry.declaration),
|
|
889
|
+
entry.declaration
|
|
890
|
+
);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
entry.declaration.type ? declaredHere && (entry.value.returnType = ctx.types.renderInstantiated(
|
|
894
|
+
entry.declaration.type,
|
|
895
|
+
substitutions
|
|
896
|
+
)) : signature && (entry.value.returnType = ctx.types.renderCheckerType(
|
|
897
|
+
signature.getReturnType(),
|
|
898
|
+
entry.declaration
|
|
899
|
+
));
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
function mergeBucket(ctx, members, baseMembers, bucket) {
|
|
749
903
|
for (let inherited of baseMembers[bucket]) {
|
|
750
|
-
let key = memberKey(inherited);
|
|
751
904
|
if ([members[bucket], members.methods].some(
|
|
752
|
-
(entries) => entries.some((entry) =>
|
|
905
|
+
(entries) => entries.some((entry) => sameMemberIdentity(entry, inherited))
|
|
753
906
|
))
|
|
754
907
|
continue;
|
|
755
|
-
let index = members.properties.findIndex((entry) =>
|
|
908
|
+
let index = members.properties.findIndex((entry) => sameMemberIdentity(entry, inherited));
|
|
756
909
|
if (index < 0) {
|
|
757
910
|
members[bucket].push(inherited);
|
|
758
911
|
continue;
|
|
759
912
|
}
|
|
760
|
-
let [own] = members.properties.splice(index, 1);
|
|
761
|
-
members[bucket].push(promote(own, inherited));
|
|
913
|
+
let [own] = members.properties.splice(index, 1), inheritedModel = inherited.typeSource?.kind === "signal" && inherited.typeSource.signalKind === "model", typeOnlyRedeclaration = (ctx.ts.getModifiers(own.declaration) ?? []).some((modifier) => modifier.kind === ctx.ts.SyntaxKind.DeclareKeyword);
|
|
914
|
+
members[bucket].push(promote(own, inherited, inheritedModel && typeOnlyRedeclaration));
|
|
762
915
|
}
|
|
763
916
|
}
|
|
764
|
-
var promote = (own, inherited) =>
|
|
917
|
+
var promote = (own, inherited, preserveInheritedSignal) => preserveInheritedSignal ? {
|
|
765
918
|
...own,
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
919
|
+
...inherited.typeSource ? { typeSource: inherited.typeSource } : {},
|
|
920
|
+
value: {
|
|
921
|
+
...inherited.value,
|
|
922
|
+
...own.value.decorators ? { decorators: own.value.decorators } : {},
|
|
923
|
+
...own.value.visibility ? { visibility: own.value.visibility } : {},
|
|
924
|
+
...own.value.internal ? { internal: own.value.internal } : {},
|
|
925
|
+
...own.value.description ? { description: own.value.description } : {},
|
|
926
|
+
...own.value.rawdescription ? { rawdescription: own.value.rawdescription } : {},
|
|
927
|
+
...own.value.jsdoctags ? { jsdoctags: own.value.jsdoctags } : {}
|
|
928
|
+
}
|
|
929
|
+
} : {
|
|
930
|
+
...own,
|
|
931
|
+
value: {
|
|
932
|
+
...own.value,
|
|
933
|
+
name: inherited.value.name,
|
|
934
|
+
...inherited.value.line === void 0 ? {} : { line: inherited.value.line }
|
|
935
|
+
}
|
|
936
|
+
}, claimedElsewhere = (members, inherited) => [members.inputs, members.outputs, members.properties, members.methods].some(
|
|
937
|
+
(bucket) => bucket.some((entry) => sameMemberIdentity(entry, inherited))
|
|
769
938
|
);
|
|
770
939
|
function mergeInto(target, source, members) {
|
|
771
940
|
for (let inherited of source)
|
|
772
|
-
claimedElsewhere(members,
|
|
941
|
+
claimedElsewhere(members, inherited) || target.push(inherited);
|
|
773
942
|
}
|
|
774
|
-
function collectClassMembers(ctx, classNode) {
|
|
775
|
-
let members = resolveClassMembers(ctx, classNode);
|
|
943
|
+
function collectClassMembers(ctx, classNode, kind) {
|
|
944
|
+
let members = resolveClassMembers(ctx, classNode, kind);
|
|
776
945
|
return sortMembers(members), emitMembers(members);
|
|
777
946
|
}
|
|
778
947
|
function sortMembers(members) {
|
|
@@ -788,6 +957,222 @@ function emitMembers(members) {
|
|
|
788
957
|
methods: values(members.methods)
|
|
789
958
|
};
|
|
790
959
|
}
|
|
960
|
+
var stripImportQualifiers = (text) => text.replace(/import\("[^"]*"\)\./g, ""), collapseWhitespace = (text) => text.replace(/\s+/g, " ").trim(), TypeIndex = class {
|
|
961
|
+
constructor(ts, checker) {
|
|
962
|
+
this.ts = ts, this.checker = checker, this.typealiases = /* @__PURE__ */ new Map(), this.enumerations = /* @__PURE__ */ new Map(), this.aliasCycleGuard = /* @__PURE__ */ new Set();
|
|
963
|
+
}
|
|
964
|
+
/**
|
|
965
|
+
* Render a type node to the spelling the props table shows.
|
|
966
|
+
*
|
|
967
|
+
* Syntactic on purpose, to match the spellings the argTypes extractor depends on: string
|
|
968
|
+
* literals double-quoted, unions joined with ` | `.
|
|
969
|
+
*/
|
|
970
|
+
render(typeNode) {
|
|
971
|
+
let { ts } = this;
|
|
972
|
+
if (ts.isLiteralTypeNode(typeNode)) {
|
|
973
|
+
let { literal } = typeNode;
|
|
974
|
+
return ts.isStringLiteral(literal) || ts.isNoSubstitutionTemplateLiteral(literal) ? JSON.stringify(literal.text) : literal.getText();
|
|
975
|
+
}
|
|
976
|
+
if (ts.isUnionTypeNode(typeNode))
|
|
977
|
+
return typeNode.types.map((type) => this.render(type)).join(" | ");
|
|
978
|
+
if (ts.isIntersectionTypeNode(typeNode))
|
|
979
|
+
return typeNode.types.map((type) => this.render(type)).join(" & ");
|
|
980
|
+
if (ts.isArrayTypeNode(typeNode))
|
|
981
|
+
return `${this.render(typeNode.elementType)}[]`;
|
|
982
|
+
if (ts.isTupleTypeNode(typeNode))
|
|
983
|
+
return `[${typeNode.elements.map((element) => this.render(element)).join(", ")}]`;
|
|
984
|
+
if (ts.isParenthesizedTypeNode(typeNode))
|
|
985
|
+
return `(${this.render(typeNode.type)})`;
|
|
986
|
+
if (ts.isFunctionTypeNode(typeNode) || ts.isConstructorTypeNode(typeNode)) {
|
|
987
|
+
let typeParameters = typeNode.typeParameters?.length ? `<${typeNode.typeParameters.map((parameter) => parameter.getText()).join(", ")}>` : "", parameters = typeNode.parameters.map((parameter) => {
|
|
988
|
+
let name = parameter.name.getText(), rest = parameter.dotDotDotToken ? "..." : "", optional = parameter.questionToken ? "?" : "", type = parameter.type ? this.render(parameter.type) : "any";
|
|
989
|
+
return `${rest}${name}${optional}: ${type}`;
|
|
990
|
+
}).join(", ");
|
|
991
|
+
return `${ts.isConstructorTypeNode(typeNode) ? "new " : ""}${typeParameters}(${parameters}) => ${this.render(typeNode.type)}`;
|
|
992
|
+
}
|
|
993
|
+
if (ts.isTypeOperatorNode(typeNode))
|
|
994
|
+
return `${typeNode.operator === ts.SyntaxKind.KeyOfKeyword ? "keyof" : typeNode.operator === ts.SyntaxKind.ReadonlyKeyword ? "readonly" : "unique"} ${this.render(typeNode.type)}`;
|
|
995
|
+
if (ts.isIndexedAccessTypeNode(typeNode))
|
|
996
|
+
return `${this.render(typeNode.objectType)}[${this.render(typeNode.indexType)}]`;
|
|
997
|
+
if (ts.isTypeReferenceNode(typeNode)) {
|
|
998
|
+
let name = typeNode.typeName.getText(), symbol = this.checker.getSymbolAtLocation(typeNode.typeName);
|
|
999
|
+
symbol && this.addFromSymbol(symbol, name);
|
|
1000
|
+
let args = typeNode.typeArguments?.length ? `<${typeNode.typeArguments.map((arg) => this.render(arg)).join(", ")}>` : "";
|
|
1001
|
+
return `${name}${args}`;
|
|
1002
|
+
}
|
|
1003
|
+
return collapseWhitespace(typeNode.getText());
|
|
1004
|
+
}
|
|
1005
|
+
/** Render a checker type without losing aliases or truncating its spelling. */
|
|
1006
|
+
renderCheckerType(type, node) {
|
|
1007
|
+
return this.addFromType(type), stripImportQualifiers(
|
|
1008
|
+
this.checker.typeToString(type, node, this.ts.TypeFormatFlags.NoTruncation)
|
|
1009
|
+
);
|
|
1010
|
+
}
|
|
1011
|
+
/** Preserve a union, but widen a lone literal before rendering a value-facing type. */
|
|
1012
|
+
renderValueType(type, node) {
|
|
1013
|
+
let widened = type.isUnion() ? type : this.checker.getBaseTypeOfLiteralType(type);
|
|
1014
|
+
return this.renderCheckerType(widened, node);
|
|
1015
|
+
}
|
|
1016
|
+
/**
|
|
1017
|
+
* Render a type node after substituting class type parameters by symbol identity.
|
|
1018
|
+
*
|
|
1019
|
+
* A source-level transform type is not represented by the class property's checker type, so
|
|
1020
|
+
* inherited decorator transforms take this path instead. Symbol identity leaves method-local
|
|
1021
|
+
* binders with the same spelling untouched.
|
|
1022
|
+
*/
|
|
1023
|
+
renderInstantiated(typeNode, substitutions) {
|
|
1024
|
+
if (substitutions.size === 0)
|
|
1025
|
+
return this.render(typeNode);
|
|
1026
|
+
this.addFromTypeNode(typeNode);
|
|
1027
|
+
for (let replacement of substitutions.values())
|
|
1028
|
+
this.addFromTypeNode(replacement);
|
|
1029
|
+
let resolving = /* @__PURE__ */ new Set(), transformed = this.ts.transform(typeNode, [
|
|
1030
|
+
(context) => {
|
|
1031
|
+
let visit = (node) => {
|
|
1032
|
+
if (this.ts.isTypeReferenceNode(node) && this.ts.isIdentifier(node.typeName)) {
|
|
1033
|
+
let symbol = this.checker.getSymbolAtLocation(node.typeName), replacement = symbol && substitutions.get(symbol);
|
|
1034
|
+
if (symbol && replacement && !resolving.has(symbol)) {
|
|
1035
|
+
resolving.add(symbol);
|
|
1036
|
+
let resolved = this.ts.visitNode(replacement, visit);
|
|
1037
|
+
return resolving.delete(symbol), resolved;
|
|
1038
|
+
}
|
|
1039
|
+
}
|
|
1040
|
+
return this.ts.isLiteralTypeNode(node) && (this.ts.isStringLiteral(node.literal) || this.ts.isNoSubstitutionTemplateLiteral(node.literal)) ? this.ts.factory.createLiteralTypeNode(
|
|
1041
|
+
this.ts.factory.createStringLiteral(node.literal.text)
|
|
1042
|
+
) : this.ts.visitEachChild(node, visit, context);
|
|
1043
|
+
};
|
|
1044
|
+
return (root) => this.ts.visitNode(root, visit);
|
|
1045
|
+
}
|
|
1046
|
+
]);
|
|
1047
|
+
try {
|
|
1048
|
+
return collapseWhitespace(
|
|
1049
|
+
this.ts.createPrinter({ removeComments: !0 }).printNode(
|
|
1050
|
+
this.ts.EmitHint.Unspecified,
|
|
1051
|
+
transformed.transformed[0],
|
|
1052
|
+
typeNode.getSourceFile()
|
|
1053
|
+
)
|
|
1054
|
+
);
|
|
1055
|
+
} finally {
|
|
1056
|
+
transformed.dispose();
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
/** Widen and render a declaration's inferred type, as the legacy pipeline did (`'v1'` to `string`). */
|
|
1060
|
+
infer(node) {
|
|
1061
|
+
let { checker } = this;
|
|
1062
|
+
if (!node.name)
|
|
1063
|
+
return;
|
|
1064
|
+
let symbol = checker.getSymbolAtLocation(node.name);
|
|
1065
|
+
if (!symbol)
|
|
1066
|
+
return;
|
|
1067
|
+
let type = checker.getBaseTypeOfLiteralType(checker.getTypeOfSymbolAtLocation(symbol, node));
|
|
1068
|
+
return this.renderCheckerType(type, node);
|
|
1069
|
+
}
|
|
1070
|
+
// Checker-derived types have no TypeNode to walk, so the type's own symbol and each union
|
|
1071
|
+
// constituent's are fed in directly.
|
|
1072
|
+
addFromType(type) {
|
|
1073
|
+
let feed = (candidate) => {
|
|
1074
|
+
let symbol = candidate.aliasSymbol ?? candidate.getSymbol();
|
|
1075
|
+
symbol && this.addFromSymbol(symbol);
|
|
1076
|
+
};
|
|
1077
|
+
if (feed(type), type.isUnion())
|
|
1078
|
+
for (let constituent of type.types)
|
|
1079
|
+
feed(constituent);
|
|
1080
|
+
}
|
|
1081
|
+
addFromTypeNode(typeNode) {
|
|
1082
|
+
let visit = (node) => {
|
|
1083
|
+
if (this.ts.isTypeReferenceNode(node)) {
|
|
1084
|
+
let symbol = this.checker.getSymbolAtLocation(node.typeName);
|
|
1085
|
+
symbol && this.addFromSymbol(symbol, node.typeName.getText());
|
|
1086
|
+
}
|
|
1087
|
+
this.ts.forEachChild(node, visit);
|
|
1088
|
+
};
|
|
1089
|
+
visit(typeNode);
|
|
1090
|
+
}
|
|
1091
|
+
addDeclaration(declaration, referencedAs) {
|
|
1092
|
+
declaration.getSourceFile().isDeclarationFile || (this.ts.isEnumDeclaration(declaration) ? this.addEnum(declaration, referencedAs ?? declaration.name.text) : this.ts.isTypeAliasDeclaration(declaration) && this.addTypeAlias(declaration, referencedAs ?? declaration.name.text));
|
|
1093
|
+
}
|
|
1094
|
+
toMiscellaneous() {
|
|
1095
|
+
let byName = (a, b) => a.name.localeCompare(b.name);
|
|
1096
|
+
return {
|
|
1097
|
+
typealiases: [...this.typealiases.values()].sort(byName),
|
|
1098
|
+
enumerations: [...this.enumerations.values()].sort(byName)
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
/**
|
|
1102
|
+
* `referencedAs` is the spelling {@link render} produced, which an import rename makes differ from
|
|
1103
|
+
* the declaration's own name.
|
|
1104
|
+
*/
|
|
1105
|
+
addFromSymbol(symbol, referencedAs) {
|
|
1106
|
+
let target = symbol.flags & this.ts.SymbolFlags.Alias ? this.checker.getAliasedSymbol(symbol) : symbol;
|
|
1107
|
+
for (let declaration of target.declarations ?? [])
|
|
1108
|
+
this.addDeclaration(declaration, referencedAs);
|
|
1109
|
+
}
|
|
1110
|
+
addEnum(declaration, name) {
|
|
1111
|
+
if (this.enumerations.has(name))
|
|
1112
|
+
return;
|
|
1113
|
+
let childs = declaration.members.map((member) => {
|
|
1114
|
+
let value = this.enumMemberValue(member.initializer);
|
|
1115
|
+
return {
|
|
1116
|
+
name: memberName(this.ts, member.name),
|
|
1117
|
+
...value === void 0 ? {} : { value }
|
|
1118
|
+
};
|
|
1119
|
+
});
|
|
1120
|
+
this.enumerations.set(name, {
|
|
1121
|
+
name,
|
|
1122
|
+
childs,
|
|
1123
|
+
ctype: "miscellaneous",
|
|
1124
|
+
subtype: "enum",
|
|
1125
|
+
file: declaration.getSourceFile().fileName
|
|
1126
|
+
});
|
|
1127
|
+
}
|
|
1128
|
+
addTypeAlias(declaration, name) {
|
|
1129
|
+
if (this.typealiases.has(name) || this.aliasCycleGuard.has(name))
|
|
1130
|
+
return;
|
|
1131
|
+
this.aliasCycleGuard.add(name);
|
|
1132
|
+
let rendered = this.render(declaration.type), rawtype = this.enumResolvableAsWritten(declaration.type) ? rendered : this.literalUnionFromChecker(declaration.type) ?? rendered;
|
|
1133
|
+
this.aliasCycleGuard.delete(name), this.typealiases.set(name, {
|
|
1134
|
+
name,
|
|
1135
|
+
ctype: "miscellaneous",
|
|
1136
|
+
subtype: "typealias",
|
|
1137
|
+
rawtype,
|
|
1138
|
+
file: declaration.getSourceFile().fileName,
|
|
1139
|
+
kind: declaration.type.kind
|
|
1140
|
+
});
|
|
1141
|
+
}
|
|
1142
|
+
// What the extractor's enum path can resolve without help: it splits `rawtype` on `|` and
|
|
1143
|
+
// JSON-parses each member, recursing only into a whole-string alias name.
|
|
1144
|
+
enumResolvableAsWritten(typeNode) {
|
|
1145
|
+
let { ts } = this;
|
|
1146
|
+
return ts.isLiteralTypeNode(typeNode) ? !0 : ts.isTypeReferenceNode(typeNode) ? !typeNode.typeArguments?.length : ts.isUnionTypeNode(typeNode) ? typeNode.types.every(
|
|
1147
|
+
(member) => ts.isLiteralTypeNode(member) || member.kind === ts.SyntaxKind.UndefinedKeyword
|
|
1148
|
+
) : !1;
|
|
1149
|
+
}
|
|
1150
|
+
literalUnionFromChecker(typeNode) {
|
|
1151
|
+
let { checker, ts } = this, type = checker.getTypeAtLocation(typeNode);
|
|
1152
|
+
if (!type.isUnion())
|
|
1153
|
+
return;
|
|
1154
|
+
let literal = ts.TypeFlags.StringLiteral | ts.TypeFlags.NumberLiteral | ts.TypeFlags.BooleanLiteral | ts.TypeFlags.Undefined | ts.TypeFlags.Null;
|
|
1155
|
+
if (type.types.every(
|
|
1156
|
+
(member) => member.flags & literal && !(member.flags & ts.TypeFlags.EnumLiteral)
|
|
1157
|
+
))
|
|
1158
|
+
return checker.typeToString(
|
|
1159
|
+
type,
|
|
1160
|
+
typeNode,
|
|
1161
|
+
ts.TypeFormatFlags.NoTruncation | ts.TypeFormatFlags.InTypeAlias
|
|
1162
|
+
);
|
|
1163
|
+
}
|
|
1164
|
+
// Numeric initializers stay numbers, so a `0` member is falsy and correctly disables the
|
|
1165
|
+
// extractor's enum path.
|
|
1166
|
+
enumMemberValue(initializer) {
|
|
1167
|
+
let { ts } = this;
|
|
1168
|
+
if (initializer) {
|
|
1169
|
+
if (ts.isStringLiteral(initializer) || ts.isNoSubstitutionTemplateLiteral(initializer))
|
|
1170
|
+
return initializer.text;
|
|
1171
|
+
if (ts.isNumericLiteral(initializer))
|
|
1172
|
+
return Number(initializer.text);
|
|
1173
|
+
}
|
|
1174
|
+
}
|
|
1175
|
+
};
|
|
791
1176
|
function analyzeSourceFile(ts, sourceFile, checker) {
|
|
792
1177
|
let types = new TypeIndex(ts, checker), ctx = { ts, checker, types }, meta = {
|
|
793
1178
|
components: [],
|
|
@@ -813,7 +1198,7 @@ function analyzeSourceFile(ts, sourceFile, checker) {
|
|
|
813
1198
|
logger2.debug(`[angular-cm] ${statement.name.text} left out of docgen: an @NgModule`);
|
|
814
1199
|
continue;
|
|
815
1200
|
}
|
|
816
|
-
let name = statement.name.text, file = sourceFile.fileName, members = collectClassMembers(ctx, statement), common = {
|
|
1201
|
+
let name = statement.name.text, file = sourceFile.fileName, members = collectClassMembers(ctx, statement, kind), common = {
|
|
817
1202
|
file,
|
|
818
1203
|
...getJsDocDescription(ts, statement),
|
|
819
1204
|
...getJsDocTagsField(ts, statement)
|
|
@@ -892,10 +1277,10 @@ var KNOWN_DECORATORS = {
|
|
|
892
1277
|
if (value?.kind === ctx.ts.SyntaxKind.FalseKeyword)
|
|
893
1278
|
return !1;
|
|
894
1279
|
}, resolveInitializer = (ctx, expression) => {
|
|
895
|
-
let { ts
|
|
1280
|
+
let { ts } = ctx;
|
|
896
1281
|
if (!ts.isIdentifier(expression))
|
|
897
1282
|
return expression;
|
|
898
|
-
let
|
|
1283
|
+
let declaration = resolvedSymbol(ctx, expression)?.valueDeclaration;
|
|
899
1284
|
return declaration && ts.isVariableDeclaration(declaration) ? declaration.initializer : void 0;
|
|
900
1285
|
}, pipeName = (ctx, node) => {
|
|
901
1286
|
let metadata = decoratorObjectArg(ctx, node, "Pipe");
|
|
@@ -946,7 +1331,15 @@ var KNOWN_DECORATORS = {
|
|
|
946
1331
|
}
|
|
947
1332
|
let checker = program.getTypeChecker(), fileMeta = analyzeSourceFile(this.typescript, sourceFile, checker), entry = this.pickEntry(fileMeta, sourceFile, names);
|
|
948
1333
|
if (entry)
|
|
949
|
-
return this.debug(`${describe(entry)} from ${fileName}`), {
|
|
1334
|
+
return this.debug(`${describe(entry)} from ${fileName}`), {
|
|
1335
|
+
entry,
|
|
1336
|
+
json: fileMeta,
|
|
1337
|
+
...jsDocInfoField(
|
|
1338
|
+
this.typescript,
|
|
1339
|
+
checker,
|
|
1340
|
+
findClassDeclaration(this.typescript, sourceFile, entry.name)
|
|
1341
|
+
)
|
|
1342
|
+
};
|
|
950
1343
|
let viaExports = this.extractViaModuleExports(checker, sourceFile, fileMeta, names);
|
|
951
1344
|
if (viaExports)
|
|
952
1345
|
return this.debug(`${describe(viaExports.entry)} from ${fileName}, reached through its exports`), viaExports;
|
|
@@ -989,7 +1382,11 @@ var KNOWN_DECORATORS = {
|
|
|
989
1382
|
continue;
|
|
990
1383
|
let declarationFile = declaration.getSourceFile(), targetMeta = declarationFile === sourceFile ? fileMeta : analyzeSourceFile(this.typescript, declarationFile, checker), entry = findRecord(targetMeta, declaration.name.text);
|
|
991
1384
|
if (entry)
|
|
992
|
-
return {
|
|
1385
|
+
return {
|
|
1386
|
+
entry,
|
|
1387
|
+
json: targetMeta,
|
|
1388
|
+
...jsDocInfoField(this.typescript, checker, declaration)
|
|
1389
|
+
};
|
|
993
1390
|
}
|
|
994
1391
|
}
|
|
995
1392
|
}, importClosure = (typescript, program, entry) => {
|
|
@@ -1017,6 +1414,15 @@ var KNOWN_DECORATORS = {
|
|
|
1017
1414
|
let counts = "inputsClass" in entry ? `${entry.inputsClass?.length ?? 0} input(s), ${entry.outputsClass?.length ?? 0} output(s), ${"propertiesClass" in entry ? entry.propertiesClass?.length ?? 0 : 0} propertie(s)` : `${entry.properties.length} propertie(s), ${entry.methods.length} method(s)`;
|
|
1018
1415
|
return `extracted ${entry.type} ${entry.name} with ${counts}`;
|
|
1019
1416
|
}, findRecord = (fileMeta, name) => name ? allRecords(fileMeta).find((record) => record.name === name) : void 0;
|
|
1417
|
+
function findClassDeclaration(typescript, sourceFile, name) {
|
|
1418
|
+
return sourceFile.statements.find(
|
|
1419
|
+
(statement) => typescript.isClassDeclaration(statement) && statement.name?.text === name
|
|
1420
|
+
);
|
|
1421
|
+
}
|
|
1422
|
+
function jsDocInfoField(typescript, checker, declaration) {
|
|
1423
|
+
let symbol = declaration?.name && checker.getSymbolAtLocation(declaration.name);
|
|
1424
|
+
return symbol ? { jsDocInfo: extractComponentJsDocInfo(typescript, checker, symbol) } : {};
|
|
1425
|
+
}
|
|
1020
1426
|
function findDefaultExportedClassName(typescript, sourceFile) {
|
|
1021
1427
|
for (let statement of sourceFile.statements) {
|
|
1022
1428
|
if (typescript.isClassDeclaration(statement) && statement.name && statement.modifiers?.some(
|
|
@@ -1088,11 +1494,85 @@ var AngularComponentMetaManager = class extends ComponentMetaManager {
|
|
|
1088
1494
|
// src/docgen/build-docgen.ts
|
|
1089
1495
|
import { getComponentIdFromEntry, getStoryImportPathFromEntry } from "storybook/internal/common";
|
|
1090
1496
|
import { resolve } from "node:path";
|
|
1091
|
-
|
|
1497
|
+
|
|
1498
|
+
// src/docgen/api-description.ts
|
|
1499
|
+
var readMember = (name, argType) => {
|
|
1500
|
+
let table = argType.table;
|
|
1501
|
+
return {
|
|
1502
|
+
name,
|
|
1503
|
+
description: argType.description,
|
|
1504
|
+
type: table?.type?.summary,
|
|
1505
|
+
required: table?.type?.required !== !1,
|
|
1506
|
+
defaultValue: table?.defaultValue?.summary,
|
|
1507
|
+
deprecated: table?.jsDocTags?.deprecated
|
|
1508
|
+
};
|
|
1509
|
+
}, commentLines = (text) => text.replace(/\*\//g, "*\\/").split(`
|
|
1510
|
+
`).map((line) => line.trimEnd()), docComment = (member) => {
|
|
1511
|
+
let description = member.description?.trim(), body = description ? commentLines(description) : [], tags = [];
|
|
1512
|
+
if (member.deprecated !== void 0) {
|
|
1513
|
+
let deprecated = member.deprecated.trim();
|
|
1514
|
+
tags.push(...commentLines(deprecated ? `@deprecated ${deprecated}` : "@deprecated"));
|
|
1515
|
+
}
|
|
1516
|
+
return member.defaultValue !== void 0 && tags.push(
|
|
1517
|
+
...commentLines(`@default ${member.defaultValue === "" ? "''" : member.defaultValue}`)
|
|
1518
|
+
), tags.length > 0 && (body.length > 0 && body.push(""), body.push(...tags)), body.length === 0 ? [] : body.length === 1 ? [` /** ${body[0]} */`] : [" /**", ...body.map((line) => line ? ` * ${line}` : " *"), " */"];
|
|
1519
|
+
}, quotedName = (name) => JSON.stringify(name).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029"), fieldName = (name) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name) ? name : quotedName(name), bindingName = (name) => quotedName(name).slice(1, -1), inputLine = (member, isTwoWay) => {
|
|
1520
|
+
let optional = member.required ? "" : "?", line = ` ${fieldName(member.name)}${optional}: ${member.type ?? "any"};`;
|
|
1521
|
+
return isTwoWay ? `${line} // two-way: [(${bindingName(member.name)})]` : line;
|
|
1522
|
+
}, outputLine = (member) => ` ${fieldName(member.name)}: ${member.type ?? "any"};`, section = (heading, typeName, lines) => [
|
|
1523
|
+
`## ${heading}`,
|
|
1524
|
+
"",
|
|
1525
|
+
"```",
|
|
1526
|
+
`export type ${typeName} = {`,
|
|
1527
|
+
...lines,
|
|
1528
|
+
"}",
|
|
1529
|
+
"```",
|
|
1530
|
+
""
|
|
1531
|
+
];
|
|
1532
|
+
function buildApiDescription(argTypes, componentName) {
|
|
1533
|
+
let inputs = [], outputs = [];
|
|
1534
|
+
for (let [name, argType] of Object.entries(argTypes)) {
|
|
1535
|
+
let category = argType.table?.category;
|
|
1536
|
+
category === "inputs" ? inputs.push(readMember(name, argType)) : category === "outputs" && outputs.push(readMember(name, argType));
|
|
1537
|
+
}
|
|
1538
|
+
if (inputs.length === 0 && outputs.length === 0)
|
|
1539
|
+
return;
|
|
1540
|
+
let outputNames = new Set(outputs.map((output) => output.name)), typePrefix = componentName.replace(/\W+/g, ""), parts = [];
|
|
1541
|
+
return inputs.length > 0 && parts.push(
|
|
1542
|
+
...section(
|
|
1543
|
+
"Inputs",
|
|
1544
|
+
`${typePrefix}Inputs`,
|
|
1545
|
+
inputs.flatMap((input) => [
|
|
1546
|
+
...docComment(input),
|
|
1547
|
+
inputLine(input, outputNames.has(`${input.name}Change`))
|
|
1548
|
+
])
|
|
1549
|
+
)
|
|
1550
|
+
), outputs.length > 0 && parts.push(
|
|
1551
|
+
...section(
|
|
1552
|
+
"Outputs",
|
|
1553
|
+
`${typePrefix}Outputs`,
|
|
1554
|
+
outputs.flatMap((output) => [...docComment(output), outputLine(output)])
|
|
1555
|
+
)
|
|
1556
|
+
), parts.join(`
|
|
1557
|
+
`).trim();
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
// src/docgen/build-docgen.ts
|
|
1561
|
+
var inputsOf = (entry) => "inputsClass" in entry ? entry.inputsClass ?? [] : [], outputsOf = (entry) => "outputsClass" in entry ? entry.outputsClass ?? [] : [], describedBy = (text) => text?.trim() || void 0, analyzerJsDocTags = (entry) => {
|
|
1562
|
+
let tags = {};
|
|
1563
|
+
for (let tag of entry.jsdoctags ?? []) {
|
|
1564
|
+
let name = tag.tagName?.escapedText;
|
|
1565
|
+
if (!name)
|
|
1566
|
+
continue;
|
|
1567
|
+
let value = tag.comment === void 0 ? "" : String(tag.comment).trim();
|
|
1568
|
+
(tags[name] ??= []).push(value);
|
|
1569
|
+
}
|
|
1570
|
+
return tags;
|
|
1571
|
+
}, metaToSnippetMeta = (meta) => {
|
|
1092
1572
|
let { entry } = meta, inputs = inputsOf(entry).map((input) => input.name), inputNames = new Set(inputs), outputs = [];
|
|
1093
1573
|
for (let output of outputsOf(entry)) {
|
|
1094
|
-
let
|
|
1095
|
-
outputs.includes(
|
|
1574
|
+
let bindingName2 = inputNames.has(output.name) ? `${output.name}Change` : output.name;
|
|
1575
|
+
outputs.includes(bindingName2) || outputs.push(bindingName2);
|
|
1096
1576
|
}
|
|
1097
1577
|
return {
|
|
1098
1578
|
name: entry.name,
|
|
@@ -1105,24 +1585,33 @@ var inputsOf = (entry) => "inputsClass" in entry ? entry.inputsClass ?? [] : [],
|
|
|
1105
1585
|
members: enumeration.childs.map((child) => ({ name: child.name, value: child.value }))
|
|
1106
1586
|
}))
|
|
1107
1587
|
};
|
|
1108
|
-
}, extractJsDocTags = (entry) => {
|
|
1109
|
-
let tags = {};
|
|
1110
|
-
for (let tag of entry.jsdoctags ?? []) {
|
|
1111
|
-
let name = tag?.tagName?.escapedText;
|
|
1112
|
-
if (!name)
|
|
1113
|
-
continue;
|
|
1114
|
-
let value = tag.comment === void 0 ? "" : String(tag.comment).trim();
|
|
1115
|
-
(tags[name] ??= []).push(value);
|
|
1116
|
-
}
|
|
1117
|
-
return tags;
|
|
1118
1588
|
}, errorPayload = (base, name, message) => ({ ...base, jsDocTags: {}, error: { name, message } }), buildDocgenPayload = (input, context) => {
|
|
1119
1589
|
let { manager, options, logger: logger5 } = context, storyImportPath = getStoryImportPathFromEntry(input.entry);
|
|
1120
1590
|
if (!storyImportPath)
|
|
1121
1591
|
return;
|
|
1122
1592
|
let storyFilePath = (context.resolvePath ?? ((importPath) => resolve(process.cwd(), importPath)))(storyImportPath), resolved = resolveStoryComponent(storyFilePath, input.entry.title);
|
|
1123
1593
|
if ("reason" in resolved) {
|
|
1124
|
-
|
|
1125
|
-
|
|
1594
|
+
if (resolved.reason === "no-meta-component") {
|
|
1595
|
+
logger5.debug(`No Angular component resolved from ${storyFilePath}: ${resolved.reason}.`);
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1598
|
+
let unreadableBase = {
|
|
1599
|
+
id: getComponentIdFromEntry(input.entry),
|
|
1600
|
+
name: resolved.reason === "unreadable-component-expression" ? resolved.expression : input.entry.title.split("/").at(-1) ?? input.entry.title,
|
|
1601
|
+
path: storyImportPath
|
|
1602
|
+
};
|
|
1603
|
+
return errorPayload(
|
|
1604
|
+
unreadableBase,
|
|
1605
|
+
"AngularComponentMetaNotFound",
|
|
1606
|
+
resolved.reason === "unreadable-component-expression" ? `The story file sets \`component: ${resolved.expression}\`, which does not resolve to a class.
|
|
1607
|
+
Storybook follows an imported name, a namespace-import property access, or a chain of property accesses and spreads through modules it can resolve. Assign the component to a name in ${storyFilePath}.` : (
|
|
1608
|
+
// `meta.component` may reach this binding through another module (e.g. a spread config
|
|
1609
|
+
// object), so the type-only or namespace import is not necessarily written in the story
|
|
1610
|
+
// file itself - naming it here would send the reader to the wrong file.
|
|
1611
|
+
`Resolving \`meta.component\` from ${storyFilePath} reached a binding that is a type-only or namespace import, which carries no class to document.
|
|
1612
|
+
Import the component as a value in whichever module declares that binding.`
|
|
1613
|
+
)
|
|
1614
|
+
);
|
|
1126
1615
|
}
|
|
1127
1616
|
let { component } = resolved, displayName = component.exportName === "default" ? component.localName : component.exportName, base = {
|
|
1128
1617
|
id: getComponentIdFromEntry(input.entry),
|
|
@@ -1133,8 +1622,11 @@ var inputsOf = (entry) => "inputsClass" in entry ? entry.inputsClass ?? [] : [],
|
|
|
1133
1622
|
return errorPayload(
|
|
1134
1623
|
base,
|
|
1135
1624
|
"AngularComponentMetaNotFound",
|
|
1136
|
-
`
|
|
1137
|
-
|
|
1625
|
+
// `component.importId` may be read from a module `meta.component` only reaches through a
|
|
1626
|
+
// chain (e.g. a spread config object), so the import is not necessarily written in the story
|
|
1627
|
+
// file itself - naming it here would send the reader to the wrong file.
|
|
1628
|
+
`Storybook could not resolve the import of "${displayName}" from "${component.importId}", reached while resolving \`meta.component\` from ${storyFilePath}.
|
|
1629
|
+
Check the import specifier (and any tsconfig path aliases it relies on) in whichever module actually imports it.`
|
|
1138
1630
|
);
|
|
1139
1631
|
let meta;
|
|
1140
1632
|
try {
|
|
@@ -1158,9 +1650,13 @@ Check that the file exports the component class and is covered by a tsconfig.jso
|
|
|
1158
1650
|
);
|
|
1159
1651
|
let argTypes = extractArgTypesFromData(meta.entry, {
|
|
1160
1652
|
metadataJson: meta.json,
|
|
1161
|
-
|
|
1653
|
+
propsTable: options.propsTable,
|
|
1654
|
+
logger: logger5
|
|
1655
|
+
}), apiArgTypes = options.propsTable === "api" ? argTypes : extractArgTypesFromData(meta.entry, {
|
|
1656
|
+
metadataJson: meta.json,
|
|
1657
|
+
propsTable: "api",
|
|
1162
1658
|
logger: logger5
|
|
1163
|
-
}), jsDocTags =
|
|
1659
|
+
}), jsDocTags = meta.jsDocInfo?.jsDocTags ?? analyzerJsDocTags(meta.entry), description = describedBy(meta.jsDocInfo?.description) ?? describedBy(meta.entry.rawdescription) ?? describedBy(meta.entry.description);
|
|
1164
1660
|
return {
|
|
1165
1661
|
...base,
|
|
1166
1662
|
// The analyzer knows the class name even when the story file imported it as a default export.
|
|
@@ -1169,6 +1665,8 @@ Check that the file exports the component class and is covered by a tsconfig.jso
|
|
|
1169
1665
|
summary: jsDocTags.summary?.[0],
|
|
1170
1666
|
jsDocTags,
|
|
1171
1667
|
argTypes,
|
|
1668
|
+
apiDescription: buildApiDescription(apiArgTypes, meta.entry.name),
|
|
1669
|
+
renderer: "angular",
|
|
1172
1670
|
angularComponentMeta: metaToSnippetMeta(meta)
|
|
1173
1671
|
};
|
|
1174
1672
|
};
|
|
@@ -1187,7 +1685,7 @@ var workerLogger = {
|
|
|
1187
1685
|
);
|
|
1188
1686
|
return;
|
|
1189
1687
|
}
|
|
1190
|
-
}, createDocgenProvider = (options
|
|
1688
|
+
}, createDocgenProvider = (options) => {
|
|
1191
1689
|
let managerPromise;
|
|
1192
1690
|
return (nextDocgen) => async (input) => {
|
|
1193
1691
|
let storyImportPath = getStoryImportPathFromEntry2(input.entry);
|