@immense/vue-pom-generator 1.0.99 → 1.0.101

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
@@ -7,7 +7,7 @@ import * as compilerDom from "@vue/compiler-dom";
7
7
  import { parse as parse$2, NodeTypes as NodeTypes$1 } from "@vue/compiler-dom";
8
8
  import { parse as parse$1, compileScript } from "@vue/compiler-sfc";
9
9
  import { parseExpression, parse } from "@babel/parser";
10
- import { NodeTypes, stringifyExpression, createSimpleExpression, ConstantTypes, ElementTypes } from "@vue/compiler-core";
10
+ import { NodeTypes, stringifyExpression, createSimpleExpression, processExpression, ConstantTypes, ElementTypes } from "@vue/compiler-core";
11
11
  import { Project, QuoteKind, NewLineKind, IndentationText, CodeBlockWriter, StructureKind, VariableDeclarationKind } from "ts-morph";
12
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, isImportDeclaration, isImportSpecifier, isExportDefaultDeclaration, isExpression, isVariableDeclaration, isFunctionDeclaration, isFunctionExpression, isReturnStatement, isTSAsExpression, isTSTypeAssertion, isTSNonNullExpression, isForInStatement, isIfStatement } from "@babel/types";
13
13
  import { POM_ROUTER_GLOBAL_NAME } from "./router.mjs";
@@ -2725,7 +2725,7 @@ function findTestIdAttribute(element, attributeName) {
2725
2725
  return staticAttr;
2726
2726
  return findDirectiveByName(element, "bind", attributeName) ?? null;
2727
2727
  }
