@mui/internal-docs-infra 0.1.1-canary.8 → 0.2.0-alpha.1
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,849 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
4
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
6
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
7
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
8
|
+
var _excluded = ["parseImportsResult", "remaining"];
|
|
9
|
+
import { parseImports } from "../loaderUtils/index.js";
|
|
10
|
+
import { parseFunctionArguments, isTypeAssertion, isFunction, isGeneric, isArray, isArrowFunction, isObjectLiteral } from "./parseFunctionArguments.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Parse options for create* factory call parsing
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Helper function to extract string value from parser output, removing quotes if present
|
|
18
|
+
*/
|
|
19
|
+
function extractStringValue(value) {
|
|
20
|
+
if (typeof value !== 'string') {
|
|
21
|
+
return String(value);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Remove surrounding quotes if present
|
|
25
|
+
var trimmed = value.trim();
|
|
26
|
+
if (trimmed.startsWith('"') && trimmed.endsWith('"') || trimmed.startsWith("'") && trimmed.endsWith("'")) {
|
|
27
|
+
return trimmed.slice(1, -1);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Handle template literals
|
|
31
|
+
if (trimmed.startsWith('`') && trimmed.endsWith('`')) {
|
|
32
|
+
return trimmed.slice(1, -1);
|
|
33
|
+
}
|
|
34
|
+
return trimmed;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Helper function to recursively clean up structured data from parser for user consumption,
|
|
39
|
+
* removing quotes from strings and converting basic types
|
|
40
|
+
*/
|
|
41
|
+
function cleanStructuredData(data) {
|
|
42
|
+
// Check all structured data types first using the parser helpers
|
|
43
|
+
|
|
44
|
+
// Check for function calls
|
|
45
|
+
var functionCall = isFunction(data);
|
|
46
|
+
if (functionCall) {
|
|
47
|
+
// Build a function call string like "console.log('test')"
|
|
48
|
+
var argStr = functionCall.arguments.map(function (arg) {
|
|
49
|
+
if (Array.isArray(arg)) {
|
|
50
|
+
return arg.map(function (a) {
|
|
51
|
+
return typeof a === 'string' ? a : String(a);
|
|
52
|
+
}).join(', ');
|
|
53
|
+
}
|
|
54
|
+
return typeof arg === 'string' ? arg : String(arg);
|
|
55
|
+
}).join(', ');
|
|
56
|
+
return "".concat(functionCall.name, "(").concat(argStr, ")");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Check for generic structures
|
|
60
|
+
var generic = isGeneric(data);
|
|
61
|
+
if (generic) {
|
|
62
|
+
// Build a generic string like "Component<{ foo: string }>"
|
|
63
|
+
var genericsStr = generic.generics.map(function (g) {
|
|
64
|
+
return typeof g === 'string' ? g : JSON.stringify(g);
|
|
65
|
+
}).join(', ');
|
|
66
|
+
if (generic.arguments && generic.arguments.length > 0) {
|
|
67
|
+
// Function with generics: Component<T>(args)
|
|
68
|
+
var argsStr = generic.arguments.map(function (p) {
|
|
69
|
+
return typeof p === 'string' ? p : String(p);
|
|
70
|
+
}).join(', ');
|
|
71
|
+
return "".concat(generic.name, "<").concat(genericsStr, ">(").concat(argsStr, ")");
|
|
72
|
+
}
|
|
73
|
+
// Type with generics: Component<T>
|
|
74
|
+
return "".concat(generic.name, "<").concat(genericsStr, ">");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Check for type assertions
|
|
78
|
+
var typeAssertion = isTypeAssertion(data);
|
|
79
|
+
if (typeAssertion) {
|
|
80
|
+
var cleanedExpression = cleanStructuredData(typeAssertion.expression);
|
|
81
|
+
return "".concat(cleanedExpression, " as ").concat(typeAssertion.type);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Check for arrow functions
|
|
85
|
+
var arrowFunction = isArrowFunction(data);
|
|
86
|
+
if (arrowFunction) {
|
|
87
|
+
var _argsStr = arrowFunction.args.map(function (p) {
|
|
88
|
+
return typeof p === 'string' ? p : String(p);
|
|
89
|
+
}).join(', ');
|
|
90
|
+
if (arrowFunction.types) {
|
|
91
|
+
// Typed arrow function
|
|
92
|
+
var _arrowFunction$types = _slicedToArray(arrowFunction.types, 2),
|
|
93
|
+
inputType = _arrowFunction$types[0],
|
|
94
|
+
outputType = _arrowFunction$types[1];
|
|
95
|
+
var _returnValue = cleanStructuredData(arrowFunction.returnValue);
|
|
96
|
+
return "(".concat(_argsStr, ": ").concat(inputType, "): ").concat(outputType, " => ").concat(_returnValue);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Simple arrow function
|
|
100
|
+
var returnValue = cleanStructuredData(arrowFunction.returnValue);
|
|
101
|
+
return "(".concat(_argsStr, ") => ").concat(returnValue);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Check for literal arrays
|
|
105
|
+
var arrayLiteral = isArray(data);
|
|
106
|
+
if (arrayLiteral) {
|
|
107
|
+
return arrayLiteral.items[0].map(cleanStructuredData);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// Check for object literals
|
|
111
|
+
var objectLiteral = isObjectLiteral(data);
|
|
112
|
+
if (objectLiteral) {
|
|
113
|
+
var cleaned = {};
|
|
114
|
+
for (var _i = 0, _Object$entries = Object.entries(objectLiteral.properties); _i < _Object$entries.length; _i++) {
|
|
115
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
116
|
+
key = _Object$entries$_i[0],
|
|
117
|
+
value = _Object$entries$_i[1];
|
|
118
|
+
cleaned[key] = cleanStructuredData(value);
|
|
119
|
+
}
|
|
120
|
+
return cleaned;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Handle basic types after structured data checks
|
|
124
|
+
|
|
125
|
+
if (typeof data === 'string') {
|
|
126
|
+
// First extract string value (handle quotes)
|
|
127
|
+
var extracted = extractStringValue(data);
|
|
128
|
+
|
|
129
|
+
// Then try type conversion
|
|
130
|
+
if (extracted === 'true') {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
if (extracted === 'false') {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// Check if it's a number (but be conservative about version strings like "1.0")
|
|
138
|
+
if (/^\d+(\.\d+)?$/.test(extracted)) {
|
|
139
|
+
var num = Number(extracted);
|
|
140
|
+
if (!Number.isNaN(num) && Number.isFinite(num)) {
|
|
141
|
+
// Don't convert simple version-like patterns (e.g., "1.0", "2.0", but convert "123.45")
|
|
142
|
+
if (extracted.includes('.')) {
|
|
143
|
+
// For decimals, only convert if it's not a simple version pattern
|
|
144
|
+
// Version patterns are typically single digit followed by .0 or simple patterns
|
|
145
|
+
if (!/^\d{1,2}\.0$/.test(extracted)) {
|
|
146
|
+
return num;
|
|
147
|
+
}
|
|
148
|
+
} else {
|
|
149
|
+
// Convert all integers
|
|
150
|
+
return num;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return extracted;
|
|
155
|
+
}
|
|
156
|
+
if (Array.isArray(data)) {
|
|
157
|
+
// Fallback for arrays that don't match structured patterns
|
|
158
|
+
return data.map(cleanStructuredData);
|
|
159
|
+
}
|
|
160
|
+
if (data && _typeof(data) === 'object') {
|
|
161
|
+
// Fallback for objects that don't match structured patterns
|
|
162
|
+
var _cleaned = {};
|
|
163
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(data); _i2 < _Object$entries2.length; _i2++) {
|
|
164
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
165
|
+
_key = _Object$entries2$_i[0],
|
|
166
|
+
_value = _Object$entries2$_i[1];
|
|
167
|
+
_cleaned[_key] = cleanStructuredData(_value);
|
|
168
|
+
}
|
|
169
|
+
return _cleaned;
|
|
170
|
+
}
|
|
171
|
+
return data;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Helper function to con );
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// Throw error if the identifier is not found in imports
|
|
179
|
+
throw new Error(
|
|
180
|
+
`Invalid variants arguments in ${functionName} call in ${filePath}. ` +
|
|
181
|
+
`Component '${typeof structuredVariants === 'string' ? structuredVariants : JSON.stringify(structuredVariants)}' is not imported. Make sure to import it first.`,
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Parse variants from object representation (new format)
|
|
187
|
+
*/
|
|
188
|
+
function parseVariantsObjectFromObject(obj, importMap, namedExportsMap, functionName, filePath) {
|
|
189
|
+
var demoImports = {};
|
|
190
|
+
var namedExports = {};
|
|
191
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(obj); _i3 < _Object$entries3.length; _i3++) {
|
|
192
|
+
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
193
|
+
key = _Object$entries3$_i[0],
|
|
194
|
+
value = _Object$entries3$_i[1];
|
|
195
|
+
// Handle both string values and structured values (arrays for TypeScript generics)
|
|
196
|
+
var importName = void 0;
|
|
197
|
+
|
|
198
|
+
// Use type discriminators to determine the structure type
|
|
199
|
+
var typeAssertion = isTypeAssertion(value);
|
|
200
|
+
if (typeAssertion) {
|
|
201
|
+
// This is a structured type assertion: ['as', 'React.FC<Props>', 'Component']
|
|
202
|
+
// Extract the actual component name from the expression
|
|
203
|
+
var expression = typeAssertion.expression;
|
|
204
|
+
importName = typeof expression === 'string' ? expression : String(expression);
|
|
205
|
+
} else if (typeof value === 'string') {
|
|
206
|
+
// Simple string value - strip TypeScript type assertions
|
|
207
|
+
var asIndex = value.indexOf(' as ');
|
|
208
|
+
importName = asIndex !== -1 ? value.substring(0, asIndex).trim() : value.trim();
|
|
209
|
+
} else {
|
|
210
|
+
// Handle other structured types (functions, generics, arrays)
|
|
211
|
+
var functionCall = isFunction(value);
|
|
212
|
+
var generic = isGeneric(value);
|
|
213
|
+
var arrayLiteral = isArray(value);
|
|
214
|
+
if (functionCall) {
|
|
215
|
+
// Function call: ['Component', [...]]
|
|
216
|
+
importName = functionCall.name;
|
|
217
|
+
} else if (generic) {
|
|
218
|
+
// Generic: ['Component', [...], [...]]
|
|
219
|
+
importName = generic.name;
|
|
220
|
+
} else if (arrayLiteral) {
|
|
221
|
+
// Array literal: handle first element
|
|
222
|
+
var firstItem = arrayLiteral.items[0];
|
|
223
|
+
importName = typeof firstItem === 'string' ? firstItem : String(firstItem);
|
|
224
|
+
} else if (Array.isArray(value) && value.length > 0) {
|
|
225
|
+
// Fallback for unrecognized array structures
|
|
226
|
+
var componentExpression = String(value[0]);
|
|
227
|
+
var _asIndex = componentExpression.indexOf(' as ');
|
|
228
|
+
importName = _asIndex !== -1 ? componentExpression.substring(0, _asIndex).trim() : componentExpression.trim();
|
|
229
|
+
} else {
|
|
230
|
+
// Final fallback - convert to string and extract
|
|
231
|
+
var valueStr = String(value);
|
|
232
|
+
var _asIndex2 = valueStr.indexOf(' as ');
|
|
233
|
+
importName = _asIndex2 !== -1 ? valueStr.substring(0, _asIndex2).trim() : valueStr.trim();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (importMap.has(importName)) {
|
|
237
|
+
demoImports[key] = importMap.get(importName);
|
|
238
|
+
namedExports[key] = namedExportsMap.get(importName);
|
|
239
|
+
} else {
|
|
240
|
+
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."));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return {
|
|
244
|
+
variants: demoImports,
|
|
245
|
+
namedExports: namedExports
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Helper function to convert the new parseImports format to a Map
|
|
251
|
+
* that maps import names to their resolved paths
|
|
252
|
+
*/
|
|
253
|
+
function buildImportMap(importResult, allowExternalVariants) {
|
|
254
|
+
var importMap = new Map();
|
|
255
|
+
Object.values(importResult.relative).forEach(function (_ref) {
|
|
256
|
+
var path = _ref.path,
|
|
257
|
+
names = _ref.names;
|
|
258
|
+
names.forEach(function (_ref2) {
|
|
259
|
+
var name = _ref2.name,
|
|
260
|
+
alias = _ref2.alias;
|
|
261
|
+
// Use alias if available, otherwise use the original name
|
|
262
|
+
var nameToUse = alias || name;
|
|
263
|
+
importMap.set(nameToUse, path);
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
// Include external imports if allowExternalVariants is enabled
|
|
268
|
+
if (allowExternalVariants) {
|
|
269
|
+
Object.entries(importResult.externals).forEach(function (_ref3) {
|
|
270
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
271
|
+
modulePath = _ref4[0],
|
|
272
|
+
externalImport = _ref4[1];
|
|
273
|
+
if (externalImport && externalImport.names) {
|
|
274
|
+
externalImport.names.forEach(function (_ref5) {
|
|
275
|
+
var name = _ref5.name,
|
|
276
|
+
alias = _ref5.alias;
|
|
277
|
+
// Use alias if available, otherwise use the original name
|
|
278
|
+
var nameToUse = alias || name;
|
|
279
|
+
importMap.set(nameToUse, modulePath);
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
}
|
|
284
|
+
return importMap;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Helper function to build a mapping from import aliases to their original named exports
|
|
289
|
+
*/
|
|
290
|
+
function buildNamedExportsMap(importResult, allowExternalVariants) {
|
|
291
|
+
var namedExportsMap = new Map();
|
|
292
|
+
Object.values(importResult.relative).forEach(function (_ref6) {
|
|
293
|
+
var names = _ref6.names;
|
|
294
|
+
names.forEach(function (_ref7) {
|
|
295
|
+
var name = _ref7.name,
|
|
296
|
+
alias = _ref7.alias,
|
|
297
|
+
type = _ref7.type;
|
|
298
|
+
// Use alias if available, otherwise use the original name as key
|
|
299
|
+
var nameToUse = alias || name;
|
|
300
|
+
|
|
301
|
+
// Only map to the original export name for named imports
|
|
302
|
+
// Default imports should map to undefined since they don't have a specific named export
|
|
303
|
+
if (type === 'named') {
|
|
304
|
+
namedExportsMap.set(nameToUse, name);
|
|
305
|
+
} else {
|
|
306
|
+
namedExportsMap.set(nameToUse, undefined); // undefined for default/namespace imports
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
// Include external imports if allowExternalVariants is enabled
|
|
312
|
+
if (allowExternalVariants) {
|
|
313
|
+
Object.entries(importResult.externals).forEach(function (_ref8) {
|
|
314
|
+
var _ref9 = _slicedToArray(_ref8, 2),
|
|
315
|
+
externalImport = _ref9[1];
|
|
316
|
+
if (externalImport && externalImport.names) {
|
|
317
|
+
externalImport.names.forEach(function (_ref0) {
|
|
318
|
+
var name = _ref0.name,
|
|
319
|
+
alias = _ref0.alias,
|
|
320
|
+
type = _ref0.type;
|
|
321
|
+
// Use alias if available, otherwise use the original name as key
|
|
322
|
+
var nameToUse = alias || name;
|
|
323
|
+
|
|
324
|
+
// Only map to the original export name for named imports
|
|
325
|
+
// Default imports should map to undefined since they don't have a specific named export
|
|
326
|
+
if (type === 'named') {
|
|
327
|
+
namedExportsMap.set(nameToUse, name);
|
|
328
|
+
} else {
|
|
329
|
+
namedExportsMap.set(nameToUse, undefined); // undefined for default/namespace imports
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
return namedExportsMap;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Parses a variants object using pre-parsed structured data
|
|
339
|
+
*/
|
|
340
|
+
function parseVariantsObjectFromStructured(structuredData, importMap, namedExportsMap, functionName, filePath) {
|
|
341
|
+
var demoImports = {};
|
|
342
|
+
var namedExports = {};
|
|
343
|
+
var _iterator = _createForOfIteratorHelper(structuredData),
|
|
344
|
+
_step;
|
|
345
|
+
try {
|
|
346
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
347
|
+
var item = _step.value;
|
|
348
|
+
// If it's a string, process it directly
|
|
349
|
+
if (typeof item === 'string') {
|
|
350
|
+
var trimmedPart = item.trim();
|
|
351
|
+
|
|
352
|
+
// Check if this part contains a colon (key: value syntax)
|
|
353
|
+
var colonIndex = trimmedPart.indexOf(':');
|
|
354
|
+
if (colonIndex !== -1) {
|
|
355
|
+
// Handle "key: value" syntax
|
|
356
|
+
var key = trimmedPart.substring(0, colonIndex).trim();
|
|
357
|
+
var valueExpression = trimmedPart.substring(colonIndex + 1).trim();
|
|
358
|
+
|
|
359
|
+
// Strip TypeScript type assertions (e.g., "Component as React.ComponentType<...>" -> "Component")
|
|
360
|
+
var asIndex = valueExpression.indexOf(' as ');
|
|
361
|
+
var importName = asIndex !== -1 ? valueExpression.substring(0, asIndex).trim() : valueExpression;
|
|
362
|
+
if (importMap.has(importName)) {
|
|
363
|
+
demoImports[key] = importMap.get(importName);
|
|
364
|
+
namedExports[key] = namedExportsMap.get(importName);
|
|
365
|
+
} else {
|
|
366
|
+
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."));
|
|
367
|
+
}
|
|
368
|
+
} else {
|
|
369
|
+
// Handle shorthand syntax (just the component name)
|
|
370
|
+
var _importName = trimmedPart;
|
|
371
|
+
if (importMap.has(_importName)) {
|
|
372
|
+
demoImports[_importName] = importMap.get(_importName);
|
|
373
|
+
namedExports[_importName] = namedExportsMap.get(_importName);
|
|
374
|
+
} else {
|
|
375
|
+
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."));
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
// If it's an array (nested structure), we don't expect this in variants parsing
|
|
380
|
+
// but we could handle it if needed in the future
|
|
381
|
+
}
|
|
382
|
+
} catch (err) {
|
|
383
|
+
_iterator.e(err);
|
|
384
|
+
} finally {
|
|
385
|
+
_iterator.f();
|
|
386
|
+
}
|
|
387
|
+
return {
|
|
388
|
+
variants: demoImports,
|
|
389
|
+
namedExports: namedExports
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Parses variants argument using pre-parsed structured data
|
|
395
|
+
*/
|
|
396
|
+
function parseVariantsArgumentFromStructured(structuredVariants, importMap, namedExportsMap, functionName, filePath) {
|
|
397
|
+
// If it's an object (Record<string, string>)
|
|
398
|
+
if (_typeof(structuredVariants) === 'object' && !Array.isArray(structuredVariants)) {
|
|
399
|
+
// We have an object with key-value pairs
|
|
400
|
+
return parseVariantsObjectFromObject(structuredVariants, importMap, namedExportsMap, functionName, filePath);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// If it's an array (object literal parsed into structured data)
|
|
404
|
+
if (Array.isArray(structuredVariants)) {
|
|
405
|
+
// Parse the object contents using structured data
|
|
406
|
+
return parseVariantsObjectFromStructured(structuredVariants, importMap, namedExportsMap, functionName, filePath);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// If it's a single identifier string
|
|
410
|
+
if (typeof structuredVariants === 'string') {
|
|
411
|
+
var componentName = structuredVariants.trim();
|
|
412
|
+
if (importMap.has(componentName)) {
|
|
413
|
+
return {
|
|
414
|
+
variants: {
|
|
415
|
+
Default: importMap.get(componentName)
|
|
416
|
+
},
|
|
417
|
+
namedExports: {
|
|
418
|
+
Default: namedExportsMap.get(componentName)
|
|
419
|
+
}
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// Throw error if the identifier is not found in imports
|
|
424
|
+
throw new Error("Invalid variants argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Component '".concat(componentName, "' is not imported. Make sure to import it first."));
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// If we reach here, the structured data format is unexpected
|
|
428
|
+
throw new Error("Unexpected structured variants format in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected string, array, or object but got: ".concat(_typeof(structuredVariants)));
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Validates that a URL argument follows the expected convention
|
|
433
|
+
*/
|
|
434
|
+
function validateUrlArgument(url, functionName, filePath) {
|
|
435
|
+
var trimmedUrl = url.trim();
|
|
436
|
+
|
|
437
|
+
// Only accept import.meta.url
|
|
438
|
+
if (trimmedUrl === 'import.meta.url') {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// For error messages, show the argument as parsed by parseFunctionArguments
|
|
443
|
+
// Simple string literals preserve their quotes, complex expressions are shown as parsed
|
|
444
|
+
var errorUrl = trimmedUrl;
|
|
445
|
+
throw new Error("Invalid URL argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 'import.meta.url' but got: ".concat(errorUrl));
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Validates that a variants argument is either an object mapping to imports or a single identifier
|
|
450
|
+
*/
|
|
451
|
+
function validateVariantsArgument(structuredVariants, functionName, filePath) {
|
|
452
|
+
if (!structuredVariants) {
|
|
453
|
+
throw new Error("Invalid variants argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object mapping variant names to imports or a single component identifier.");
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
// Check if it's a valid single identifier (string)
|
|
457
|
+
if (typeof structuredVariants === 'string') {
|
|
458
|
+
var trimmed = structuredVariants.trim();
|
|
459
|
+
if (!trimmed || !/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(trimmed)) {
|
|
460
|
+
throw new Error("Invalid variants argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected a valid component identifier, but got: \"".concat(trimmed, "\""));
|
|
461
|
+
}
|
|
462
|
+
return; // Valid identifier
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
// Check if it's an array (object literal structure) or object (parsed key-value pairs)
|
|
466
|
+
if (Array.isArray(structuredVariants) || _typeof(structuredVariants) === 'object' && structuredVariants !== null) {
|
|
467
|
+
return; // Valid object structure
|
|
468
|
+
}
|
|
469
|
+
throw new Error("Invalid variants argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object mapping variant names to imports or a single component identifier, but got: ".concat(_typeof(structuredVariants)));
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Parses a file to extract a single create* factory call and its variants and options
|
|
474
|
+
* Returns the parsed result with remaining content included
|
|
475
|
+
* Returns null if no create* call is found
|
|
476
|
+
*/
|
|
477
|
+
export function parseCreateFactoryCall(_x, _x2) {
|
|
478
|
+
return _parseCreateFactoryCall.apply(this, arguments);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Parses all create* factory calls in a file sequentially
|
|
483
|
+
* Returns a record of export names mapped to their parsed factory calls
|
|
484
|
+
*/
|
|
485
|
+
function _parseCreateFactoryCall() {
|
|
486
|
+
_parseCreateFactoryCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(code, filePath) {
|
|
487
|
+
var parseOptions,
|
|
488
|
+
parseImportsResult,
|
|
489
|
+
createFactoryMatches,
|
|
490
|
+
match,
|
|
491
|
+
functionName,
|
|
492
|
+
fullMatch,
|
|
493
|
+
urlArg,
|
|
494
|
+
structuredVariants,
|
|
495
|
+
optionsStructured,
|
|
496
|
+
hasOptions,
|
|
497
|
+
argumentsStartIndex,
|
|
498
|
+
argumentsEndIndex,
|
|
499
|
+
allowExternalVariants,
|
|
500
|
+
importMap,
|
|
501
|
+
namedExportsMap,
|
|
502
|
+
externals,
|
|
503
|
+
_parseOptions$metadat2,
|
|
504
|
+
metadataOnly,
|
|
505
|
+
url,
|
|
506
|
+
variants,
|
|
507
|
+
namedExports,
|
|
508
|
+
variantsResult,
|
|
509
|
+
options,
|
|
510
|
+
skipPrecomputeValue,
|
|
511
|
+
transformedExternals,
|
|
512
|
+
_i4,
|
|
513
|
+
_Object$entries4,
|
|
514
|
+
_Object$entries4$_i,
|
|
515
|
+
modulePath,
|
|
516
|
+
externalImport,
|
|
517
|
+
remaining,
|
|
518
|
+
parsed,
|
|
519
|
+
_args = arguments,
|
|
520
|
+
_t;
|
|
521
|
+
return _regenerator().w(function (_context) {
|
|
522
|
+
while (1) switch (_context.n) {
|
|
523
|
+
case 0:
|
|
524
|
+
parseOptions = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
|
|
525
|
+
parseImportsResult = _args.length > 3 ? _args[3] : undefined;
|
|
526
|
+
// Find all create* calls in the code
|
|
527
|
+
createFactoryMatches = findCreateFactoryCalls(code, filePath, parseOptions); // Enforce single create* call per file unless allowMultipleFactories is true
|
|
528
|
+
if (!(!parseOptions.allowMultipleFactories && createFactoryMatches.length > 1)) {
|
|
529
|
+
_context.n = 1;
|
|
530
|
+
break;
|
|
531
|
+
}
|
|
532
|
+
throw new Error("Multiple create* factory calls found in ".concat(filePath, ". Only one create* call per file is supported. Found ").concat(createFactoryMatches.length, " calls."));
|
|
533
|
+
case 1:
|
|
534
|
+
if (!(createFactoryMatches.length === 0)) {
|
|
535
|
+
_context.n = 2;
|
|
536
|
+
break;
|
|
537
|
+
}
|
|
538
|
+
return _context.a(2, null);
|
|
539
|
+
case 2:
|
|
540
|
+
match = createFactoryMatches[0];
|
|
541
|
+
functionName = match.functionName, fullMatch = match.fullMatch, urlArg = match.urlArg, structuredVariants = match.structuredVariants, optionsStructured = match.optionsStructured, hasOptions = match.hasOptions, argumentsStartIndex = match.argumentsStartIndex, argumentsEndIndex = match.argumentsEndIndex; // Get import mappings from precomputed imports or parse them
|
|
542
|
+
_t = parseImportsResult;
|
|
543
|
+
if (_t) {
|
|
544
|
+
_context.n = 4;
|
|
545
|
+
break;
|
|
546
|
+
}
|
|
547
|
+
_context.n = 3;
|
|
548
|
+
return parseImports(code, filePath);
|
|
549
|
+
case 3:
|
|
550
|
+
_t = _context.v;
|
|
551
|
+
case 4:
|
|
552
|
+
parseImportsResult = _t;
|
|
553
|
+
allowExternalVariants = parseOptions.allowExternalVariants || false;
|
|
554
|
+
importMap = buildImportMap(parseImportsResult, allowExternalVariants);
|
|
555
|
+
namedExportsMap = buildNamedExportsMap(parseImportsResult, allowExternalVariants);
|
|
556
|
+
externals = parseImportsResult.externals; // Validate URL argument
|
|
557
|
+
validateUrlArgument(urlArg, functionName, filePath);
|
|
558
|
+
|
|
559
|
+
// Validate variants argument (skip in metadata-only mode)
|
|
560
|
+
_parseOptions$metadat2 = parseOptions.metadataOnly, metadataOnly = _parseOptions$metadat2 === void 0 ? false : _parseOptions$metadat2;
|
|
561
|
+
if (!metadataOnly && structuredVariants !== undefined) {
|
|
562
|
+
validateVariantsArgument(structuredVariants, functionName, filePath);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// Extract URL (typically import.meta.url)
|
|
566
|
+
url = urlArg.trim(); // Resolve variants using structured data (skip in metadata-only mode)
|
|
567
|
+
if (!metadataOnly && structuredVariants !== undefined) {
|
|
568
|
+
variantsResult = parseVariantsArgumentFromStructured(structuredVariants, importMap, namedExportsMap, functionName, filePath);
|
|
569
|
+
variants = variantsResult.variants;
|
|
570
|
+
namedExports = variantsResult.namedExports;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
// Parse options object
|
|
574
|
+
// Initialize with all options from structured data, then override specific fields
|
|
575
|
+
options = optionsStructured && _typeof(optionsStructured) === 'object' ? cleanStructuredData(optionsStructured) : {}; // Override with specific processing for known fields that need special handling
|
|
576
|
+
if (optionsStructured && _typeof(optionsStructured) === 'object') {
|
|
577
|
+
if ('name' in optionsStructured) {
|
|
578
|
+
options.name = extractStringValue(optionsStructured.name);
|
|
579
|
+
}
|
|
580
|
+
if ('slug' in optionsStructured) {
|
|
581
|
+
options.slug = extractStringValue(optionsStructured.slug);
|
|
582
|
+
}
|
|
583
|
+
if ('skipPrecompute' in optionsStructured) {
|
|
584
|
+
skipPrecomputeValue = optionsStructured.skipPrecompute;
|
|
585
|
+
if (skipPrecomputeValue === 'true' || skipPrecomputeValue === true) {
|
|
586
|
+
options.skipPrecompute = true;
|
|
587
|
+
} else if (skipPrecomputeValue === 'false' || skipPrecomputeValue === false) {
|
|
588
|
+
options.skipPrecompute = false;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// Handle precompute from structured data - clean for user consumption
|
|
593
|
+
if ('precompute' in optionsStructured) {
|
|
594
|
+
options.precompute = cleanStructuredData(optionsStructured.precompute);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// Transform externals from parseImports format to simplified format
|
|
599
|
+
// Only include side-effect imports (where names array is empty)
|
|
600
|
+
transformedExternals = {};
|
|
601
|
+
for (_i4 = 0, _Object$entries4 = Object.entries(externals); _i4 < _Object$entries4.length; _i4++) {
|
|
602
|
+
_Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2), modulePath = _Object$entries4$_i[0], externalImport = _Object$entries4$_i[1];
|
|
603
|
+
// Only include side-effect imports (empty names array)
|
|
604
|
+
if (externalImport.names.length === 0) {
|
|
605
|
+
transformedExternals[modulePath] = []; // Empty array for side-effect imports
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
// Calculate remaining content after the function call
|
|
610
|
+
remaining = code.substring(match.functionEndIndex + 1);
|
|
611
|
+
parsed = {
|
|
612
|
+
functionName: functionName,
|
|
613
|
+
url: url,
|
|
614
|
+
variants: variants,
|
|
615
|
+
namedExports: namedExports,
|
|
616
|
+
options: options,
|
|
617
|
+
fullMatch: fullMatch,
|
|
618
|
+
hasOptions: hasOptions,
|
|
619
|
+
externals: transformedExternals,
|
|
620
|
+
argumentsStartIndex: argumentsStartIndex,
|
|
621
|
+
argumentsEndIndex: argumentsEndIndex,
|
|
622
|
+
// Add structured data for serialization - this preserves quotes for proper output
|
|
623
|
+
structuredUrl: urlArg,
|
|
624
|
+
structuredVariants: structuredVariants,
|
|
625
|
+
structuredOptions: optionsStructured,
|
|
626
|
+
// Use original structured data, not cleaned options
|
|
627
|
+
remaining: remaining,
|
|
628
|
+
parseImportsResult: parseImportsResult // Include import data for reuse
|
|
629
|
+
};
|
|
630
|
+
return _context.a(2, parsed);
|
|
631
|
+
}
|
|
632
|
+
}, _callee);
|
|
633
|
+
}));
|
|
634
|
+
return _parseCreateFactoryCall.apply(this, arguments);
|
|
635
|
+
}
|
|
636
|
+
export function parseAllCreateFactoryCalls(_x3, _x4) {
|
|
637
|
+
return _parseAllCreateFactoryCalls.apply(this, arguments);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Finds create* factory calls in code, handling multiline cases
|
|
642
|
+
*/
|
|
643
|
+
function _parseAllCreateFactoryCalls() {
|
|
644
|
+
_parseAllCreateFactoryCalls = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(code, filePath) {
|
|
645
|
+
var parseOptions,
|
|
646
|
+
results,
|
|
647
|
+
currentCode,
|
|
648
|
+
parseImportsResult,
|
|
649
|
+
result,
|
|
650
|
+
exportMatch,
|
|
651
|
+
exportName,
|
|
652
|
+
unusedResult,
|
|
653
|
+
unusedRemaining,
|
|
654
|
+
parsedFactory,
|
|
655
|
+
_args2 = arguments;
|
|
656
|
+
return _regenerator().w(function (_context2) {
|
|
657
|
+
while (1) switch (_context2.n) {
|
|
658
|
+
case 0:
|
|
659
|
+
parseOptions = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
|
|
660
|
+
results = {}; // Process the code sequentially, reusing import data from the first call
|
|
661
|
+
currentCode = code;
|
|
662
|
+
case 1:
|
|
663
|
+
if (!currentCode.trim()) {
|
|
664
|
+
_context2.n = 5;
|
|
665
|
+
break;
|
|
666
|
+
}
|
|
667
|
+
_context2.n = 2;
|
|
668
|
+
return parseCreateFactoryCall(currentCode, filePath, _extends(_extends({}, parseOptions), {}, {
|
|
669
|
+
allowMultipleFactories: true
|
|
670
|
+
}),
|
|
671
|
+
// Allow multiple factories for this function
|
|
672
|
+
parseImportsResult // undefined for first call, reused for subsequent calls
|
|
673
|
+
);
|
|
674
|
+
case 2:
|
|
675
|
+
result = _context2.v;
|
|
676
|
+
if (result) {
|
|
677
|
+
_context2.n = 3;
|
|
678
|
+
break;
|
|
679
|
+
}
|
|
680
|
+
return _context2.a(3, 5);
|
|
681
|
+
case 3:
|
|
682
|
+
// Extract export name from the function call context
|
|
683
|
+
exportMatch = currentCode.match(/export\s+const\s+(\w+)\s*=/);
|
|
684
|
+
exportName = (exportMatch == null ? void 0 : exportMatch[1]) || 'unknown'; // Capture import data from the first successful call for reuse
|
|
685
|
+
parseImportsResult = result.parseImportsResult || parseImportsResult;
|
|
686
|
+
|
|
687
|
+
// Remove the parseImportsResult before storing (we don't need it in the final result)
|
|
688
|
+
unusedResult = result.parseImportsResult, unusedRemaining = result.remaining, parsedFactory = _objectWithoutPropertiesLoose(result, _excluded);
|
|
689
|
+
results[exportName] = parsedFactory;
|
|
690
|
+
|
|
691
|
+
// Move to the remaining code after this export
|
|
692
|
+
if (result.remaining) {
|
|
693
|
+
_context2.n = 4;
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
currentCode = '';
|
|
697
|
+
return _context2.a(3, 5);
|
|
698
|
+
case 4:
|
|
699
|
+
currentCode = result.remaining;
|
|
700
|
+
_context2.n = 1;
|
|
701
|
+
break;
|
|
702
|
+
case 5:
|
|
703
|
+
return _context2.a(2, results);
|
|
704
|
+
}
|
|
705
|
+
}, _callee2);
|
|
706
|
+
}));
|
|
707
|
+
return _parseAllCreateFactoryCalls.apply(this, arguments);
|
|
708
|
+
}
|
|
709
|
+
function findCreateFactoryCalls(code, filePath) {
|
|
710
|
+
var parseOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
711
|
+
var results = [];
|
|
712
|
+
|
|
713
|
+
// Find all create* function calls
|
|
714
|
+
var createFactoryRegex = /\b(create\w*)\s*\(/g;
|
|
715
|
+
var match = createFactoryRegex.exec(code);
|
|
716
|
+
while (match !== null) {
|
|
717
|
+
var functionName = match[1];
|
|
718
|
+
var startIndex = match.index;
|
|
719
|
+
var parenIndex = match.index + match[0].length - 1; // Position of opening parenthesis
|
|
720
|
+
|
|
721
|
+
// Find the matching closing parenthesis
|
|
722
|
+
var parenCount = 0;
|
|
723
|
+
var endIndex = -1;
|
|
724
|
+
for (var i = parenIndex; i < code.length; i += 1) {
|
|
725
|
+
if (code[i] === '(') {
|
|
726
|
+
parenCount += 1;
|
|
727
|
+
} else if (code[i] === ')') {
|
|
728
|
+
parenCount -= 1;
|
|
729
|
+
if (parenCount === 0) {
|
|
730
|
+
endIndex = i;
|
|
731
|
+
break;
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
if (endIndex === -1) {
|
|
736
|
+
match = createFactoryRegex.exec(code);
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
var fullMatch = code.substring(startIndex, endIndex + 1);
|
|
740
|
+
var content = code.substring(parenIndex + 1, endIndex);
|
|
741
|
+
|
|
742
|
+
// Split by commas at the top level, handling nested structures and comments
|
|
743
|
+
var structured = parseFunctionArguments(content);
|
|
744
|
+
|
|
745
|
+
// Validate the function follows the convention
|
|
746
|
+
var _parseOptions$metadat = parseOptions.metadataOnly,
|
|
747
|
+
metadataOnly = _parseOptions$metadat === void 0 ? false : _parseOptions$metadat;
|
|
748
|
+
if (metadataOnly) {
|
|
749
|
+
// For metadata-only mode: expect 1-2 arguments (url, options?)
|
|
750
|
+
if (structured.length < 1 || structured.length > 2) {
|
|
751
|
+
throw new Error("Invalid ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 1-2 arguments (url, options?) but got ".concat(structured.length, " arguments. ") + "In metadata-only mode, functions should follow: create*(url, options?)");
|
|
752
|
+
}
|
|
753
|
+
} else if (structured.length < 2 || structured.length > 3) {
|
|
754
|
+
// Normal mode: expect 2-3 arguments (url, variants, options?)
|
|
755
|
+
throw new Error("Invalid ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 2-3 arguments (url, variants, options?) but got ".concat(structured.length, " arguments. ") + "Functions starting with 'create' must follow the convention: create*(url, variants, options?)");
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
// Handle different argument patterns based on mode
|
|
759
|
+
if (metadataOnly) {
|
|
760
|
+
// Metadata-only mode: expect 1-2 arguments (url, options?)
|
|
761
|
+
if (structured.length === 1) {
|
|
762
|
+
var _structured = _slicedToArray(structured, 1),
|
|
763
|
+
urlArg = _structured[0];
|
|
764
|
+
results.push({
|
|
765
|
+
functionName: functionName,
|
|
766
|
+
fullMatch: fullMatch,
|
|
767
|
+
urlArg: typeof urlArg === 'string' ? urlArg.trim() : String(urlArg),
|
|
768
|
+
structuredVariants: undefined,
|
|
769
|
+
// No variants in metadata-only mode
|
|
770
|
+
optionsStructured: undefined,
|
|
771
|
+
hasOptions: false,
|
|
772
|
+
functionStartIndex: startIndex,
|
|
773
|
+
functionEndIndex: endIndex,
|
|
774
|
+
argumentsStartIndex: parenIndex + 1,
|
|
775
|
+
argumentsEndIndex: endIndex
|
|
776
|
+
});
|
|
777
|
+
} else if (structured.length === 2) {
|
|
778
|
+
var _structured2 = _slicedToArray(structured, 2),
|
|
779
|
+
_urlArg = _structured2[0],
|
|
780
|
+
optionsStructured = _structured2[1];
|
|
781
|
+
|
|
782
|
+
// Options should be an object
|
|
783
|
+
if (typeof optionsStructured === 'string' || !Array.isArray(optionsStructured) && _typeof(optionsStructured) !== 'object') {
|
|
784
|
+
throw new Error("Invalid options argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object but got: ".concat(typeof optionsStructured === 'string' ? optionsStructured : JSON.stringify(optionsStructured)));
|
|
785
|
+
}
|
|
786
|
+
results.push({
|
|
787
|
+
functionName: functionName,
|
|
788
|
+
fullMatch: fullMatch,
|
|
789
|
+
urlArg: typeof _urlArg === 'string' ? _urlArg.trim() : String(_urlArg),
|
|
790
|
+
structuredVariants: undefined,
|
|
791
|
+
// No variants in metadata-only mode
|
|
792
|
+
optionsStructured: _typeof(optionsStructured) === 'object' && optionsStructured !== null ? optionsStructured : undefined,
|
|
793
|
+
hasOptions: true,
|
|
794
|
+
functionStartIndex: startIndex,
|
|
795
|
+
functionEndIndex: endIndex,
|
|
796
|
+
argumentsStartIndex: parenIndex + 1,
|
|
797
|
+
argumentsEndIndex: endIndex
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// Normal mode: expect 2-3 arguments (url, variants, options?)
|
|
803
|
+
if (!metadataOnly) {
|
|
804
|
+
if (structured.length === 2) {
|
|
805
|
+
var _structured3 = _slicedToArray(structured, 2),
|
|
806
|
+
_urlArg2 = _structured3[0],
|
|
807
|
+
variantsStructured = _structured3[1];
|
|
808
|
+
results.push({
|
|
809
|
+
functionName: functionName,
|
|
810
|
+
fullMatch: fullMatch,
|
|
811
|
+
urlArg: typeof _urlArg2 === 'string' ? _urlArg2.trim() : String(_urlArg2),
|
|
812
|
+
structuredVariants: variantsStructured,
|
|
813
|
+
optionsStructured: undefined,
|
|
814
|
+
hasOptions: false,
|
|
815
|
+
// No options argument was provided
|
|
816
|
+
functionStartIndex: startIndex,
|
|
817
|
+
functionEndIndex: endIndex,
|
|
818
|
+
argumentsStartIndex: parenIndex + 1,
|
|
819
|
+
argumentsEndIndex: endIndex
|
|
820
|
+
});
|
|
821
|
+
} else if (structured.length === 3) {
|
|
822
|
+
var _structured4 = _slicedToArray(structured, 3),
|
|
823
|
+
_urlArg3 = _structured4[0],
|
|
824
|
+
_variantsStructured = _structured4[1],
|
|
825
|
+
_optionsStructured = _structured4[2];
|
|
826
|
+
|
|
827
|
+
// Options should be an object (Record<string, any>) or an empty object
|
|
828
|
+
if (typeof _optionsStructured === 'string' || !Array.isArray(_optionsStructured) && _typeof(_optionsStructured) !== 'object') {
|
|
829
|
+
throw new Error("Invalid options argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object but got: ".concat(typeof _optionsStructured === 'string' ? _optionsStructured : JSON.stringify(_optionsStructured)));
|
|
830
|
+
}
|
|
831
|
+
results.push({
|
|
832
|
+
functionName: functionName,
|
|
833
|
+
fullMatch: fullMatch,
|
|
834
|
+
urlArg: typeof _urlArg3 === 'string' ? _urlArg3.trim() : String(_urlArg3),
|
|
835
|
+
structuredVariants: _variantsStructured,
|
|
836
|
+
optionsStructured: _typeof(_optionsStructured) === 'object' && _optionsStructured !== null ? _optionsStructured : undefined,
|
|
837
|
+
hasOptions: true,
|
|
838
|
+
// Options argument was provided
|
|
839
|
+
functionStartIndex: startIndex,
|
|
840
|
+
functionEndIndex: endIndex,
|
|
841
|
+
argumentsStartIndex: parenIndex + 1,
|
|
842
|
+
argumentsEndIndex: endIndex
|
|
843
|
+
});
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
match = createFactoryRegex.exec(code);
|
|
847
|
+
}
|
|
848
|
+
return results;
|
|
849
|
+
}
|