@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/README.md CHANGED
@@ -77,7 +77,7 @@ The generator does not use one naming trick. It layers several signals.
77
77
  - **Router links / `:to` bindings** can contribute route-based naming and typed navigation return types when the target can be resolved.
78
78
  - **Wrapper components** are inferred from the rendered element that actually receives Vue fallthrough attributes; `nativeWrappers` supplies exceptional overrides.
79
79
  - **Fallback naming exists, but it is intentionally conservative.** That is why `generation.nameCollisionBehavior` exists.
80
- - **Wrapper-action generation fails fast.** The generator blocks button-like wrapper `:handler` expressions that it cannot turn into a semantic action name.
80
+ - **Wrapper-action generation fails fast.** The generator blocks button-like wrapper `:loadAction` (legacy `:handler`, or a wrapper-declared `actionProp`) expressions that it cannot turn into a semantic action name, and fails when a wrapper that declares `actionProp` is used without that binding (or `@click`).
81
81
 
82
82
  Wrapper inference follows the public attribute contract instead of scanning for an arbitrary interactive descendant. It recognizes automatic single-root fallthrough, `v-bind="$attrs"`, aliases returned by `useAttrs()`, explicit forwarding such as `:data-testid="$attrs['data-testid']"`, and simple helpers that copy all attributes except named keys. The role comes from that target's explicit static ARIA role first, then its native HTML semantics. This means `<button role="tab">` is a tab, while an editable `<input role="combobox">` retains input behavior so generated actions fill it instead of calling native `selectOption()`. A `<div><button>...</button></div>` is not misclassified as a button wrapper because the caller's test id lands on the `<div>`. Nested wrappers are followed recursively. Polymorphic targets with different roles are deliberately left unresolved; configure `nativeWrappers` when one stable generated role is still appropriate.
83
83
 
