@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
  2. package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
  3. package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
  4. package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
  5. package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
  6. package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
  7. package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
  8. package/esm/CodeHighlighter/errors.js +248 -400
  9. package/esm/CodeHighlighter/parseControlledCode.js +12 -20
  10. package/esm/CodeProvider/CodeContext.js +3 -3
  11. package/esm/CodeProvider/CodeProvider.js +31 -40
  12. package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
  13. package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
  14. package/esm/cli/index.js +1 -1
  15. package/esm/cli/runValidate.js +160 -264
  16. package/esm/createDemoData/createDemoData.js +11 -12
  17. package/esm/createSitemap/createSitemap.js +2 -2
  18. package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
  19. package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
  20. package/esm/pipeline/hastUtils/hastUtils.js +16 -17
  21. package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
  22. package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
  23. package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
  24. package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
  25. package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
  26. package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
  27. package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
  28. package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
  29. package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
  30. package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
  31. package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
  32. package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
  33. package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
  34. package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
  35. package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
  36. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
  37. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
  38. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
  39. package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
  40. package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
  41. package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
  42. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
  43. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
  44. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
  45. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
  46. package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
  47. package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
  48. package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
  49. package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
  50. package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
  51. package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
  52. package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
  53. package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
  54. package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
  55. package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
  56. package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
  57. package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
  58. package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
  59. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
  60. package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
  61. package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
  62. package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
  63. package/esm/pipeline/parseSource/addLineGutters.js +33 -45
  64. package/esm/pipeline/parseSource/grammars.js +3 -3
  65. package/esm/pipeline/parseSource/parseSource.js +13 -31
  66. package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
  67. package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
  68. package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
  69. package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
  70. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
  71. package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
  72. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
  73. package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
  74. package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
  75. package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
  76. package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
  77. package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
  78. package/esm/useCode/Pre.js +58 -62
  79. package/esm/useCode/useCode.js +59 -61
  80. package/esm/useCode/useCodeUtils.js +54 -63
  81. package/esm/useCode/useCopyFunctionality.js +10 -9
  82. package/esm/useCode/useFileNavigation.js +150 -212
  83. package/esm/useCode/useSourceEditing.js +17 -14
  84. package/esm/useCode/useTransformManagement.js +23 -26
  85. package/esm/useCode/useUIState.js +12 -20
  86. package/esm/useCode/useVariantSelection.js +62 -79
  87. package/esm/useCopier/index.js +29 -56
  88. package/esm/useDemo/createCodeSandbox.js +12 -15
  89. package/esm/useDemo/createStackBlitz.js +14 -20
  90. package/esm/useDemo/exportVariant.js +200 -180
  91. package/esm/useDemo/exportVariantAsCra.js +22 -25
  92. package/esm/useDemo/useDemo.js +80 -84
  93. package/esm/useErrors/ErrorsContext.js +1 -1
  94. package/esm/useErrors/useErrors.js +3 -3
  95. package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
  96. package/esm/usePreference/PreferencesProvider.js +1 -1
  97. package/esm/usePreference/usePreference.js +9 -11
  98. package/esm/useSearch/useSearch.js +290 -387
  99. package/esm/useUrlHashState/useUrlHashState.js +11 -14
  100. package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
  101. package/esm/withDocsInfra/withDocsInfra.js +99 -101
  102. package/package.json +7 -4
@@ -1,9 +1,3 @@
1
- import _regenerator from "@babel/runtime/helpers/esm/regenerator";
2
- import _extends from "@babel/runtime/helpers/esm/extends";
3
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
5
- import _typeof from "@babel/runtime/helpers/esm/typeof";
6
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
7
1
  import { parseImportsAndComments } from "../loaderUtils/index.js";
8
2
  import { parseFunctionArguments, isTypeAssertion, isFunction, isGeneric, isArray, isArrowFunction, isObjectLiteral } from "./parseFunctionArguments.js";
9
3
 
@@ -20,7 +14,7 @@ function extractStringValue(value) {
20
14
  }
21
15
 
22
16
  // Remove surrounding quotes if present
23
- var trimmed = value.trim();
17
+ const trimmed = value.trim();
24
18
  if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
25
19
  return trimmed.slice(1, -1);
26
20
  }
