@immense/vue-pom-generator 1.0.110 → 1.0.111

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
@@ -9,6 +9,7 @@ import * as compilerDom from "@vue/compiler-dom";
9
9
  import { parse as parse$2, NodeTypes as NodeTypes$1 } from "@vue/compiler-dom";
10
10
  import { parse as parse$1, compileScript } from "@vue/compiler-sfc";
11
11
  import { Project, QuoteKind, NewLineKind, IndentationText, CodeBlockWriter, StructureKind, VariableDeclarationKind } from "ts-morph";
12
+ import { camelize } from "@vue/shared";
12
13
  import { isIdentifier, isObjectPattern, isRestElement, isObjectProperty, isArrayExpression, isStringLiteral, isTemplateLiteral, isArrowFunctionExpression, isExpressionStatement, isAssignmentPattern, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression, isObjectExpression, isFile, isBlockStatement, isLogicalExpression, isConditionalExpression, isSequenceExpression, isProgram, isArrayPattern, VISITOR_KEYS, isBooleanLiteral, isNumericLiteral, isNullLiteral, isImportDeclaration, isImportSpecifier, isExportDefaultDeclaration, isExpression, isVariableDeclaration, isFunctionDeclaration, isFunctionExpression, isReturnStatement, isTSAsExpression, isTSTypeAssertion, isTSNonNullExpression, isForInStatement, isIfStatement } from "@babel/types";
13
14
  import { createHash, randomUUID } from "node:crypto";
14
15
  import { POM_ROUTER_GLOBAL_NAME } from "./router.mjs";
