@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.5
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/esm/CodeControllerContext/CodeControllerContext.js +2 -2
- package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
- package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
- package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
- package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
- package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
- package/esm/CodeHighlighter/errors.js +248 -400
- package/esm/CodeHighlighter/parseControlledCode.js +12 -20
- package/esm/CodeProvider/CodeContext.js +3 -3
- package/esm/CodeProvider/CodeProvider.js +31 -40
- package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
- package/esm/cli/index.js +1 -1
- package/esm/cli/runValidate.js +160 -264
- package/esm/createDemoData/createDemoData.js +11 -12
- package/esm/createSitemap/createSitemap.js +2 -2
- package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
- package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
- package/esm/pipeline/hastUtils/hastUtils.js +16 -17
- package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
- package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
- package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
- package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
- package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
- package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
- package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
- package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
- package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
- package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
- package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
- package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
- package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
- package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
- package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
- package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
- package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
- package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
- package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
- package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
- package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
- package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
- package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
- package/esm/pipeline/parseSource/addLineGutters.js +33 -45
- package/esm/pipeline/parseSource/grammars.js +3 -3
- package/esm/pipeline/parseSource/parseSource.js +13 -31
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
- package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
- package/esm/useCode/Pre.js +58 -62
- package/esm/useCode/useCode.js +59 -61
- package/esm/useCode/useCodeUtils.js +54 -63
- package/esm/useCode/useCopyFunctionality.js +10 -9
- package/esm/useCode/useFileNavigation.js +150 -212
- package/esm/useCode/useSourceEditing.js +17 -14
- package/esm/useCode/useTransformManagement.js +23 -26
- package/esm/useCode/useUIState.js +12 -20
- package/esm/useCode/useVariantSelection.js +62 -79
- package/esm/useCopier/index.js +29 -56
- package/esm/useDemo/createCodeSandbox.js +12 -15
- package/esm/useDemo/createStackBlitz.js +14 -20
- package/esm/useDemo/exportVariant.js +200 -180
- package/esm/useDemo/exportVariantAsCra.js +22 -25
- package/esm/useDemo/useDemo.js +80 -84
- package/esm/useErrors/ErrorsContext.js +1 -1
- package/esm/useErrors/useErrors.js +3 -3
- package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
- package/esm/usePreference/PreferencesProvider.js +1 -1
- package/esm/usePreference/usePreference.js +9 -11
- package/esm/useSearch/useSearch.js +290 -387
- package/esm/useUrlHashState/useUrlHashState.js +11 -14
- package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
- package/esm/withDocsInfra/withDocsInfra.js +99 -101
- 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
|
-
|
|
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
|
-
|
|
37
|
+
const functionCall = isFunction(data);
|
|
44
38
|
if (functionCall) {
|
|
45
39
|
// Build a function call string like "console.log('test')"
|
|
46
|
-
|
|
40
|
+
const argStr = functionCall.arguments.map(arg => {
|
|
47
41
|
if (Array.isArray(arg)) {
|
|
48
|
-
return arg.map(
|
|
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
|
|
46
|
+
return `${functionCall.name}(${argStr})`;
|
|
55
47
|
}
|
|
56
48
|
|
|
57
49
|
// Check for generic structures
|
|
58
|
-
|
|
50
|
+
const generic = isGeneric(data);
|
|
59
51
|
if (generic) {
|
|
60
52
|
// Build a generic string like "Component<{ foo: string }>"
|
|
61
|
-
|
|
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
|
-
|
|
67
|
-
|
|
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
|
|
60
|
+
return `${generic.name}<${genericsStr}>`;
|
|
73
61
|
}
|
|
74
62
|
|
|
75
63
|
// Check for type assertions
|
|
76
|
-
|
|
64
|
+
const typeAssertion = isTypeAssertion(data);
|
|
77
65
|
if (typeAssertion) {
|
|
78
|
-
|
|
79
|
-
return
|
|
66
|
+
const cleanedExpression = cleanStructuredData(typeAssertion.expression);
|
|
67
|
+
return `${cleanedExpression} as ${typeAssertion.type}`;
|
|
80
68
|
}
|
|
81
69
|
|
|
82
70
|
// Check for arrow functions
|
|
83
|
-
|
|
71
|
+
const arrowFunction = isArrowFunction(data);
|
|
84
72
|
if (arrowFunction) {
|
|
85
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
99
|
-
return
|
|
82
|
+
const returnValue = cleanStructuredData(arrowFunction.returnValue);
|
|
83
|
+
return `(${argsStr}) => ${returnValue}`;
|
|
100
84
|
}
|
|
101
85
|
|
|
102
86
|
// Check for literal arrays
|
|
103
|
-
|
|
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
|
-
|
|
93
|
+
const objectLiteral = isObjectLiteral(data);
|
|
110
94
|
if (objectLiteral) {
|
|
111
|
-
|
|
112
|
-
for (
|
|
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
|
-
|
|
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
|
-
|
|
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 &&
|
|
139
|
+
if (data && typeof data === 'object') {
|
|
159
140
|
// Fallback for objects that don't match structured patterns
|
|
160
|
-
|
|
161
|
-
for (
|
|
162
|
-
|
|
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
|
|
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
|
-
|
|
188
|
-
|
|
189
|
-
for (
|
|
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
|
-
|
|
169
|
+
let importName;
|
|
195
170
|
|
|
196
171
|
// Use type discriminators to determine the structure type
|
|
197
|
-
|
|
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
|
-
|
|
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
|
-
|
|
206
|
-
|
|
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
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
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
|
-
|
|
233
|
-
|
|
234
|
-
importName =
|
|
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
|
-
|
|
238
|
-
|
|
239
|
-
importName =
|
|
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(
|
|
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
|
|
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
|
-
|
|
261
|
-
Object.values(importResult.relative).forEach(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
281
|
-
|
|
282
|
-
|
|
256
|
+
externalImport.names.forEach(({
|
|
257
|
+
name,
|
|
258
|
+
alias
|
|
259
|
+
}) => {
|
|
283
260
|
// Use alias if available, otherwise use the original name
|
|
284
|
-
|
|
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
|
-
|
|
298
|
-
Object.values(importResult.relative).forEach(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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
|
-
|
|
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
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
//
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
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
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
-
|
|
389
|
-
|
|
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
|
|
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 (
|
|
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
|
-
|
|
386
|
+
let componentName = structuredVariants.trim();
|
|
418
387
|
|
|
419
388
|
// Handle TypeScript type assertions in single component syntax
|
|
420
|
-
|
|
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(
|
|
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(
|
|
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
|
-
|
|
428
|
+
const trimmed = genericContent.trim();
|
|
460
429
|
if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
|
461
430
|
// Parse as object literal using the existing parser
|
|
462
|
-
|
|
463
|
-
if (
|
|
464
|
-
return
|
|
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
|
-
|
|
438
|
+
const parsed = parseFunctionArguments(genericContent);
|
|
470
439
|
|
|
471
440
|
// If it's a single object, return it
|
|
472
|
-
if (parsed.length === 1 &&
|
|
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
|
-
|
|
486
|
-
parsed.forEach(
|
|
454
|
+
const result = {};
|
|
455
|
+
parsed.forEach((item, index) => {
|
|
487
456
|
if (typeof item === 'string') {
|
|
488
|
-
result[
|
|
489
|
-
} else if (
|
|
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
|
-
|
|
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
|
-
|
|
512
|
-
throw new Error(
|
|
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(
|
|
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
|
-
|
|
494
|
+
const trimmed = structuredVariants.trim();
|
|
526
495
|
if (!trimmed || !/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(trimmed)) {
|
|
527
|
-
throw new Error(
|
|
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) ||
|
|
502
|
+
if (Array.isArray(structuredVariants) || typeof structuredVariants === 'object' && structuredVariants !== null) {
|
|
534
503
|
return; // Valid object structure
|
|
535
504
|
}
|
|
536
|
-
throw new Error(
|
|
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(
|
|
545
|
-
|
|
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
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
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
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
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
|
-
}
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
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
|
|
693
|
-
|
|
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
|
-
|
|
697
|
+
const match = createFunctionRegex.exec(code);
|
|
792
698
|
if (!match) {
|
|
793
699
|
return null;
|
|
794
700
|
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
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
|
-
|
|
808
|
-
|
|
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
|
-
|
|
814
|
-
|
|
719
|
+
let angleCount = 1;
|
|
720
|
+
let genericEndIndex = -1;
|
|
815
721
|
|
|
816
722
|
// Find the matching closing angle bracket, handling nesting
|
|
817
|
-
for (
|
|
818
|
-
|
|
819
|
-
if (
|
|
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 (
|
|
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
|
-
|
|
753
|
+
const parenIndex = currentIndex;
|
|
848
754
|
|
|
849
755
|
// Find the matching closing parenthesis
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
for (
|
|
853
|
-
if (code[
|
|
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[
|
|
761
|
+
} else if (code[i] === ')') {
|
|
856
762
|
parenCount -= 1;
|
|
857
763
|
if (parenCount === 0) {
|
|
858
|
-
endIndex =
|
|
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
|
-
|
|
868
|
-
|
|
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
|
-
|
|
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
|
-
|
|
784
|
+
const structured = parseFunctionArguments(content);
|
|
879
785
|
|
|
880
786
|
// Validate the function follows the convention
|
|
881
|
-
|
|
882
|
-
metadataOnly =
|
|
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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
903
|
-
urlArg = _structured[0];
|
|
809
|
+
const [urlArg] = structured;
|
|
904
810
|
return {
|
|
905
|
-
functionName
|
|
906
|
-
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
|
|
913
|
-
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
|
-
|
|
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) &&
|
|
927
|
-
throw new Error(
|
|
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
|
|
931
|
-
fullMatch
|
|
932
|
-
urlArg: typeof
|
|
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:
|
|
839
|
+
optionsStructured: typeof optionsStructured === 'object' && optionsStructured !== null ? optionsStructured : undefined,
|
|
936
840
|
hasOptions: true,
|
|
937
|
-
hasGenerics
|
|
938
|
-
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
|
-
|
|
948
|
-
_urlArg2 = _structured3[0];
|
|
851
|
+
const [urlArg] = structured;
|
|
949
852
|
return {
|
|
950
|
-
functionName
|
|
951
|
-
fullMatch
|
|
952
|
-
urlArg: typeof
|
|
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
|
|
958
|
-
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
|
-
|
|
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
|
|
974
|
-
fullMatch
|
|
975
|
-
urlArg: typeof
|
|
874
|
+
functionName,
|
|
875
|
+
fullMatch,
|
|
876
|
+
urlArg: typeof urlArg === 'string' ? urlArg.trim() : String(urlArg),
|
|
976
877
|
structuredVariants: undefined,
|
|
977
878
|
// Use generics
|
|
978
|
-
optionsStructured:
|
|
879
|
+
optionsStructured: typeof secondArg === 'object' && secondArg !== null ? secondArg : undefined,
|
|
979
880
|
hasOptions: true,
|
|
980
|
-
hasGenerics
|
|
981
|
-
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
|
|
991
|
-
fullMatch
|
|
992
|
-
urlArg: typeof
|
|
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
|
|
997
|
-
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
|
-
|
|
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
|
|
1012
|
-
throw new Error(
|
|
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
|
|
1016
|
-
fullMatch
|
|
1017
|
-
urlArg: typeof
|
|
913
|
+
functionName,
|
|
914
|
+
fullMatch,
|
|
915
|
+
urlArg: typeof urlArg === 'string' ? urlArg.trim() : String(urlArg),
|
|
1018
916
|
structuredVariants: variantsStructured,
|
|
1019
|
-
optionsStructured:
|
|
917
|
+
optionsStructured: typeof optionsStructured === 'object' && optionsStructured !== null ? optionsStructured : undefined,
|
|
1020
918
|
hasOptions: true,
|
|
1021
919
|
// Options argument was provided
|
|
1022
|
-
hasGenerics
|
|
1023
|
-
structuredGenerics
|
|
920
|
+
hasGenerics,
|
|
921
|
+
structuredGenerics,
|
|
1024
922
|
functionStartIndex: matchStartIndex,
|
|
1025
923
|
functionEndIndex: endIndex,
|
|
1026
924
|
argumentsStartIndex: parenIndex + 1,
|