2728
- function upsertAttribute(element, attributeName, value) {
2728
+ function upsertAttribute(element, attributeName, value, context) {
2729
2729
  element.props = element.props.filter((prop) => {
2730
2730
  if (prop.type === NodeTypes.ATTRIBUTE && prop.name === attributeName) {
2731
2731
  return false;
@@ -2736,6 +2736,7 @@ function upsertAttribute(element, attributeName, value) {
2736
2736
  return true;
2737
2737
  });
2738
2738
  if (value.kind === "template") {
2739
+ const expression = createSimpleExpression(`\`${value.template}\``, false, element.loc);
2739
2740
  element.props.push({
2740
2741
  type: NodeTypes.DIRECTIVE,
2741
2742
  name: "bind",
@@ -2746,7 +2747,10 @@ function upsertAttribute(element, attributeName, value) {
2746
2747
  constType: 0,
2747
2748
  loc: element.loc
2748
2749
  },
2749
- exp: createSimpleExpression(`\`${value.template}\``, false, element.loc),
2750
+ // Custom node transforms run after Vue's built-in expression transform.
2751
+ // Process generator-owned bindings explicitly so setup bindings, props,
2752
+ // and v-for/slot locals retain the same runtime scope as authored bindings.
2753
+ exp: context?.prefixIdentifiers ? processExpression(expression, context) : expression,
2750
2754
  modifiers: [],
2751
2755
  loc: element.loc
2752
2756
  });
@@ -3319,7 +3323,12 @@ Fix: make the element identifiable (e.g. add id/name/inner text or use a more sp
3319
3323
  }
3320
3324
  const normalizedParameters = selectorIsParameterized ? setPomParameter(parameters, selectorParameterName, keyTypeFromValues) : removePomParameter(parameters, selectorParameterName);
3321
3325
  if (addHtmlAttribute && !fromExisting) {
3322
- upsertAttribute(args.element, testIdAttribute, dataTestId);
3326
+ upsertAttribute(
3327
+ args.element,
3328
+ testIdAttribute,
3329
+ runtimeDataTestId,
3330
+ args.preferredRuntimeValue ? args.context : void 0
3331
+ );
3323
3332
  }
3324
3333
  const childComponentName = args.element.tag;
3325
3334
  const dataTestIdEntry = {
@@ -3357,13 +3366,18 @@ Fix: make the element identifiable (e.g. add id/name/inner text or use a more sp
3357
3366
  throw new Error(`[vue-pom-generator] runtime.annotator.enabled requires element source locations for ${args.componentName}.`);
3358
3367
  }
3359
3368
  const metadataAttributePrefix = args.annotatorMetadata.metadataAttributePrefix;
3360
- upsertAttribute(args.element, args.annotatorMetadata.sourceAttribute, staticAttributeValue(`${filename}:${sourceLocation.line}:${sourceLocation.column}`));
3361
- upsertAttribute(args.element, `${metadataAttributePrefix}-component`, staticAttributeValue(args.componentName));
3362
- upsertAttribute(args.element, `${metadataAttributePrefix}-tag`, staticAttributeValue(args.element.tag));
3363
- upsertAttribute(args.element, `${metadataAttributePrefix}-testid`, runtimeDataTestId);
3364
- upsertAttribute(args.element, `${metadataAttributePrefix}-action`, staticAttributeValue(buildPomGeneratedActionName(dataTestIdEntry.pom)));
3365
- upsertAttribute(args.element, `${metadataAttributePrefix}-property`, staticAttributeValue(buildPomGeneratedPropertyName(dataTestIdEntry.pom)));
3366
- upsertAttribute(args.element, `${metadataAttributePrefix}-role`, staticAttributeValue(normalizedRole));
3369
+ upsertAttribute(args.element, args.annotatorMetadata.sourceAttribute, staticAttributeValue(`${filename}:${sourceLocation.line}:${sourceLocation.column}`), args.context);
3370
+ upsertAttribute(args.element, `${metadataAttributePrefix}-component`, staticAttributeValue(args.componentName), args.context);
3371
+ upsertAttribute(args.element, `${metadataAttributePrefix}-tag`, staticAttributeValue(args.element.tag), args.context);
3372
+ upsertAttribute(
3373
+ args.element,
3374
+ `${metadataAttributePrefix}-testid`,
3375
+ runtimeDataTestId,
3376
+ args.preferredRuntimeValue ? args.context : void 0
3377
+ );
3378
+ upsertAttribute(args.element, `${metadataAttributePrefix}-action`, staticAttributeValue(buildPomGeneratedActionName(dataTestIdEntry.pom)), args.context);
3379
+ upsertAttribute(args.element, `${metadataAttributePrefix}-property`, staticAttributeValue(buildPomGeneratedPropertyName(dataTestIdEntry.pom)), args.context);
3380
+ upsertAttribute(args.element, `${metadataAttributePrefix}-role`, staticAttributeValue(normalizedRole), args.context);
3367
3381
  }
3368
3382
  args.dependencies.childrenComponentSet.add(childComponentName);
3369
3383
  args.dependencies.usedComponentSet.add(childComponentName);
@@ -8687,6 +8701,24 @@ function getStaticAttributeContent(element, name) {
8687
8701
  function getNativeHtmlControlRole(element) {
8688
8702
  return getElementControlRole(element);
8689
8703
  }
8704
+ function getConventionalOptionIdentityAttribute(element) {
8705
+ const explicitRole = getStaticAttributeContent(element, "role")?.toLowerCase();
8706
+ if (explicitRole === "option") {
8707
+ return "data-value";
8708
+ }
8709
+ if (explicitRole === "radio") {
8710
+ return "value";
8711
+ }
8712
+ const tag = element.tag.toLowerCase();
8713
+ const type = getStaticAttributeContent(element, "type")?.toLowerCase();
8714
+ if ((tag === "input" || tag === "uinput") && type === "radio") {
8715
+ return "value";
8716
+ }
8717
+ return null;
8718
+ }
8719
+ function describeConventionalOption(element) {
8720
+ return getConventionalOptionIdentityAttribute(element) === "value" ? "radio" : `<${element.tag} role="option">`;
8721
+ }
8690
8722
  function normalizeControlLabelText(value) {
8691
8723
  const normalized = (value ?? "").replace(/\*/g, " ").replace(/\s+/g, " ").trim();
8692
8724
  return normalized || null;
@@ -9241,15 +9273,55 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
9241
9273
  const getBestAvailableKeyInfo = () => {
9242
9274
  const parentNode = context.parent && typeof context.parent === "object" ? context.parent : null;
9243
9275
  const isDirectVForChild = parentNode?.type === NodeTypes.FOR;
9244
- const configuredAttrName = optionKeyAttribute[componentName];
9276
+ const isInVForScope = isDirectVForChild || context.scopes.vFor > 0;
9277
+ const vForKeyInfo = (isDirectVForChild ? getKeyDirectiveInfo(element) : null) || getContainedInVForDirectiveKeyInfo(context, element, hierarchyMap);
9278
+ const conventionalIdentityAttribute = getConventionalOptionIdentityAttribute(element);
9279
+ const configuredAttrName = optionKeyAttribute[componentName]?.trim();
9280
+ if (configuredAttrName === "key") {
9281
+ if (vForKeyInfo) {
9282
+ return vForKeyInfo;
9283
+ }
9284
+ if (isInVForScope && conventionalIdentityAttribute) {
9285
+ const loc = element.loc.start;
9286
+ throw new Error(
9287
+ `[vue-pom-generator] optionKeyAttribute maps ${componentName} to "key", but repeated ${describeConventionalOption(element)} has no resolvable v-for :key.
9288
+ File: ${context.filename ?? "unknown"}:${loc.line}:${loc.column}
9289
+
9290
+ Fix: bind :key on the repeated option or remove the override to use the conventional :${conventionalIdentityAttribute} identity.`
9291
+ );
9292
+ }
9293
+ }
9245
9294
  if (configuredAttrName && configuredAttrName !== "key") {
9246
9295
  const bindingKeyInfo = getBindingKeyInfo(element, configuredAttrName);
9247
9296
  if (bindingKeyInfo) {
9248
9297
  selectorParameterName = configuredAttrName === "value" ? "value" : "key";
9249
9298
  return bindingKeyInfo;
9250
9299
  }
9300
+ if (isInVForScope && conventionalIdentityAttribute) {
9301
+ const loc = element.loc.start;
9302
+ throw new Error(
9303
+ `[vue-pom-generator] optionKeyAttribute maps ${componentName} to "${configuredAttrName}", but repeated ${describeConventionalOption(element)} does not bind :${configuredAttrName}.
9304
+ File: ${context.filename ?? "unknown"}:${loc.line}:${loc.column}
9305
+
9306
+ Fix: bind :${configuredAttrName} on the option element or remove the override to use the conventional :${conventionalIdentityAttribute} identity.`
9307
+ );
9308
+ }
9309
+ }
9310
+ if (conventionalIdentityAttribute) {
9311
+ const bindingKeyInfo = getBindingKeyInfo(element, conventionalIdentityAttribute);
9312
+ if (bindingKeyInfo) {
9313
+ selectorParameterName = conventionalIdentityAttribute === "value" ? "value" : "key";
9314
+ return bindingKeyInfo;
9315
+ }
9316
+ if (isInVForScope) {
9317
+ const loc = element.loc.start;
9318
+ throw new Error(
9319
+ `[vue-pom-generator] Repeated ${describeConventionalOption(element)} must bind :${conventionalIdentityAttribute} for generated option selection.
9320
+ Component: ${componentName}
9321
+ File: ${context.filename ?? "unknown"}:${loc.line}:${loc.column}`
9322
+ );
9323
+ }
9251
9324
  }
9252
- const vForKeyInfo = (isDirectVForChild ? getKeyDirectiveInfo(element) : null) || getContainedInVForDirectiveKeyInfo(context, element, hierarchyMap);
9253
9325
  if (vForKeyInfo) {
9254
9326
  return vForKeyInfo;
9255
9327
  }
@@ -9264,7 +9336,10 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
9264
9336
  const propName = crossFileKeyRegistry.get(componentName);
9265
9337
  if (propName) {
9266
9338
  const fallbackExpr = buildSlotScopeFallbackKeyExpression(propName);
9267
- return toResolvedKeyInfo(fallbackExpr, fallbackExpr);
9339
+ const runtimeExpression = createSimpleExpression(fallbackExpr, false, element.loc);
9340
+ const selectorExpression = context.prefixIdentifiers ? processExpression(runtimeExpression, context) : runtimeExpression;
9341
+ const selectorSource = getVueExpressionSource(selectorExpression, "compiled", "content");
9342
+ return toResolvedKeyInfo(selectorSource, fallbackExpr);
9268
9343
  }
9269
9344
  }
9270
9345
  return null;
@@ -9300,7 +9375,7 @@ File: ${context.filename ?? "unknown"}:${loc.line}:${loc.column}`
9300
9375
  });
9301
9376
  const runtimeMarker = componentInstanceKeyInfo ? templateAttributeValue(`${componentName}-${componentInstanceKeyInfo.runtimeFragment}-${instanceName}-component`) : staticAttributeValue(`${componentName}-${instanceName}-component`);
9302
9377
  const selector = componentInstanceKeyInfo ? createPomStringPattern(`${componentName}-\${key}-${instanceName}-component`, "parameterized", ["key"]) : createPomStringPattern(`${componentName}-${instanceName}-component`, "static", []);
9303
- upsertAttribute(element, POM_INSTANCE_ATTRIBUTE, runtimeMarker);
9378
+ upsertAttribute(element, POM_INSTANCE_ATTRIBUTE, runtimeMarker, context);
9304
9379
  const slotTemplate = getContainedInSlotTemplateNode(element, hierarchyMap);
9305
9380
  const slotName = slotTemplate ? getSlotNameFromTemplate(slotTemplate) : null;
9306
9381
  const slotOwner = slotTemplate ? getNearestComponentAncestor(slotTemplate, hierarchyMap, isComponentLikeTag2) : null;
@@ -9472,7 +9547,7 @@ Existing ${attrLabel}: ${JSON.stringify(existing.value)}
9472
9547
  Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrite" or "error".`
9473
9548
  );
9474
9549
  }
9475
- upsertAttribute(element, "option-data-testid-prefix", optionDataTestIdPrefixValue);
9550
+ upsertAttribute(element, "option-data-testid-prefix", optionDataTestIdPrefixValue, context);
9476
9551
  }
9477
9552
  const nativeRole = resolvedNativeWrappers[element.tag]?.role ?? element.tag;
9478
9553
  const wrapperHintCandidates = [