@mui/internal-docs-infra 0.12.1-canary.50 → 0.12.1-canary.51

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/internal-docs-infra",
3
- "version": "0.12.1-canary.50",
3
+ "version": "0.12.1-canary.51",
4
4
  "author": "MUI Team",
5
5
  "description": "MUI Infra - internal documentation creation tools.",
6
6
  "license": "MIT",
@@ -65,7 +65,7 @@
65
65
  "remark-typography": "^0.8.6",
66
66
  "sucrase": "^3.35.1",
67
67
  "typescript": "npm:@typescript/typescript6@6.0.2",
68
- "typescript-api-extractor": "1.0.0-beta.6",
68
+ "typescript-api-extractor": "1.0.0-beta.7",
69
69
  "uint8-to-base64": "^0.2.1",
70
70
  "unified": "^11.0.5",
71
71
  "unist-util-visit": "^5.1.0",
@@ -814,5 +814,5 @@
814
814
  "bin": {
815
815
  "docs-infra": "./cli/index.mjs"
816
816
  },
817
- "gitSha": "5aa500cdf1274a4ecc6674e3cab2ef7dc8a92aa9"
817
+ "gitSha": "9741b9d5e30ddcd5bccf4020dd59ec56ea4932cb"
818
818
  }
@@ -48,12 +48,23 @@ export declare function formatFunctionSignature(type: tae.FunctionNode): string;
48
48
  * Attempts to collect a named union type as an external type during formatting.
49
49
  * Only collects if:
50
50
  * - The type has a name
51
- * - ALL members are literals or simple intrinsics (string, number, boolean)
51
+ * - ALL members are literals, simple intrinsics (string, number, boolean), or template literals
52
+ * whose placeholders are simple intrinsics
52
53
  * - The type is not in allExports (not an own type)
53
54
  * - The type is not a built-in namespace
54
55
  * - The optional pattern filter matches
55
56
  */
56
57
  export declare function maybeCollectExternalUnion(type: tae.UnionNode, collector: ExternalTypesCollector): void;
