@mui/internal-docs-infra 0.2.0-alpha.1 → 0.2.0

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.
Files changed (45) hide show
  1. package/esm/CodeHighlighter/CodeHighlighter.js +54 -39
  2. package/esm/CodeHighlighter/CodeHighlighterClient.js +77 -33
  3. package/esm/CodeHighlighter/errors.js +1 -1
  4. package/esm/CodeHighlighter/loadFallbackCode.js +6 -2
  5. package/esm/CodeHighlighter/loadVariant.js +64 -22
  6. package/esm/CodeHighlighter/maybeInitialData.d.ts +2 -2
  7. package/esm/CodeHighlighter/maybeInitialData.js +2 -2
  8. package/esm/CodeHighlighter/transformSource.js +57 -17
  9. package/esm/CodeHighlighter/types.d.ts +20 -3
  10. package/esm/abstractCreateDemo/abstractCreateDemo.d.ts +4 -2
  11. package/esm/abstractCreateDemo/abstractCreateDemo.js +2 -1
  12. package/esm/pipeline/hastUtils/hastUtils.d.ts +6 -0
  13. package/esm/pipeline/hastUtils/hastUtils.js +20 -0
  14. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.d.ts +3 -1
  15. package/esm/pipeline/loadPrecomputedCodeHighlighter/loadPrecomputedCodeHighlighter.js +2 -1
  16. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.d.ts +6 -4
  17. package/esm/pipeline/loadPrecomputedCodeHighlighter/parseCreateFactoryCall.js +443 -258
  18. package/esm/pipeline/loadServerSource/loadServerSource.js +59 -19
  19. package/esm/pipeline/loaderUtils/index.d.ts +1 -1
  20. package/esm/pipeline/loaderUtils/index.js +1 -1
  21. package/esm/pipeline/loaderUtils/parseImportsAndComments.d.ts +91 -0
  22. package/esm/pipeline/loaderUtils/parseImportsAndComments.js +1329 -0
  23. package/esm/pipeline/loaderUtils/processRelativeImports.d.ts +8 -3
  24. package/esm/pipeline/loaderUtils/processRelativeImports.js +237 -118
  25. package/esm/pipeline/loaderUtils/resolveModulePath.d.ts +7 -3
  26. package/esm/pipeline/loaderUtils/resolveModulePath.js +3 -3
  27. package/esm/pipeline/loaderUtils/resolveModulePathWithFs.d.ts +4 -0
  28. package/esm/pipeline/loaderUtils/rewriteImports.d.ts +12 -5
  29. package/esm/pipeline/loaderUtils/rewriteImports.js +56 -26
  30. package/esm/pipeline/transformHtmlCodePrecomputed/index.d.ts +2 -0
  31. package/esm/pipeline/transformHtmlCodePrecomputed/index.js +4 -0
  32. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.d.ts +13 -0
  33. package/esm/pipeline/transformHtmlCodePrecomputed/transformHtmlCodePrecomputed.js +415 -0
  34. package/esm/pipeline/transformMarkdownCode/transformMarkdownCode.js +304 -47
  35. package/esm/useCode/Pre.js +5 -0
  36. package/esm/useCode/useFileNavigation.js +4 -0
  37. package/esm/withDocsInfra/withDocsInfra.d.ts +12 -1
  38. package/esm/withDocsInfra/withDocsInfra.js +34 -6
  39. package/package.json +6 -4
  40. package/esm/pipeline/loaderUtils/parseImports.d.ts +0 -19
  41. package/esm/pipeline/loaderUtils/parseImports.js +0 -306
  42. package/esm/pipeline/transformHtmlCode/index.d.ts +0 -2
  43. package/esm/pipeline/transformHtmlCode/index.js +0 -4
  44. package/esm/pipeline/transformHtmlCode/transformHtmlCode.d.ts +0 -13
  45. package/esm/pipeline/transformHtmlCode/transformHtmlCode.js +0 -300
@@ -1,12 +1,10 @@
1
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
- import _extends from "@babel/runtime/helpers/esm/extends";
3
1
  import _regenerator from "@babel/runtime/helpers/esm/regenerator";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
4
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
5
4
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
6
5
  import _typeof from "@babel/runtime/helpers/esm/typeof";
7
6
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
8
- var _excluded = ["parseImportsResult", "remaining"];
9
- import { parseImports } from "../loaderUtils/index.js";
7
+ import { parseImportsAndComments } from "../loaderUtils/index.js";
10
8
  import { parseFunctionArguments, isTypeAssertion, isFunction, isGeneric, isArray, isArrowFunction, isObjectLiteral } from "./parseFunctionArguments.js";
11
9
 
12
10
  /**
@@ -203,9 +201,17 @@ function parseVariantsObjectFromObject(obj, importMap, namedExportsMap, function
203
201
  var expression = typeAssertion.expression;
204
202
  importName = typeof expression === 'string' ? expression : String(expression);
205
203
  } else if (typeof value === 'string') {
206
- // Simple string value - strip TypeScript type assertions
207
- var asIndex = value.indexOf(' as ');
208
- importName = asIndex !== -1 ? value.substring(0, asIndex).trim() : value.trim();
204
+ // Simple string value - strip TypeScript type assertions and typeof expressions
205
+ var processedValue = value.trim();
206
+ var asIndex = processedValue.indexOf(' as ');
207
+ if (asIndex !== -1) {
208
+ processedValue = processedValue.substring(0, asIndex).trim();
209
+ }
210
+ // Handle typeof expressions
211
+ if (processedValue.startsWith('typeof ')) {
212
+ processedValue = processedValue.substring(7).trim();
213
+ }
214
+ importName = processedValue;
209
215
  } else {
210
216
  // Handle other structured types (functions, generics, arrays)
211
217
  var functionCall = isFunction(value);
@@ -247,7 +253,7 @@ function parseVariantsObjectFromObject(obj, importMap, namedExportsMap, function
247
253
  }
248
254
 
249
255
  /**
250
- * Helper function to convert the new parseImports format to a Map
256
+ * Helper function to convert the new parseImportsAndComments format to a Map
251
257
  * that maps import names to their resolved paths
252
258
  */
