@immense/vue-pom-generator 1.0.93 → 1.0.94
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 +17 -17
- package/RELEASE_NOTES.md +68 -21
- package/dist/index.cjs +789 -296
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +790 -297
- package/dist/index.mjs.map +1 -1
- package/dist/plugin/create-vue-pom-generator-plugins.d.ts.map +1 -1
- package/dist/plugin/internal/build-plugin.d.ts +1 -1
- package/dist/plugin/internal/build-plugin.d.ts.map +1 -1
- package/dist/plugin/internal/dev-plugin.d.ts +1 -1
- package/dist/plugin/internal/dev-plugin.d.ts.map +1 -1
- package/dist/plugin/internal-plugins.d.ts +1 -1
- package/dist/plugin/internal-plugins.d.ts.map +1 -1
- package/dist/plugin/resolved-injection-options.d.ts +2 -2
- package/dist/plugin/resolved-injection-options.d.ts.map +1 -1
- package/dist/plugin/types.d.ts +13 -7
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/vue-plugin.d.ts +1 -1
- package/dist/plugin/vue-plugin.d.ts.map +1 -1
- package/dist/tests/wrapper-contract.test.d.ts +2 -0
- package/dist/tests/wrapper-contract.test.d.ts.map +1 -0
- package/dist/transform.d.ts +6 -12
- package/dist/transform.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/wrapper-contract.d.ts +37 -0
- package/dist/wrapper-contract.d.ts.map +1 -0
- 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, ConstantTypes, createSimpleExpression, 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, isSequenceExpression, isProgram, VISITOR_KEYS, isBooleanLiteral, isNumericLiteral, isNullLiteral } from "@babel/types";
|
|
12
|
+
import { isIdentifier, isObjectPattern, isRestElement, isObjectProperty, isArrayExpression, isStringLiteral, isTemplateLiteral, isArrowFunctionExpression, isExpressionStatement, isAssignmentPattern, isMemberExpression, isOptionalMemberExpression, isCallExpression, isOptionalCallExpression, isAssignmentExpression, isObjectExpression, isFile, isBlockStatement, isLogicalExpression, isConditionalExpression, isSequenceExpression, isProgram, 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";
|
|
@@ -238,7 +238,7 @@ function resolveInjectionSupportOptions(options) {
|
|
|
238
238
|
wrapperSearchRoots: isNuxt ? [] : options.wrapperSearchRoots ?? [],
|
|
239
239
|
nativeWrappers: options.nativeWrappers ?? {},
|
|
240
240
|
optionKeyAttribute: options.optionKeyAttribute ?? {},
|
|
241
|
-
|
|
241
|
+
skipTestIdGenerationInsideComponents: options.skipTestIdGenerationInsideComponents ?? [],
|
|
242
242
|
existingIdBehavior: options.existingIdBehavior ?? "error",
|
|
243
243
|
testIdAttribute: (options.testIdAttribute ?? "data-testid").trim() || "data-testid"
|
|
244
244
|
};
|
|
@@ -1205,20 +1205,20 @@ function upperFirst(value) {
|
|
|
1205
1205
|
function collapseWhitespace(value) {
|
|
1206
1206
|
return value.replace(/\s+/g, " ").trim();
|
|
1207
1207
|
}
|
|
1208
|
-
function isAsciiUppercaseLetterCode(code) {
|
|
1208
|
+
function isAsciiUppercaseLetterCode$1(code) {
|
|
1209
1209
|
return code >= 65 && code <= 90;
|
|
1210
1210
|
}
|
|
1211
1211
|
function isAsciiLowercaseLetterCode(code) {
|
|
1212
1212
|
return code >= 97 && code <= 122;
|
|
1213
1213
|
}
|
|
1214
|
-
function isAsciiLetterCode(code) {
|
|
1215
|
-
return isAsciiUppercaseLetterCode(code) || isAsciiLowercaseLetterCode(code);
|
|
1214
|
+
function isAsciiLetterCode$1(code) {
|
|
1215
|
+
return isAsciiUppercaseLetterCode$1(code) || isAsciiLowercaseLetterCode(code);
|
|
1216
1216
|
}
|
|
1217
|
-
function isAsciiDigitCode(code) {
|
|
1217
|
+
function isAsciiDigitCode$1(code) {
|
|
1218
1218
|
return code >= 48 && code <= 57;
|
|
1219
1219
|
}
|
|
1220
1220
|
function isAsciiAlphaNumericCode(code) {
|
|
1221
|
-
return isAsciiLetterCode(code) || isAsciiDigitCode(code);
|
|
1221
|
+
return isAsciiLetterCode$1(code) || isAsciiDigitCode$1(code);
|
|
1222
1222
|
}
|
|
1223
1223
|
function staticAttributeValue(value) {
|
|
1224
1224
|
return { kind: "static", value };
|
|
@@ -2265,13 +2265,17 @@ function getNativeWrapperTransformInfo(node, componentName, nativeWrappers) {
|
|
|
2265
2265
|
if (nodeHasClickDirective(node) && role === "button") {
|
|
2266
2266
|
return { nativeWrappersValue: null, optionDataTestIdPrefixValue: null, semanticNameHint: null };
|
|
2267
2267
|
}
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2268
|
+
const inferredValueAttribute = inferred && !valueAttribute ? ["aria-label", "name", "id", "title", "label"].find((attributeName) => {
|
|
2269
|
+
return !!findAttributeByKey(node, attributeName) || !!findDirectiveByName(node, "bind", attributeName);
|
|
2270
|
+
}) : void 0;
|
|
2271
|
+
const resolvedValueAttribute = valueAttribute ?? inferredValueAttribute;
|
|
2272
|
+
if (resolvedValueAttribute) {
|
|
2273
|
+
const value = getDataTestIdValueFromValueAttribute(node, componentName, resolvedValueAttribute, role);
|
|
2274
|
+
const attrStatic = findAttributeByKey(node, resolvedValueAttribute);
|
|
2271
2275
|
if (attrStatic?.value?.content) {
|
|
2272
2276
|
return { nativeWrappersValue: value || null, optionDataTestIdPrefixValue: null, semanticNameHint: attrStatic.value.content };
|
|
2273
2277
|
}
|
|
2274
|
-
const attrDynamic = findDirectiveByName(node, "bind",
|
|
2278
|
+
const attrDynamic = findDirectiveByName(node, "bind", resolvedValueAttribute);
|
|
2275
2279
|
if (attrDynamic && "exp" in attrDynamic && attrDynamic.exp && "ast" in attrDynamic.exp && attrDynamic.exp.ast) {
|
|
2276
2280
|
const { name } = getClickHandlerNameFromAst(attrDynamic.exp.ast);
|
|
2277
2281
|
if (name) {
|
|
@@ -2852,8 +2856,8 @@ function isAllCapsOrDigits(value) {
|
|
|
2852
2856
|
}
|
|
2853
2857
|
for (let i = 0; i < value.length; i++) {
|
|
2854
2858
|
const c = value.charCodeAt(i);
|
|
2855
|
-
const isUpper = isAsciiUppercaseLetterCode(c);
|
|
2856
|
-
const isDigit = isAsciiDigitCode(c);
|
|
2859
|
+
const isUpper = isAsciiUppercaseLetterCode$1(c);
|
|
2860
|
+
const isDigit = isAsciiDigitCode$1(c);
|
|
2857
2861
|
if (!isUpper && !isDigit) {
|
|
2858
2862
|
return false;
|
|
2859
2863
|
}
|
|
@@ -2865,7 +2869,7 @@ function startsWithDigit(value) {
|
|
|
2865
2869
|
return false;
|
|
2866
2870
|
}
|
|
2867
2871
|
const c = value.charCodeAt(0);
|
|
2868
|
-
return isAsciiDigitCode(c);
|
|
2872
|
+
return isAsciiDigitCode$1(c);
|
|
2869
2873
|
}
|
|
2870
2874
|
function stripNonIdentifierChars(value) {
|
|
2871
2875
|
let out = "";
|
|
@@ -3904,10 +3908,10 @@ function debugLog(message) {
|
|
|
3904
3908
|
}
|
|
3905
3909
|
}
|
|
3906
3910
|
function isIdentifierStartCode(code) {
|
|
3907
|
-
return code === 95 || code === 36 || isAsciiLetterCode(code);
|
|
3911
|
+
return code === 95 || code === 36 || isAsciiLetterCode$1(code);
|
|
3908
3912
|
}
|
|
3909
3913
|
function isIdentifierPartCode(code) {
|
|
3910
|
-
return isIdentifierStartCode(code) || isAsciiDigitCode(code);
|
|
3914
|
+
return isIdentifierStartCode(code) || isAsciiDigitCode$1(code);
|
|
3911
3915
|
}
|
|
3912
3916
|
function isValidJsIdentifier(name) {
|
|
3913
3917
|
if (!name.length)
|
|
@@ -7411,10 +7415,17 @@ function getConstructor(childrenComponent, componentHierarchyMap, attachmentsFor
|
|
|
7411
7415
|
});
|
|
7412
7416
|
}
|
|
7413
7417
|
const TESTID_CLICK_EVENT_NAME = "__testid_event__";
|
|
7414
|
-
const CLICK_EVENT_NAME = TESTID_CLICK_EVENT_NAME;
|
|
7415
|
-
const inferredNativeWrapperConfigByLookup = /* @__PURE__ */ new Map();
|
|
7416
|
-
const inferredSfcPathByLookup = /* @__PURE__ */ new Map();
|
|
7417
7418
|
const indexedVueSfcPathsByRoots = /* @__PURE__ */ new Map();
|
|
7419
|
+
const resolvedSfcPathByLookup = /* @__PURE__ */ new Map();
|
|
7420
|
+
function isAsciiUppercaseLetterCode(code) {
|
|
7421
|
+
return code >= 65 && code <= 90;
|
|
7422
|
+
}
|
|
7423
|
+
function isAsciiLetterCode(code) {
|
|
7424
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
7425
|
+
}
|
|
7426
|
+
function isAsciiDigitCode(code) {
|
|
7427
|
+
return code >= 48 && code <= 57;
|
|
7428
|
+
}
|
|
7418
7429
|
function toKebabCaseTag(tag) {
|
|
7419
7430
|
let result = "";
|
|
7420
7431
|
let previousWasSeparator = false;
|
|
@@ -7430,8 +7441,7 @@ function toKebabCaseTag(tag) {
|
|
|
7430
7441
|
}
|
|
7431
7442
|
const previous = i > 0 ? tag[i - 1] : "";
|
|
7432
7443
|
const previousCode = previous ? previous.charCodeAt(0) : 0;
|
|
7433
|
-
const
|
|
7434
|
-
const shouldInsertSeparator = hasPrevious && isAsciiUppercaseLetterCode(code) && (isAsciiLetterCode(previousCode) || isAsciiDigitCode(previousCode)) && !previousWasSeparator;
|
|
7444
|
+
const shouldInsertSeparator = i > 0 && isAsciiUppercaseLetterCode(code) && (isAsciiLetterCode(previousCode) || isAsciiDigitCode(previousCode)) && !previousWasSeparator;
|
|
7435
7445
|
if (shouldInsertSeparator) {
|
|
7436
7446
|
result += "-";
|
|
7437
7447
|
}
|
|
@@ -7440,90 +7450,7 @@ function toKebabCaseTag(tag) {
|
|
|
7440
7450
|
}
|
|
7441
7451
|
return result;
|
|
7442
7452
|
}
|
|
7443
|
-
function
|
|
7444
|
-
const attr = element.props.find((prop) => {
|
|
7445
|
-
return prop.type === NodeTypes.ATTRIBUTE && prop.name === name;
|
|
7446
|
-
});
|
|
7447
|
-
return attr?.value?.content?.trim() || null;
|
|
7448
|
-
}
|
|
7449
|
-
function getNativeHtmlControlRole(element) {
|
|
7450
|
-
const tag = (element.tag || "").toLowerCase();
|
|
7451
|
-
const type = (getStaticAttributeContent(element, "type") || "").toLowerCase();
|
|
7452
|
-
if (tag === "textarea") {
|
|
7453
|
-
return "input";
|
|
7454
|
-
}
|
|
7455
|
-
if (tag === "select") {
|
|
7456
|
-
return "select";
|
|
7457
|
-
}
|
|
7458
|
-
if (tag !== "input") {
|
|
7459
|
-
return null;
|
|
7460
|
-
}
|
|
7461
|
-
if (type === "radio") {
|
|
7462
|
-
return "radio";
|
|
7463
|
-
}
|
|
7464
|
-
if (type === "checkbox") {
|
|
7465
|
-
return "checkbox";
|
|
7466
|
-
}
|
|
7467
|
-
return "input";
|
|
7468
|
-
}
|
|
7469
|
-
function normalizeControlLabelText(value) {
|
|
7470
|
-
const normalized = (value ?? "").replace(/\*/g, " ").replace(/\s+/g, " ").trim();
|
|
7471
|
-
return normalized || null;
|
|
7472
|
-
}
|
|
7473
|
-
function getLabelNodeText(labelNode) {
|
|
7474
|
-
for (const child of labelNode.children || []) {
|
|
7475
|
-
if (child.type === NodeTypes.TEXT) {
|
|
7476
|
-
const normalized2 = normalizeControlLabelText(child.content);
|
|
7477
|
-
if (normalized2) {
|
|
7478
|
-
return normalized2;
|
|
7479
|
-
}
|
|
7480
|
-
continue;
|
|
7481
|
-
}
|
|
7482
|
-
if (child.type !== NodeTypes.ELEMENT) {
|
|
7483
|
-
continue;
|
|
7484
|
-
}
|
|
7485
|
-
if (getNativeHtmlControlRole(child)) {
|
|
7486
|
-
continue;
|
|
7487
|
-
}
|
|
7488
|
-
const normalized = normalizeControlLabelText(getInnerText(child));
|
|
7489
|
-
if (normalized) {
|
|
7490
|
-
return normalized;
|
|
7491
|
-
}
|
|
7492
|
-
}
|
|
7493
|
-
return normalizeControlLabelText(getInnerText(labelNode));
|
|
7494
|
-
}
|
|
7495
|
-
function getAssociatedLabelText(element, hierarchyMap2) {
|
|
7496
|
-
let parent = hierarchyMap2.get(element) || null;
|
|
7497
|
-
while (parent) {
|
|
7498
|
-
if (parent.tag === "label") {
|
|
7499
|
-
return getLabelNodeText(parent);
|
|
7500
|
-
}
|
|
7501
|
-
parent = hierarchyMap2.get(parent) || null;
|
|
7502
|
-
}
|
|
7503
|
-
const id = getStaticAttributeContent(element, "id");
|
|
7504
|
-
if (!id) {
|
|
7505
|
-
return null;
|
|
7506
|
-
}
|
|
7507
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
7508
|
-
for (const child of hierarchyMap2.keys()) {
|
|
7509
|
-
candidates.add(child);
|
|
7510
|
-
}
|
|
7511
|
-
for (const maybeParent of hierarchyMap2.values()) {
|
|
7512
|
-
if (maybeParent) {
|
|
7513
|
-
candidates.add(maybeParent);
|
|
7514
|
-
}
|
|
7515
|
-
}
|
|
7516
|
-
for (const candidate of candidates) {
|
|
7517
|
-
if (candidate.tag !== "label") {
|
|
7518
|
-
continue;
|
|
7519
|
-
}
|
|
7520
|
-
if (getStaticAttributeContent(candidate, "for") === id) {
|
|
7521
|
-
return getLabelNodeText(candidate);
|
|
7522
|
-
}
|
|
7523
|
-
}
|
|
7524
|
-
return null;
|
|
7525
|
-
}
|
|
7526
|
-
function normalizeSearchRoots(wrapperSearchRoots) {
|
|
7453
|
+
function normalizeWrapperSearchRoots(wrapperSearchRoots) {
|
|
7527
7454
|
const normalized = /* @__PURE__ */ new Set();
|
|
7528
7455
|
for (const root of wrapperSearchRoots) {
|
|
7529
7456
|
const resolved = path.resolve(root);
|
|
@@ -7598,14 +7525,14 @@ function buildVueSfcPathIndex(searchRoots) {
|
|
|
7598
7525
|
indexedVueSfcPathsByRoots.set(indexKey, index);
|
|
7599
7526
|
return index;
|
|
7600
7527
|
}
|
|
7601
|
-
function
|
|
7528
|
+
function resolveSfcPathForTag(tag, vueFilesPathMap, wrapperSearchRoots = []) {
|
|
7602
7529
|
const registeredPath = vueFilesPathMap?.get(tag);
|
|
7603
|
-
const normalizedSearchRoots =
|
|
7530
|
+
const normalizedSearchRoots = normalizeWrapperSearchRoots(wrapperSearchRoots);
|
|
7604
7531
|
const lookupKey = `${tag}
|
|
7605
7532
|
${registeredPath ?? ""}
|
|
7606
7533
|
${buildSearchRootsKey(normalizedSearchRoots)}`;
|
|
7607
|
-
if (
|
|
7608
|
-
return
|
|
7534
|
+
if (resolvedSfcPathByLookup.has(lookupKey)) {
|
|
7535
|
+
return resolvedSfcPathByLookup.get(lookupKey) ?? null;
|
|
7609
7536
|
}
|
|
7610
7537
|
const candidateNames = [`${tag}.vue`, `${toKebabCaseTag(tag)}.vue`];
|
|
7611
7538
|
const directCandidates = [
|
|
@@ -7614,11 +7541,11 @@ ${buildSearchRootsKey(normalizedSearchRoots)}`;
|
|
|
7614
7541
|
].filter((value) => !!value);
|
|
7615
7542
|
const directMatch = directCandidates.find((candidatePath) => fs.existsSync(candidatePath));
|
|
7616
7543
|
if (directMatch) {
|
|
7617
|
-
|
|
7544
|
+
resolvedSfcPathByLookup.set(lookupKey, directMatch);
|
|
7618
7545
|
return directMatch;
|
|
7619
7546
|
}
|
|
7620
7547
|
if (normalizedSearchRoots.length === 0) {
|
|
7621
|
-
|
|
7548
|
+
resolvedSfcPathByLookup.set(lookupKey, null);
|
|
7622
7549
|
return null;
|
|
7623
7550
|
}
|
|
7624
7551
|
const index = buildVueSfcPathIndex(normalizedSearchRoots);
|
|
@@ -7645,9 +7572,685 @@ ${buildSearchRootsKey(normalizedSearchRoots)}`;
|
|
|
7645
7572
|
}
|
|
7646
7573
|
}
|
|
7647
7574
|
}
|
|
7648
|
-
|
|
7575
|
+
resolvedSfcPathByLookup.set(lookupKey, bestMatch);
|
|
7649
7576
|
return bestMatch;
|
|
7650
7577
|
}
|
|
7578
|
+
function walkBabel(node, visitor) {
|
|
7579
|
+
visitor(node);
|
|
7580
|
+
const keys = VISITOR_KEYS[node.type] ?? [];
|
|
7581
|
+
const record = node;
|
|
7582
|
+
for (const key of keys) {
|
|
7583
|
+
const value = record[key];
|
|
7584
|
+
if (Array.isArray(value)) {
|
|
7585
|
+
for (const child of value) {
|
|
7586
|
+
if (child && typeof child === "object" && "type" in child) {
|
|
7587
|
+
walkBabel(child, visitor);
|
|
7588
|
+
}
|
|
7589
|
+
}
|
|
7590
|
+
continue;
|
|
7591
|
+
}
|
|
7592
|
+
if (value && typeof value === "object" && "type" in value) {
|
|
7593
|
+
walkBabel(value, visitor);
|
|
7594
|
+
}
|
|
7595
|
+
}
|
|
7596
|
+
}
|
|
7597
|
+
function unwrapExpression(expression) {
|
|
7598
|
+
let current = expression;
|
|
7599
|
+
while (isTSAsExpression(current) || isTSTypeAssertion(current) || isTSNonNullExpression(current)) {
|
|
7600
|
+
current = current.expression;
|
|
7601
|
+
}
|
|
7602
|
+
return current;
|
|
7603
|
+
}
|
|
7604
|
+
function getStaticObjectKey(node) {
|
|
7605
|
+
if (isIdentifier(node)) {
|
|
7606
|
+
return node.name;
|
|
7607
|
+
}
|
|
7608
|
+
if (isStringLiteral(node)) {
|
|
7609
|
+
return node.value;
|
|
7610
|
+
}
|
|
7611
|
+
return null;
|
|
7612
|
+
}
|
|
7613
|
+
function getBooleanObjectProperty(object, propertyName) {
|
|
7614
|
+
for (const property of object.properties) {
|
|
7615
|
+
if (!isObjectProperty(property) || property.computed) {
|
|
7616
|
+
continue;
|
|
7617
|
+
}
|
|
7618
|
+
if (getStaticObjectKey(property.key) !== propertyName || !isBooleanLiteral(property.value)) {
|
|
7619
|
+
continue;
|
|
7620
|
+
}
|
|
7621
|
+
return property.value.value;
|
|
7622
|
+
}
|
|
7623
|
+
return null;
|
|
7624
|
+
}
|
|
7625
|
+
function getOptionsObject(expression) {
|
|
7626
|
+
if (!expression) {
|
|
7627
|
+
return null;
|
|
7628
|
+
}
|
|
7629
|
+
const unwrapped = unwrapExpression(expression);
|
|
7630
|
+
if (isObjectExpression(unwrapped)) {
|
|
7631
|
+
return unwrapped;
|
|
7632
|
+
}
|
|
7633
|
+
if (!isCallExpression(unwrapped) || unwrapped.arguments.length === 0) {
|
|
7634
|
+
return null;
|
|
7635
|
+
}
|
|
7636
|
+
const firstArgument = unwrapped.arguments[0];
|
|
7637
|
+
return firstArgument && isObjectExpression(firstArgument) ? firstArgument : null;
|
|
7638
|
+
}
|
|
7639
|
+
function parseScriptStatements(source, lang) {
|
|
7640
|
+
if (!source.trim()) {
|
|
7641
|
+
return [];
|
|
7642
|
+
}
|
|
7643
|
+
const plugins = ["decorators-legacy"];
|
|
7644
|
+
if (lang === "ts" || lang === "tsx") {
|
|
7645
|
+
plugins.push("typescript");
|
|
7646
|
+
}
|
|
7647
|
+
if (lang === "jsx" || lang === "tsx") {
|
|
7648
|
+
plugins.push("jsx");
|
|
7649
|
+
}
|
|
7650
|
+
return parse(source, { sourceType: "module", plugins }).program.body;
|
|
7651
|
+
}
|
|
7652
|
+
function getFunctionBody(functionNode) {
|
|
7653
|
+
return functionNode.body;
|
|
7654
|
+
}
|
|
7655
|
+
function findFunctionDeclarations(statements) {
|
|
7656
|
+
const functions = /* @__PURE__ */ new Map();
|
|
7657
|
+
for (const statement of statements) {
|
|
7658
|
+
if (isFunctionDeclaration(statement) && statement.id) {
|
|
7659
|
+
functions.set(statement.id.name, statement);
|
|
7660
|
+
continue;
|
|
7661
|
+
}
|
|
7662
|
+
if (!isVariableDeclaration(statement)) {
|
|
7663
|
+
continue;
|
|
7664
|
+
}
|
|
7665
|
+
for (const declaration of statement.declarations) {
|
|
7666
|
+
if (!isIdentifier(declaration.id) || !declaration.init) {
|
|
7667
|
+
continue;
|
|
7668
|
+
}
|
|
7669
|
+
const init = isExpression(declaration.init) ? unwrapExpression(declaration.init) : declaration.init;
|
|
7670
|
+
if (isArrowFunctionExpression(init) || isFunctionExpression(init)) {
|
|
7671
|
+
functions.set(declaration.id.name, init);
|
|
7672
|
+
}
|
|
7673
|
+
}
|
|
7674
|
+
}
|
|
7675
|
+
return functions;
|
|
7676
|
+
}
|
|
7677
|
+
function expressionForwardsTestId(expression, testIdAttribute, attrsObjectNames, attrsFunctionNames) {
|
|
7678
|
+
const unwrapped = unwrapExpression(expression);
|
|
7679
|
+
if (isIdentifier(unwrapped)) {
|
|
7680
|
+
return attrsObjectNames.has(unwrapped.name);
|
|
7681
|
+
}
|
|
7682
|
+
if (isCallExpression(unwrapped) && isIdentifier(unwrapped.callee)) {
|
|
7683
|
+
return attrsFunctionNames.has(unwrapped.callee.name);
|
|
7684
|
+
}
|
|
7685
|
+
if (isObjectExpression(unwrapped)) {
|
|
7686
|
+
let forwards = false;
|
|
7687
|
+
for (const property of unwrapped.properties) {
|
|
7688
|
+
if (property.type === "SpreadElement") {
|
|
7689
|
+
forwards = isExpression(property.argument) && expressionForwardsTestId(property.argument, testIdAttribute, attrsObjectNames, attrsFunctionNames);
|
|
7690
|
+
continue;
|
|
7691
|
+
}
|
|
7692
|
+
if (property.computed) {
|
|
7693
|
+
forwards = false;
|
|
7694
|
+
continue;
|
|
7695
|
+
}
|
|
7696
|
+
if (getStaticObjectKey(property.key) === testIdAttribute) {
|
|
7697
|
+
forwards = isObjectProperty(property) && isExpression(property.value) && expressionReadsTestId(property.value, testIdAttribute, attrsObjectNames, attrsFunctionNames);
|
|
7698
|
+
}
|
|
7699
|
+
}
|
|
7700
|
+
return forwards;
|
|
7701
|
+
}
|
|
7702
|
+
return false;
|
|
7703
|
+
}
|
|
7704
|
+
function expressionReadsTestId(expression, testIdAttribute, attrsObjectNames, attrsFunctionNames) {
|
|
7705
|
+
const unwrapped = unwrapExpression(expression);
|
|
7706
|
+
if (!isMemberExpression(unwrapped) || !isExpression(unwrapped.object)) {
|
|
7707
|
+
return false;
|
|
7708
|
+
}
|
|
7709
|
+
if (!expressionForwardsTestId(unwrapped.object, testIdAttribute, attrsObjectNames, attrsFunctionNames)) {
|
|
7710
|
+
return false;
|
|
7711
|
+
}
|
|
7712
|
+
if (!unwrapped.computed && isIdentifier(unwrapped.property)) {
|
|
7713
|
+
return unwrapped.property.name === testIdAttribute;
|
|
7714
|
+
}
|
|
7715
|
+
return isStringLiteral(unwrapped.property) && unwrapped.property.value === testIdAttribute;
|
|
7716
|
+
}
|
|
7717
|
+
function collectExcludedKeys(expression, keyName) {
|
|
7718
|
+
const unwrapped = unwrapExpression(expression);
|
|
7719
|
+
if (isLogicalExpression(unwrapped) && unwrapped.operator === "&&") {
|
|
7720
|
+
const left = collectExcludedKeys(unwrapped.left, keyName);
|
|
7721
|
+
const right = collectExcludedKeys(unwrapped.right, keyName);
|
|
7722
|
+
if (!left || !right) {
|
|
7723
|
+
return null;
|
|
7724
|
+
}
|
|
7725
|
+
return /* @__PURE__ */ new Set([...left, ...right]);
|
|
7726
|
+
}
|
|
7727
|
+
if (unwrapped.type !== "BinaryExpression" || unwrapped.operator !== "!==" && unwrapped.operator !== "!=") {
|
|
7728
|
+
return null;
|
|
7729
|
+
}
|
|
7730
|
+
if (isIdentifier(unwrapped.left, { name: keyName }) && isStringLiteral(unwrapped.right)) {
|
|
7731
|
+
return /* @__PURE__ */ new Set([unwrapped.right.value]);
|
|
7732
|
+
}
|
|
7733
|
+
if (isStringLiteral(unwrapped.left) && isIdentifier(unwrapped.right, { name: keyName })) {
|
|
7734
|
+
return /* @__PURE__ */ new Set([unwrapped.left.value]);
|
|
7735
|
+
}
|
|
7736
|
+
return null;
|
|
7737
|
+
}
|
|
7738
|
+
function getSingleStatement(statement) {
|
|
7739
|
+
if (isBlockStatement(statement)) {
|
|
7740
|
+
return statement.body.length === 1 ? statement.body[0] : null;
|
|
7741
|
+
}
|
|
7742
|
+
return statement;
|
|
7743
|
+
}
|
|
7744
|
+
function tryGetForwardedAccumulator(statement, testIdAttribute, attrsObjectNames, attrsFunctionNames) {
|
|
7745
|
+
if (!isForInStatement(statement) || !isExpression(statement.right)) {
|
|
7746
|
+
return null;
|
|
7747
|
+
}
|
|
7748
|
+
if (!expressionForwardsTestId(statement.right, testIdAttribute, attrsObjectNames, attrsFunctionNames)) {
|
|
7749
|
+
return null;
|
|
7750
|
+
}
|
|
7751
|
+
let keyName = null;
|
|
7752
|
+
if (isVariableDeclaration(statement.left) && statement.left.declarations.length === 1) {
|
|
7753
|
+
const declaration = statement.left.declarations[0];
|
|
7754
|
+
keyName = isIdentifier(declaration.id) ? declaration.id.name : null;
|
|
7755
|
+
} else if (isIdentifier(statement.left)) {
|
|
7756
|
+
keyName = statement.left.name;
|
|
7757
|
+
}
|
|
7758
|
+
if (!keyName) {
|
|
7759
|
+
return null;
|
|
7760
|
+
}
|
|
7761
|
+
const bodyStatement = getSingleStatement(statement.body);
|
|
7762
|
+
if (!bodyStatement || !isIfStatement(bodyStatement) || !isExpression(bodyStatement.test)) {
|
|
7763
|
+
return null;
|
|
7764
|
+
}
|
|
7765
|
+
const excludedKeys = collectExcludedKeys(bodyStatement.test, keyName);
|
|
7766
|
+
if (!excludedKeys || excludedKeys.has(testIdAttribute) || bodyStatement.alternate) {
|
|
7767
|
+
return null;
|
|
7768
|
+
}
|
|
7769
|
+
const consequent = getSingleStatement(bodyStatement.consequent);
|
|
7770
|
+
if (!consequent || !isExpressionStatement(consequent) || !isAssignmentExpression(consequent.expression, { operator: "=" })) {
|
|
7771
|
+
return null;
|
|
7772
|
+
}
|
|
7773
|
+
const { left, right } = consequent.expression;
|
|
7774
|
+
if (!isMemberExpression(left) || !left.computed || !isIdentifier(left.object) || !isIdentifier(left.property, { name: keyName })) {
|
|
7775
|
+
return null;
|
|
7776
|
+
}
|
|
7777
|
+
if (!isMemberExpression(right) || !right.computed || !isIdentifier(right.property, { name: keyName }) || !isExpression(right.object)) {
|
|
7778
|
+
return null;
|
|
7779
|
+
}
|
|
7780
|
+
if (!expressionForwardsTestId(right.object, testIdAttribute, attrsObjectNames, attrsFunctionNames)) {
|
|
7781
|
+
return null;
|
|
7782
|
+
}
|
|
7783
|
+
return left.object.name;
|
|
7784
|
+
}
|
|
7785
|
+
function functionForwardsTestId(functionNode, testIdAttribute, globalAttrsObjectNames, attrsFunctionNames) {
|
|
7786
|
+
const body = getFunctionBody(functionNode);
|
|
7787
|
+
if (isExpression(body)) {
|
|
7788
|
+
return expressionForwardsTestId(body, testIdAttribute, globalAttrsObjectNames, attrsFunctionNames);
|
|
7789
|
+
}
|
|
7790
|
+
const localAttrsObjectNames = new Set(globalAttrsObjectNames);
|
|
7791
|
+
for (const statement of body.body) {
|
|
7792
|
+
if (isVariableDeclaration(statement)) {
|
|
7793
|
+
for (const declaration of statement.declarations) {
|
|
7794
|
+
if (isIdentifier(declaration.id) && declaration.init && isExpression(declaration.init)) {
|
|
7795
|
+
if (expressionForwardsTestId(declaration.init, testIdAttribute, localAttrsObjectNames, attrsFunctionNames)) {
|
|
7796
|
+
localAttrsObjectNames.add(declaration.id.name);
|
|
7797
|
+
}
|
|
7798
|
+
continue;
|
|
7799
|
+
}
|
|
7800
|
+
if (!isObjectPattern(declaration.id) || !declaration.init || !isExpression(declaration.init)) {
|
|
7801
|
+
continue;
|
|
7802
|
+
}
|
|
7803
|
+
if (!expressionForwardsTestId(declaration.init, testIdAttribute, localAttrsObjectNames, attrsFunctionNames)) {
|
|
7804
|
+
continue;
|
|
7805
|
+
}
|
|
7806
|
+
const excludedKeys = /* @__PURE__ */ new Set();
|
|
7807
|
+
let restName = null;
|
|
7808
|
+
for (const property of declaration.id.properties) {
|
|
7809
|
+
if (isRestElement(property) && isIdentifier(property.argument)) {
|
|
7810
|
+
restName = property.argument.name;
|
|
7811
|
+
continue;
|
|
7812
|
+
}
|
|
7813
|
+
if (isObjectProperty(property)) {
|
|
7814
|
+
const key = getStaticObjectKey(property.key);
|
|
7815
|
+
if (key) {
|
|
7816
|
+
excludedKeys.add(key);
|
|
7817
|
+
}
|
|
7818
|
+
}
|
|
7819
|
+
}
|
|
7820
|
+
if (restName && !excludedKeys.has(testIdAttribute)) {
|
|
7821
|
+
localAttrsObjectNames.add(restName);
|
|
7822
|
+
}
|
|
7823
|
+
}
|
|
7824
|
+
continue;
|
|
7825
|
+
}
|
|
7826
|
+
const accumulatorName = tryGetForwardedAccumulator(
|
|
7827
|
+
statement,
|
|
7828
|
+
testIdAttribute,
|
|
7829
|
+
localAttrsObjectNames,
|
|
7830
|
+
attrsFunctionNames
|
|
7831
|
+
);
|
|
7832
|
+
if (accumulatorName) {
|
|
7833
|
+
localAttrsObjectNames.add(accumulatorName);
|
|
7834
|
+
continue;
|
|
7835
|
+
}
|
|
7836
|
+
if (isReturnStatement(statement) && statement.argument && isExpression(statement.argument)) {
|
|
7837
|
+
if (expressionForwardsTestId(statement.argument, testIdAttribute, localAttrsObjectNames, attrsFunctionNames)) {
|
|
7838
|
+
return true;
|
|
7839
|
+
}
|
|
7840
|
+
}
|
|
7841
|
+
}
|
|
7842
|
+
return body.body.some((statement) => {
|
|
7843
|
+
return isReturnStatement(statement) && !!statement.argument && isExpression(statement.argument) && expressionForwardsTestId(statement.argument, testIdAttribute, localAttrsObjectNames, attrsFunctionNames);
|
|
7844
|
+
});
|
|
7845
|
+
}
|
|
7846
|
+
function analyzeScriptForwardingMetadata(scriptBlocks, testIdAttribute) {
|
|
7847
|
+
const statements = scriptBlocks.flatMap((block) => parseScriptStatements(block.content, block.lang));
|
|
7848
|
+
const useAttrsCalleeNames = /* @__PURE__ */ new Set(["useAttrs"]);
|
|
7849
|
+
let inheritAttrs = true;
|
|
7850
|
+
for (const statement of statements) {
|
|
7851
|
+
if (isImportDeclaration(statement) && statement.source.value === "vue") {
|
|
7852
|
+
for (const specifier of statement.specifiers) {
|
|
7853
|
+
if (isImportSpecifier(specifier) && isIdentifier(specifier.imported, { name: "useAttrs" })) {
|
|
7854
|
+
useAttrsCalleeNames.add(specifier.local.name);
|
|
7855
|
+
}
|
|
7856
|
+
}
|
|
7857
|
+
}
|
|
7858
|
+
if (isExportDefaultDeclaration(statement)) {
|
|
7859
|
+
const declaration = statement.declaration;
|
|
7860
|
+
const options = isExpression(declaration) ? getOptionsObject(declaration) : null;
|
|
7861
|
+
const configured = options ? getBooleanObjectProperty(options, "inheritAttrs") : null;
|
|
7862
|
+
if (configured !== null) {
|
|
7863
|
+
inheritAttrs = configured;
|
|
7864
|
+
}
|
|
7865
|
+
}
|
|
7866
|
+
}
|
|
7867
|
+
for (const statement of statements) {
|
|
7868
|
+
walkBabel(statement, (node) => {
|
|
7869
|
+
if (!isCallExpression(node) || !isIdentifier(node.callee, { name: "defineOptions" })) {
|
|
7870
|
+
return;
|
|
7871
|
+
}
|
|
7872
|
+
const options = node.arguments[0];
|
|
7873
|
+
if (!options || !isObjectExpression(options)) {
|
|
7874
|
+
return;
|
|
7875
|
+
}
|
|
7876
|
+
const configured = getBooleanObjectProperty(options, "inheritAttrs");
|
|
7877
|
+
if (configured !== null) {
|
|
7878
|
+
inheritAttrs = configured;
|
|
7879
|
+
}
|
|
7880
|
+
});
|
|
7881
|
+
}
|
|
7882
|
+
const attrsObjectNames = /* @__PURE__ */ new Set(["$attrs"]);
|
|
7883
|
+
for (const statement of statements) {
|
|
7884
|
+
walkBabel(statement, (node) => {
|
|
7885
|
+
if (node.type !== "VariableDeclarator") {
|
|
7886
|
+
return;
|
|
7887
|
+
}
|
|
7888
|
+
const declaration = node;
|
|
7889
|
+
if (!declaration.init || !isCallExpression(declaration.init)) {
|
|
7890
|
+
return;
|
|
7891
|
+
}
|
|
7892
|
+
if (!isIdentifier(declaration.init.callee) || !useAttrsCalleeNames.has(declaration.init.callee.name)) {
|
|
7893
|
+
return;
|
|
7894
|
+
}
|
|
7895
|
+
if (isIdentifier(declaration.id)) {
|
|
7896
|
+
attrsObjectNames.add(declaration.id.name);
|
|
7897
|
+
return;
|
|
7898
|
+
}
|
|
7899
|
+
if (!isObjectPattern(declaration.id)) {
|
|
7900
|
+
return;
|
|
7901
|
+
}
|
|
7902
|
+
const excludedKeys = /* @__PURE__ */ new Set();
|
|
7903
|
+
let restName = null;
|
|
7904
|
+
for (const property of declaration.id.properties) {
|
|
7905
|
+
if (isRestElement(property) && isIdentifier(property.argument)) {
|
|
7906
|
+
restName = property.argument.name;
|
|
7907
|
+
continue;
|
|
7908
|
+
}
|
|
7909
|
+
if (isObjectProperty(property)) {
|
|
7910
|
+
const key = getStaticObjectKey(property.key);
|
|
7911
|
+
if (key) {
|
|
7912
|
+
excludedKeys.add(key);
|
|
7913
|
+
}
|
|
7914
|
+
}
|
|
7915
|
+
}
|
|
7916
|
+
if (restName && !excludedKeys.has(testIdAttribute)) {
|
|
7917
|
+
attrsObjectNames.add(restName);
|
|
7918
|
+
}
|
|
7919
|
+
});
|
|
7920
|
+
}
|
|
7921
|
+
let aliasesChanged = true;
|
|
7922
|
+
while (aliasesChanged) {
|
|
7923
|
+
aliasesChanged = false;
|
|
7924
|
+
for (const statement of statements) {
|
|
7925
|
+
if (!isVariableDeclaration(statement)) {
|
|
7926
|
+
continue;
|
|
7927
|
+
}
|
|
7928
|
+
for (const declaration of statement.declarations) {
|
|
7929
|
+
if (!isIdentifier(declaration.id) || attrsObjectNames.has(declaration.id.name) || !declaration.init || !isExpression(declaration.init)) {
|
|
7930
|
+
continue;
|
|
7931
|
+
}
|
|
7932
|
+
if (expressionForwardsTestId(declaration.init, testIdAttribute, attrsObjectNames, /* @__PURE__ */ new Set())) {
|
|
7933
|
+
attrsObjectNames.add(declaration.id.name);
|
|
7934
|
+
aliasesChanged = true;
|
|
7935
|
+
}
|
|
7936
|
+
}
|
|
7937
|
+
}
|
|
7938
|
+
}
|
|
7939
|
+
const functions = findFunctionDeclarations(statements);
|
|
7940
|
+
const attrsFunctionNames = /* @__PURE__ */ new Set();
|
|
7941
|
+
let changed = true;
|
|
7942
|
+
while (changed) {
|
|
7943
|
+
changed = false;
|
|
7944
|
+
for (const [name, functionNode] of functions) {
|
|
7945
|
+
if (attrsFunctionNames.has(name)) {
|
|
7946
|
+
continue;
|
|
7947
|
+
}
|
|
7948
|
+
if (functionForwardsTestId(functionNode, testIdAttribute, attrsObjectNames, attrsFunctionNames)) {
|
|
7949
|
+
attrsFunctionNames.add(name);
|
|
7950
|
+
changed = true;
|
|
7951
|
+
}
|
|
7952
|
+
}
|
|
7953
|
+
}
|
|
7954
|
+
return { inheritAttrs, attrsObjectNames, attrsFunctionNames };
|
|
7955
|
+
}
|
|
7956
|
+
function getStaticAttributeContent$1(element, name) {
|
|
7957
|
+
const attribute = element.props.find((prop) => {
|
|
7958
|
+
return prop.type === NodeTypes.ATTRIBUTE && prop.name === name;
|
|
7959
|
+
});
|
|
7960
|
+
return attribute?.value?.content?.trim() || null;
|
|
7961
|
+
}
|
|
7962
|
+
function mapExplicitAriaRole(role) {
|
|
7963
|
+
switch (role.toLowerCase()) {
|
|
7964
|
+
case "button":
|
|
7965
|
+
case "checkbox":
|
|
7966
|
+
case "grid":
|
|
7967
|
+
case "link":
|
|
7968
|
+
case "radio":
|
|
7969
|
+
case "tab":
|
|
7970
|
+
return role.toLowerCase();
|
|
7971
|
+
case "radiogroup":
|
|
7972
|
+
return "radio";
|
|
7973
|
+
case "combobox":
|
|
7974
|
+
case "listbox":
|
|
7975
|
+
return "select";
|
|
7976
|
+
case "searchbox":
|
|
7977
|
+
case "spinbutton":
|
|
7978
|
+
case "textbox":
|
|
7979
|
+
return "input";
|
|
7980
|
+
case "switch":
|
|
7981
|
+
return "toggle";
|
|
7982
|
+
default:
|
|
7983
|
+
return null;
|
|
7984
|
+
}
|
|
7985
|
+
}
|
|
7986
|
+
function hasAttribute(element, name) {
|
|
7987
|
+
return element.props.some((prop) => {
|
|
7988
|
+
if (prop.type === NodeTypes.ATTRIBUTE) {
|
|
7989
|
+
return prop.name === name;
|
|
7990
|
+
}
|
|
7991
|
+
return prop.type === NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === name;
|
|
7992
|
+
});
|
|
7993
|
+
}
|
|
7994
|
+
function getElementControlRole(element) {
|
|
7995
|
+
const explicitRole = getStaticAttributeContent$1(element, "role");
|
|
7996
|
+
if (explicitRole) {
|
|
7997
|
+
return mapExplicitAriaRole(explicitRole);
|
|
7998
|
+
}
|
|
7999
|
+
const tag = element.tag.toLowerCase();
|
|
8000
|
+
const type = (getStaticAttributeContent$1(element, "type") || "").toLowerCase();
|
|
8001
|
+
if (tag === "input" || tag === "uinput") {
|
|
8002
|
+
if (type === "radio") {
|
|
8003
|
+
return "radio";
|
|
8004
|
+
}
|
|
8005
|
+
if (type === "checkbox") {
|
|
8006
|
+
return "checkbox";
|
|
8007
|
+
}
|
|
8008
|
+
return "input";
|
|
8009
|
+
}
|
|
8010
|
+
if (tag === "textarea" || tag === "utextarea") {
|
|
8011
|
+
return "input";
|
|
8012
|
+
}
|
|
8013
|
+
if (tag === "select" || tag === "uselect") {
|
|
8014
|
+
return "select";
|
|
8015
|
+
}
|
|
8016
|
+
if (tag === "vselect") {
|
|
8017
|
+
return "vselect";
|
|
8018
|
+
}
|
|
8019
|
+
if (tag === "button" || tag === "ubutton") {
|
|
8020
|
+
return "button";
|
|
8021
|
+
}
|
|
8022
|
+
if (tag === "router-link" || tag === "routerlink") {
|
|
8023
|
+
return "link";
|
|
8024
|
+
}
|
|
8025
|
+
if ((tag === "a" || tag === "ua") && hasAttribute(element, "href")) {
|
|
8026
|
+
return "link";
|
|
8027
|
+
}
|
|
8028
|
+
return null;
|
|
8029
|
+
}
|
|
8030
|
+
function isComponentLikeTag(tag) {
|
|
8031
|
+
if (!tag) {
|
|
8032
|
+
return false;
|
|
8033
|
+
}
|
|
8034
|
+
return isAsciiUppercaseLetterCode(tag.charCodeAt(0)) || tag.includes("-");
|
|
8035
|
+
}
|
|
8036
|
+
function parseTemplateExpression(source) {
|
|
8037
|
+
try {
|
|
8038
|
+
return parseExpression(source, { plugins: ["typescript"] });
|
|
8039
|
+
} catch {
|
|
8040
|
+
return null;
|
|
8041
|
+
}
|
|
8042
|
+
}
|
|
8043
|
+
function directiveExpressionSource(directive) {
|
|
8044
|
+
if (!directive.exp) {
|
|
8045
|
+
return "";
|
|
8046
|
+
}
|
|
8047
|
+
return directive.exp.loc?.source || (directive.exp.type === NodeTypes.SIMPLE_EXPRESSION ? directive.exp.content : "");
|
|
8048
|
+
}
|
|
8049
|
+
function elementExplicitlyForwardsTestId(element, testIdAttribute, scriptMetadata) {
|
|
8050
|
+
for (const prop of element.props) {
|
|
8051
|
+
if (prop.type !== NodeTypes.DIRECTIVE || prop.name !== "bind" || !prop.exp) {
|
|
8052
|
+
continue;
|
|
8053
|
+
}
|
|
8054
|
+
const source = directiveExpressionSource(prop);
|
|
8055
|
+
const expression = parseTemplateExpression(source);
|
|
8056
|
+
if (!expression) {
|
|
8057
|
+
continue;
|
|
8058
|
+
}
|
|
8059
|
+
if (!prop.arg) {
|
|
8060
|
+
if (expressionForwardsTestId(expression, testIdAttribute, scriptMetadata.attrsObjectNames, scriptMetadata.attrsFunctionNames)) {
|
|
8061
|
+
return true;
|
|
8062
|
+
}
|
|
8063
|
+
continue;
|
|
8064
|
+
}
|
|
8065
|
+
if (prop.arg.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic && prop.arg.content === testIdAttribute && expressionReadsTestId(expression, testIdAttribute, scriptMetadata.attrsObjectNames, scriptMetadata.attrsFunctionNames)) {
|
|
8066
|
+
return true;
|
|
8067
|
+
}
|
|
8068
|
+
}
|
|
8069
|
+
return false;
|
|
8070
|
+
}
|
|
8071
|
+
function walkTemplate(node, visitor) {
|
|
8072
|
+
if (node.type === NodeTypes.ELEMENT) {
|
|
8073
|
+
visitor(node);
|
|
8074
|
+
for (const child of node.children) {
|
|
8075
|
+
walkTemplate(child, visitor);
|
|
8076
|
+
}
|
|
8077
|
+
return;
|
|
8078
|
+
}
|
|
8079
|
+
if (node.type === NodeTypes.ROOT) {
|
|
8080
|
+
for (const child of node.children) {
|
|
8081
|
+
walkTemplate(child, visitor);
|
|
8082
|
+
}
|
|
8083
|
+
}
|
|
8084
|
+
}
|
|
8085
|
+
function getRenderedRootElements(ast) {
|
|
8086
|
+
const rendered = ast.children.filter((child) => {
|
|
8087
|
+
return child.type !== NodeTypes.COMMENT && !(child.type === NodeTypes.TEXT && child.content.trim() === "");
|
|
8088
|
+
});
|
|
8089
|
+
if (rendered.length !== 1 || rendered[0]?.type !== NodeTypes.ELEMENT || rendered[0].tag === "template") {
|
|
8090
|
+
return [];
|
|
8091
|
+
}
|
|
8092
|
+
return [rendered[0]];
|
|
8093
|
+
}
|
|
8094
|
+
function analyzeWrapperContractFromSfc(options) {
|
|
8095
|
+
const { descriptor } = parse$1(options.source, { filename: options.filePath });
|
|
8096
|
+
const template = descriptor.template?.content ?? "";
|
|
8097
|
+
if (!template.trim()) {
|
|
8098
|
+
return {
|
|
8099
|
+
role: null,
|
|
8100
|
+
targetRoles: [],
|
|
8101
|
+
forwardedTestIdTargetOffsets: /* @__PURE__ */ new Set(),
|
|
8102
|
+
forwardedTestIdTargetSfcOffsets: /* @__PURE__ */ new Set(),
|
|
8103
|
+
explicitlyForwardedTestIdTargetOffsets: /* @__PURE__ */ new Set(),
|
|
8104
|
+
explicitlyForwardedTestIdTargetSfcOffsets: /* @__PURE__ */ new Set()
|
|
8105
|
+
};
|
|
8106
|
+
}
|
|
8107
|
+
const scriptMetadata = analyzeScriptForwardingMetadata(
|
|
8108
|
+
[descriptor.script, descriptor.scriptSetup].filter((block) => !!block).map((block) => ({ content: block.content, lang: block.lang })),
|
|
8109
|
+
options.testIdAttribute
|
|
8110
|
+
);
|
|
8111
|
+
const ast = parse$2(template, { comments: false });
|
|
8112
|
+
const targets = /* @__PURE__ */ new Map();
|
|
8113
|
+
const explicitTargetOffsets = /* @__PURE__ */ new Set();
|
|
8114
|
+
if (scriptMetadata.inheritAttrs) {
|
|
8115
|
+
for (const element of getRenderedRootElements(ast)) {
|
|
8116
|
+
targets.set(element.loc.start.offset, element);
|
|
8117
|
+
}
|
|
8118
|
+
}
|
|
8119
|
+
walkTemplate(ast, (element) => {
|
|
8120
|
+
if (elementExplicitlyForwardsTestId(element, options.testIdAttribute, scriptMetadata)) {
|
|
8121
|
+
targets.set(element.loc.start.offset, element);
|
|
8122
|
+
explicitTargetOffsets.add(element.loc.start.offset);
|
|
8123
|
+
}
|
|
8124
|
+
});
|
|
8125
|
+
const targetRoles = [...targets.values()].map((element) => {
|
|
8126
|
+
const directRole = getElementControlRole(element);
|
|
8127
|
+
if (directRole) {
|
|
8128
|
+
return directRole;
|
|
8129
|
+
}
|
|
8130
|
+
if (isComponentLikeTag(element.tag)) {
|
|
8131
|
+
return options.resolveNestedContract(element.tag)?.role ?? null;
|
|
8132
|
+
}
|
|
8133
|
+
return null;
|
|
8134
|
+
});
|
|
8135
|
+
const uniqueRoles = new Set(targetRoles);
|
|
8136
|
+
const role = uniqueRoles.size === 1 && !uniqueRoles.has(null) ? targetRoles[0] ?? null : null;
|
|
8137
|
+
const templateContentStartOffset = descriptor.template?.loc.start.offset ?? 0;
|
|
8138
|
+
const toSfcOffsets = (offsets) => new Set(
|
|
8139
|
+
[...offsets].map((offset2) => offset2 + templateContentStartOffset)
|
|
8140
|
+
);
|
|
8141
|
+
return {
|
|
8142
|
+
role,
|
|
8143
|
+
targetRoles,
|
|
8144
|
+
forwardedTestIdTargetOffsets: new Set(targets.keys()),
|
|
8145
|
+
forwardedTestIdTargetSfcOffsets: toSfcOffsets(targets.keys()),
|
|
8146
|
+
explicitlyForwardedTestIdTargetOffsets: explicitTargetOffsets,
|
|
8147
|
+
explicitlyForwardedTestIdTargetSfcOffsets: toSfcOffsets(explicitTargetOffsets)
|
|
8148
|
+
};
|
|
8149
|
+
}
|
|
8150
|
+
function resolveWrapperContractForTag(options) {
|
|
8151
|
+
const normalizedSearchRoots = normalizeWrapperSearchRoots(options.wrapperSearchRoots ?? []);
|
|
8152
|
+
const memo = /* @__PURE__ */ new Map();
|
|
8153
|
+
const resolving = /* @__PURE__ */ new Set();
|
|
8154
|
+
const resolveTag = (tag) => {
|
|
8155
|
+
const first = tag.charCodeAt(0);
|
|
8156
|
+
if (!isAsciiUppercaseLetterCode(first) && !tag.includes("-")) {
|
|
8157
|
+
return null;
|
|
8158
|
+
}
|
|
8159
|
+
const filePath = resolveSfcPathForTag(tag, options.vueFilesPathMap, normalizedSearchRoots);
|
|
8160
|
+
if (!filePath) {
|
|
8161
|
+
return null;
|
|
8162
|
+
}
|
|
8163
|
+
const normalizedPath = path.normalize(filePath);
|
|
8164
|
+
if (memo.has(normalizedPath)) {
|
|
8165
|
+
return memo.get(normalizedPath) ?? null;
|
|
8166
|
+
}
|
|
8167
|
+
if (resolving.has(normalizedPath)) {
|
|
8168
|
+
return null;
|
|
8169
|
+
}
|
|
8170
|
+
const source = fs.readFileSync(normalizedPath, "utf8");
|
|
8171
|
+
resolving.add(normalizedPath);
|
|
8172
|
+
try {
|
|
8173
|
+
const contract = analyzeWrapperContractFromSfc({
|
|
8174
|
+
filePath: normalizedPath,
|
|
8175
|
+
source,
|
|
8176
|
+
testIdAttribute: options.testIdAttribute,
|
|
8177
|
+
resolveNestedContract: resolveTag
|
|
8178
|
+
});
|
|
8179
|
+
memo.set(normalizedPath, contract);
|
|
8180
|
+
return contract;
|
|
8181
|
+
} finally {
|
|
8182
|
+
resolving.delete(normalizedPath);
|
|
8183
|
+
}
|
|
8184
|
+
};
|
|
8185
|
+
return resolveTag(options.tag);
|
|
8186
|
+
}
|
|
8187
|
+
const CLICK_EVENT_NAME = TESTID_CLICK_EVENT_NAME;
|
|
8188
|
+
function getStaticAttributeContent(element, name) {
|
|
8189
|
+
const attr = element.props.find((prop) => {
|
|
8190
|
+
return prop.type === NodeTypes.ATTRIBUTE && prop.name === name;
|
|
8191
|
+
});
|
|
8192
|
+
return attr?.value?.content?.trim() || null;
|
|
8193
|
+
}
|
|
8194
|
+
function getNativeHtmlControlRole(element) {
|
|
8195
|
+
return getElementControlRole(element);
|
|
8196
|
+
}
|
|
8197
|
+
function normalizeControlLabelText(value) {
|
|
8198
|
+
const normalized = (value ?? "").replace(/\*/g, " ").replace(/\s+/g, " ").trim();
|
|
8199
|
+
return normalized || null;
|
|
8200
|
+
}
|
|
8201
|
+
function getLabelNodeText(labelNode) {
|
|
8202
|
+
for (const child of labelNode.children || []) {
|
|
8203
|
+
if (child.type === NodeTypes.TEXT) {
|
|
8204
|
+
const normalized2 = normalizeControlLabelText(child.content);
|
|
8205
|
+
if (normalized2) {
|
|
8206
|
+
return normalized2;
|
|
8207
|
+
}
|
|
8208
|
+
continue;
|
|
8209
|
+
}
|
|
8210
|
+
if (child.type !== NodeTypes.ELEMENT) {
|
|
8211
|
+
continue;
|
|
8212
|
+
}
|
|
8213
|
+
if (getNativeHtmlControlRole(child)) {
|
|
8214
|
+
continue;
|
|
8215
|
+
}
|
|
8216
|
+
const normalized = normalizeControlLabelText(getInnerText(child));
|
|
8217
|
+
if (normalized) {
|
|
8218
|
+
return normalized;
|
|
8219
|
+
}
|
|
8220
|
+
}
|
|
8221
|
+
return normalizeControlLabelText(getInnerText(labelNode));
|
|
8222
|
+
}
|
|
8223
|
+
function getAssociatedLabelText(element, hierarchyMap2) {
|
|
8224
|
+
let parent = hierarchyMap2.get(element) || null;
|
|
8225
|
+
while (parent) {
|
|
8226
|
+
if (parent.tag === "label") {
|
|
8227
|
+
return getLabelNodeText(parent);
|
|
8228
|
+
}
|
|
8229
|
+
parent = hierarchyMap2.get(parent) || null;
|
|
8230
|
+
}
|
|
8231
|
+
const id = getStaticAttributeContent(element, "id");
|
|
8232
|
+
if (!id) {
|
|
8233
|
+
return null;
|
|
8234
|
+
}
|
|
8235
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
8236
|
+
for (const child of hierarchyMap2.keys()) {
|
|
8237
|
+
candidates.add(child);
|
|
8238
|
+
}
|
|
8239
|
+
for (const maybeParent of hierarchyMap2.values()) {
|
|
8240
|
+
if (maybeParent) {
|
|
8241
|
+
candidates.add(maybeParent);
|
|
8242
|
+
}
|
|
8243
|
+
}
|
|
8244
|
+
for (const candidate of candidates) {
|
|
8245
|
+
if (candidate.tag !== "label") {
|
|
8246
|
+
continue;
|
|
8247
|
+
}
|
|
8248
|
+
if (getStaticAttributeContent(candidate, "for") === id) {
|
|
8249
|
+
return getLabelNodeText(candidate);
|
|
8250
|
+
}
|
|
8251
|
+
}
|
|
8252
|
+
return null;
|
|
8253
|
+
}
|
|
7651
8254
|
function trimLeadingSeparators(value) {
|
|
7652
8255
|
if (!value) {
|
|
7653
8256
|
return "";
|
|
@@ -7700,11 +8303,11 @@ function tryExtractStableHintFromConditionalExpressionSource(source) {
|
|
|
7700
8303
|
return false;
|
|
7701
8304
|
const isUnderscore = (ch) => ch === 95;
|
|
7702
8305
|
const first = v.charCodeAt(0);
|
|
7703
|
-
if (!isAsciiLetterCode(first))
|
|
8306
|
+
if (!isAsciiLetterCode$1(first))
|
|
7704
8307
|
return false;
|
|
7705
8308
|
for (let i = 1; i < v.length; i += 1) {
|
|
7706
8309
|
const ch = v.charCodeAt(i);
|
|
7707
|
-
if (isAsciiLetterCode(ch) || isAsciiDigitCode(ch) || isUnderscore(ch)) {
|
|
8310
|
+
if (isAsciiLetterCode$1(ch) || isAsciiDigitCode$1(ch) || isUnderscore(ch)) {
|
|
7708
8311
|
continue;
|
|
7709
8312
|
}
|
|
7710
8313
|
return false;
|
|
@@ -7761,150 +8364,6 @@ function tryExtractStableHintFromConditionalExpressionSource(source) {
|
|
|
7761
8364
|
return null;
|
|
7762
8365
|
}
|
|
7763
8366
|
}
|
|
7764
|
-
function tryInferNativeWrapperRoleFromSfc(tag, vueFilesPathMap, wrapperSearchRoots = [], seenTags = /* @__PURE__ */ new Set()) {
|
|
7765
|
-
const first = tag.charCodeAt(0);
|
|
7766
|
-
const isUpper = isAsciiUppercaseLetterCode(first);
|
|
7767
|
-
if (!isUpper)
|
|
7768
|
-
return null;
|
|
7769
|
-
if (seenTags.has(tag)) {
|
|
7770
|
-
return null;
|
|
7771
|
-
}
|
|
7772
|
-
const normalizedSearchRoots = normalizeSearchRoots(wrapperSearchRoots);
|
|
7773
|
-
const cacheKey = `${tag}
|
|
7774
|
-
${vueFilesPathMap?.get(tag) ?? ""}
|
|
7775
|
-
${buildSearchRootsKey(normalizedSearchRoots)}`;
|
|
7776
|
-
const cached = inferredNativeWrapperConfigByLookup.get(cacheKey);
|
|
7777
|
-
if (cached)
|
|
7778
|
-
return cached.role ? cached : null;
|
|
7779
|
-
const filePath = tryResolveSfcPathForTag(tag, vueFilesPathMap, normalizedSearchRoots);
|
|
7780
|
-
if (!filePath) {
|
|
7781
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7782
|
-
return null;
|
|
7783
|
-
}
|
|
7784
|
-
let source = "";
|
|
7785
|
-
try {
|
|
7786
|
-
source = fs.readFileSync(filePath, "utf8");
|
|
7787
|
-
} catch {
|
|
7788
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7789
|
-
return null;
|
|
7790
|
-
}
|
|
7791
|
-
let template = "";
|
|
7792
|
-
try {
|
|
7793
|
-
const { descriptor } = parse$1(source, { filename: filePath });
|
|
7794
|
-
template = descriptor.template?.content ?? "";
|
|
7795
|
-
} catch {
|
|
7796
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7797
|
-
return null;
|
|
7798
|
-
}
|
|
7799
|
-
if (!template.trim()) {
|
|
7800
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7801
|
-
return null;
|
|
7802
|
-
}
|
|
7803
|
-
try {
|
|
7804
|
-
const ast = parse$2(template, { comments: false });
|
|
7805
|
-
const renderedRoots = ast.children.filter((child) => {
|
|
7806
|
-
return child.type !== NodeTypes.COMMENT && !(child.type === NodeTypes.TEXT && child.content.trim() === "");
|
|
7807
|
-
});
|
|
7808
|
-
if (renderedRoots.length !== 1) {
|
|
7809
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7810
|
-
return null;
|
|
7811
|
-
}
|
|
7812
|
-
const nextSeen = new Set(seenTags);
|
|
7813
|
-
nextSeen.add(tag);
|
|
7814
|
-
const isComponentLikeTag = (value) => {
|
|
7815
|
-
if (!value)
|
|
7816
|
-
return false;
|
|
7817
|
-
const code = value.charCodeAt(0);
|
|
7818
|
-
return isAsciiUppercaseLetterCode(code) || value.includes("-");
|
|
7819
|
-
};
|
|
7820
|
-
const getStaticTypeAttribute = (element) => {
|
|
7821
|
-
const typeAttr = element.props.find((prop) => {
|
|
7822
|
-
return prop.type === NodeTypes.ATTRIBUTE && prop.name === "type";
|
|
7823
|
-
});
|
|
7824
|
-
return (typeAttr?.value?.content ?? "").toLowerCase();
|
|
7825
|
-
};
|
|
7826
|
-
const hasHrefAttribute = (element) => {
|
|
7827
|
-
return element.props.some((prop) => {
|
|
7828
|
-
if (prop.type === NodeTypes.ATTRIBUTE) {
|
|
7829
|
-
return prop.name === "href";
|
|
7830
|
-
}
|
|
7831
|
-
if (prop.type === NodeTypes.DIRECTIVE) {
|
|
7832
|
-
const directive = prop;
|
|
7833
|
-
return directive.name === "bind" && directive.arg?.type === NodeTypes.SIMPLE_EXPRESSION && directive.arg.content === "href";
|
|
7834
|
-
}
|
|
7835
|
-
return false;
|
|
7836
|
-
});
|
|
7837
|
-
};
|
|
7838
|
-
let inferRoleFromNode;
|
|
7839
|
-
const inferRoleFromElement = (element) => {
|
|
7840
|
-
const elementTag = (element.tag || "").toLowerCase();
|
|
7841
|
-
const inputType = getStaticTypeAttribute(element);
|
|
7842
|
-
if (elementTag === "input" || elementTag === "uinput") {
|
|
7843
|
-
if (inputType === "radio")
|
|
7844
|
-
return { role: "radio" };
|
|
7845
|
-
if (inputType === "checkbox")
|
|
7846
|
-
return { role: "checkbox" };
|
|
7847
|
-
return { role: "input" };
|
|
7848
|
-
}
|
|
7849
|
-
if (elementTag === "textarea" || elementTag === "utextarea")
|
|
7850
|
-
return { role: "input" };
|
|
7851
|
-
if (elementTag === "select" || elementTag === "uselect")
|
|
7852
|
-
return { role: "select" };
|
|
7853
|
-
if (elementTag === "vselect")
|
|
7854
|
-
return { role: "vselect" };
|
|
7855
|
-
if (elementTag === "button" || elementTag === "ubutton")
|
|
7856
|
-
return { role: "button" };
|
|
7857
|
-
if (elementTag === "router-link" || elementTag === "routerlink")
|
|
7858
|
-
return { role: "link" };
|
|
7859
|
-
if ((elementTag === "a" || elementTag === "ua") && hasHrefAttribute(element))
|
|
7860
|
-
return { role: "link" };
|
|
7861
|
-
if (isComponentLikeTag(element.tag) && element.tag !== tag) {
|
|
7862
|
-
const nested = tryInferNativeWrapperRoleFromSfc(element.tag, vueFilesPathMap, normalizedSearchRoots, nextSeen);
|
|
7863
|
-
if (nested)
|
|
7864
|
-
return nested;
|
|
7865
|
-
}
|
|
7866
|
-
for (const child of element.children ?? []) {
|
|
7867
|
-
const inferred2 = inferRoleFromNode(child);
|
|
7868
|
-
if (inferred2)
|
|
7869
|
-
return inferred2;
|
|
7870
|
-
}
|
|
7871
|
-
return null;
|
|
7872
|
-
};
|
|
7873
|
-
inferRoleFromNode = (node) => {
|
|
7874
|
-
if (!node || typeof node !== "object")
|
|
7875
|
-
return null;
|
|
7876
|
-
if (node.type === NodeTypes.ELEMENT) {
|
|
7877
|
-
return inferRoleFromElement(node);
|
|
7878
|
-
}
|
|
7879
|
-
if (node.type === NodeTypes.ROOT || node.type === NodeTypes.IF_BRANCH || node.type === NodeTypes.FOR) {
|
|
7880
|
-
for (const child of node.children ?? []) {
|
|
7881
|
-
const inferred2 = inferRoleFromNode(child);
|
|
7882
|
-
if (inferred2)
|
|
7883
|
-
return inferred2;
|
|
7884
|
-
}
|
|
7885
|
-
return null;
|
|
7886
|
-
}
|
|
7887
|
-
if (node.type === NodeTypes.IF) {
|
|
7888
|
-
for (const branch of node.branches ?? []) {
|
|
7889
|
-
const inferred2 = inferRoleFromNode(branch);
|
|
7890
|
-
if (inferred2)
|
|
7891
|
-
return inferred2;
|
|
7892
|
-
}
|
|
7893
|
-
}
|
|
7894
|
-
return null;
|
|
7895
|
-
};
|
|
7896
|
-
const inferred = inferRoleFromNode(ast);
|
|
7897
|
-
if (inferred) {
|
|
7898
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, inferred);
|
|
7899
|
-
return inferred;
|
|
7900
|
-
}
|
|
7901
|
-
} catch {
|
|
7902
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7903
|
-
return null;
|
|
7904
|
-
}
|
|
7905
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7906
|
-
return null;
|
|
7907
|
-
}
|
|
7908
8367
|
function tryWrapClickDirectiveForTestEvents(element, testIdAttribute, resolvedRuntimeTestId) {
|
|
7909
8368
|
const jsStringLiteral = (value) => {
|
|
7910
8369
|
return JSON.stringify(value);
|
|
@@ -8049,7 +8508,7 @@ function tryWrapClickDirectiveForTestEvents(element, testIdAttribute, resolvedRu
|
|
|
8049
8508
|
}
|
|
8050
8509
|
let previousFileName = "";
|
|
8051
8510
|
const hierarchyMap = /* @__PURE__ */ new Map();
|
|
8052
|
-
function createTestIdTransform(componentName, componentHierarchyMap, nativeWrappers = {},
|
|
8511
|
+
function createTestIdTransform(componentName, componentHierarchyMap, nativeWrappers = {}, skipTestIdGenerationInsideComponents = [], viewsDirAbs, options = {}) {
|
|
8053
8512
|
const existingIdBehavior = options.existingIdBehavior ?? "error";
|
|
8054
8513
|
const testIdAttribute = (options.testIdAttribute || "data-testid").trim() || "data-testid";
|
|
8055
8514
|
const nameCollisionBehavior = options.nameCollisionBehavior ?? "error";
|
|
@@ -8060,6 +8519,21 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8060
8519
|
const annotatorMetadata = options.annotatorMetadata ?? null;
|
|
8061
8520
|
const crossFileKeyRegistry = options.crossFileKeyRegistry;
|
|
8062
8521
|
const optionKeyAttribute = options.optionKeyAttribute ?? {};
|
|
8522
|
+
const resolvedNativeWrappers = Object.fromEntries(
|
|
8523
|
+
Object.entries(nativeWrappers).map(([tag, config]) => [tag, { ...config }])
|
|
8524
|
+
);
|
|
8525
|
+
const wrapperContractByTag = /* @__PURE__ */ new Map();
|
|
8526
|
+
const getWrapperContract = (tag) => {
|
|
8527
|
+
if (!wrapperContractByTag.has(tag)) {
|
|
8528
|
+
wrapperContractByTag.set(tag, resolveWrapperContractForTag({
|
|
8529
|
+
tag,
|
|
8530
|
+
vueFilesPathMap,
|
|
8531
|
+
wrapperSearchRoots,
|
|
8532
|
+
testIdAttribute
|
|
8533
|
+
}));
|
|
8534
|
+
}
|
|
8535
|
+
return wrapperContractByTag.get(tag) ?? null;
|
|
8536
|
+
};
|
|
8063
8537
|
const safeRealpath2 = (p) => {
|
|
8064
8538
|
try {
|
|
8065
8539
|
return fs.existsSync(p) ? fs.realpathSync(p) : p;
|
|
@@ -8111,7 +8585,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8111
8585
|
}
|
|
8112
8586
|
};
|
|
8113
8587
|
return (node, context) => {
|
|
8114
|
-
if (
|
|
8588
|
+
if (skipTestIdGenerationInsideComponents.includes(componentName)) {
|
|
8115
8589
|
return;
|
|
8116
8590
|
}
|
|
8117
8591
|
if (node.type === NodeTypes.IF) {
|
|
@@ -8176,13 +8650,13 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8176
8650
|
}
|
|
8177
8651
|
return deps;
|
|
8178
8652
|
})();
|
|
8179
|
-
const
|
|
8653
|
+
const isComponentLikeTag2 = (tag) => {
|
|
8180
8654
|
if (!tag) return false;
|
|
8181
8655
|
const first = tag.charCodeAt(0);
|
|
8182
|
-
const isUpper = isAsciiUppercaseLetterCode(first);
|
|
8656
|
+
const isUpper = isAsciiUppercaseLetterCode$1(first);
|
|
8183
8657
|
return isUpper || tag.includes("-");
|
|
8184
8658
|
};
|
|
8185
|
-
if (
|
|
8659
|
+
if (isComponentLikeTag2(element.tag)) {
|
|
8186
8660
|
dependencies.usedComponentSet.add(element.tag);
|
|
8187
8661
|
if (crossFileKeyRegistry && context.scopes.vSlot > 0) {
|
|
8188
8662
|
const findSlotTemplate = () => {
|
|
@@ -8210,31 +8684,38 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8210
8684
|
}
|
|
8211
8685
|
}
|
|
8212
8686
|
}
|
|
8213
|
-
const
|
|
8687
|
+
const ownWrapperContract = getWrapperContract(componentName);
|
|
8688
|
+
const elementStartOffset = element.loc.start.offset;
|
|
8689
|
+
const isExplicitFallthroughTarget = ownWrapperContract?.explicitlyForwardedTestIdTargetOffsets.has(elementStartOffset) || ownWrapperContract?.explicitlyForwardedTestIdTargetSfcOffsets.has(elementStartOffset);
|
|
8690
|
+
if (!dependencies.isView && isExplicitFallthroughTarget) {
|
|
8691
|
+
return;
|
|
8692
|
+
}
|
|
8693
|
+
const existingWrapperConfig = resolvedNativeWrappers[element.tag];
|
|
8214
8694
|
if (!existingWrapperConfig) {
|
|
8215
|
-
const
|
|
8216
|
-
if (
|
|
8217
|
-
|
|
8218
|
-
} else if (element.tag.endsWith("Button") && !
|
|
8219
|
-
|
|
8695
|
+
const contract = getWrapperContract(element.tag);
|
|
8696
|
+
if (contract?.role) {
|
|
8697
|
+
resolvedNativeWrappers[element.tag] = { role: contract.role, inferred: true };
|
|
8698
|
+
} else if (element.tag.endsWith("Button") && !resolveSfcPathForTag(element.tag, vueFilesPathMap, wrapperSearchRoots)) {
|
|
8699
|
+
resolvedNativeWrappers[element.tag] = { role: "button" };
|
|
8220
8700
|
} else if (element.tag === "DxDataGrid") {
|
|
8221
|
-
|
|
8701
|
+
resolvedNativeWrappers[element.tag] = { role: "grid" };
|
|
8222
8702
|
}
|
|
8223
8703
|
} else if (!existingWrapperConfig.role) {
|
|
8224
|
-
const
|
|
8225
|
-
if (!
|
|
8704
|
+
const contract = getWrapperContract(element.tag);
|
|
8705
|
+
if (!contract?.role) {
|
|
8226
8706
|
const loc = element.loc?.start;
|
|
8227
8707
|
const locationHint = loc ? `${loc.line}:${loc.column}` : "unknown";
|
|
8708
|
+
const targetRoles = contract?.targetRoles.length ? contract.targetRoles.map((role) => role ?? "non-interactive").join(", ") : "no forwarded test-id target";
|
|
8228
8709
|
throw new Error(
|
|
8229
8710
|
`[vue-pom-generator] Could not infer a native role for declared wrapper <${element.tag}> in ${componentName} (${context.filename ?? "unknown"}:${locationHint}).
|
|
8230
|
-
|
|
8711
|
+
Resolved fallthrough targets: ${targetRoles}. The generator requires one stable role across every target.
|
|
8231
8712
|
|
|
8232
8713
|
Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role: "button", ... } }).`
|
|
8233
8714
|
);
|
|
8234
8715
|
}
|
|
8235
|
-
|
|
8716
|
+
resolvedNativeWrappers[element.tag] = {
|
|
8236
8717
|
...existingWrapperConfig,
|
|
8237
|
-
role:
|
|
8718
|
+
role: contract.role
|
|
8238
8719
|
};
|
|
8239
8720
|
}
|
|
8240
8721
|
const getBestAvailableKeyInfo = () => {
|
|
@@ -8344,7 +8825,7 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
|
|
|
8344
8825
|
}
|
|
8345
8826
|
let cachedTagSuffix = null;
|
|
8346
8827
|
const getTagSuffix = () => {
|
|
8347
|
-
cachedTagSuffix ??= formatTagName(element,
|
|
8828
|
+
cachedTagSuffix ??= formatTagName(element, resolvedNativeWrappers);
|
|
8348
8829
|
return cachedTagSuffix;
|
|
8349
8830
|
};
|
|
8350
8831
|
const getNativeRoleFromTagSuffix = () => getTagSuffix().slice(1);
|
|
@@ -8391,12 +8872,12 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
|
|
|
8391
8872
|
annotatorMetadata
|
|
8392
8873
|
});
|
|
8393
8874
|
};
|
|
8394
|
-
const { nativeWrappersValue, optionDataTestIdPrefixValue, semanticNameHint } = getNativeWrapperTransformInfo(element, componentName,
|
|
8875
|
+
const { nativeWrappersValue, optionDataTestIdPrefixValue, semanticNameHint } = getNativeWrapperTransformInfo(element, componentName, resolvedNativeWrappers);
|
|
8395
8876
|
const handlerDirective = element.props.find((p) => {
|
|
8396
8877
|
return p.type === NodeTypes.DIRECTIVE && p.name === "bind" && p.arg?.type === NodeTypes.SIMPLE_EXPRESSION && p.arg.content === "handler" && !!p.exp;
|
|
8397
8878
|
}) ?? null;
|
|
8398
8879
|
const handlerInfo = handlerDirective ? nodeHandlerAttributeInfo(element) : null;
|
|
8399
|
-
if (
|
|
8880
|
+
if (resolvedNativeWrappers[element.tag]?.role === "button" && handlerDirective && !handlerInfo) {
|
|
8400
8881
|
const loc = element.loc?.start;
|
|
8401
8882
|
const locationHint = loc ? `${loc.line}:${loc.column}` : "unknown";
|
|
8402
8883
|
const handlerSource = (handlerDirective.exp?.loc?.source ?? "").trim() || "<unknown>";
|
|
@@ -8427,7 +8908,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8427
8908
|
}
|
|
8428
8909
|
upsertAttribute(element, "option-data-testid-prefix", optionDataTestIdPrefixValue);
|
|
8429
8910
|
}
|
|
8430
|
-
const nativeRole =
|
|
8911
|
+
const nativeRole = resolvedNativeWrappers[element.tag]?.role ?? element.tag;
|
|
8431
8912
|
const wrapperHintCandidates = [
|
|
8432
8913
|
semanticNameHint,
|
|
8433
8914
|
getStaticAttributeContent(element, "title"),
|
|
@@ -8497,7 +8978,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8497
8978
|
const innerText = getInnerText(element) || null;
|
|
8498
8979
|
const toDirective = nodeHasToDirective(element);
|
|
8499
8980
|
if (toDirective) {
|
|
8500
|
-
const dataTestId = generateToDirectiveDataTestId(componentName, element, toDirective, context, hierarchyMap,
|
|
8981
|
+
const dataTestId = generateToDirectiveDataTestId(componentName, element, toDirective, context, hierarchyMap, resolvedNativeWrappers);
|
|
8501
8982
|
const target = tryResolveToDirectiveTargetComponentName(toDirective);
|
|
8502
8983
|
const routeNameHint = toDirectiveObjectFieldNameValue(toDirective);
|
|
8503
8984
|
const existing = tryGetExistingElementDataTestId(element, testIdAttribute);
|
|
@@ -8518,7 +8999,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8518
8999
|
});
|
|
8519
9000
|
return;
|
|
8520
9001
|
}
|
|
8521
|
-
if (handlerInfo &&
|
|
9002
|
+
if (handlerInfo && resolvedNativeWrappers[element.tag]) {
|
|
8522
9003
|
const testId = getHandlerAttributeValueDataTestId(handlerInfo.semanticNameHint);
|
|
8523
9004
|
applyResolvedDataTestIdForElement({
|
|
8524
9005
|
preferredGeneratedValue: testId,
|
|
@@ -8527,6 +9008,15 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8527
9008
|
});
|
|
8528
9009
|
return;
|
|
8529
9010
|
}
|
|
9011
|
+
const inferredWrapperRole = resolvedNativeWrappers[element.tag]?.inferred ? resolvedNativeWrappers[element.tag]?.role : null;
|
|
9012
|
+
if (inferredWrapperRole && innerText) {
|
|
9013
|
+
applyResolvedDataTestIdForElement({
|
|
9014
|
+
preferredGeneratedValue: staticAttributeValue(`${componentName}-${innerText}-${inferredWrapperRole}`),
|
|
9015
|
+
nativeRoleOverride: inferredWrapperRole,
|
|
9016
|
+
semanticNameHint: innerText
|
|
9017
|
+
});
|
|
9018
|
+
return;
|
|
9019
|
+
}
|
|
8530
9020
|
const existingElementDataTestId = tryGetExistingElementDataTestId(element, testIdAttribute);
|
|
8531
9021
|
const shouldPreserveExisting = existingElementDataTestId && existingIdBehavior === "preserve";
|
|
8532
9022
|
const clickDirective = tryGetClickDirective(element);
|
|
@@ -8553,7 +9043,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8553
9043
|
}
|
|
8554
9044
|
if (existingElementDataTestId) {
|
|
8555
9045
|
const inferredRole = getNativeRoleFromTagSuffix().toLowerCase();
|
|
8556
|
-
const isRecognizedInteractiveRole = inferredRole === "button" || inferredRole === "input" || inferredRole === "select" || inferredRole === "vselect" || inferredRole === "checkbox" || inferredRole === "toggle" || inferredRole === "radio" || inferredRole === "grid" || inferredRole === "link" || inferredRole === "tab" ||
|
|
9046
|
+
const isRecognizedInteractiveRole = inferredRole === "button" || inferredRole === "input" || inferredRole === "select" || inferredRole === "vselect" || inferredRole === "checkbox" || inferredRole === "toggle" || inferredRole === "radio" || inferredRole === "grid" || inferredRole === "link" || inferredRole === "tab" || isComponentLikeTag2(element.tag);
|
|
8557
9047
|
if (!isRecognizedInteractiveRole) {
|
|
8558
9048
|
return;
|
|
8559
9049
|
}
|
|
@@ -8776,7 +9266,7 @@ function createVuePluginWithTestIds(options) {
|
|
|
8776
9266
|
componentHierarchyMap,
|
|
8777
9267
|
crossFileKeyRegistry,
|
|
8778
9268
|
vueFilesPathMap,
|
|
8779
|
-
|
|
9269
|
+
skipTestIdGenerationInsideComponents,
|
|
8780
9270
|
getViewsDirAbs,
|
|
8781
9271
|
testIdAttribute,
|
|
8782
9272
|
accessibilityAudit,
|
|
@@ -8834,7 +9324,7 @@ function createVuePluginWithTestIds(options) {
|
|
|
8834
9324
|
componentName,
|
|
8835
9325
|
componentHierarchyMap,
|
|
8836
9326
|
nativeWrappers,
|
|
8837
|
-
|
|
9327
|
+
skipTestIdGenerationInsideComponents,
|
|
8838
9328
|
viewsDirAbs,
|
|
8839
9329
|
{
|
|
8840
9330
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -8892,7 +9382,7 @@ function createVuePluginWithTestIds(options) {
|
|
|
8892
9382
|
componentName,
|
|
8893
9383
|
componentHierarchyMap,
|
|
8894
9384
|
nativeWrappers,
|
|
8895
|
-
|
|
9385
|
+
skipTestIdGenerationInsideComponents,
|
|
8896
9386
|
viewsDirAbs,
|
|
8897
9387
|
{
|
|
8898
9388
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -9052,7 +9542,7 @@ function createBuildProcessorPlugin(options) {
|
|
|
9052
9542
|
projectRootRef,
|
|
9053
9543
|
nativeWrappers,
|
|
9054
9544
|
optionKeyAttribute,
|
|
9055
|
-
|
|
9545
|
+
skipTestIdGenerationInsideComponents,
|
|
9056
9546
|
getWrapperSearchRoots,
|
|
9057
9547
|
getResolvedRouterEntry,
|
|
9058
9548
|
loggerRef
|
|
@@ -9174,7 +9664,7 @@ function createBuildProcessorPlugin(options) {
|
|
|
9174
9664
|
componentName,
|
|
9175
9665
|
componentHierarchyMap,
|
|
9176
9666
|
nativeWrappers,
|
|
9177
|
-
|
|
9667
|
+
skipTestIdGenerationInsideComponents,
|
|
9178
9668
|
getViewsDirAbs(),
|
|
9179
9669
|
{
|
|
9180
9670
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -9307,7 +9797,7 @@ function createDevProcessorPlugin(options) {
|
|
|
9307
9797
|
elementMetadata,
|
|
9308
9798
|
nativeWrappers,
|
|
9309
9799
|
optionKeyAttribute,
|
|
9310
|
-
|
|
9800
|
+
skipTestIdGenerationInsideComponents,
|
|
9311
9801
|
getPageDirs,
|
|
9312
9802
|
getComponentDirs,
|
|
9313
9803
|
getLayoutDirs,
|
|
@@ -9530,7 +10020,7 @@ function createDevProcessorPlugin(options) {
|
|
|
9530
10020
|
componentName,
|
|
9531
10021
|
provisionalHierarchy,
|
|
9532
10022
|
nativeWrappers,
|
|
9533
|
-
|
|
10023
|
+
skipTestIdGenerationInsideComponents,
|
|
9534
10024
|
getViewsDirAbs(),
|
|
9535
10025
|
{
|
|
9536
10026
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -9876,7 +10366,7 @@ function createInternalPlugins(options) {
|
|
|
9876
10366
|
vueFilesPathMap,
|
|
9877
10367
|
nativeWrappers,
|
|
9878
10368
|
optionKeyAttribute,
|
|
9879
|
-
|
|
10369
|
+
skipTestIdGenerationInsideComponents,
|
|
9880
10370
|
getPageDirs,
|
|
9881
10371
|
getComponentDirs,
|
|
9882
10372
|
getLayoutDirs,
|
|
@@ -9928,7 +10418,7 @@ function createInternalPlugins(options) {
|
|
|
9928
10418
|
projectRootRef,
|
|
9929
10419
|
nativeWrappers,
|
|
9930
10420
|
optionKeyAttribute,
|
|
9931
|
-
|
|
10421
|
+
skipTestIdGenerationInsideComponents,
|
|
9932
10422
|
getWrapperSearchRoots,
|
|
9933
10423
|
getResolvedRouterEntry: resolveRouterEntry2,
|
|
9934
10424
|
loggerRef
|
|
@@ -9937,7 +10427,7 @@ function createInternalPlugins(options) {
|
|
|
9937
10427
|
elementMetadata,
|
|
9938
10428
|
nativeWrappers,
|
|
9939
10429
|
optionKeyAttribute,
|
|
9940
|
-
|
|
10430
|
+
skipTestIdGenerationInsideComponents,
|
|
9941
10431
|
getPageDirs,
|
|
9942
10432
|
getComponentDirs,
|
|
9943
10433
|
getLayoutDirs,
|
|
@@ -10192,7 +10682,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10192
10682
|
wrapperSearchRoots: injection.wrapperSearchRoots,
|
|
10193
10683
|
nativeWrappers: injection.nativeWrappers,
|
|
10194
10684
|
optionKeyAttribute: injection.optionKeyAttribute,
|
|
10195
|
-
|
|
10685
|
+
skipTestIdGenerationInsideComponents: injection.skipTestIdGenerationInsideComponents,
|
|
10196
10686
|
existingIdBehavior: injection.existingIdBehavior,
|
|
10197
10687
|
testIdAttribute: injection.attribute
|
|
10198
10688
|
})
|
|
@@ -10200,7 +10690,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10200
10690
|
const resolvedInjectionOptions = resolvedInjectionOptionsRef.current;
|
|
10201
10691
|
const nativeWrappers = resolvedInjectionOptions.nativeWrappers;
|
|
10202
10692
|
const optionKeyAttribute = resolvedInjectionOptions.optionKeyAttribute;
|
|
10203
|
-
const
|
|
10693
|
+
const skipTestIdGenerationInsideComponents = resolvedInjectionOptions.skipTestIdGenerationInsideComponents;
|
|
10204
10694
|
const testIdAttribute = resolvedInjectionOptions.testIdAttribute;
|
|
10205
10695
|
const routerEntry = !isNuxt ? vueGenerationOptions?.router?.entry : void 0;
|
|
10206
10696
|
const routerType = isNuxt ? "nuxt" : vueGenerationOptions?.router?.type ?? "vue-router";
|
|
@@ -10314,7 +10804,10 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10314
10804
|
}
|
|
10315
10805
|
};
|
|
10316
10806
|
const getViewsDirAbs = () => resolveFromProjectRoot(projectRootRef.current, getViewsDir());
|
|
10317
|
-
const getWrapperSearchRootsAbs = () =>
|
|
10807
|
+
const getWrapperSearchRootsAbs = () => Array.from(new Set([
|
|
10808
|
+
...getSourceDirs(),
|
|
10809
|
+
...getWrapperSearchRoots()
|
|
10810
|
+
].map((root) => resolveFromProjectRoot(projectRootRef.current, root))));
|
|
10318
10811
|
const { elementMetadata, semanticNameMap, componentHierarchyMap, crossFileKeyRegistry, vueFilesPathMap } = sharedState;
|
|
10319
10812
|
const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions } = createVuePluginWithTestIds({
|
|
10320
10813
|
vueOptions,
|
|
@@ -10328,7 +10821,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10328
10821
|
componentHierarchyMap,
|
|
10329
10822
|
crossFileKeyRegistry,
|
|
10330
10823
|
vueFilesPathMap,
|
|
10331
|
-
|
|
10824
|
+
skipTestIdGenerationInsideComponents,
|
|
10332
10825
|
getViewsDirAbs,
|
|
10333
10826
|
testIdAttribute,
|
|
10334
10827
|
accessibilityAudit: resolvedGenerationOptions.accessibilityAudit,
|
|
@@ -10349,7 +10842,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10349
10842
|
vueFilesPathMap,
|
|
10350
10843
|
nativeWrappers,
|
|
10351
10844
|
optionKeyAttribute,
|
|
10352
|
-
|
|
10845
|
+
skipTestIdGenerationInsideComponents,
|
|
10353
10846
|
getPageDirs,
|
|
10354
10847
|
getComponentDirs,
|
|
10355
10848
|
getLayoutDirs,
|