@immense/vue-pom-generator 1.0.77 → 1.0.78

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/dist/index.mjs CHANGED
@@ -9,7 +9,7 @@ import { parse as parse$1, compileScript } from "@vue/compiler-sfc";
9
9
  import { parseExpression, parse } from "@babel/parser";
10
10
  import { NodeTypes, stringifyExpression, ConstantTypes, createSimpleExpression, ElementTypes } from "@vue/compiler-core";
11
11
  import { Project, QuoteKind, NewLineKind, IndentationText, CodeBlockWriter, StructureKind, VariableDeclarationKind } from "ts-morph";
12
- import { isArrayExpression, isStringLiteral, isTemplateLiteral, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression, isIdentifier, isExpressionStatement, isObjectExpression, isFile, isArrowFunctionExpression, isBlockStatement, isLogicalExpression, isConditionalExpression, isSequenceExpression, isAssignmentPattern, isRestElement, isObjectPattern, isObjectProperty, isProgram, VISITOR_KEYS, isBooleanLiteral, isNumericLiteral, isNullLiteral } from "@babel/types";
12
+ import { isIdentifier, isObjectPattern, isRestElement, isObjectProperty, isArrayExpression, isStringLiteral, isTemplateLiteral, isArrowFunctionExpression, isExpressionStatement, isAssignmentPattern, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression, isObjectExpression, isFile, isBlockStatement, isLogicalExpression, isConditionalExpression, isSequenceExpression, isProgram, VISITOR_KEYS, isBooleanLiteral, isNumericLiteral, isNullLiteral } from "@babel/types";
13
13
  import { performance } from "node:perf_hooks";
14
14
  import vue from "@vitejs/plugin-vue";
15
15
  import { autoUpdate, computePosition, offset, autoPlacement, shift, arrow } from "@floating-ui/dom";
@@ -1478,6 +1478,31 @@ function tryGetTemplateSlotScopeKeyInfo(expression) {
1478
1478
  const candidateExpression = bindingNode ? tryGetSlotScopeKeyCandidate(bindingNode)?.expression ?? null : null;
1479
1479
  return candidateExpression ? toResolvedKeyInfo(candidateExpression) : null;
1480
1480
  }
