@mui/internal-docs-infra 0.1.1-canary.9 → 0.2.0-alpha.2
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/CHANGELOG.md +9 -0
- package/README.md +3 -11
- package/esm/CodeControllerContext/CodeControllerContext.d.ts +62 -0
- package/esm/CodeControllerContext/CodeControllerContext.js +33 -0
- package/esm/CodeControllerContext/index.d.ts +1 -0
- package/esm/CodeControllerContext/index.js +1 -0
- package/esm/CodeExternalsContext/CodeExternalsContext.d.ts +8 -0
- package/esm/CodeExternalsContext/CodeExternalsContext.js +8 -0
- package/esm/CodeExternalsContext/index.d.ts +1 -0
- package/esm/CodeExternalsContext/index.js +1 -0
- package/esm/CodeHighlighter/CodeHighlighter.d.ts +2 -0
- package/esm/CodeHighlighter/CodeHighlighter.js +441 -0
- package/esm/CodeHighlighter/CodeHighlighterClient.d.ts +2 -0
- package/esm/CodeHighlighter/CodeHighlighterClient.js +984 -0
- package/esm/CodeHighlighter/CodeHighlighterContext.d.ts +16 -0
- package/esm/CodeHighlighter/CodeHighlighterContext.js +15 -0
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.d.ts +7 -0
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +14 -0
- package/esm/CodeHighlighter/addPathsToVariant.d.ts +14 -0
- package/esm/CodeHighlighter/addPathsToVariant.js +68 -0
- package/esm/CodeHighlighter/applyTransform.d.ts +19 -0
- package/esm/CodeHighlighter/applyTransform.js +75 -0
- package/esm/CodeHighlighter/calculateMainFilePath.d.ts +1 -0
- package/esm/CodeHighlighter/calculateMainFilePath.js +108 -0
- package/esm/CodeHighlighter/codeToFallbackProps.d.ts +2 -0
- package/esm/CodeHighlighter/codeToFallbackProps.js +73 -0
- package/esm/CodeHighlighter/errors.d.ts +141 -0
- package/esm/CodeHighlighter/errors.js +441 -0
- package/esm/CodeHighlighter/examineVariant.d.ts +25 -0
- package/esm/CodeHighlighter/examineVariant.js +73 -0
- package/esm/CodeHighlighter/hasAllVariants.d.ts +27 -0
- package/esm/CodeHighlighter/hasAllVariants.js +63 -0
- package/esm/CodeHighlighter/index.d.ts +1 -0
- package/esm/CodeHighlighter/index.js +1 -0
- package/esm/CodeHighlighter/loadFallbackCode.d.ts +10 -0
- package/esm/CodeHighlighter/loadFallbackCode.js +679 -0
- package/esm/CodeHighlighter/loadVariant.d.ts +12 -0
- package/esm/CodeHighlighter/loadVariant.js +1044 -0
- package/esm/CodeHighlighter/maybeInitialData.d.ts +108 -0
- package/esm/CodeHighlighter/maybeInitialData.js +192 -0
- package/esm/CodeHighlighter/mergeMetadata.d.ts +40 -0
- package/esm/CodeHighlighter/mergeMetadata.js +165 -0
- package/esm/CodeHighlighter/parseCode.d.ts +6 -0
- package/esm/CodeHighlighter/parseCode.js +134 -0
- package/esm/CodeHighlighter/parseControlledCode.d.ts +6 -0
- package/esm/CodeHighlighter/parseControlledCode.js +87 -0
- package/esm/CodeHighlighter/pathUtils.d.ts +120 -0
- package/esm/CodeHighlighter/pathUtils.js +258 -0
- package/esm/CodeHighlighter/transformCode.d.ts +21 -0
- package/esm/CodeHighlighter/transformCode.js +251 -0
- package/esm/CodeHighlighter/transformParsedSource.d.ts +3 -0
- package/esm/CodeHighlighter/transformParsedSource.js +60 -0
- package/esm/CodeHighlighter/transformSource.d.ts +2 -0
- package/esm/CodeHighlighter/transformSource.js +103 -0
- package/esm/CodeHighlighter/types.d.ts +276 -0
- package/esm/CodeHighlighter/types.js +1 -0
- package/esm/CodeProvider/CodeContext.d.ts +31 -0
- package/esm/CodeProvider/CodeContext.js +12 -0
- package/esm/CodeProvider/CodeProvider.d.ts +13 -0
- package/esm/CodeProvider/CodeProvider.js +83 -0
- package/esm/CodeProvider/index.d.ts +1 -0
- package/esm/CodeProvider/index.js +1 -0
- package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +45 -0
- package/esm/abstractCreateDemo/abstractCreateDemo.js +100 -0
- package/esm/abstractCreateDemo/index.d.ts +1 -0
- package/esm/abstractCreateDemo/index.js +1 -0
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.d.ts +32 -0
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +52 -0
- package/esm/abstractCreateDemoClient/index.d.ts +1 -0
- package/esm/abstractCreateDemoClient/index.js +1 -0
- package/esm/createDemoData/createDemoData.d.ts +44 -0
- package/esm/createDemoData/createDemoData.js +74 -0
- package/esm/createDemoData/index.d.ts +1 -0
- package/esm/createDemoData/index.js +1 -0
- package/esm/createDemoData/types.d.ts +25 -0
- package/esm/createDemoData/types.js +1 -0
- package/esm/pipeline/hastUtils/hastUtils.d.ts +11 -0
- package/esm/pipeline/hastUtils/hastUtils.js +67 -0
- package/esm/pipeline/hastUtils/index.d.ts +1 -0
- package/esm/pipeline/hastUtils/index.js +1 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/index.d.ts +2 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/index.js +4 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +14 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +178 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +47 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +849 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.d.ts +85 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +715 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.d.ts +14 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +73 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.d.ts +11 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +203 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.d.ts +6 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +23 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.d.ts +6 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +148 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.d.ts +9 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +198 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.d.ts +2 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/index.js +4 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.d.ts +5 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +21 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.d.ts +15 -0
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +233 -0
- package/esm/pipeline/loadServerCodeMeta/index.d.ts +1 -0
- package/esm/pipeline/loadServerCodeMeta/index.js +1 -0
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.d.ts +24 -0
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +90 -0
- package/esm/pipeline/loadServerSource/index.d.ts +1 -0
- package/esm/pipeline/loadServerSource/index.js +1 -0
- package/esm/pipeline/loadServerSource/loadServerSource.d.ts +25 -0
- package/esm/pipeline/loadServerSource/loadServerSource.js +134 -0
- package/esm/pipeline/loaderUtils/externalsToPackages.d.ts +1 -0
- package/esm/pipeline/loaderUtils/externalsToPackages.js +46 -0
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.d.ts +34 -0
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +161 -0
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.d.ts +12 -0
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +66 -0
- package/esm/pipeline/loaderUtils/index.d.ts +7 -0
- package/esm/pipeline/loaderUtils/index.js +7 -0
- package/esm/pipeline/loaderUtils/mergeExternals.d.ts +32 -0
- package/esm/pipeline/loaderUtils/mergeExternals.js +72 -0
- package/esm/pipeline/loaderUtils/parseImports.d.ts +19 -0
- package/esm/pipeline/loaderUtils/parseImports.js +306 -0
- package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +19 -0
- package/esm/pipeline/loaderUtils/processRelativeImports.js +352 -0
- package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +87 -0
- package/esm/pipeline/loaderUtils/resolveModulePath.js +1435 -0
- package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +47 -0
- package/esm/pipeline/loaderUtils/resolveModulePathWithFs.js +150 -0
- package/esm/pipeline/loaderUtils/rewriteImports.d.ts +9 -0
- package/esm/pipeline/loaderUtils/rewriteImports.js +35 -0
- package/esm/pipeline/parseSource/addLineGutters.d.ts +9 -0
- package/esm/pipeline/parseSource/addLineGutters.js +181 -0
- package/esm/pipeline/parseSource/grammars.d.ts +2 -0
- package/esm/pipeline/parseSource/grammars.js +27 -0
- package/esm/pipeline/parseSource/index.d.ts +1 -0
- package/esm/pipeline/parseSource/index.js +1 -0
- package/esm/pipeline/parseSource/parseSource.d.ts +3 -0
- package/esm/pipeline/parseSource/parseSource.js +51 -0
- package/esm/pipeline/transformHtmlCode/index.d.ts +2 -0
- package/esm/pipeline/transformHtmlCode/index.js +4 -0
- package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +13 -0
- package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +300 -0
- package/esm/pipeline/transformMarkdownCode/index.d.ts +2 -0
- package/esm/pipeline/transformMarkdownCode/index.js +4 -0
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.d.ts +2 -0
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +514 -0
- package/esm/pipeline/transformTypescriptToJavascript/index.d.ts +1 -0
- package/esm/pipeline/transformTypescriptToJavascript/index.js +1 -0
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.d.ts +13 -0
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +131 -0
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.d.ts +3 -0
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +31 -0
- package/esm/useCode/Pre.d.ts +15 -0
- package/esm/useCode/Pre.js +164 -0
- package/esm/useCode/index.d.ts +1 -0
- package/esm/useCode/index.js +1 -0
- package/esm/useCode/useCode.d.ts +41 -0
- package/esm/useCode/useCode.js +128 -0
- package/esm/useCode/useCodeUtils.d.ts +44 -0
- package/esm/useCode/useCodeUtils.js +245 -0
- package/esm/useCode/useCopyFunctionality.d.ts +18 -0
- package/esm/useCode/useCopyFunctionality.js +28 -0
- package/esm/useCode/useFileNavigation.d.ts +41 -0
- package/esm/useCode/useFileNavigation.js +453 -0
- package/esm/useCode/useSourceEditing.d.ts +21 -0
- package/esm/useCode/useSourceEditing.js +32 -0
- package/esm/useCode/useTransformManagement.d.ts +30 -0
- package/esm/useCode/useTransformManagement.js +72 -0
- package/esm/useCode/useUIState.d.ts +16 -0
- package/esm/useCode/useUIState.js +21 -0
- package/esm/useCode/useVariantSelection.d.ts +23 -0
- package/esm/useCode/useVariantSelection.js +75 -0
- package/esm/useCopier/index.d.ts +1 -1
- package/esm/useCopier/index.js +5 -5
- package/esm/useDemo/createCodeSandbox.d.ts +15 -0
- package/esm/useDemo/createCodeSandbox.js +42 -0
- package/esm/useDemo/createStackBlitz.d.ts +22 -0
- package/esm/useDemo/createStackBlitz.js +38 -0
- package/esm/useDemo/exportVariant.d.ts +184 -0
- package/esm/useDemo/exportVariant.js +422 -0
- package/esm/useDemo/exportVariantAsCra.d.ts +15 -0
- package/esm/useDemo/exportVariantAsCra.js +57 -0
- package/esm/useDemo/flattenVariant.d.ts +19 -0
- package/esm/useDemo/flattenVariant.js +49 -0
- package/esm/useDemo/index.d.ts +6 -51
- package/esm/useDemo/index.js +6 -104
- package/esm/useDemo/useDemo.d.ts +81 -0
- package/esm/useDemo/useDemo.js +193 -0
- package/esm/useErrors/ErrorsContext.d.ts +6 -0
- package/esm/useErrors/ErrorsContext.js +8 -0
- package/esm/useErrors/index.d.ts +1 -0
- package/esm/useErrors/index.js +1 -0
- package/esm/useErrors/useErrors.d.ts +5 -0
- package/esm/useErrors/useErrors.js +7 -0
- package/esm/useLocalStorageState/index.d.ts +2 -0
- package/esm/useLocalStorageState/index.js +2 -0
- package/esm/useLocalStorageState/useLocalStorageState.d.ts +14 -0
- package/esm/useLocalStorageState/useLocalStorageState.js +128 -0
- package/esm/usePreference/PreferencesProvider.d.ts +6 -0
- package/esm/usePreference/PreferencesProvider.js +8 -0
- package/esm/usePreference/index.d.ts +2 -0
- package/esm/usePreference/index.js +2 -0
- package/esm/usePreference/usePreference.d.ts +2 -0
- package/esm/usePreference/usePreference.js +25 -0
- package/esm/useUrlHashState/index.d.ts +1 -0
- package/esm/useUrlHashState/index.js +1 -0
- package/esm/useUrlHashState/useUrlHashState.d.ts +5 -0
- package/esm/useUrlHashState/useUrlHashState.js +68 -0
- package/esm/withDocsInfra/index.d.ts +1 -0
- package/esm/withDocsInfra/index.js +1 -0
- package/esm/withDocsInfra/withDocsInfra.d.ts +82 -0
- package/esm/withDocsInfra/withDocsInfra.js +147 -0
- package/package.json +178 -11
- package/esm/useCopier/index.d.ts.map +0 -1
- package/esm/useDemo/index.d.ts.map +0 -1
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
/**
|
|
3
|
+
* Utility function for parsing function arguments and handling nested structures
|
|
4
|
+
* in JavaScript/TypeScript code with structured representations.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Structured argument types for discriminating between different code constructs:
|
|
9
|
+
* - `[Array]`: Literal array - e.g., `['1', '2', '3']`
|
|
10
|
+
* - `[String, Array]`: Function call - e.g., `['func', ['a', 'b']]`
|
|
11
|
+
* - `[String, Array, Array]`: Function with generics - e.g., `['Component', [{ foo: 'string' }], []]`
|
|
12
|
+
* - `[String, Array, null]`: Type with generics - e.g., `['Theme', ['"dark" | "light"'], null]`
|
|
13
|
+
* - `[Array, any]`: Simple arrow function - e.g., `[['evt'], 'evt.preventDefault()']`
|
|
14
|
+
* - `[Array, [any, any], any]`: Typed arrow function - e.g., `[['data'], ['string', 'Promise<string>'], ['Promise.resolve', ['data']]]`
|
|
15
|
+
* - `['as', string, any]`: TypeScript type assertion - e.g., `['as', 'React.FC<Props>', 'Component']`
|
|
16
|
+
* - `Record<string, any>`: Object literal - e.g., `{ key: 'value' }`
|
|
17
|
+
* - `string`: Plain string value
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Type guard and extractor for literal arrays
|
|
22
|
+
* @param value - The value to check
|
|
23
|
+
* @returns Object with items array if it's a literal array, false otherwise
|
|
24
|
+
*/
|
|
25
|
+
export function isArray(value) {
|
|
26
|
+
if (Array.isArray(value) && value.length === 1 && Array.isArray(value[0])) {
|
|
27
|
+
return {
|
|
28
|
+
items: value
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Type guard and extractor for function calls
|
|
36
|
+
* @param value - The value to check
|
|
37
|
+
* @returns Object with name and arguments if it's a function call, false otherwise
|
|
38
|
+
*/
|
|
39
|
+
export function isFunction(value) {
|
|
40
|
+
if (Array.isArray(value) && value.length === 2 && typeof value[0] === 'string' && Array.isArray(value[1])) {
|
|
41
|
+
return {
|
|
42
|
+
name: value[0],
|
|
43
|
+
arguments: value[1]
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Type guard and extractor for generics (both function and type generics)
|
|
51
|
+
* @param value - The value to check
|
|
52
|
+
* @returns Object with name, generics, and arguments (or null for types) if it's a generic, false otherwise
|
|
53
|
+
*/
|
|
54
|
+
export function isGeneric(value) {
|
|
55
|
+
if (Array.isArray(value) && value.length === 3 && typeof value[0] === 'string' && Array.isArray(value[1])) {
|
|
56
|
+
return {
|
|
57
|
+
name: value[0],
|
|
58
|
+
generics: value[1],
|
|
59
|
+
arguments: value[2]
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Type guard and extractor for arrow functions
|
|
67
|
+
* @param value - The value to check
|
|
68
|
+
* @returns Object with args, types (if typed), and returnValue if it's an arrow function, false otherwise
|
|
69
|
+
*/
|
|
70
|
+
export function isArrowFunction(value) {
|
|
71
|
+
if (Array.isArray(value) && Array.isArray(value[0])) {
|
|
72
|
+
if (value.length === 2) {
|
|
73
|
+
// Simple arrow function: [Array, any]
|
|
74
|
+
return {
|
|
75
|
+
args: value[0],
|
|
76
|
+
returnValue: value[1]
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (value.length === 3 && Array.isArray(value[1]) && value[1].length === 2) {
|
|
80
|
+
// Typed arrow function: [Array, [inputTypes, outputTypes], any]
|
|
81
|
+
return {
|
|
82
|
+
args: value[0],
|
|
83
|
+
types: [value[1][0], value[1][1]],
|
|
84
|
+
returnValue: value[2]
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Type guard and extractor for object literals
|
|
93
|
+
* @param value - The value to check
|
|
94
|
+
* @returns Object with properties if it's an object literal, false otherwise
|
|
95
|
+
*/
|
|
96
|
+
export function isObjectLiteral(value) {
|
|
97
|
+
if (_typeof(value) === 'object' && value !== null && !Array.isArray(value)) {
|
|
98
|
+
return {
|
|
99
|
+
properties: value
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Type guard and extractor for TypeScript type assertions
|
|
107
|
+
* @param value - The value to check
|
|
108
|
+
* @returns Object with type and expression if it's a type assertion, false otherwise
|
|
109
|
+
*/
|
|
110
|
+
export function isTypeAssertion(value) {
|
|
111
|
+
if (Array.isArray(value) && value.length === 3 && value[0] === 'as' && typeof value[1] === 'string') {
|
|
112
|
+
return {
|
|
113
|
+
type: value[1],
|
|
114
|
+
expression: value[2]
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Main API: Parse arguments and return structured representation
|
|
122
|
+
* This is the primary parsing function optimized for recursive data structures
|
|
123
|
+
*/
|
|
124
|
+
export function parseFunctionArguments(str) {
|
|
125
|
+
return parseArgumentsRecursive(str);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Parse entire file and extract all exports with their function calls
|
|
130
|
+
* Returns a mapping of export names to their function call information
|
|
131
|
+
*/
|
|
132
|
+
export function parseFileExports(fileContent) {
|
|
133
|
+
var exports = {};
|
|
134
|
+
|
|
135
|
+
// Find all export statements that assign function calls
|
|
136
|
+
var exportRegex = /export\s+const\s+(\w+)\s*=\s*(\w+)\s*\(/g;
|
|
137
|
+
var match = exportRegex.exec(fileContent);
|
|
138
|
+
while (match !== null) {
|
|
139
|
+
var exportName = match[1];
|
|
140
|
+
var functionName = match[2];
|
|
141
|
+
var callStartIndex = match.index;
|
|
142
|
+
var parenIndex = match.index + match[0].length - 1; // Position of opening parenthesis
|
|
143
|
+
|
|
144
|
+
// Find the matching closing parenthesis
|
|
145
|
+
var parenCount = 0;
|
|
146
|
+
var callEndIndex = -1;
|
|
147
|
+
for (var i = parenIndex; i < fileContent.length; i += 1) {
|
|
148
|
+
if (fileContent[i] === '(') {
|
|
149
|
+
parenCount += 1;
|
|
150
|
+
} else if (fileContent[i] === ')') {
|
|
151
|
+
parenCount -= 1;
|
|
152
|
+
if (parenCount === 0) {
|
|
153
|
+
callEndIndex = i;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (callEndIndex !== -1) {
|
|
159
|
+
// Extract the arguments content between parentheses
|
|
160
|
+
var argumentsContent = fileContent.substring(parenIndex + 1, callEndIndex);
|
|
161
|
+
exports[exportName] = {
|
|
162
|
+
functionName: functionName,
|
|
163
|
+
// Parse the arguments using existing logic
|
|
164
|
+
arguments: parseFunctionArguments(argumentsContent),
|
|
165
|
+
sourceRange: [callStartIndex, callEndIndex + 1]
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
match = exportRegex.exec(fileContent);
|
|
169
|
+
}
|
|
170
|
+
return exports;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Internal recursive parsing function
|
|
175
|
+
*/
|
|
176
|
+
function parseArgumentsRecursive(str) {
|
|
177
|
+
var result = [];
|
|
178
|
+
var current = '';
|
|
179
|
+
var parenCount = 0;
|
|
180
|
+
var braceCount = 0;
|
|
181
|
+
var bracketCount = 0;
|
|
182
|
+
var angleCount = 0;
|
|
183
|
+
var inSingleLineComment = false;
|
|
184
|
+
var inMultiLineComment = false;
|
|
185
|
+
var inString = false;
|
|
186
|
+
var stringChar = '';
|
|
187
|
+
for (var i = 0; i < str.length; i += 1) {
|
|
188
|
+
var _char = str[i];
|
|
189
|
+
var nextChar = str[i + 1];
|
|
190
|
+
|
|
191
|
+
// Handle comments
|
|
192
|
+
if (!inString && !inSingleLineComment && !inMultiLineComment) {
|
|
193
|
+
if (_char === '/' && nextChar === '/') {
|
|
194
|
+
inSingleLineComment = true;
|
|
195
|
+
current += _char;
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
if (_char === '/' && nextChar === '*') {
|
|
199
|
+
inMultiLineComment = true;
|
|
200
|
+
current += _char;
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (inSingleLineComment && _char === '\n') {
|
|
205
|
+
inSingleLineComment = false;
|
|
206
|
+
current += _char;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (inMultiLineComment && _char === '*' && nextChar === '/') {
|
|
210
|
+
inMultiLineComment = false;
|
|
211
|
+
current += _char + nextChar;
|
|
212
|
+
i += 1; // Skip next character
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (inSingleLineComment || inMultiLineComment) {
|
|
216
|
+
current += _char;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// Handle strings
|
|
221
|
+
if (!inString && (_char === '"' || _char === "'" || _char === '`')) {
|
|
222
|
+
inString = true;
|
|
223
|
+
stringChar = _char;
|
|
224
|
+
current += _char;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (inString && _char === stringChar && str[i - 1] !== '\\') {
|
|
228
|
+
inString = false;
|
|
229
|
+
stringChar = '';
|
|
230
|
+
current += _char;
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
if (inString) {
|
|
234
|
+
current += _char;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// Handle brackets and parentheses
|
|
239
|
+
if (_char === '(') {
|
|
240
|
+
parenCount += 1;
|
|
241
|
+
} else if (_char === ')') {
|
|
242
|
+
parenCount -= 1;
|
|
243
|
+
} else if (_char === '{') {
|
|
244
|
+
braceCount += 1;
|
|
245
|
+
} else if (_char === '}') {
|
|
246
|
+
braceCount -= 1;
|
|
247
|
+
} else if (_char === '[') {
|
|
248
|
+
bracketCount += 1;
|
|
249
|
+
} else if (_char === ']') {
|
|
250
|
+
bracketCount -= 1;
|
|
251
|
+
} else if (_char === '<') {
|
|
252
|
+
angleCount += 1;
|
|
253
|
+
} else if (_char === '>' && str[i - 1] !== '=') {
|
|
254
|
+
// Only count > as closing angle bracket if it's not part of =>
|
|
255
|
+
angleCount -= 1;
|
|
256
|
+
} else if (_char === ',' && parenCount === 0 && braceCount === 0 && bracketCount === 0 && angleCount === 0) {
|
|
257
|
+
var trimmedPart = current.trim();
|
|
258
|
+
if (trimmedPart) {
|
|
259
|
+
result.push(parseElement(trimmedPart));
|
|
260
|
+
}
|
|
261
|
+
current = '';
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
current += _char;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
// Handle the last part
|
|
268
|
+
if (current.trim()) {
|
|
269
|
+
var _trimmedPart = current.trim();
|
|
270
|
+
result.push(parseElement(_trimmedPart));
|
|
271
|
+
}
|
|
272
|
+
return result;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Parse a single element and determine its type/structure
|
|
277
|
+
*/
|
|
278
|
+
function parseElement(element) {
|
|
279
|
+
var trimmed = element.trim();
|
|
280
|
+
|
|
281
|
+
// Remove comments
|
|
282
|
+
trimmed = removeComments(trimmed);
|
|
283
|
+
|
|
284
|
+
// Handle object literals FIRST before checking for 'as'
|
|
285
|
+
if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
|
|
286
|
+
return parseObjectLiteral(trimmed);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// Handle TypeScript 'as' type assertions with structured representation
|
|
290
|
+
if (trimmed.includes(' as ')) {
|
|
291
|
+
return parseTypeAssertion(trimmed);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// Handle array literals
|
|
295
|
+
if (trimmed.startsWith('[') && trimmed.endsWith(']')) {
|
|
296
|
+
return parseArrayLiteral(trimmed);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// Handle arrow functions
|
|
300
|
+
if (trimmed.includes('=>')) {
|
|
301
|
+
return parseArrowFunction(trimmed);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Handle function calls and generics
|
|
305
|
+
if (trimmed.includes('(') || trimmed.includes('<')) {
|
|
306
|
+
return parseFunctionOrGeneric(trimmed);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// Everything else is just a string
|
|
310
|
+
return trimmed;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* Remove comments from a string
|
|
315
|
+
*/
|
|
316
|
+
function removeComments(str) {
|
|
317
|
+
var result = '';
|
|
318
|
+
var inSingleLineComment = false;
|
|
319
|
+
var inMultiLineComment = false;
|
|
320
|
+
var inString = false;
|
|
321
|
+
var stringChar = '';
|
|
322
|
+
for (var i = 0; i < str.length; i += 1) {
|
|
323
|
+
var _char2 = str[i];
|
|
324
|
+
var nextChar = str[i + 1];
|
|
325
|
+
|
|
326
|
+
// Handle strings first
|
|
327
|
+
if (!inSingleLineComment && !inMultiLineComment && !inString && (_char2 === '"' || _char2 === "'" || _char2 === '`')) {
|
|
328
|
+
inString = true;
|
|
329
|
+
stringChar = _char2;
|
|
330
|
+
result += _char2;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (inString && _char2 === stringChar && str[i - 1] !== '\\') {
|
|
334
|
+
inString = false;
|
|
335
|
+
stringChar = '';
|
|
336
|
+
result += _char2;
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (inString) {
|
|
340
|
+
result += _char2;
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// Handle comments
|
|
345
|
+
if (!inSingleLineComment && !inMultiLineComment) {
|
|
346
|
+
if (_char2 === '/' && nextChar === '/') {
|
|
347
|
+
inSingleLineComment = true;
|
|
348
|
+
i += 1; // Skip next character
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (_char2 === '/' && nextChar === '*') {
|
|
352
|
+
inMultiLineComment = true;
|
|
353
|
+
i += 1; // Skip next character
|
|
354
|
+
continue;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (inSingleLineComment && _char2 === '\n') {
|
|
358
|
+
inSingleLineComment = false;
|
|
359
|
+
result += _char2;
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
if (inMultiLineComment && _char2 === '*' && nextChar === '/') {
|
|
363
|
+
inMultiLineComment = false;
|
|
364
|
+
i += 1; // Skip next character
|
|
365
|
+
continue;
|
|
366
|
+
}
|
|
367
|
+
if (inSingleLineComment || inMultiLineComment) {
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
result += _char2;
|
|
371
|
+
}
|
|
372
|
+
return result.trim();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Parse object literal like { key: value, other: data }
|
|
377
|
+
*/
|
|
378
|
+
function parseObjectLiteral(str) {
|
|
379
|
+
var content = str.slice(1, -1).trim(); // Remove { }
|
|
380
|
+
if (!content) {
|
|
381
|
+
return {};
|
|
382
|
+
}
|
|
383
|
+
var obj = {};
|
|
384
|
+
|
|
385
|
+
// Parse object properties manually to handle complex types
|
|
386
|
+
var properties = parseObjectProperties(content);
|
|
387
|
+
for (var _i = 0, _properties = properties; _i < _properties.length; _i++) {
|
|
388
|
+
var prop = _properties[_i];
|
|
389
|
+
var colonIndex = prop.indexOf(':');
|
|
390
|
+
if (colonIndex !== -1) {
|
|
391
|
+
var key = prop.substring(0, colonIndex).trim();
|
|
392
|
+
var value = prop.substring(colonIndex + 1).trim();
|
|
393
|
+
// Parse the value
|
|
394
|
+
var parsedValue = parseElement(value);
|
|
395
|
+
|
|
396
|
+
// For object properties: preserve strings as-is, but only wrap array LITERALS in another array
|
|
397
|
+
if (typeof parsedValue === 'string' && !Array.isArray(parsedValue)) {
|
|
398
|
+
obj[key] = parsedValue;
|
|
399
|
+
} else if (Array.isArray(parsedValue)) {
|
|
400
|
+
// Only double-wrap array literals (parsed from [1, 2, 3])
|
|
401
|
+
// Functions and generics should remain as single arrays
|
|
402
|
+
var originalValue = value.trim();
|
|
403
|
+
if (originalValue.startsWith('[') && originalValue.endsWith(']')) {
|
|
404
|
+
// This is an array literal - double wrap it
|
|
405
|
+
obj[key] = [parsedValue];
|
|
406
|
+
} else {
|
|
407
|
+
// This is a function call or generic - keep as single array
|
|
408
|
+
obj[key] = parsedValue;
|
|
409
|
+
}
|
|
410
|
+
} else {
|
|
411
|
+
obj[key] = parsedValue;
|
|
412
|
+
}
|
|
413
|
+
} else {
|
|
414
|
+
// Shorthand property like { foo } -> { foo: 'foo' }
|
|
415
|
+
var trimmed = prop.trim();
|
|
416
|
+
obj[trimmed] = trimmed;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
return obj;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Parse object properties, handling complex nested types
|
|
424
|
+
*/
|
|
425
|
+
function parseObjectProperties(content) {
|
|
426
|
+
var properties = [];
|
|
427
|
+
var current = '';
|
|
428
|
+
var depth = 0;
|
|
429
|
+
var inString = false;
|
|
430
|
+
var stringChar = '';
|
|
431
|
+
for (var i = 0; i < content.length; i += 1) {
|
|
432
|
+
var _char3 = content[i];
|
|
433
|
+
var nextChar = content[i + 1];
|
|
434
|
+
if (!inString && (_char3 === '"' || _char3 === "'" || _char3 === '`')) {
|
|
435
|
+
inString = true;
|
|
436
|
+
stringChar = _char3;
|
|
437
|
+
} else if (inString && _char3 === stringChar && content[i - 1] !== '\\') {
|
|
438
|
+
inString = false;
|
|
439
|
+
stringChar = '';
|
|
440
|
+
}
|
|
441
|
+
if (!inString) {
|
|
442
|
+
if (_char3 === '<' || _char3 === '{' || _char3 === '(' || _char3 === '[') {
|
|
443
|
+
depth += 1;
|
|
444
|
+
} else if (_char3 === '>' && nextChar !== '=' && content[i - 1] !== '=') {
|
|
445
|
+
// Only count > as closing bracket if it's not part of => or >=
|
|
446
|
+
depth -= 1;
|
|
447
|
+
} else if (_char3 === '}' || _char3 === ')' || _char3 === ']') {
|
|
448
|
+
depth -= 1;
|
|
449
|
+
} else if (_char3 === ',' && depth === 0) {
|
|
450
|
+
if (current.trim()) {
|
|
451
|
+
properties.push(current.trim());
|
|
452
|
+
}
|
|
453
|
+
current = '';
|
|
454
|
+
continue;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
current += _char3;
|
|
458
|
+
}
|
|
459
|
+
if (current.trim()) {
|
|
460
|
+
properties.push(current.trim());
|
|
461
|
+
}
|
|
462
|
+
return properties;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Parse array literal like [1, 2, 3]
|
|
467
|
+
*/
|
|
468
|
+
function parseArrayLiteral(str) {
|
|
469
|
+
var content = str.slice(1, -1).trim(); // Remove [ ]
|
|
470
|
+
if (!content) {
|
|
471
|
+
return [];
|
|
472
|
+
}
|
|
473
|
+
return parseArgumentsRecursive(content);
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Parse arrow function like (a) => a + 1 or (data: string): Promise<string> => Promise.resolve(data)
|
|
478
|
+
*/
|
|
479
|
+
function parseArrowFunction(str) {
|
|
480
|
+
var arrowIndex = str.indexOf('=>');
|
|
481
|
+
var leftPart = str.substring(0, arrowIndex).trim();
|
|
482
|
+
var rightPart = str.substring(arrowIndex + 2).trim();
|
|
483
|
+
|
|
484
|
+
// Parse arguments
|
|
485
|
+
var args = [];
|
|
486
|
+
var types;
|
|
487
|
+
if (leftPart.startsWith('(') && leftPart.includes(')')) {
|
|
488
|
+
var parenEnd = leftPart.lastIndexOf(')');
|
|
489
|
+
var argsPart = leftPart.substring(1, parenEnd);
|
|
490
|
+
var afterParen = leftPart.substring(parenEnd + 1).trim();
|
|
491
|
+
args = argsPart ? parseArgumentsRecursive(argsPart) : [];
|
|
492
|
+
|
|
493
|
+
// Check for return type annotation
|
|
494
|
+
if (afterParen.startsWith(':')) {
|
|
495
|
+
var returnType = afterParen.substring(1).trim();
|
|
496
|
+
// Extract input types from args if they have type annotations
|
|
497
|
+
var inputTypes = args.map(function (arg) {
|
|
498
|
+
if (typeof arg === 'string' && arg.includes(':')) {
|
|
499
|
+
return arg.split(':')[1].trim();
|
|
500
|
+
}
|
|
501
|
+
return 'any';
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
// Clean argument names (remove type annotations)
|
|
505
|
+
args = args.map(function (arg) {
|
|
506
|
+
if (typeof arg === 'string' && arg.includes(':')) {
|
|
507
|
+
return arg.split(':')[0].trim();
|
|
508
|
+
}
|
|
509
|
+
return arg;
|
|
510
|
+
});
|
|
511
|
+
types = [inputTypes.length === 1 ? inputTypes[0] : inputTypes, returnType];
|
|
512
|
+
}
|
|
513
|
+
} else {
|
|
514
|
+
args = [leftPart];
|
|
515
|
+
}
|
|
516
|
+
var returnValue = parseElement(rightPart);
|
|
517
|
+
if (types) {
|
|
518
|
+
return [args, types, returnValue];
|
|
519
|
+
}
|
|
520
|
+
return [args, returnValue];
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Parse function calls and generics like func(a, b) or Component<{ foo: string }>
|
|
525
|
+
*/
|
|
526
|
+
function parseFunctionOrGeneric(str) {
|
|
527
|
+
// Check for generics first
|
|
528
|
+
var angleStart = str.indexOf('<');
|
|
529
|
+
var parenStart = str.indexOf('(');
|
|
530
|
+
if (angleStart !== -1 && (parenStart === -1 || angleStart < parenStart)) {
|
|
531
|
+
return parseGeneric(str);
|
|
532
|
+
}
|
|
533
|
+
if (parenStart !== -1) {
|
|
534
|
+
var result = parseFunctionCall(str);
|
|
535
|
+
// If parseFunctionCall detected property access and returned [str], unwrap it
|
|
536
|
+
if (Array.isArray(result) && result.length === 1 && result[0] === str) {
|
|
537
|
+
return str;
|
|
538
|
+
}
|
|
539
|
+
return result;
|
|
540
|
+
}
|
|
541
|
+
return str;
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Parse generic content while preserving nested structures
|
|
546
|
+
*/
|
|
547
|
+
function parseGenericContent(content) {
|
|
548
|
+
var elements = [];
|
|
549
|
+
var current = '';
|
|
550
|
+
var parenCount = 0;
|
|
551
|
+
var braceCount = 0;
|
|
552
|
+
var bracketCount = 0;
|
|
553
|
+
var angleCount = 0;
|
|
554
|
+
var inString = false;
|
|
555
|
+
var stringChar = '';
|
|
556
|
+
for (var i = 0; i < content.length; i += 1) {
|
|
557
|
+
var _char4 = content[i];
|
|
558
|
+
if (!inString && (_char4 === '"' || _char4 === "'")) {
|
|
559
|
+
inString = true;
|
|
560
|
+
stringChar = _char4;
|
|
561
|
+
current += _char4;
|
|
562
|
+
} else if (inString && _char4 === stringChar && content[i - 1] !== '\\') {
|
|
563
|
+
inString = false;
|
|
564
|
+
stringChar = '';
|
|
565
|
+
current += _char4;
|
|
566
|
+
} else if (!inString) {
|
|
567
|
+
if (_char4 === '(') {
|
|
568
|
+
parenCount += 1;
|
|
569
|
+
} else if (_char4 === ')') {
|
|
570
|
+
parenCount -= 1;
|
|
571
|
+
} else if (_char4 === '{') {
|
|
572
|
+
braceCount += 1;
|
|
573
|
+
} else if (_char4 === '}') {
|
|
574
|
+
braceCount -= 1;
|
|
575
|
+
} else if (_char4 === '[') {
|
|
576
|
+
bracketCount += 1;
|
|
577
|
+
} else if (_char4 === ']') {
|
|
578
|
+
bracketCount -= 1;
|
|
579
|
+
} else if (_char4 === '<') {
|
|
580
|
+
angleCount += 1;
|
|
581
|
+
} else if (_char4 === '>') {
|
|
582
|
+
angleCount -= 1;
|
|
583
|
+
} else if (_char4 === ',' && parenCount === 0 && braceCount === 0 && bracketCount === 0 && angleCount === 0) {
|
|
584
|
+
if (current.trim()) {
|
|
585
|
+
elements.push(parseElement(current.trim()));
|
|
586
|
+
}
|
|
587
|
+
current = '';
|
|
588
|
+
continue;
|
|
589
|
+
}
|
|
590
|
+
current += _char4;
|
|
591
|
+
} else {
|
|
592
|
+
current += _char4;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
if (current.trim()) {
|
|
596
|
+
elements.push(parseElement(current.trim()));
|
|
597
|
+
}
|
|
598
|
+
return elements;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* Parse generic like Component<{ foo: string }> or Theme<"dark" | "light", Component[]>
|
|
603
|
+
*/
|
|
604
|
+
function parseGeneric(str) {
|
|
605
|
+
var angleStart = str.indexOf('<');
|
|
606
|
+
var name = str.substring(0, angleStart).trim();
|
|
607
|
+
|
|
608
|
+
// Find matching closing angle bracket
|
|
609
|
+
var angleCount = 0;
|
|
610
|
+
var angleEnd = -1;
|
|
611
|
+
for (var i = angleStart; i < str.length; i += 1) {
|
|
612
|
+
if (str[i] === '<') {
|
|
613
|
+
angleCount += 1;
|
|
614
|
+
} else if (str[i] === '>') {
|
|
615
|
+
angleCount -= 1;
|
|
616
|
+
if (angleCount === 0) {
|
|
617
|
+
angleEnd = i;
|
|
618
|
+
break;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
if (angleEnd === -1) {
|
|
623
|
+
return [str];
|
|
624
|
+
}
|
|
625
|
+
var genericContent = str.substring(angleStart + 1, angleEnd).trim();
|
|
626
|
+
var afterGeneric = str.substring(angleEnd + 1).trim();
|
|
627
|
+
|
|
628
|
+
// Parse generic content - don't split on commas within generics for unions and arrays
|
|
629
|
+
var generics = genericContent ? parseGenericContent(genericContent) : [];
|
|
630
|
+
|
|
631
|
+
// Check if there are function arguments after the generic
|
|
632
|
+
if (afterGeneric.startsWith('(') && afterGeneric.endsWith(')')) {
|
|
633
|
+
var argContent = afterGeneric.slice(1, -1).trim();
|
|
634
|
+
var args = argContent ? parseArgumentsRecursive(argContent) : [];
|
|
635
|
+
return [name, generics, args];
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
// For standalone generics like Component<Props>, treat as function call with empty args
|
|
639
|
+
// This matches the test expectation for Component<{ foo: string }> -> ['Component', [{ foo: 'string' }], []]
|
|
640
|
+
return [name, generics, []];
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
/**
|
|
644
|
+
* Parse function call like func(a, b)
|
|
645
|
+
*/
|
|
646
|
+
function parseFunctionCall(str) {
|
|
647
|
+
var parenStart = str.indexOf('(');
|
|
648
|
+
var name = str.substring(0, parenStart).trim();
|
|
649
|
+
|
|
650
|
+
// Find matching closing parenthesis
|
|
651
|
+
var parenCount = 0;
|
|
652
|
+
var parenEnd = -1;
|
|
653
|
+
for (var i = parenStart; i < str.length; i += 1) {
|
|
654
|
+
if (str[i] === '(') {
|
|
655
|
+
parenCount += 1;
|
|
656
|
+
} else if (str[i] === ')') {
|
|
657
|
+
parenCount -= 1;
|
|
658
|
+
if (parenCount === 0) {
|
|
659
|
+
parenEnd = i;
|
|
660
|
+
break;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
if (parenEnd === -1) {
|
|
665
|
+
return [str];
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// Check if there's meaningful continuation after the closing parenthesis
|
|
669
|
+
var remainingLength = str.length - parenEnd - 1;
|
|
670
|
+
if (remainingLength > 0) {
|
|
671
|
+
// Skip whitespace to find the first meaningful character
|
|
672
|
+
var _i2 = parenEnd + 1;
|
|
673
|
+
while (_i2 < str.length && (str[_i2] === ' ' || str[_i2] === '\t' || str[_i2] === '\n' || str[_i2] === '\r')) {
|
|
674
|
+
_i2 += 1;
|
|
675
|
+
}
|
|
676
|
+
if (_i2 < str.length) {
|
|
677
|
+
var firstChar = str[_i2];
|
|
678
|
+
if (firstChar === '.' || firstChar === '[' || firstChar === '(' || firstChar === '!') {
|
|
679
|
+
// Property access, bracket notation, chained calls, or non-null assertion
|
|
680
|
+
return [str];
|
|
681
|
+
}
|
|
682
|
+
if (firstChar === '?' && _i2 + 1 < str.length && str[_i2 + 1] === '.') {
|
|
683
|
+
// Optional chaining
|
|
684
|
+
return [str];
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
var argContent = str.substring(parenStart + 1, parenEnd).trim();
|
|
689
|
+
if (!argContent) {
|
|
690
|
+
return [name, []];
|
|
691
|
+
}
|
|
692
|
+
var args = parseArgumentsRecursive(argContent);
|
|
693
|
+
|
|
694
|
+
// Special case: if there's a single array literal argument, flatten it
|
|
695
|
+
if (args.length === 1 && Array.isArray(args[0])) {
|
|
696
|
+
return [name, args[0]];
|
|
697
|
+
}
|
|
698
|
+
return [name, args];
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Parse TypeScript type assertion like "Component as React.FC<Props>"
|
|
703
|
+
*/
|
|
704
|
+
function parseTypeAssertion(str) {
|
|
705
|
+
var asIndex = str.indexOf(' as ');
|
|
706
|
+
if (asIndex === -1) {
|
|
707
|
+
return [str]; // fallback to string if no 'as' found
|
|
708
|
+
}
|
|
709
|
+
var expression = str.substring(0, asIndex).trim();
|
|
710
|
+
var type = str.substring(asIndex + 4).trim(); // +4 for ' as '
|
|
711
|
+
|
|
712
|
+
// Parse the expression part recursively in case it's complex
|
|
713
|
+
var parsedExpression = parseElement(expression);
|
|
714
|
+
return ['as', type, parsedExpression];
|
|
715
|
+
}
|