@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
- package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
- package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
- package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
- package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
- package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
- package/esm/CodeHighlighter/errors.js +248 -400
- package/esm/CodeHighlighter/parseControlledCode.js +12 -20
- package/esm/CodeProvider/CodeContext.js +3 -3
- package/esm/CodeProvider/CodeProvider.js +31 -40
- package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
- package/esm/cli/index.js +1 -1
- package/esm/cli/runValidate.js +160 -264
- package/esm/createDemoData/createDemoData.js +11 -12
- package/esm/createSitemap/createSitemap.js +2 -2
- package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
- package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
- package/esm/pipeline/hastUtils/hastUtils.js +16 -17
- package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
- package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
- package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
- package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
- package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
- package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
- package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
- package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
- package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
- package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
- package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
- package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
- package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
- package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
- package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
- package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
- package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
- package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
- package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
- package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
- package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
- package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
- package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
- package/esm/pipeline/parseSource/addLineGutters.js +33 -45
- package/esm/pipeline/parseSource/grammars.js +3 -3
- package/esm/pipeline/parseSource/parseSource.js +13 -31
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
- package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
- package/esm/useCode/Pre.js +58 -62
- package/esm/useCode/useCode.js +59 -61
- package/esm/useCode/useCodeUtils.js +54 -63
- package/esm/useCode/useCopyFunctionality.js +10 -9
- package/esm/useCode/useFileNavigation.js +150 -212
- package/esm/useCode/useSourceEditing.js +17 -14
- package/esm/useCode/useTransformManagement.js +23 -26
- package/esm/useCode/useUIState.js +12 -20
- package/esm/useCode/useVariantSelection.js +62 -79
- package/esm/useCopier/index.js +29 -56
- package/esm/useDemo/createCodeSandbox.js +12 -15
- package/esm/useDemo/createStackBlitz.js +14 -20
- package/esm/useDemo/exportVariant.js +200 -180
- package/esm/useDemo/exportVariantAsCra.js +22 -25
- package/esm/useDemo/useDemo.js +80 -84
- package/esm/useErrors/ErrorsContext.js +1 -1
- package/esm/useErrors/useErrors.js +3 -3
- package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
- package/esm/usePreference/PreferencesProvider.js +1 -1
- package/esm/usePreference/usePreference.js +9 -11
- package/esm/useSearch/useSearch.js +290 -387
- package/esm/useUrlHashState/useUrlHashState.js +11 -14
- package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
- package/esm/withDocsInfra/withDocsInfra.js +99 -101
- package/package.json +7 -4
|
@@ -1,762 +1,547 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
3
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
5
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
6
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
7
1
|
import { loadCodeVariant } from "./loadCodeVariant.js";
|
|
8
2
|
import { getFileNameFromUrl, getLanguageFromExtension } from "../loaderUtils/index.js";
|
|
9
3
|
import { performanceMeasure } from "../loadPrecomputedCodeHighlighter/performanceLogger.js";
|
|
10
4
|
|
|
11
5
|
// Helper function to get the source for a specific filename from a variant
|
|
12
|
-
function getFileSource(
|
|
13
|
-
|
|
6
|
+
async function getFileSource(variant, requestedFilename, loadSource) {
|
|
7
|
+
const filename = requestedFilename || variant.fileName;
|
|
8
|
+
if (!filename) {
|
|
9
|
+
// If no filename is available, return the main variant source
|
|
10
|
+
if (variant.source !== undefined) {
|
|
11
|
+
return {
|
|
12
|
+
source: variant.source,
|
|
13
|
+
filename: undefined
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
throw new Error('No filename available and no source in variant');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// If requesting the main file and we have its source
|
|
20
|
+
if (filename === variant.fileName && variant.source !== undefined) {
|
|
21
|
+
return {
|
|
22
|
+
source: variant.source,
|
|
23
|
+
filename
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// If requesting an extra file and we have its source
|
|
28
|
+
if (filename !== variant.fileName && variant.extraFiles) {
|
|
29
|
+
const extraFile = variant.extraFiles[filename];
|
|
30
|
+
if (extraFile && typeof extraFile !== 'string' && extraFile.source !== undefined) {
|
|
31
|
+
return {
|
|
32
|
+
source: extraFile.source,
|
|
33
|
+
filename
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// If we have the URL but not the source, we need to load it
|
|
38
|
+
if (typeof extraFile === 'string' && loadSource) {
|
|
39
|
+
const loadResult = await loadSource(extraFile);
|
|
40
|
+
return {
|
|
41
|
+
source: loadResult.source,
|
|
42
|
+
filename
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (extraFile && typeof extraFile !== 'string' && !extraFile.source && loadSource) {
|
|
46
|
+
// This case shouldn't normally happen, but handle it anyway
|
|
47
|
+
throw new Error(`Extra file ${filename} has no source or URL to load from`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
throw new Error(`File ${filename} not found in variant or cannot be loaded`);
|
|
14
51
|
}
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
52
|
+
export async function loadCodeFallback(url, initialVariant, loaded, options = {}) {
|
|
53
|
+
const {
|
|
54
|
+
shouldHighlight,
|
|
55
|
+
fallbackUsesExtraFiles,
|
|
56
|
+
fallbackUsesAllVariants,
|
|
57
|
+
sourceParser,
|
|
58
|
+
loadSource,
|
|
59
|
+
loadVariantMeta,
|
|
60
|
+
loadCodeMeta,
|
|
61
|
+
initialFilename,
|
|
62
|
+
variants,
|
|
63
|
+
globalsCode,
|
|
64
|
+
output
|
|
65
|
+
} = options;
|
|
66
|
+
loaded = {
|
|
67
|
+
...loaded
|
|
68
|
+
};
|
|
69
|
+
const functionName = 'Load Fallback Code';
|
|
70
|
+
let currentMark = performanceMeasure(undefined, {
|
|
71
|
+
mark: 'Start',
|
|
72
|
+
measure: 'Start'
|
|
73
|
+
}, [functionName, url], true);
|
|
74
|
+
|
|
75
|
+
// Step 1: Ensure we have the initial variant loaded
|
|
76
|
+
let initial = loaded[initialVariant];
|
|
77
|
+
if (!initial) {
|
|
78
|
+
if (!loadCodeMeta) {
|
|
79
|
+
throw new Error('"loadCodeMeta" function is required when initial variant is not provided');
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
loaded = await loadCodeMeta(url);
|
|
83
|
+
} catch (error) {
|
|
84
|
+
throw new Error(`Failed to load code from URL: ${url}. Error: ${JSON.stringify(error)}`);
|
|
85
|
+
}
|
|
86
|
+
initial = loaded[initialVariant];
|
|
87
|
+
if (!initial) {
|
|
88
|
+
throw new Error(`Initial variant "${initialVariant}" not found in loaded code.`);
|
|
89
|
+
}
|
|
90
|
+
currentMark = performanceMeasure(currentMark, {
|
|
91
|
+
mark: 'Loaded Code Meta',
|
|
92
|
+
measure: 'Code Meta Loading'
|
|
93
|
+
}, [functionName, url]);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Check if we can return early after loadCodeMeta
|
|
97
|
+
if (typeof initial !== 'string' && initial.allFilesListed && !fallbackUsesExtraFiles && !fallbackUsesAllVariants) {
|
|
98
|
+
// Collect all file names from the loaded code
|
|
99
|
+
const allFileNames = new Set();
|
|
100
|
+
if (initial.fileName) {
|
|
101
|
+
allFileNames.add(initial.fileName);
|
|
102
|
+
}
|
|
103
|
+
if (initial.extraFiles) {
|
|
104
|
+
Object.keys(initial.extraFiles).forEach(fileName => allFileNames.add(fileName));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Get the source for the requested filename (or main file if not specified)
|
|
108
|
+
let fileSource;
|
|
109
|
+
let actualFilename;
|
|
110
|
+
try {
|
|
111
|
+
const result = await getFileSource(initial, initialFilename, loadSource);
|
|
112
|
+
fileSource = result.source;
|
|
113
|
+
actualFilename = result.filename;
|
|
114
|
+
} catch (error) {
|
|
115
|
+
throw new Error(`Failed to get source for file ${initialFilename || initial.fileName} in variant ${initialVariant}: ${error}`);
|
|
116
|
+
}
|
|
117
|
+
currentMark = performanceMeasure(currentMark, {
|
|
118
|
+
mark: 'Loaded Main File',
|
|
119
|
+
measure: 'Main File Loading'
|
|
120
|
+
}, [functionName, url]);
|
|
121
|
+
|
|
122
|
+
// If we need highlighting and have a string source, parse it
|
|
123
|
+
if (shouldHighlight && typeof fileSource === 'string' && sourceParser && actualFilename) {
|
|
124
|
+
try {
|
|
125
|
+
const parseSource = await sourceParser;
|
|
126
|
+
fileSource = parseSource(fileSource, actualFilename);
|
|
127
|
+
} catch (error) {
|
|
128
|
+
throw new Error(`Failed to parse source for highlighting (variant: ${initialVariant}, file: ${actualFilename}): ${JSON.stringify(error)}`);
|
|
82
129
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
loadVariantMeta,
|
|
99
|
-
loadCodeMeta,
|
|
100
|
-
initialFilename,
|
|
101
|
-
variants,
|
|
102
|
-
globalsCode,
|
|
103
|
-
output,
|
|
104
|
-
functionName,
|
|
105
|
-
currentMark,
|
|
106
|
-
initial,
|
|
107
|
-
_allFileNames,
|
|
108
|
-
fileSource,
|
|
109
|
-
actualFilename,
|
|
110
|
-
result,
|
|
111
|
-
parseSource,
|
|
112
|
-
quickVariant,
|
|
113
|
-
derivedFileName,
|
|
114
|
-
extension,
|
|
115
|
-
beforeInitialVariantMark,
|
|
116
|
-
_allFileNames2,
|
|
117
|
-
_fileSource,
|
|
118
|
-
_actualFilename,
|
|
119
|
-
_result,
|
|
120
|
-
_parseSource,
|
|
121
|
-
beforeGlobalsMark,
|
|
122
|
-
globalsCodeObjects,
|
|
123
|
-
hasStringUrls,
|
|
124
|
-
globalsPromises,
|
|
125
|
-
resolvedGlobalsCode,
|
|
126
|
-
_iterator,
|
|
127
|
-
_step,
|
|
128
|
-
codeObj,
|
|
129
|
-
targetVariant,
|
|
130
|
-
_yield$loadCodeVarian,
|
|
131
|
-
loadedVariant,
|
|
132
|
-
allFileNames,
|
|
133
|
-
beforeAllVariantMark,
|
|
134
|
-
allVariants,
|
|
135
|
-
variantPromises,
|
|
136
|
-
variantResults,
|
|
137
|
-
finalInitial,
|
|
138
|
-
finalFileSource,
|
|
139
|
-
finalFilename,
|
|
140
|
-
_result2,
|
|
141
|
-
_args4 = arguments,
|
|
142
|
-
_t4,
|
|
143
|
-
_t5,
|
|
144
|
-
_t6,
|
|
145
|
-
_t7,
|
|
146
|
-
_t8,
|
|
147
|
-
_t9,
|
|
148
|
-
_t0,
|
|
149
|
-
_t1;
|
|
150
|
-
return _regenerator().w(function (_context4) {
|
|
151
|
-
while (1) switch (_context4.p = _context4.n) {
|
|
152
|
-
case 0:
|
|
153
|
-
options = _args4.length > 3 && _args4[3] !== undefined ? _args4[3] : {};
|
|
154
|
-
shouldHighlight = options.shouldHighlight, fallbackUsesExtraFiles = options.fallbackUsesExtraFiles, fallbackUsesAllVariants = options.fallbackUsesAllVariants, sourceParser = options.sourceParser, loadSource = options.loadSource, loadVariantMeta = options.loadVariantMeta, loadCodeMeta = options.loadCodeMeta, initialFilename = options.initialFilename, variants = options.variants, globalsCode = options.globalsCode, output = options.output;
|
|
155
|
-
loaded = _extends({}, loaded);
|
|
156
|
-
functionName = 'Load Fallback Code';
|
|
157
|
-
currentMark = performanceMeasure(undefined, {
|
|
158
|
-
mark: 'Start',
|
|
159
|
-
measure: 'Start'
|
|
160
|
-
}, [functionName, url], true); // Step 1: Ensure we have the initial variant loaded
|
|
161
|
-
initial = loaded[initialVariant];
|
|
162
|
-
if (initial) {
|
|
163
|
-
_context4.n = 6;
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
if (loadCodeMeta) {
|
|
167
|
-
_context4.n = 1;
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
throw new Error('"loadCodeMeta" function is required when initial variant is not provided');
|
|
171
|
-
case 1:
|
|
172
|
-
_context4.p = 1;
|
|
173
|
-
_context4.n = 2;
|
|
174
|
-
return loadCodeMeta(url);
|
|
175
|
-
case 2:
|
|
176
|
-
loaded = _context4.v;
|
|
177
|
-
_context4.n = 4;
|
|
178
|
-
break;
|
|
179
|
-
case 3:
|
|
180
|
-
_context4.p = 3;
|
|
181
|
-
_t4 = _context4.v;
|
|
182
|
-
throw new Error("Failed to load code from URL: ".concat(url, ". Error: ").concat(JSON.stringify(_t4)));
|
|
183
|
-
case 4:
|
|
184
|
-
initial = loaded[initialVariant];
|
|
185
|
-
if (initial) {
|
|
186
|
-
_context4.n = 5;
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
throw new Error("Initial variant \"".concat(initialVariant, "\" not found in loaded code."));
|
|
190
|
-
case 5:
|
|
191
|
-
currentMark = performanceMeasure(currentMark, {
|
|
192
|
-
mark: 'Loaded Code Meta',
|
|
193
|
-
measure: 'Code Meta Loading'
|
|
194
|
-
}, [functionName, url]);
|
|
195
|
-
case 6:
|
|
196
|
-
if (!(typeof initial !== 'string' && initial.allFilesListed && !fallbackUsesExtraFiles && !fallbackUsesAllVariants)) {
|
|
197
|
-
_context4.n = 17;
|
|
198
|
-
break;
|
|
199
|
-
}
|
|
200
|
-
// Collect all file names from the loaded code
|
|
201
|
-
_allFileNames = new Set();
|
|
202
|
-
if (initial.fileName) {
|
|
203
|
-
_allFileNames.add(initial.fileName);
|
|
204
|
-
}
|
|
205
|
-
if (initial.extraFiles) {
|
|
206
|
-
Object.keys(initial.extraFiles).forEach(function (fileName) {
|
|
207
|
-
return _allFileNames.add(fileName);
|
|
208
|
-
});
|
|
209
|
-
}
|
|
130
|
+
currentMark = performanceMeasure(currentMark, {
|
|
131
|
+
mark: 'Parsed Main File',
|
|
132
|
+
measure: 'Main File Parsing'
|
|
133
|
+
}, [functionName, url]);
|
|
134
|
+
} else if (shouldHighlight && typeof fileSource === 'string' && !actualFilename) {
|
|
135
|
+
// Create basic HAST node when we can't parse due to missing filename
|
|
136
|
+
// This marks that the source has passed through the parsing pipeline
|
|
137
|
+
fileSource = {
|
|
138
|
+
type: 'root',
|
|
139
|
+
children: [{
|
|
140
|
+
type: 'text',
|
|
141
|
+
value: fileSource
|
|
142
|
+
}]
|
|
143
|
+
};
|
|
144
|
+
}
|
|
210
145
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
146
|
+
// Update the loaded code with any changes we made
|
|
147
|
+
if (actualFilename && actualFilename === initial.fileName) {
|
|
148
|
+
initial = {
|
|
149
|
+
...initial,
|
|
150
|
+
source: fileSource
|
|
151
|
+
};
|
|
152
|
+
loaded = {
|
|
153
|
+
...loaded,
|
|
154
|
+
[initialVariant]: initial
|
|
155
|
+
};
|
|
156
|
+
} else if (!actualFilename && !initial.fileName) {
|
|
157
|
+
// If both are undefined, we're dealing with the main source
|
|
158
|
+
initial = {
|
|
159
|
+
...initial,
|
|
160
|
+
source: fileSource
|
|
161
|
+
};
|
|
162
|
+
loaded = {
|
|
163
|
+
...loaded,
|
|
164
|
+
[initialVariant]: initial
|
|
165
|
+
};
|
|
166
|
+
}
|
|
230
167
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
parseSource = _context4.v;
|
|
241
|
-
fileSource = parseSource(fileSource, actualFilename);
|
|
242
|
-
_context4.n = 14;
|
|
243
|
-
break;
|
|
244
|
-
case 13:
|
|
245
|
-
_context4.p = 13;
|
|
246
|
-
_t6 = _context4.v;
|
|
247
|
-
throw new Error("Failed to parse source for highlighting (variant: ".concat(initialVariant, ", file: ").concat(actualFilename, "): ").concat(JSON.stringify(_t6)));
|
|
248
|
-
case 14:
|
|
249
|
-
currentMark = performanceMeasure(currentMark, {
|
|
250
|
-
mark: 'Parsed Main File',
|
|
251
|
-
measure: 'Main File Parsing'
|
|
252
|
-
}, [functionName, url]);
|
|
253
|
-
_context4.n = 16;
|
|
254
|
-
break;
|
|
255
|
-
case 15:
|
|
256
|
-
if (shouldHighlight && typeof fileSource === 'string' && !actualFilename) {
|
|
257
|
-
// Create basic HAST node when we can't parse due to missing filename
|
|
258
|
-
// This marks that the source has passed through the parsing pipeline
|
|
259
|
-
fileSource = {
|
|
260
|
-
type: 'root',
|
|
261
|
-
children: [{
|
|
262
|
-
type: 'text',
|
|
263
|
-
value: fileSource
|
|
264
|
-
}]
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
case 16:
|
|
268
|
-
// Update the loaded code with any changes we made
|
|
269
|
-
if (actualFilename && actualFilename === initial.fileName) {
|
|
270
|
-
initial = _extends(_extends({}, initial), {}, {
|
|
271
|
-
source: fileSource
|
|
272
|
-
});
|
|
273
|
-
loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, initial));
|
|
274
|
-
} else if (!actualFilename && !initial.fileName) {
|
|
275
|
-
// If both are undefined, we're dealing with the main source
|
|
276
|
-
initial = _extends(_extends({}, initial), {}, {
|
|
277
|
-
source: fileSource
|
|
278
|
-
});
|
|
279
|
-
loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, initial));
|
|
280
|
-
}
|
|
168
|
+
// Early return - we have all the info we need
|
|
169
|
+
return {
|
|
170
|
+
code: loaded,
|
|
171
|
+
initialFilename: actualFilename,
|
|
172
|
+
initialSource: fileSource,
|
|
173
|
+
initialExtraFiles: initial.extraFiles || {},
|
|
174
|
+
allFileNames: Array.from(allFileNames)
|
|
175
|
+
};
|
|
176
|
+
}
|
|
281
177
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
break;
|
|
310
|
-
case 20:
|
|
311
|
-
// Create a basic variant using fallback logic
|
|
312
|
-
derivedFileName = getFileNameFromUrl(initial).fileName;
|
|
313
|
-
extension = derivedFileName.slice(derivedFileName.lastIndexOf('.'));
|
|
314
|
-
quickVariant = {
|
|
315
|
-
url: initial,
|
|
316
|
-
fileName: derivedFileName,
|
|
317
|
-
language: getLanguageFromExtension(extension)
|
|
318
|
-
};
|
|
319
|
-
case 21:
|
|
320
|
-
beforeInitialVariantMark = currentMark;
|
|
321
|
-
loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, quickVariant));
|
|
322
|
-
initial = quickVariant;
|
|
178
|
+
// Step 2: Try to get variant metadata quickly first
|
|
179
|
+
if (typeof initial === 'string') {
|
|
180
|
+
try {
|
|
181
|
+
let quickVariant;
|
|
182
|
+
if (loadVariantMeta) {
|
|
183
|
+
// Use provided loadVariantMeta function
|
|
184
|
+
quickVariant = await loadVariantMeta(initialVariant, initial);
|
|
185
|
+
currentMark = performanceMeasure(currentMark, {
|
|
186
|
+
mark: 'Loaded Initial Variant Meta',
|
|
187
|
+
measure: 'Initial Variant Meta Loading'
|
|
188
|
+
}, [functionName, url]);
|
|
189
|
+
} else {
|
|
190
|
+
// Create a basic variant using fallback logic
|
|
191
|
+
const derivedFileName = getFileNameFromUrl(initial).fileName;
|
|
192
|
+
const extension = derivedFileName.slice(derivedFileName.lastIndexOf('.'));
|
|
193
|
+
quickVariant = {
|
|
194
|
+
url: initial,
|
|
195
|
+
fileName: derivedFileName,
|
|
196
|
+
language: getLanguageFromExtension(extension)
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
const beforeInitialVariantMark = currentMark;
|
|
200
|
+
loaded = {
|
|
201
|
+
...loaded,
|
|
202
|
+
[initialVariant]: quickVariant
|
|
203
|
+
};
|
|
204
|
+
initial = quickVariant;
|
|
323
205
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
if (quickVariant.extraFiles) {
|
|
335
|
-
Object.keys(quickVariant.extraFiles).forEach(function (fileName) {
|
|
336
|
-
return _allFileNames2.add(fileName);
|
|
337
|
-
});
|
|
338
|
-
}
|
|
206
|
+
// If we have all files listed and don't need extra file processing, we can optimize
|
|
207
|
+
if (quickVariant.allFilesListed && !fallbackUsesExtraFiles && !fallbackUsesAllVariants) {
|
|
208
|
+
// Collect all file names from the quick load
|
|
209
|
+
const allFileNames = new Set();
|
|
210
|
+
if (quickVariant.fileName) {
|
|
211
|
+
allFileNames.add(quickVariant.fileName);
|
|
212
|
+
}
|
|
213
|
+
if (quickVariant.extraFiles) {
|
|
214
|
+
Object.keys(quickVariant.extraFiles).forEach(fileName => allFileNames.add(fileName));
|
|
215
|
+
}
|
|
339
216
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
_actualFilename = _result.filename;
|
|
217
|
+
// Get the source for the requested filename (or main file if not specified)
|
|
218
|
+
let fileSource;
|
|
219
|
+
let actualFilename;
|
|
220
|
+
try {
|
|
221
|
+
const result = await getFileSource(quickVariant, initialFilename, loadSource);
|
|
222
|
+
fileSource = result.source;
|
|
223
|
+
actualFilename = result.filename;
|
|
348
224
|
currentMark = performanceMeasure(currentMark, {
|
|
349
225
|
mark: 'Loaded Initial File',
|
|
350
226
|
measure: 'Initial File Loading'
|
|
351
227
|
}, [functionName, initialFilename || 'unknown', url]);
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
228
|
+
} catch (error) {
|
|
229
|
+
throw new Error(`Failed to get source for file ${initialFilename || quickVariant.fileName} in variant ${initialVariant}: ${error}`);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// If we need highlighting and have a string source, parse it
|
|
233
|
+
if (shouldHighlight && typeof fileSource === 'string' && sourceParser && actualFilename) {
|
|
234
|
+
try {
|
|
235
|
+
const parseSource = await sourceParser;
|
|
236
|
+
fileSource = parseSource(fileSource, actualFilename);
|
|
237
|
+
currentMark = performanceMeasure(currentMark, {
|
|
238
|
+
mark: 'Parsed Initial File',
|
|
239
|
+
measure: 'Initial File Parsing'
|
|
240
|
+
}, [functionName, initialFilename || 'unknown', url]);
|
|
241
|
+
} catch (error) {
|
|
242
|
+
throw new Error(`Failed to parse source for highlighting (variant: ${initialVariant}, file: ${actualFilename}): ${JSON.stringify(error)}`);
|
|
243
|
+
}
|
|
244
|
+
} else if (shouldHighlight && typeof fileSource === 'string' && !actualFilename) {
|
|
245
|
+
// Create basic HAST node when we can't parse due to missing filename
|
|
246
|
+
// This marks that the source has passed through the parsing pipeline
|
|
247
|
+
fileSource = {
|
|
248
|
+
type: 'root',
|
|
249
|
+
children: [{
|
|
250
|
+
type: 'text',
|
|
251
|
+
value: fileSource
|
|
252
|
+
}]
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Update the loaded code with any changes we made
|
|
257
|
+
if (actualFilename && actualFilename === quickVariant.fileName) {
|
|
258
|
+
initial = {
|
|
259
|
+
...quickVariant,
|
|
260
|
+
source: fileSource
|
|
261
|
+
};
|
|
262
|
+
loaded = {
|
|
263
|
+
...loaded,
|
|
264
|
+
[initialVariant]: initial
|
|
265
|
+
};
|
|
266
|
+
} else if (!actualFilename && !quickVariant.fileName) {
|
|
267
|
+
// If both are undefined, we're dealing with the main source
|
|
268
|
+
initial = {
|
|
269
|
+
...quickVariant,
|
|
270
|
+
source: fileSource
|
|
271
|
+
};
|
|
272
|
+
loaded = {
|
|
273
|
+
...loaded,
|
|
274
|
+
[initialVariant]: initial
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
currentMark = performanceMeasure(beforeInitialVariantMark, {
|
|
278
|
+
mark: 'Loaded Initial Files',
|
|
279
|
+
measure: 'Initial Files Loading'
|
|
280
|
+
}, [functionName, url], true);
|
|
281
|
+
|
|
282
|
+
// Early return - we have all the info we need
|
|
283
|
+
return {
|
|
284
|
+
code: loaded,
|
|
285
|
+
initialFilename: actualFilename,
|
|
286
|
+
initialSource: fileSource,
|
|
287
|
+
initialExtraFiles: quickVariant.extraFiles || {},
|
|
288
|
+
allFileNames: Array.from(allFileNames)
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
} catch (error) {
|
|
292
|
+
throw new Error(`Failed to load initial variant code (variant: ${initialVariant}, url: ${initial}): ${JSON.stringify(error)}`);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
const beforeGlobalsMark = currentMark;
|
|
296
|
+
|
|
297
|
+
// Step 2b: Fall back to full loadCodeVariant processing
|
|
298
|
+
// Load globalsCode - convert string URLs to Code objects, keep Code objects as-is
|
|
299
|
+
let globalsCodeObjects;
|
|
300
|
+
if (globalsCode && globalsCode.length > 0) {
|
|
301
|
+
const hasStringUrls = globalsCode.some(item => typeof item === 'string');
|
|
302
|
+
if (hasStringUrls && !loadCodeMeta) {
|
|
303
|
+
throw new Error('loadCodeMeta function is required when globalsCode contains string URLs');
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// Load all string URLs in parallel, keep Code objects as-is
|
|
307
|
+
const globalsPromises = globalsCode.map(async globalItem => {
|
|
308
|
+
if (typeof globalItem === 'string') {
|
|
309
|
+
// String URL - load Code object via loadCodeMeta
|
|
310
|
+
try {
|
|
311
|
+
const codeMeta = await loadCodeMeta(globalItem);
|
|
369
312
|
currentMark = performanceMeasure(currentMark, {
|
|
370
|
-
mark: '
|
|
371
|
-
measure: '
|
|
372
|
-
}, [functionName,
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
children: [{
|
|
389
|
-
type: 'text',
|
|
390
|
-
value: _fileSource
|
|
391
|
-
}]
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
case 31:
|
|
395
|
-
// Update the loaded code with any changes we made
|
|
396
|
-
if (_actualFilename && _actualFilename === quickVariant.fileName) {
|
|
397
|
-
initial = _extends(_extends({}, quickVariant), {}, {
|
|
398
|
-
source: _fileSource
|
|
399
|
-
});
|
|
400
|
-
loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, initial));
|
|
401
|
-
} else if (!_actualFilename && !quickVariant.fileName) {
|
|
402
|
-
// If both are undefined, we're dealing with the main source
|
|
403
|
-
initial = _extends(_extends({}, quickVariant), {}, {
|
|
404
|
-
source: _fileSource
|
|
405
|
-
});
|
|
406
|
-
loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, initialVariant, initial));
|
|
407
|
-
}
|
|
408
|
-
currentMark = performanceMeasure(beforeInitialVariantMark, {
|
|
409
|
-
mark: 'Loaded Initial Files',
|
|
410
|
-
measure: 'Initial Files Loading'
|
|
411
|
-
}, [functionName, url], true);
|
|
313
|
+
mark: 'Loaded Global Code Meta',
|
|
314
|
+
measure: 'Global Code Meta Loading'
|
|
315
|
+
}, [functionName, globalItem, url]);
|
|
316
|
+
return codeMeta;
|
|
317
|
+
} catch (error) {
|
|
318
|
+
throw new Error(`Failed to load globalsCode from URL: ${globalItem}. Error: ${JSON.stringify(error)}`);
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
// Code object - return as-is
|
|
322
|
+
return globalItem;
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
globalsCodeObjects = await Promise.all(globalsPromises);
|
|
326
|
+
currentMark = performanceMeasure(beforeGlobalsMark, {
|
|
327
|
+
mark: 'Loaded Globals Meta',
|
|
328
|
+
measure: 'Globals Meta Loading'
|
|
329
|
+
}, [functionName, url], true);
|
|
330
|
+
}
|
|
412
331
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
332
|
+
// Convert globalsCodeObjects to VariantCode | string for this specific variant
|
|
333
|
+
let resolvedGlobalsCode;
|
|
334
|
+
if (globalsCodeObjects && globalsCodeObjects.length > 0) {
|
|
335
|
+
resolvedGlobalsCode = [];
|
|
336
|
+
for (const codeObj of globalsCodeObjects) {
|
|
337
|
+
// Only use the variant that matches the current initialVariant
|
|
338
|
+
const targetVariant = codeObj[initialVariant];
|
|
339
|
+
if (targetVariant) {
|
|
340
|
+
resolvedGlobalsCode.push(targetVariant);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
try {
|
|
345
|
+
const {
|
|
346
|
+
code: loadedVariant
|
|
347
|
+
} = await loadCodeVariant(url, initialVariant, initial, {
|
|
348
|
+
sourceParser,
|
|
349
|
+
loadSource,
|
|
350
|
+
loadVariantMeta,
|
|
351
|
+
sourceTransformers: undefined,
|
|
352
|
+
// sourceTransformers - skip transforms for fallback
|
|
353
|
+
disableTransforms: true,
|
|
354
|
+
// Don't apply transforms for fallback
|
|
355
|
+
disableParsing: !shouldHighlight,
|
|
356
|
+
// Only parse if highlighting is needed
|
|
357
|
+
globalsCode: resolvedGlobalsCode,
|
|
358
|
+
// Pass resolved globalsCode
|
|
359
|
+
output
|
|
360
|
+
});
|
|
361
|
+
currentMark = performanceMeasure(currentMark, {
|
|
362
|
+
mark: 'Loaded Initial Variant',
|
|
363
|
+
measure: 'Initial Variant Loading'
|
|
364
|
+
}, [functionName, url], true);
|
|
365
|
+
|
|
366
|
+
// Update the loaded code with the processed variant
|
|
367
|
+
loaded = {
|
|
368
|
+
...loaded,
|
|
369
|
+
[initialVariant]: loadedVariant
|
|
370
|
+
};
|
|
371
|
+
initial = loadedVariant;
|
|
372
|
+
} catch (error) {
|
|
373
|
+
throw new Error(`Failed to load initial variant using loadCodeVariant (variant: ${initialVariant}, url: ${url}): ${JSON.stringify(error)}`);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Step 3: Collect all file names
|
|
377
|
+
const allFileNames = new Set();
|
|
378
|
+
if (initial.fileName) {
|
|
379
|
+
allFileNames.add(initial.fileName);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// Add extra files from the initial variant
|
|
383
|
+
if (initial.extraFiles) {
|
|
384
|
+
Object.keys(initial.extraFiles).forEach(fileName => allFileNames.add(fileName));
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// Step 4: Handle fallbackUsesAllVariants - load all variants to get all possible files
|
|
388
|
+
if (fallbackUsesAllVariants) {
|
|
389
|
+
const beforeAllVariantMark = currentMark;
|
|
390
|
+
|
|
391
|
+
// Determine all variants to process - use provided variants or infer from loaded code
|
|
392
|
+
const allVariants = variants || Object.keys(loaded || {});
|
|
393
|
+
if (allVariants.length === 0) {
|
|
394
|
+
console.warn('No variants found for fallbackUsesAllVariants processing');
|
|
395
|
+
} else {
|
|
396
|
+
// Process all required variants, not just the ones already loaded
|
|
397
|
+
const variantPromises = allVariants.map(async variantName => {
|
|
398
|
+
if (variantName === initialVariant) {
|
|
399
|
+
// Skip initial variant as it's already processed
|
|
400
|
+
return {
|
|
401
|
+
variantName,
|
|
402
|
+
loadedVariant: null,
|
|
403
|
+
fileNames: []
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
let variant = loaded?.[variantName];
|
|
407
|
+
|
|
408
|
+
// If variant is not loaded yet, load it first using loadCodeMeta
|
|
409
|
+
if (!variant && loadCodeMeta) {
|
|
410
|
+
try {
|
|
411
|
+
const allCode = await loadCodeMeta(url);
|
|
412
|
+
variant = allCode[variantName];
|
|
413
|
+
// Update loaded with all variants from loadCodeMeta
|
|
414
|
+
loaded = {
|
|
415
|
+
...loaded,
|
|
416
|
+
...allCode
|
|
417
|
+
};
|
|
418
|
+
currentMark = performanceMeasure(currentMark, {
|
|
419
|
+
mark: 'Loaded Initial Code Meta',
|
|
420
|
+
measure: 'Initial Code Meta Loading'
|
|
421
|
+
}, [functionName, url]);
|
|
422
|
+
} catch (error) {
|
|
423
|
+
console.warn(`Failed to load code meta for variant ${variantName}: ${error}`);
|
|
424
|
+
return {
|
|
425
|
+
variantName,
|
|
426
|
+
loadedVariant: null,
|
|
427
|
+
fileNames: []
|
|
478
428
|
};
|
|
479
|
-
}());
|
|
480
|
-
_context4.n = 36;
|
|
481
|
-
return Promise.all(globalsPromises);
|
|
482
|
-
case 36:
|
|
483
|
-
globalsCodeObjects = _context4.v;
|
|
484
|
-
currentMark = performanceMeasure(beforeGlobalsMark, {
|
|
485
|
-
mark: 'Loaded Globals Meta',
|
|
486
|
-
measure: 'Globals Meta Loading'
|
|
487
|
-
}, [functionName, url], true);
|
|
488
|
-
case 37:
|
|
489
|
-
if (globalsCodeObjects && globalsCodeObjects.length > 0) {
|
|
490
|
-
resolvedGlobalsCode = [];
|
|
491
|
-
_iterator = _createForOfIteratorHelper(globalsCodeObjects);
|
|
492
|
-
try {
|
|
493
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
494
|
-
codeObj = _step.value;
|
|
495
|
-
// Only use the variant that matches the current initialVariant
|
|
496
|
-
targetVariant = codeObj[initialVariant];
|
|
497
|
-
if (targetVariant) {
|
|
498
|
-
resolvedGlobalsCode.push(targetVariant);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
} catch (err) {
|
|
502
|
-
_iterator.e(err);
|
|
503
|
-
} finally {
|
|
504
|
-
_iterator.f();
|
|
505
|
-
}
|
|
506
429
|
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
430
|
+
}
|
|
431
|
+
if (!variant) {
|
|
432
|
+
console.warn(`Variant ${variantName} not found after loading code meta`);
|
|
433
|
+
return {
|
|
434
|
+
variantName,
|
|
435
|
+
loadedVariant: null,
|
|
436
|
+
fileNames: []
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
try {
|
|
440
|
+
const {
|
|
441
|
+
code: loadedVariant
|
|
442
|
+
} = await loadCodeVariant(url, variantName, variant, {
|
|
443
|
+
sourceParser,
|
|
444
|
+
loadSource,
|
|
445
|
+
loadVariantMeta,
|
|
513
446
|
sourceTransformers: undefined,
|
|
514
|
-
// sourceTransformers
|
|
447
|
+
// sourceTransformers
|
|
515
448
|
disableTransforms: true,
|
|
516
|
-
// Don't apply transforms for fallback
|
|
517
449
|
disableParsing: !shouldHighlight,
|
|
518
|
-
|
|
519
|
-
globalsCode:
|
|
520
|
-
|
|
521
|
-
|
|
450
|
+
output,
|
|
451
|
+
globalsCode: globalsCodeObjects && globalsCodeObjects.length > 0 ? (() => {
|
|
452
|
+
// Convert globalsCodeObjects to VariantCode | string for this specific variant
|
|
453
|
+
const variantGlobalsCode = [];
|
|
454
|
+
for (const codeObj of globalsCodeObjects) {
|
|
455
|
+
// Only use the variant that matches the current variantName
|
|
456
|
+
const targetVariant = codeObj[variantName];
|
|
457
|
+
if (targetVariant) {
|
|
458
|
+
variantGlobalsCode.push(targetVariant);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
return variantGlobalsCode;
|
|
462
|
+
})() : undefined
|
|
522
463
|
});
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
464
|
+
|
|
465
|
+
// Collect file names from this variant
|
|
466
|
+
const fileNames = loadedVariant.fileName ? [loadedVariant.fileName] : [];
|
|
467
|
+
if (loadedVariant.extraFiles) {
|
|
468
|
+
fileNames.push(...Object.keys(loadedVariant.extraFiles));
|
|
469
|
+
}
|
|
526
470
|
currentMark = performanceMeasure(currentMark, {
|
|
527
471
|
mark: 'Loaded Initial Variant',
|
|
528
472
|
measure: 'Initial Variant Loading'
|
|
529
|
-
}, [functionName, url], true);
|
|
473
|
+
}, [functionName, variantName, url], true);
|
|
474
|
+
return {
|
|
475
|
+
variantName,
|
|
476
|
+
loadedVariant,
|
|
477
|
+
fileNames
|
|
478
|
+
};
|
|
479
|
+
} catch (error) {
|
|
480
|
+
// Log but don't fail - we want to get as many file names as possible
|
|
481
|
+
console.warn(`Failed to load variant ${variantName} for file listing: ${error}`);
|
|
482
|
+
return {
|
|
483
|
+
variantName,
|
|
484
|
+
loadedVariant: null,
|
|
485
|
+
fileNames: []
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
const variantResults = await Promise.all(variantPromises);
|
|
530
490
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
491
|
+
// Update loaded code and collect file names
|
|
492
|
+
variantResults.forEach(({
|
|
493
|
+
variantName,
|
|
494
|
+
loadedVariant,
|
|
495
|
+
fileNames
|
|
496
|
+
}) => {
|
|
497
|
+
if (loadedVariant) {
|
|
498
|
+
loaded = {
|
|
499
|
+
...loaded,
|
|
500
|
+
[variantName]: loadedVariant
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
fileNames.forEach(fileName => allFileNames.add(fileName));
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
currentMark = performanceMeasure(beforeAllVariantMark, {
|
|
507
|
+
mark: 'Loaded Initial Variants',
|
|
508
|
+
measure: 'Initial Variants Loading'
|
|
509
|
+
}, [functionName, url], true);
|
|
510
|
+
}
|
|
546
511
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
}
|
|
512
|
+
// Ensure we have the latest initial variant data
|
|
513
|
+
const finalInitial = loaded[initialVariant];
|
|
514
|
+
if (!finalInitial || typeof finalInitial === 'string') {
|
|
515
|
+
throw new Error(`Failed to process initial variant: ${initialVariant}`);
|
|
516
|
+
}
|
|
553
517
|
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
loadedVariant: null,
|
|
584
|
-
fileNames: []
|
|
585
|
-
});
|
|
586
|
-
case 1:
|
|
587
|
-
variant = (_loaded = loaded) == null ? void 0 : _loaded[variantName]; // If variant is not loaded yet, load it first using loadCodeMeta
|
|
588
|
-
if (!(!variant && loadCodeMeta)) {
|
|
589
|
-
_context3.n = 5;
|
|
590
|
-
break;
|
|
591
|
-
}
|
|
592
|
-
_context3.p = 2;
|
|
593
|
-
_context3.n = 3;
|
|
594
|
-
return loadCodeMeta(url);
|
|
595
|
-
case 3:
|
|
596
|
-
allCode = _context3.v;
|
|
597
|
-
variant = allCode[variantName];
|
|
598
|
-
// Update loaded with all variants from loadCodeMeta
|
|
599
|
-
loaded = _extends(_extends({}, loaded), allCode);
|
|
600
|
-
currentMark = performanceMeasure(currentMark, {
|
|
601
|
-
mark: 'Loaded Initial Code Meta',
|
|
602
|
-
measure: 'Initial Code Meta Loading'
|
|
603
|
-
}, [functionName, url]);
|
|
604
|
-
_context3.n = 5;
|
|
605
|
-
break;
|
|
606
|
-
case 4:
|
|
607
|
-
_context3.p = 4;
|
|
608
|
-
_t2 = _context3.v;
|
|
609
|
-
console.warn("Failed to load code meta for variant ".concat(variantName, ": ").concat(_t2));
|
|
610
|
-
return _context3.a(2, {
|
|
611
|
-
variantName: variantName,
|
|
612
|
-
loadedVariant: null,
|
|
613
|
-
fileNames: []
|
|
614
|
-
});
|
|
615
|
-
case 5:
|
|
616
|
-
if (variant) {
|
|
617
|
-
_context3.n = 6;
|
|
618
|
-
break;
|
|
619
|
-
}
|
|
620
|
-
console.warn("Variant ".concat(variantName, " not found after loading code meta"));
|
|
621
|
-
return _context3.a(2, {
|
|
622
|
-
variantName: variantName,
|
|
623
|
-
loadedVariant: null,
|
|
624
|
-
fileNames: []
|
|
625
|
-
});
|
|
626
|
-
case 6:
|
|
627
|
-
_context3.p = 6;
|
|
628
|
-
_context3.n = 7;
|
|
629
|
-
return loadCodeVariant(url, variantName, variant, {
|
|
630
|
-
sourceParser: sourceParser,
|
|
631
|
-
loadSource: loadSource,
|
|
632
|
-
loadVariantMeta: loadVariantMeta,
|
|
633
|
-
sourceTransformers: undefined,
|
|
634
|
-
// sourceTransformers
|
|
635
|
-
disableTransforms: true,
|
|
636
|
-
disableParsing: !shouldHighlight,
|
|
637
|
-
output: output,
|
|
638
|
-
globalsCode: globalsCodeObjects && globalsCodeObjects.length > 0 ? function () {
|
|
639
|
-
// Convert globalsCodeObjects to VariantCode | string for this specific variant
|
|
640
|
-
var variantGlobalsCode = [];
|
|
641
|
-
var _iterator2 = _createForOfIteratorHelper(globalsCodeObjects),
|
|
642
|
-
_step2;
|
|
643
|
-
try {
|
|
644
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
645
|
-
var _codeObj = _step2.value;
|
|
646
|
-
// Only use the variant that matches the current variantName
|
|
647
|
-
var _targetVariant = _codeObj[variantName];
|
|
648
|
-
if (_targetVariant) {
|
|
649
|
-
variantGlobalsCode.push(_targetVariant);
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
} catch (err) {
|
|
653
|
-
_iterator2.e(err);
|
|
654
|
-
} finally {
|
|
655
|
-
_iterator2.f();
|
|
656
|
-
}
|
|
657
|
-
return variantGlobalsCode;
|
|
658
|
-
}() : undefined
|
|
659
|
-
});
|
|
660
|
-
case 7:
|
|
661
|
-
_yield$loadCodeVarian2 = _context3.v;
|
|
662
|
-
_loadedVariant = _yield$loadCodeVarian2.code;
|
|
663
|
-
// Collect file names from this variant
|
|
664
|
-
fileNames = _loadedVariant.fileName ? [_loadedVariant.fileName] : [];
|
|
665
|
-
if (_loadedVariant.extraFiles) {
|
|
666
|
-
fileNames.push.apply(fileNames, _toConsumableArray(Object.keys(_loadedVariant.extraFiles)));
|
|
667
|
-
}
|
|
668
|
-
currentMark = performanceMeasure(currentMark, {
|
|
669
|
-
mark: 'Loaded Initial Variant',
|
|
670
|
-
measure: 'Initial Variant Loading'
|
|
671
|
-
}, [functionName, variantName, url], true);
|
|
672
|
-
return _context3.a(2, {
|
|
673
|
-
variantName: variantName,
|
|
674
|
-
loadedVariant: _loadedVariant,
|
|
675
|
-
fileNames: fileNames
|
|
676
|
-
});
|
|
677
|
-
case 8:
|
|
678
|
-
_context3.p = 8;
|
|
679
|
-
_t3 = _context3.v;
|
|
680
|
-
// Log but don't fail - we want to get as many file names as possible
|
|
681
|
-
console.warn("Failed to load variant ".concat(variantName, " for file listing: ").concat(_t3));
|
|
682
|
-
return _context3.a(2, {
|
|
683
|
-
variantName: variantName,
|
|
684
|
-
loadedVariant: null,
|
|
685
|
-
fileNames: []
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
}, _callee3, null, [[6, 8], [2, 4]]);
|
|
689
|
-
}));
|
|
690
|
-
return function (_x8) {
|
|
691
|
-
return _ref2.apply(this, arguments);
|
|
692
|
-
};
|
|
693
|
-
}());
|
|
694
|
-
_context4.n = 43;
|
|
695
|
-
return Promise.all(variantPromises);
|
|
696
|
-
case 43:
|
|
697
|
-
variantResults = _context4.v;
|
|
698
|
-
// Update loaded code and collect file names
|
|
699
|
-
variantResults.forEach(function (_ref3) {
|
|
700
|
-
var variantName = _ref3.variantName,
|
|
701
|
-
loadedVariant = _ref3.loadedVariant,
|
|
702
|
-
fileNames = _ref3.fileNames;
|
|
703
|
-
if (loadedVariant) {
|
|
704
|
-
loaded = _extends(_extends({}, loaded), {}, _defineProperty({}, variantName, loadedVariant));
|
|
705
|
-
}
|
|
706
|
-
fileNames.forEach(function (fileName) {
|
|
707
|
-
return allFileNames.add(fileName);
|
|
708
|
-
});
|
|
709
|
-
});
|
|
710
|
-
case 44:
|
|
711
|
-
currentMark = performanceMeasure(beforeAllVariantMark, {
|
|
712
|
-
mark: 'Loaded Initial Variants',
|
|
713
|
-
measure: 'Initial Variants Loading'
|
|
714
|
-
}, [functionName, url], true);
|
|
715
|
-
case 45:
|
|
716
|
-
// Ensure we have the latest initial variant data
|
|
717
|
-
finalInitial = loaded[initialVariant];
|
|
718
|
-
if (!(!finalInitial || typeof finalInitial === 'string')) {
|
|
719
|
-
_context4.n = 46;
|
|
720
|
-
break;
|
|
721
|
-
}
|
|
722
|
-
throw new Error("Failed to process initial variant: ".concat(initialVariant));
|
|
723
|
-
case 46:
|
|
724
|
-
_context4.p = 46;
|
|
725
|
-
_context4.n = 47;
|
|
726
|
-
return getFileSource(finalInitial, initialFilename, loadSource);
|
|
727
|
-
case 47:
|
|
728
|
-
_result2 = _context4.v;
|
|
729
|
-
finalFileSource = _result2.source;
|
|
730
|
-
finalFilename = _result2.filename;
|
|
731
|
-
_context4.n = 50;
|
|
732
|
-
break;
|
|
733
|
-
case 48:
|
|
734
|
-
_context4.p = 48;
|
|
735
|
-
_t1 = _context4.v;
|
|
736
|
-
if (!(!finalInitial.fileName && !finalInitial.source)) {
|
|
737
|
-
_context4.n = 49;
|
|
738
|
-
break;
|
|
739
|
-
}
|
|
740
|
-
throw new Error("Cannot determine filename for initial variant \"".concat(initialVariant, "\". ") + "No fileName available in variant definition, no initialFilename provided, and no source available.");
|
|
741
|
-
case 49:
|
|
742
|
-
// Fall back to the main file with proper validation
|
|
743
|
-
finalFileSource = finalInitial.source || '';
|
|
744
|
-
finalFilename = finalInitial.fileName;
|
|
745
|
-
case 50:
|
|
746
|
-
currentMark = performanceMeasure(currentMark, {
|
|
747
|
-
mark: 'Loaded Initial File',
|
|
748
|
-
measure: 'Initial File Loading'
|
|
749
|
-
}, [functionName, url]);
|
|
750
|
-
return _context4.a(2, {
|
|
751
|
-
code: loaded,
|
|
752
|
-
initialFilename: finalFilename,
|
|
753
|
-
initialSource: finalFileSource,
|
|
754
|
-
initialExtraFiles: finalInitial.extraFiles || {},
|
|
755
|
-
allFileNames: Array.from(allFileNames),
|
|
756
|
-
processedGlobalsCode: globalsCodeObjects
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
}, _callee4, null, [[46, 48], [38, 40], [26, 28], [22, 24], [18, 33], [11, 13], [7, 9], [1, 3]]);
|
|
760
|
-
}));
|
|
761
|
-
return _loadCodeFallback.apply(this, arguments);
|
|
518
|
+
// Get the source for the requested filename (or main file if not specified) for the final return
|
|
519
|
+
let finalFileSource;
|
|
520
|
+
let finalFilename;
|
|
521
|
+
try {
|
|
522
|
+
const result = await getFileSource(finalInitial, initialFilename, loadSource);
|
|
523
|
+
finalFileSource = result.source;
|
|
524
|
+
finalFilename = result.filename;
|
|
525
|
+
} catch (error) {
|
|
526
|
+
// If we can't get the specific file, fall back to main file
|
|
527
|
+
if (!finalInitial.fileName && !finalInitial.source) {
|
|
528
|
+
throw new Error(`Cannot determine filename for initial variant "${initialVariant}". ` + `No fileName available in variant definition, no initialFilename provided, and no source available.`);
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// Fall back to the main file with proper validation
|
|
532
|
+
finalFileSource = finalInitial.source || '';
|
|
533
|
+
finalFilename = finalInitial.fileName;
|
|
534
|
+
}
|
|
535
|
+
currentMark = performanceMeasure(currentMark, {
|
|
536
|
+
mark: 'Loaded Initial File',
|
|
537
|
+
measure: 'Initial File Loading'
|
|
538
|
+
}, [functionName, url]);
|
|
539
|
+
return {
|
|
540
|
+
code: loaded,
|
|
541
|
+
initialFilename: finalFilename,
|
|
542
|
+
initialSource: finalFileSource,
|
|
543
|
+
initialExtraFiles: finalInitial.extraFiles || {},
|
|
544
|
+
allFileNames: Array.from(allFileNames),
|
|
545
|
+
processedGlobalsCode: globalsCodeObjects
|
|
546
|
+
};
|
|
762
547
|
}
|