@immense/vue-pom-generator 1.0.103 → 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 +32 -11
- package/class-generation/index.ts +20 -17
- package/dist/index.cjs +198 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +199 -14
- package/dist/index.mjs.map +1 -1
- package/dist/transform.d.ts.map +1 -1
- package/dist/utils.d.ts +41 -6
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { parse as parse$1, compileScript } from "@vue/compiler-sfc";
|
|
|
9
9
|
import { parseExpression, parse } from "@babel/parser";
|
|
10
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
|
-
import { isIdentifier, isObjectPattern, isRestElement, isObjectProperty, isArrayExpression, isStringLiteral, isTemplateLiteral, isArrowFunctionExpression, isExpressionStatement, isAssignmentPattern, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression, isObjectExpression, isFile, isBlockStatement, isLogicalExpression, isConditionalExpression,
|
|
12
|
+
import { isIdentifier, isObjectPattern, isRestElement, isObjectProperty, isArrayExpression, isStringLiteral, isTemplateLiteral, isArrowFunctionExpression, isExpressionStatement, isAssignmentPattern, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression, isSequenceExpression, isObjectExpression, isFile, isBlockStatement, isLogicalExpression, isConditionalExpression, isProgram, isArrayPattern, 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";
|
|
14
14
|
import vue from "@vitejs/plugin-vue";
|
|
15
15
|
import { performance } from "node:perf_hooks";
|
|
@@ -1354,6 +1354,145 @@ function findTemplateSlotScopeExpression(node) {
|
|
|
1354
1354
|
function buildSlotScopeFallbackKeyExpression(identifier) {
|
|
1355
1355
|
return `${identifier}.key ?? ${identifier}.data?.id ?? ${identifier}.id ?? ${identifier}.value ?? ${identifier}.url ?? ${identifier}`;
|
|
1356
1356
|
}
|
|
1357
|
+
function getDegenerateSlotScopeFallbackKeyVariable(expression) {
|
|
1358
|
+
if (!expression) {
|
|
1359
|
+
return null;
|
|
1360
|
+
}
|
|
1361
|
+
const trimmed = expression.trim();
|
|
1362
|
+
if (!trimmed) {
|
|
1363
|
+
return null;
|
|
1364
|
+
}
|
|
1365
|
+
const parts = splitNullishCoalescingExpression(trimmed);
|
|
1366
|
+
if (parts.length < 2) {
|
|
1367
|
+
return null;
|
|
1368
|
+
}
|
|
1369
|
+
const variableName = parts[parts.length - 1].trim();
|
|
1370
|
+
if (!variableName) {
|
|
1371
|
+
return null;
|
|
1372
|
+
}
|
|
1373
|
+
let terminalIsIdentifier;
|
|
1374
|
+
try {
|
|
1375
|
+
terminalIsIdentifier = isIdentifier(parseExpression(variableName, { plugins: ["typescript"] }));
|
|
1376
|
+
} catch {
|
|
1377
|
+
terminalIsIdentifier = false;
|
|
1378
|
+
}
|
|
1379
|
+
if (!terminalIsIdentifier) {
|
|
1380
|
+
return null;
|
|
1381
|
+
}
|
|
1382
|
+
const toMemberChainBase = (node) => {
|
|
1383
|
+
let current = node;
|
|
1384
|
+
while (isMemberExpression(current) || isOptionalMemberExpression(current)) {
|
|
1385
|
+
current = current.object;
|
|
1386
|
+
}
|
|
1387
|
+
return current;
|
|
1388
|
+
};
|
|
1389
|
+
const allMembersOfVariable = parts.slice(0, -1).every((part) => {
|
|
1390
|
+
try {
|
|
1391
|
+
const memberAst = parseExpression(part, { plugins: ["typescript"] });
|
|
1392
|
+
const base = toMemberChainBase(memberAst);
|
|
1393
|
+
return isIdentifier(base) && base.name === variableName;
|
|
1394
|
+
} catch {
|
|
1395
|
+
return false;
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1398
|
+
return allMembersOfVariable ? variableName : null;
|
|
1399
|
+
}
|
|
1400
|
+
function getSlotScopeVariablesUsedAsBareCallbackHandlers(templateNode) {
|
|
1401
|
+
const scopeExpression = findTemplateSlotScopeExpression(templateNode);
|
|
1402
|
+
if (!scopeExpression) {
|
|
1403
|
+
return [];
|
|
1404
|
+
}
|
|
1405
|
+
const scopeVariables = new Set(tryExtractSlotScopeVariableNames(scopeExpression));
|
|
1406
|
+
if (scopeVariables.size === 0) {
|
|
1407
|
+
return [];
|
|
1408
|
+
}
|
|
1409
|
+
const used = /* @__PURE__ */ new Set();
|
|
1410
|
+
const collectScopeBindings = (node) => {
|
|
1411
|
+
const names = [];
|
|
1412
|
+
const slotScope = findTemplateSlotScopeExpression(node);
|
|
1413
|
+
if (slotScope) {
|
|
1414
|
+
names.push(...tryExtractSlotScopeVariableNames(slotScope));
|
|
1415
|
+
}
|
|
1416
|
+
const vFor = node.props.find(
|
|
1417
|
+
(prop) => prop.type === NodeTypes.DIRECTIVE && prop.name === "for"
|
|
1418
|
+
);
|
|
1419
|
+
if (vFor?.exp) {
|
|
1420
|
+
const forSource = getVueExpressionSource(vFor.exp, "content", "compiled");
|
|
1421
|
+
if (forSource) {
|
|
1422
|
+
const aliasMatch = /^\s*([\s\S]+?)\s+(?:in|of)\s+[\s\S]+$/.exec(forSource);
|
|
1423
|
+
const aliasSource = aliasMatch?.[1];
|
|
1424
|
+
if (aliasSource) {
|
|
1425
|
+
try {
|
|
1426
|
+
const aliasAst = parseExpression(aliasSource, { plugins: ["typescript"] });
|
|
1427
|
+
if (isSequenceExpression(aliasAst)) {
|
|
1428
|
+
for (const part of aliasAst.expressions) {
|
|
1429
|
+
names.push(...collectBindingPatternNames(part));
|
|
1430
|
+
}
|
|
1431
|
+
} else {
|
|
1432
|
+
names.push(...collectBindingPatternNames(aliasAst));
|
|
1433
|
+
}
|
|
1434
|
+
} catch {
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1439
|
+
return names;
|
|
1440
|
+
};
|
|
1441
|
+
const visit = (current, shadowed) => {
|
|
1442
|
+
if (!current || typeof current !== "object" || !("type" in current)) {
|
|
1443
|
+
return;
|
|
1444
|
+
}
|
|
1445
|
+
if (current.type === NodeTypes.ELEMENT) {
|
|
1446
|
+
const element = current;
|
|
1447
|
+
const isSlotTemplate = element.tag === "template" && findTemplateSlotScopeExpression(element) !== null;
|
|
1448
|
+
const isForElement = element.props.some(
|
|
1449
|
+
(prop) => prop.type === NodeTypes.DIRECTIVE && prop.name === "for"
|
|
1450
|
+
);
|
|
1451
|
+
if (!isSlotTemplate && !isForElement) {
|
|
1452
|
+
const handlerName = tryGetBareCallbackClickHandlerName(element);
|
|
1453
|
+
if (handlerName && !shadowed.has(handlerName) && scopeVariables.has(handlerName)) {
|
|
1454
|
+
used.add(handlerName);
|
|
1455
|
+
}
|
|
1456
|
+
}
|
|
1457
|
+
const introduced = collectScopeBindings(element);
|
|
1458
|
+
if (introduced.length > 0) {
|
|
1459
|
+
const innerShadowed = new Set(shadowed);
|
|
1460
|
+
for (const name of introduced) {
|
|
1461
|
+
innerShadowed.add(name);
|
|
1462
|
+
}
|
|
1463
|
+
for (const child of element.children ?? []) {
|
|
1464
|
+
visit(child, innerShadowed);
|
|
1465
|
+
}
|
|
1466
|
+
return;
|
|
1467
|
+
}
|
|
1468
|
+
for (const child of element.children ?? []) {
|
|
1469
|
+
visit(child, shadowed);
|
|
1470
|
+
}
|
|
1471
|
+
return;
|
|
1472
|
+
}
|
|
1473
|
+
if (current.type === NodeTypes.ROOT) {
|
|
1474
|
+
for (const child of current.children ?? []) {
|
|
1475
|
+
visit(child, shadowed);
|
|
1476
|
+
}
|
|
1477
|
+
return;
|
|
1478
|
+
}
|
|
1479
|
+
if (current.type === NodeTypes.IF) {
|
|
1480
|
+
for (const branch of current.branches ?? []) {
|
|
1481
|
+
visit(branch, shadowed);
|
|
1482
|
+
}
|
|
1483
|
+
return;
|
|
1484
|
+
}
|
|
1485
|
+
if (current.type === NodeTypes.IF_BRANCH || current.type === NodeTypes.FOR) {
|
|
1486
|
+
for (const child of current.children ?? []) {
|
|
1487
|
+
visit(child, shadowed);
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
};
|
|
1491
|
+
for (const child of templateNode.children ?? []) {
|
|
1492
|
+
visit(child, /* @__PURE__ */ new Set());
|
|
1493
|
+
}
|
|
1494
|
+
return [...used];
|
|
1495
|
+
}
|
|
1357
1496
|
function tryGetBindingIdentifierName(node) {
|
|
1358
1497
|
if (!node) {
|
|
1359
1498
|
return null;
|
|
@@ -1510,6 +1649,39 @@ function tryGetTemplateSlotScopeKeyInfo(expression) {
|
|
|
1510
1649
|
const candidateExpression = bindingNode ? tryGetSlotScopeKeyCandidate(bindingNode)?.expression ?? null : null;
|
|
1511
1650
|
return candidateExpression ? toResolvedKeyInfo(candidateExpression) : null;
|
|
1512
1651
|
}
|
|
1652
|
+
function collectBindingPatternNames(node) {
|
|
1653
|
+
if (!node) {
|
|
1654
|
+
return [];
|
|
1655
|
+
}
|
|
1656
|
+
if (isIdentifier(node)) {
|
|
1657
|
+
return [node.name];
|
|
1658
|
+
}
|
|
1659
|
+
if (isAssignmentPattern(node)) {
|
|
1660
|
+
return collectBindingPatternNames(node.left);
|
|
1661
|
+
}
|
|
1662
|
+
if (isRestElement(node)) {
|
|
1663
|
+
return collectBindingPatternNames(node.argument);
|
|
1664
|
+
}
|
|
1665
|
+
if (isObjectPattern(node)) {
|
|
1666
|
+
const names = [];
|
|
1667
|
+
for (const property of node.properties) {
|
|
1668
|
+
if (isRestElement(property)) {
|
|
1669
|
+
names.push(...collectBindingPatternNames(property.argument));
|
|
1670
|
+
} else if (isObjectProperty(property)) {
|
|
1671
|
+
names.push(...collectBindingPatternNames(property.value));
|
|
1672
|
+
}
|
|
1673
|
+
}
|
|
1674
|
+
return names;
|
|
1675
|
+
}
|
|
1676
|
+
if (isArrayPattern(node)) {
|
|
1677
|
+
const names = [];
|
|
1678
|
+
for (const element of node.elements) {
|
|
1679
|
+
names.push(...collectBindingPatternNames(element));
|
|
1680
|
+
}
|
|
1681
|
+
return names;
|
|
1682
|
+
}
|
|
1683
|
+
return [];
|
|
1684
|
+
}
|
|
1513
1685
|
function tryExtractSlotScopeVariableNames(expression) {
|
|
1514
1686
|
const bindingNode = tryGetTemplateSlotScopeBindingNode(expression);
|
|
1515
1687
|
if (!bindingNode) {
|
|
@@ -6905,12 +7077,16 @@ Fix: give direct and slot-projected instances distinct accessible names or seman
|
|
|
6905
7077
|
const members = [];
|
|
6906
7078
|
if (isView && (componentRefsForInstances.size > 0 || attachmentsForThisClass.length > 0 || widgetInstances.length > 0)) {
|
|
6907
7079
|
members.push(...getComponentInstances(directComponentInstances, projectedComponentInstances, attachmentsForThisClass, widgetInstances));
|
|
6908
|
-
members.push(getConstructor(directComponentInstances, attachmentsForThisClass, widgetInstances, { testIdAttribute }));
|
|
6909
7080
|
}
|
|
6910
7081
|
if (!isView && (componentRefsForInstances.size > 0 || attachmentsForThisClass.length > 0)) {
|
|
6911
7082
|
members.push(...getComponentInstances(directComponentInstances, projectedComponentInstances, attachmentsForThisClass));
|
|
6912
|
-
members.push(getConstructor(directComponentInstances, attachmentsForThisClass, [], { testIdAttribute }));
|
|
6913
7083
|
}
|
|
7084
|
+
members.push(getConstructor(
|
|
7085
|
+
directComponentInstances,
|
|
7086
|
+
attachmentsForThisClass,
|
|
7087
|
+
isView ? widgetInstances : [],
|
|
7088
|
+
{ testIdAttribute }
|
|
7089
|
+
));
|
|
6914
7090
|
members.push(
|
|
6915
7091
|
...getAttachmentPassthroughMethods(componentName, dependencies, attachmentsForThisClass, reservedAttachmentPassthroughNames)
|
|
6916
7092
|
);
|
|
@@ -6955,7 +7131,6 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
|
|
|
6955
7131
|
const basePageImport = path.relative(fromAbs, toAbs).replace(/\\/g, "/");
|
|
6956
7132
|
const basePageImportNoExt = stripExtension(basePageImport).replace(/\\/g, "/");
|
|
6957
7133
|
const basePageImportSpecifier = basePageImportNoExt.startsWith(".") ? basePageImportNoExt : `./${basePageImportNoExt}`;
|
|
6958
|
-
const needsPlaywrightPageImport = prepared.isView || prepared.attachmentsForThisClass.length > 0 || prepared.componentRefsForInstances.size > 0 || prepared.widgetInstances.length > 0;
|
|
6959
7134
|
const customPomImportSpecifiersByClass = options.customPomImportSpecifiersByClass ?? {};
|
|
6960
7135
|
const customImports = Array.from(
|
|
6961
7136
|
/* @__PURE__ */ new Set([
|
|
@@ -7007,16 +7182,14 @@ function generateViewObjectModelContent(componentName, dependencies, componentHi
|
|
|
7007
7182
|
const prefixText = `${buildFilePrefix({ eslintDisableSortImports: true })}${doc}
|
|
7008
7183
|
`;
|
|
7009
7184
|
return renderSourceFile(`${prepared.className}.ts`, (sourceFile) => {
|
|
7010
|
-
|
|
7011
|
-
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
7018
|
-
});
|
|
7019
|
-
}
|
|
7185
|
+
addNamedImport(sourceFile, {
|
|
7186
|
+
moduleSpecifier: "@playwright/test",
|
|
7187
|
+
isTypeOnly: true,
|
|
7188
|
+
namedImports: [
|
|
7189
|
+
{ name: "Locator", alias: "PwLocator" },
|
|
7190
|
+
{ name: "Page", alias: "PwPage" }
|
|
7191
|
+
]
|
|
7192
|
+
});
|
|
7020
7193
|
addNamedImport(sourceFile, {
|
|
7021
7194
|
moduleSpecifier: basePageImportSpecifier,
|
|
7022
7195
|
namedImports: ["BasePage", "Fluent"]
|
|
@@ -9089,6 +9262,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
9089
9262
|
const conditionalMergeGroupByIfBranch = /* @__PURE__ */ new WeakMap();
|
|
9090
9263
|
const componentInstanceNameOwnerByName = /* @__PURE__ */ new Map();
|
|
9091
9264
|
let conditionalMergeGroupCounter = 0;
|
|
9265
|
+
const slotScopeCallbackVariablesByTemplate = /* @__PURE__ */ new WeakMap();
|
|
9092
9266
|
const getElementLocationKey = (element) => {
|
|
9093
9267
|
const startOffset = element.loc?.start.offset;
|
|
9094
9268
|
const endOffset = element.loc?.end.offset;
|
|
@@ -9165,6 +9339,12 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
9165
9339
|
}
|
|
9166
9340
|
const element = node;
|
|
9167
9341
|
const parentIsRoot = context?.parent?.type === NodeTypes.ROOT;
|
|
9342
|
+
if (element.tag === "template" && !slotScopeCallbackVariablesByTemplate.has(element)) {
|
|
9343
|
+
const callbackVariables = getSlotScopeVariablesUsedAsBareCallbackHandlers(element);
|
|
9344
|
+
if (callbackVariables.length > 0) {
|
|
9345
|
+
slotScopeCallbackVariablesByTemplate.set(element, new Set(callbackVariables));
|
|
9346
|
+
}
|
|
9347
|
+
}
|
|
9168
9348
|
const grandParent = context.grandParent;
|
|
9169
9349
|
const parentElement = !parentIsRoot && context?.parent?.type === NodeTypes.ELEMENT ? context.parent : !parentIsRoot && grandParent?.type === NodeTypes.ELEMENT ? grandParent : null;
|
|
9170
9350
|
hierarchyMap.set(element, parentElement);
|
|
@@ -9330,6 +9510,11 @@ File: ${context.filename ?? "unknown"}:${loc.line}:${loc.column}`
|
|
|
9330
9510
|
if (isSlotScopeCallbackClickHandler(element, hierarchyMap)) {
|
|
9331
9511
|
return null;
|
|
9332
9512
|
}
|
|
9513
|
+
const slotTemplateNode = getContainedInSlotTemplateNode(element, hierarchyMap);
|
|
9514
|
+
const degenerateKeyVariable = getDegenerateSlotScopeFallbackKeyVariable(slotKeyInfo.rawExpression);
|
|
9515
|
+
if (degenerateKeyVariable && slotTemplateNode && slotScopeCallbackVariablesByTemplate.get(slotTemplateNode)?.has(degenerateKeyVariable)) {
|
|
9516
|
+
return null;
|
|
9517
|
+
}
|
|
9333
9518
|
return slotKeyInfo;
|
|
9334
9519
|
}
|
|
9335
9520
|
if (crossFileKeyRegistry) {
|