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