@immense/vue-pom-generator 1.0.93 → 1.0.95
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 +18 -24
- package/dist/index.cjs +790 -296
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +791 -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,686 @@ ${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, elementTag) {
|
|
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
|
+
return elementTag === "input" || elementTag === "uinput" ? "input" : "select";
|
|
7975
|
+
case "listbox":
|
|
7976
|
+
return "select";
|
|
7977
|
+
case "searchbox":
|
|
7978
|
+
case "spinbutton":
|
|
7979
|
+
case "textbox":
|
|
7980
|
+
return "input";
|
|
7981
|
+
case "switch":
|
|
7982
|
+
return "toggle";
|
|
7983
|
+
default:
|
|
7984
|
+
return null;
|
|
7985
|
+
}
|
|
7986
|
+
}
|
|
7987
|
+
function hasAttribute(element, name) {
|
|
7988
|
+
return element.props.some((prop) => {
|
|
7989
|
+
if (prop.type === NodeTypes.ATTRIBUTE) {
|
|
7990
|
+
return prop.name === name;
|
|
7991
|
+
}
|
|
7992
|
+
return prop.type === NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === name;
|
|
7993
|
+
});
|
|
7994
|
+
}
|
|
7995
|
+
function getElementControlRole(element) {
|
|
7996
|
+
const tag = element.tag.toLowerCase();
|
|
7997
|
+
const explicitRole = getStaticAttributeContent$1(element, "role");
|
|
7998
|
+
if (explicitRole) {
|
|
7999
|
+
return mapExplicitAriaRole(explicitRole, tag);
|
|
8000
|
+
}
|
|
8001
|
+
const type = (getStaticAttributeContent$1(element, "type") || "").toLowerCase();
|
|
8002
|
+
if (tag === "input" || tag === "uinput") {
|
|
8003
|
+
if (type === "radio") {
|
|
8004
|
+
return "radio";
|
|
8005
|
+
}
|
|
8006
|
+
if (type === "checkbox") {
|
|
8007
|
+
return "checkbox";
|
|
8008
|
+
}
|
|
8009
|
+
return "input";
|
|
8010
|
+
}
|
|
8011
|
+
if (tag === "textarea" || tag === "utextarea") {
|
|
8012
|
+
return "input";
|
|
8013
|
+
}
|
|
8014
|
+
if (tag === "select" || tag === "uselect") {
|
|
8015
|
+
return "select";
|
|
8016
|
+
}
|
|
8017
|
+
if (tag === "vselect") {
|
|
8018
|
+
return "vselect";
|
|
8019
|
+
}
|
|
8020
|
+
if (tag === "button" || tag === "ubutton") {
|
|
8021
|
+
return "button";
|
|
8022
|
+
}
|
|
8023
|
+
if (tag === "router-link" || tag === "routerlink") {
|
|
8024
|
+
return "link";
|
|
8025
|
+
}
|
|
8026
|
+
if ((tag === "a" || tag === "ua") && hasAttribute(element, "href")) {
|
|
8027
|
+
return "link";
|
|
8028
|
+
}
|
|
8029
|
+
return null;
|
|
8030
|
+
}
|
|
8031
|
+
function isComponentLikeTag(tag) {
|
|
8032
|
+
if (!tag) {
|
|
8033
|
+
return false;
|
|
8034
|
+
}
|
|
8035
|
+
return isAsciiUppercaseLetterCode(tag.charCodeAt(0)) || tag.includes("-");
|
|
8036
|
+
}
|
|
8037
|
+
function parseTemplateExpression(source) {
|
|
8038
|
+
try {
|
|
8039
|
+
return parseExpression(source, { plugins: ["typescript"] });
|
|
8040
|
+
} catch {
|
|
8041
|
+
return null;
|
|
8042
|
+
}
|
|
8043
|
+
}
|
|
8044
|
+
function directiveExpressionSource(directive) {
|
|
8045
|
+
if (!directive.exp) {
|
|
8046
|
+
return "";
|
|
8047
|
+
}
|
|
8048
|
+
return directive.exp.loc?.source || (directive.exp.type === NodeTypes.SIMPLE_EXPRESSION ? directive.exp.content : "");
|
|
8049
|
+
}
|
|
8050
|
+
function elementExplicitlyForwardsTestId(element, testIdAttribute, scriptMetadata) {
|
|
8051
|
+
for (const prop of element.props) {
|
|
8052
|
+
if (prop.type !== NodeTypes.DIRECTIVE || prop.name !== "bind" || !prop.exp) {
|
|
8053
|
+
continue;
|
|
8054
|
+
}
|
|
8055
|
+
const source = directiveExpressionSource(prop);
|
|
8056
|
+
const expression = parseTemplateExpression(source);
|
|
8057
|
+
if (!expression) {
|
|
8058
|
+
continue;
|
|
8059
|
+
}
|
|
8060
|
+
if (!prop.arg) {
|
|
8061
|
+
if (expressionForwardsTestId(expression, testIdAttribute, scriptMetadata.attrsObjectNames, scriptMetadata.attrsFunctionNames)) {
|
|
8062
|
+
return true;
|
|
8063
|
+
}
|
|
8064
|
+
continue;
|
|
8065
|
+
}
|
|
8066
|
+
if (prop.arg.type === NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic && prop.arg.content === testIdAttribute && expressionReadsTestId(expression, testIdAttribute, scriptMetadata.attrsObjectNames, scriptMetadata.attrsFunctionNames)) {
|
|
8067
|
+
return true;
|
|
8068
|
+
}
|
|
8069
|
+
}
|
|
8070
|
+
return false;
|
|
8071
|
+
}
|
|
8072
|
+
function walkTemplate(node, visitor) {
|
|
8073
|
+
if (node.type === NodeTypes.ELEMENT) {
|
|
8074
|
+
visitor(node);
|
|
8075
|
+
for (const child of node.children) {
|
|
8076
|
+
walkTemplate(child, visitor);
|
|
8077
|
+
}
|
|
8078
|
+
return;
|
|
8079
|
+
}
|
|
8080
|
+
if (node.type === NodeTypes.ROOT) {
|
|
8081
|
+
for (const child of node.children) {
|
|
8082
|
+
walkTemplate(child, visitor);
|
|
8083
|
+
}
|
|
8084
|
+
}
|
|
8085
|
+
}
|
|
8086
|
+
function getRenderedRootElements(ast) {
|
|
8087
|
+
const rendered = ast.children.filter((child) => {
|
|
8088
|
+
return child.type !== NodeTypes.COMMENT && !(child.type === NodeTypes.TEXT && child.content.trim() === "");
|
|
8089
|
+
});
|
|
8090
|
+
if (rendered.length !== 1 || rendered[0]?.type !== NodeTypes.ELEMENT || rendered[0].tag === "template") {
|
|
8091
|
+
return [];
|
|
8092
|
+
}
|
|
8093
|
+
return [rendered[0]];
|
|
8094
|
+
}
|
|
8095
|
+
function analyzeWrapperContractFromSfc(options) {
|
|
8096
|
+
const { descriptor } = parse$1(options.source, { filename: options.filePath });
|
|
8097
|
+
const template = descriptor.template?.content ?? "";
|
|
8098
|
+
if (!template.trim()) {
|
|
8099
|
+
return {
|
|
8100
|
+
role: null,
|
|
8101
|
+
targetRoles: [],
|
|
8102
|
+
forwardedTestIdTargetOffsets: /* @__PURE__ */ new Set(),
|
|
8103
|
+
forwardedTestIdTargetSfcOffsets: /* @__PURE__ */ new Set(),
|
|
8104
|
+
explicitlyForwardedTestIdTargetOffsets: /* @__PURE__ */ new Set(),
|
|
8105
|
+
explicitlyForwardedTestIdTargetSfcOffsets: /* @__PURE__ */ new Set()
|
|
8106
|
+
};
|
|
8107
|
+
}
|
|
8108
|
+
const scriptMetadata = analyzeScriptForwardingMetadata(
|
|
8109
|
+
[descriptor.script, descriptor.scriptSetup].filter((block) => !!block).map((block) => ({ content: block.content, lang: block.lang })),
|
|
8110
|
+
options.testIdAttribute
|
|
8111
|
+
);
|
|
8112
|
+
const ast = parse$2(template, { comments: false });
|
|
8113
|
+
const targets = /* @__PURE__ */ new Map();
|
|
8114
|
+
const explicitTargetOffsets = /* @__PURE__ */ new Set();
|
|
8115
|
+
if (scriptMetadata.inheritAttrs) {
|
|
8116
|
+
for (const element of getRenderedRootElements(ast)) {
|
|
8117
|
+
targets.set(element.loc.start.offset, element);
|
|
8118
|
+
}
|
|
8119
|
+
}
|
|
8120
|
+
walkTemplate(ast, (element) => {
|
|
8121
|
+
if (elementExplicitlyForwardsTestId(element, options.testIdAttribute, scriptMetadata)) {
|
|
8122
|
+
targets.set(element.loc.start.offset, element);
|
|
8123
|
+
explicitTargetOffsets.add(element.loc.start.offset);
|
|
8124
|
+
}
|
|
8125
|
+
});
|
|
8126
|
+
const targetRoles = [...targets.values()].map((element) => {
|
|
8127
|
+
const directRole = getElementControlRole(element);
|
|
8128
|
+
if (directRole) {
|
|
8129
|
+
return directRole;
|
|
8130
|
+
}
|
|
8131
|
+
if (isComponentLikeTag(element.tag)) {
|
|
8132
|
+
return options.resolveNestedContract(element.tag)?.role ?? null;
|
|
8133
|
+
}
|
|
8134
|
+
return null;
|
|
8135
|
+
});
|
|
8136
|
+
const uniqueRoles = new Set(targetRoles);
|
|
8137
|
+
const role = uniqueRoles.size === 1 && !uniqueRoles.has(null) ? targetRoles[0] ?? null : null;
|
|
8138
|
+
const templateContentStartOffset = descriptor.template?.loc.start.offset ?? 0;
|
|
8139
|
+
const toSfcOffsets = (offsets) => new Set(
|
|
8140
|
+
[...offsets].map((offset2) => offset2 + templateContentStartOffset)
|
|
8141
|
+
);
|
|
8142
|
+
return {
|
|
8143
|
+
role,
|
|
8144
|
+
targetRoles,
|
|
8145
|
+
forwardedTestIdTargetOffsets: new Set(targets.keys()),
|
|
8146
|
+
forwardedTestIdTargetSfcOffsets: toSfcOffsets(targets.keys()),
|
|
8147
|
+
explicitlyForwardedTestIdTargetOffsets: explicitTargetOffsets,
|
|
8148
|
+
explicitlyForwardedTestIdTargetSfcOffsets: toSfcOffsets(explicitTargetOffsets)
|
|
8149
|
+
};
|
|
8150
|
+
}
|
|
8151
|
+
function resolveWrapperContractForTag(options) {
|
|
8152
|
+
const normalizedSearchRoots = normalizeWrapperSearchRoots(options.wrapperSearchRoots ?? []);
|
|
8153
|
+
const memo = /* @__PURE__ */ new Map();
|
|
8154
|
+
const resolving = /* @__PURE__ */ new Set();
|
|
8155
|
+
const resolveTag = (tag) => {
|
|
8156
|
+
const first = tag.charCodeAt(0);
|
|
8157
|
+
if (!isAsciiUppercaseLetterCode(first) && !tag.includes("-")) {
|
|
8158
|
+
return null;
|
|
8159
|
+
}
|
|
8160
|
+
const filePath = resolveSfcPathForTag(tag, options.vueFilesPathMap, normalizedSearchRoots);
|
|
8161
|
+
if (!filePath) {
|
|
8162
|
+
return null;
|
|
8163
|
+
}
|
|
8164
|
+
const normalizedPath = path.normalize(filePath);
|
|
8165
|
+
if (memo.has(normalizedPath)) {
|
|
8166
|
+
return memo.get(normalizedPath) ?? null;
|
|
8167
|
+
}
|
|
8168
|
+
if (resolving.has(normalizedPath)) {
|
|
8169
|
+
return null;
|
|
8170
|
+
}
|
|
8171
|
+
const source = fs.readFileSync(normalizedPath, "utf8");
|
|
8172
|
+
resolving.add(normalizedPath);
|
|
8173
|
+
try {
|
|
8174
|
+
const contract = analyzeWrapperContractFromSfc({
|
|
8175
|
+
filePath: normalizedPath,
|
|
8176
|
+
source,
|
|
8177
|
+
testIdAttribute: options.testIdAttribute,
|
|
8178
|
+
resolveNestedContract: resolveTag
|
|
8179
|
+
});
|
|
8180
|
+
memo.set(normalizedPath, contract);
|
|
8181
|
+
return contract;
|
|
8182
|
+
} finally {
|
|
8183
|
+
resolving.delete(normalizedPath);
|
|
8184
|
+
}
|
|
8185
|
+
};
|
|
8186
|
+
return resolveTag(options.tag);
|
|
8187
|
+
}
|
|
8188
|
+
const CLICK_EVENT_NAME = TESTID_CLICK_EVENT_NAME;
|
|
8189
|
+
function getStaticAttributeContent(element, name) {
|
|
8190
|
+
const attr = element.props.find((prop) => {
|
|
8191
|
+
return prop.type === NodeTypes.ATTRIBUTE && prop.name === name;
|
|
8192
|
+
});
|
|
8193
|
+
return attr?.value?.content?.trim() || null;
|
|
8194
|
+
}
|
|
8195
|
+
function getNativeHtmlControlRole(element) {
|
|
8196
|
+
return getElementControlRole(element);
|
|
8197
|
+
}
|
|
8198
|
+
function normalizeControlLabelText(value) {
|
|
8199
|
+
const normalized = (value ?? "").replace(/\*/g, " ").replace(/\s+/g, " ").trim();
|
|
8200
|
+
return normalized || null;
|
|
8201
|
+
}
|
|
8202
|
+
function getLabelNodeText(labelNode) {
|
|
8203
|
+
for (const child of labelNode.children || []) {
|
|
8204
|
+
if (child.type === NodeTypes.TEXT) {
|
|
8205
|
+
const normalized2 = normalizeControlLabelText(child.content);
|
|
8206
|
+
if (normalized2) {
|
|
8207
|
+
return normalized2;
|
|
8208
|
+
}
|
|
8209
|
+
continue;
|
|
8210
|
+
}
|
|
8211
|
+
if (child.type !== NodeTypes.ELEMENT) {
|
|
8212
|
+
continue;
|
|
8213
|
+
}
|
|
8214
|
+
if (getNativeHtmlControlRole(child)) {
|
|
8215
|
+
continue;
|
|
8216
|
+
}
|
|
8217
|
+
const normalized = normalizeControlLabelText(getInnerText(child));
|
|
8218
|
+
if (normalized) {
|
|
8219
|
+
return normalized;
|
|
8220
|
+
}
|
|
8221
|
+
}
|
|
8222
|
+
return normalizeControlLabelText(getInnerText(labelNode));
|
|
8223
|
+
}
|
|
8224
|
+
function getAssociatedLabelText(element, hierarchyMap2) {
|
|
8225
|
+
let parent = hierarchyMap2.get(element) || null;
|
|
8226
|
+
while (parent) {
|
|
8227
|
+
if (parent.tag === "label") {
|
|
8228
|
+
return getLabelNodeText(parent);
|
|
8229
|
+
}
|
|
8230
|
+
parent = hierarchyMap2.get(parent) || null;
|
|
8231
|
+
}
|
|
8232
|
+
const id = getStaticAttributeContent(element, "id");
|
|
8233
|
+
if (!id) {
|
|
8234
|
+
return null;
|
|
8235
|
+
}
|
|
8236
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
8237
|
+
for (const child of hierarchyMap2.keys()) {
|
|
8238
|
+
candidates.add(child);
|
|
8239
|
+
}
|
|
8240
|
+
for (const maybeParent of hierarchyMap2.values()) {
|
|
8241
|
+
if (maybeParent) {
|
|
8242
|
+
candidates.add(maybeParent);
|
|
8243
|
+
}
|
|
8244
|
+
}
|
|
8245
|
+
for (const candidate of candidates) {
|
|
8246
|
+
if (candidate.tag !== "label") {
|
|
8247
|
+
continue;
|
|
8248
|
+
}
|
|
8249
|
+
if (getStaticAttributeContent(candidate, "for") === id) {
|
|
8250
|
+
return getLabelNodeText(candidate);
|
|
8251
|
+
}
|
|
8252
|
+
}
|
|
8253
|
+
return null;
|
|
8254
|
+
}
|
|
7651
8255
|
function trimLeadingSeparators(value) {
|
|
7652
8256
|
if (!value) {
|
|
7653
8257
|
return "";
|
|
@@ -7700,11 +8304,11 @@ function tryExtractStableHintFromConditionalExpressionSource(source) {
|
|
|
7700
8304
|
return false;
|
|
7701
8305
|
const isUnderscore = (ch) => ch === 95;
|
|
7702
8306
|
const first = v.charCodeAt(0);
|
|
7703
|
-
if (!isAsciiLetterCode(first))
|
|
8307
|
+
if (!isAsciiLetterCode$1(first))
|
|
7704
8308
|
return false;
|
|
7705
8309
|
for (let i = 1; i < v.length; i += 1) {
|
|
7706
8310
|
const ch = v.charCodeAt(i);
|
|
7707
|
-
if (isAsciiLetterCode(ch) || isAsciiDigitCode(ch) || isUnderscore(ch)) {
|
|
8311
|
+
if (isAsciiLetterCode$1(ch) || isAsciiDigitCode$1(ch) || isUnderscore(ch)) {
|
|
7708
8312
|
continue;
|
|
7709
8313
|
}
|
|
7710
8314
|
return false;
|
|
@@ -7761,150 +8365,6 @@ function tryExtractStableHintFromConditionalExpressionSource(source) {
|
|
|
7761
8365
|
return null;
|
|
7762
8366
|
}
|
|
7763
8367
|
}
|
|
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
8368
|
function tryWrapClickDirectiveForTestEvents(element, testIdAttribute, resolvedRuntimeTestId) {
|
|
7909
8369
|
const jsStringLiteral = (value) => {
|
|
7910
8370
|
return JSON.stringify(value);
|
|
@@ -8049,7 +8509,7 @@ function tryWrapClickDirectiveForTestEvents(element, testIdAttribute, resolvedRu
|
|
|
8049
8509
|
}
|
|
8050
8510
|
let previousFileName = "";
|
|
8051
8511
|
const hierarchyMap = /* @__PURE__ */ new Map();
|
|
8052
|
-
function createTestIdTransform(componentName, componentHierarchyMap, nativeWrappers = {},
|
|
8512
|
+
function createTestIdTransform(componentName, componentHierarchyMap, nativeWrappers = {}, skipTestIdGenerationInsideComponents = [], viewsDirAbs, options = {}) {
|
|
8053
8513
|
const existingIdBehavior = options.existingIdBehavior ?? "error";
|
|
8054
8514
|
const testIdAttribute = (options.testIdAttribute || "data-testid").trim() || "data-testid";
|
|
8055
8515
|
const nameCollisionBehavior = options.nameCollisionBehavior ?? "error";
|
|
@@ -8060,6 +8520,21 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8060
8520
|
const annotatorMetadata = options.annotatorMetadata ?? null;
|
|
8061
8521
|
const crossFileKeyRegistry = options.crossFileKeyRegistry;
|
|
8062
8522
|
const optionKeyAttribute = options.optionKeyAttribute ?? {};
|
|
8523
|
+
const resolvedNativeWrappers = Object.fromEntries(
|
|
8524
|
+
Object.entries(nativeWrappers).map(([tag, config]) => [tag, { ...config }])
|
|
8525
|
+
);
|
|
8526
|
+
const wrapperContractByTag = /* @__PURE__ */ new Map();
|
|
8527
|
+
const getWrapperContract = (tag) => {
|
|
8528
|
+
if (!wrapperContractByTag.has(tag)) {
|
|
8529
|
+
wrapperContractByTag.set(tag, resolveWrapperContractForTag({
|
|
8530
|
+
tag,
|
|
8531
|
+
vueFilesPathMap,
|
|
8532
|
+
wrapperSearchRoots,
|
|
8533
|
+
testIdAttribute
|
|
8534
|
+
}));
|
|
8535
|
+
}
|
|
8536
|
+
return wrapperContractByTag.get(tag) ?? null;
|
|
8537
|
+
};
|
|
8063
8538
|
const safeRealpath2 = (p) => {
|
|
8064
8539
|
try {
|
|
8065
8540
|
return fs.existsSync(p) ? fs.realpathSync(p) : p;
|
|
@@ -8111,7 +8586,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8111
8586
|
}
|
|
8112
8587
|
};
|
|
8113
8588
|
return (node, context) => {
|
|
8114
|
-
if (
|
|
8589
|
+
if (skipTestIdGenerationInsideComponents.includes(componentName)) {
|
|
8115
8590
|
return;
|
|
8116
8591
|
}
|
|
8117
8592
|
if (node.type === NodeTypes.IF) {
|
|
@@ -8176,13 +8651,13 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8176
8651
|
}
|
|
8177
8652
|
return deps;
|
|
8178
8653
|
})();
|
|
8179
|
-
const
|
|
8654
|
+
const isComponentLikeTag2 = (tag) => {
|
|
8180
8655
|
if (!tag) return false;
|
|
8181
8656
|
const first = tag.charCodeAt(0);
|
|
8182
|
-
const isUpper = isAsciiUppercaseLetterCode(first);
|
|
8657
|
+
const isUpper = isAsciiUppercaseLetterCode$1(first);
|
|
8183
8658
|
return isUpper || tag.includes("-");
|
|
8184
8659
|
};
|
|
8185
|
-
if (
|
|
8660
|
+
if (isComponentLikeTag2(element.tag)) {
|
|
8186
8661
|
dependencies.usedComponentSet.add(element.tag);
|
|
8187
8662
|
if (crossFileKeyRegistry && context.scopes.vSlot > 0) {
|
|
8188
8663
|
const findSlotTemplate = () => {
|
|
@@ -8210,31 +8685,38 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8210
8685
|
}
|
|
8211
8686
|
}
|
|
8212
8687
|
}
|
|
8213
|
-
const
|
|
8688
|
+
const ownWrapperContract = getWrapperContract(componentName);
|
|
8689
|
+
const elementStartOffset = element.loc.start.offset;
|
|
8690
|
+
const isExplicitFallthroughTarget = ownWrapperContract?.explicitlyForwardedTestIdTargetOffsets.has(elementStartOffset) || ownWrapperContract?.explicitlyForwardedTestIdTargetSfcOffsets.has(elementStartOffset);
|
|
8691
|
+
if (!dependencies.isView && isExplicitFallthroughTarget) {
|
|
8692
|
+
return;
|
|
8693
|
+
}
|
|
8694
|
+
const existingWrapperConfig = resolvedNativeWrappers[element.tag];
|
|
8214
8695
|
if (!existingWrapperConfig) {
|
|
8215
|
-
const
|
|
8216
|
-
if (
|
|
8217
|
-
|
|
8218
|
-
} else if (element.tag.endsWith("Button") && !
|
|
8219
|
-
|
|
8696
|
+
const contract = getWrapperContract(element.tag);
|
|
8697
|
+
if (contract?.role) {
|
|
8698
|
+
resolvedNativeWrappers[element.tag] = { role: contract.role, inferred: true };
|
|
8699
|
+
} else if (element.tag.endsWith("Button") && !resolveSfcPathForTag(element.tag, vueFilesPathMap, wrapperSearchRoots)) {
|
|
8700
|
+
resolvedNativeWrappers[element.tag] = { role: "button" };
|
|
8220
8701
|
} else if (element.tag === "DxDataGrid") {
|
|
8221
|
-
|
|
8702
|
+
resolvedNativeWrappers[element.tag] = { role: "grid" };
|
|
8222
8703
|
}
|
|
8223
8704
|
} else if (!existingWrapperConfig.role) {
|
|
8224
|
-
const
|
|
8225
|
-
if (!
|
|
8705
|
+
const contract = getWrapperContract(element.tag);
|
|
8706
|
+
if (!contract?.role) {
|
|
8226
8707
|
const loc = element.loc?.start;
|
|
8227
8708
|
const locationHint = loc ? `${loc.line}:${loc.column}` : "unknown";
|
|
8709
|
+
const targetRoles = contract?.targetRoles.length ? contract.targetRoles.map((role) => role ?? "non-interactive").join(", ") : "no forwarded test-id target";
|
|
8228
8710
|
throw new Error(
|
|
8229
8711
|
`[vue-pom-generator] Could not infer a native role for declared wrapper <${element.tag}> in ${componentName} (${context.filename ?? "unknown"}:${locationHint}).
|
|
8230
|
-
|
|
8712
|
+
Resolved fallthrough targets: ${targetRoles}. The generator requires one stable role across every target.
|
|
8231
8713
|
|
|
8232
8714
|
Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role: "button", ... } }).`
|
|
8233
8715
|
);
|
|
8234
8716
|
}
|
|
8235
|
-
|
|
8717
|
+
resolvedNativeWrappers[element.tag] = {
|
|
8236
8718
|
...existingWrapperConfig,
|
|
8237
|
-
role:
|
|
8719
|
+
role: contract.role
|
|
8238
8720
|
};
|
|
8239
8721
|
}
|
|
8240
8722
|
const getBestAvailableKeyInfo = () => {
|
|
@@ -8344,7 +8826,7 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
|
|
|
8344
8826
|
}
|
|
8345
8827
|
let cachedTagSuffix = null;
|
|
8346
8828
|
const getTagSuffix = () => {
|
|
8347
|
-
cachedTagSuffix ??= formatTagName(element,
|
|
8829
|
+
cachedTagSuffix ??= formatTagName(element, resolvedNativeWrappers);
|
|
8348
8830
|
return cachedTagSuffix;
|
|
8349
8831
|
};
|
|
8350
8832
|
const getNativeRoleFromTagSuffix = () => getTagSuffix().slice(1);
|
|
@@ -8391,12 +8873,12 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
|
|
|
8391
8873
|
annotatorMetadata
|
|
8392
8874
|
});
|
|
8393
8875
|
};
|
|
8394
|
-
const { nativeWrappersValue, optionDataTestIdPrefixValue, semanticNameHint } = getNativeWrapperTransformInfo(element, componentName,
|
|
8876
|
+
const { nativeWrappersValue, optionDataTestIdPrefixValue, semanticNameHint } = getNativeWrapperTransformInfo(element, componentName, resolvedNativeWrappers);
|
|
8395
8877
|
const handlerDirective = element.props.find((p) => {
|
|
8396
8878
|
return p.type === NodeTypes.DIRECTIVE && p.name === "bind" && p.arg?.type === NodeTypes.SIMPLE_EXPRESSION && p.arg.content === "handler" && !!p.exp;
|
|
8397
8879
|
}) ?? null;
|
|
8398
8880
|
const handlerInfo = handlerDirective ? nodeHandlerAttributeInfo(element) : null;
|
|
8399
|
-
if (
|
|
8881
|
+
if (resolvedNativeWrappers[element.tag]?.role === "button" && handlerDirective && !handlerInfo) {
|
|
8400
8882
|
const loc = element.loc?.start;
|
|
8401
8883
|
const locationHint = loc ? `${loc.line}:${loc.column}` : "unknown";
|
|
8402
8884
|
const handlerSource = (handlerDirective.exp?.loc?.source ?? "").trim() || "<unknown>";
|
|
@@ -8427,7 +8909,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8427
8909
|
}
|
|
8428
8910
|
upsertAttribute(element, "option-data-testid-prefix", optionDataTestIdPrefixValue);
|
|
8429
8911
|
}
|
|
8430
|
-
const nativeRole =
|
|
8912
|
+
const nativeRole = resolvedNativeWrappers[element.tag]?.role ?? element.tag;
|
|
8431
8913
|
const wrapperHintCandidates = [
|
|
8432
8914
|
semanticNameHint,
|
|
8433
8915
|
getStaticAttributeContent(element, "title"),
|
|
@@ -8497,7 +8979,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8497
8979
|
const innerText = getInnerText(element) || null;
|
|
8498
8980
|
const toDirective = nodeHasToDirective(element);
|
|
8499
8981
|
if (toDirective) {
|
|
8500
|
-
const dataTestId = generateToDirectiveDataTestId(componentName, element, toDirective, context, hierarchyMap,
|
|
8982
|
+
const dataTestId = generateToDirectiveDataTestId(componentName, element, toDirective, context, hierarchyMap, resolvedNativeWrappers);
|
|
8501
8983
|
const target = tryResolveToDirectiveTargetComponentName(toDirective);
|
|
8502
8984
|
const routeNameHint = toDirectiveObjectFieldNameValue(toDirective);
|
|
8503
8985
|
const existing = tryGetExistingElementDataTestId(element, testIdAttribute);
|
|
@@ -8518,7 +9000,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8518
9000
|
});
|
|
8519
9001
|
return;
|
|
8520
9002
|
}
|
|
8521
|
-
if (handlerInfo &&
|
|
9003
|
+
if (handlerInfo && resolvedNativeWrappers[element.tag]) {
|
|
8522
9004
|
const testId = getHandlerAttributeValueDataTestId(handlerInfo.semanticNameHint);
|
|
8523
9005
|
applyResolvedDataTestIdForElement({
|
|
8524
9006
|
preferredGeneratedValue: testId,
|
|
@@ -8527,6 +9009,15 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8527
9009
|
});
|
|
8528
9010
|
return;
|
|
8529
9011
|
}
|
|
9012
|
+
const inferredWrapperRole = resolvedNativeWrappers[element.tag]?.inferred ? resolvedNativeWrappers[element.tag]?.role : null;
|
|
9013
|
+
if (inferredWrapperRole && innerText) {
|
|
9014
|
+
applyResolvedDataTestIdForElement({
|
|
9015
|
+
preferredGeneratedValue: staticAttributeValue(`${componentName}-${innerText}-${inferredWrapperRole}`),
|
|
9016
|
+
nativeRoleOverride: inferredWrapperRole,
|
|
9017
|
+
semanticNameHint: innerText
|
|
9018
|
+
});
|
|
9019
|
+
return;
|
|
9020
|
+
}
|
|
8530
9021
|
const existingElementDataTestId = tryGetExistingElementDataTestId(element, testIdAttribute);
|
|
8531
9022
|
const shouldPreserveExisting = existingElementDataTestId && existingIdBehavior === "preserve";
|
|
8532
9023
|
const clickDirective = tryGetClickDirective(element);
|
|
@@ -8553,7 +9044,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8553
9044
|
}
|
|
8554
9045
|
if (existingElementDataTestId) {
|
|
8555
9046
|
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" ||
|
|
9047
|
+
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
9048
|
if (!isRecognizedInteractiveRole) {
|
|
8558
9049
|
return;
|
|
8559
9050
|
}
|
|
@@ -8776,7 +9267,7 @@ function createVuePluginWithTestIds(options) {
|
|
|
8776
9267
|
componentHierarchyMap,
|
|
8777
9268
|
crossFileKeyRegistry,
|
|
8778
9269
|
vueFilesPathMap,
|
|
8779
|
-
|
|
9270
|
+
skipTestIdGenerationInsideComponents,
|
|
8780
9271
|
getViewsDirAbs,
|
|
8781
9272
|
testIdAttribute,
|
|
8782
9273
|
accessibilityAudit,
|
|
@@ -8834,7 +9325,7 @@ function createVuePluginWithTestIds(options) {
|
|
|
8834
9325
|
componentName,
|
|
8835
9326
|
componentHierarchyMap,
|
|
8836
9327
|
nativeWrappers,
|
|
8837
|
-
|
|
9328
|
+
skipTestIdGenerationInsideComponents,
|
|
8838
9329
|
viewsDirAbs,
|
|
8839
9330
|
{
|
|
8840
9331
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -8892,7 +9383,7 @@ function createVuePluginWithTestIds(options) {
|
|
|
8892
9383
|
componentName,
|
|
8893
9384
|
componentHierarchyMap,
|
|
8894
9385
|
nativeWrappers,
|
|
8895
|
-
|
|
9386
|
+
skipTestIdGenerationInsideComponents,
|
|
8896
9387
|
viewsDirAbs,
|
|
8897
9388
|
{
|
|
8898
9389
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -9052,7 +9543,7 @@ function createBuildProcessorPlugin(options) {
|
|
|
9052
9543
|
projectRootRef,
|
|
9053
9544
|
nativeWrappers,
|
|
9054
9545
|
optionKeyAttribute,
|
|
9055
|
-
|
|
9546
|
+
skipTestIdGenerationInsideComponents,
|
|
9056
9547
|
getWrapperSearchRoots,
|
|
9057
9548
|
getResolvedRouterEntry,
|
|
9058
9549
|
loggerRef
|
|
@@ -9174,7 +9665,7 @@ function createBuildProcessorPlugin(options) {
|
|
|
9174
9665
|
componentName,
|
|
9175
9666
|
componentHierarchyMap,
|
|
9176
9667
|
nativeWrappers,
|
|
9177
|
-
|
|
9668
|
+
skipTestIdGenerationInsideComponents,
|
|
9178
9669
|
getViewsDirAbs(),
|
|
9179
9670
|
{
|
|
9180
9671
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -9307,7 +9798,7 @@ function createDevProcessorPlugin(options) {
|
|
|
9307
9798
|
elementMetadata,
|
|
9308
9799
|
nativeWrappers,
|
|
9309
9800
|
optionKeyAttribute,
|
|
9310
|
-
|
|
9801
|
+
skipTestIdGenerationInsideComponents,
|
|
9311
9802
|
getPageDirs,
|
|
9312
9803
|
getComponentDirs,
|
|
9313
9804
|
getLayoutDirs,
|
|
@@ -9530,7 +10021,7 @@ function createDevProcessorPlugin(options) {
|
|
|
9530
10021
|
componentName,
|
|
9531
10022
|
provisionalHierarchy,
|
|
9532
10023
|
nativeWrappers,
|
|
9533
|
-
|
|
10024
|
+
skipTestIdGenerationInsideComponents,
|
|
9534
10025
|
getViewsDirAbs(),
|
|
9535
10026
|
{
|
|
9536
10027
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -9876,7 +10367,7 @@ function createInternalPlugins(options) {
|
|
|
9876
10367
|
vueFilesPathMap,
|
|
9877
10368
|
nativeWrappers,
|
|
9878
10369
|
optionKeyAttribute,
|
|
9879
|
-
|
|
10370
|
+
skipTestIdGenerationInsideComponents,
|
|
9880
10371
|
getPageDirs,
|
|
9881
10372
|
getComponentDirs,
|
|
9882
10373
|
getLayoutDirs,
|
|
@@ -9928,7 +10419,7 @@ function createInternalPlugins(options) {
|
|
|
9928
10419
|
projectRootRef,
|
|
9929
10420
|
nativeWrappers,
|
|
9930
10421
|
optionKeyAttribute,
|
|
9931
|
-
|
|
10422
|
+
skipTestIdGenerationInsideComponents,
|
|
9932
10423
|
getWrapperSearchRoots,
|
|
9933
10424
|
getResolvedRouterEntry: resolveRouterEntry2,
|
|
9934
10425
|
loggerRef
|
|
@@ -9937,7 +10428,7 @@ function createInternalPlugins(options) {
|
|
|
9937
10428
|
elementMetadata,
|
|
9938
10429
|
nativeWrappers,
|
|
9939
10430
|
optionKeyAttribute,
|
|
9940
|
-
|
|
10431
|
+
skipTestIdGenerationInsideComponents,
|
|
9941
10432
|
getPageDirs,
|
|
9942
10433
|
getComponentDirs,
|
|
9943
10434
|
getLayoutDirs,
|
|
@@ -10192,7 +10683,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10192
10683
|
wrapperSearchRoots: injection.wrapperSearchRoots,
|
|
10193
10684
|
nativeWrappers: injection.nativeWrappers,
|
|
10194
10685
|
optionKeyAttribute: injection.optionKeyAttribute,
|
|
10195
|
-
|
|
10686
|
+
skipTestIdGenerationInsideComponents: injection.skipTestIdGenerationInsideComponents,
|
|
10196
10687
|
existingIdBehavior: injection.existingIdBehavior,
|
|
10197
10688
|
testIdAttribute: injection.attribute
|
|
10198
10689
|
})
|
|
@@ -10200,7 +10691,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10200
10691
|
const resolvedInjectionOptions = resolvedInjectionOptionsRef.current;
|
|
10201
10692
|
const nativeWrappers = resolvedInjectionOptions.nativeWrappers;
|
|
10202
10693
|
const optionKeyAttribute = resolvedInjectionOptions.optionKeyAttribute;
|
|
10203
|
-
const
|
|
10694
|
+
const skipTestIdGenerationInsideComponents = resolvedInjectionOptions.skipTestIdGenerationInsideComponents;
|
|
10204
10695
|
const testIdAttribute = resolvedInjectionOptions.testIdAttribute;
|
|
10205
10696
|
const routerEntry = !isNuxt ? vueGenerationOptions?.router?.entry : void 0;
|
|
10206
10697
|
const routerType = isNuxt ? "nuxt" : vueGenerationOptions?.router?.type ?? "vue-router";
|
|
@@ -10314,7 +10805,10 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10314
10805
|
}
|
|
10315
10806
|
};
|
|
10316
10807
|
const getViewsDirAbs = () => resolveFromProjectRoot(projectRootRef.current, getViewsDir());
|
|
10317
|
-
const getWrapperSearchRootsAbs = () =>
|
|
10808
|
+
const getWrapperSearchRootsAbs = () => Array.from(new Set([
|
|
10809
|
+
...getSourceDirs(),
|
|
10810
|
+
...getWrapperSearchRoots()
|
|
10811
|
+
].map((root) => resolveFromProjectRoot(projectRootRef.current, root))));
|
|
10318
10812
|
const { elementMetadata, semanticNameMap, componentHierarchyMap, crossFileKeyRegistry, vueFilesPathMap } = sharedState;
|
|
10319
10813
|
const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions } = createVuePluginWithTestIds({
|
|
10320
10814
|
vueOptions,
|
|
@@ -10328,7 +10822,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10328
10822
|
componentHierarchyMap,
|
|
10329
10823
|
crossFileKeyRegistry,
|
|
10330
10824
|
vueFilesPathMap,
|
|
10331
|
-
|
|
10825
|
+
skipTestIdGenerationInsideComponents,
|
|
10332
10826
|
getViewsDirAbs,
|
|
10333
10827
|
testIdAttribute,
|
|
10334
10828
|
accessibilityAudit: resolvedGenerationOptions.accessibilityAudit,
|
|
@@ -10349,7 +10843,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10349
10843
|
vueFilesPathMap,
|
|
10350
10844
|
nativeWrappers,
|
|
10351
10845
|
optionKeyAttribute,
|
|
10352
|
-
|
|
10846
|
+
skipTestIdGenerationInsideComponents,
|
|
10353
10847
|
getPageDirs,
|
|
10354
10848
|
getComponentDirs,
|
|
10355
10849
|
getLayoutDirs,
|