@immense/vue-pom-generator 1.0.100 → 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);
@@ -9322,7 +9336,10 @@ File: ${context.filename ?? "unknown"}:${loc.line}:${loc.column}`
9322
9336
  const propName = crossFileKeyRegistry.get(componentName);
9323
9337
  if (propName) {
9324
9338
  const fallbackExpr = buildSlotScopeFallbackKeyExpression(propName);
9325
- 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);
9326
9343
  }
9327
9344
  }
9328
9345
  return null;
@@ -9358,7 +9375,7 @@ File: ${context.filename ?? "unknown"}:${loc.line}:${loc.column}`
9358
9375
  });
9359
9376
  const runtimeMarker = componentInstanceKeyInfo ? templateAttributeValue(`${componentName}-${componentInstanceKeyInfo.runtimeFragment}-${instanceName}-component`) : staticAttributeValue(`${componentName}-${instanceName}-component`);
9360
9377
  const selector = componentInstanceKeyInfo ? createPomStringPattern(`${componentName}-\${key}-${instanceName}-component`, "parameterized", ["key"]) : createPomStringPattern(`${componentName}-${instanceName}-component`, "static", []);
9361
- upsertAttribute(element, POM_INSTANCE_ATTRIBUTE, runtimeMarker);
9378
+ upsertAttribute(element, POM_INSTANCE_ATTRIBUTE, runtimeMarker, context);
9362
9379
  const slotTemplate = getContainedInSlotTemplateNode(element, hierarchyMap);
9363
9380
  const slotName = slotTemplate ? getSlotNameFromTemplate(slotTemplate) : null;
9364
9381
  const slotOwner = slotTemplate ? getNearestComponentAncestor(slotTemplate, hierarchyMap, isComponentLikeTag2) : null;
@@ -9530,7 +9547,7 @@ Existing ${attrLabel}: ${JSON.stringify(existing.value)}
9530
9547
  Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrite" or "error".`
9531
9548
  );
9532
9549
  }
9533
- upsertAttribute(element, "option-data-testid-prefix", optionDataTestIdPrefixValue);
9550
+ upsertAttribute(element, "option-data-testid-prefix", optionDataTestIdPrefixValue, context);
9534
9551
  }
9535
9552
  const nativeRole = resolvedNativeWrappers[element.tag]?.role ?? element.tag;
9536
9553
  const wrapperHintCandidates = [