@@ -1309,6 +1309,15 @@ The sections below follow the actual `VuePomGeneratorPluginOptions` shape from `
1309
1309
  - **Benefit:** You get meaningful ids and method names from wrapper props instead of fallback names.
1310
1310
  - **Without it:** wrapper naming falls back to model bindings or other weaker signals.
1311
1311
 
1312
+ ##### `nativeWrappers[...].actionProp`
1313
+
1314
+ - **What it does:** Names the wrapper prop that triggers the component's click action (for example `"loadAction"`), so semantic POM action methods (`clickSave()`, `clickResolveFailuresForAgent()`, ...) are derived from that binding.
1315
+ - **Why it exists:** Without it, the generator matches a built-in set of LoadButton-style prop names (`loadAction`, kebab-case `load-action`, legacy `handler`). A consumer that renames its action prop would otherwise silently lose semantic action names until the generator learns the new name.
1316
+ - **Benefit:** Prop renames become a one-line config change in the same PR as the rename; the contract lives with the consumer that owns the component.
1317
+ - **Matching:** The declared name matches any attribute spelling that normalizes to it — Vue accepts both `:loadAction` and `:load-action` for the same prop.
1318
+ - **Without it:** the built-in `loadAction` and legacy `handler` names are matched, in either spelling.
1319
+ - **Fail-fast:** a usage of a wrapper that declares `actionProp` must bind that prop (either spelling) or `@click`; anything else fails generation instead of emitting a POM member with no actionable behavior.
1320
+
1312
1321
  ##### `nativeWrappers[...].requiresOptionDataTestIdPrefix`
1313
1322
 
1314
1323
  - **What it does:** Adds an `option-data-testid-prefix` attribute for wrappers that need stable option-level ids.
package/RELEASE_NOTES.md CHANGED
@@ -1,34 +1,37 @@
1
1
  Highlights
2
2
 
3
- - Added a CI duplication gate ("deslop") that fails builds when duplicated code is reintroduced.
4
- - Extracted shared Babel AST guard logic into a new compiler/babel-guards.ts module, removing
5
- repeated inline guards across the compiler.
6
- - Deduplicated the test suite with new shared helpers — net ~250 lines removed (596 insertions, 850
7
- deletions).
3
+ - Wrapper POM action names now derive from :loadAction as well as the legacy :handler binding, so
4
+ load-style wrappers get semantic method names (#75)
5
+ - Action-prop matching is now consumer-declared: nativeWrappers[...].actionProp replaces the
6
+ built-in name set, so renaming a wrapper's prop no longer requires generator changes (#75)
7
+ - Matching uses Vue's own camelize on normalized prop names, so any spelling the Vue runtime maps
8
+ to the prop (:loadAction, :load-action, legacy :handler) works (#75)
8
9
 
9
10
  Changes
10
11
 
11
- CI / tooling
12
-
13
- - New .github/workflows/deslop.yml with a .deslop.toml config enforcing the duplication gate (#76).
14
- - Added deslop artifacts to .gitignore.
15
-
16
- Refactoring
17
-
18
- - New compiler/babel-guards.ts centralizes Babel node-guard predicates; transform.ts,
19
- routing/to-directive.ts, and utils.ts now consume them, substantially shrinking utils.ts.
20
- - New shared test helpers: tests/helpers/ast-queries.ts and tests/helpers/component-deps.ts.
21
- - Slimmed tests/transform.test.ts, tests/utils-coverage.test.ts,
22
- tests/class-generation-coverage.test.ts, tests/generated-tsc.test.ts, and
23
- tests/wrapper-contract.test.ts to use the shared helpers.
12
+ - POM naming
13
+ - Declared actionProp on a native wrapper replaces the built-in action-prop names for that wrapper
14
+ (#75)
15
+ - Fail fast when a wrapper declaring actionProp is used without that binding or a static @click;
16
+ @change/@mousedown and dynamic event/argument bindings don't count as proof (#75)
17
+ - Echo the matched directive argument in the unnameable-handler error so legacy :handler consumers
18
+ get valid advice (#75)
19
+ - Keep the handler:expr: merge-key prefix — generated POM identity is unchanged (#75)
20
+ - Dependencies
21
+ - @vue/shared moves to peerDependencies (>=3.5), matching how the compiler packages are declared
22
+ (#75)
23
+ - Docs
24
+ - README and sequence-diagram updated for the action-prop contract (#75)
24
25
 
25
26
  Pull Requests Included
26
27
 
27
- - ]8;id=md-c49k8z;https://github.com/immense/vue-pom-generator/pull/76#76]8;;]8;; — ci: Deslop duplication gate + test-suite deslop wave 1 (@dkattan)]8;;
28
+ - ]8;id=md-ce95xy;https://github.com/immense/vue-pom-generator/pull/75#75]8;;]8;; — fix(pom): derive semantic action names from :loadAction as well as :handler ]8;;
29
+ (@steve-price-immybot)
28
30
 
29
31
  Testing
30
32
 
31
- - No new runtime features; existing transform, utils-coverage, class-generation, generated-tsc, and
32
- wrapper-contract suites were consolidated onto the new helpers and pass as part of the release
33
- validation.
33
+ - Extended transform coverage for action-prop matching and naming (+208 lines in
34
+ transform.test.ts), plus updates to utils-coverage, existing-id-behavior,
35
+ semantic-component-instances, and vue-test-utils-pom suites; vendor-specific naming dropped from
36
+ fixtures.
34
37
 
package/dist/index.cjs CHANGED
@@ -32,6 +32,7 @@ const compilerCore = require("@vue/compiler-core");
32
32
  const compilerDom = require("@vue/compiler-dom");
33
33
  const compilerSfc = require("@vue/compiler-sfc");
34
34
  const tsMorph = require("ts-morph");
35
+ const shared = require("@vue/shared");
35
36
  const types = require("@babel/types");
36
37
  const node_crypto = require("node:crypto");
37
38
  const router = require("./router.cjs");
@@ -1502,6 +1503,16 @@ function tryGetClickDirective(node) {
1502
1503
  function nodeHasClickDirective(node) {
1503
1504
  return tryGetClickDirective(node) !== void 0;
1504
1505
  }
1506
+ function nodeHasStaticClickDirective(node) {
1507
+ return node.props.some((prop) => {
1508
+ if (prop.type !== compilerCore.NodeTypes.DIRECTIVE) {
1509
+ return false;
1510
+ }
1511
+ const directive = prop;
1512
+ const arg = directive.arg;
1513
+ return directive.name === "on" && arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && arg.isStatic && arg.content === "click";
1514
+ });
1515
+ }
1505
1516
  function findTemplateSlotScopeExpression(node) {
1506
1517
  if (node.tag !== "template") {
1507
1518
  return null;
@@ -2216,12 +2227,40 @@ function tryGetContainedInStaticVForSourceLiteralValues(context, _node, _hierarc
2216
2227
  function getParent(hierarchyMap2, node) {
2217
2228
  return hierarchyMap2.get(node) || null;
2218
2229
  }
2219
- function nodeHandlerAttributeValue(node) {
2220
- return nodeHandlerAttributeInfo(node)?.semanticNameHint ?? null;
2230
+ function nodeHandlerAttributeValue(node, actionPropNames) {
2231
+ return nodeHandlerAttributeInfo(node, actionPropNames)?.semanticNameHint ?? null;
2232
+ }
2233
+ const LOAD_ACTION_PROP_NAMES = ["loadAction", "handler"];
2234
+ function resolveActionPropNames(wrapperConfig) {
2235
+ if (!wrapperConfig || wrapperConfig.actionProp === void 0) {
2236
+ return LOAD_ACTION_PROP_NAMES;
2237
+ }
2238
+ const declared = wrapperConfig.actionProp.trim();
2239
+ if (!declared) {
2240
+ throw new Error(
2241
+ `[vue-pom-generator] nativeWrappers actionProp must name the component's click-action prop (e.g. "loadAction"); got an empty value.`
2242
+ );
2243
+ }
2244
+ return [declared];
2245
+ }
2246
+ function findLoadActionDirective(node, actionPropNames = LOAD_ACTION_PROP_NAMES) {
2247
+ const normalizedNames = new Set(actionPropNames.map((name) => shared.camelize(name)));
2248
+ const directive = node.props.find((prop) => {
2249
+ if (prop.type !== compilerCore.NodeTypes.DIRECTIVE) {
2250
+ return false;
2251
+ }
2252
+ const candidate = prop;
2253
+ if (candidate.name !== "bind" || !candidate.exp) {
2254
+ return false;
2255
+ }
2256
+ const arg = candidate.arg;
2257
+ return arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && arg.isStatic && normalizedNames.has(shared.camelize(arg.content));
2258
+ });
2259
+ return directive ?? null;
2221
2260
  }
