@immense/vue-pom-generator 1.0.104 → 1.0.105

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/RELEASE_NOTES.md CHANGED
@@ -1,28 +1,46 @@
1
- The window query shows only #67 (and boundary case #66, which is already part of v1.0.103 since it's
2
- absent from the compare range). Let me verify the previous tag/release to confirm.
3
-
4
1
  Highlights
5
2
 
6
- - Scoped leaf POMs are now constructible: generated classes for leaf components reached through
7
- scoped slots can be instantiated without errors (#67)
3
+ - Slot-scope callbacks passed as slot props (e.g. cancel handed to a #popup-footer slot) are no
4
+ longer stringified into data-testid values — no more multi-line function source leaking into test
5
+ ids.
6
+ - Elements whose click handler references (rather than calls) a slot-scope callback now fall
7
+ through to the static testid path, producing clean ids like MonitorConfigureDialog-Save-immybutton.
8
+ - Degenerate fallback key chains (v.key ?? v.data?.id ?? … ?? v) are detected via AST and rejected
9
+ when their terminal variable is proven a callback, so generated clickSaveByKey(key) accessors are no
10
+ longer keyed by unguessable function source.
11
+ - Hand-written meaningful chains, chains over non-identifier operands, and per-iteration row-data
12
+ handlers (@click="remove(item)") are unaffected.
13
+ - Adds an integration test reproducing the exact scoped-slot shape plus unit tests for the new
14
+ chain-detection helper.
8
15
 
9
16
  Changes
10
17
 
11
- Fixed
18
+ Fixes
12
19
 
13
- - Made scoped leaf POM classes constructible during class generation, so instances of leaf
14
- components under scoped slots can be created from generated code (#67)
20
+ - Stop stringifying slot-scope callbacks into keyed test ids; affected elements emit static test
21
+ ids matching their static-text siblings ([e2106e2])
22
+ - Snapshot, at the slot <template> node before click instrumentation rewrites descendants, which
23
+ slot-scope variables are used as bare callback click handlers anywhere in slot content — closing the
24
+ gap where a sibling handler (e.g. save) inherited the degenerate chain ([2811f91])
25
+ - Add getDegenerateSlotScopeFallbackKeyVariable to recognize degenerate chains (every operand a
26
+ member chain rooted at the terminal bare identifier), including renamed destructured props like {
27
+ cancel: cancelAction } ([2811f91])
15
28
 
16
- Breaking Changes
29
+ Tests
17
30
 
18
- None.
31
+ - Integration test in tests/transform.test.ts: button-rendering child in a scoped slot with a
32
+ sibling callback handler and dynamic text — asserts a static testid containing no ??, function, or
33
+ callback source
34
+ - Unit tests in tests/utils.test.ts for getDegenerateSlotScopeFallbackKeyVariable: degenerate
35
+ chains (including renames) detected; meaningful chains, mixed operands, non-chains, and nullish
36
+ input rejected
19
37
 
20
38
  Pull Requests Included
21
39
 
22
- - #67 — fix: make scoped leaf POMs constructible (]8;id=md-bu6t21;https://github.com/immense/vue-pom-generator/pull/67#67]8;;]8;;) by @dkattan]8;;
40
+ - ]8;id=md-ec38as;https://github.com/immense/vue-pom-generator/pull/68#68]8;;]8;; — fix: stop stringifying slot-scope callbacks into keyed test ids (@dkattan)]8;;
23
41
 
24
42
  Testing
25
43
 
26
- - Added a constructibility case to tests/semantic-component-instances.test.ts, alongside the fix in
27
- class-generation/index.ts (2 files changed, +22/−17).
44
+ Full suite: 439 passed (437 before, +2 new tests plus helpers) covering the regression shape and the
45
+ new helper.
28
46
 
package/dist/index.cjs CHANGED
@@ -1395,6 +1395,145 @@ function findTemplateSlotScopeExpression(node) {
1395
1395
  function buildSlotScopeFallbackKeyExpression(identifier) {
1396
1396
  return `${identifier}.key ?? ${identifier}.data?.id ?? ${identifier}.id ?? ${identifier}.value ?? ${identifier}.url ?? ${identifier}`;
1397
1397
  }
1398
+ function getDegenerateSlotScopeFallbackKeyVariable(expression) {
1399
+ if (!expression) {
1400
+ return null;
1401
+ }
1402
+ const trimmed = expression.trim();
1403
+ if (!trimmed) {
1404
+ return null;
1405
+ }
1406
+ const parts = splitNullishCoalescingExpression(trimmed);
1407
+ if (parts.length < 2) {
1408
+ return null;
1409
+ }
1410
+ const variableName = parts[parts.length - 1].trim();
1411
+ if (!variableName) {
1412
+ return null;
1413
+ }
1414
+ let terminalIsIdentifier;
1415
+ try {
1416
+ terminalIsIdentifier = types.isIdentifier(parser.parseExpression(variableName, { plugins: ["typescript"] }));
1417
+ } catch {
1418
+ terminalIsIdentifier = false;
1419
+ }
1420
+ if (!terminalIsIdentifier) {
1421
+ return null;
1422
+ }
1423
+ const toMemberChainBase = (node) => {
1424
+ let current = node;
1425
+ while (types.isMemberExpression(current) || types.isOptionalMemberExpression(current)) {
1426
+ current = current.object;
1427
+ }
1428
+ return current;
1429
+ };
1430
+ const allMembersOfVariable = parts.slice(0, -1).every((part) => {
1431
+ try {
1432
+ const memberAst = parser.parseExpression(part, { plugins: ["typescript"] });
1433
+ const base = toMemberChainBase(memberAst);
1434
+ return types.isIdentifier(base) && base.name === variableName;
1435
+ } catch {
1436
+ return false;
1437
+ }
1438
+ });
1439
+ return allMembersOfVariable ? variableName : null;
1440
+ }
1441
+ function getSlotScopeVariablesUsedAsBareCallbackHandlers(templateNode) {
1442
+ const scopeExpression = findTemplateSlotScopeExpression(templateNode);
1443
+ if (!scopeExpression) {
1444
+ return [];
1445
+ }
1446
+ const scopeVariables = new Set(tryExtractSlotScopeVariableNames(scopeExpression));
1447
+ if (scopeVariables.size === 0) {
1448
+ return [];
1449
+ }
1450
+ const used = /* @__PURE__ */ new Set();
1451
+ const collectScopeBindings = (node) => {
1452
+ const names = [];
1453
+ const slotScope = findTemplateSlotScopeExpression(node);
1454
+ if (slotScope) {
1455
+ names.push(...tryExtractSlotScopeVariableNames(slotScope));
1456
+ }
1457
+ const vFor = node.props.find(
1458
+ (prop) => prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "for"
1459
+ );
1460
+ if (vFor?.exp) {
1461
+ const forSource = getVueExpressionSource(vFor.exp, "content", "compiled");
1462
+ if (forSource) {
1463
+ const aliasMatch = /^\s*([\s\S]+?)\s+(?:in|of)\s+[\s\S]+$/.exec(forSource);
1464
+ const aliasSource = aliasMatch?.[1];
1465
+ if (aliasSource) {
1466
+ try {
1467
+ const aliasAst = parser.parseExpression(aliasSource, { plugins: ["typescript"] });
1468
+ if (types.isSequenceExpression(aliasAst)) {
1469
+ for (const part of aliasAst.expressions) {
1470
+ names.push(...collectBindingPatternNames(part));
1471
+ }
1472
+ } else {
1473
+ names.push(...collectBindingPatternNames(aliasAst));
1474
+ }
1475
+ } catch {
1476
+ }
1477
+ }
1478
+ }
1479
+ }
1480
+ return names;
1481
+ };
1482
+ const visit = (current, shadowed) => {
1483
+ if (!current || typeof current !== "object" || !("type" in current)) {
1484
+ return;
1485
+ }
1486
+ if (current.type === compilerCore.NodeTypes.ELEMENT) {
1487
+ const element = current;
1488
+ const isSlotTemplate = element.tag === "template" && findTemplateSlotScopeExpression(element) !== null;
1489
+ const isForElement = element.props.some(
1490
+ (prop) => prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "for"
1491
+ );
1492
+ if (!isSlotTemplate && !isForElement) {
1493
+ const handlerName = tryGetBareCallbackClickHandlerName(element);
1494
+ if (handlerName && !shadowed.has(handlerName) && scopeVariables.has(handlerName)) {
1495
+ used.add(handlerName);
1496
+ }
1497
+ }
1498
+ const introduced = collectScopeBindings(element);
1499
+ if (introduced.length > 0) {
1500
+ const innerShadowed = new Set(shadowed);
1501
+ for (const name of introduced) {
1502
+ innerShadowed.add(name);
1503
+ }
1504
+ for (const child of element.children ?? []) {
1505
+ visit(child, innerShadowed);
1506
+ }
1507
+ return;
1508
+ }
1509
+ for (const child of element.children ?? []) {
1510
+ visit(child, shadowed);
1511
+ }
1512
+ return;
1513
+ }
1514
+ if (current.type === compilerCore.NodeTypes.ROOT) {
1515
+ for (const child of current.children ?? []) {
1516
+ visit(child, shadowed);
1517
+ }
1518
+ return;
1519
+ }
1520
+ if (current.type === compilerCore.NodeTypes.IF) {
1521
+ for (const branch of current.branches ?? []) {
1522
+ visit(branch, shadowed);
1523
+ }
1524
+ return;
1525
+ }
1526
+ if (current.type === compilerCore.NodeTypes.IF_BRANCH || current.type === compilerCore.NodeTypes.FOR) {
1527
+ for (const child of current.children ?? []) {
1528
+ visit(child, shadowed);
1529
+ }
1530
+ }
1531
+ };
1532
+ for (const child of templateNode.children ?? []) {
1533
+ visit(child, /* @__PURE__ */ new Set());
1534
+ }
1535
+ return [...used];
1536
+ }
1398
1537
  function tryGetBindingIdentifierName(node) {
1399
1538
  if (!node) {
1400
1539
  return null;
@@ -1551,6 +1690,39 @@ function tryGetTemplateSlotScopeKeyInfo(expression) {
1551
1690
  const candidateExpression = bindingNode ? tryGetSlotScopeKeyCandidate(bindingNode)?.expression ?? null : null;
1552
1691
  return candidateExpression ? toResolvedKeyInfo(candidateExpression) : null;
1553
1692
  }
1693
+ function collectBindingPatternNames(node) {
1694
+ if (!node) {
1695
+ return [];
1696
+ }
1697
+ if (types.isIdentifier(node)) {
1698
+ return [node.name];
1699
+ }
1700
+ if (types.isAssignmentPattern(node)) {
1701
+ return collectBindingPatternNames(node.left);
1702
+ }
1703
+ if (types.isRestElement(node)) {
1704
+ return collectBindingPatternNames(node.argument);
1705
+ }
1706
+ if (types.isObjectPattern(node)) {
1707
+ const names = [];
1708
+ for (const property of node.properties) {
1709
+ if (types.isRestElement(property)) {
1710
+ names.push(...collectBindingPatternNames(property.argument));
1711
+ } else if (types.isObjectProperty(property)) {
1712
+ names.push(...collectBindingPatternNames(property.value));
1713
+ }
1714
+ }
1715
+ return names;
1716
+ }
1717
+ if (types.isArrayPattern(node)) {
1718
+ const names = [];
1719
+ for (const element of node.elements) {
1720
+ names.push(...collectBindingPatternNames(element));
1721
+ }
1722
+ return names;
1723
+ }
1724
+ return [];
1725
+ }
1554
1726
  function tryExtractSlotScopeVariableNames(expression) {
1555
1727
  const bindingNode = tryGetTemplateSlotScopeBindingNode(expression);
1556
1728
  if (!bindingNode) {
@@ -9131,6 +9303,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
9131
9303
  const conditionalMergeGroupByIfBranch = /* @__PURE__ */ new WeakMap();
9132
9304
  const componentInstanceNameOwnerByName = /* @__PURE__ */ new Map();
9133
9305
  let conditionalMergeGroupCounter = 0;
9306
+ const slotScopeCallbackVariablesByTemplate = /* @__PURE__ */ new WeakMap();
9134
9307
  const getElementLocationKey = (element) => {
9135
9308
  const startOffset = element.loc?.start.offset;
9136
9309
  const endOffset = element.loc?.end.offset;
@@ -9207,6 +9380,12 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
9207
9380
  }
9208
9381
  const element = node;
9209
9382
  const parentIsRoot = context?.parent?.type === compilerCore.NodeTypes.ROOT;
9383
+ if (element.tag === "template" && !slotScopeCallbackVariablesByTemplate.has(element)) {
9384
+ const callbackVariables = getSlotScopeVariablesUsedAsBareCallbackHandlers(element);
9385
+ if (callbackVariables.length > 0) {
9386
+ slotScopeCallbackVariablesByTemplate.set(element, new Set(callbackVariables));
9387
+ }
9388
+ }
9210
9389
  const grandParent = context.grandParent;
9211
9390
  const parentElement = !parentIsRoot && context?.parent?.type === compilerCore.NodeTypes.ELEMENT ? context.parent : !parentIsRoot && grandParent?.type === compilerCore.NodeTypes.ELEMENT ? grandParent : null;
9212
9391
  hierarchyMap.set(element, parentElement);
@@ -9372,6 +9551,11 @@ File: ${context.filename ?? "unknown"}:${loc.line}:${loc.column}`
9372
9551
  if (isSlotScopeCallbackClickHandler(element, hierarchyMap)) {
9373
9552
  return null;
9374
9553
  }
9554
+ const slotTemplateNode = getContainedInSlotTemplateNode(element, hierarchyMap);
9555
+ const degenerateKeyVariable = getDegenerateSlotScopeFallbackKeyVariable(slotKeyInfo.rawExpression);
9556
+ if (degenerateKeyVariable && slotTemplateNode && slotScopeCallbackVariablesByTemplate.get(slotTemplateNode)?.has(degenerateKeyVariable)) {
9557
+ return null;
9558
+ }
9375
9559
  return slotKeyInfo;
9376
9560
  }
9377
9561
  if (crossFileKeyRegistry) {