@immense/vue-pom-generator 1.0.94 → 1.0.96

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.cjs CHANGED
@@ -2942,18 +2942,18 @@ function safeMethodNameFromParts(parts) {
2942
2942
  }
2943
2943
  return name;
2944
2944
  }
2945
- function toPomKeyPattern(templateValue) {
2945
+ function toPomKeyPattern(templateValue, parameterName = "key") {
2946
2946
  const { templateLiteral } = templateValue.parsedTemplate;
2947
2947
  let out = "";
2948
2948
  let hasExpression = false;
2949
2949
  for (let i = 0; i < templateLiteral.quasis.length; i += 1) {
2950
2950
  out += templateLiteral.quasis[i]?.value.raw ?? "";
2951
2951
  if (templateLiteral.expressions[i]) {
2952
- out += "${key}";
2952
+ out += `\${${parameterName}}`;
2953
2953
  hasExpression = true;
2954
2954
  }
2955
2955
  }
2956
- return { formatted: out, templateVariables: hasExpression ? ["key"] : [] };
2956
+ return { formatted: out, templateVariables: hasExpression ? [parameterName] : [] };
2957
2957
  }
2958
2958
  function applyResolvedDataTestId(args) {
2959
2959
  const addHtmlAttribute = args.addHtmlAttribute ?? true;
@@ -3078,7 +3078,8 @@ Fix: either (1) include ${bestKeyPreservePlaceholder} in your :${attrLabel} temp
3078
3078
  };
3079
3079
  const normalizedRole = normalizeNativeRole(args.nativeRole) ?? "button";
3080
3080
  const targetPageObjectModelClass = entryOverrides.targetPageObjectModelClass;
3081
- const pomKeyPattern = dataTestId.kind === "template" ? toPomKeyPattern(dataTestId) : null;
3081
+ const selectorParameterName = args.selectorParameterName?.trim() || "key";
3082
+ const pomKeyPattern = dataTestId.kind === "template" ? toPomKeyPattern(dataTestId, selectorParameterName) : null;
3082
3083
  const formattedDataTestIdForPom = dataTestId.kind === "template" ? pomKeyPattern.formatted : dataTestId.value;
3083
3084
  const selectorPatternKind = dataTestId.kind === "template" ? "parameterized" : "static";
3084
3085
  const selectorTemplateVariables = dataTestId.kind === "template" ? pomKeyPattern.templateVariables : [];
@@ -3224,8 +3225,11 @@ Fix: either (1) include ${bestKeyPreservePlaceholder} in your :${attrLabel} temp
3224
3225
  existingPom.alternateSelectors.push(selectorPattern);
3225
3226
  }
3226
3227
  }
3227
- if (selectorIsParameterized && !existingPom.parameters.some((param) => param.name === "key")) {
3228
- existingPom.parameters = [createPomParameterSpec("key", keyTypeFromValues), ...existingPom.parameters];
3228
+ if (selectorIsParameterized && !existingPom.parameters.some((param) => param.name === selectorParameterName)) {
3229
+ existingPom.parameters = [
3230
+ createPomParameterSpec(selectorParameterName, keyTypeFromValues),
3231
+ ...existingPom.parameters
3232
+ ];
3229
3233
  }
3230
3234
  return true;
3231
3235
  };
@@ -3239,7 +3243,8 @@ Fix: either (1) include ${bestKeyPreservePlaceholder} in your :${attrLabel} temp
3239
3243
  let suffix = 1;
