@mui/internal-docs-infra 0.3.1-canary.3 → 0.3.1-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/CodeControllerContext/CodeControllerContext.js +2 -2
- package/esm/CodeExternalsContext/CodeExternalsContext.js +1 -1
- package/esm/CodeHighlighter/CodeHighlighter.js +247 -329
- package/esm/CodeHighlighter/CodeHighlighterClient.js +447 -653
- package/esm/CodeHighlighter/CodeHighlighterContext.js +2 -2
- package/esm/CodeHighlighter/CodeHighlighterFallbackContext.js +2 -2
- package/esm/CodeHighlighter/codeToFallbackProps.js +21 -37
- package/esm/CodeHighlighter/errors.js +248 -400
- package/esm/CodeHighlighter/parseControlledCode.js +12 -20
- package/esm/CodeProvider/CodeContext.js +3 -3
- package/esm/CodeProvider/CodeProvider.js +31 -40
- package/esm/abstractCreateDemo/abstractCreateDemo.js +13 -17
- package/esm/abstractCreateDemoClient/abstractCreateDemoClient.js +12 -12
- package/esm/cli/index.js +1 -1
- package/esm/cli/runValidate.js +160 -264
- package/esm/createDemoData/createDemoData.js +11 -12
- package/esm/createSitemap/createSitemap.js +2 -2
- package/esm/pipeline/getFileConventions/fileConventions.js +1 -1
- package/esm/pipeline/getFileConventions/getFileConventions.js +2 -15
- package/esm/pipeline/hastUtils/hastUtils.js +16 -17
- package/esm/pipeline/loadCodeVariant/addCodeVariantPaths.js +24 -24
- package/esm/pipeline/loadCodeVariant/applyCodeTransform.js +12 -22
- package/esm/pipeline/loadCodeVariant/calculateMainFilePath.js +30 -37
- package/esm/pipeline/loadCodeVariant/computeHastDeltas.js +107 -185
- package/esm/pipeline/loadCodeVariant/diffHast.js +18 -53
- package/esm/pipeline/loadCodeVariant/examineCodeVariant.js +24 -27
- package/esm/pipeline/loadCodeVariant/flattenCodeVariant.js +9 -10
- package/esm/pipeline/loadCodeVariant/hasAllCodeVariants.js +5 -5
- package/esm/pipeline/loadCodeVariant/loadCodeFallback.js +516 -731
- package/esm/pipeline/loadCodeVariant/loadCodeVariant.js +679 -1079
- package/esm/pipeline/loadCodeVariant/maybeCodeInitialData.js +14 -20
- package/esm/pipeline/loadCodeVariant/mergeCodeMetadata.js +53 -63
- package/esm/pipeline/loadCodeVariant/parseCode.js +40 -48
- package/esm/pipeline/loadCodeVariant/pathUtils.js +43 -64
- package/esm/pipeline/loadCodeVariant/transformSource.js +55 -125
- package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +160 -221
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +377 -479
- package/esm/pipeline/loadPrecomputedCodeHighlighter/parseFunctionArguments.js +171 -173
- package/esm/pipeline/loadPrecomputedCodeHighlighter/performanceLogger.js +14 -30
- package/esm/pipeline/loadPrecomputedCodeHighlighter/replacePrecomputeValue.js +19 -21
- package/esm/pipeline/loadPrecomputedCodeHighlighter/serializeFunctionArguments.js +37 -71
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/filterRuntimeExternals.js +3 -9
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateImportStatements.js +54 -80
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/generateResolvedExternals.js +71 -98
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/injectImportsIntoSource.js +5 -5
- package/esm/pipeline/loadPrecomputedCodeHighlighterClient/loadPrecomputedCodeHighlighterClient.js +161 -211
- package/esm/pipeline/loadPrecomputedSitemap/loadPrecomputedSitemap.js +159 -207
- package/esm/pipeline/loadServerCodeMeta/loadServerCodeMeta.js +42 -64
- package/esm/pipeline/loadServerCodeMeta/resolveModulePathWithFs.js +20 -96
- package/esm/pipeline/loadServerPageIndex/loadServerPageIndex.js +66 -85
- package/esm/pipeline/loadServerSitemap/loadServerSitemap.js +71 -118
- package/esm/pipeline/loadServerSource/loadServerSource.js +121 -148
- package/esm/pipeline/loaderUtils/externalsToPackages.js +7 -7
- package/esm/pipeline/loaderUtils/extractNameAndSlugFromUrl.js +8 -12
- package/esm/pipeline/loaderUtils/fileUrlToPortablePath.js +5 -5
- package/esm/pipeline/loaderUtils/getFileNameFromUrl.js +19 -29
- package/esm/pipeline/loaderUtils/getLanguageFromExtension.js +3 -4
- package/esm/pipeline/loaderUtils/mergeExternals.js +15 -35
- package/esm/pipeline/loaderUtils/parseImportsAndComments.js +413 -433
- package/esm/pipeline/loaderUtils/processRelativeImports.js +153 -239
- package/esm/pipeline/loaderUtils/resolveModulePath.js +544 -1303
- package/esm/pipeline/loaderUtils/rewriteImports.js +73 -111
- package/esm/pipeline/parseSource/addLineGutters.js +33 -45
- package/esm/pipeline/parseSource/grammars.js +3 -3
- package/esm/pipeline/parseSource/parseSource.js +13 -31
- package/esm/pipeline/syncPageIndex/createMarkdownNodes.js +32 -55
- package/esm/pipeline/syncPageIndex/mergeMetadataMarkdown.js +107 -160
- package/esm/pipeline/syncPageIndex/metadataToMarkdown.js +846 -1033
- package/esm/pipeline/syncPageIndex/syncPageIndex.js +291 -438
- package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +213 -311
- package/esm/pipeline/transformMarkdownBlockquoteCallouts/transformMarkdownBlockquoteCallouts.js +10 -10
- package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +133 -193
- package/esm/pipeline/transformMarkdownDemoLinks/transformMarkdownDemoLinks.js +25 -27
- package/esm/pipeline/transformMarkdownMetadata/transformMarkdownMetadata.js +572 -717
- package/esm/pipeline/transformMarkdownRelativePaths/transformMarkdownRelativePaths.js +8 -8
- package/esm/pipeline/transformTypescriptToJavascript/removeTypes.js +84 -113
- package/esm/pipeline/transformTypescriptToJavascript/transformTypescriptToJavascript.js +10 -26
- package/esm/useCode/Pre.js +58 -62
- package/esm/useCode/useCode.js +59 -61
- package/esm/useCode/useCodeUtils.js +54 -63
- package/esm/useCode/useCopyFunctionality.js +10 -9
- package/esm/useCode/useFileNavigation.js +150 -212
- package/esm/useCode/useSourceEditing.js +17 -14
- package/esm/useCode/useTransformManagement.js +23 -26
- package/esm/useCode/useUIState.js +12 -20
- package/esm/useCode/useVariantSelection.js +62 -79
- package/esm/useCopier/index.js +29 -56
- package/esm/useDemo/createCodeSandbox.js +12 -15
- package/esm/useDemo/createStackBlitz.js +14 -20
- package/esm/useDemo/exportVariant.js +200 -180
- package/esm/useDemo/exportVariantAsCra.js +22 -25
- package/esm/useDemo/useDemo.js +80 -84
- package/esm/useErrors/ErrorsContext.js +1 -1
- package/esm/useErrors/useErrors.js +3 -3
- package/esm/useLocalStorageState/useLocalStorageState.js +23 -39
- package/esm/usePreference/PreferencesProvider.js +1 -1
- package/esm/usePreference/usePreference.js +9 -11
- package/esm/useSearch/useSearch.js +290 -387
- package/esm/useUrlHashState/useUrlHashState.js +11 -14
- package/esm/withDocsInfra/withDeploymentConfig.js +26 -21
- package/esm/withDocsInfra/withDocsInfra.js +99 -101
- package/package.json +7 -4
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import _regenerator from "@babel/runtime/helpers/esm/regenerator";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
-
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
4
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
5
|
-
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
6
1
|
import * as path from 'path-module';
|
|
7
2
|
import { fileUrlToPortablePath, portablePathToFileUrl } from "./fileUrlToPortablePath.js";
|
|
8
3
|
|
|
@@ -47,16 +42,16 @@ function isStringStart(ch, withinMdx) {
|
|
|
47
42
|
* @returns True if the comment starts with any of the specified prefixes
|
|
48
43
|
*/
|
|
49
44
|
function matchesCommentPrefix(commentText, removeCommentsWithPrefix) {
|
|
50
|
-
return removeCommentsWithPrefix.some(
|
|
45
|
+
return removeCommentsWithPrefix.some(prefix => {
|
|
51
46
|
// For single-line comments, check after the //
|
|
52
47
|
if (commentText.startsWith('//')) {
|
|
53
|
-
|
|
48
|
+
const content = commentText.slice(2).trim();
|
|
54
49
|
return content.startsWith(prefix);
|
|
55
50
|
}
|
|
56
51
|
// For multi-line comments, check after the /*
|
|
57
52
|
if (commentText.startsWith('/*')) {
|
|
58
|
-
|
|
59
|
-
return
|
|
53
|
+
const content = commentText.slice(2, -2).trim();
|
|
54
|
+
return content.startsWith(prefix);
|
|
60
55
|
}
|
|
61
56
|
return false;
|
|
62
57
|
});
|
|
@@ -74,12 +69,8 @@ function stripCommentMarkers(commentText) {
|
|
|
74
69
|
}
|
|
75
70
|
// For multi-line comments, remove /* and */, split by lines, and trim each line
|
|
76
71
|
if (commentText.startsWith('/*') && commentText.endsWith('*/')) {
|
|
77
|
-
|
|
78
|
-
return content.split('\n').map(
|
|
79
|
-
return line.trim();
|
|
80
|
-
}).filter(function (line) {
|
|
81
|
-
return line !== '';
|
|
82
|
-
});
|
|
72
|
+
const content = commentText.slice(2, -2);
|
|
73
|
+
return content.split('\n').map(line => line.trim()).filter(line => line !== '');
|
|
83
74
|
}
|
|
84
75
|
// Fallback: return as single-item array if format is unexpected
|
|
85
76
|
return [commentText];
|
|
@@ -92,8 +83,8 @@ function stripCommentMarkers(commentText) {
|
|
|
92
83
|
* @returns The number of consecutive backticks found
|
|
93
84
|
*/
|
|
94
85
|
function countBackticks(sourceText, startPos) {
|
|
95
|
-
|
|
96
|
-
|
|
86
|
+
let count = 0;
|
|
87
|
+
let pos = startPos;
|
|
97
88
|
while (pos < sourceText.length && sourceText[pos] === '`') {
|
|
98
89
|
count += 1;
|
|
99
90
|
pos += 1;
|
|
@@ -114,46 +105,46 @@ function countBackticks(sourceText, startPos) {
|
|
|
114
105
|
* @returns Object containing found import statements and optionally processed code/comments
|
|
115
106
|
*/
|
|
116
107
|
function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWithPrefix, notableCommentsPrefix) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
108
|
+
const statements = [];
|
|
109
|
+
const comments = {};
|
|
110
|
+
const shouldProcessComments = !!(removeCommentsWithPrefix || notableCommentsPrefix);
|
|
111
|
+
let result = shouldProcessComments ? '' : sourceCode;
|
|
121
112
|
|
|
122
113
|
// Position mapping from original source to processed source (after comment removal)
|
|
123
|
-
|
|
124
|
-
|
|
114
|
+
const positionMapping = new Map();
|
|
115
|
+
let processedPos = 0;
|
|
125
116
|
|
|
126
117
|
// Helper to check if a comment matches notable prefix
|
|
127
|
-
|
|
118
|
+
const matchesNotablePrefix = commentText => {
|
|
128
119
|
if (!notableCommentsPrefix || notableCommentsPrefix.length === 0) {
|
|
129
120
|
return false; // If no notable prefix specified, don't match any comments as notable
|
|
130
121
|
}
|
|
131
|
-
return notableCommentsPrefix.some(
|
|
122
|
+
return notableCommentsPrefix.some(prefix => {
|
|
132
123
|
if (commentText.startsWith('//')) {
|
|
133
|
-
|
|
124
|
+
const content = commentText.slice(2).trim();
|
|
134
125
|
return content.startsWith(prefix);
|
|
135
126
|
}
|
|
136
127
|
if (commentText.startsWith('/*')) {
|
|
137
|
-
|
|
138
|
-
return
|
|
128
|
+
const content = commentText.slice(2, -2).trim();
|
|
129
|
+
return content.startsWith(prefix);
|
|
139
130
|
}
|
|
140
131
|
return false;
|
|
141
132
|
});
|
|
142
133
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
134
|
+
let i = 0;
|
|
135
|
+
let outputLine = 0; // Line number in output code after comment removal
|
|
136
|
+
const len = sourceCode.length;
|
|
137
|
+
let state = 'code';
|
|
138
|
+
let stringQuote = null;
|
|
139
|
+
let codeblockBacktickCount = 0; // Track how many backticks opened the current code block
|
|
149
140
|
// Comment stripping variables
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
141
|
+
let commentStart = 0;
|
|
142
|
+
let commentStartOutputLine = 0;
|
|
143
|
+
let lineStartPos = 0;
|
|
144
|
+
let preCommentContent = '';
|
|
154
145
|
while (i < len) {
|
|
155
|
-
|
|
156
|
-
|
|
146
|
+
const ch = sourceCode[i];
|
|
147
|
+
const next = sourceCode[i + 1];
|
|
157
148
|
if (state === 'code') {
|
|
158
149
|
// Track line numbers for newlines in code
|
|
159
150
|
if (ch === '\n') {
|
|
@@ -170,7 +161,7 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
170
161
|
// Check for backtick sequences (3 or more backticks start code blocks in MDX)
|
|
171
162
|
if (isMdxFile && ch === '`') {
|
|
172
163
|
// Count consecutive backticks
|
|
173
|
-
|
|
164
|
+
const backtickCount = countBackticks(sourceCode, i);
|
|
174
165
|
if (backtickCount >= 3) {
|
|
175
166
|
state = 'codeblock';
|
|
176
167
|
codeblockBacktickCount = backtickCount;
|
|
@@ -187,7 +178,7 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
187
178
|
commentStart = i;
|
|
188
179
|
commentStartOutputLine = outputLine;
|
|
189
180
|
// Remove content that was already added to result for this line
|
|
190
|
-
|
|
181
|
+
const contentSinceLineStart = sourceCode.slice(lineStartPos, commentStart);
|
|
191
182
|
result = result.slice(0, result.length - contentSinceLineStart.length);
|
|
192
183
|
preCommentContent = contentSinceLineStart;
|
|
193
184
|
}
|
|
@@ -201,9 +192,9 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
201
192
|
commentStart = i;
|
|
202
193
|
commentStartOutputLine = outputLine;
|
|
203
194
|
// Remove content that was already added to result for this line
|
|
204
|
-
|
|
205
|
-
result = result.slice(0, result.length -
|
|
206
|
-
preCommentContent =
|
|
195
|
+
const contentSinceLineStart = sourceCode.slice(lineStartPos, commentStart);
|
|
196
|
+
result = result.slice(0, result.length - contentSinceLineStart.length);
|
|
197
|
+
preCommentContent = contentSinceLineStart;
|
|
207
198
|
}
|
|
208
199
|
state = 'multiline-comment';
|
|
209
200
|
i += 2;
|
|
@@ -226,30 +217,30 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
226
217
|
}
|
|
227
218
|
|
|
228
219
|
// Create position mapper function
|
|
229
|
-
|
|
220
|
+
const positionMapper = originalPos => {
|
|
230
221
|
if (!shouldProcessComments) {
|
|
231
222
|
return originalPos; // No comment processing, positions are unchanged
|
|
232
223
|
}
|
|
233
224
|
// Find the closest mapped position
|
|
234
|
-
|
|
235
|
-
positionMapping.forEach(
|
|
225
|
+
let closest = 0;
|
|
226
|
+
positionMapping.forEach((procPos, origPos) => {
|
|
236
227
|
if (origPos <= originalPos && origPos > closest) {
|
|
237
228
|
closest = origPos;
|
|
238
229
|
}
|
|
239
230
|
});
|
|
240
|
-
|
|
231
|
+
const offset = originalPos - closest;
|
|
241
232
|
return (positionMapping.get(closest) || 0) + offset;
|
|
242
233
|
};
|
|
243
234
|
|
|
244
235
|
// Use the provided import detector on the original source code
|
|
245
|
-
|
|
236
|
+
const detection = importDetector(sourceCode, i, positionMapper);
|
|
246
237
|
if (detection.found) {
|
|
247
238
|
if (detection.statement) {
|
|
248
239
|
statements.push(detection.statement);
|
|
249
240
|
}
|
|
250
241
|
// Copy the detected import to result if we're building one
|
|
251
242
|
if (shouldProcessComments) {
|
|
252
|
-
|
|
243
|
+
const importText = sourceCode.slice(i, detection.nextPos);
|
|
253
244
|
result += importText;
|
|
254
245
|
processedPos += importText.length;
|
|
255
246
|
}
|
|
@@ -267,22 +258,21 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
267
258
|
if (ch === '\n') {
|
|
268
259
|
if (shouldProcessComments) {
|
|
269
260
|
// End of single-line comment
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
261
|
+
const commentText = sourceCode.slice(commentStart, i);
|
|
262
|
+
const shouldStrip = removeCommentsWithPrefix && matchesCommentPrefix(commentText, removeCommentsWithPrefix);
|
|
263
|
+
const isNotable = matchesNotablePrefix(commentText);
|
|
273
264
|
|
|
274
265
|
// Collect comments if they're notable (all stripped comments when no prefix specified, or notable comments when prefix specified)
|
|
275
|
-
|
|
266
|
+
const shouldCollect = shouldStrip && !notableCommentsPrefix || isNotable;
|
|
276
267
|
if (shouldCollect) {
|
|
277
|
-
var _comments$commentStar;
|
|
278
268
|
if (!comments[commentStartOutputLine]) {
|
|
279
269
|
comments[commentStartOutputLine] = [];
|
|
280
270
|
}
|
|
281
|
-
|
|
271
|
+
comments[commentStartOutputLine].push(...stripCommentMarkers(commentText));
|
|
282
272
|
}
|
|
283
273
|
if (shouldStrip) {
|
|
284
274
|
// Check if comment is the only thing on its line (ignoring whitespace)
|
|
285
|
-
|
|
275
|
+
const isCommentOnlyLine = preCommentContent.trim() === '';
|
|
286
276
|
if (isCommentOnlyLine) {
|
|
287
277
|
// Don't add the pre-comment content or newline for comment-only lines
|
|
288
278
|
// Skip the newline entirely
|
|
@@ -311,29 +301,28 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
311
301
|
if (ch === '*' && next === '/') {
|
|
312
302
|
if (shouldProcessComments) {
|
|
313
303
|
// End of multi-line comment
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
304
|
+
const commentText = sourceCode.slice(commentStart, i + 2);
|
|
305
|
+
const shouldStrip = removeCommentsWithPrefix && matchesCommentPrefix(commentText, removeCommentsWithPrefix);
|
|
306
|
+
const isNotable = matchesNotablePrefix(commentText);
|
|
317
307
|
|
|
318
308
|
// Collect comments if they're notable (all stripped comments when no prefix specified, or notable comments when prefix specified)
|
|
319
|
-
|
|
320
|
-
if (
|
|
321
|
-
var _comments$commentStar2;
|
|
309
|
+
const shouldCollect = shouldStrip && !notableCommentsPrefix || isNotable;
|
|
310
|
+
if (shouldCollect) {
|
|
322
311
|
if (!comments[commentStartOutputLine]) {
|
|
323
312
|
comments[commentStartOutputLine] = [];
|
|
324
313
|
}
|
|
325
|
-
|
|
314
|
+
comments[commentStartOutputLine].push(...stripCommentMarkers(commentText));
|
|
326
315
|
}
|
|
327
|
-
if (
|
|
316
|
+
if (shouldStrip) {
|
|
328
317
|
// Find the end of the comment and check what's after
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
318
|
+
const afterCommentPos = i + 2;
|
|
319
|
+
let afterCommentContent = '';
|
|
320
|
+
let nextNewlinePos = sourceCode.indexOf('\n', afterCommentPos);
|
|
332
321
|
if (nextNewlinePos === -1) {
|
|
333
322
|
nextNewlinePos = sourceCode.length;
|
|
334
323
|
}
|
|
335
324
|
afterCommentContent = sourceCode.slice(afterCommentPos, nextNewlinePos).trim();
|
|
336
|
-
|
|
325
|
+
const isCommentOnlyLines = preCommentContent.trim() === '' && afterCommentContent === '';
|
|
337
326
|
if (isCommentOnlyLines) {
|
|
338
327
|
// Skip the entire comment and everything up to and including the next newline
|
|
339
328
|
i = nextNewlinePos;
|
|
@@ -355,9 +344,9 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
355
344
|
} else {
|
|
356
345
|
// Keep the comment - add pre-comment content and comment
|
|
357
346
|
result += preCommentContent;
|
|
358
|
-
result +=
|
|
347
|
+
result += commentText;
|
|
359
348
|
// Count newlines in the kept comment to update output line
|
|
360
|
-
|
|
349
|
+
const newlineCount = (commentText.match(/\n/g) || []).length;
|
|
361
350
|
outputLine += newlineCount;
|
|
362
351
|
i += 2;
|
|
363
352
|
}
|
|
@@ -427,7 +416,7 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
427
416
|
}
|
|
428
417
|
// Look for closing backticks that match or exceed the opening count
|
|
429
418
|
if (ch === '`') {
|
|
430
|
-
|
|
419
|
+
const closingBacktickCount = countBackticks(sourceCode, i);
|
|
431
420
|
if (closingBacktickCount >= codeblockBacktickCount) {
|
|
432
421
|
state = 'code';
|
|
433
422
|
codeblockBacktickCount = 0;
|
|
@@ -452,46 +441,46 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
452
441
|
|
|
453
442
|
// Handle case where file ends with a comment
|
|
454
443
|
if (shouldProcessComments && (state === 'singleline-comment' || state === 'multiline-comment')) {
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
444
|
+
const commentText = sourceCode.slice(commentStart);
|
|
445
|
+
const shouldStrip = removeCommentsWithPrefix && matchesCommentPrefix(commentText, removeCommentsWithPrefix);
|
|
446
|
+
const isNotable = matchesNotablePrefix(commentText);
|
|
458
447
|
|
|
459
448
|
// Collect comments if they're notable (all stripped comments when no prefix specified, or notable comments when prefix specified)
|
|
460
|
-
|
|
461
|
-
if (
|
|
462
|
-
var _comments$commentStar3;
|
|
449
|
+
const shouldCollect = shouldStrip && !notableCommentsPrefix || isNotable;
|
|
450
|
+
if (shouldCollect) {
|
|
463
451
|
if (!comments[commentStartOutputLine]) {
|
|
464
452
|
comments[commentStartOutputLine] = [];
|
|
465
453
|
}
|
|
466
|
-
|
|
454
|
+
comments[commentStartOutputLine].push(...stripCommentMarkers(commentText));
|
|
467
455
|
}
|
|
468
|
-
if (!
|
|
469
|
-
result +=
|
|
456
|
+
if (!shouldStrip) {
|
|
457
|
+
result += commentText;
|
|
470
458
|
}
|
|
471
459
|
}
|
|
472
460
|
|
|
473
461
|
// Create the final position mapper for return
|
|
474
|
-
|
|
462
|
+
const finalPositionMapper = originalPos => {
|
|
475
463
|
if (!shouldProcessComments) {
|
|
476
464
|
return originalPos; // No comment processing, positions are unchanged
|
|
477
465
|
}
|
|
478
466
|
// Find the closest mapped position
|
|
479
|
-
|
|
480
|
-
positionMapping.forEach(
|
|
467
|
+
let closest = 0;
|
|
468
|
+
positionMapping.forEach((procPos, origPos) => {
|
|
481
469
|
if (origPos <= originalPos && origPos > closest) {
|
|
482
470
|
closest = origPos;
|
|
483
471
|
}
|
|
484
472
|
});
|
|
485
|
-
|
|
473
|
+
const offset = originalPos - closest;
|
|
486
474
|
return (positionMapping.get(closest) || 0) + offset;
|
|
487
475
|
};
|
|
488
|
-
return
|
|
489
|
-
statements
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
476
|
+
return {
|
|
477
|
+
statements,
|
|
478
|
+
...(shouldProcessComments && {
|
|
479
|
+
code: result,
|
|
480
|
+
comments,
|
|
481
|
+
positionMapper: finalPositionMapper
|
|
482
|
+
})
|
|
483
|
+
};
|
|
495
484
|
}
|
|
496
485
|
|
|
497
486
|
/**
|
|
@@ -503,19 +492,18 @@ function scanForImports(sourceCode, importDetector, isMdxFile, removeCommentsWit
|
|
|
503
492
|
* @param isType - Whether this is a TypeScript type-only import
|
|
504
493
|
*/
|
|
505
494
|
function addImportName(target, name, type, alias, isType) {
|
|
506
|
-
|
|
507
|
-
return n.name === name && n.type === type && n.alias === alias;
|
|
508
|
-
});
|
|
495
|
+
const existing = target.find(n => n.name === name && n.type === type && n.alias === alias);
|
|
509
496
|
if (!existing) {
|
|
510
|
-
target.push(
|
|
511
|
-
name
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
type
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
497
|
+
target.push({
|
|
498
|
+
name,
|
|
499
|
+
...(alias && {
|
|
500
|
+
alias
|
|
501
|
+
}),
|
|
502
|
+
type,
|
|
503
|
+
...(isType && {
|
|
504
|
+
isType: true
|
|
505
|
+
})
|
|
506
|
+
});
|
|
519
507
|
}
|
|
520
508
|
}
|
|
521
509
|
|
|
@@ -544,7 +532,7 @@ function isWhitespace(ch) {
|
|
|
544
532
|
* @returns The position of the next non-whitespace character
|
|
545
533
|
*/
|
|
546
534
|
function skipWhitespace(text, start) {
|
|
547
|
-
|
|
535
|
+
let pos = start;
|
|
548
536
|
while (pos < text.length && isWhitespace(text[pos])) {
|
|
549
537
|
pos += 1;
|
|
550
538
|
}
|
|
@@ -558,8 +546,8 @@ function skipWhitespace(text, start) {
|
|
|
558
546
|
* @returns Object containing the identifier name and the next position
|
|
559
547
|
*/
|
|
560
548
|
function readIdentifier(text, start) {
|
|
561
|
-
|
|
562
|
-
|
|
549
|
+
let pos = start;
|
|
550
|
+
let name = '';
|
|
563
551
|
|
|
564
552
|
// First character must be letter, underscore, or dollar sign
|
|
565
553
|
if (pos < text.length && /[a-zA-Z_$]/.test(text[pos])) {
|
|
@@ -573,33 +561,33 @@ function readIdentifier(text, start) {
|
|
|
573
561
|
}
|
|
574
562
|
}
|
|
575
563
|
return {
|
|
576
|
-
name
|
|
564
|
+
name,
|
|
577
565
|
nextPos: pos
|
|
578
566
|
};
|
|
579
567
|
}
|
|
580
568
|
|
|
581
569
|
// Helper function to read a quoted string starting at position
|
|
582
570
|
function readQuotedString(text, start) {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
571
|
+
const quote = text[start];
|
|
572
|
+
let pos = start + 1;
|
|
573
|
+
let value = '';
|
|
574
|
+
const pathStart = start; // Start at the opening quote
|
|
587
575
|
|
|
588
576
|
while (pos < text.length) {
|
|
589
|
-
|
|
577
|
+
const ch = text[pos];
|
|
590
578
|
if (ch === '\\' && pos + 1 < text.length) {
|
|
591
579
|
// Skip escaped character
|
|
592
580
|
pos += 2;
|
|
593
581
|
continue;
|
|
594
582
|
}
|
|
595
583
|
if (ch === quote) {
|
|
596
|
-
|
|
584
|
+
const pathEnd = pos + 1; // End after the closing quote
|
|
597
585
|
pos += 1;
|
|
598
586
|
return {
|
|
599
|
-
value
|
|
587
|
+
value,
|
|
600
588
|
nextPos: pos,
|
|
601
|
-
pathStart
|
|
602
|
-
pathEnd
|
|
589
|
+
pathStart,
|
|
590
|
+
pathEnd
|
|
603
591
|
};
|
|
604
592
|
}
|
|
605
593
|
value += ch;
|
|
@@ -608,17 +596,17 @@ function readQuotedString(text, start) {
|
|
|
608
596
|
|
|
609
597
|
// If we reach here, no closing quote was found - fallback
|
|
610
598
|
return {
|
|
611
|
-
value
|
|
599
|
+
value,
|
|
612
600
|
nextPos: pos,
|
|
613
|
-
pathStart
|
|
601
|
+
pathStart,
|
|
614
602
|
pathEnd: pos
|
|
615
603
|
};
|
|
616
604
|
}
|
|
617
605
|
|
|
618
606
|
// Helper function to parse named imports from a brace-enclosed section
|
|
619
607
|
function parseNamedImports(text, start, end) {
|
|
620
|
-
|
|
621
|
-
|
|
608
|
+
const imports = [];
|
|
609
|
+
let pos = start;
|
|
622
610
|
while (pos < end) {
|
|
623
611
|
pos = skipWhitespace(text, pos);
|
|
624
612
|
if (pos >= end) {
|
|
@@ -653,7 +641,7 @@ function parseNamedImports(text, start, end) {
|
|
|
653
641
|
}
|
|
654
642
|
|
|
655
643
|
// Check for 'type' keyword
|
|
656
|
-
|
|
644
|
+
let isTypeImport = false;
|
|
657
645
|
if (text.slice(pos, pos + 4) === 'type' && !isIdentifierChar(text[pos + 4] || '')) {
|
|
658
646
|
isTypeImport = true;
|
|
659
647
|
pos += 4;
|
|
@@ -661,9 +649,10 @@ function parseNamedImports(text, start, end) {
|
|
|
661
649
|
}
|
|
662
650
|
|
|
663
651
|
// Read the import name
|
|
664
|
-
|
|
665
|
-
name
|
|
666
|
-
nextPos
|
|
652
|
+
const {
|
|
653
|
+
name,
|
|
654
|
+
nextPos
|
|
655
|
+
} = readIdentifier(text, pos);
|
|
667
656
|
if (!name) {
|
|
668
657
|
pos += 1;
|
|
669
658
|
continue;
|
|
@@ -672,22 +661,24 @@ function parseNamedImports(text, start, end) {
|
|
|
672
661
|
pos = skipWhitespace(text, pos);
|
|
673
662
|
|
|
674
663
|
// Check for 'as' keyword (alias)
|
|
675
|
-
|
|
664
|
+
let alias;
|
|
676
665
|
if (text.slice(pos, pos + 2) === 'as' && !isIdentifierChar(text[pos + 2] || '')) {
|
|
677
666
|
pos += 2;
|
|
678
667
|
pos = skipWhitespace(text, pos);
|
|
679
|
-
|
|
668
|
+
const aliasResult = readIdentifier(text, pos);
|
|
680
669
|
alias = aliasResult.name;
|
|
681
670
|
pos = aliasResult.nextPos;
|
|
682
671
|
pos = skipWhitespace(text, pos);
|
|
683
672
|
}
|
|
684
|
-
imports.push(
|
|
685
|
-
name
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
673
|
+
imports.push({
|
|
674
|
+
name,
|
|
675
|
+
...(alias && {
|
|
676
|
+
alias
|
|
677
|
+
}),
|
|
678
|
+
...(isTypeImport && {
|
|
679
|
+
isType: true
|
|
680
|
+
})
|
|
681
|
+
});
|
|
691
682
|
|
|
692
683
|
// Skip comma if present
|
|
693
684
|
if (text[pos] === ',') {
|
|
@@ -699,16 +690,16 @@ function parseNamedImports(text, start, end) {
|
|
|
699
690
|
|
|
700
691
|
// Function to parse a single CSS @import statement
|
|
701
692
|
function parseCssImportStatement(cssCode, start) {
|
|
702
|
-
|
|
703
|
-
|
|
693
|
+
let pos = start + 7; // Skip '@import'
|
|
694
|
+
const len = cssCode.length;
|
|
704
695
|
|
|
705
696
|
// Skip whitespace
|
|
706
697
|
while (pos < len && /\s/.test(cssCode[pos])) {
|
|
707
698
|
pos += 1;
|
|
708
699
|
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
700
|
+
let modulePath = null;
|
|
701
|
+
let pathStart;
|
|
702
|
+
let pathEnd;
|
|
712
703
|
|
|
713
704
|
// Check for url() syntax
|
|
714
705
|
if (cssCode.slice(pos, pos + 4) === 'url(') {
|
|
@@ -720,10 +711,10 @@ function parseCssImportStatement(cssCode, start) {
|
|
|
720
711
|
|
|
721
712
|
// Read the URL (quoted or unquoted)
|
|
722
713
|
if (pos < len && (cssCode[pos] === '"' || cssCode[pos] === "'")) {
|
|
723
|
-
|
|
714
|
+
const quote = cssCode[pos];
|
|
724
715
|
pathStart = pos; // Start at the opening quote
|
|
725
716
|
pos += 1;
|
|
726
|
-
|
|
717
|
+
let url = '';
|
|
727
718
|
while (pos < len && cssCode[pos] !== quote) {
|
|
728
719
|
// Only stop at newlines - parentheses and semicolons are valid in URLs
|
|
729
720
|
if (cssCode[pos] === '\n') {
|
|
@@ -745,13 +736,13 @@ function parseCssImportStatement(cssCode, start) {
|
|
|
745
736
|
} else {
|
|
746
737
|
// Unquoted URL
|
|
747
738
|
pathStart = pos;
|
|
748
|
-
|
|
739
|
+
let url = '';
|
|
749
740
|
while (pos < len && cssCode[pos] !== ')' && !/\s/.test(cssCode[pos])) {
|
|
750
|
-
|
|
741
|
+
url += cssCode[pos];
|
|
751
742
|
pos += 1;
|
|
752
743
|
}
|
|
753
744
|
pathEnd = pos;
|
|
754
|
-
modulePath =
|
|
745
|
+
modulePath = url;
|
|
755
746
|
}
|
|
756
747
|
|
|
757
748
|
// Skip to closing parenthesis - if we don't find it, the url() is malformed
|
|
@@ -769,11 +760,11 @@ function parseCssImportStatement(cssCode, start) {
|
|
|
769
760
|
}
|
|
770
761
|
} else if (pos < len && (cssCode[pos] === '"' || cssCode[pos] === "'")) {
|
|
771
762
|
// Direct quoted import
|
|
772
|
-
|
|
763
|
+
const quote = cssCode[pos];
|
|
773
764
|
pathStart = pos; // Start at the opening quote
|
|
774
765
|
pos += 1;
|
|
775
|
-
|
|
776
|
-
while (pos < len && cssCode[pos] !==
|
|
766
|
+
let url = '';
|
|
767
|
+
while (pos < len && cssCode[pos] !== quote) {
|
|
777
768
|
// Stop if we hit a newline (likely malformed), but semicolons are valid in URLs
|
|
778
769
|
if (cssCode[pos] === '\n') {
|
|
779
770
|
break;
|
|
@@ -782,13 +773,13 @@ function parseCssImportStatement(cssCode, start) {
|
|
|
782
773
|
pos += 2;
|
|
783
774
|
continue;
|
|
784
775
|
}
|
|
785
|
-
|
|
776
|
+
url += cssCode[pos];
|
|
786
777
|
pos += 1;
|
|
787
778
|
}
|
|
788
|
-
if (pos < len && cssCode[pos] ===
|
|
779
|
+
if (pos < len && cssCode[pos] === quote) {
|
|
789
780
|
pathEnd = pos + 1; // End after the closing quote
|
|
790
781
|
pos += 1;
|
|
791
|
-
modulePath =
|
|
782
|
+
modulePath = url;
|
|
792
783
|
}
|
|
793
784
|
// If we didn't find the closing quote, don't set modulePath (malformed import)
|
|
794
785
|
}
|
|
@@ -801,29 +792,29 @@ function parseCssImportStatement(cssCode, start) {
|
|
|
801
792
|
pos += 1;
|
|
802
793
|
}
|
|
803
794
|
return {
|
|
804
|
-
modulePath
|
|
795
|
+
modulePath,
|
|
805
796
|
nextPos: pos,
|
|
806
|
-
pathStart
|
|
807
|
-
pathEnd
|
|
797
|
+
pathStart,
|
|
798
|
+
pathEnd
|
|
808
799
|
};
|
|
809
800
|
}
|
|
810
801
|
|
|
811
802
|
// CSS import detector function
|
|
812
803
|
function detectCssImport(sourceText, pos, cssResult, cssExternals, cssFilePath, positionMapper) {
|
|
813
|
-
|
|
804
|
+
const ch = sourceText[pos];
|
|
814
805
|
|
|
815
806
|
// Look for '@import' keyword
|
|
816
807
|
if (ch === '@' && sourceText.slice(pos, pos + 7) === '@import' && /\s/.test(sourceText[pos + 7] || '')) {
|
|
817
808
|
// Parse the @import statement
|
|
818
|
-
|
|
809
|
+
const importResult = parseCssImportStatement(sourceText, pos);
|
|
819
810
|
if (importResult.modulePath && importResult.pathStart !== undefined && importResult.pathEnd !== undefined) {
|
|
820
811
|
// In CSS, imports are relative unless they have a protocol/hostname
|
|
821
812
|
// Examples of external: "http://...", "https://...", "//example.com/style.css"
|
|
822
813
|
// Examples of relative: "print.css", "./local.css", "../parent.css"
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
814
|
+
const hasProtocol = /^https?:\/\//.test(importResult.modulePath);
|
|
815
|
+
const hasHostname = /^\/\//.test(importResult.modulePath);
|
|
816
|
+
const isExternal = hasProtocol || hasHostname;
|
|
817
|
+
const position = {
|
|
827
818
|
start: positionMapper(importResult.pathStart),
|
|
828
819
|
end: positionMapper(importResult.pathEnd)
|
|
829
820
|
};
|
|
@@ -837,11 +828,11 @@ function detectCssImport(sourceText, pos, cssResult, cssExternals, cssFilePath,
|
|
|
837
828
|
cssExternals[importResult.modulePath].positions.push(position);
|
|
838
829
|
} else {
|
|
839
830
|
// Treat as relative import - normalize the path if it doesn't start with ./ or ../
|
|
840
|
-
|
|
831
|
+
let normalizedPath = importResult.modulePath;
|
|
841
832
|
if (!normalizedPath.startsWith('./') && !normalizedPath.startsWith('../')) {
|
|
842
|
-
normalizedPath =
|
|
833
|
+
normalizedPath = `./${normalizedPath}`;
|
|
843
834
|
}
|
|
844
|
-
|
|
835
|
+
const resolvedPath = path.resolve(path.dirname(cssFilePath), normalizedPath);
|
|
845
836
|
if (!cssResult[importResult.modulePath]) {
|
|
846
837
|
cssResult[importResult.modulePath] = {
|
|
847
838
|
url: portablePathToFileUrl(resolvedPath),
|
|
@@ -875,17 +866,17 @@ function detectCssImport(sourceText, pos, cssResult, cssExternals, cssFilePath,
|
|
|
875
866
|
*/
|
|
876
867
|
function parseCssImports(cssCode, cssFilePath, cssResult, cssExternals, removeCommentsWithPrefix, notableCommentsPrefix) {
|
|
877
868
|
// Use the generic scanner with a bound detector function
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
}, false, removeCommentsWithPrefix, notableCommentsPrefix);
|
|
881
|
-
return _extends(_extends({
|
|
869
|
+
const scanResult = scanForImports(cssCode, (sourceText, pos, positionMapper) => detectCssImport(sourceText, pos, cssResult, cssExternals, cssFilePath, positionMapper), false, removeCommentsWithPrefix, notableCommentsPrefix);
|
|
870
|
+
return {
|
|
882
871
|
relative: cssResult,
|
|
883
|
-
externals: cssExternals
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
872
|
+
externals: cssExternals,
|
|
873
|
+
...(scanResult.code && {
|
|
874
|
+
code: scanResult.code
|
|
875
|
+
}),
|
|
876
|
+
...(scanResult.comments && {
|
|
877
|
+
comments: scanResult.comments
|
|
878
|
+
})
|
|
879
|
+
};
|
|
889
880
|
}
|
|
890
881
|
|
|
891
882
|
/**
|
|
@@ -901,211 +892,62 @@ function parseCssImports(cssCode, cssFilePath, cssResult, cssExternals, removeCo
|
|
|
901
892
|
*/
|
|
902
893
|
function parseJSImports(code, filePath, result, externals, isMdxFile, removeCommentsWithPrefix, notableCommentsPrefix) {
|
|
903
894
|
// Scan code for JavaScript import statements
|
|
904
|
-
|
|
895
|
+
const scanResult = scanForImports(code, detectJavaScriptImport, isMdxFile, removeCommentsWithPrefix, notableCommentsPrefix);
|
|
905
896
|
|
|
906
897
|
// Now, parse each import statement using character-by-character parsing
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
// Skip 'import'
|
|
918
|
-
pos = 6; // We know it starts with 'import'
|
|
919
|
-
pos = skipWhitespace(text, pos);
|
|
920
|
-
|
|
921
|
-
// Check for 'type' keyword
|
|
922
|
-
var isTypeImport = false;
|
|
923
|
-
if (text.slice(pos, pos + 4) === 'type' && !isIdentifierChar(text[pos + 4] || '')) {
|
|
924
|
-
isTypeImport = true;
|
|
925
|
-
pos += 4;
|
|
926
|
-
pos = skipWhitespace(text, pos);
|
|
927
|
-
}
|
|
928
|
-
|
|
929
|
-
// Check if this is a side-effect import (starts with quote)
|
|
930
|
-
if (pos < textLen && (text[pos] === '"' || text[pos] === "'")) {
|
|
931
|
-
var _readQuotedString = readQuotedString(text, pos),
|
|
932
|
-
_modulePath = _readQuotedString.value,
|
|
933
|
-
_pathStart = _readQuotedString.pathStart,
|
|
934
|
-
_pathEnd = _readQuotedString.pathEnd;
|
|
935
|
-
if (_modulePath) {
|
|
936
|
-
// Calculate the position in the original source code
|
|
937
|
-
var _originalPathStart = start + _pathStart;
|
|
938
|
-
var _originalPathEnd = start + _pathEnd;
|
|
939
|
-
|
|
940
|
-
// Apply position mapping if available (for comment-stripped positions)
|
|
941
|
-
var _mappedStart = _originalPathStart;
|
|
942
|
-
var _mappedEnd = _originalPathEnd;
|
|
943
|
-
if (scanResult.positionMapper) {
|
|
944
|
-
_mappedStart = scanResult.positionMapper(_originalPathStart);
|
|
945
|
-
_mappedEnd = scanResult.positionMapper(_originalPathEnd);
|
|
946
|
-
}
|
|
947
|
-
var _position = {
|
|
948
|
-
start: _mappedStart,
|
|
949
|
-
end: _mappedEnd
|
|
950
|
-
};
|
|
951
|
-
var _isRelative = _modulePath.startsWith('./') || _modulePath.startsWith('../');
|
|
952
|
-
if (_isRelative) {
|
|
953
|
-
var resolvedPath = path.resolve(path.dirname(filePath), _modulePath);
|
|
954
|
-
if (!result[_modulePath]) {
|
|
955
|
-
result[_modulePath] = {
|
|
956
|
-
url: portablePathToFileUrl(resolvedPath),
|
|
957
|
-
names: [],
|
|
958
|
-
positions: []
|
|
959
|
-
};
|
|
960
|
-
}
|
|
961
|
-
result[_modulePath].positions.push(_position);
|
|
962
|
-
} else {
|
|
963
|
-
if (!externals[_modulePath]) {
|
|
964
|
-
externals[_modulePath] = {
|
|
965
|
-
names: [],
|
|
966
|
-
positions: []
|
|
967
|
-
};
|
|
968
|
-
}
|
|
969
|
-
externals[_modulePath].positions.push(_position);
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
return 0; // continue
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
// Parse import specifiers
|
|
976
|
-
var defaultImport;
|
|
977
|
-
var namespaceImport;
|
|
978
|
-
var namedImports = [];
|
|
979
|
-
|
|
980
|
-
// Check for default import (identifier not followed by 'from')
|
|
981
|
-
if (pos < textLen && /[a-zA-Z_$]/.test(text[pos])) {
|
|
982
|
-
var _readIdentifier2 = readIdentifier(text, pos),
|
|
983
|
-
name = _readIdentifier2.name,
|
|
984
|
-
nextPos = _readIdentifier2.nextPos;
|
|
985
|
-
var afterName = skipWhitespace(text, nextPos);
|
|
986
|
-
|
|
987
|
-
// If next non-whitespace is comma or 'from', this is a default import
|
|
988
|
-
if (afterName >= textLen || text[afterName] === ',' || text.slice(afterName, afterName + 4) === 'from') {
|
|
989
|
-
defaultImport = name;
|
|
990
|
-
pos = afterName;
|
|
991
|
-
|
|
992
|
-
// Skip comma if present
|
|
993
|
-
if (pos < textLen && text[pos] === ',') {
|
|
994
|
-
pos += 1;
|
|
995
|
-
pos = skipWhitespace(text, pos);
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
// Check for namespace import (* as Name)
|
|
1001
|
-
if (pos < textLen && text[pos] === '*') {
|
|
1002
|
-
pos += 1;
|
|
1003
|
-
pos = skipWhitespace(text, pos);
|
|
1004
|
-
|
|
1005
|
-
// Expect 'as'
|
|
1006
|
-
if (text.slice(pos, pos + 2) === 'as') {
|
|
1007
|
-
pos += 2;
|
|
1008
|
-
pos = skipWhitespace(text, pos);
|
|
1009
|
-
var _readIdentifier3 = readIdentifier(text, pos),
|
|
1010
|
-
_name = _readIdentifier3.name;
|
|
1011
|
-
if (_name) {
|
|
1012
|
-
namespaceImport = _name;
|
|
1013
|
-
pos = readIdentifier(text, pos).nextPos;
|
|
1014
|
-
pos = skipWhitespace(text, pos);
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
|
|
1019
|
-
// Check for named imports ({ ... })
|
|
1020
|
-
if (pos < textLen && text[pos] === '{') {
|
|
1021
|
-
pos += 1;
|
|
1022
|
-
var braceStart = pos;
|
|
1023
|
-
|
|
1024
|
-
// Find the closing brace
|
|
1025
|
-
var braceDepth = 1;
|
|
1026
|
-
while (pos < textLen && braceDepth > 0) {
|
|
1027
|
-
if (text[pos] === '{') {
|
|
1028
|
-
braceDepth += 1;
|
|
1029
|
-
} else if (text[pos] === '}') {
|
|
1030
|
-
braceDepth -= 1;
|
|
1031
|
-
}
|
|
1032
|
-
pos += 1;
|
|
1033
|
-
}
|
|
1034
|
-
if (braceDepth === 0) {
|
|
1035
|
-
var braceEnd = pos - 1;
|
|
1036
|
-
namedImports = parseNamedImports(text, braceStart, braceEnd);
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
// Skip to 'from' keyword
|
|
1041
|
-
pos = skipWhitespace(text, pos);
|
|
1042
|
-
while (pos < textLen && text.slice(pos, pos + 4) !== 'from') {
|
|
1043
|
-
pos += 1;
|
|
1044
|
-
}
|
|
1045
|
-
if (pos >= textLen || text.slice(pos, pos + 4) !== 'from') {
|
|
1046
|
-
return 0; // continue
|
|
1047
|
-
// No 'from' found, skip this import
|
|
1048
|
-
}
|
|
1049
|
-
pos += 4;
|
|
1050
|
-
pos = skipWhitespace(text, pos);
|
|
898
|
+
for (const {
|
|
899
|
+
start,
|
|
900
|
+
text
|
|
901
|
+
} of scanResult.statements) {
|
|
902
|
+
let pos = 0;
|
|
903
|
+
const textLen = text.length;
|
|
904
|
+
|
|
905
|
+
// Skip 'import'
|
|
906
|
+
pos = 6; // We know it starts with 'import'
|
|
907
|
+
pos = skipWhitespace(text, pos);
|
|
1051
908
|
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
pathStart = _readQuotedString2.pathStart,
|
|
1060
|
-
pathEnd = _readQuotedString2.pathEnd;
|
|
1061
|
-
if (!modulePath) {
|
|
1062
|
-
return 0; // continue
|
|
1063
|
-
}
|
|
909
|
+
// Check for 'type' keyword
|
|
910
|
+
let isTypeImport = false;
|
|
911
|
+
if (text.slice(pos, pos + 4) === 'type' && !isIdentifierChar(text[pos + 4] || '')) {
|
|
912
|
+
isTypeImport = true;
|
|
913
|
+
pos += 4;
|
|
914
|
+
pos = skipWhitespace(text, pos);
|
|
915
|
+
}
|
|
1064
916
|
|
|
917
|
+
// Check if this is a side-effect import (starts with quote)
|
|
918
|
+
if (pos < textLen && (text[pos] === '"' || text[pos] === "'")) {
|
|
919
|
+
const {
|
|
920
|
+
value: modulePath,
|
|
921
|
+
pathStart,
|
|
922
|
+
pathEnd
|
|
923
|
+
} = readQuotedString(text, pos);
|
|
924
|
+
if (modulePath) {
|
|
1065
925
|
// Calculate the position in the original source code
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
var isRelative = modulePath.startsWith('./') || modulePath.startsWith('../');
|
|
926
|
+
const originalPathStart = start + pathStart;
|
|
927
|
+
const originalPathEnd = start + pathEnd;
|
|
1069
928
|
|
|
1070
929
|
// Apply position mapping if available (for comment-stripped positions)
|
|
1071
|
-
|
|
1072
|
-
|
|
930
|
+
let mappedStart = originalPathStart;
|
|
931
|
+
let mappedEnd = originalPathEnd;
|
|
1073
932
|
if (scanResult.positionMapper) {
|
|
1074
933
|
mappedStart = scanResult.positionMapper(originalPathStart);
|
|
1075
934
|
mappedEnd = scanResult.positionMapper(originalPathEnd);
|
|
1076
935
|
}
|
|
1077
|
-
|
|
936
|
+
const position = {
|
|
1078
937
|
start: mappedStart,
|
|
1079
938
|
end: mappedEnd
|
|
1080
939
|
};
|
|
940
|
+
const isRelative = modulePath.startsWith('./') || modulePath.startsWith('../');
|
|
1081
941
|
if (isRelative) {
|
|
1082
|
-
|
|
942
|
+
const resolvedPath = path.resolve(path.dirname(filePath), modulePath);
|
|
1083
943
|
if (!result[modulePath]) {
|
|
1084
|
-
result[modulePath] =
|
|
1085
|
-
url: portablePathToFileUrl(
|
|
944
|
+
result[modulePath] = {
|
|
945
|
+
url: portablePathToFileUrl(resolvedPath),
|
|
1086
946
|
names: [],
|
|
1087
947
|
positions: []
|
|
1088
|
-
}
|
|
1089
|
-
includeTypeDefs: true
|
|
1090
|
-
});
|
|
1091
|
-
} else if (isTypeImport && !result[modulePath].includeTypeDefs) {
|
|
1092
|
-
result[modulePath].includeTypeDefs = true;
|
|
948
|
+
};
|
|
1093
949
|
}
|
|
1094
|
-
|
|
1095
|
-
// Add position information
|
|
1096
950
|
result[modulePath].positions.push(position);
|
|
1097
|
-
if (defaultImport) {
|
|
1098
|
-
addImportName(result[modulePath].names, defaultImport, 'default', undefined, isTypeImport);
|
|
1099
|
-
}
|
|
1100
|
-
if (namespaceImport) {
|
|
1101
|
-
addImportName(result[modulePath].names, namespaceImport, 'namespace', undefined, isTypeImport);
|
|
1102
|
-
}
|
|
1103
|
-
namedImports.forEach(function (_ref) {
|
|
1104
|
-
var name = _ref.name,
|
|
1105
|
-
alias = _ref.alias,
|
|
1106
|
-
isType = _ref.isType;
|
|
1107
|
-
addImportName(result[modulePath].names, name, 'named', alias, isTypeImport || isType);
|
|
1108
|
-
});
|
|
1109
951
|
} else {
|
|
1110
952
|
if (!externals[modulePath]) {
|
|
1111
953
|
externals[modulePath] = {
|
|
@@ -1113,41 +955,184 @@ function parseJSImports(code, filePath, result, externals, isMdxFile, removeComm
|
|
|
1113
955
|
positions: []
|
|
1114
956
|
};
|
|
1115
957
|
}
|
|
1116
|
-
|
|
1117
|
-
// Add position information
|
|
1118
958
|
externals[modulePath].positions.push(position);
|
|
1119
|
-
if (defaultImport) {
|
|
1120
|
-
addImportName(externals[modulePath].names, defaultImport, 'default', undefined, isTypeImport);
|
|
1121
|
-
}
|
|
1122
|
-
if (namespaceImport) {
|
|
1123
|
-
addImportName(externals[modulePath].names, namespaceImport, 'namespace', undefined, isTypeImport);
|
|
1124
|
-
}
|
|
1125
|
-
namedImports.forEach(function (_ref2) {
|
|
1126
|
-
var name = _ref2.name,
|
|
1127
|
-
alias = _ref2.alias,
|
|
1128
|
-
isType = _ref2.isType;
|
|
1129
|
-
addImportName(externals[modulePath].names, name, 'named', alias, isTypeImport || isType);
|
|
1130
|
-
});
|
|
1131
959
|
}
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
960
|
+
}
|
|
961
|
+
continue;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
// Parse import specifiers
|
|
965
|
+
let defaultImport;
|
|
966
|
+
let namespaceImport;
|
|
967
|
+
let namedImports = [];
|
|
968
|
+
|
|
969
|
+
// Check for default import (identifier not followed by 'from')
|
|
970
|
+
if (pos < textLen && /[a-zA-Z_$]/.test(text[pos])) {
|
|
971
|
+
const {
|
|
972
|
+
name,
|
|
973
|
+
nextPos
|
|
974
|
+
} = readIdentifier(text, pos);
|
|
975
|
+
const afterName = skipWhitespace(text, nextPos);
|
|
976
|
+
|
|
977
|
+
// If next non-whitespace is comma or 'from', this is a default import
|
|
978
|
+
if (afterName >= textLen || text[afterName] === ',' || text.slice(afterName, afterName + 4) === 'from') {
|
|
979
|
+
defaultImport = name;
|
|
980
|
+
pos = afterName;
|
|
981
|
+
|
|
982
|
+
// Skip comma if present
|
|
983
|
+
if (pos < textLen && text[pos] === ',') {
|
|
984
|
+
pos += 1;
|
|
985
|
+
pos = skipWhitespace(text, pos);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
// Check for namespace import (* as Name)
|
|
991
|
+
if (pos < textLen && text[pos] === '*') {
|
|
992
|
+
pos += 1;
|
|
993
|
+
pos = skipWhitespace(text, pos);
|
|
994
|
+
|
|
995
|
+
// Expect 'as'
|
|
996
|
+
if (text.slice(pos, pos + 2) === 'as') {
|
|
997
|
+
pos += 2;
|
|
998
|
+
pos = skipWhitespace(text, pos);
|
|
999
|
+
const {
|
|
1000
|
+
name
|
|
1001
|
+
} = readIdentifier(text, pos);
|
|
1002
|
+
if (name) {
|
|
1003
|
+
namespaceImport = name;
|
|
1004
|
+
pos = readIdentifier(text, pos).nextPos;
|
|
1005
|
+
pos = skipWhitespace(text, pos);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
// Check for named imports ({ ... })
|
|
1011
|
+
if (pos < textLen && text[pos] === '{') {
|
|
1012
|
+
pos += 1;
|
|
1013
|
+
const braceStart = pos;
|
|
1014
|
+
|
|
1015
|
+
// Find the closing brace
|
|
1016
|
+
let braceDepth = 1;
|
|
1017
|
+
while (pos < textLen && braceDepth > 0) {
|
|
1018
|
+
if (text[pos] === '{') {
|
|
1019
|
+
braceDepth += 1;
|
|
1020
|
+
} else if (text[pos] === '}') {
|
|
1021
|
+
braceDepth -= 1;
|
|
1022
|
+
}
|
|
1023
|
+
pos += 1;
|
|
1024
|
+
}
|
|
1025
|
+
if (braceDepth === 0) {
|
|
1026
|
+
const braceEnd = pos - 1;
|
|
1027
|
+
namedImports = parseNamedImports(text, braceStart, braceEnd);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
// Skip to 'from' keyword
|
|
1032
|
+
pos = skipWhitespace(text, pos);
|
|
1033
|
+
while (pos < textLen && text.slice(pos, pos + 4) !== 'from') {
|
|
1034
|
+
pos += 1;
|
|
1035
|
+
}
|
|
1036
|
+
if (pos >= textLen || text.slice(pos, pos + 4) !== 'from') {
|
|
1037
|
+
continue; // No 'from' found, skip this import
|
|
1038
|
+
}
|
|
1039
|
+
pos += 4;
|
|
1040
|
+
pos = skipWhitespace(text, pos);
|
|
1041
|
+
|
|
1042
|
+
// Read module path
|
|
1043
|
+
if (pos >= textLen || !(text[pos] === '"' || text[pos] === "'")) {
|
|
1044
|
+
continue; // No quoted module path found
|
|
1045
|
+
}
|
|
1046
|
+
const {
|
|
1047
|
+
value: modulePath,
|
|
1048
|
+
pathStart,
|
|
1049
|
+
pathEnd
|
|
1050
|
+
} = readQuotedString(text, pos);
|
|
1051
|
+
if (!modulePath) {
|
|
1052
|
+
continue;
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
// Calculate the position in the original source code
|
|
1056
|
+
const originalPathStart = start + pathStart;
|
|
1057
|
+
const originalPathEnd = start + pathEnd;
|
|
1058
|
+
const isRelative = modulePath.startsWith('./') || modulePath.startsWith('../');
|
|
1059
|
+
|
|
1060
|
+
// Apply position mapping if available (for comment-stripped positions)
|
|
1061
|
+
let mappedStart = originalPathStart;
|
|
1062
|
+
let mappedEnd = originalPathEnd;
|
|
1063
|
+
if (scanResult.positionMapper) {
|
|
1064
|
+
mappedStart = scanResult.positionMapper(originalPathStart);
|
|
1065
|
+
mappedEnd = scanResult.positionMapper(originalPathEnd);
|
|
1066
|
+
}
|
|
1067
|
+
const position = {
|
|
1068
|
+
start: mappedStart,
|
|
1069
|
+
end: mappedEnd
|
|
1070
|
+
};
|
|
1071
|
+
if (isRelative) {
|
|
1072
|
+
const resolvedPath = path.resolve(path.dirname(filePath), modulePath);
|
|
1073
|
+
if (!result[modulePath]) {
|
|
1074
|
+
result[modulePath] = {
|
|
1075
|
+
url: portablePathToFileUrl(resolvedPath),
|
|
1076
|
+
names: [],
|
|
1077
|
+
positions: [],
|
|
1078
|
+
...(isTypeImport && {
|
|
1079
|
+
includeTypeDefs: true
|
|
1080
|
+
})
|
|
1081
|
+
};
|
|
1082
|
+
} else if (isTypeImport && !result[modulePath].includeTypeDefs) {
|
|
1083
|
+
result[modulePath].includeTypeDefs = true;
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
// Add position information
|
|
1087
|
+
result[modulePath].positions.push(position);
|
|
1088
|
+
if (defaultImport) {
|
|
1089
|
+
addImportName(result[modulePath].names, defaultImport, 'default', undefined, isTypeImport);
|
|
1090
|
+
}
|
|
1091
|
+
if (namespaceImport) {
|
|
1092
|
+
addImportName(result[modulePath].names, namespaceImport, 'namespace', undefined, isTypeImport);
|
|
1093
|
+
}
|
|
1094
|
+
namedImports.forEach(({
|
|
1095
|
+
name,
|
|
1096
|
+
alias,
|
|
1097
|
+
isType
|
|
1098
|
+
}) => {
|
|
1099
|
+
addImportName(result[modulePath].names, name, 'named', alias, isTypeImport || isType);
|
|
1100
|
+
});
|
|
1101
|
+
} else {
|
|
1102
|
+
if (!externals[modulePath]) {
|
|
1103
|
+
externals[modulePath] = {
|
|
1104
|
+
names: [],
|
|
1105
|
+
positions: []
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
// Add position information
|
|
1110
|
+
externals[modulePath].positions.push(position);
|
|
1111
|
+
if (defaultImport) {
|
|
1112
|
+
addImportName(externals[modulePath].names, defaultImport, 'default', undefined, isTypeImport);
|
|
1113
|
+
}
|
|
1114
|
+
if (namespaceImport) {
|
|
1115
|
+
addImportName(externals[modulePath].names, namespaceImport, 'namespace', undefined, isTypeImport);
|
|
1116
|
+
}
|
|
1117
|
+
namedImports.forEach(({
|
|
1118
|
+
name,
|
|
1119
|
+
alias,
|
|
1120
|
+
isType
|
|
1121
|
+
}) => {
|
|
1122
|
+
addImportName(externals[modulePath].names, name, 'named', alias, isTypeImport || isType);
|
|
1123
|
+
});
|
|
1137
1124
|
}
|
|
1138
|
-
} catch (err) {
|
|
1139
|
-
_iterator.e(err);
|
|
1140
|
-
} finally {
|
|
1141
|
-
_iterator.f();
|
|
1142
1125
|
}
|
|
1143
|
-
return
|
|
1126
|
+
return {
|
|
1144
1127
|
relative: result,
|
|
1145
|
-
externals
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1128
|
+
externals,
|
|
1129
|
+
...(scanResult.code && {
|
|
1130
|
+
code: scanResult.code
|
|
1131
|
+
}),
|
|
1132
|
+
...(scanResult.comments && {
|
|
1133
|
+
comments: scanResult.comments
|
|
1134
|
+
})
|
|
1135
|
+
};
|
|
1151
1136
|
}
|
|
1152
1137
|
|
|
1153
1138
|
/**
|
|
@@ -1158,23 +1143,23 @@ function parseJSImports(code, filePath, result, externals, isMdxFile, removeComm
|
|
|
1158
1143
|
* @returns Object indicating if an import was found, the next position, and statement details
|
|
1159
1144
|
*/
|
|
1160
1145
|
function detectJavaScriptImport(sourceText, pos, _positionMapper) {
|
|
1161
|
-
|
|
1146
|
+
const ch = sourceText[pos];
|
|
1162
1147
|
|
|
1163
1148
|
// Look for 'import' keyword (not part of an identifier, and not preceded by @)
|
|
1164
1149
|
if (ch === 'i' && sourceText.slice(pos, pos + 6) === 'import' && (pos === 0 || /[^a-zA-Z0-9_$@]/.test(sourceText[pos - 1])) && /[^a-zA-Z0-9_$]/.test(sourceText[pos + 6] || '')) {
|
|
1165
1150
|
// Mark start of import statement
|
|
1166
|
-
|
|
1167
|
-
|
|
1151
|
+
const importStart = pos;
|
|
1152
|
+
const len = sourceText.length;
|
|
1168
1153
|
|
|
1169
1154
|
// Now, scan forward to find the end of the statement (semicolon or proper end for side-effect imports)
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1155
|
+
let j = pos + 6;
|
|
1156
|
+
let importState = 'code';
|
|
1157
|
+
let importQuote = null;
|
|
1158
|
+
let braceDepth = 0;
|
|
1159
|
+
let foundFrom = false;
|
|
1160
|
+
let foundModulePath = false;
|
|
1176
1161
|
while (j < len) {
|
|
1177
|
-
|
|
1162
|
+
const cj = sourceText[j];
|
|
1178
1163
|
if (importState === 'code') {
|
|
1179
1164
|
if (cj === ';') {
|
|
1180
1165
|
j += 1;
|
|
@@ -1184,7 +1169,7 @@ function detectJavaScriptImport(sourceText, pos, _positionMapper) {
|
|
|
1184
1169
|
if (cj === '\n' && !foundFrom && !foundModulePath && braceDepth === 0) {
|
|
1185
1170
|
// This might be a side-effect import or end of statement
|
|
1186
1171
|
// Look ahead to see if there's content that could be part of the import
|
|
1187
|
-
|
|
1172
|
+
let k = j + 1;
|
|
1188
1173
|
while (k < len && /\s/.test(sourceText[k])) {
|
|
1189
1174
|
k += 1;
|
|
1190
1175
|
}
|
|
@@ -1217,15 +1202,15 @@ function detectJavaScriptImport(sourceText, pos, _positionMapper) {
|
|
|
1217
1202
|
// If we found a module path and we're back to normal code, we might be done
|
|
1218
1203
|
if (foundModulePath && braceDepth === 0 && /\s/.test(cj)) {
|
|
1219
1204
|
// Look ahead for semicolon or end of statement
|
|
1220
|
-
|
|
1221
|
-
while (
|
|
1222
|
-
|
|
1205
|
+
let k = j;
|
|
1206
|
+
while (k < len && /\s/.test(sourceText[k])) {
|
|
1207
|
+
k += 1;
|
|
1223
1208
|
}
|
|
1224
|
-
if (
|
|
1225
|
-
if (sourceText[
|
|
1226
|
-
j =
|
|
1209
|
+
if (k >= len || sourceText[k] === ';' || sourceText[k] === '\n') {
|
|
1210
|
+
if (sourceText[k] === ';') {
|
|
1211
|
+
j = k + 1;
|
|
1227
1212
|
} else {
|
|
1228
|
-
j =
|
|
1213
|
+
j = k;
|
|
1229
1214
|
}
|
|
1230
1215
|
break;
|
|
1231
1216
|
}
|
|
@@ -1254,7 +1239,7 @@ function detectJavaScriptImport(sourceText, pos, _positionMapper) {
|
|
|
1254
1239
|
}
|
|
1255
1240
|
j += 1;
|
|
1256
1241
|
}
|
|
1257
|
-
|
|
1242
|
+
const importText = sourceText.slice(importStart, j);
|
|
1258
1243
|
return {
|
|
1259
1244
|
found: true,
|
|
1260
1245
|
nextPos: j,
|
|
@@ -1305,30 +1290,25 @@ function detectJavaScriptImport(sourceText, pos, _positionMapper) {
|
|
|
1305
1290
|
* // result.relative['./Button'] contains the Button import with url: 'file:///src/Button'
|
|
1306
1291
|
* ```
|
|
1307
1292
|
*/
|
|
1308
|
-
export function parseImportsAndComments(
|
|
1309
|
-
|
|
1310
|
-
}
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
return _context.a(2, parseJSImports(code, filePath, result, externals, isMdxFile, options == null ? void 0 : options.removeCommentsWithPrefix, options == null ? void 0 : options.notableCommentsPrefix));
|
|
1330
|
-
}
|
|
1331
|
-
}, _callee);
|
|
1332
|
-
}));
|
|
1333
|
-
return _parseImportsAndComments.apply(this, arguments);
|
|
1293
|
+
export async function parseImportsAndComments(code, fileUrl, options) {
|
|
1294
|
+
const result = {};
|
|
1295
|
+
const externals = {};
|
|
1296
|
+
|
|
1297
|
+
// Convert file:// URL or OS path to portable path format for cross-platform compatibility
|
|
1298
|
+
// Portable paths always use forward slashes and start with / (even on Windows: /C:/...)
|
|
1299
|
+
const filePath = fileUrlToPortablePath(fileUrl);
|
|
1300
|
+
|
|
1301
|
+
// Check if this is a CSS file
|
|
1302
|
+
const isCssFile = filePath.toLowerCase().endsWith('.css');
|
|
1303
|
+
|
|
1304
|
+
// Check if this is an MDX file (which can contain code blocks with triple backticks)
|
|
1305
|
+
const isMdxFile = filePath.toLowerCase().endsWith('.mdx');
|
|
1306
|
+
|
|
1307
|
+
// If this is a CSS file, parse CSS @import statements instead
|
|
1308
|
+
if (isCssFile) {
|
|
1309
|
+
return parseCssImports(code, filePath, result, externals, options?.removeCommentsWithPrefix, options?.notableCommentsPrefix);
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
// Parse JavaScript import statements
|
|
1313
|
+
return parseJSImports(code, filePath, result, externals, isMdxFile, options?.removeCommentsWithPrefix, options?.notableCommentsPrefix);
|
|
1334
1314
|
}
|