@@ -40,79 +34,66 @@ function cleanStructuredData(data) {
40
34
  // Check all structured data types first using the parser helpers
41
35
 
42
36
  // Check for function calls
43
- var functionCall = isFunction(data);
37
+ const functionCall = isFunction(data);
44
38
  if (functionCall) {
45
39
  // Build a function call string like "console.log('test')"
46
- var argStr = functionCall.arguments.map(function (arg) {
40
+ const argStr = functionCall.arguments.map(arg => {
47
41
  if (Array.isArray(arg)) {
48
- return arg.map(function (a) {
49
- return typeof a === 'string' ? a : String(a);
50
- }).join(', ');
42
+ return arg.map(a => typeof a === 'string' ? a : String(a)).join(', ');
51
43
  }
52
44
  return typeof arg === 'string' ? arg : String(arg);
53
45
  }).join(', ');
54
- return "".concat(functionCall.name, "(").concat(argStr, ")");
46
+ return `${functionCall.name}(${argStr})`;
55
47
  }
56
48
 
57
49
  // Check for generic structures
58
- var generic = isGeneric(data);
50
+ const generic = isGeneric(data);
59
51
  if (generic) {
60
52
  // Build a generic string like "Component<{ foo: string }>"
61
- var genericsStr = generic.generics.map(function (g) {
62
- return typeof g === 'string' ? g : JSON.stringify(g);
63
- }).join(', ');
53
+ const genericsStr = generic.generics.map(g => typeof g === 'string' ? g : JSON.stringify(g)).join(', ');
64
54
  if (generic.arguments && generic.arguments.length > 0) {
65
55
  // Function with generics: Component<T>(args)
66
- var argsStr = generic.arguments.map(function (p) {
67
- return typeof p === 'string' ? p : String(p);
68
- }).join(', ');
69
- return "".concat(generic.name, "<").concat(genericsStr, ">(").concat(argsStr, ")");
56
+ const argsStr = generic.arguments.map(p => typeof p === 'string' ? p : String(p)).join(', ');
57
+ return `${generic.name}<${genericsStr}>(${argsStr})`;
70
58
  }
71
59
  // Type with generics: Component<T>
72
- return "".concat(generic.name, "<").concat(genericsStr, ">");
60
+ return `${generic.name}<${genericsStr}>`;
73
61
  }
74
62
 
75
63
  // Check for type assertions
76
- var typeAssertion = isTypeAssertion(data);
64
+ const typeAssertion = isTypeAssertion(data);
77
65
  if (typeAssertion) {
78
- var cleanedExpression = cleanStructuredData(typeAssertion.expression);
79
- return "".concat(cleanedExpression, " as ").concat(typeAssertion.type);
66
+ const cleanedExpression = cleanStructuredData(typeAssertion.expression);
67
+ return `${cleanedExpression} as ${typeAssertion.type}`;
80
68
  }
81
69
 
82
70
  // Check for arrow functions
83
- var arrowFunction = isArrowFunction(data);
71
+ const arrowFunction = isArrowFunction(data);
84
72
  if (arrowFunction) {
85
- var _argsStr = arrowFunction.args.map(function (p) {
86
- return typeof p === 'string' ? p : String(p);
87
- }).join(', ');
73
+ const argsStr = arrowFunction.args.map(p => typeof p === 'string' ? p : String(p)).join(', ');
88
74
  if (arrowFunction.types) {
89
75
  // Typed arrow function
90
- var _arrowFunction$types = _slicedToArray(arrowFunction.types, 2),
91
- inputType = _arrowFunction$types[0],
92
- outputType = _arrowFunction$types[1];
93
- var _returnValue = cleanStructuredData(arrowFunction.returnValue);
94
- return "(".concat(_argsStr, ": ").concat(inputType, "): ").concat(outputType, " => ").concat(_returnValue);
76
+ const [inputType, outputType] = arrowFunction.types;
77
+ const returnValue = cleanStructuredData(arrowFunction.returnValue);
78
+ return `(${argsStr}: ${inputType}): ${outputType} => ${returnValue}`;
95
79
  }
96
80
 
97
81
  // Simple arrow function
98
- var returnValue = cleanStructuredData(arrowFunction.returnValue);
99
- return "(".concat(_argsStr, ") => ").concat(returnValue);
82
+ const returnValue = cleanStructuredData(arrowFunction.returnValue);
83
+ return `(${argsStr}) => ${returnValue}`;
100
84
  }
101
85
 
102
86
  // Check for literal arrays
103
- var arrayLiteral = isArray(data);
87
+ const arrayLiteral = isArray(data);
104
88
  if (arrayLiteral) {
105
89
  return arrayLiteral.items[0].map(cleanStructuredData);
106
90
  }
107
91
 
108
92
  // Check for object literals
109
- var objectLiteral = isObjectLiteral(data);
93
+ const objectLiteral = isObjectLiteral(data);
110
94
  if (objectLiteral) {
111
- var cleaned = {};
112
- for (var _i = 0, _Object$entries = Object.entries(objectLiteral.properties); _i < _Object$entries.length; _i++) {
113
- var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
114
- key = _Object$entries$_i[0],
115
- value = _Object$entries$_i[1];
95
+ const cleaned = {};
96
+ for (const [key, value] of Object.entries(objectLiteral.properties)) {
116
97
  cleaned[key] = cleanStructuredData(value);
117
98
  }
118
99
  return cleaned;
@@ -122,7 +103,7 @@ function cleanStructuredData(data) {
122
103
 
123
104
  if (typeof data === 'string') {
124
105
  // First extract string value (handle quotes)
125
- var extracted = extractStringValue(data);
106
+ const extracted = extractStringValue(data);
126
107
 
127
108
  // Then try type conversion
128
109
  if (extracted === 'true') {
@@ -134,7 +115,7 @@ function cleanStructuredData(data) {
134
115
 
135
116
  // Check if it's a number (but be conservative about version strings like "1.0")
136
117
  if (/^\d+(\.\d+)?$/.test(extracted)) {
137
- var num = Number(extracted);
118
+ const num = Number(extracted);
138
119
  if (!Number.isNaN(num) && Number.isFinite(num)) {
139
120
  // Don't convert simple version-like patterns (e.g., "1.0", "2.0", but convert "123.45")
140
121
  if (extracted.includes('.')) {
@@ -155,16 +136,13 @@ function cleanStructuredData(data) {
155
136
  // Fallback for arrays that don't match structured patterns
156
137
  return data.map(cleanStructuredData);
157
138
  }
158
- if (data && _typeof(data) === 'object') {
139
+ if (data && typeof data === 'object') {
159
140
  // Fallback for objects that don't match structured patterns
160
- var _cleaned = {};
161
- for (var _i2 = 0, _Object$entries2 = Object.entries(data); _i2 < _Object$entries2.length; _i2++) {
162
- var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
163
- _key = _Object$entries2$_i[0],
164
- _value = _Object$entries2$_i[1];
165
- _cleaned[_key] = cleanStructuredData(_value);
141
+ const cleaned = {};
142
+ for (const [key, value] of Object.entries(data)) {
143
+ cleaned[key] = cleanStructuredData(value);
166
144
  }
167
- return _cleaned;
145
+ return cleaned;
168
146
  }
169
147
  return data;
170
148
  }
@@ -184,26 +162,25 @@ function cleanStructuredData(data) {
184
162
  * Parse variants from object representation (new format)
185
163
  */
186
164
  function parseVariantsObjectFromObject(obj, importMap, namedExportsMap, functionName, filePath) {
187
- var demoImports = {};
188
- var namedExports = {};
189
- for (var _i3 = 0, _Object$entries3 = Object.entries(obj); _i3 < _Object$entries3.length; _i3++) {
190
- var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
191
- key = _Object$entries3$_i[0],
192
- value = _Object$entries3$_i[1];
165
+ const demoImports = {};
166
+ const namedExports = {};
167
+ for (const [key, value] of Object.entries(obj)) {
193
168
  // Handle both string values and structured values (arrays for TypeScript generics)
194
- var importName = void 0;
169
+ let importName;
195
170
 
196
171
  // Use type discriminators to determine the structure type
197
- var typeAssertion = isTypeAssertion(value);
172
+ const typeAssertion = isTypeAssertion(value);
198
173
  if (typeAssertion) {
199
174
  // This is a structured type assertion: ['as', 'React.FC<Props>', 'Component']
200
175
  // Extract the actual component name from the expression
201
- var expression = typeAssertion.expression;
176
+ const {
177
+ expression
178
+ } = typeAssertion;
202
179
  importName = typeof expression === 'string' ? expression : String(expression);
203
180
  } else if (typeof value === 'string') {
204
181
  // Simple string value - strip TypeScript type assertions and typeof expressions
205
- var processedValue = value.trim();
206
- var asIndex = processedValue.indexOf(' as ');
182
+ let processedValue = value.trim();
183
+ const asIndex = processedValue.indexOf(' as ');
207
184
  if (asIndex !== -1) {
208
185
  processedValue = processedValue.substring(0, asIndex).trim();
209
186
  }
@@ -214,9 +191,9 @@ function parseVariantsObjectFromObject(obj, importMap, namedExportsMap, function
214
191
  importName = processedValue;
215
192
  } else {
216
193
  // Handle other structured types (functions, generics, arrays)
217
- var functionCall = isFunction(value);
218
- var generic = isGeneric(value);
219
- var arrayLiteral = isArray(value);
194
+ const functionCall = isFunction(value);
195
+ const generic = isGeneric(value);
196
+ const arrayLiteral = isArray(value);
220
197
  if (functionCall) {
221
198
  // Function call: ['Component', [...]]
222
199
  importName = functionCall.name;
@@ -225,30 +202,30 @@ function parseVariantsObjectFromObject(obj, importMap, namedExportsMap, function
225
202
  importName = generic.name;
226
203
  } else if (arrayLiteral) {
227
204
  // Array literal: handle first element
228
- var firstItem = arrayLiteral.items[0];
205
+ const firstItem = arrayLiteral.items[0];
229
206
  importName = typeof firstItem === 'string' ? firstItem : String(firstItem);
230
207
  } else if (Array.isArray(value) && value.length > 0) {
231
208
  // Fallback for unrecognized array structures
232
- var componentExpression = String(value[0]);
233
- var _asIndex = componentExpression.indexOf(' as ');
234
- importName = _asIndex !== -1 ? componentExpression.substring(0, _asIndex).trim() : componentExpression.trim();
209
+ const componentExpression = String(value[0]);
210
+ const asIndex = componentExpression.indexOf(' as ');
211
+ importName = asIndex !== -1 ? componentExpression.substring(0, asIndex).trim() : componentExpression.trim();
235
212
  } else {
236
213
  // Final fallback - convert to string and extract
237
- var valueStr = String(value);
238
- var _asIndex2 = valueStr.indexOf(' as ');
239
- importName = _asIndex2 !== -1 ? valueStr.substring(0, _asIndex2).trim() : valueStr.trim();
214
+ const valueStr = String(value);
215
+ const asIndex = valueStr.indexOf(' as ');
216
+ importName = asIndex !== -1 ? valueStr.substring(0, asIndex).trim() : valueStr.trim();
240
217
  }
241
218
  }
242
219
  if (importMap.has(importName)) {
243
220
  demoImports[key] = importMap.get(importName);
244
221
  namedExports[key] = namedExportsMap.get(importName);
245
222
  } else {
246
- throw new Error("Invalid variants argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Component '".concat(importName, "' is not imported. Make sure to import it first."));
223
+ throw new Error(`Invalid variants argument in ${functionName} call in ${filePath}. ` + `Component '${importName}' is not imported. Make sure to import it first.`);
247
224
  }
248
225
  }
249
226
  return {
250
227
  variants: demoImports,
251
- namedExports: namedExports
228
+ namedExports
252
229
  };
253
230
  }
254
231
 
@@ -257,31 +234,31 @@ function parseVariantsObjectFromObject(obj, importMap, namedExportsMap, function
257
234
  * that maps import names to their resolved URLs
258
235
  */
259
236
  function buildImportMap(importResult, allowExternalVariants) {
260
- var importMap = new Map();
261
- Object.values(importResult.relative).forEach(function (_ref) {
262
- var url = _ref.url,
263
- names = _ref.names;
264
- names.forEach(function (_ref2) {
265
- var name = _ref2.name,
266
- alias = _ref2.alias;
237
+ const importMap = new Map();
238
+ Object.values(importResult.relative).forEach(({
239
+ url,
240
+ names
241
+ }) => {
242
+ names.forEach(({
243
+ name,
244
+ alias
245
+ }) => {
267
246
  // Use alias if available, otherwise use the original name
268
- var nameToUse = alias || name;
247
+ const nameToUse = alias || name;
269
248
  importMap.set(nameToUse, url);
270
249
  });
271
250
  });
272
251
 
273
252
  // Include external imports if allowExternalVariants is enabled
274
253
  if (allowExternalVariants) {
275
- Object.entries(importResult.externals).forEach(function (_ref3) {
276
- var _ref4 = _slicedToArray(_ref3, 2),
277
- modulePath = _ref4[0],
278
- externalImport = _ref4[1];
254
+ Object.entries(importResult.externals).forEach(([modulePath, externalImport]) => {
279
255
  if (externalImport && externalImport.names) {
280
- externalImport.names.forEach(function (_ref5) {
281
- var name = _ref5.name,
282
- alias = _ref5.alias;
256
+ externalImport.names.forEach(({
257
+ name,
258
+ alias
259
+ }) => {
283
260
  // Use alias if available, otherwise use the original name
284
- var nameToUse = alias || name;
261
+ const nameToUse = alias || name;
285
262
  importMap.set(nameToUse, modulePath);
286
263
  });
287
264
  }
@@ -294,15 +271,17 @@ function buildImportMap(importResult, allowExternalVariants) {
294
271
  * Helper function to build a mapping from import aliases to their original named exports
295
272
  */
296
273
  function buildNamedExportsMap(importResult, allowExternalVariants) {
297
- var namedExportsMap = new Map();
298
- Object.values(importResult.relative).forEach(function (_ref6) {
299
- var names = _ref6.names;
300
- names.forEach(function (_ref7) {
301
- var name = _ref7.name,
302
- alias = _ref7.alias,
303
- type = _ref7.type;
274
+ const namedExportsMap = new Map();
275
+ Object.values(importResult.relative).forEach(({
276
+ names
277
+ }) => {
278
+ names.forEach(({
279
+ name,
280
+ alias,
281
+ type
282
+ }) => {
304
283
  // Use alias if available, otherwise use the original name as key
305
- var nameToUse = alias || name;
284
+ const nameToUse = alias || name;
306
285
 
307
286
  // Only map to the original export name for named imports
308
287
  // Default imports should map to undefined since they don't have a specific named export
@@ -316,16 +295,15 @@ function buildNamedExportsMap(importResult, allowExternalVariants) {
316
295
 
317
296
  // Include external imports if allowExternalVariants is enabled
318
297
  if (allowExternalVariants) {
319
- Object.entries(importResult.externals).forEach(function (_ref8) {
320
- var _ref9 = _slicedToArray(_ref8, 2),
321
- externalImport = _ref9[1];
298
+ Object.entries(importResult.externals).forEach(([, externalImport]) => {
322
299
  if (externalImport && externalImport.names) {
323
- externalImport.names.forEach(function (_ref0) {
324
- var name = _ref0.name,
325
- alias = _ref0.alias,
326
- type = _ref0.type;
300
+ externalImport.names.forEach(({
301
+ name,
302
+ alias,
303
+ type
304
+ }) => {
327
305
  // Use alias if available, otherwise use the original name as key
328
- var nameToUse = alias || name;
306
+ const nameToUse = alias || name;
329
307
 
330
308
  // Only map to the original export name for named imports
331
309
  // Default imports should map to undefined since they don't have a specific named export
@@ -344,55 +322,46 @@ function buildNamedExportsMap(importResult, allowExternalVariants) {
344
322
  * Parses a variants object using pre-parsed structured data
345
323
  */
346
324
  function parseVariantsObjectFromStructured(structuredData, importMap, namedExportsMap, functionName, filePath) {
347
- var demoImports = {};
348
- var namedExports = {};
349
- var _iterator = _createForOfIteratorHelper(structuredData),
350
- _step;
351
- try {
352
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
353
- var item = _step.value;
354
- // If it's a string, process it directly
355
- if (typeof item === 'string') {
356
- var trimmedPart = item.trim();
357
-
358
- // Check if this part contains a colon (key: value syntax)
359
- var colonIndex = trimmedPart.indexOf(':');
360
- if (colonIndex !== -1) {
361
- // Handle "key: value" syntax
362
- var key = trimmedPart.substring(0, colonIndex).trim();
363
- var valueExpression = trimmedPart.substring(colonIndex + 1).trim();
364
-
365
- // Strip TypeScript type assertions (e.g., "Component as React.ComponentType<...>" -> "Component")
366
- var asIndex = valueExpression.indexOf(' as ');
367
- var importName = asIndex !== -1 ? valueExpression.substring(0, asIndex).trim() : valueExpression;
368
- if (importMap.has(importName)) {
369
- demoImports[key] = importMap.get(importName);
370
- namedExports[key] = namedExportsMap.get(importName);
371
- } else {
372
- throw new Error("Invalid variants argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Component '".concat(importName, "' is not imported. Make sure to import it first."));
373
- }
325
+ const demoImports = {};
326
+ const namedExports = {};
327
+ for (const item of structuredData) {
328
+ // If it's a string, process it directly
329
+ if (typeof item === 'string') {
330
+ const trimmedPart = item.trim();
331
+
332
+ // Check if this part contains a colon (key: value syntax)
333
+ const colonIndex = trimmedPart.indexOf(':');
334
+ if (colonIndex !== -1) {
335
+ // Handle "key: value" syntax
336
+ const key = trimmedPart.substring(0, colonIndex).trim();
337
+ const valueExpression = trimmedPart.substring(colonIndex + 1).trim();
338
+
339
+ // Strip TypeScript type assertions (e.g., "Component as React.ComponentType<...>" -> "Component")
340
+ const asIndex = valueExpression.indexOf(' as ');
341
+ const importName = asIndex !== -1 ? valueExpression.substring(0, asIndex).trim() : valueExpression;
342
+ if (importMap.has(importName)) {
343
+ demoImports[key] = importMap.get(importName);
344
+ namedExports[key] = namedExportsMap.get(importName);
374
345
  } else {
375
- // Handle shorthand syntax (just the component name)
376
- var _importName = trimmedPart;
377
- if (importMap.has(_importName)) {
378
- demoImports[_importName] = importMap.get(_importName);
379
- namedExports[_importName] = namedExportsMap.get(_importName);
380
- } else {
381
- throw new Error("Invalid variants argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Component '".concat(_importName, "' is not imported. Make sure to import it first."));
382
- }
346
+ throw new Error(`Invalid variants argument in ${functionName} call in ${filePath}. ` + `Component '${importName}' is not imported. Make sure to import it first.`);
347
+ }
348
+ } else {
349
+ // Handle shorthand syntax (just the component name)
350
+ const importName = trimmedPart;
351
+ if (importMap.has(importName)) {
352
+ demoImports[importName] = importMap.get(importName);
353
+ namedExports[importName] = namedExportsMap.get(importName);
354
+ } else {
355
+ throw new Error(`Invalid variants argument in ${functionName} call in ${filePath}. ` + `Component '${importName}' is not imported. Make sure to import it first.`);
383
356
  }
384
357
  }
385
- // If it's an array (nested structure), we don't expect this in variants parsing
386
- // but we could handle it if needed in the future
387
358
  }
388
- } catch (err) {
389
- _iterator.e(err);
390
- } finally {
391
- _iterator.f();
359
+ // If it's an array (nested structure), we don't expect this in variants parsing
360
+ // but we could handle it if needed in the future
392
361
  }
393
362
  return {
394
363
  variants: demoImports,
395
- namedExports: namedExports
364
+ namedExports
396
365
  };
397
366
  }
398
367
 
@@ -401,7 +370,7 @@ function parseVariantsObjectFromStructured(structuredData, importMap, namedExpor
401
370
  */
402
371
  function parseVariantsArgumentFromStructured(structuredVariants, importMap, namedExportsMap, functionName, filePath) {
403
372
  // If it's an object (Record<string, string>)
404
- if (_typeof(structuredVariants) === 'object' && !Array.isArray(structuredVariants)) {
373
+ if (typeof structuredVariants === 'object' && !Array.isArray(structuredVariants)) {
405
374
  // We have an object with key-value pairs
406
375
  return parseVariantsObjectFromObject(structuredVariants, importMap, namedExportsMap, functionName, filePath);
407
376
  }
@@ -414,10 +383,10 @@ function parseVariantsArgumentFromStructured(structuredVariants, importMap, name
414
383
 
415
384
  // If it's a single identifier string
416
385
  if (typeof structuredVariants === 'string') {
417
- var componentName = structuredVariants.trim();
386
+ let componentName = structuredVariants.trim();
418
387
 
419
388
  // Handle TypeScript type assertions in single component syntax
420
- var asIndex = componentName.indexOf(' as ');
389
+ const asIndex = componentName.indexOf(' as ');
421
390
  if (asIndex !== -1) {
422
391
  componentName = componentName.substring(0, asIndex).trim();
423
392
  }
@@ -438,11 +407,11 @@ function parseVariantsArgumentFromStructured(structuredVariants, importMap, name
438
407
  }
439
408
 
440
409
  // Throw error if the identifier is not found in imports
441
- throw new Error("Invalid variants argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Component '".concat(componentName, "' is not imported. Make sure to import it first."));
410
+ throw new Error(`Invalid variants argument in ${functionName} call in ${filePath}. ` + `Component '${componentName}' is not imported. Make sure to import it first.`);
442
411
  }
443
412
 
444
413
  // If we reach here, the structured data format is unexpected
445
- throw new Error("Unexpected structured variants format in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected string, array, or object but got: ".concat(_typeof(structuredVariants)));
414
+ throw new Error(`Unexpected structured variants format in ${functionName} call in ${filePath}. ` + `Expected string, array, or object but got: ${typeof structuredVariants}`);
446
415
  }
447
416
 
448
417
  /**
@@ -456,20 +425,20 @@ function parseGenericDefinitions(genericContent) {
456
425
  }
457
426
 
458
427
  // Handle object literals directly (most common case)
459
- var trimmed = genericContent.trim();
428
+ const trimmed = genericContent.trim();
460
429
  if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
461
430
  // Parse as object literal using the existing parser
462
- var _parsed = parseFunctionArguments(trimmed);
463
- if (_parsed.length === 1 && _typeof(_parsed[0]) === 'object' && !Array.isArray(_parsed[0])) {
464
- return _parsed[0];
431
+ const parsed = parseFunctionArguments(trimmed);
432
+ if (parsed.length === 1 && typeof parsed[0] === 'object' && !Array.isArray(parsed[0])) {
433
+ return parsed[0];
465
434
  }
466
435
  }
467
436
 
468
437
  // Parse the generic content using the existing parser
469
- var parsed = parseFunctionArguments(genericContent);
438
+ const parsed = parseFunctionArguments(genericContent);
470
439
 
471
440
  // If it's a single object, return it
472
- if (parsed.length === 1 && _typeof(parsed[0]) === 'object' && !Array.isArray(parsed[0])) {
441
+ if (parsed.length === 1 && typeof parsed[0] === 'object' && !Array.isArray(parsed[0])) {
473
442
  return parsed[0];
474
443
  }
475
444
 
@@ -482,11 +451,11 @@ function parseGenericDefinitions(genericContent) {
482
451
 
483
452
  // If it's multiple elements, try to interpret as an object
484
453
  if (parsed.length > 1) {
485
- var result = {};
486
- parsed.forEach(function (item, index) {
454
+ const result = {};
455
+ parsed.forEach((item, index) => {
487
456
  if (typeof item === 'string') {
488
- result["Variant".concat(index + 1)] = item;
489
- } else if (_typeof(item) === 'object' && item !== null) {
457
+ result[`Variant${index + 1}`] = item;
458
+ } else if (typeof item === 'object' && item !== null) {
490
459
  Object.assign(result, item);
491
460
  }
492
461
  });
@@ -499,7 +468,7 @@ function parseGenericDefinitions(genericContent) {
499
468
  * Validates that a URL argument follows the expected convention
500
469
  */
501
470
  function validateUrlArgument(url, functionName, filePath) {
502
- var trimmedUrl = url.trim();
471
+ const trimmedUrl = url.trim();
503
472
 
504
473
  // Only accept import.meta.url
505
474
  if (trimmedUrl === 'import.meta.url') {
@@ -508,8 +477,8 @@ function validateUrlArgument(url, functionName, filePath) {
508
477
 
509
478
  // For error messages, show the argument as parsed by parseFunctionArguments
510
479
  // Simple string literals preserve their quotes, complex expressions are shown as parsed
511
- var errorUrl = trimmedUrl;
512
- throw new Error("Invalid URL argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 'import.meta.url' but got: ".concat(errorUrl));
480
+ const errorUrl = trimmedUrl;
481
+ throw new Error(`Invalid URL argument in ${functionName} call in ${filePath}. ` + `Expected 'import.meta.url' but got: ${errorUrl}`);
513
482
  }
514
483
 
515
484
  /**
@@ -517,23 +486,23 @@ function validateUrlArgument(url, functionName, filePath) {
517
486
  */
518
487
  function validateVariantsArgument(structuredVariants, functionName, filePath) {
519
488
  if (!structuredVariants) {
520
- throw new Error("Invalid variants argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object mapping variant names to imports or a single component identifier.");
489
+ throw new Error(`Invalid variants argument in ${functionName} call in ${filePath}. ` + `Expected an object mapping variant names to imports or a single component identifier.`);
521
490
  }
522
491
 
523
492
  // Check if it's a valid single identifier (string)
524
493
  if (typeof structuredVariants === 'string') {
525
- var trimmed = structuredVariants.trim();
494
+ const trimmed = structuredVariants.trim();
526
495
  if (!trimmed || !/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(trimmed)) {
527
- throw new Error("Invalid variants argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected a valid component identifier, but got: \"".concat(trimmed, "\""));
496
+ throw new Error(`Invalid variants argument in ${functionName} call in ${filePath}. ` + `Expected a valid component identifier, but got: "${trimmed}"`);
528
497
  }
529
498
  return; // Valid identifier
530
499
  }
531
500
 
532
501
  // Check if it's an array (object literal structure) or object (parsed key-value pairs)
533
- if (Array.isArray(structuredVariants) || _typeof(structuredVariants) === 'object' && structuredVariants !== null) {
502
+ if (Array.isArray(structuredVariants) || typeof structuredVariants === 'object' && structuredVariants !== null) {
534
503
  return; // Valid object structure
535
504
  }
536
- throw new Error("Invalid variants argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object mapping variant names to imports or a single component identifier, but got: ".concat(_typeof(structuredVariants)));
505
+ throw new Error(`Invalid variants argument in ${functionName} call in ${filePath}. ` + `Expected an object mapping variant names to imports or a single component identifier, but got: ${typeof structuredVariants}`);
537
506
  }
538
507
 
539
508
  /**
@@ -541,260 +510,197 @@ function validateVariantsArgument(structuredVariants, functionName, filePath) {
541
510
  * Returns the parsed result with remaining content included
542
511
  * Returns null if no create* call is found
543
512
  */
544
- export function parseCreateFactoryCall(_x, _x2) {
545
- return _parseCreateFactoryCall.apply(this, arguments);
513
+ export async function parseCreateFactoryCall(code, filePath, parseOptions = {}, importsAndComments) {
514
+ // Find the first create* call in the code
515
+ const match = findFirstCreateFactoryCall(code, filePath, parseOptions);
516
+
517
+ // Return null if no create* call found
518
+ if (!match) {
519
+ return null;
520
+ }
521
+
522
+ // Check for multiple create* calls if allowMultipleFactories is false
523
+ if (!parseOptions.allowMultipleFactories) {
524
+ const secondMatch = findFirstCreateFactoryCall(code, filePath, parseOptions, match.functionEndIndex + 1);
525
+ if (secondMatch) {
526
+ throw new Error(`Multiple create* factory calls found in ${filePath}. Only one create* call per file is supported. Found 2 calls.`);
527
+ }
528
+ }
529
+ // Get import mappings from precomputed imports or parse them
530
+ importsAndComments = importsAndComments || (await parseImportsAndComments(code, filePath));
531
+
532
+ // Process the match using shared logic
533
+ const parsed = await processCreateFactoryMatch(match, code, filePath, parseOptions, importsAndComments);
534
+
535
+ // Calculate remaining content after the function call
536
+ const remaining = code.substring(match.functionEndIndex + 1);
537
+ return {
538
+ ...parsed,
539
+ remaining,
540
+ importsAndComments // Include import data for reuse
541
+ };
546
542
  }
547
543
 
548
544
  /**
549
545
  * Parses all create* factory calls in a file sequentially
550
546
  * Returns a record of export names mapped to their parsed factory calls
551
547
  */
552
- function _parseCreateFactoryCall() {
553
- _parseCreateFactoryCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(code, filePath) {
554
- var parseOptions,
555
- importsAndComments,
556
- match,
557
- secondMatch,
558
- parsed,
559
- remaining,
560
- _args = arguments,
561
- _t;
562
- return _regenerator().w(function (_context) {
563
- while (1) switch (_context.n) {
564
- case 0:
565
- parseOptions = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
566
- importsAndComments = _args.length > 3 ? _args[3] : undefined;
567
- // Find the first create* call in the code
568
- match = findFirstCreateFactoryCall(code, filePath, parseOptions); // Return null if no create* call found
569
- if (match) {
570
- _context.n = 1;
571
- break;
572
- }
573
- return _context.a(2, null);
574
- case 1:
575
- if (parseOptions.allowMultipleFactories) {
576
- _context.n = 2;
577
- break;
578
- }
579
- secondMatch = findFirstCreateFactoryCall(code, filePath, parseOptions, match.functionEndIndex + 1);
580
- if (!secondMatch) {
581
- _context.n = 2;
582
- break;
583
- }
584
- throw new Error("Multiple create* factory calls found in ".concat(filePath, ". Only one create* call per file is supported. Found 2 calls."));
585
- case 2:
586
- _t = importsAndComments;
587
- if (_t) {
588
- _context.n = 4;
589
- break;
590
- }
591
- _context.n = 3;
592
- return parseImportsAndComments(code, filePath);
593
- case 3:
594
- _t = _context.v;
595
- case 4:
596
- importsAndComments = _t;
597
- _context.n = 5;
598
- return processCreateFactoryMatch(match, code, filePath, parseOptions, importsAndComments);
599
- case 5:
600
- parsed = _context.v;
601
- // Calculate remaining content after the function call
602
- remaining = code.substring(match.functionEndIndex + 1);
603
- return _context.a(2, _extends(_extends({}, parsed), {}, {
604
- remaining: remaining,
605
- importsAndComments: importsAndComments // Include import data for reuse
606
- }));
607
- }
608
- }, _callee);
609
- }));
610
- return _parseCreateFactoryCall.apply(this, arguments);
611
- }
612
- export function parseAllCreateFactoryCalls(_x3, _x4) {
613
- return _parseAllCreateFactoryCalls.apply(this, arguments);
548
+ export async function parseAllCreateFactoryCalls(code, filePath, parseOptions = {}) {
549
+ const results = {};
550
+ let importsAndComments;
551
+ let searchIndex = 0;
552
+
553
+ // Process the code using single-pass approach
554
+ while (searchIndex < code.length) {
555
+ // Find the next create* call
556
+ const match = findFirstCreateFactoryCall(code, filePath, parseOptions, searchIndex);
557
+ if (!match) {
558
+ // No more create* calls found
559
+ break;
560
+ }
561
+
562
+ // Extract export name from the function call context
563
+ const beforeMatch = code.substring(0, match.functionStartIndex);
564
+ const exportMatch = beforeMatch.match(/export\s+const\s+(\w+)\s*=\s*$/m);
565
+ const exportName = exportMatch?.[1] || 'unknown';
566
+
567
+ // Get import mappings from precomputed imports or parse them
568
+ // eslint-disable-next-line no-await-in-loop
569
+ importsAndComments = importsAndComments || (await parseImportsAndComments(code, filePath));
570
+
571
+ // Process the match using shared logic
572
+ // eslint-disable-next-line no-await-in-loop
573
+ const parsedFactory = await processCreateFactoryMatch(match, code, filePath, parseOptions, importsAndComments);
574
+ results[exportName] = parsedFactory;
575
+
576
+ // Continue searching from after this function call
577
+ searchIndex = match.functionEndIndex + 1;
578
+ }
579
+ return results;
614
580
  }
615
581
 
616
582
  /**
617
583
  * Processes a matched create* factory call into a ParsedCreateFactory object
618
584
  * Handles all the common logic for validation, parsing, and transformation
619
585
  */
620
- function _parseAllCreateFactoryCalls() {
621
- _parseAllCreateFactoryCalls = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(code, filePath) {
622
- var parseOptions,
623
- results,
624
- importsAndComments,
625
- searchIndex,
626
- match,
627
- beforeMatch,
628
- exportMatch,
629
- exportName,
630
- parsedFactory,
631
- _args2 = arguments,
632
- _t2;
633
- return _regenerator().w(function (_context2) {
634
- while (1) switch (_context2.n) {
635
- case 0:
636
- parseOptions = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
637
- results = {};
638
- searchIndex = 0; // Process the code using single-pass approach
639
- case 1:
640
- if (!(searchIndex < code.length)) {
641
- _context2.n = 6;
642
- break;
643
- }
644
- // Find the next create* call
645
- match = findFirstCreateFactoryCall(code, filePath, parseOptions, searchIndex);
646
- if (match) {
647
- _context2.n = 2;
648
- break;
649
- }
650
- return _context2.a(3, 6);
651
- case 2:
652
- // Extract export name from the function call context
653
- beforeMatch = code.substring(0, match.functionStartIndex);
654
- exportMatch = beforeMatch.match(/export\s+const\s+(\w+)\s*=\s*$/m);
655
- exportName = (exportMatch == null ? void 0 : exportMatch[1]) || 'unknown'; // Get import mappings from precomputed imports or parse them
656
- // eslint-disable-next-line no-await-in-loop
657
- _t2 = importsAndComments;
658
- if (_t2) {
659
- _context2.n = 4;
660
- break;
661
- }
662
- _context2.n = 3;
663
- return parseImportsAndComments(code, filePath);
664
- case 3:
665
- _t2 = _context2.v;
666
- case 4:
667
- importsAndComments = _t2;
668
- _context2.n = 5;
669
- return processCreateFactoryMatch(match, code, filePath, parseOptions, importsAndComments);
670
- case 5:
671
- parsedFactory = _context2.v;
672
- results[exportName] = parsedFactory;
673
-
674
- // Continue searching from after this function call
675
- searchIndex = match.functionEndIndex + 1;
676
- _context2.n = 1;
677
- break;
678
- case 6:
679
- return _context2.a(2, results);
586
+ async function processCreateFactoryMatch(match, code, filePath, parseOptions, importsAndComments) {
587
+ const {
588
+ functionName,
589
+ fullMatch,
590
+ urlArg,
591
+ structuredVariants,
592
+ optionsStructured,
593
+ hasOptions,
594
+ argumentsStartIndex,
595
+ argumentsEndIndex
596
+ } = match;
597
+ const allowExternalVariants = parseOptions.allowExternalVariants || false;
598
+ const importMap = buildImportMap(importsAndComments, allowExternalVariants);
599
+ const namedExportsMap = buildNamedExportsMap(importsAndComments, allowExternalVariants);
600
+ const externals = importsAndComments.externals;
601
+
602
+ // Validate URL argument
603
+ validateUrlArgument(urlArg, functionName, filePath);
604
+
605
+ // Validate variants argument (skip in metadata-only mode)
606
+ const {
607
+ metadataOnly = false
608
+ } = parseOptions;
609
+ if (!metadataOnly && structuredVariants !== undefined) {
610
+ validateVariantsArgument(structuredVariants, functionName, filePath);
611
+ }
612
+
613
+ // Extract URL (typically import.meta.url)
614
+ const url = urlArg.trim();
615
+
616
+ // Resolve variants using structured data (skip in metadata-only mode)
617
+ let variants;
618
+ let namedExports;
619
+ if (!metadataOnly) {
620
+ if (structuredVariants !== undefined) {
621
+ // Use regular variants argument
622
+ const variantsResult = parseVariantsArgumentFromStructured(structuredVariants, importMap, namedExportsMap, functionName, filePath);
623
+ variants = variantsResult.variants;
624
+ namedExports = variantsResult.namedExports;
625
+ } else if (match.hasGenerics && match.structuredGenerics && Object.keys(match.structuredGenerics).length > 0) {
626
+ // Use generics as variants when no variants argument is provided and generics are not empty
627
+ const variantsResult = parseVariantsArgumentFromStructured(match.structuredGenerics, importMap, namedExportsMap, functionName, filePath);
628
+ variants = variantsResult.variants;
629
+ namedExports = variantsResult.namedExports;
630
+ }
631
+ }
632
+
633
+ // Parse options object
634
+ // Initialize with all options from structured data, then override specific fields
635
+ const options = optionsStructured && typeof optionsStructured === 'object' ? cleanStructuredData(optionsStructured) : {};
636
+
637
+ // Override with specific processing for known fields that need special handling
638
+ if (optionsStructured && typeof optionsStructured === 'object') {
639
+ if ('name' in optionsStructured) {
640
+ options.name = extractStringValue(optionsStructured.name);
641
+ }
642
+ if ('slug' in optionsStructured) {
643
+ options.slug = extractStringValue(optionsStructured.slug);
644
+ }
645
+ if ('skipPrecompute' in optionsStructured) {
646
+ const skipPrecomputeValue = optionsStructured.skipPrecompute;
647
+ if (skipPrecomputeValue === 'true' || skipPrecomputeValue === true) {
648
+ options.skipPrecompute = true;
649
+ } else if (skipPrecomputeValue === 'false' || skipPrecomputeValue === false) {
650
+ options.skipPrecompute = false;
680
651
  }
681
- }, _callee2);
682
- }));
683
- return _parseAllCreateFactoryCalls.apply(this, arguments);
684
- }
685
- function processCreateFactoryMatch(_x5, _x6, _x7, _x8, _x9) {
686
- return _processCreateFactoryMatch.apply(this, arguments);
652
+ }
653
+
654
+ // Handle precompute from structured data - clean for user consumption
655
+ if ('precompute' in optionsStructured) {
656
+ options.precompute = cleanStructuredData(optionsStructured.precompute);
657
+ }
658
+ }
659
+
660
+ // Transform externals from parseImportsAndComments format to simplified format
661
+ // Only include side-effect imports (where names array is empty)
662
+ const transformedExternals = {};
663
+ for (const [modulePath, externalImport] of Object.entries(externals)) {
664
+ // Only include side-effect imports (empty names array)
665
+ if (externalImport.names.length === 0) {
666
+ transformedExternals[modulePath] = []; // Empty array for side-effect imports
667
+ }
668
+ }
669
+ return {
670
+ functionName,
671
+ url,
672
+ variants,
673
+ namedExports,
674
+ options,
675
+ fullMatch,
676
+ hasOptions,
677
+ externals: transformedExternals,
678
+ argumentsStartIndex,
679
+ argumentsEndIndex,
680
+ // Add structured data for serialization - this preserves quotes for proper output
681
+ structuredUrl: urlArg,
682
+ structuredVariants,
683
+ structuredOptions: optionsStructured,
684
+ // Use original structured data, not cleaned options
685
+ hasGenerics: match.hasGenerics,
686
+ structuredGenerics: match.structuredGenerics
687
+ };
687
688
  }
689
+
688
690
  /**
689
691
  * Finds the first create* factory call in code, starting from a given index
690
692
  * Returns null if no create* call is found
691
693
  */
692
- function _processCreateFactoryMatch() {
693
- _processCreateFactoryMatch = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(match, code, filePath, parseOptions, importsAndComments) {
694
- var functionName, fullMatch, urlArg, structuredVariants, optionsStructured, hasOptions, argumentsStartIndex, argumentsEndIndex, allowExternalVariants, importMap, namedExportsMap, externals, _parseOptions$metadat2, metadataOnly, url, variants, namedExports, variantsResult, _variantsResult, options, skipPrecomputeValue, transformedExternals, _i5, _Object$entries4, _Object$entries4$_i, modulePath, externalImport;
695
- return _regenerator().w(function (_context3) {
696
- while (1) switch (_context3.n) {
697
- case 0:
698
- functionName = match.functionName, fullMatch = match.fullMatch, urlArg = match.urlArg, structuredVariants = match.structuredVariants, optionsStructured = match.optionsStructured, hasOptions = match.hasOptions, argumentsStartIndex = match.argumentsStartIndex, argumentsEndIndex = match.argumentsEndIndex;
699
- allowExternalVariants = parseOptions.allowExternalVariants || false;
700
- importMap = buildImportMap(importsAndComments, allowExternalVariants);
701
- namedExportsMap = buildNamedExportsMap(importsAndComments, allowExternalVariants);
702
- externals = importsAndComments.externals; // Validate URL argument
703
- validateUrlArgument(urlArg, functionName, filePath);
704
-
705
- // Validate variants argument (skip in metadata-only mode)
706
- _parseOptions$metadat2 = parseOptions.metadataOnly, metadataOnly = _parseOptions$metadat2 === void 0 ? false : _parseOptions$metadat2;
707
- if (!metadataOnly && structuredVariants !== undefined) {
708
- validateVariantsArgument(structuredVariants, functionName, filePath);
709
- }
710
-
711
- // Extract URL (typically import.meta.url)
712
- url = urlArg.trim(); // Resolve variants using structured data (skip in metadata-only mode)
713
- if (!metadataOnly) {
714
- if (structuredVariants !== undefined) {
715
- // Use regular variants argument
716
- variantsResult = parseVariantsArgumentFromStructured(structuredVariants, importMap, namedExportsMap, functionName, filePath);
717
- variants = variantsResult.variants;
718
- namedExports = variantsResult.namedExports;
719
- } else if (match.hasGenerics && match.structuredGenerics && Object.keys(match.structuredGenerics).length > 0) {
720
- // Use generics as variants when no variants argument is provided and generics are not empty
721
- _variantsResult = parseVariantsArgumentFromStructured(match.structuredGenerics, importMap, namedExportsMap, functionName, filePath);
722
- variants = _variantsResult.variants;
723
- namedExports = _variantsResult.namedExports;
724
- }
725
- }
726
-
727
- // Parse options object
728
- // Initialize with all options from structured data, then override specific fields
729
- options = optionsStructured && _typeof(optionsStructured) === 'object' ? cleanStructuredData(optionsStructured) : {}; // Override with specific processing for known fields that need special handling
730
- if (optionsStructured && _typeof(optionsStructured) === 'object') {
731
- if ('name' in optionsStructured) {
732
- options.name = extractStringValue(optionsStructured.name);
733
- }
734
- if ('slug' in optionsStructured) {
735
- options.slug = extractStringValue(optionsStructured.slug);
736
- }
737
- if ('skipPrecompute' in optionsStructured) {
738
- skipPrecomputeValue = optionsStructured.skipPrecompute;
739
- if (skipPrecomputeValue === 'true' || skipPrecomputeValue === true) {
740
- options.skipPrecompute = true;
741
- } else if (skipPrecomputeValue === 'false' || skipPrecomputeValue === false) {
742
- options.skipPrecompute = false;
743
- }
744
- }
745
-
746
- // Handle precompute from structured data - clean for user consumption
747
- if ('precompute' in optionsStructured) {
748
- options.precompute = cleanStructuredData(optionsStructured.precompute);
749
- }
750
- }
751
-
752
- // Transform externals from parseImportsAndComments format to simplified format
753
- // Only include side-effect imports (where names array is empty)
754
- transformedExternals = {};
755
- for (_i5 = 0, _Object$entries4 = Object.entries(externals); _i5 < _Object$entries4.length; _i5++) {
756
- _Object$entries4$_i = _slicedToArray(_Object$entries4[_i5], 2), modulePath = _Object$entries4$_i[0], externalImport = _Object$entries4$_i[1];
757
- // Only include side-effect imports (empty names array)
758
- if (externalImport.names.length === 0) {
759
- transformedExternals[modulePath] = []; // Empty array for side-effect imports
760
- }
761
- }
762
- return _context3.a(2, {
763
- functionName: functionName,
764
- url: url,
765
- variants: variants,
766
- namedExports: namedExports,
767
- options: options,
768
- fullMatch: fullMatch,
769
- hasOptions: hasOptions,
770
- externals: transformedExternals,
771
- argumentsStartIndex: argumentsStartIndex,
772
- argumentsEndIndex: argumentsEndIndex,
773
- // Add structured data for serialization - this preserves quotes for proper output
774
- structuredUrl: urlArg,
775
- structuredVariants: structuredVariants,
776
- structuredOptions: optionsStructured,
777
- // Use original structured data, not cleaned options
778
- hasGenerics: match.hasGenerics,
779
- structuredGenerics: match.structuredGenerics
780
- });
781
- }
782
- }, _callee3);
783
- }));
784
- return _processCreateFactoryMatch.apply(this, arguments);
785
- }
786
- function findFirstCreateFactoryCall(code, filePath) {
787
- var parseOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
788
- var startIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
789
- var createFunctionRegex = /\b(create\w*)\s*/g;
694
+ function findFirstCreateFactoryCall(code, filePath, parseOptions = {}, startIndex = 0) {
695
+ const createFunctionRegex = /\b(create\w*)\s*/g;
790
696
  createFunctionRegex.lastIndex = startIndex;
791
- var match = createFunctionRegex.exec(code);
697
+ const match = createFunctionRegex.exec(code);
792
698
  if (!match) {
793
699
  return null;
794
700
  }
795
- var functionName = match[1];
796
- var matchStartIndex = match.index;
797
- var currentIndex = match.index + match[0].length;
701
+ const functionName = match[1];
702
+ const matchStartIndex = match.index;
703
+ let currentIndex = match.index + match[0].length;
798
704
 
799
705
  // Skip any whitespace after function name
800
706
  while (currentIndex < code.length && /\s/.test(code[currentIndex])) {
@@ -804,21 +710,21 @@ function findFirstCreateFactoryCall(code, filePath) {
804
710
  // No opening parenthesis found, try to find the next create* call
805
711
  return findFirstCreateFactoryCall(code, filePath, parseOptions, match.index + match[0].length);
806
712
  }
807
- var genericContent = '';
808
- var hasGenerics = false;
713
+ let genericContent = '';
714
+ let hasGenerics = false;
809
715
 
810
716
  // Check if we have generics (starts with <)
811
717
  if (code[currentIndex] === '<') {
812
718
  hasGenerics = true;
813
- var angleCount = 1;
814
- var genericEndIndex = -1;
719
+ let angleCount = 1;
720
+ let genericEndIndex = -1;
815
721
 
816
722
  // Find the matching closing angle bracket, handling nesting
817
- for (var i = currentIndex + 1; i < code.length; i += 1) {
818
- var _char = code[i];
819
- if (_char === '<') {
723
+ for (let i = currentIndex + 1; i < code.length; i += 1) {
724
+ const char = code[i];
725
+ if (char === '<') {
820
726
  angleCount += 1;
821
- } else if (_char === '>') {
727
+ } else if (char === '>') {
822
728
  angleCount -= 1;
823
729
  if (angleCount === 0) {
824
730
  genericEndIndex = i;
@@ -844,18 +750,18 @@ function findFirstCreateFactoryCall(code, filePath) {
844
750
  // No opening parenthesis found, try to find the next create* call
845
751
  return findFirstCreateFactoryCall(code, filePath, parseOptions, match.index + match[0].length);
846
752
  }
847
- var parenIndex = currentIndex;
753
+ const parenIndex = currentIndex;
848
754
 
849
755
  // Find the matching closing parenthesis
850
- var parenCount = 0;
851
- var endIndex = -1;
852
- for (var _i4 = parenIndex; _i4 < code.length; _i4 += 1) {
853
- if (code[_i4] === '(') {
756
+ let parenCount = 0;
757
+ let endIndex = -1;
758
+ for (let i = parenIndex; i < code.length; i += 1) {
759
+ if (code[i] === '(') {
854
760
  parenCount += 1;
855
- } else if (code[_i4] === ')') {
761
+ } else if (code[i] === ')') {
856
762
  parenCount -= 1;
857
763
  if (parenCount === 0) {
858
- endIndex = _i4;
764
+ endIndex = i;
859
765
  break;
860
766
  }
861
767
  }
@@ -864,53 +770,53 @@ function findFirstCreateFactoryCall(code, filePath) {
864
770
  // Unmatched parentheses, try to find the next create* call
865
771
  return findFirstCreateFactoryCall(code, filePath, parseOptions, match.index + match[0].length);
866
772
  }
867
- var fullMatch = code.substring(matchStartIndex, endIndex + 1);
868
- var content = code.substring(parenIndex + 1, endIndex);
773
+ const fullMatch = code.substring(matchStartIndex, endIndex + 1);
774
+ const content = code.substring(parenIndex + 1, endIndex);
869
775
 
870
776
  // Parse generic content if present
871
- var structuredGenerics;
777
+ let structuredGenerics;
872
778
  if (hasGenerics) {
873
779
  // Parse the generic content as TypeScript type definitions
874
780
  structuredGenerics = parseGenericDefinitions(genericContent);
875
781
  }
876
782
 
877
783
  // Split by commas at the top level, handling nested structures and comments
878
- var structured = parseFunctionArguments(content);
784
+ const structured = parseFunctionArguments(content);
879
785
 
880
786
  // Validate the function follows the convention
881
- var _parseOptions$metadat = parseOptions.metadataOnly,
882
- metadataOnly = _parseOptions$metadat === void 0 ? false : _parseOptions$metadat;
787
+ const {
788
+ metadataOnly = false
789
+ } = parseOptions;
883
790
  if (metadataOnly) {
884
791
  // For metadata-only mode: expect 1-2 arguments (url, options?)
885
792
  if (structured.length < 1 || structured.length > 2) {
886
- throw new Error("Invalid ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 1-2 arguments (url, options?) but got ".concat(structured.length, " arguments. ") + "In metadata-only mode, functions should follow: create*(url, options?)");
793
+ throw new Error(`Invalid ${functionName} call in ${filePath}. ` + `Expected 1-2 arguments (url, options?) but got ${structured.length} arguments. ` + `In metadata-only mode, functions should follow: create*(url, options?)`);
887
794
  }
888
795
  } else if (hasGenerics && structured.length <= 2) {
889
796
  // When generics are present AND we have 1-2 arguments, expect (url, options?)
890
797
  if (structured.length < 1 || structured.length > 2) {
891
- throw new Error("Invalid ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 1-2 arguments (url, options?) but got ".concat(structured.length, " arguments. ") + "Functions with TypeScript generics should follow: create*<variants>(url, options?)");
798
+ throw new Error(`Invalid ${functionName} call in ${filePath}. ` + `Expected 1-2 arguments (url, options?) but got ${structured.length} arguments. ` + `Functions with TypeScript generics should follow: create*<variants>(url, options?)`);
892
799
  }
893
800
  } else if (!hasGenerics && (structured.length < 2 || structured.length > 3)) {
894
801
  // Normal mode: expect 2-3 arguments (url, variants, options?)
895
- throw new Error("Invalid ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 2-3 arguments (url, variants, options?) but got ".concat(structured.length, " arguments. ") + "Functions starting with 'create' must follow the convention: create*(url, variants, options?)");
802
+ throw new Error(`Invalid ${functionName} call in ${filePath}. ` + `Expected 2-3 arguments (url, variants, options?) but got ${structured.length} arguments. ` + `Functions starting with 'create' must follow the convention: create*(url, variants, options?)`);
896
803
  }
897
804
 
898
805
  // Handle different argument patterns based on mode
899
806
  if (metadataOnly) {
900
807
  // Metadata-only mode: expect 1-2 arguments (url, options?)
901
808
  if (structured.length === 1) {
902
- var _structured = _slicedToArray(structured, 1),
903
- urlArg = _structured[0];
809
+ const [urlArg] = structured;
904
810
  return {
905
- functionName: functionName,
906
- fullMatch: fullMatch,
811
+ functionName,
812
+ fullMatch,
907
813
  urlArg: typeof urlArg === 'string' ? urlArg.trim() : String(urlArg),
908
814
  structuredVariants: hasGenerics ? structuredGenerics : undefined,
909
815
  // Use generics as variants in metadata-only mode
910
816
  optionsStructured: undefined,
911
817
  hasOptions: false,
912
- hasGenerics: hasGenerics,
913
- structuredGenerics: structuredGenerics,
818
+ hasGenerics,
819
+ structuredGenerics,
914
820
  functionStartIndex: matchStartIndex,
915
821
  functionEndIndex: endIndex,
916
822
  argumentsStartIndex: parenIndex + 1,
@@ -918,24 +824,22 @@ function findFirstCreateFactoryCall(code, filePath) {
918
824
  };
919
825
  }
920
826
  if (structured.length === 2) {
921
- var _structured2 = _slicedToArray(structured, 2),
922
- _urlArg = _structured2[0],
923
- optionsStructured = _structured2[1];
827
+ const [urlArg, optionsStructured] = structured;
924
828
 
925
829
  // Options should be an object
926
- if (typeof optionsStructured === 'string' || !Array.isArray(optionsStructured) && _typeof(optionsStructured) !== 'object') {
927
- throw new Error("Invalid options argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object but got: ".concat(typeof optionsStructured === 'string' ? optionsStructured : JSON.stringify(optionsStructured)));
830
+ if (typeof optionsStructured === 'string' || !Array.isArray(optionsStructured) && typeof optionsStructured !== 'object') {
831
+ throw new Error(`Invalid options argument in ${functionName} call in ${filePath}. ` + `Expected an object but got: ${typeof optionsStructured === 'string' ? optionsStructured : JSON.stringify(optionsStructured)}`);
928
832
  }
929
833
  return {
930
- functionName: functionName,
931
- fullMatch: fullMatch,
932
- urlArg: typeof _urlArg === 'string' ? _urlArg.trim() : String(_urlArg),
834
+ functionName,
835
+ fullMatch,
836
+ urlArg: typeof urlArg === 'string' ? urlArg.trim() : String(urlArg),
933
837
  structuredVariants: hasGenerics ? structuredGenerics : undefined,
934
838
  // Use generics as variants in metadata-only mode
935
- optionsStructured: _typeof(optionsStructured) === 'object' && optionsStructured !== null ? optionsStructured : undefined,
839
+ optionsStructured: typeof optionsStructured === 'object' && optionsStructured !== null ? optionsStructured : undefined,
936
840
  hasOptions: true,
937
- hasGenerics: hasGenerics,
938
- structuredGenerics: structuredGenerics,
841
+ hasGenerics,
842
+ structuredGenerics,
939
843
  functionStartIndex: matchStartIndex,
940
844
  functionEndIndex: endIndex,
941
845
  argumentsStartIndex: parenIndex + 1,
@@ -944,18 +848,17 @@ function findFirstCreateFactoryCall(code, filePath) {
944
848
  }
945
849
  } else if (!metadataOnly && hasGenerics && structured.length === 1) {
946
850
  // Generics-only mode (non-metadata): expect 1 argument (url) - use generics as variants
947
- var _structured3 = _slicedToArray(structured, 1),
948
- _urlArg2 = _structured3[0];
851
+ const [urlArg] = structured;
949
852
  return {
950
- functionName: functionName,
951
- fullMatch: fullMatch,
952
- urlArg: typeof _urlArg2 === 'string' ? _urlArg2.trim() : String(_urlArg2),
853
+ functionName,
854
+ fullMatch,
855
+ urlArg: typeof urlArg === 'string' ? urlArg.trim() : String(urlArg),
953
856
  structuredVariants: undefined,
954
857
  // No explicit variants, will use generics later
955
858
  optionsStructured: undefined,
956
859
  hasOptions: false,
957
- hasGenerics: hasGenerics,
958
- structuredGenerics: structuredGenerics,
860
+ hasGenerics,
861
+ structuredGenerics,
959
862
  functionStartIndex: matchStartIndex,
960
863
  functionEndIndex: endIndex,
961
864
  argumentsStartIndex: parenIndex + 1,
@@ -964,21 +867,19 @@ function findFirstCreateFactoryCall(code, filePath) {
964
867
  } else if (!metadataOnly && structured.length >= 2) {
965
868
  // Normal mode: expect 2-3 arguments (url, variants, options?)
966
869
  if (structured.length === 2) {
967
- var _structured4 = _slicedToArray(structured, 2),
968
- _urlArg3 = _structured4[0],
969
- secondArg = _structured4[1];
870
+ const [urlArg, secondArg] = structured;
970
871
  if (hasGenerics) {
971
872
  // With generics: 2 arguments means (url, options) - use generics as variants
972
873
  return {
973
- functionName: functionName,
974
- fullMatch: fullMatch,
975
- urlArg: typeof _urlArg3 === 'string' ? _urlArg3.trim() : String(_urlArg3),
874
+ functionName,
875
+ fullMatch,
876
+ urlArg: typeof urlArg === 'string' ? urlArg.trim() : String(urlArg),
976
877
  structuredVariants: undefined,
977
878
  // Use generics
978
- optionsStructured: _typeof(secondArg) === 'object' && secondArg !== null ? secondArg : undefined,
879
+ optionsStructured: typeof secondArg === 'object' && secondArg !== null ? secondArg : undefined,
979
880
  hasOptions: true,
980
- hasGenerics: hasGenerics,
981
- structuredGenerics: structuredGenerics,
881
+ hasGenerics,
882
+ structuredGenerics,
982
883
  functionStartIndex: matchStartIndex,
983
884
  functionEndIndex: endIndex,
984
885
  argumentsStartIndex: parenIndex + 1,
@@ -987,14 +888,14 @@ function findFirstCreateFactoryCall(code, filePath) {
987
888
  }
988
889
  // Without generics: 2 arguments means (url, variants) - use second arg as variants
989
890
  return {
990
- functionName: functionName,
991
- fullMatch: fullMatch,
992
- urlArg: typeof _urlArg3 === 'string' ? _urlArg3.trim() : String(_urlArg3),
891
+ functionName,
892
+ fullMatch,
893
+ urlArg: typeof urlArg === 'string' ? urlArg.trim() : String(urlArg),
993
894
  structuredVariants: secondArg,
994
895
  optionsStructured: undefined,
995
896
  hasOptions: false,
996
- hasGenerics: hasGenerics,
997
- structuredGenerics: structuredGenerics,
897
+ hasGenerics,
898
+ structuredGenerics,
998
899
  functionStartIndex: matchStartIndex,
999
900
  functionEndIndex: endIndex,
1000
901
  argumentsStartIndex: parenIndex + 1,
@@ -1002,25 +903,22 @@ function findFirstCreateFactoryCall(code, filePath) {
1002
903
  };
1003
904
  }
1004
905
  if (structured.length === 3) {
1005
- var _structured5 = _slicedToArray(structured, 3),
1006
- _urlArg4 = _structured5[0],
1007
- variantsStructured = _structured5[1],
1008
- _optionsStructured = _structured5[2];
906
+ const [urlArg, variantsStructured, optionsStructured] = structured;
1009
907
 
1010
908
  // Options should be an object (Record<string, any>) or an empty object
1011
- if (typeof _optionsStructured === 'string' || !Array.isArray(_optionsStructured) && _typeof(_optionsStructured) !== 'object') {
1012
- throw new Error("Invalid options argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object but got: ".concat(typeof _optionsStructured === 'string' ? _optionsStructured : JSON.stringify(_optionsStructured)));
909
+ if (typeof optionsStructured === 'string' || !Array.isArray(optionsStructured) && typeof optionsStructured !== 'object') {
910
+ throw new Error(`Invalid options argument in ${functionName} call in ${filePath}. ` + `Expected an object but got: ${typeof optionsStructured === 'string' ? optionsStructured : JSON.stringify(optionsStructured)}`);
1013
911
  }
1014
912
  return {
1015
- functionName: functionName,
1016
- fullMatch: fullMatch,
1017
- urlArg: typeof _urlArg4 === 'string' ? _urlArg4.trim() : String(_urlArg4),
913
+ functionName,
914
+ fullMatch,
915
+ urlArg: typeof urlArg === 'string' ? urlArg.trim() : String(urlArg),
1018
916
  structuredVariants: variantsStructured,
1019
- optionsStructured: _typeof(_optionsStructured) === 'object' && _optionsStructured !== null ? _optionsStructured : undefined,
917
+ optionsStructured: typeof optionsStructured === 'object' && optionsStructured !== null ? optionsStructured : undefined,
1020
918
  hasOptions: true,
1021
919
  // Options argument was provided
1022
- hasGenerics: hasGenerics,
1023
- structuredGenerics: structuredGenerics,
920
+ hasGenerics,
921
+ structuredGenerics,
1024
922
  functionStartIndex: matchStartIndex,
1025
923
  functionEndIndex: endIndex,
1026
924
  argumentsStartIndex: parenIndex + 1,