@immense/vue-pom-generator 1.0.61 → 1.0.63

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
@@ -1761,11 +1761,12 @@ function nodeHandlerAttributeInfo(node) {
1761
1761
  return null;
1762
1762
  }
1763
1763
  const exp = handlerDirective.exp;
1764
- const source = getVueExpressionSource(exp, "content", "compiled");
1765
- if (!source) {
1764
+ const transformedSource = getVueExpressionSource(exp, "content", "compiled");
1765
+ const authorSource = getVueExpressionSource(exp, "loc", "content", "compiled");
1766
+ if (!authorSource) {
1766
1767
  return null;
1767
1768
  }
1768
- const mergeKey = `handler:expr:${source}`;
1769
+ const mergeKey = `handler:expr:${authorSource}`;
1769
1770
  const expr = tryGetDirectiveBabelAst(handlerDirective, {
1770
1771
  preferredViews: ["content", "compiled"],
1771
1772
  plugins: ["typescript", "jsx"],
@@ -1773,9 +1774,7 @@ function nodeHandlerAttributeInfo(node) {
1773
1774
  // That is fine for Vue codegen, but our semantic-name extraction needs a normal Babel parse tree.
1774
1775
  preferExistingAst: false
1775
1776
  });
1776
- if (!expr) {
1777
- return null;
1778
- }
1777
+ const fallbackExpr = transformedSource !== authorSource ? tryParseBabelExpressionFromSource(authorSource, ["typescript", "jsx"]) : null;
1779
1778
  const isNodeType2 = (node2, type) => {
1780
1779
  return node2 !== null && node2.type === type;
1781
1780
  };
@@ -2011,59 +2010,73 @@ function nodeHandlerAttributeInfo(node) {
2011
2010
  const limited = parts.slice(0, 2);
2012
2011
  return limited.map((p) => `${toPascalCase(p.key)}${p.value}`).join("");
2013
2012
  };
2014
- const direct = getLastIdentifierFromMemberChain(expr);
2015
- if (direct) {
2016
- return { semanticNameHint: toPascalCase(direct), mergeKey };
2017
- }
2018
- if (isArrowFunctionExpressionNode(expr)) {
2019
- const body = expr.body;
2020
- const tryFromCallExpression = (call) => {
2021
- const resolvedCall = isAwaitExpressionNode(call) ? call.argument : call;
2022
- if (!isCallExpressionNode(resolvedCall)) {
2023
- return null;
2024
- }
2025
- const name = getLastIdentifierFromMemberChain(resolvedCall.callee);
2026
- if (!name) {
2027
- return null;
2013
+ const tryFromCallExpression = (call) => {
2014
+ const resolvedCall = isAwaitExpressionNode(call) ? call.argument : call;
2015
+ if (!isCallExpressionNode(resolvedCall)) {
2016
+ return null;
2017
+ }
2018
+ const name = getLastIdentifierFromMemberChain(resolvedCall.callee);
2019
+ if (!name) {
2020
+ return null;
2021
+ }
2022
+ const suffix = getStableSuffixFromCall(resolvedCall);
2023
+ const semanticNameHint2 = suffix ? `${toPascalCase(name)}${suffix}` : toPascalCase(name);
2024
+ return semanticNameHint2;
2025
+ };
2026
+ const resolveSemanticName = (candidateExpr) => {
2027
+ if (!candidateExpr) {
2028
+ return null;
2029
+ }
2030
+ const direct = getLastIdentifierFromMemberChain(candidateExpr);
2031
+ if (direct) {
2032
+ return toPascalCase(direct);
2033
+ }
2034
+ if (isArrowFunctionExpressionNode(candidateExpr)) {
2035
+ const body = candidateExpr.body;
2036
+ const directCall = tryFromCallExpression(body);
2037
+ if (directCall) {
2038
+ return directCall;
2039
+ }
2040
+ if (isAssignmentExpressionNode(body)) {
2041
+ const lhs = getAssignmentTargetName(body.left);
2042
+ if (lhs) {
2043
+ const rhs = stableWordFromValue(body.right);
2044
+ return `Set${toPascalCase(lhs)}${rhs ?? ""}`;
2045
+ }
2028
2046
  }
2029
- const suffix = getStableSuffixFromCall(resolvedCall);
2030
- const semanticNameHint = suffix ? `${toPascalCase(name)}${suffix}` : toPascalCase(name);
2031
- return semanticNameHint;
2032
- };
2033
- const directCall = tryFromCallExpression(body);
2034
- if (directCall) {
2035
- return { semanticNameHint: directCall, mergeKey };
2036
- }
2037
- if (isAssignmentExpressionNode(body)) {
2038
- const lhs = getAssignmentTargetName(body.left);
2039
- if (lhs) {
2040
- const rhs = stableWordFromValue(body.right);
2041
- const semanticNameHint = `Set${toPascalCase(lhs)}${rhs ?? ""}`;
2042
- return { semanticNameHint, mergeKey };
2043
- }
2044
- }
2045
- if (isBlockStatementNode(body)) {
2046
- const stmts = body.body ?? [];
2047
- if (stmts.length > 0) {
2048
- const firstStmt = stmts[0];
2049
- if (isReturnStatementNode(firstStmt)) {
2050
- const fromReturn = tryFromCallExpression(firstStmt.argument ?? null);
2051
- if (fromReturn) {
2052
- return { semanticNameHint: fromReturn, mergeKey };
2047
+ if (isBlockStatementNode(body)) {
2048
+ const stmts = body.body ?? [];
2049
+ if (stmts.length > 0) {
2050
+ const firstStmt = stmts[0];
2051
+ if (isReturnStatementNode(firstStmt)) {
2052
+ const fromReturn = tryFromCallExpression(firstStmt.argument ?? null);
2053
+ if (fromReturn) {
2054
+ return fromReturn;
2055
+ }
2053
2056
  }
2054
- }
2055
- if (isExpressionStatementNode(firstStmt)) {
2056
- const fromExpr = tryFromCallExpression(firstStmt.expression ?? null);
2057
- if (fromExpr) {
2058
- return { semanticNameHint: fromExpr, mergeKey };
2057
+ if (isExpressionStatementNode(firstStmt)) {
2058
+ const fromExpr = tryFromCallExpression(firstStmt.expression ?? null);
2059
+ if (fromExpr) {
2060
+ return fromExpr;
2061
+ }
2059
2062
  }
2060
2063
  }
2061
2064
  }
2065
+ const bodyName = getLastIdentifierFromMemberChain(body);
2066
+ if (bodyName) {
2067
+ return toPascalCase(bodyName);
2068
+ }
2062
2069
  }
2063
- const bodyName = getLastIdentifierFromMemberChain(body);
2064
- if (bodyName) {
2065
- return { semanticNameHint: toPascalCase(bodyName), mergeKey };
2066
- }
2070
+ return null;
2071
+ };
2072
+ const isVueRefValueAccess = (candidate) => {
2073
+ return isMemberExpressionNode(candidate) && candidate.computed === false && isIdentifierNode2(candidate.property) && candidate.property.name === "value";
2074
+ };
2075
+ const transformedSemanticName = resolveSemanticName(expr);
2076
+ const fallbackSemanticName = resolveSemanticName(fallbackExpr);
2077
+ const semanticNameHint = fallbackSemanticName && transformedSource !== authorSource && isVueRefValueAccess(expr) ? fallbackSemanticName : transformedSemanticName ?? fallbackSemanticName;
2078
+ if (semanticNameHint) {
2079
+ return { semanticNameHint, mergeKey };
2067
2080
  }
2068
2081
  return null;
2069
2082
  }
@@ -5439,14 +5452,51 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
5439
5452
  customPomAttachments = [],
5440
5453
  testIdAttribute
5441
5454
  } = options;
5455
+ const normalizeTrackedComponentRef = (value) => {
5456
+ return value.endsWith(".vue") ? value.slice(0, -4) : value;
5457
+ };
5458
+ const resolveTrackedComponentRef = (value) => {
5459
+ const normalizedValue = normalizeTrackedComponentRef(value);
5460
+ if (componentHierarchyMap.has(value)) {
5461
+ return value;
5462
+ }
5463
+ if (componentHierarchyMap.has(normalizedValue)) {
5464
+ return normalizedValue;
5465
+ }
5466
+ let match = null;
5467
+ for (const [candidateName, candidateDeps] of componentHierarchyMap.entries()) {
5468
+ const normalizedCandidate = normalizeTrackedComponentRef(candidateName);
5469
+ const candidateBaseName = path.parse(candidateDeps.filePath).name;
5470
+ if (normalizedCandidate !== normalizedValue && candidateBaseName !== normalizedValue) {
5471
+ continue;
5472
+ }
5473
+ if (match && match !== candidateName) {
5474
+ return null;
5475
+ }
5476
+ match = candidateName;
5477
+ }
5478
+ return match;
5479
+ };
5480
+ const rawComponentRefsForInstances = isView ? usedComponentSet?.size ? usedComponentSet : childrenComponentSet : childrenComponentSet;
5481
+ const componentRefsForInstances = /* @__PURE__ */ new Set();
5482
+ for (const ref of rawComponentRefsForInstances) {
5483
+ componentRefsForInstances.add(resolveTrackedComponentRef(ref) ?? normalizeTrackedComponentRef(ref));
5484
+ }
5442
5485
  const hasChildComponent = (needle) => {
5443
- const haystack = usedComponentSet?.size ? usedComponentSet : childrenComponentSet;
5444
- for (const child of haystack) {
5445
- if (child === needle)
5486
+ const normalizedNeedle = normalizeTrackedComponentRef(needle);
5487
+ for (const child of rawComponentRefsForInstances) {
5488
+ const resolvedChild = resolveTrackedComponentRef(child);
5489
+ if (normalizeTrackedComponentRef(child) === normalizedNeedle)
5446
5490
  return true;
5447
- if (child === `${needle}.vue`)
5491
+ if (resolvedChild && normalizeTrackedComponentRef(resolvedChild) === normalizedNeedle)
5448
5492
  return true;
5449
- if (child.endsWith(".vue") && child.slice(0, -4) === needle)
5493
+ if (resolvedChild) {
5494
+ const resolvedDeps = componentHierarchyMap.get(resolvedChild);
5495
+ if (resolvedDeps && path.parse(resolvedDeps.filePath).name === normalizedNeedle) {
5496
+ return true;
5497
+ }
5498
+ }
5499
+ if (child === `${needle}.vue`)
5450
5500
  return true;
5451
5501
  }
5452
5502
  return false;
@@ -5470,7 +5520,6 @@ function prepareViewObjectModelClass(componentName, dependencies, componentHiera
5470
5520
  methodSignatures: a.flatten ? customPomMethodSignaturesByClass.get(a.className) ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map()
5471
5521
  }));
5472
5522
  const widgetInstances = isView ? getWidgetInstancesForView(componentName, dependencies.dataTestIdSet, customPomAvailableClassIdentifiers) : [];
5473
- const componentRefsForInstances = isView ? usedComponentSet?.size ? usedComponentSet : childrenComponentSet : childrenComponentSet;
5474
5523
  const className = toPascalCaseLocal(componentName);
5475
5524
  const childInstancePropertyNames = Array.from(componentRefsForInstances).filter((child) => componentHierarchyMap.has(child) && componentHierarchyMap.get(child)?.dataTestIdSet.size).map((child) => child.split(".vue")[0]);
5476
5525
  const blockedViewPassthroughMethodNames = new Set(