1481
+ function tryExtractSlotScopeVariableNames(expression) {
1482
+ const bindingNode = tryGetTemplateSlotScopeBindingNode(expression);
1483
+ if (!bindingNode) {
1484
+ return [];
1485
+ }
1486
+ if (isIdentifier(bindingNode)) {
1487
+ return [bindingNode.name];
1488
+ }
1489
+ if (!isObjectPattern(bindingNode)) {
1490
+ return [];
1491
+ }
1492
+ const names = [];
1493
+ for (const property of bindingNode.properties) {
1494
+ if (isRestElement(property)) {
1495
+ const argName = tryGetBindingIdentifierName(property.argument);
1496
+ if (argName) names.push(argName);
1497
+ } else if (isObjectProperty(property)) {
1498
+ const bindingName = tryGetBindingIdentifierName(property.value) ?? tryGetBindingIdentifierName(property.key);
1499
+ if (bindingName) {
1500
+ names.push(bindingName);
1501
+ }
1502
+ }
1503
+ }
1504
+ return names;
1505
+ }
1481
1506
  function nodeHasToDirective(node) {
1482
1507
  const toDirective = findDirectiveByName(node, "bind", "to");
1483
1508
  if (toDirective?.exp) {
@@ -1660,12 +1685,21 @@ function getStaticIdOrNameHint(node) {
1660
1685
  return identifier;
1661
1686
  }
1662
1687
  function getContainedInSlotDataKeyInfo(node, hierarchyMap2) {
1688
+ const templateNode = getContainedInSlotTemplateNode(node, hierarchyMap2);
1689
+ if (templateNode) {
1690
+ const slotScopeExpression = findTemplateSlotScopeExpression(templateNode);
1691
+ if (slotScopeExpression) {
1692
+ return tryGetTemplateSlotScopeKeyInfo(slotScopeExpression);
1693
+ }
1694
+ }
1695
+ return null;
1696
+ }
1697
+ function getContainedInSlotTemplateNode(node, hierarchyMap2) {
1663
1698
  let parent = getParent(hierarchyMap2, node);
1664
1699
  while (parent) {
1665
1700
  if (parent.type === NodeTypes.ELEMENT && parent.tag === "template") {
1666
- const slotScopeExpression = findTemplateSlotScopeExpression(parent);
1667
- if (slotScopeExpression) {
1668
- return tryGetTemplateSlotScopeKeyInfo(slotScopeExpression);
1701
+ if (findTemplateSlotScopeExpression(parent)) {
1702
+ return parent;
1669
1703
  }
1670
1704
  }
1671
1705
  parent = getParent(hierarchyMap2, parent);
@@ -7218,6 +7252,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
7218
7252
  const vueFilesPathMap = options.vueFilesPathMap;
7219
7253
  const wrapperSearchRoots = options.wrapperSearchRoots ?? [];
7220
7254
  const annotatorMetadata = options.annotatorMetadata ?? null;
7255
+ const crossFileKeyRegistry = options.crossFileKeyRegistry;
7221
7256
  const safeRealpath2 = (p) => {
7222
7257
  try {
7223
7258
  return fs.existsSync(p) ? fs.realpathSync(p) : p;
@@ -7347,6 +7382,31 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
7347
7382
  };
7348
7383
  if (isComponentLikeTag(element.tag)) {
7349
7384
  dependencies.usedComponentSet.add(element.tag);
7385
+ if (crossFileKeyRegistry && context.scopes.vSlot > 0) {
7386
+ const findSlotTemplate = () => {
7387
+ const gp = context.grandParent;
7388
+ if (gp?.type === NodeTypes.ELEMENT && gp.tag === "template") {
7389
+ return gp;
7390
+ }
7391
+ return getContainedInSlotTemplateNode(element, hierarchyMap);
7392
+ };
7393
+ const slotTemplate = findSlotTemplate();
7394
+ if (slotTemplate) {
7395
+ const slotScopeExpression = findTemplateSlotScopeExpression(slotTemplate);
7396
+ if (slotScopeExpression) {
7397
+ const slotVarNames = tryExtractSlotScopeVariableNames(slotScopeExpression);
7398
+ if (slotVarNames.length > 0) {
7399
+ for (const prop of element.props) {
7400
+ if (prop.type === NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.exp?.type === NodeTypes.SIMPLE_EXPRESSION && slotVarNames.includes(prop.exp.content)) {
7401
+ const propName = prop.arg.content;
7402
+ crossFileKeyRegistry.set(element.tag, propName);
7403
+ break;
7404
+ }
7405
+ }
7406
+ }
7407
+ }
7408
+ }
7409
+ }
7350
7410
  }
7351
7411
  if (!nativeWrappers[element.tag]) {
7352
7412
  const inferred = tryInferNativeWrapperRoleFromSfc(element.tag, vueFilesPathMap, wrapperSearchRoots);
@@ -7365,7 +7425,18 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
7365
7425
  if (vForKeyInfo) {
7366
7426
  return vForKeyInfo;
7367
7427
  }
7368
- return getContainedInSlotDataKeyInfo(element, hierarchyMap);
7428
+ const slotKeyInfo = getContainedInSlotDataKeyInfo(element, hierarchyMap);
7429
+ if (slotKeyInfo) {
7430
+ return slotKeyInfo;
7431
+ }
7432
+ if (crossFileKeyRegistry) {
7433
+ const propName = crossFileKeyRegistry.get(componentName);
7434
+ if (propName) {
7435
+ const fallbackExpr = buildSlotScopeFallbackKeyExpression(propName);
7436
+ return toResolvedKeyInfo(fallbackExpr, fallbackExpr);
7437
+ }
7438
+ }
7439
+ return null;
7369
7440
  };
7370
7441
  const bestKeyInfo = getBestAvailableKeyInfo();
7371
7442
  const bestKeyPlaceholder = bestKeyInfo?.selectorFragment ?? null;
@@ -7713,6 +7784,7 @@ function isLessRich(candidate, previous) {
7713
7784
  function createBuildProcessorPlugin(options) {
7714
7785
  const {
7715
7786
  componentHierarchyMap,
7787
+ crossFileKeyRegistry,
7716
7788
  vueFilesPathMap,
7717
7789
  getPageDirs,
7718
7790
  getComponentDirs,
@@ -7855,7 +7927,8 @@ function createBuildProcessorPlugin(options) {
7855
7927
  missingSemanticNameBehavior,
7856
7928
  warn: (message) => loggerRef.current.warn(message),
7857
7929
  vueFilesPathMap,
7858
- wrapperSearchRoots: getWrapperSearchRoots()
7930
+ wrapperSearchRoots: getWrapperSearchRoots(),
7931
+ crossFileKeyRegistry
7859
7932
  }
7860
7933
  )
7861
7934
  ]
@@ -8178,6 +8251,7 @@ function createDevProcessorPlugin(options) {
8178
8251
  }
8179
8252
  const { bindings: bindingMetadata, isScriptSetup } = getScriptInfo(sfc, absolutePath);
8180
8253
  const provisionalHierarchy = /* @__PURE__ */ new Map();
8254
+ const provisionalKeyRegistry = /* @__PURE__ */ new Map();
8181
8255
  const provisionalVuePathMap = new Map(targetVuePathMap);
8182
8256
  provisionalVuePathMap.set(componentName, absolutePath);
8183
8257
  compilerDom.compile(template, {
@@ -8205,7 +8279,8 @@ function createDevProcessorPlugin(options) {
8205
8279
  testIdAttribute,
8206
8280
  warn: (message) => loggerRef.current.warn(message),
8207
8281
  vueFilesPathMap: provisionalVuePathMap,
8208
- wrapperSearchRoots: getWrapperSearchRoots()
8282
+ wrapperSearchRoots: getWrapperSearchRoots(),
8283
+ crossFileKeyRegistry: provisionalKeyRegistry
8209
8284
  }
8210
8285
  )
8211
8286
  ]
@@ -8729,6 +8804,7 @@ ${code}`,
8729
8804
  function createInternalPlugins(options) {
8730
8805
  const {
8731
8806
  componentHierarchyMap,
8807
+ crossFileKeyRegistry,
8732
8808
  elementMetadata,
8733
8809
  vueFilesPathMap,
8734
8810
  nativeWrappers,
@@ -8784,6 +8860,7 @@ function createInternalPlugins(options) {
8784
8860
  const normalizedBasePagePath = path.posix.normalize(basePageClassPath);
8785
8861
  const tsProcessor = createBuildProcessorPlugin({
8786
8862
  componentHierarchyMap,
8863
+ crossFileKeyRegistry,
8787
8864
  vueFilesPathMap,
8788
8865
  getPageDirs,
8789
8866
  getComponentDirs,
@@ -9009,6 +9086,7 @@ function createVuePluginWithTestIds(options) {
9009
9086
  elementMetadata,
9010
9087
  semanticNameMap,
9011
9088
  componentHierarchyMap,
9089
+ crossFileKeyRegistry,
9012
9090
  vueFilesPathMap,
9013
9091
  excludedComponents,
9014
9092
  getViewsDirAbs,
@@ -9078,7 +9156,8 @@ function createVuePluginWithTestIds(options) {
9078
9156
  warn: (message) => loggerRef.current.warn(message),
9079
9157
  vueFilesPathMap,
9080
9158
  wrapperSearchRoots: getWrapperSearchRoots(),
9081
- annotatorMetadata
9159
+ annotatorMetadata,
9160
+ crossFileKeyRegistry
9082
9161
  }
9083
9162
  )
9084
9163
  );
@@ -9134,7 +9213,8 @@ function createVuePluginWithTestIds(options) {
9134
9213
  warn: (message) => loggerRef.current.warn(message),
9135
9214
  vueFilesPathMap,
9136
9215
  wrapperSearchRoots: getWrapperSearchRoots(),
9137
- annotatorMetadata
9216
+ annotatorMetadata,
9217
+ crossFileKeyRegistry
9138
9218
  }
9139
9219
  );
9140
9220
  perFileTransform.set(componentName, transform);
@@ -9378,6 +9458,7 @@ function getSharedGeneratorState(key) {
9378
9458
  elementMetadata: /* @__PURE__ */ new Map(),
9379
9459
  semanticNameMap: /* @__PURE__ */ new Map(),
9380
9460
  componentHierarchyMap: /* @__PURE__ */ new Map(),
9461
+ crossFileKeyRegistry: /* @__PURE__ */ new Map(),
9381
9462
  vueFilesPathMap: /* @__PURE__ */ new Map()
9382
9463
  };
9383
9464
  sharedGeneratorStateRegistry.set(key, state);
@@ -9592,7 +9673,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9592
9673
  };
9593
9674
  const getViewsDirAbs = () => resolveFromProjectRoot(projectRootRef.current, getViewsDir());
9594
9675
  const getWrapperSearchRootsAbs = () => getWrapperSearchRoots().map((root) => resolveFromProjectRoot(projectRootRef.current, root));
9595
- const { elementMetadata, semanticNameMap, componentHierarchyMap, vueFilesPathMap } = sharedState;
9676
+ const { elementMetadata, semanticNameMap, componentHierarchyMap, crossFileKeyRegistry, vueFilesPathMap } = sharedState;
9596
9677
  const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions } = createVuePluginWithTestIds({
9597
9678
  vueOptions,
9598
9679
  existingIdBehavior: resolvedGenerationOptions.existingIdBehavior,
@@ -9602,6 +9683,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9602
9683
  elementMetadata,
9603
9684
  semanticNameMap,
9604
9685
  componentHierarchyMap,
9686
+ crossFileKeyRegistry,
9605
9687
  vueFilesPathMap,
9606
9688
  excludedComponents,
9607
9689
  getViewsDirAbs,
@@ -9619,6 +9701,7 @@ function createVuePomGeneratorPlugins(options = {}) {
9619
9701
  templateCompilerOptionsForResolvedPlugin = templateCompilerOptions;
9620
9702
  const internalPlugins = createInternalPlugins({
9621
9703
  componentHierarchyMap,
9704
+ crossFileKeyRegistry,
9622
9705
  elementMetadata,
9623
9706
  vueFilesPathMap,
9624
9707
  nativeWrappers,