3240
3244
  while (true) {
3241
3245
  const baseWithSuffix = suffix === 1 ? base : `${base}${suffix}`;
3242
- const candidate = selectorIsParameterized ? `${baseWithSuffix}ByKey` : baseWithSuffix;
3246
+ const parameterizedSuffix = `By${upperFirst(selectorParameterName)}`;
3247
+ const candidate = selectorIsParameterized ? normalizedRole === "radio" && selectorParameterName !== "key" ? parameterizedSuffix : `${baseWithSuffix}${parameterizedSuffix}` : baseWithSuffix;
3243
3248
  const actionName = getPrimaryActionMethodName(candidate);
3244
3249
  const getterCandidates = getPrimaryGetterNameCandidates(candidate);
3245
3250
  let chosenGetterName = getterCandidates.primary;
@@ -3265,7 +3270,7 @@ Fix: either (1) include ${bestKeyPreservePlaceholder} in your :${attrLabel} temp
3265
3270
  const baseNameUpper = upperFirst(baseWithSuffix);
3266
3271
  if (!hasRoleSuffix(baseNameUpper, roleSuffix)) {
3267
3272
  const baseWithRoleSuffix = `${baseWithSuffix}${roleSuffix}`;
3268
- const candidateWithRoleSuffix = selectorIsParameterized ? `${baseWithRoleSuffix}ByKey` : baseWithRoleSuffix;
3273
+ const candidateWithRoleSuffix = selectorIsParameterized ? `${baseWithRoleSuffix}By${upperFirst(selectorParameterName)}` : baseWithRoleSuffix;
3269
3274
  const actionNameWithRoleSuffix = getPrimaryActionMethodName(candidateWithRoleSuffix);
3270
3275
  const getterCandidatesWithRoleSuffix = getPrimaryGetterNameCandidates(candidateWithRoleSuffix);
3271
3276
  let chosenGetterNameWithRoleSuffix = getterCandidatesWithRoleSuffix.primary;
@@ -3333,7 +3338,7 @@ Conflicts: getter=${last.getterName}, method=${last.actionName}
3333
3338
  Fix: make the element identifiable (e.g. add id/name/inner text or use a more specific click handler name), or switch generation.nameCollisionBehavior to "warn"/"suffix".`
3334
3339
  );
3335
3340
  }
3336
- let parameters = selectorIsParameterized ? [createPomParameterSpec("key", keyTypeFromValues)] : [];
3341
+ let parameters = selectorIsParameterized ? [createPomParameterSpec(selectorParameterName, keyTypeFromValues)] : [];
3337
3342
  switch (normalizedRole) {
3338
3343
  case "input":
3339
3344
  parameters = setPomParameter(parameters, "text", "string");
@@ -3352,7 +3357,7 @@ Fix: make the element identifiable (e.g. add id/name/inner text or use a more sp
3352
3357
  parameters = setPomParameter(parameters, "annotationText", 'string = ""');
3353
3358
  break;
3354
3359
  }
3355
- const normalizedParameters = selectorIsParameterized ? setPomParameter(parameters, "key", keyTypeFromValues) : removePomParameter(parameters, "key");
3360
+ const normalizedParameters = selectorIsParameterized ? setPomParameter(parameters, selectorParameterName, keyTypeFromValues) : removePomParameter(parameters, selectorParameterName);
3356
3361
  if (addHtmlAttribute && !fromExisting) {
3357
3362
  upsertAttribute(args.element, testIdAttribute, dataTestId);
3358
3363
  }
@@ -6509,21 +6514,116 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
6509
6514
  const nestedRefs = resolvedDependencies.usedComponentSet?.size ? resolvedDependencies.usedComponentSet : resolvedDependencies.childrenComponentSet;
6510
6515
  return Array.from(nestedRefs).some((child) => hasGeneratedPomSurface(child, nextSeen));
6511
6516
  };
6512
- const rawComponentRefsForInstances = usedComponentSet?.size ? usedComponentSet : childrenComponentSet;
6513
6517
  const ownClassName = toPascalCaseLocal(componentName);
6514
6518
  const isSelfReference = (ref) => {
6515
6519
  return toPascalCaseLocal(normalizeTrackedComponentRef(ref)) === ownClassName && ownClassName.length > 0;
6516
6520
  };
6517
- const componentRefsForInstances = /* @__PURE__ */ new Set();
6518
- for (const ref of rawComponentRefsForInstances) {
6519
- const resolvedRef = resolveTrackedComponentRef(ref) ?? normalizeTrackedComponentRef(ref);
6520
- if (isSelfReference(resolvedRef)) {
6521
- continue;
6521
+ const resolveComponentInstance = (spec) => {
6522
+ const componentRef = resolveTrackedComponentRef(spec.componentName);
6523
+ if (!componentRef || isSelfReference(componentRef) || !hasGeneratedPomSurface(componentRef, /* @__PURE__ */ new Set([componentName]))) {
6524
+ return null;
6525
+ }
6526
+ return {
6527
+ ...spec,
6528
+ componentRef,
6529
+ className: normalizeTrackedComponentRef(componentRef)
6530
+ };
6531
+ };
6532
+ const uniqueInstances = (instances, ownerName) => {
6533
+ const byPublicName = /* @__PURE__ */ new Map();
6534
+ for (const instance of instances) {
6535
+ const existing = byPublicName.get(instance.instanceName);
6536
+ if (!existing) {
6537
+ byPublicName.set(instance.instanceName, instance);
6538
+ continue;
6539
+ }
6540
+ const sameInvocationShape = existing.componentRef === instance.componentRef && JSON.stringify(existing.selector) === JSON.stringify(instance.selector) && JSON.stringify(existing.parameters) === JSON.stringify(instance.parameters);
6541
+ if (sameInvocationShape) {
6542
+ continue;
6543
+ }
6544
+ throw new VuePomGeneratorError(
6545
+ `Semantic component instance name ${JSON.stringify(instance.instanceName)} is ambiguous in ${ownerName}.
6546
+ It refers to both <${existing.componentName}> and <${instance.componentName}>.
6547
+
6548
+ Fix: give the invocations distinct accessible names or distinct semantic model/options bindings.`
6549
+ );
6522
6550
  }
6523
- if (!hasGeneratedPomSurface(resolvedRef, /* @__PURE__ */ new Set([componentName]))) {
6551
+ return Array.from(byPublicName.values());
6552
+ };
6553
+ const allInvocationSpecs = dependencies.componentInstances ?? [];
6554
+ const directComponentInstances = uniqueInstances(
6555
+ allInvocationSpecs.filter((spec) => !spec.suppliedSlot).map(resolveComponentInstance).filter((instance) => !!instance),
6556
+ componentName
6557
+ );
6558
+ const projectedComponentInstances = [];
6559
+ for (const owner of directComponentInstances) {
6560
+ const ownerDependencies = componentHierarchyMap.get(owner.componentRef);
6561
+ if (!ownerDependencies?.slotOutlets?.length) {
6524
6562
  continue;
6525
6563
  }
6526
- componentRefsForInstances.add(resolvedRef);
6564
+ const suppliedBySlot = /* @__PURE__ */ new Map();
6565
+ for (const suppliedSpec of allInvocationSpecs) {
6566
+ if (suppliedSpec.suppliedSlot?.ownerSourceId !== owner.sourceId) {
6567
+ continue;
6568
+ }
6569
+ const supplied = resolveComponentInstance(suppliedSpec);
6570
+ if (!supplied) {
6571
+ continue;
6572
+ }
6573
+ const values = suppliedBySlot.get(suppliedSpec.suppliedSlot.name) ?? [];
6574
+ values.push(supplied);
6575
+ suppliedBySlot.set(suppliedSpec.suppliedSlot.name, values);
6576
+ }
6577
+ for (const [slotName, rawContents] of suppliedBySlot) {
6578
+ const outletTargetIds = new Set(
6579
+ ownerDependencies.slotOutlets.filter((outlet) => outlet.name === slotName).map((outlet) => outlet.targetSourceId)
6580
+ );
6581
+ const targetInstances = uniqueInstances(
6582
+ (ownerDependencies.componentInstances ?? []).filter((spec) => outletTargetIds.has(spec.sourceId)).map(resolveComponentInstance).filter((instance) => !!instance),
6583
+ `${owner.className} slot ${JSON.stringify(slotName)}`
6584
+ );
6585
+ const contents = uniqueInstances(rawContents, `${componentName} slot ${JSON.stringify(slotName)}`);
6586
+ for (const target of targetInstances) {
6587
+ if (owner.parameters.length > 0) {
6588
+ throw new VuePomGeneratorError(
6589
+ `Cannot project slot ${JSON.stringify(slotName)} through keyed component instance ${owner.instanceName} in ${componentName}.
6590
+ The owner and projected target require distinct key scopes, which cannot be represented by one unambiguous generated accessor.`
6591
+ );
6592
+ }
6593
+ const keyedContent = contents.find((content) => content.parameters.length > 0);
6594
+ if (keyedContent) {
6595
+ throw new VuePomGeneratorError(
6596
+ `Cannot attach keyed slot content ${keyedContent.instanceName} as a property of ${target.instanceName} in ${componentName}.
6597
+ Move the repetition to the receiving component boundary so the generator can expose it as a keyed accessor.`
6598
+ );
6599
+ }
6600
+ const existingProjection = projectedComponentInstances.find((projection) => {
6601
+ return projection.owner.sourceId === owner.sourceId && projection.target.instanceName === target.instanceName && projection.target.componentRef === target.componentRef && JSON.stringify(projection.target.selector) === JSON.stringify(target.selector);
6602
+ });
6603
+ if (existingProjection) {
6604
+ existingProjection.contents = uniqueInstances(
6605
+ [...existingProjection.contents, ...contents],
6606
+ `${componentName} projected ${target.instanceName}`
6607
+ );
6608
+ continue;
6609
+ }
6610
+ projectedComponentInstances.push({ owner, target, contents });
6611
+ }
6612
+ }
6613
+ }
6614
+ const rawComponentRefsForInstances = usedComponentSet?.size ? usedComponentSet : childrenComponentSet;
6615
+ const componentRefsForInstances = /* @__PURE__ */ new Set();
6616
+ for (const instance of directComponentInstances) {
6617
+ if (!isSelfReference(instance.componentRef)) {
6618
+ componentRefsForInstances.add(instance.componentRef);
6619
+ }
6620
+ }
6621
+ for (const projection of projectedComponentInstances) {
6622
+ for (const instance of [projection.owner, projection.target, ...projection.contents]) {
6623
+ if (!isSelfReference(instance.componentRef)) {
6624
+ componentRefsForInstances.add(instance.componentRef);
6625
+ }
6626
+ }
6527
6627
  }
6528
6628
  const hasChildComponent = (needle) => {
6529
6629
  const normalizedNeedle = normalizeTrackedComponentRef(needle);
@@ -6564,7 +6664,19 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
6564
6664
  }));
6565
6665
  const widgetInstances = isView ? getWidgetInstancesForView(componentName, dependencies.dataTestIdSet, customPomAvailableClassIdentifiers) : [];
6566
6666
  const className = toPascalCaseLocal(componentName);
6567
- const childInstancePropertyNames = Array.from(componentRefsForInstances).map((child) => child.split(".vue")[0]);
6667
+ const childInstancePropertyNames = [
6668
+ ...directComponentInstances.map((instance) => instance.instanceName),
6669
+ ...projectedComponentInstances.map((projection) => projection.target.instanceName)
6670
+ ];
6671
+ const duplicateChildInstanceName = childInstancePropertyNames.find((name, index) => {
6672
+ return childInstancePropertyNames.indexOf(name) !== index;
6673
+ });
6674
+ if (duplicateChildInstanceName) {
6675
+ throw new VuePomGeneratorError(
6676
+ `Semantic component instance ${JSON.stringify(duplicateChildInstanceName)} would be emitted more than once in ${componentName}.
6677
+ Fix: give direct and slot-projected instances distinct accessible names or semantic bindings.`
6678
+ );
6679
+ }
6568
6680
  const blockedViewPassthroughMethodNames = new Set(
6569
6681
  attachmentsForThisClass.filter((a) => a.flatten).flatMap((a) => Array.from(a.methodSignatures.keys()))
6570
6682
  );
@@ -6575,22 +6687,22 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
6575
6687
  ]);
6576
6688
  const members = [];
6577
6689
  if (isView && (componentRefsForInstances.size > 0 || attachmentsForThisClass.length > 0 || widgetInstances.length > 0)) {
6578
- members.push(...getComponentInstances(componentRefsForInstances, componentHierarchyMap, attachmentsForThisClass, widgetInstances));
6579
- members.push(getConstructor(componentRefsForInstances, componentHierarchyMap, attachmentsForThisClass, widgetInstances, { testIdAttribute }));
6690
+ members.push(...getComponentInstances(directComponentInstances, projectedComponentInstances, attachmentsForThisClass, widgetInstances));
6691
+ members.push(getConstructor(directComponentInstances, attachmentsForThisClass, widgetInstances, { testIdAttribute }));
6580
6692
  }
6581
6693
  if (!isView && (componentRefsForInstances.size > 0 || attachmentsForThisClass.length > 0)) {
6582
- members.push(...getComponentInstances(componentRefsForInstances, componentHierarchyMap, attachmentsForThisClass));
6583
- members.push(getConstructor(componentRefsForInstances, componentHierarchyMap, attachmentsForThisClass, [], { testIdAttribute }));
6694
+ members.push(...getComponentInstances(directComponentInstances, projectedComponentInstances, attachmentsForThisClass));
6695
+ members.push(getConstructor(directComponentInstances, attachmentsForThisClass, [], { testIdAttribute }));
6584
6696
  }
6585
6697
  members.push(
6586
6698
  ...getAttachmentPassthroughMethods(componentName, dependencies, attachmentsForThisClass, reservedAttachmentPassthroughNames)
6587
6699
  );
6588
- if (isView && componentRefsForInstances.size === 1) {
6700
+ if (isView && directComponentInstances.length === 1) {
6589
6701
  members.push(
6590
6702
  ...getViewPassthroughMethods(
6591
6703
  componentName,
6592
6704
  dependencies,
6593
- componentRefsForInstances,
6705
+ directComponentInstances,
6594
6706
  componentHierarchyMap,
6595
6707
  blockedViewPassthroughMethodNames
6596
6708
  )
@@ -6605,6 +6717,8 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
6605
6717
  return {
6606
6718
  className,
6607
6719
  componentRefsForInstances,
6720
+ directComponentInstances,
6721
+ projectedComponentInstances,
6608
6722
  attachmentsForThisClass,
6609
6723
  widgetInstances,
6610
6724
  isView,
@@ -6680,7 +6794,10 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
6680
6794
  addNamedImport(sourceFile, {
6681
6795
  moduleSpecifier: "@playwright/test",
6682
6796
  isTypeOnly: true,
6683
- namedImports: [{ name: "Page", alias: "PwPage" }]
6797
+ namedImports: [
6798
+ { name: "Locator", alias: "PwLocator" },
6799
+ { name: "Page", alias: "PwPage" }
6800
+ ]
6684
6801
  });
6685
6802
  }
6686
6803
  addNamedImport(sourceFile, {
@@ -6709,17 +6826,17 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
6709
6826
  }
6710
6827
  }, { prefixText });
6711
6828
  }
6712
- function getViewPassthroughMethods(viewName, viewDependencies, childrenComponentSet, componentHierarchyMap, blockedMethodNames = /* @__PURE__ */ new Set()) {
6829
+ function getViewPassthroughMethods(viewName, viewDependencies, componentInstances, componentHierarchyMap, blockedMethodNames = /* @__PURE__ */ new Set()) {
6713
6830
  const existingOnView = viewDependencies.generatedMethods ?? /* @__PURE__ */ new Map();
6714
6831
  const methodToChildren = /* @__PURE__ */ new Map();
6715
- for (const child of childrenComponentSet) {
6716
- const childDeps = componentHierarchyMap.get(child);
6832
+ for (const instance of componentInstances) {
6833
+ const childDeps = componentHierarchyMap.get(instance.componentRef);
6717
6834
  if (!childDeps || !childDeps.dataTestIdSet?.size)
6718
6835
  continue;
6719
6836
  const methods = childDeps.generatedMethods;
6720
6837
  if (!methods)
6721
6838
  continue;
6722
- const childProp = child.endsWith(".vue") ? child.slice(0, -4) : child;
6839
+ const childProp = instance.instanceName;
6723
6840
  for (const [name, sig] of methods.entries()) {
6724
6841
  if (!sig)
6725
6842
  continue;
@@ -7409,7 +7526,7 @@ function getWidgetInstancesForView(componentName, dataTestIdSet, availableClassI
7409
7526
  }
7410
7527
  return out;
7411
7528
  }
7412
- function getComponentInstances(childrenComponent, componentHierarchyMap, attachmentsForThisView = [], widgetInstances = []) {
7529
+ function getComponentInstances(componentInstances, projectedComponentInstances, attachmentsForThisView = [], widgetInstances = []) {
7413
7530
  const declarations = [];
7414
7531
  for (const a of attachmentsForThisView) {
7415
7532
  declarations.push(createClassProperty({
@@ -7423,35 +7540,80 @@ function getComponentInstances(childrenComponent, componentHierarchyMap, attachm
7423
7540
  type: w.className
7424
7541
  }));
7425
7542
  }
7426
- childrenComponent.forEach((child) => {
7427
- if (componentHierarchyMap.has(child)) {
7428
- const childName = child.split(".vue")[0];
7543
+ for (const instance of componentInstances) {
7544
+ if (instance.parameters.length === 0) {
7429
7545
  declarations.push(createClassProperty({
7430
- name: childName,
7431
- type: childName
7546
+ name: instance.instanceName,
7547
+ type: instance.className
7432
7548
  }));
7549
+ continue;
7433
7550
  }
7434
- });
7551
+ declarations.push(createClassMethod({
7552
+ name: instance.instanceName,
7553
+ parameters: toTypeScriptPomParameterStructures(instance.parameters),
7554
+ returnType: instance.className,
7555
+ statements: (writer) => {
7556
+ writer.writeLine(`const root = this.componentInstanceLocator(${toTypeScriptPomPatternExpression(instance.selector)});`);
7557
+ writer.writeLine(`return new ${instance.className}(this.page, root);`);
7558
+ }
7559
+ }));
7560
+ }
7561
+ for (const projection of projectedComponentInstances) {
7562
+ const projectedPropertiesType = projection.contents.length > 0 ? ` & { ${projection.contents.map((content) => `readonly ${content.instanceName}: ${content.className}`).join("; ")} }` : "";
7563
+ const statements = (writer) => {
7564
+ const ownerSelector = toTypeScriptPomPatternExpression(projection.owner.selector);
7565
+ const targetSelector = toTypeScriptPomPatternExpression(projection.target.selector);
7566
+ writer.writeLine(`const ownerRoot = this.componentInstanceLocator(${ownerSelector});`);
7567
+ writer.writeLine(`const root = this.componentInstanceLocator(${targetSelector}, ownerRoot);`);
7568
+ writer.writeLine(`const instance = new ${projection.target.className}(this.page, root);`);
7569
+ if (projection.contents.length === 0) {
7570
+ writer.writeLine("return instance;");
7571
+ return;
7572
+ }
7573
+ writer.writeLine("return Object.assign(instance, {");
7574
+ writer.indent(() => {
7575
+ for (const content of projection.contents) {
7576
+ const contentSelector = toTypeScriptPomPatternExpression(content.selector);
7577
+ writer.writeLine(`${content.instanceName}: new ${content.className}(this.page, this.componentInstanceLocator(${contentSelector}, root)),`);
7578
+ }
7579
+ });
7580
+ writer.writeLine("});");
7581
+ };
7582
+ const returnType = `${projection.target.className}${projectedPropertiesType}`;
7583
+ declarations.push(projection.target.parameters.length > 0 ? createClassMethod({
7584
+ name: projection.target.instanceName,
7585
+ parameters: toTypeScriptPomParameterStructures(projection.target.parameters),
7586
+ returnType,
7587
+ statements
7588
+ }) : createClassGetter({
7589
+ name: projection.target.instanceName,
7590
+ returnType,
7591
+ statements
7592
+ }));
7593
+ }
7435
7594
  return declarations;
7436
7595
  }
7437
- function getConstructor(childrenComponent, componentHierarchyMap, attachmentsForThisView = [], widgetInstances = [], options) {
7596
+ function getConstructor(componentInstances, attachmentsForThisView = [], widgetInstances = [], options) {
7438
7597
  const attr = (options?.testIdAttribute ?? "data-testid").trim() || "data-testid";
7439
7598
  return createClassConstructor({
7440
- parameters: [{ name: "page", type: "PwPage" }],
7599
+ parameters: [
7600
+ { name: "page", type: "PwPage" },
7601
+ { name: "root", type: "PwLocator", hasQuestionToken: true }
7602
+ ],
7441
7603
  statements: (writer) => {
7442
- writer.writeLine(`super(page, { testIdAttribute: ${JSON.stringify(attr)} });`);
7604
+ writer.writeLine(`super(page, { root, testIdAttribute: ${JSON.stringify(attr)} });`);
7443
7605
  for (const a of attachmentsForThisView) {
7444
7606
  writer.writeLine(`this.${a.propertyName} = new ${a.className}(this.page, this);`);
7445
7607
  }
7446
7608
  for (const w of widgetInstances) {
7447
7609
  writer.writeLine(`this.${w.propertyName} = new ${w.className}(this.page, ${JSON.stringify(w.testId)});`);
7448
7610
  }
7449
- childrenComponent.forEach((child) => {
7450
- if (componentHierarchyMap.has(child)) {
7451
- const childName = child.split(".vue")[0];
7452
- writer.writeLine(`this.${childName} = new ${childName}(page);`);
7611
+ for (const instance of componentInstances) {
7612
+ if (instance.parameters.length === 0) {
7613
+ const selector = toTypeScriptPomPatternExpression(instance.selector);
7614
+ writer.writeLine(`this.${instance.instanceName} = new ${instance.className}(page, this.componentInstanceLocator(${selector}));`);
7453
7615
  }
7454
- });
7616
+ }
7455
7617
  }
7456
7618
  });
7457
7619
  }
@@ -8000,7 +8162,7 @@ function getStaticAttributeContent$1(element, name) {
8000
8162
  });
8001
8163
  return attribute?.value?.content?.trim() || null;
8002
8164
  }
8003
- function mapExplicitAriaRole(role) {
8165
+ function mapExplicitAriaRole(role, elementTag) {
8004
8166
  switch (role.toLowerCase()) {
8005
8167
  case "button":
8006
8168
  case "checkbox":
@@ -8012,6 +8174,7 @@ function mapExplicitAriaRole(role) {
8012
8174
  case "radiogroup":
8013
8175
  return "radio";
8014
8176
  case "combobox":
8177
+ return elementTag === "input" || elementTag === "uinput" ? "input" : "select";
8015
8178
  case "listbox":
8016
8179
  return "select";
8017
8180
  case "searchbox":
@@ -8033,11 +8196,11 @@ function hasAttribute(element, name) {
8033
8196
  });
8034
8197
  }
8035
8198
  function getElementControlRole(element) {
8199
+ const tag = element.tag.toLowerCase();
8036
8200
  const explicitRole = getStaticAttributeContent$1(element, "role");
8037
8201
  if (explicitRole) {
8038
- return mapExplicitAriaRole(explicitRole);
8202
+ return mapExplicitAriaRole(explicitRole, tag);
8039
8203
  }
8040
- const tag = element.tag.toLowerCase();
8041
8204
  const type = (getStaticAttributeContent$1(element, "type") || "").toLowerCase();
8042
8205
  if (tag === "input" || tag === "uinput") {
8043
8206
  if (type === "radio") {
@@ -8226,6 +8389,92 @@ function resolveWrapperContractForTag(options) {
8226
8389
  return resolveTag(options.tag);
8227
8390
  }
8228
8391
  const CLICK_EVENT_NAME = TESTID_CLICK_EVENT_NAME;
8392
+ const POM_INSTANCE_ATTRIBUTE = "data-pom-instance";
8393
+ function getLastSemanticIdentifier(node) {
8394
+ if (!node) {
8395
+ return null;
8396
+ }
8397
+ if (node.type === "Identifier") {
8398
+ return node.name?.trim() || null;
8399
+ }
8400
+ if (node.type === "MemberExpression" || node.type === "OptionalMemberExpression") {
8401
+ if (!node.computed && node.property?.type === "Identifier") {
8402
+ return node.property.name?.trim() || null;
8403
+ }
8404
+ if (node.computed && node.property?.type === "StringLiteral") {
8405
+ return node.property.value?.trim() || null;
8406
+ }
8407
+ return getLastSemanticIdentifier(node.object);
8408
+ }
8409
+ if (node.type === "CallExpression" || node.type === "OptionalCallExpression") {
8410
+ return getLastSemanticIdentifier(node.callee);
8411
+ }
8412
+ if (node.type === "TSAsExpression" || node.type === "TSTypeAssertion" || node.type === "TSNonNullExpression" || node.type === "ChainExpression") {
8413
+ return getLastSemanticIdentifier(node.expression);
8414
+ }
8415
+ return null;
8416
+ }
8417
+ function getBoundSemanticName(element, attributeName) {
8418
+ const directive = element.props.find((prop) => {
8419
+ return prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === attributeName && !!prop.exp;
8420
+ });
8421
+ if (!directive?.exp) {
8422
+ return null;
8423
+ }
8424
+ const source = getVueExpressionSource(
8425
+ directive.exp,
8426
+ "loc",
8427
+ "content",
8428
+ "compiled"
8429
+ );
8430
+ if (!source) {
8431
+ return null;
8432
+ }
8433
+ try {
8434
+ const identifier = getLastSemanticIdentifier(parser.parseExpression(source, { plugins: ["typescript"] }));
8435
+ return identifier ? toPascalCase(identifier) : null;
8436
+ } catch {
8437
+ return null;
8438
+ }
8439
+ }
8440
+ function getComponentInstanceNameCandidates(element) {
8441
+ const explicitAccessibleNames = ["aria-label", "label", "title", "name"].map((attributeName) => getStaticAttributeContent(element, attributeName)).filter((value) => !!value).map(toPascalCase);
8442
+ const optionsName = getBoundSemanticName(element, "options");
8443
+ const { vModel, modelValue } = getModelBindingValues(element);
8444
+ const modelName = modelValue || vModel;
8445
+ const candidates = [
8446
+ ...explicitAccessibleNames,
8447
+ optionsName && optionsName !== "Options" ? optionsName : null,
8448
+ modelName && !(/* @__PURE__ */ new Set(["Data", "Item", "ModelValue", "Value"])).has(modelName) ? toPascalCase(modelName) : null,
8449
+ toPascalCase(element.tag)
8450
+ ].filter((value) => !!value);
8451
+ return Array.from(new Set(candidates));
8452
+ }
8453
+ function getElementSourceId(element) {
8454
+ return `${element.tag}:${element.loc.start.offset}:${element.loc.end.offset}`;
8455
+ }
8456
+ function getNearestComponentAncestor(element, hierarchyMap2, isComponentLikeTag2) {
8457
+ let parent = hierarchyMap2.get(element) ?? null;
8458
+ while (parent) {
8459
+ if (isComponentLikeTag2(parent.tag)) {
8460
+ return parent;
8461
+ }
8462
+ parent = hierarchyMap2.get(parent) ?? null;
8463
+ }
8464
+ return null;
8465
+ }
8466
+ function getSlotNameFromTemplate(element) {
8467
+ const directive = element.props.find((prop) => {
8468
+ return prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "slot";
8469
+ });
8470
+ if (!directive) {
8471
+ return null;
8472
+ }
8473
+ if (!directive.arg) {
8474
+ return "default";
8475
+ }
8476
+ return directive.arg.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION ? directive.arg.content.trim() || "default" : null;
8477
+ }
8229
8478
  function getStaticAttributeContent(element, name) {
8230
8479
  const attr = element.props.find((prop) => {
8231
8480
  return prop.type === compilerCore.NodeTypes.ATTRIBUTE && prop.name === name;
@@ -8564,6 +8813,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
8564
8813
  Object.entries(nativeWrappers).map(([tag, config]) => [tag, { ...config }])
8565
8814
  );
8566
8815
  const wrapperContractByTag = /* @__PURE__ */ new Map();
8816
+ const instanceWrapperContractByTag = /* @__PURE__ */ new Map();
8567
8817
  const getWrapperContract = (tag) => {
8568
8818
  if (!wrapperContractByTag.has(tag)) {
8569
8819
  wrapperContractByTag.set(tag, resolveWrapperContractForTag({
@@ -8575,6 +8825,17 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
8575
8825
  }
8576
8826
  return wrapperContractByTag.get(tag) ?? null;
8577
8827
  };
8828
+ const getInstanceWrapperContract = (tag) => {
8829
+ if (!instanceWrapperContractByTag.has(tag)) {
8830
+ instanceWrapperContractByTag.set(tag, resolveWrapperContractForTag({
8831
+ tag,
8832
+ vueFilesPathMap,
8833
+ wrapperSearchRoots,
8834
+ testIdAttribute: POM_INSTANCE_ATTRIBUTE
8835
+ }));
8836
+ }
8837
+ return instanceWrapperContractByTag.get(tag) ?? null;
8838
+ };
8578
8839
  const safeRealpath2 = (p) => {
8579
8840
  try {
8580
8841
  return fs.existsSync(p) ? fs.realpathSync(p) : p;
@@ -8591,6 +8852,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
8591
8852
  const conditionalMergeGroupByElement = /* @__PURE__ */ new WeakMap();
8592
8853
  const conditionalMergeGroupByElementLoc = /* @__PURE__ */ new Map();
8593
8854
  const conditionalMergeGroupByIfBranch = /* @__PURE__ */ new WeakMap();
8855
+ const componentInstanceNameOwnerByName = /* @__PURE__ */ new Map();
8594
8856
  let conditionalMergeGroupCounter = 0;
8595
8857
  const getElementLocationKey = (element) => {
8596
8858
  const startOffset = element.loc?.start.offset;
@@ -8684,6 +8946,8 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
8684
8946
  childrenComponentSet: /* @__PURE__ */ new Set(),
8685
8947
  usedComponentSet: /* @__PURE__ */ new Set(),
8686
8948
  dataTestIdSet: /* @__PURE__ */ new Set(),
8949
+ componentInstances: [],
8950
+ slotOutlets: [],
8687
8951
  isView,
8688
8952
  methodsContent: ""
8689
8953
  };
@@ -8697,6 +8961,17 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
8697
8961
  const isUpper = isAsciiUppercaseLetterCode$1(first);
8698
8962
  return isUpper || tag.includes("-");
8699
8963
  };
8964
+ if (element.tag === "slot") {
8965
+ const slotName = getStaticAttributeContent(element, "name") ?? "default";
8966
+ const target = getNearestComponentAncestor(element, hierarchyMap, isComponentLikeTag2);
8967
+ if (target) {
8968
+ dependencies.slotOutlets ??= [];
8969
+ const outlet = { name: slotName, targetSourceId: getElementSourceId(target) };
8970
+ if (!dependencies.slotOutlets.some((existing) => existing.name === outlet.name && existing.targetSourceId === outlet.targetSourceId)) {
8971
+ dependencies.slotOutlets.push(outlet);
8972
+ }
8973
+ }
8974
+ }
8700
8975
  if (isComponentLikeTag2(element.tag)) {
8701
8976
  dependencies.usedComponentSet.add(element.tag);
8702
8977
  if (crossFileKeyRegistry && context.scopes.vSlot > 0) {
@@ -8759,6 +9034,7 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
8759
9034
  role: contract.role
8760
9035
  };
8761
9036
  }
9037
+ let selectorParameterName = "key";
8762
9038
  const getBestAvailableKeyInfo = () => {
8763
9039
  const parentNode = context.parent && typeof context.parent === "object" ? context.parent : null;
8764
9040
  const isDirectVForChild = parentNode?.type === compilerCore.NodeTypes.FOR;
@@ -8766,6 +9042,7 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
8766
9042
  if (configuredAttrName && configuredAttrName !== "key") {
8767
9043
  const bindingKeyInfo = getBindingKeyInfo(element, configuredAttrName);
8768
9044
  if (bindingKeyInfo) {
9045
+ selectorParameterName = configuredAttrName === "value" ? "value" : "key";
8769
9046
  return bindingKeyInfo;
8770
9047
  }
8771
9048
  }
@@ -8792,6 +9069,50 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
8792
9069
  const bestKeyInfo = getBestAvailableKeyInfo();
8793
9070
  const bestKeyPlaceholder = bestKeyInfo?.selectorFragment ?? null;
8794
9071
  const bestRuntimeKeyPlaceholder = bestKeyInfo?.runtimeFragment ?? null;
9072
+ if (isComponentLikeTag2(element.tag)) {
9073
+ const componentInstanceKeyInfo = getKeyDirectiveInfo(element) || getContainedInVForDirectiveKeyInfo(context, element, hierarchyMap);
9074
+ const instanceContract = getInstanceWrapperContract(element.tag);
9075
+ if ((instanceContract?.forwardedTestIdTargetOffsets.size ?? 0) > 0) {
9076
+ if (tryGetExistingElementDataTestId(element, POM_INSTANCE_ATTRIBUTE)) {
9077
+ const loc = element.loc.start;
9078
+ throw new Error(
9079
+ `[vue-pom-generator] ${POM_INSTANCE_ATTRIBUTE} is generator-owned and cannot be authored manually.
9080
+ Component: ${componentName}
9081
+ File: ${context.filename ?? "unknown"}:${loc.line}:${loc.column}`
9082
+ );
9083
+ }
9084
+ const sourceId = getElementSourceId(element);
9085
+ const semanticNameCandidates = getComponentInstanceNameCandidates(element);
9086
+ const componentTypeName = toPascalCase(element.tag);
9087
+ const instanceNameCandidates = componentInstanceKeyInfo ? [componentTypeName, ...semanticNameCandidates.filter((candidate) => candidate !== componentTypeName)] : semanticNameCandidates;
9088
+ const instanceName = instanceNameCandidates.find((candidate) => {
9089
+ const owner = componentInstanceNameOwnerByName.get(candidate);
9090
+ return !owner || !!componentInstanceKeyInfo && owner.keyed && owner.componentName === element.tag;
9091
+ });
9092
+ if (instanceName) {
9093
+ componentInstanceNameOwnerByName.set(instanceName, {
9094
+ componentName: element.tag,
9095
+ keyed: !!componentInstanceKeyInfo,
9096
+ sourceId
9097
+ });
9098
+ const runtimeMarker = componentInstanceKeyInfo ? templateAttributeValue(`${componentName}-${componentInstanceKeyInfo.runtimeFragment}-${instanceName}-component`) : staticAttributeValue(`${componentName}-${instanceName}-component`);
9099
+ const selector = componentInstanceKeyInfo ? createPomStringPattern(`${componentName}-\${key}-${instanceName}-component`, "parameterized", ["key"]) : createPomStringPattern(`${componentName}-${instanceName}-component`, "static", []);
9100
+ upsertAttribute(element, POM_INSTANCE_ATTRIBUTE, runtimeMarker);
9101
+ const slotTemplate = getContainedInSlotTemplateNode(element, hierarchyMap);
9102
+ const slotName = slotTemplate ? getSlotNameFromTemplate(slotTemplate) : null;
9103
+ const slotOwner = slotTemplate ? getNearestComponentAncestor(slotTemplate, hierarchyMap, isComponentLikeTag2) : null;
9104
+ dependencies.componentInstances ??= [];
9105
+ dependencies.componentInstances.push({
9106
+ sourceId,
9107
+ componentName: element.tag,
9108
+ instanceName,
9109
+ selector,
9110
+ parameters: componentInstanceKeyInfo ? [createPomParameterSpec("key", "string")] : [],
9111
+ suppliedSlot: slotName && slotOwner ? { ownerSourceId: getElementSourceId(slotOwner), name: slotName } : void 0
9112
+ });
9113
+ }
9114
+ }
9115
+ }
8795
9116
  const keyValuesOverride = tryGetContainedInStaticVForSourceLiteralValues(context);
8796
9117
  const parentKey = context?.parent ? context.parent : null;
8797
9118
  const conditional = getConditionalDirectiveInfo(element);
@@ -8900,6 +9221,7 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
8900
9221
  preferredGeneratedValue: args.preferredGeneratedValue,
8901
9222
  preferredRuntimeValue: args.preferredRuntimeValue,
8902
9223
  keyInfo: bestKeyInfo,
9224
+ selectorParameterName,
8903
9225
  keyValuesOverride,
8904
9226
  entryOverrides: args.entryOverrides,
8905
9227
  semanticNameHint: args.semanticNameHint,