@@ -1461,6 +1462,16 @@ function tryGetClickDirective(node) {
1461
1462
  function nodeHasClickDirective(node) {
1462
1463
  return tryGetClickDirective(node) !== void 0;
1463
1464
  }
1465
+ function nodeHasStaticClickDirective(node) {
1466
+ return node.props.some((prop) => {
1467
+ if (prop.type !== NodeTypes.DIRECTIVE) {
1468
+ return false;
1469
+ }
1470
+ const directive = prop;
1471
+ const arg = directive.arg;
1472
+ return directive.name === "on" && arg?.type === NodeTypes.SIMPLE_EXPRESSION && arg.isStatic && arg.content === "click";
1473
+ });
1474
+ }
1464
1475
  function findTemplateSlotScopeExpression(node) {
1465
1476
  if (node.tag !== "template") {
1466
1477
  return null;
@@ -2175,12 +2186,40 @@ function tryGetContainedInStaticVForSourceLiteralValues(context, _node, _hierarc
2175
2186
  function getParent(hierarchyMap2, node) {
2176
2187
  return hierarchyMap2.get(node) || null;
2177
2188
  }
2178
- function nodeHandlerAttributeValue(node) {
2179
- return nodeHandlerAttributeInfo(node)?.semanticNameHint ?? null;
2189
+ function nodeHandlerAttributeValue(node, actionPropNames) {
2190
+ return nodeHandlerAttributeInfo(node, actionPropNames)?.semanticNameHint ?? null;
2191
+ }
2192
+ const LOAD_ACTION_PROP_NAMES = ["loadAction", "handler"];
2193
+ function resolveActionPropNames(wrapperConfig) {
2194
+ if (!wrapperConfig || wrapperConfig.actionProp === void 0) {
2195
+ return LOAD_ACTION_PROP_NAMES;
2196
+ }
2197
+ const declared = wrapperConfig.actionProp.trim();
2198
+ if (!declared) {
2199
+ throw new Error(
2200
+ `[vue-pom-generator] nativeWrappers actionProp must name the component's click-action prop (e.g. "loadAction"); got an empty value.`
2201
+ );
2202
+ }
2203
+ return [declared];
2204
+ }
2205
+ function findLoadActionDirective(node, actionPropNames = LOAD_ACTION_PROP_NAMES) {
2206
+ const normalizedNames = new Set(actionPropNames.map((name) => camelize(name)));
2207
+ const directive = node.props.find((prop) => {
2208
+ if (prop.type !== NodeTypes.DIRECTIVE) {
2209
+ return false;
2210
+ }
2211
+ const candidate = prop;
2212
+ if (candidate.name !== "bind" || !candidate.exp) {
2213
+ return false;
2214
+ }
2215
+ const arg = candidate.arg;
2216
+ return arg?.type === NodeTypes.SIMPLE_EXPRESSION && arg.isStatic && normalizedNames.has(camelize(arg.content));
2217
+ });
2218
+ return directive ?? null;
2180
2219
  }
2181
- function nodeHandlerAttributeInfo(node) {
2182
- const handlerDirective = findDirectiveByName(node, "bind", "handler");
2183
- if (!handlerDirective?.exp) {
2220
+ function nodeHandlerAttributeInfo(node, actionPropNames) {
2221
+ const handlerDirective = findLoadActionDirective(node, actionPropNames);
2222
+ if (!handlerDirective) {
2184
2223
  return null;
2185
2224
  }
2186
2225
  const exp = handlerDirective.exp;
@@ -9946,20 +9985,29 @@ File: ${context.filename ?? "unknown"}:${loc.line}:${loc.column}`
9946
9985
  });
9947
9986
  };
9948
9987
  const { nativeWrappersValue, optionDataTestIdPrefixValue, semanticNameHint } = getNativeWrapperTransformInfo(element, componentName, resolvedNativeWrappers);
9949
- const handlerDirective = element.props.find((p) => {
9950
- return p.type === NodeTypes.DIRECTIVE && p.name === "bind" && p.arg?.type === NodeTypes.SIMPLE_EXPRESSION && p.arg.content === "handler" && !!p.exp;
9951
- }) ?? null;
9952
- const handlerInfo = handlerDirective ? nodeHandlerAttributeInfo(element) : null;
9953
- if (resolvedNativeWrappers[element.tag]?.role === "button" && handlerDirective && !handlerInfo) {
9988
+ const wrapperConfig = resolvedNativeWrappers[element.tag];
9989
+ const actionPropNames = resolveActionPropNames(wrapperConfig);
9990
+ const handlerDirective = findLoadActionDirective(element, actionPropNames);
9991
+ const handlerInfo = handlerDirective ? nodeHandlerAttributeInfo(element, actionPropNames) : null;
9992
+ if (wrapperConfig?.role === "button" && handlerDirective && !handlerInfo) {
9954
9993
  const loc = element.loc?.start;
9955
9994
  const locationHint = loc ? `${loc.line}:${loc.column}` : "unknown";
9956
9995
  const handlerSource = (handlerDirective.exp?.loc?.source ?? "").trim() || "<unknown>";
9996
+ const actionArgName = handlerDirective.arg.content;
9957
9997
  throw new Error(
9958
9998
  `[vue-pom-generator] Could not derive a semantic POM action name for button-like wrapper in ${componentName} (${context.filename ?? "unknown"}:${locationHint}).
9959
9999
  Element: <${element.tag}>
9960
10000
  Handler: ${handlerSource}
9961
10001
 
9962
- Fix: move complex inline logic into a named function (for example, const onAction = () => ...; then bind :handler="onAction"), or simplify the handler to a direct identifier/call the generator can name.`
10002
+ Fix: move complex inline logic into a named function (for example, const onAction = () => ...; then bind :${actionArgName}="onAction"), or simplify the handler to a direct identifier/call the generator can name.`
10003
+ );
10004
+ }
10005
+ if (wrapperConfig?.actionProp && !handlerDirective && !nodeHasStaticClickDirective(element)) {
10006
+ const loc = element.loc?.start;
10007
+ const locationHint = loc ? `${loc.line}:${loc.column}` : "unknown";
10008
+ throw new Error(
10009
+ `[vue-pom-generator] Wrapper <${element.tag}> declares actionProp "${wrapperConfig.actionProp}" but this usage in ${componentName} (${context.filename ?? "unknown"}:${locationHint}) binds neither :${wrapperConfig.actionProp} nor @click.
10010
+ Fix: bind :${wrapperConfig.actionProp}="onAction" (or @click="...") so the usage exposes an actionable POM member, or remove actionProp from the wrapper config if this component is not action-driven.`
9963
10011
  );
9964
10012
  }
9965
10013
  if (nativeWrappersValue) {
@@ -10120,7 +10168,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
10120
10168
  if (!isRecognizedInteractiveRole) {
10121
10169
  return;
10122
10170
  }
10123
- const identifierHint = getStaticIdOrNameHint(element) || nodeHandlerAttributeValue(element) || innerText || existingElementDataTestId.value || conditionalHint || void 0;
10171
+ const identifierHint = getStaticIdOrNameHint(element) || nodeHandlerAttributeValue(element, actionPropNames) || innerText || existingElementDataTestId.value || conditionalHint || void 0;
10124
10172
  const preferredGeneratedValue = existingElementDataTestId.isDynamic ? templateAttributeValue(existingElementDataTestId.template) : staticAttributeValue(existingElementDataTestId.value);
10125
10173
  applyResolvedDataTestIdForElement({
10126
10174
  preferredGeneratedValue,