253
259
  function buildImportMap(importResult, allowExternalVariants) {
@@ -409,6 +415,17 @@ function parseVariantsArgumentFromStructured(structuredVariants, importMap, name
409
415
  // If it's a single identifier string
410
416
  if (typeof structuredVariants === 'string') {
411
417
  var componentName = structuredVariants.trim();
418
+
419
+ // Handle TypeScript type assertions in single component syntax
420
+ var asIndex = componentName.indexOf(' as ');
421
+ if (asIndex !== -1) {
422
+ componentName = componentName.substring(0, asIndex).trim();
423
+ }
424
+
425
+ // Handle typeof expressions in single component syntax
426
+ if (componentName.startsWith('typeof ')) {
427
+ componentName = componentName.substring(7).trim();
428
+ }
412
429
  if (importMap.has(componentName)) {
413
430
  return {
414
431
  variants: {
@@ -428,6 +445,56 @@ function parseVariantsArgumentFromStructured(structuredVariants, importMap, name
428
445
  throw new Error("Unexpected structured variants format in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected string, array, or object but got: ".concat(_typeof(structuredVariants)));
429
446
  }
430
447
 
448
+ /**
449
+ * Parse TypeScript generic definitions to extract variants mapping
450
+ * e.g., "{ VariantA: ComponentA, VariantB: ComponentB }" -> { VariantA: "ComponentA", VariantB: "ComponentB" }
451
+ * e.g., "Component" -> { Default: "Component" }
452
+ */
453
+ function parseGenericDefinitions(genericContent) {
454
+ if (!genericContent.trim()) {
455
+ return {};
456
+ }
457
+
458
+ // Handle object literals directly (most common case)
459
+ var trimmed = genericContent.trim();
460
+ if (trimmed.startsWith('{') && trimmed.endsWith('}')) {
461
+ // Parse as object literal using the existing parser
462
+ var _parsed = parseFunctionArguments(trimmed);
463
+ if (_parsed.length === 1 && _typeof(_parsed[0]) === 'object' && !Array.isArray(_parsed[0])) {
464
+ return _parsed[0];
465
+ }
466
+ }
467
+
468
+ // Parse the generic content using the existing parser
469
+ var parsed = parseFunctionArguments(genericContent);
470
+
471
+ // If it's a single object, return it
472
+ if (parsed.length === 1 && _typeof(parsed[0]) === 'object' && !Array.isArray(parsed[0])) {
473
+ return parsed[0];
474
+ }
475
+
476
+ // If it's a single string (single component), treat as Default variant
477
+ if (parsed.length === 1 && typeof parsed[0] === 'string') {
478
+ return {
479
+ Default: parsed[0]
480
+ };
481
+ }
482
+
483
+ // If it's multiple elements, try to interpret as an object
484
+ if (parsed.length > 1) {
485
+ var result = {};
486
+ parsed.forEach(function (item, index) {
487
+ if (typeof item === 'string') {
488
+ result["Variant".concat(index + 1)] = item;
489
+ } else if (_typeof(item) === 'object' && item !== null) {
490
+ Object.assign(result, item);
491
+ }
492
+ });
493
+ return result;
494
+ }
495
+ return {};
496
+ }
497
+
431
498
  /**
432
499
  * Validates that a URL argument follows the expected convention
433
500
  */
@@ -485,75 +552,154 @@ export function parseCreateFactoryCall(_x, _x2) {
485
552
  function _parseCreateFactoryCall() {
486
553
  _parseCreateFactoryCall = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(code, filePath) {
487
554
  var parseOptions,
488
- parseImportsResult,
489
- createFactoryMatches,
555
+ importsAndComments,
490
556
  match,
491
- functionName,
492
- fullMatch,
493
- urlArg,
494
- structuredVariants,
495
- optionsStructured,
496
- hasOptions,
497
- argumentsStartIndex,
498
- argumentsEndIndex,
499
- allowExternalVariants,
500
- importMap,
501
- namedExportsMap,
502
- externals,
503
- _parseOptions$metadat2,
504
- metadataOnly,
505
- url,
506
- variants,
507
- namedExports,
508
- variantsResult,
509
- options,
510
- skipPrecomputeValue,
511
- transformedExternals,
512
- _i4,
513
- _Object$entries4,
514
- _Object$entries4$_i,
515
- modulePath,
516
- externalImport,
517
- remaining,
557
+ secondMatch,
518
558
  parsed,
559
+ remaining,
519
560
  _args = arguments,
520
561
  _t;
521
562
  return _regenerator().w(function (_context) {
522
563
  while (1) switch (_context.n) {
523
564
  case 0:
524
565
  parseOptions = _args.length > 2 && _args[2] !== undefined ? _args[2] : {};
525
- parseImportsResult = _args.length > 3 ? _args[3] : undefined;
526
- // Find all create* calls in the code
527
- createFactoryMatches = findCreateFactoryCalls(code, filePath, parseOptions); // Enforce single create* call per file unless allowMultipleFactories is true
528
- if (!(!parseOptions.allowMultipleFactories && createFactoryMatches.length > 1)) {
566
+ importsAndComments = _args.length > 3 ? _args[3] : undefined;
567
+ // Find the first create* call in the code
568
+ match = findFirstCreateFactoryCall(code, filePath, parseOptions); // Return null if no create* call found
569
+ if (match) {
529
570
  _context.n = 1;
530
571
  break;
531
572
  }
532
- throw new Error("Multiple create* factory calls found in ".concat(filePath, ". Only one create* call per file is supported. Found ").concat(createFactoryMatches.length, " calls."));
573
+ return _context.a(2, null);
533
574
  case 1:
534
- if (!(createFactoryMatches.length === 0)) {
575
+ if (parseOptions.allowMultipleFactories) {
535
576
  _context.n = 2;
536
577
  break;
537
578
  }
538
- return _context.a(2, null);
579
+ secondMatch = findFirstCreateFactoryCall(code, filePath, parseOptions, match.functionEndIndex + 1);
580
+ if (!secondMatch) {
581
+ _context.n = 2;
582
+ break;
583
+ }
584
+ throw new Error("Multiple create* factory calls found in ".concat(filePath, ". Only one create* call per file is supported. Found 2 calls."));
539
585
  case 2:
540
- match = createFactoryMatches[0];
541
- functionName = match.functionName, fullMatch = match.fullMatch, urlArg = match.urlArg, structuredVariants = match.structuredVariants, optionsStructured = match.optionsStructured, hasOptions = match.hasOptions, argumentsStartIndex = match.argumentsStartIndex, argumentsEndIndex = match.argumentsEndIndex; // Get import mappings from precomputed imports or parse them
542
- _t = parseImportsResult;
586
+ _t = importsAndComments;
543
587
  if (_t) {
544
588
  _context.n = 4;
545
589
  break;
546
590
  }
547
591
  _context.n = 3;
548
- return parseImports(code, filePath);
592
+ return parseImportsAndComments(code, filePath);
549
593
  case 3:
550
594
  _t = _context.v;
551
595
  case 4:
552
- parseImportsResult = _t;
596
+ importsAndComments = _t;
597
+ _context.n = 5;
598
+ return processCreateFactoryMatch(match, code, filePath, parseOptions, importsAndComments);
599
+ case 5:
600
+ parsed = _context.v;
601
+ // Calculate remaining content after the function call
602
+ remaining = code.substring(match.functionEndIndex + 1);
603
+ return _context.a(2, _extends(_extends({}, parsed), {}, {
604
+ remaining: remaining,
605
+ importsAndComments: importsAndComments // Include import data for reuse
606
+ }));
607
+ }
608
+ }, _callee);
609
+ }));
610
+ return _parseCreateFactoryCall.apply(this, arguments);
611
+ }
612
+ export function parseAllCreateFactoryCalls(_x3, _x4) {
613
+ return _parseAllCreateFactoryCalls.apply(this, arguments);
614
+ }
615
+
616
+ /**
617
+ * Processes a matched create* factory call into a ParsedCreateFactory object
618
+ * Handles all the common logic for validation, parsing, and transformation
619
+ */
620
+ function _parseAllCreateFactoryCalls() {
621
+ _parseAllCreateFactoryCalls = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(code, filePath) {
622
+ var parseOptions,
623
+ results,
624
+ importsAndComments,
625
+ searchIndex,
626
+ match,
627
+ beforeMatch,
628
+ exportMatch,
629
+ exportName,
630
+ parsedFactory,
631
+ _args2 = arguments,
632
+ _t2;
633
+ return _regenerator().w(function (_context2) {
634
+ while (1) switch (_context2.n) {
635
+ case 0:
636
+ parseOptions = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
637
+ results = {};
638
+ searchIndex = 0; // Process the code using single-pass approach
639
+ case 1:
640
+ if (!(searchIndex < code.length)) {
641
+ _context2.n = 6;
642
+ break;
643
+ }
644
+ // Find the next create* call
645
+ match = findFirstCreateFactoryCall(code, filePath, parseOptions, searchIndex);
646
+ if (match) {
647
+ _context2.n = 2;
648
+ break;
649
+ }
650
+ return _context2.a(3, 6);
651
+ case 2:
652
+ // Extract export name from the function call context
653
+ beforeMatch = code.substring(0, match.functionStartIndex);
654
+ exportMatch = beforeMatch.match(/export\s+const\s+(\w+)\s*=\s*$/m);
655
+ exportName = (exportMatch == null ? void 0 : exportMatch[1]) || 'unknown'; // Get import mappings from precomputed imports or parse them
656
+ // eslint-disable-next-line no-await-in-loop
657
+ _t2 = importsAndComments;
658
+ if (_t2) {
659
+ _context2.n = 4;
660
+ break;
661
+ }
662
+ _context2.n = 3;
663
+ return parseImportsAndComments(code, filePath);
664
+ case 3:
665
+ _t2 = _context2.v;
666
+ case 4:
667
+ importsAndComments = _t2;
668
+ _context2.n = 5;
669
+ return processCreateFactoryMatch(match, code, filePath, parseOptions, importsAndComments);
670
+ case 5:
671
+ parsedFactory = _context2.v;
672
+ results[exportName] = parsedFactory;
673
+
674
+ // Continue searching from after this function call
675
+ searchIndex = match.functionEndIndex + 1;
676
+ _context2.n = 1;
677
+ break;
678
+ case 6:
679
+ return _context2.a(2, results);
680
+ }
681
+ }, _callee2);
682
+ }));
683
+ return _parseAllCreateFactoryCalls.apply(this, arguments);
684
+ }
685
+ function processCreateFactoryMatch(_x5, _x6, _x7, _x8, _x9) {
686
+ return _processCreateFactoryMatch.apply(this, arguments);
687
+ }
688
+ /**
689
+ * Finds the first create* factory call in code, starting from a given index
690
+ * Returns null if no create* call is found
691
+ */
692
+ function _processCreateFactoryMatch() {
693
+ _processCreateFactoryMatch = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(match, code, filePath, parseOptions, importsAndComments) {
694
+ var functionName, fullMatch, urlArg, structuredVariants, optionsStructured, hasOptions, argumentsStartIndex, argumentsEndIndex, allowExternalVariants, importMap, namedExportsMap, externals, _parseOptions$metadat2, metadataOnly, url, variants, namedExports, variantsResult, _variantsResult, options, skipPrecomputeValue, transformedExternals, _i5, _Object$entries4, _Object$entries4$_i, modulePath, externalImport;
695
+ return _regenerator().w(function (_context3) {
696
+ while (1) switch (_context3.n) {
697
+ case 0:
698
+ functionName = match.functionName, fullMatch = match.fullMatch, urlArg = match.urlArg, structuredVariants = match.structuredVariants, optionsStructured = match.optionsStructured, hasOptions = match.hasOptions, argumentsStartIndex = match.argumentsStartIndex, argumentsEndIndex = match.argumentsEndIndex;
553
699
  allowExternalVariants = parseOptions.allowExternalVariants || false;
554
- importMap = buildImportMap(parseImportsResult, allowExternalVariants);
555
- namedExportsMap = buildNamedExportsMap(parseImportsResult, allowExternalVariants);
556
- externals = parseImportsResult.externals; // Validate URL argument
700
+ importMap = buildImportMap(importsAndComments, allowExternalVariants);
701
+ namedExportsMap = buildNamedExportsMap(importsAndComments, allowExternalVariants);
702
+ externals = importsAndComments.externals; // Validate URL argument
557
703
  validateUrlArgument(urlArg, functionName, filePath);
558
704
 
559
705
  // Validate variants argument (skip in metadata-only mode)
@@ -564,10 +710,18 @@ function _parseCreateFactoryCall() {
564
710
 
565
711
  // Extract URL (typically import.meta.url)
566
712
  url = urlArg.trim(); // Resolve variants using structured data (skip in metadata-only mode)
567
- if (!metadataOnly && structuredVariants !== undefined) {
568
- variantsResult = parseVariantsArgumentFromStructured(structuredVariants, importMap, namedExportsMap, functionName, filePath);
569
- variants = variantsResult.variants;
570
- namedExports = variantsResult.namedExports;
713
+ if (!metadataOnly) {
714
+ if (structuredVariants !== undefined) {
715
+ // Use regular variants argument
716
+ variantsResult = parseVariantsArgumentFromStructured(structuredVariants, importMap, namedExportsMap, functionName, filePath);
717
+ variants = variantsResult.variants;
718
+ namedExports = variantsResult.namedExports;
719
+ } else if (match.hasGenerics && match.structuredGenerics && Object.keys(match.structuredGenerics).length > 0) {
720
+ // Use generics as variants when no variants argument is provided and generics are not empty
721
+ _variantsResult = parseVariantsArgumentFromStructured(match.structuredGenerics, importMap, namedExportsMap, functionName, filePath);
722
+ variants = _variantsResult.variants;
723
+ namedExports = _variantsResult.namedExports;
724
+ }
571
725
  }
572
726
 
573
727
  // Parse options object
@@ -595,20 +749,17 @@ function _parseCreateFactoryCall() {
595
749
  }
596
750
  }
597
751
 
598
- // Transform externals from parseImports format to simplified format
752
+ // Transform externals from parseImportsAndComments format to simplified format
599
753
  // Only include side-effect imports (where names array is empty)
600
754
  transformedExternals = {};
601
- for (_i4 = 0, _Object$entries4 = Object.entries(externals); _i4 < _Object$entries4.length; _i4++) {
602
- _Object$entries4$_i = _slicedToArray(_Object$entries4[_i4], 2), modulePath = _Object$entries4$_i[0], externalImport = _Object$entries4$_i[1];
755
+ for (_i5 = 0, _Object$entries4 = Object.entries(externals); _i5 < _Object$entries4.length; _i5++) {
756
+ _Object$entries4$_i = _slicedToArray(_Object$entries4[_i5], 2), modulePath = _Object$entries4$_i[0], externalImport = _Object$entries4$_i[1];
603
757
  // Only include side-effect imports (empty names array)
604
758
  if (externalImport.names.length === 0) {
605
759
  transformedExternals[modulePath] = []; // Empty array for side-effect imports
606
760
  }
607
761
  }
608
-
609
- // Calculate remaining content after the function call
610
- remaining = code.substring(match.functionEndIndex + 1);
611
- parsed = {
762
+ return _context3.a(2, {
612
763
  functionName: functionName,
613
764
  url: url,
614
765
  variants: variants,
@@ -624,226 +775,260 @@ function _parseCreateFactoryCall() {
624
775
  structuredVariants: structuredVariants,
625
776
  structuredOptions: optionsStructured,
626
777
  // Use original structured data, not cleaned options
627
- remaining: remaining,
628
- parseImportsResult: parseImportsResult // Include import data for reuse
629
- };
630
- return _context.a(2, parsed);
778
+ hasGenerics: match.hasGenerics,
779
+ structuredGenerics: match.structuredGenerics
780
+ });
631
781
  }
632
- }, _callee);
782
+ }, _callee3);
633
783
  }));
634
- return _parseCreateFactoryCall.apply(this, arguments);
635
- }
636
- export function parseAllCreateFactoryCalls(_x3, _x4) {
637
- return _parseAllCreateFactoryCalls.apply(this, arguments);
784
+ return _processCreateFactoryMatch.apply(this, arguments);
638
785
  }
786
+ function findFirstCreateFactoryCall(code, filePath) {
787
+ var parseOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
788
+ var startIndex = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
789
+ var createFunctionRegex = /\b(create\w*)\s*/g;
790
+ createFunctionRegex.lastIndex = startIndex;
791
+ var match = createFunctionRegex.exec(code);
792
+ if (!match) {
793
+ return null;
794
+ }
795
+ var functionName = match[1];
796
+ var matchStartIndex = match.index;
797
+ var currentIndex = match.index + match[0].length;
639
798
 
640
- /**
641
- * Finds create* factory calls in code, handling multiline cases
642
- */
643
- function _parseAllCreateFactoryCalls() {
644
- _parseAllCreateFactoryCalls = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(code, filePath) {
645
- var parseOptions,
646
- results,
647
- currentCode,
648
- parseImportsResult,
649
- result,
650
- exportMatch,
651
- exportName,
652
- unusedResult,
653
- unusedRemaining,
654
- parsedFactory,
655
- _args2 = arguments;
656
- return _regenerator().w(function (_context2) {
657
- while (1) switch (_context2.n) {
658
- case 0:
659
- parseOptions = _args2.length > 2 && _args2[2] !== undefined ? _args2[2] : {};
660
- results = {}; // Process the code sequentially, reusing import data from the first call
661
- currentCode = code;
662
- case 1:
663
- if (!currentCode.trim()) {
664
- _context2.n = 5;
665
- break;
666
- }
667
- _context2.n = 2;
668
- return parseCreateFactoryCall(currentCode, filePath, _extends(_extends({}, parseOptions), {}, {
669
- allowMultipleFactories: true
670
- }),
671
- // Allow multiple factories for this function
672
- parseImportsResult // undefined for first call, reused for subsequent calls
673
- );
674
- case 2:
675
- result = _context2.v;
676
- if (result) {
677
- _context2.n = 3;
678
- break;
679
- }
680
- return _context2.a(3, 5);
681
- case 3:
682
- // Extract export name from the function call context
683
- exportMatch = currentCode.match(/export\s+const\s+(\w+)\s*=/);
684
- exportName = (exportMatch == null ? void 0 : exportMatch[1]) || 'unknown'; // Capture import data from the first successful call for reuse
685
- parseImportsResult = result.parseImportsResult || parseImportsResult;
799
+ // Skip any whitespace after function name
800
+ while (currentIndex < code.length && /\s/.test(code[currentIndex])) {
801
+ currentIndex += 1;
802
+ }
803
+ if (currentIndex >= code.length) {
804
+ // No opening parenthesis found, try to find the next create* call
805
+ return findFirstCreateFactoryCall(code, filePath, parseOptions, match.index + match[0].length);
806
+ }
807
+ var genericContent = '';
808
+ var hasGenerics = false;
686
809
 
687
- // Remove the parseImportsResult before storing (we don't need it in the final result)
688
- unusedResult = result.parseImportsResult, unusedRemaining = result.remaining, parsedFactory = _objectWithoutPropertiesLoose(result, _excluded);
689
- results[exportName] = parsedFactory;
810
+ // Check if we have generics (starts with <)
811
+ if (code[currentIndex] === '<') {
812
+ hasGenerics = true;
813
+ var angleCount = 1;
814
+ var genericEndIndex = -1;
690
815
 
691
- // Move to the remaining code after this export
692
- if (result.remaining) {
693
- _context2.n = 4;
694
- break;
695
- }
696
- currentCode = '';
697
- return _context2.a(3, 5);
698
- case 4:
699
- currentCode = result.remaining;
700
- _context2.n = 1;
701
- break;
702
- case 5:
703
- return _context2.a(2, results);
704
- }
705
- }, _callee2);
706
- }));
707
- return _parseAllCreateFactoryCalls.apply(this, arguments);
708
- }
709
- function findCreateFactoryCalls(code, filePath) {
710
- var parseOptions = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
711
- var results = [];
712
-
713
- // Find all create* function calls
714
- var createFactoryRegex = /\b(create\w*)\s*\(/g;
715
- var match = createFactoryRegex.exec(code);
716
- while (match !== null) {
717
- var functionName = match[1];
718
- var startIndex = match.index;
719
- var parenIndex = match.index + match[0].length - 1; // Position of opening parenthesis
720
-
721
- // Find the matching closing parenthesis
722
- var parenCount = 0;
723
- var endIndex = -1;
724
- for (var i = parenIndex; i < code.length; i += 1) {
725
- if (code[i] === '(') {
726
- parenCount += 1;
727
- } else if (code[i] === ')') {
728
- parenCount -= 1;
729
- if (parenCount === 0) {
730
- endIndex = i;
816
+ // Find the matching closing angle bracket, handling nesting
817
+ for (var i = currentIndex + 1; i < code.length; i += 1) {
818
+ var _char = code[i];
819
+ if (_char === '<') {
820
+ angleCount += 1;
821
+ } else if (_char === '>') {
822
+ angleCount -= 1;
823
+ if (angleCount === 0) {
824
+ genericEndIndex = i;
731
825
  break;
732
826
  }
733
827
  }
734
828
  }
735
- if (endIndex === -1) {
736
- match = createFactoryRegex.exec(code);
737
- continue;
829
+ if (genericEndIndex === -1) {
830
+ // Unmatched angle brackets, try to find the next create* call
831
+ return findFirstCreateFactoryCall(code, filePath, parseOptions, match.index + match[0].length);
738
832
  }
739
- var fullMatch = code.substring(startIndex, endIndex + 1);
740
- var content = code.substring(parenIndex + 1, endIndex);
741
-
742
- // Split by commas at the top level, handling nested structures and comments
743
- var structured = parseFunctionArguments(content);
744
-
745
- // Validate the function follows the convention
746
- var _parseOptions$metadat = parseOptions.metadataOnly,
747
- metadataOnly = _parseOptions$metadat === void 0 ? false : _parseOptions$metadat;
748
- if (metadataOnly) {
749
- // For metadata-only mode: expect 1-2 arguments (url, options?)
750
- if (structured.length < 1 || structured.length > 2) {
751
- throw new Error("Invalid ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 1-2 arguments (url, options?) but got ".concat(structured.length, " arguments. ") + "In metadata-only mode, functions should follow: create*(url, options?)");
752
- }
753
- } else if (structured.length < 2 || structured.length > 3) {
754
- // Normal mode: expect 2-3 arguments (url, variants, options?)
755
- throw new Error("Invalid ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 2-3 arguments (url, variants, options?) but got ".concat(structured.length, " arguments. ") + "Functions starting with 'create' must follow the convention: create*(url, variants, options?)");
833
+ genericContent = code.substring(currentIndex + 1, genericEndIndex);
834
+ currentIndex = genericEndIndex + 1;
835
+
836
+ // Skip whitespace after generics
837
+ while (currentIndex < code.length && /\s/.test(code[currentIndex])) {
838
+ currentIndex += 1;
756
839
  }
840
+ }
757
841
 
758
- // Handle different argument patterns based on mode
759
- if (metadataOnly) {
760
- // Metadata-only mode: expect 1-2 arguments (url, options?)
761
- if (structured.length === 1) {
762
- var _structured = _slicedToArray(structured, 1),
763
- urlArg = _structured[0];
764
- results.push({
765
- functionName: functionName,
766
- fullMatch: fullMatch,
767
- urlArg: typeof urlArg === 'string' ? urlArg.trim() : String(urlArg),
768
- structuredVariants: undefined,
769
- // No variants in metadata-only mode
770
- optionsStructured: undefined,
771
- hasOptions: false,
772
- functionStartIndex: startIndex,
773
- functionEndIndex: endIndex,
774
- argumentsStartIndex: parenIndex + 1,
775
- argumentsEndIndex: endIndex
776
- });
777
- } else if (structured.length === 2) {
778
- var _structured2 = _slicedToArray(structured, 2),
779
- _urlArg = _structured2[0],
780
- optionsStructured = _structured2[1];
781
-
782
- // Options should be an object
783
- if (typeof optionsStructured === 'string' || !Array.isArray(optionsStructured) && _typeof(optionsStructured) !== 'object') {
784
- throw new Error("Invalid options argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object but got: ".concat(typeof optionsStructured === 'string' ? optionsStructured : JSON.stringify(optionsStructured)));
785
- }
786
- results.push({
787
- functionName: functionName,
788
- fullMatch: fullMatch,
789
- urlArg: typeof _urlArg === 'string' ? _urlArg.trim() : String(_urlArg),
790
- structuredVariants: undefined,
791
- // No variants in metadata-only mode
792
- optionsStructured: _typeof(optionsStructured) === 'object' && optionsStructured !== null ? optionsStructured : undefined,
793
- hasOptions: true,
794
- functionStartIndex: startIndex,
795
- functionEndIndex: endIndex,
796
- argumentsStartIndex: parenIndex + 1,
797
- argumentsEndIndex: endIndex
798
- });
842
+ // Now look for the opening parenthesis
843
+ if (currentIndex >= code.length || code[currentIndex] !== '(') {
844
+ // No opening parenthesis found, try to find the next create* call
845
+ return findFirstCreateFactoryCall(code, filePath, parseOptions, match.index + match[0].length);
846
+ }
847
+ var parenIndex = currentIndex;
848
+
849
+ // Find the matching closing parenthesis
850
+ var parenCount = 0;
851
+ var endIndex = -1;
852
+ for (var _i4 = parenIndex; _i4 < code.length; _i4 += 1) {
853
+ if (code[_i4] === '(') {
854
+ parenCount += 1;
855
+ } else if (code[_i4] === ')') {
856
+ parenCount -= 1;
857
+ if (parenCount === 0) {
858
+ endIndex = _i4;
859
+ break;
799
860
  }
800
861
  }
862
+ }
863
+ if (endIndex === -1) {
864
+ // Unmatched parentheses, try to find the next create* call
865
+ return findFirstCreateFactoryCall(code, filePath, parseOptions, match.index + match[0].length);
866
+ }
867
+ var fullMatch = code.substring(matchStartIndex, endIndex + 1);
868
+ var content = code.substring(parenIndex + 1, endIndex);
869
+
870
+ // Parse generic content if present
871
+ var structuredGenerics;
872
+ if (hasGenerics) {
873
+ // Parse the generic content as TypeScript type definitions
874
+ structuredGenerics = parseGenericDefinitions(genericContent);
875
+ }
876
+
877
+ // Split by commas at the top level, handling nested structures and comments
878
+ var structured = parseFunctionArguments(content);
801
879
 
880
+ // Validate the function follows the convention
881
+ var _parseOptions$metadat = parseOptions.metadataOnly,
882
+ metadataOnly = _parseOptions$metadat === void 0 ? false : _parseOptions$metadat;
883
+ if (metadataOnly) {
884
+ // For metadata-only mode: expect 1-2 arguments (url, options?)
885
+ if (structured.length < 1 || structured.length > 2) {
886
+ throw new Error("Invalid ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 1-2 arguments (url, options?) but got ".concat(structured.length, " arguments. ") + "In metadata-only mode, functions should follow: create*(url, options?)");
887
+ }
888
+ } else if (hasGenerics && structured.length <= 2) {
889
+ // When generics are present AND we have 1-2 arguments, expect (url, options?)
890
+ if (structured.length < 1 || structured.length > 2) {
891
+ throw new Error("Invalid ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 1-2 arguments (url, options?) but got ".concat(structured.length, " arguments. ") + "Functions with TypeScript generics should follow: create*<variants>(url, options?)");
892
+ }
893
+ } else if (!hasGenerics && (structured.length < 2 || structured.length > 3)) {
802
894
  // Normal mode: expect 2-3 arguments (url, variants, options?)
803
- if (!metadataOnly) {
804
- if (structured.length === 2) {
805
- var _structured3 = _slicedToArray(structured, 2),
806
- _urlArg2 = _structured3[0],
807
- variantsStructured = _structured3[1];
808
- results.push({
809
- functionName: functionName,
810
- fullMatch: fullMatch,
811
- urlArg: typeof _urlArg2 === 'string' ? _urlArg2.trim() : String(_urlArg2),
812
- structuredVariants: variantsStructured,
813
- optionsStructured: undefined,
814
- hasOptions: false,
815
- // No options argument was provided
816
- functionStartIndex: startIndex,
817
- functionEndIndex: endIndex,
818
- argumentsStartIndex: parenIndex + 1,
819
- argumentsEndIndex: endIndex
820
- });
821
- } else if (structured.length === 3) {
822
- var _structured4 = _slicedToArray(structured, 3),
823
- _urlArg3 = _structured4[0],
824
- _variantsStructured = _structured4[1],
825
- _optionsStructured = _structured4[2];
826
-
827
- // Options should be an object (Record<string, any>) or an empty object
828
- if (typeof _optionsStructured === 'string' || !Array.isArray(_optionsStructured) && _typeof(_optionsStructured) !== 'object') {
829
- throw new Error("Invalid options argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object but got: ".concat(typeof _optionsStructured === 'string' ? _optionsStructured : JSON.stringify(_optionsStructured)));
830
- }
831
- results.push({
895
+ throw new Error("Invalid ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected 2-3 arguments (url, variants, options?) but got ".concat(structured.length, " arguments. ") + "Functions starting with 'create' must follow the convention: create*(url, variants, options?)");
896
+ }
897
+
898
+ // Handle different argument patterns based on mode
899
+ if (metadataOnly) {
900
+ // Metadata-only mode: expect 1-2 arguments (url, options?)
901
+ if (structured.length === 1) {
902
+ var _structured = _slicedToArray(structured, 1),
903
+ urlArg = _structured[0];
904
+ return {
905
+ functionName: functionName,
906
+ fullMatch: fullMatch,
907
+ urlArg: typeof urlArg === 'string' ? urlArg.trim() : String(urlArg),
908
+ structuredVariants: hasGenerics ? structuredGenerics : undefined,
909
+ // Use generics as variants in metadata-only mode
910
+ optionsStructured: undefined,
911
+ hasOptions: false,
912
+ hasGenerics: hasGenerics,
913
+ structuredGenerics: structuredGenerics,
914
+ functionStartIndex: matchStartIndex,
915
+ functionEndIndex: endIndex,
916
+ argumentsStartIndex: parenIndex + 1,
917
+ argumentsEndIndex: endIndex
918
+ };
919
+ }
920
+ if (structured.length === 2) {
921
+ var _structured2 = _slicedToArray(structured, 2),
922
+ _urlArg = _structured2[0],
923
+ optionsStructured = _structured2[1];
924
+
925
+ // Options should be an object
926
+ if (typeof optionsStructured === 'string' || !Array.isArray(optionsStructured) && _typeof(optionsStructured) !== 'object') {
927
+ throw new Error("Invalid options argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object but got: ".concat(typeof optionsStructured === 'string' ? optionsStructured : JSON.stringify(optionsStructured)));
928
+ }
929
+ return {
930
+ functionName: functionName,
931
+ fullMatch: fullMatch,
932
+ urlArg: typeof _urlArg === 'string' ? _urlArg.trim() : String(_urlArg),
933
+ structuredVariants: hasGenerics ? structuredGenerics : undefined,
934
+ // Use generics as variants in metadata-only mode
935
+ optionsStructured: _typeof(optionsStructured) === 'object' && optionsStructured !== null ? optionsStructured : undefined,
936
+ hasOptions: true,
937
+ hasGenerics: hasGenerics,
938
+ structuredGenerics: structuredGenerics,
939
+ functionStartIndex: matchStartIndex,
940
+ functionEndIndex: endIndex,
941
+ argumentsStartIndex: parenIndex + 1,
942
+ argumentsEndIndex: endIndex
943
+ };
944
+ }
945
+ } else if (!metadataOnly && hasGenerics && structured.length === 1) {
946
+ // Generics-only mode (non-metadata): expect 1 argument (url) - use generics as variants
947
+ var _structured3 = _slicedToArray(structured, 1),
948
+ _urlArg2 = _structured3[0];
949
+ return {
950
+ functionName: functionName,
951
+ fullMatch: fullMatch,
952
+ urlArg: typeof _urlArg2 === 'string' ? _urlArg2.trim() : String(_urlArg2),
953
+ structuredVariants: undefined,
954
+ // No explicit variants, will use generics later
955
+ optionsStructured: undefined,
956
+ hasOptions: false,
957
+ hasGenerics: hasGenerics,
958
+ structuredGenerics: structuredGenerics,
959
+ functionStartIndex: matchStartIndex,
960
+ functionEndIndex: endIndex,
961
+ argumentsStartIndex: parenIndex + 1,
962
+ argumentsEndIndex: endIndex
963
+ };
964
+ } else if (!metadataOnly && structured.length >= 2) {
965
+ // Normal mode: expect 2-3 arguments (url, variants, options?)
966
+ if (structured.length === 2) {
967
+ var _structured4 = _slicedToArray(structured, 2),
968
+ _urlArg3 = _structured4[0],
969
+ secondArg = _structured4[1];
970
+ if (hasGenerics) {
971
+ // With generics: 2 arguments means (url, options) - use generics as variants
972
+ return {
832
973
  functionName: functionName,
833
974
  fullMatch: fullMatch,
834
975
  urlArg: typeof _urlArg3 === 'string' ? _urlArg3.trim() : String(_urlArg3),
835
- structuredVariants: _variantsStructured,
836
- optionsStructured: _typeof(_optionsStructured) === 'object' && _optionsStructured !== null ? _optionsStructured : undefined,
976
+ structuredVariants: undefined,
977
+ // Use generics
978
+ optionsStructured: _typeof(secondArg) === 'object' && secondArg !== null ? secondArg : undefined,
837
979
  hasOptions: true,
838
- // Options argument was provided
839
- functionStartIndex: startIndex,
980
+ hasGenerics: hasGenerics,
981
+ structuredGenerics: structuredGenerics,
982
+ functionStartIndex: matchStartIndex,
840
983
  functionEndIndex: endIndex,
841
984
  argumentsStartIndex: parenIndex + 1,
842
985
  argumentsEndIndex: endIndex
843
- });
986
+ };
987
+ }
988
+ // Without generics: 2 arguments means (url, variants) - use second arg as variants
989
+ return {
990
+ functionName: functionName,
991
+ fullMatch: fullMatch,
992
+ urlArg: typeof _urlArg3 === 'string' ? _urlArg3.trim() : String(_urlArg3),
993
+ structuredVariants: secondArg,
994
+ optionsStructured: undefined,
995
+ hasOptions: false,
996
+ hasGenerics: hasGenerics,
997
+ structuredGenerics: structuredGenerics,
998
+ functionStartIndex: matchStartIndex,
999
+ functionEndIndex: endIndex,
1000
+ argumentsStartIndex: parenIndex + 1,
1001
+ argumentsEndIndex: endIndex
1002
+ };
1003
+ }
1004
+ if (structured.length === 3) {
1005
+ var _structured5 = _slicedToArray(structured, 3),
1006
+ _urlArg4 = _structured5[0],
1007
+ variantsStructured = _structured5[1],
1008
+ _optionsStructured = _structured5[2];
1009
+
1010
+ // Options should be an object (Record<string, any>) or an empty object
1011
+ if (typeof _optionsStructured === 'string' || !Array.isArray(_optionsStructured) && _typeof(_optionsStructured) !== 'object') {
1012
+ throw new Error("Invalid options argument in ".concat(functionName, " call in ").concat(filePath, ". ") + "Expected an object but got: ".concat(typeof _optionsStructured === 'string' ? _optionsStructured : JSON.stringify(_optionsStructured)));
844
1013
  }
1014
+ return {
1015
+ functionName: functionName,
1016
+ fullMatch: fullMatch,
1017
+ urlArg: typeof _urlArg4 === 'string' ? _urlArg4.trim() : String(_urlArg4),
1018
+ structuredVariants: variantsStructured,
1019
+ optionsStructured: _typeof(_optionsStructured) === 'object' && _optionsStructured !== null ? _optionsStructured : undefined,
1020
+ hasOptions: true,
1021
+ // Options argument was provided
1022
+ hasGenerics: hasGenerics,
1023
+ structuredGenerics: structuredGenerics,
1024
+ functionStartIndex: matchStartIndex,
1025
+ functionEndIndex: endIndex,
1026
+ argumentsStartIndex: parenIndex + 1,
1027
+ argumentsEndIndex: endIndex
1028
+ };
845
1029
  }
846
- match = createFactoryRegex.exec(code);
847
1030
  }
848
- return results;
1031
+
1032
+ // Should not reach here due to validation above
1033
+ return null;
849
1034
  }