@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.
- 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,4 +1,3 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
1
|
/**
|
|
3
2
|
* Utility function for parsing function arguments and handling nested structures
|
|
4
3
|
* in JavaScript/TypeScript code with structured representations.
|
|
@@ -94,7 +93,7 @@ export function isArrowFunction(value) {
|
|
|
94
93
|
* @returns Object with properties if it's an object literal, false otherwise
|
|
95
94
|
*/
|
|
96
95
|
export function isObjectLiteral(value) {
|
|
97
|
-
if (
|
|
96
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
98
97
|
return {
|
|
99
98
|
properties: value
|
|
100
99
|
};
|
|
@@ -130,21 +129,21 @@ export function parseFunctionArguments(str) {
|
|
|
130
129
|
* Returns a mapping of export names to their function call information
|
|
131
130
|
*/
|
|
132
131
|
export function parseFileExports(fileContent) {
|
|
133
|
-
|
|
132
|
+
const exports = {};
|
|
134
133
|
|
|
135
134
|
// Find all export statements that assign function calls
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
const exportRegex = /export\s+const\s+(\w+)\s*=\s*(\w+)\s*\(/g;
|
|
136
|
+
let match = exportRegex.exec(fileContent);
|
|
138
137
|
while (match !== null) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
138
|
+
const exportName = match[1];
|
|
139
|
+
const functionName = match[2];
|
|
140
|
+
const callStartIndex = match.index;
|
|
141
|
+
const parenIndex = match.index + match[0].length - 1; // Position of opening parenthesis
|
|
143
142
|
|
|
144
143
|
// Find the matching closing parenthesis
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
for (
|
|
144
|
+
let parenCount = 0;
|
|
145
|
+
let callEndIndex = -1;
|
|
146
|
+
for (let i = parenIndex; i < fileContent.length; i += 1) {
|
|
148
147
|
if (fileContent[i] === '(') {
|
|
149
148
|
parenCount += 1;
|
|
150
149
|
} else if (fileContent[i] === ')') {
|
|
@@ -157,9 +156,9 @@ export function parseFileExports(fileContent) {
|
|
|
157
156
|
}
|
|
158
157
|
if (callEndIndex !== -1) {
|
|
159
158
|
// Extract the arguments content between parentheses
|
|
160
|
-
|
|
159
|
+
const argumentsContent = fileContent.substring(parenIndex + 1, callEndIndex);
|
|
161
160
|
exports[exportName] = {
|
|
162
|
-
functionName
|
|
161
|
+
functionName,
|
|
163
162
|
// Parse the arguments using existing logic
|
|
164
163
|
arguments: parseFunctionArguments(argumentsContent),
|
|
165
164
|
sourceRange: [callStartIndex, callEndIndex + 1]
|
|
@@ -174,100 +173,100 @@ export function parseFileExports(fileContent) {
|
|
|
174
173
|
* Internal recursive parsing function
|
|
175
174
|
*/
|
|
176
175
|
function parseArgumentsRecursive(str) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
for (
|
|
188
|
-
|
|
189
|
-
|
|
176
|
+
const result = [];
|
|
177
|
+
let current = '';
|
|
178
|
+
let parenCount = 0;
|
|
179
|
+
let braceCount = 0;
|
|
180
|
+
let bracketCount = 0;
|
|
181
|
+
let angleCount = 0;
|
|
182
|
+
let inSingleLineComment = false;
|
|
183
|
+
let inMultiLineComment = false;
|
|
184
|
+
let inString = false;
|
|
185
|
+
let stringChar = '';
|
|
186
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
187
|
+
const char = str[i];
|
|
188
|
+
const nextChar = str[i + 1];
|
|
190
189
|
|
|
191
190
|
// Handle comments
|
|
192
191
|
if (!inString && !inSingleLineComment && !inMultiLineComment) {
|
|
193
|
-
if (
|
|
192
|
+
if (char === '/' && nextChar === '/') {
|
|
194
193
|
inSingleLineComment = true;
|
|
195
|
-
current +=
|
|
194
|
+
current += char;
|
|
196
195
|
continue;
|
|
197
196
|
}
|
|
198
|
-
if (
|
|
197
|
+
if (char === '/' && nextChar === '*') {
|
|
199
198
|
inMultiLineComment = true;
|
|
200
|
-
current +=
|
|
199
|
+
current += char;
|
|
201
200
|
continue;
|
|
202
201
|
}
|
|
203
202
|
}
|
|
204
|
-
if (inSingleLineComment &&
|
|
203
|
+
if (inSingleLineComment && char === '\n') {
|
|
205
204
|
inSingleLineComment = false;
|
|
206
|
-
current +=
|
|
205
|
+
current += char;
|
|
207
206
|
continue;
|
|
208
207
|
}
|
|
209
|
-
if (inMultiLineComment &&
|
|
208
|
+
if (inMultiLineComment && char === '*' && nextChar === '/') {
|
|
210
209
|
inMultiLineComment = false;
|
|
211
|
-
current +=
|
|
210
|
+
current += char + nextChar;
|
|
212
211
|
i += 1; // Skip next character
|
|
213
212
|
continue;
|
|
214
213
|
}
|
|
215
214
|
if (inSingleLineComment || inMultiLineComment) {
|
|
216
|
-
current +=
|
|
215
|
+
current += char;
|
|
217
216
|
continue;
|
|
218
217
|
}
|
|
219
218
|
|
|
220
219
|
// Handle strings
|
|
221
|
-
if (!inString && (
|
|
220
|
+
if (!inString && (char === '"' || char === "'" || char === '`')) {
|
|
222
221
|
inString = true;
|
|
223
|
-
stringChar =
|
|
224
|
-
current +=
|
|
222
|
+
stringChar = char;
|
|
223
|
+
current += char;
|
|
225
224
|
continue;
|
|
226
225
|
}
|
|
227
|
-
if (inString &&
|
|
226
|
+
if (inString && char === stringChar && str[i - 1] !== '\\') {
|
|
228
227
|
inString = false;
|
|
229
228
|
stringChar = '';
|
|
230
|
-
current +=
|
|
229
|
+
current += char;
|
|
231
230
|
continue;
|
|
232
231
|
}
|
|
233
232
|
if (inString) {
|
|
234
|
-
current +=
|
|
233
|
+
current += char;
|
|
235
234
|
continue;
|
|
236
235
|
}
|
|
237
236
|
|
|
238
237
|
// Handle brackets and parentheses
|
|
239
|
-
if (
|
|
238
|
+
if (char === '(') {
|
|
240
239
|
parenCount += 1;
|
|
241
|
-
} else if (
|
|
240
|
+
} else if (char === ')') {
|
|
242
241
|
parenCount -= 1;
|
|
243
|
-
} else if (
|
|
242
|
+
} else if (char === '{') {
|
|
244
243
|
braceCount += 1;
|
|
245
|
-
} else if (
|
|
244
|
+
} else if (char === '}') {
|
|
246
245
|
braceCount -= 1;
|
|
247
|
-
} else if (
|
|
246
|
+
} else if (char === '[') {
|
|
248
247
|
bracketCount += 1;
|
|
249
|
-
} else if (
|
|
248
|
+
} else if (char === ']') {
|
|
250
249
|
bracketCount -= 1;
|
|
251
|
-
} else if (
|
|
250
|
+
} else if (char === '<') {
|
|
252
251
|
angleCount += 1;
|
|
253
|
-
} else if (
|
|
252
|
+
} else if (char === '>' && str[i - 1] !== '=') {
|
|
254
253
|
// Only count > as closing angle bracket if it's not part of =>
|
|
255
254
|
angleCount -= 1;
|
|
256
|
-
} else if (
|
|
257
|
-
|
|
255
|
+
} else if (char === ',' && parenCount === 0 && braceCount === 0 && bracketCount === 0 && angleCount === 0) {
|
|
256
|
+
const trimmedPart = current.trim();
|
|
258
257
|
if (trimmedPart) {
|
|
259
258
|
result.push(parseElement(trimmedPart));
|
|
260
259
|
}
|
|
261
260
|
current = '';
|
|
262
261
|
continue;
|
|
263
262
|
}
|
|
264
|
-
current +=
|
|
263
|
+
current += char;
|
|
265
264
|
}
|
|
266
265
|
|
|
267
266
|
// Handle the last part
|
|
268
267
|
if (current.trim()) {
|
|
269
|
-
|
|
270
|
-
result.push(parseElement(
|
|
268
|
+
const trimmedPart = current.trim();
|
|
269
|
+
result.push(parseElement(trimmedPart));
|
|
271
270
|
}
|
|
272
271
|
return result;
|
|
273
272
|
}
|
|
@@ -276,7 +275,7 @@ function parseArgumentsRecursive(str) {
|
|
|
276
275
|
* Parse a single element and determine its type/structure
|
|
277
276
|
*/
|
|
278
277
|
function parseElement(element) {
|
|
279
|
-
|
|
278
|
+
let trimmed = element.trim();
|
|
280
279
|
|
|
281
280
|
// Remove comments
|
|
282
281
|
trimmed = removeComments(trimmed);
|
|
@@ -314,52 +313,52 @@ function parseElement(element) {
|
|
|
314
313
|
* Remove comments from a string
|
|
315
314
|
*/
|
|
316
315
|
function removeComments(str) {
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
for (
|
|
323
|
-
|
|
324
|
-
|
|
316
|
+
let result = '';
|
|
317
|
+
let inSingleLineComment = false;
|
|
318
|
+
let inMultiLineComment = false;
|
|
319
|
+
let inString = false;
|
|
320
|
+
let stringChar = '';
|
|
321
|
+
for (let i = 0; i < str.length; i += 1) {
|
|
322
|
+
const char = str[i];
|
|
323
|
+
const nextChar = str[i + 1];
|
|
325
324
|
|
|
326
325
|
// Handle strings first
|
|
327
|
-
if (!inSingleLineComment && !inMultiLineComment && !inString && (
|
|
326
|
+
if (!inSingleLineComment && !inMultiLineComment && !inString && (char === '"' || char === "'" || char === '`')) {
|
|
328
327
|
inString = true;
|
|
329
|
-
stringChar =
|
|
330
|
-
result +=
|
|
328
|
+
stringChar = char;
|
|
329
|
+
result += char;
|
|
331
330
|
continue;
|
|
332
331
|
}
|
|
333
|
-
if (inString &&
|
|
332
|
+
if (inString && char === stringChar && str[i - 1] !== '\\') {
|
|
334
333
|
inString = false;
|
|
335
334
|
stringChar = '';
|
|
336
|
-
result +=
|
|
335
|
+
result += char;
|
|
337
336
|
continue;
|
|
338
337
|
}
|
|
339
338
|
if (inString) {
|
|
340
|
-
result +=
|
|
339
|
+
result += char;
|
|
341
340
|
continue;
|
|
342
341
|
}
|
|
343
342
|
|
|
344
343
|
// Handle comments
|
|
345
344
|
if (!inSingleLineComment && !inMultiLineComment) {
|
|
346
|
-
if (
|
|
345
|
+
if (char === '/' && nextChar === '/') {
|
|
347
346
|
inSingleLineComment = true;
|
|
348
347
|
i += 1; // Skip next character
|
|
349
348
|
continue;
|
|
350
349
|
}
|
|
351
|
-
if (
|
|
350
|
+
if (char === '/' && nextChar === '*') {
|
|
352
351
|
inMultiLineComment = true;
|
|
353
352
|
i += 1; // Skip next character
|
|
354
353
|
continue;
|
|
355
354
|
}
|
|
356
355
|
}
|
|
357
|
-
if (inSingleLineComment &&
|
|
356
|
+
if (inSingleLineComment && char === '\n') {
|
|
358
357
|
inSingleLineComment = false;
|
|
359
|
-
result +=
|
|
358
|
+
result += char;
|
|
360
359
|
continue;
|
|
361
360
|
}
|
|
362
|
-
if (inMultiLineComment &&
|
|
361
|
+
if (inMultiLineComment && char === '*' && nextChar === '/') {
|
|
363
362
|
inMultiLineComment = false;
|
|
364
363
|
i += 1; // Skip next character
|
|
365
364
|
continue;
|
|
@@ -367,7 +366,7 @@ function removeComments(str) {
|
|
|
367
366
|
if (inSingleLineComment || inMultiLineComment) {
|
|
368
367
|
continue;
|
|
369
368
|
}
|
|
370
|
-
result +=
|
|
369
|
+
result += char;
|
|
371
370
|
}
|
|
372
371
|
return result.trim();
|
|
373
372
|
}
|
|
@@ -376,22 +375,21 @@ function removeComments(str) {
|
|
|
376
375
|
* Parse object literal like { key: value, other: data }
|
|
377
376
|
*/
|
|
378
377
|
function parseObjectLiteral(str) {
|
|
379
|
-
|
|
378
|
+
const content = str.slice(1, -1).trim(); // Remove { }
|
|
380
379
|
if (!content) {
|
|
381
380
|
return {};
|
|
382
381
|
}
|
|
383
|
-
|
|
382
|
+
const obj = {};
|
|
384
383
|
|
|
385
384
|
// Parse object properties manually to handle complex types
|
|
386
|
-
|
|
387
|
-
for (
|
|
388
|
-
|
|
389
|
-
var colonIndex = prop.indexOf(':');
|
|
385
|
+
const properties = parseObjectProperties(content);
|
|
386
|
+
for (const prop of properties) {
|
|
387
|
+
const colonIndex = prop.indexOf(':');
|
|
390
388
|
if (colonIndex !== -1) {
|
|
391
|
-
|
|
392
|
-
|
|
389
|
+
const key = prop.substring(0, colonIndex).trim();
|
|
390
|
+
const value = prop.substring(colonIndex + 1).trim();
|
|
393
391
|
// Parse the value
|
|
394
|
-
|
|
392
|
+
const parsedValue = parseElement(value);
|
|
395
393
|
|
|
396
394
|
// For object properties: preserve strings as-is, but only wrap array LITERALS in another array
|
|
397
395
|
if (typeof parsedValue === 'string' && !Array.isArray(parsedValue)) {
|
|
@@ -399,7 +397,7 @@ function parseObjectLiteral(str) {
|
|
|
399
397
|
} else if (Array.isArray(parsedValue)) {
|
|
400
398
|
// Only double-wrap array literals (parsed from [1, 2, 3])
|
|
401
399
|
// Functions and generics should remain as single arrays
|
|
402
|
-
|
|
400
|
+
const originalValue = value.trim();
|
|
403
401
|
if (originalValue.startsWith('[') && originalValue.endsWith(']')) {
|
|
404
402
|
// This is an array literal - double wrap it
|
|
405
403
|
obj[key] = [parsedValue];
|
|
@@ -412,7 +410,7 @@ function parseObjectLiteral(str) {
|
|
|
412
410
|
}
|
|
413
411
|
} else {
|
|
414
412
|
// Shorthand property like { foo } -> { foo: 'foo' }
|
|
415
|
-
|
|
413
|
+
const trimmed = prop.trim();
|
|
416
414
|
obj[trimmed] = trimmed;
|
|
417
415
|
}
|
|
418
416
|
}
|
|
@@ -423,30 +421,30 @@ function parseObjectLiteral(str) {
|
|
|
423
421
|
* Parse object properties, handling complex nested types
|
|
424
422
|
*/
|
|
425
423
|
function parseObjectProperties(content) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
for (
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
if (!inString && (
|
|
424
|
+
const properties = [];
|
|
425
|
+
let current = '';
|
|
426
|
+
let depth = 0;
|
|
427
|
+
let inString = false;
|
|
428
|
+
let stringChar = '';
|
|
429
|
+
for (let i = 0; i < content.length; i += 1) {
|
|
430
|
+
const char = content[i];
|
|
431
|
+
const nextChar = content[i + 1];
|
|
432
|
+
if (!inString && (char === '"' || char === "'" || char === '`')) {
|
|
435
433
|
inString = true;
|
|
436
|
-
stringChar =
|
|
437
|
-
} else if (inString &&
|
|
434
|
+
stringChar = char;
|
|
435
|
+
} else if (inString && char === stringChar && content[i - 1] !== '\\') {
|
|
438
436
|
inString = false;
|
|
439
437
|
stringChar = '';
|
|
440
438
|
}
|
|
441
439
|
if (!inString) {
|
|
442
|
-
if (
|
|
440
|
+
if (char === '<' || char === '{' || char === '(' || char === '[') {
|
|
443
441
|
depth += 1;
|
|
444
|
-
} else if (
|
|
442
|
+
} else if (char === '>' && nextChar !== '=' && content[i - 1] !== '=') {
|
|
445
443
|
// Only count > as closing bracket if it's not part of => or >=
|
|
446
444
|
depth -= 1;
|
|
447
|
-
} else if (
|
|
445
|
+
} else if (char === '}' || char === ')' || char === ']') {
|
|
448
446
|
depth -= 1;
|
|
449
|
-
} else if (
|
|
447
|
+
} else if (char === ',' && depth === 0) {
|
|
450
448
|
if (current.trim()) {
|
|
451
449
|
properties.push(current.trim());
|
|
452
450
|
}
|
|
@@ -454,7 +452,7 @@ function parseObjectProperties(content) {
|
|
|
454
452
|
continue;
|
|
455
453
|
}
|
|
456
454
|
}
|
|
457
|
-
current +=
|
|
455
|
+
current += char;
|
|
458
456
|
}
|
|
459
457
|
if (current.trim()) {
|
|
460
458
|
properties.push(current.trim());
|
|
@@ -466,7 +464,7 @@ function parseObjectProperties(content) {
|
|
|
466
464
|
* Parse array literal like [1, 2, 3]
|
|
467
465
|
*/
|
|
468
466
|
function parseArrayLiteral(str) {
|
|
469
|
-
|
|
467
|
+
const content = str.slice(1, -1).trim(); // Remove [ ]
|
|
470
468
|
if (!content) {
|
|
471
469
|
return [];
|
|
472
470
|
}
|
|
@@ -477,24 +475,24 @@ function parseArrayLiteral(str) {
|
|
|
477
475
|
* Parse arrow function like (a) => a + 1 or (data: string): Promise<string> => Promise.resolve(data)
|
|
478
476
|
*/
|
|
479
477
|
function parseArrowFunction(str) {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
478
|
+
const arrowIndex = str.indexOf('=>');
|
|
479
|
+
const leftPart = str.substring(0, arrowIndex).trim();
|
|
480
|
+
const rightPart = str.substring(arrowIndex + 2).trim();
|
|
483
481
|
|
|
484
482
|
// Parse arguments
|
|
485
|
-
|
|
486
|
-
|
|
483
|
+
let args = [];
|
|
484
|
+
let types;
|
|
487
485
|
if (leftPart.startsWith('(') && leftPart.includes(')')) {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
486
|
+
const parenEnd = leftPart.lastIndexOf(')');
|
|
487
|
+
const argsPart = leftPart.substring(1, parenEnd);
|
|
488
|
+
const afterParen = leftPart.substring(parenEnd + 1).trim();
|
|
491
489
|
args = argsPart ? parseArgumentsRecursive(argsPart) : [];
|
|
492
490
|
|
|
493
491
|
// Check for return type annotation
|
|
494
492
|
if (afterParen.startsWith(':')) {
|
|
495
|
-
|
|
493
|
+
const returnType = afterParen.substring(1).trim();
|
|
496
494
|
// Extract input types from args if they have type annotations
|
|
497
|
-
|
|
495
|
+
const inputTypes = args.map(arg => {
|
|
498
496
|
if (typeof arg === 'string' && arg.includes(':')) {
|
|
499
497
|
return arg.split(':')[1].trim();
|
|
500
498
|
}
|
|
@@ -502,7 +500,7 @@ function parseArrowFunction(str) {
|
|
|
502
500
|
});
|
|
503
501
|
|
|
504
502
|
// Clean argument names (remove type annotations)
|
|
505
|
-
args = args.map(
|
|
503
|
+
args = args.map(arg => {
|
|
506
504
|
if (typeof arg === 'string' && arg.includes(':')) {
|
|
507
505
|
return arg.split(':')[0].trim();
|
|
508
506
|
}
|
|
@@ -513,7 +511,7 @@ function parseArrowFunction(str) {
|
|
|
513
511
|
} else {
|
|
514
512
|
args = [leftPart];
|
|
515
513
|
}
|
|
516
|
-
|
|
514
|
+
const returnValue = parseElement(rightPart);
|
|
517
515
|
if (types) {
|
|
518
516
|
return [args, types, returnValue];
|
|
519
517
|
}
|
|
@@ -525,13 +523,13 @@ function parseArrowFunction(str) {
|
|
|
525
523
|
*/
|
|
526
524
|
function parseFunctionOrGeneric(str) {
|
|
527
525
|
// Check for generics first
|
|
528
|
-
|
|
529
|
-
|
|
526
|
+
const angleStart = str.indexOf('<');
|
|
527
|
+
const parenStart = str.indexOf('(');
|
|
530
528
|
if (angleStart !== -1 && (parenStart === -1 || angleStart < parenStart)) {
|
|
531
529
|
return parseGeneric(str);
|
|
532
530
|
}
|
|
533
531
|
if (parenStart !== -1) {
|
|
534
|
-
|
|
532
|
+
const result = parseFunctionCall(str);
|
|
535
533
|
// If parseFunctionCall detected property access and returned [str], unwrap it
|
|
536
534
|
if (Array.isArray(result) && result.length === 1 && result[0] === str) {
|
|
537
535
|
return str;
|
|
@@ -545,51 +543,51 @@ function parseFunctionOrGeneric(str) {
|
|
|
545
543
|
* Parse generic content while preserving nested structures
|
|
546
544
|
*/
|
|
547
545
|
function parseGenericContent(content) {
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
for (
|
|
557
|
-
|
|
558
|
-
if (!inString && (
|
|
546
|
+
const elements = [];
|
|
547
|
+
let current = '';
|
|
548
|
+
let parenCount = 0;
|
|
549
|
+
let braceCount = 0;
|
|
550
|
+
let bracketCount = 0;
|
|
551
|
+
let angleCount = 0;
|
|
552
|
+
let inString = false;
|
|
553
|
+
let stringChar = '';
|
|
554
|
+
for (let i = 0; i < content.length; i += 1) {
|
|
555
|
+
const char = content[i];
|
|
556
|
+
if (!inString && (char === '"' || char === "'")) {
|
|
559
557
|
inString = true;
|
|
560
|
-
stringChar =
|
|
561
|
-
current +=
|
|
562
|
-
} else if (inString &&
|
|
558
|
+
stringChar = char;
|
|
559
|
+
current += char;
|
|
560
|
+
} else if (inString && char === stringChar && content[i - 1] !== '\\') {
|
|
563
561
|
inString = false;
|
|
564
562
|
stringChar = '';
|
|
565
|
-
current +=
|
|
563
|
+
current += char;
|
|
566
564
|
} else if (!inString) {
|
|
567
|
-
if (
|
|
565
|
+
if (char === '(') {
|
|
568
566
|
parenCount += 1;
|
|
569
|
-
} else if (
|
|
567
|
+
} else if (char === ')') {
|
|
570
568
|
parenCount -= 1;
|
|
571
|
-
} else if (
|
|
569
|
+
} else if (char === '{') {
|
|
572
570
|
braceCount += 1;
|
|
573
|
-
} else if (
|
|
571
|
+
} else if (char === '}') {
|
|
574
572
|
braceCount -= 1;
|
|
575
|
-
} else if (
|
|
573
|
+
} else if (char === '[') {
|
|
576
574
|
bracketCount += 1;
|
|
577
|
-
} else if (
|
|
575
|
+
} else if (char === ']') {
|
|
578
576
|
bracketCount -= 1;
|
|
579
|
-
} else if (
|
|
577
|
+
} else if (char === '<') {
|
|
580
578
|
angleCount += 1;
|
|
581
|
-
} else if (
|
|
579
|
+
} else if (char === '>') {
|
|
582
580
|
angleCount -= 1;
|
|
583
|
-
} else if (
|
|
581
|
+
} else if (char === ',' && parenCount === 0 && braceCount === 0 && bracketCount === 0 && angleCount === 0) {
|
|
584
582
|
if (current.trim()) {
|
|
585
583
|
elements.push(parseElement(current.trim()));
|
|
586
584
|
}
|
|
587
585
|
current = '';
|
|
588
586
|
continue;
|
|
589
587
|
}
|
|
590
|
-
current +=
|
|
588
|
+
current += char;
|
|
591
589
|
} else {
|
|
592
|
-
current +=
|
|
590
|
+
current += char;
|
|
593
591
|
}
|
|
594
592
|
}
|
|
595
593
|
if (current.trim()) {
|
|
@@ -602,13 +600,13 @@ function parseGenericContent(content) {
|
|
|
602
600
|
* Parse generic like Component<{ foo: string }> or Theme<"dark" | "light", Component[]>
|
|
603
601
|
*/
|
|
604
602
|
function parseGeneric(str) {
|
|
605
|
-
|
|
606
|
-
|
|
603
|
+
const angleStart = str.indexOf('<');
|
|
604
|
+
const name = str.substring(0, angleStart).trim();
|
|
607
605
|
|
|
608
606
|
// Find matching closing angle bracket
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
for (
|
|
607
|
+
let angleCount = 0;
|
|
608
|
+
let angleEnd = -1;
|
|
609
|
+
for (let i = angleStart; i < str.length; i += 1) {
|
|
612
610
|
if (str[i] === '<') {
|
|
613
611
|
angleCount += 1;
|
|
614
612
|
} else if (str[i] === '>') {
|
|
@@ -622,16 +620,16 @@ function parseGeneric(str) {
|
|
|
622
620
|
if (angleEnd === -1) {
|
|
623
621
|
return [str];
|
|
624
622
|
}
|
|
625
|
-
|
|
626
|
-
|
|
623
|
+
const genericContent = str.substring(angleStart + 1, angleEnd).trim();
|
|
624
|
+
const afterGeneric = str.substring(angleEnd + 1).trim();
|
|
627
625
|
|
|
628
626
|
// Parse generic content - don't split on commas within generics for unions and arrays
|
|
629
|
-
|
|
627
|
+
const generics = genericContent ? parseGenericContent(genericContent) : [];
|
|
630
628
|
|
|
631
629
|
// Check if there are function arguments after the generic
|
|
632
630
|
if (afterGeneric.startsWith('(') && afterGeneric.endsWith(')')) {
|
|
633
|
-
|
|
634
|
-
|
|
631
|
+
const argContent = afterGeneric.slice(1, -1).trim();
|
|
632
|
+
const args = argContent ? parseArgumentsRecursive(argContent) : [];
|
|
635
633
|
return [name, generics, args];
|
|
636
634
|
}
|
|
637
635
|
|
|
@@ -644,13 +642,13 @@ function parseGeneric(str) {
|
|
|
644
642
|
* Parse function call like func(a, b)
|
|
645
643
|
*/
|
|
646
644
|
function parseFunctionCall(str) {
|
|
647
|
-
|
|
648
|
-
|
|
645
|
+
const parenStart = str.indexOf('(');
|
|
646
|
+
const name = str.substring(0, parenStart).trim();
|
|
649
647
|
|
|
650
648
|
// Find matching closing parenthesis
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
for (
|
|
649
|
+
let parenCount = 0;
|
|
650
|
+
let parenEnd = -1;
|
|
651
|
+
for (let i = parenStart; i < str.length; i += 1) {
|
|
654
652
|
if (str[i] === '(') {
|
|
655
653
|
parenCount += 1;
|
|
656
654
|
} else if (str[i] === ')') {
|
|
@@ -666,30 +664,30 @@ function parseFunctionCall(str) {
|
|
|
666
664
|
}
|
|
667
665
|
|
|
668
666
|
// Check if there's meaningful continuation after the closing parenthesis
|
|
669
|
-
|
|
667
|
+
const remainingLength = str.length - parenEnd - 1;
|
|
670
668
|
if (remainingLength > 0) {
|
|
671
669
|
// Skip whitespace to find the first meaningful character
|
|
672
|
-
|
|
673
|
-
while (
|
|
674
|
-
|
|
670
|
+
let i = parenEnd + 1;
|
|
671
|
+
while (i < str.length && (str[i] === ' ' || str[i] === '\t' || str[i] === '\n' || str[i] === '\r')) {
|
|
672
|
+
i += 1;
|
|
675
673
|
}
|
|
676
|
-
if (
|
|
677
|
-
|
|
674
|
+
if (i < str.length) {
|
|
675
|
+
const firstChar = str[i];
|
|
678
676
|
if (firstChar === '.' || firstChar === '[' || firstChar === '(' || firstChar === '!') {
|
|
679
677
|
// Property access, bracket notation, chained calls, or non-null assertion
|
|
680
678
|
return [str];
|
|
681
679
|
}
|
|
682
|
-
if (firstChar === '?' &&
|
|
680
|
+
if (firstChar === '?' && i + 1 < str.length && str[i + 1] === '.') {
|
|
683
681
|
// Optional chaining
|
|
684
682
|
return [str];
|
|
685
683
|
}
|
|
686
684
|
}
|
|
687
685
|
}
|
|
688
|
-
|
|
686
|
+
const argContent = str.substring(parenStart + 1, parenEnd).trim();
|
|
689
687
|
if (!argContent) {
|
|
690
688
|
return [name, []];
|
|
691
689
|
}
|
|
692
|
-
|
|
690
|
+
const args = parseArgumentsRecursive(argContent);
|
|
693
691
|
|
|
694
692
|
// Special case: if there's a single array literal argument, flatten it
|
|
695
693
|
if (args.length === 1 && Array.isArray(args[0])) {
|
|
@@ -702,14 +700,14 @@ function parseFunctionCall(str) {
|
|
|
702
700
|
* Parse TypeScript type assertion like "Component as React.FC<Props>"
|
|
703
701
|
*/
|
|
704
702
|
function parseTypeAssertion(str) {
|
|
705
|
-
|
|
703
|
+
const asIndex = str.indexOf(' as ');
|
|
706
704
|
if (asIndex === -1) {
|
|
707
705
|
return [str]; // fallback to string if no 'as' found
|
|
708
706
|
}
|
|
709
|
-
|
|
710
|
-
|
|
707
|
+
const expression = str.substring(0, asIndex).trim();
|
|
708
|
+
const type = str.substring(asIndex + 4).trim(); // +4 for ' as '
|
|
711
709
|
|
|
712
710
|
// Parse the expression part recursively in case it's complex
|
|
713
|
-
|
|
711
|
+
const parsedExpression = parseElement(expression);
|
|
714
712
|
return ['as', type, parsedExpression];
|
|
715
713
|
}
|