@immense/vue-pom-generator 1.0.31 → 1.0.32

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
@@ -1818,6 +1818,12 @@ function applyResolvedDataTestId(args) {
1818
1818
  const existingIdBehavior = args.existingIdBehavior ?? "preserve";
1819
1819
  const nameCollisionBehavior = args.nameCollisionBehavior ?? "suffix";
1820
1820
  const warn = args.warn;
1821
+ const getBestKeyAccessCandidates = (expr) => {
1822
+ if (!expr) {
1823
+ return [];
1824
+ }
1825
+ return expr.split("??").map((part) => part.trim()).filter(Boolean);
1826
+ };
1821
1827
  let dataTestId = args.preferredGeneratedValue;
1822
1828
  let fromExisting = false;
1823
1829
  const existing = tryGetExistingElementDataTestId(args.element, testIdAttribute);
@@ -1840,6 +1846,7 @@ Bulk cleanup: run ESLint with the @immense/vue-pom-generator/remove-existing-tes
1840
1846
  if (existingIdBehavior === "preserve") {
1841
1847
  if (existing.isDynamic) {
1842
1848
  if (existing.template) {
1849
+ const existingTemplate = existing.template;
1843
1850
  if ((existing.templateExpressionCount ?? 0) !== 1) {
1844
1851
  throw new Error(
1845
1852
  `[vue-pom-generator] Existing ${attrLabel} is a template literal with multiple interpolations and cannot be preserved safely.
@@ -1850,8 +1857,8 @@ Existing ${attrLabel}: ${JSON.stringify(existing.value)}
1850
1857
  Fix: reduce the template to a single key-based interpolation, or remove the explicit ${attrLabel} so it can be auto-generated.`
1851
1858
  );
1852
1859
  }
1853
- const hasExact = args.bestKeyPlaceholder && existing.template.includes(args.bestKeyPlaceholder);
1854
- const hasVarAccess = args.bestKeyVariable && existing.template.includes(args.bestKeyVariable);
1860
+ const hasExact = args.bestKeyPlaceholder && existingTemplate.includes(args.bestKeyPlaceholder);
1861
+ const hasVarAccess = getBestKeyAccessCandidates(args.bestKeyVariable).some((candidate) => existingTemplate.includes(candidate));
1855
1862
  if (!hasExact && !hasVarAccess && args.bestKeyPlaceholder) {
1856
1863
  throw new Error(
1857
1864
  `[vue-pom-generator] Existing ${attrLabel} appears to be missing the key placeholder needed to keep it unique.
@@ -3842,14 +3849,18 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
3842
3849
  }
3843
3850
  return false;
3844
3851
  };
3852
+ const customPomClassIdentifierMap = options.customPomClassIdentifierMap ?? {};
3853
+ const customPomAvailableClassIdentifiers = options.customPomAvailableClassIdentifiers ?? /* @__PURE__ */ new Set();
3845
3854
  const attachmentsForThisClass = customPomAttachments.filter((a) => {
3855
+ if (!Object.prototype.hasOwnProperty.call(customPomClassIdentifierMap, a.className))
3856
+ return false;
3846
3857
  const scope = a.attachTo ?? "views";
3847
3858
  const scopeOk = isView ? scope === "views" || scope === "both" : scope === "components" || scope === "both";
3848
3859
  if (!scopeOk)
3849
3860
  return false;
3850
3861
  return a.attachWhenUsesComponents.some((c) => hasChildComponent(c));
3851
3862
  }).map((a) => ({
3852
- className: options.customPomClassIdentifierMap?.[a.className] ?? a.className,
3863
+ className: customPomClassIdentifierMap[a.className],
3853
3864
  propertyName: a.propertyName
3854
3865
  }));
3855
3866
  let content = "";
@@ -3889,7 +3900,7 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
3889
3900
  content += `
3890
3901
  export class ${className} extends BasePage {
3891
3902
  `;
3892
- const widgetInstances = isView ? getWidgetInstancesForView(componentName, dependencies.dataTestIdSet) : [];
3903
+ const widgetInstances = isView ? getWidgetInstancesForView(componentName, dependencies.dataTestIdSet, customPomAvailableClassIdentifiers) : [];
3893
3904
  const componentRefsForInstances = isView ? usedComponentSet?.size ? usedComponentSet : childrenComponentSet : childrenComponentSet;
3894
3905
  if (isView && (componentRefsForInstances.size > 0 || attachmentsForThisClass.length > 0 || widgetInstances.length > 0)) {
3895
3906
  content += getComponentInstances(componentRefsForInstances, componentHierarchyMap, attachmentsForThisClass, widgetInstances);
@@ -4047,6 +4058,7 @@ Fix by setting generation.playwright.customPoms.importAliases["${exportName}"] t
4047
4058
  return customPomClassIdentifierMap2;
4048
4059
  };
4049
4060
  const customPomClassIdentifierMap = addCustomPomImports();
4061
+ const customPomAvailableClassIdentifiers = new Set(Object.values(customPomClassIdentifierMap ?? {}));
4050
4062
  const referencedTargets = /* @__PURE__ */ new Set();
4051
4063
  for (const [, deps] of items) {
4052
4064
  for (const dt of deps.dataTestIdSet) {
@@ -4199,6 +4211,7 @@ Fix by setting generation.playwright.customPoms.importAliases["${exportName}"] t
4199
4211
  aggregated: true,
4200
4212
  customPomAttachments: options.customPomAttachments ?? [],
4201
4213
  customPomClassIdentifierMap,
4214
+ customPomAvailableClassIdentifiers,
4202
4215
  testIdAttribute: options.testIdAttribute,
4203
4216
  vueRouterFluentChaining: options.vueRouterFluentChaining,
4204
4217
  routeMetaByComponent: options.routeMetaByComponent
@@ -4293,7 +4306,7 @@ function toPascalCaseLocal(str) {
4293
4306
  return preserveInternalCaps ? upperFirst(word) : upperFirst(word.toLowerCase());
4294
4307
  }).join("");
4295
4308
  }
4296
- function getWidgetInstancesForView(componentName, dataTestIdSet) {
4309
+ function getWidgetInstancesForView(componentName, dataTestIdSet, availableClassIdentifiers) {
4297
4310
  const out = [];
4298
4311
  const usedPropNames = /* @__PURE__ */ new Set();
4299
4312
  const ensureUnique = (base) => {
@@ -4324,6 +4337,8 @@ function getWidgetInstancesForView(componentName, dataTestIdSet) {
4324
4337
  } else {
4325
4338
  continue;
4326
4339
  }
4340
+ if (!availableClassIdentifiers.has(className))
4341
+ continue;
4327
4342
  const viewPrefix = `${componentName}-`;
4328
4343
  const descriptorRaw = stem.startsWith(viewPrefix) ? stem.slice(viewPrefix.length) : stem;
4329
4344
  const descriptorPascal = toPascalCaseLocal(descriptorRaw);