58
+ /**
59
+ * Attempts to collect a named template literal type as an external type during formatting.
60
+ * Only collects if:
61
+ * - The type has a name
62
+ * - ALL placeholders are simple intrinsics (string, number, boolean)
63
+ * - The type is not in allExports (not an own type)
64
+ * - The type is not a built-in namespace
65
+ * - The optional pattern filter matches
66
+ */
67
+ export declare function maybeCollectExternalTemplateLiteral(type: tae.TemplateLiteralNode, collector: ExternalTypesCollector): void;
57
68
  /**
58
69
  * Attempts to collect a named function type as an external type during formatting.
59
70
  * Only collects named function types that aren't ComponentRenderFn, own types, or built-in.
@@ -1,7 +1,8 @@
1
1
  import { uniq } from 'es-toolkit';
2
- import { isExternalType, isIntrinsicType, isUnionType, isObjectType, isLiteralType, isTypeOperatorType, isTypeQueryType } from "./typeGuards.mjs";
2
+ import { isExternalType, isIntrinsicType, isUnionType, isObjectType, isLiteralType, isTemplateLiteralType, isTypeOperatorType, isTypeQueryType } from "./typeGuards.mjs";
3
3
  import { isBuiltInTypeName } from "./builtInTypes.mjs";
4
4
  import { groupType, UNION_OR_INTERSECTION } from "./precedence.mjs";
5
+ import { formatTemplateLiteral } from "./templateLiteral.mjs";
5
6
 
6
7
  /**
7
8
  * Metadata for an external type discovered during formatting.
@@ -93,6 +94,9 @@ export function formatExternalTypeDefinition(type) {
93
94
  }
94
95
  return String(value);
95
96
  }
97
+ if (isTemplateLiteralType(type)) {
98
+ return formatTemplateLiteral(type, formatExternalTypeDefinition);
99
+ }
96
100
  if (isIntrinsicType(type)) {
97
101
  return type.intrinsic;
98
102
  }
@@ -125,11 +129,23 @@ export function formatFunctionSignature(type) {
125
129
  return signatures.length > 1 ? signatures.map(sig => `(${sig})`).join(' | ') : signatures[0] || '() => void';
126
130
  }
127
131
 
132
+ /**
133
+ * Whether a type is a literal, a simple intrinsic (string, number, boolean), or a template
134
+ * literal whose placeholders are all simple intrinsics.
135
+ */
136
+ function isLiteralLike(type) {
137
+ if (isTemplateLiteralType(type)) {
138
+ return type.types.every(isLiteralLike);
139
+ }
140
+ return isLiteralType(type) || isIntrinsicType(type) && ['string', 'number', 'boolean'].includes(type.intrinsic);
141
+ }
142
+
128
143
  /**
129
144
  * Attempts to collect a named union type as an external type during formatting.
130
145
  * Only collects if:
131
146
  * - The type has a name
132
- * - ALL members are literals or simple intrinsics (string, number, boolean)
147
+ * - ALL members are literals, simple intrinsics (string, number, boolean), or template literals
148
+ * whose placeholders are simple intrinsics
133
149
  * - The type is not in allExports (not an own type)
134
150
  * - The type is not a built-in namespace
135
151
  * - The optional pattern filter matches
@@ -161,7 +177,7 @@ export function maybeCollectExternalUnion(type, collector) {
161
177
  }
162
178
 
163
179
  // Only collect if ALL members are literals
164
- const allMembersAreLiterals = resolvedUnionMembers(type).every(t => isLiteralType(t) || isIntrinsicType(t) && ['string', 'number', 'boolean'].includes(t.intrinsic));
180
+ const allMembersAreLiterals = resolvedUnionMembers(type).every(isLiteralLike);
165
181
  if (allMembersAreLiterals) {
166
182
  collector.collected.set(typeName, {
167
183
  name: typeName,
@@ -170,6 +186,50 @@ export function maybeCollectExternalUnion(type, collector) {
170
186
  }
171
187
  }
172
188
 
189
+ /**
190
+ * Attempts to collect a named template literal type as an external type during formatting.
191
+ * Only collects if:
192
+ * - The type has a name
193
+ * - ALL placeholders are simple intrinsics (string, number, boolean)
194
+ * - The type is not in allExports (not an own type)
195
+ * - The type is not a built-in namespace
196
+ * - The optional pattern filter matches
197
+ */
198
+ export function maybeCollectExternalTemplateLiteral(type, collector) {
199
+ const typeName = type.typeName?.name;
200
+ if (!typeName) {
201
+ return;
202
+ }
203
+
204
+ // Already collected
205
+ if (collector.collected.has(typeName)) {
206
+ return;
207
+ }
208
+
209
+ // Pattern filter
210
+ if (collector.pattern && !collector.pattern.test(typeName)) {
211
+ return;
212
+ }
213
+
214
+ // Built-in type
215
+ if (isBuiltInTypeName(type.typeName)) {
216
+ return;
217
+ }
218
+
219
+ // Own type (in exports or typeNameMap)
220
+ if (isOwnTypeName(typeName, collector)) {
221
+ return;
222
+ }
223
+
224
+ // Only collect if ALL placeholders are simple intrinsics, as unions require of their members
225
+ if (isLiteralLike(type)) {
226
+ collector.collected.set(typeName, {
227
+ name: typeName,
228
+ definition: formatExternalTypeDefinition(type)
229
+ });
230
+ }
231
+ }
232
+
173
233
  /**
174
234
  * Attempts to collect a named function type as an external type during formatting.
175
235
  * Only collects named function types that aren't ComponentRenderFn, own types, or built-in.
@@ -1,9 +1,10 @@
1
1
  import { uniq } from 'es-toolkit';
2
- import { isExternalType, isIntrinsicType, isUnionType, isIntersectionType, isObjectType, isAnonymousObjectType, isArrayType, isFunctionType, isLiteralType, isTupleType, isTypeParameterType, isTypeOperatorType, isTypeQueryType, isInternalTypeName } from "./typeGuards.mjs";
3
- import { isOwnTypeName, maybeCollectExternalUnion, maybeCollectExternalFunction, maybeCollectExternalReference } from "./externalTypes.mjs";
2
+ import { isExternalType, isIntrinsicType, isUnionType, isIntersectionType, isObjectType, isAnonymousObjectType, isArrayType, isFunctionType, isLiteralType, isTemplateLiteralType, isTupleType, isTypeParameterType, isTypeOperatorType, isTypeQueryType, isInternalTypeName } from "./typeGuards.mjs";
3
+ import { isOwnTypeName, maybeCollectExternalUnion, maybeCollectExternalTemplateLiteral, maybeCollectExternalFunction, maybeCollectExternalReference } from "./externalTypes.mjs";
4
4
  import { isBuiltInTypeReference } from "./builtInTypes.mjs";
5
5
  import { prettyFormat } from "./format.mjs";
6
6
  import { groupType, UNION, UNION_OR_INTERSECTION } from "./precedence.mjs";
7
+ import { formatTemplateLiteral } from "./templateLiteral.mjs";
7
8
  /**
8
9
  * The keys a preserved type operator stands for, or `undefined` when it should be shown as
9
10
  * the syntax it was written as.
@@ -329,6 +330,30 @@ export function formatType(type, options) {
329
330
  if (isLiteralType(type)) {
330
331
  return normalizeQuotes(String(type.value));
331
332
  }
333
+ if (isTemplateLiteralType(type)) {
334
+ // A reference to a template literal alias keeps its name, like the other named types.
335
+ // But skip if the type name matches selfName to avoid circular references like `type Foo = Foo`
336
+ if (type.typeName) {
337
+ const qualifiedName = getFullyQualifiedName(type.typeName, exportNames, typeNameMap, preserveTypeParameters);
338
+ if (!matchesSelfName(qualifiedName, type.typeName.name)) {
339
+ if (externalTypesCollector) {
340
+ // Only collect as external if the qualified name wasn't rewritten to an own type.
341
+ if (qualifiedName === type.typeName.name || !isOwnTypeName(qualifiedName, externalTypesCollector)) {
342
+ maybeCollectExternalTemplateLiteral(type, externalTypesCollector);
343
+ }
344
+ }
345
+ return qualifiedName;
346
+ }
347
+ }
348
+
349
+ // Use expandObjects=false for placeholders to prevent deep expansion (one level only)
350
+ return formatTemplateLiteral(type, placeholder => formatType(placeholder, {
351
+ exportNames,
352
+ typeNameMap,
353
+ externalTypesCollector,
354
+ preserveTypeParameters
355
+ }));
356
+ }
332
357
  if (isArrayType(type)) {
333
358
  // Use expandObjects=false for element types to prevent deep expansion (one level only)
334
359
  const formattedMemberType = formatType(type.elementType, {
@@ -0,0 +1,8 @@
1
+ import type * as tae from 'typescript-api-extractor';
2
+ /**
3
+ * Writes a template literal type as TypeScript source, such as `` `${number}px` ``.
4
+ *
5
+ * Placeholders are formatted by the caller, so each formatter keeps its own rules for the
6
+ * types inside them.
7
+ */
8
+ export declare function formatTemplateLiteral(type: tae.TemplateLiteralNode, formatPlaceholder: (placeholder: tae.AnyType) => string): string;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Writes a template literal type as TypeScript source, such as `` `${number}px` ``.
3
+ *
4
+ * Placeholders are formatted by the caller, so each formatter keeps its own rules for the
5
+ * types inside them.
6
+ */
7
+ export function formatTemplateLiteral(type, formatPlaceholder) {
8
+ const placeholders = type.types.map((placeholder, index) => `\${${formatPlaceholder(placeholder)}}${escapeTemplateText(type.texts[index + 1])}`);
9
+ return `\`${escapeTemplateText(type.texts[0])}${placeholders.join('')}\``;
10
+ }
11
+
12
+ /**
13
+ * Escapes the characters that would otherwise end the template, start a placeholder or an
14
+ * escape, or be read back as a line feed.
15
+ */
16
+ function escapeTemplateText(text) {
17
+ return text.replace(/\\|`|\$\{|\r/g, match => match === '\r' ? '\\r' : `\\${match}`);
18
+ }
@@ -45,6 +45,10 @@ export declare function isFunctionType(type: unknown): type is tae.FunctionNode;
45
45
  * Type guard to check if a type node is a literal type.
46
46
  */
47
47
  export declare function isLiteralType(type: unknown): type is tae.LiteralNode;
48
+ /**
49
+ * Type guard to check if a type node is a template literal.
50
+ */
51
+ export declare function isTemplateLiteralType(type: unknown): type is tae.TemplateLiteralNode;
48
52
  /**
49
53
  * Type guard to check if a type node is an enum type.
50
54
  */
@@ -80,6 +80,13 @@ export function isLiteralType(type) {
80
80
  return hasKind(type, 'literal');
81
81
  }
82
82
 
83
+ /**
84
+ * Type guard to check if a type node is a template literal.
85
+ */
86
+ export function isTemplateLiteralType(type) {
87
+ return hasKind(type, 'templateLiteral');
88
+ }
89
+
83
90
  /**
84
91
  * Type guard to check if a type node is an enum type.
85
92
  */