2222
- function nodeHandlerAttributeInfo(node) {
2223
- const handlerDirective = findDirectiveByName(node, "bind", "handler");
2224
- if (!handlerDirective?.exp) {
2261
+ function nodeHandlerAttributeInfo(node, actionPropNames) {
2262
+ const handlerDirective = findLoadActionDirective(node, actionPropNames);
2263
+ if (!handlerDirective) {
2225
2264
  return null;
2226
2265
  }
2227
2266
  const exp = handlerDirective.exp;
@@ -9987,20 +10026,29 @@ File: ${context.filename ?? "unknown"}:${loc.line}:${loc.column}`
9987
10026
  });
9988
10027
  };
9989
10028
  const { nativeWrappersValue, optionDataTestIdPrefixValue, semanticNameHint } = getNativeWrapperTransformInfo(element, componentName, resolvedNativeWrappers);
9990
- const handlerDirective = element.props.find((p) => {
9991
- return p.type === compilerCore.NodeTypes.DIRECTIVE && p.name === "bind" && p.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && p.arg.content === "handler" && !!p.exp;
9992
- }) ?? null;
9993
- const handlerInfo = handlerDirective ? nodeHandlerAttributeInfo(element) : null;
9994
- if (resolvedNativeWrappers[element.tag]?.role === "button" && handlerDirective && !handlerInfo) {
10029
+ const wrapperConfig = resolvedNativeWrappers[element.tag];
10030
+ const actionPropNames = resolveActionPropNames(wrapperConfig);
10031
+ const handlerDirective = findLoadActionDirective(element, actionPropNames);
10032
+ const handlerInfo = handlerDirective ? nodeHandlerAttributeInfo(element, actionPropNames) : null;
10033
+ if (wrapperConfig?.role === "button" && handlerDirective && !handlerInfo) {
9995
10034
  const loc = element.loc?.start;
9996
10035
  const locationHint = loc ? `${loc.line}:${loc.column}` : "unknown";
9997
10036
  const handlerSource = (handlerDirective.exp?.loc?.source ?? "").trim() || "<unknown>";
10037
+ const actionArgName = handlerDirective.arg.content;
9998
10038
  throw new Error(
9999
10039
  `[vue-pom-generator] Could not derive a semantic POM action name for button-like wrapper in ${componentName} (${context.filename ?? "unknown"}:${locationHint}).
10000
10040
  Element: <${element.tag}>
10001
10041
  Handler: ${handlerSource}
10002
10042
 
10003
- 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.`
10043
+ 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.`
10044
+ );
10045
+ }
10046
+ if (wrapperConfig?.actionProp && !handlerDirective && !nodeHasStaticClickDirective(element)) {
10047
+ const loc = element.loc?.start;
10048
+ const locationHint = loc ? `${loc.line}:${loc.column}` : "unknown";
10049
+ throw new Error(
10050
+ `[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.
10051
+ 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.`
10004
10052
  );
10005
10053
  }
10006
10054
  if (nativeWrappersValue) {
@@ -10161,7 +10209,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
10161
10209
  if (!isRecognizedInteractiveRole) {
10162
10210
  return;
10163
10211
  }
10164
- const identifierHint = getStaticIdOrNameHint(element) || nodeHandlerAttributeValue(element) || innerText || existingElementDataTestId.value || conditionalHint || void 0;
10212
+ const identifierHint = getStaticIdOrNameHint(element) || nodeHandlerAttributeValue(element, actionPropNames) || innerText || existingElementDataTestId.value || conditionalHint || void 0;
10165
10213
  const preferredGeneratedValue = existingElementDataTestId.isDynamic ? templateAttributeValue(existingElementDataTestId.template) : staticAttributeValue(existingElementDataTestId.value);
10166
10214
  applyResolvedDataTestIdForElement({
10167
10215
  preferredGeneratedValue,