@immense/vue-pom-generator 1.0.92 → 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 +33 -17
- package/RELEASE_NOTES.md +64 -100
- 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/playwright/runtime.cjs +945 -0
- package/dist/playwright/runtime.cjs.map +1 -0
- package/dist/playwright/runtime.mjs +945 -0
- package/dist/playwright/runtime.mjs.map +1 -0
- 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/vite.config.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 +6 -1
package/dist/index.cjs
CHANGED
|
@@ -279,7 +279,7 @@ function resolveInjectionSupportOptions(options) {
|
|
|
279
279
|
wrapperSearchRoots: isNuxt ? [] : options.wrapperSearchRoots ?? [],
|
|
280
280
|
nativeWrappers: options.nativeWrappers ?? {},
|
|
281
281
|
optionKeyAttribute: options.optionKeyAttribute ?? {},
|
|
282
|
-
|
|
282
|
+
skipTestIdGenerationInsideComponents: options.skipTestIdGenerationInsideComponents ?? [],
|
|
283
283
|
existingIdBehavior: options.existingIdBehavior ?? "error",
|
|
284
284
|
testIdAttribute: (options.testIdAttribute ?? "data-testid").trim() || "data-testid"
|
|
285
285
|
};
|
|
@@ -1246,20 +1246,20 @@ function upperFirst(value) {
|
|
|
1246
1246
|
function collapseWhitespace(value) {
|
|
1247
1247
|
return value.replace(/\s+/g, " ").trim();
|
|
1248
1248
|
}
|
|
1249
|
-
function isAsciiUppercaseLetterCode(code) {
|
|
1249
|
+
function isAsciiUppercaseLetterCode$1(code) {
|
|
1250
1250
|
return code >= 65 && code <= 90;
|
|
1251
1251
|
}
|
|
1252
1252
|
function isAsciiLowercaseLetterCode(code) {
|
|
1253
1253
|
return code >= 97 && code <= 122;
|
|
1254
1254
|
}
|
|
1255
|
-
function isAsciiLetterCode(code) {
|
|
1256
|
-
return isAsciiUppercaseLetterCode(code) || isAsciiLowercaseLetterCode(code);
|
|
1255
|
+
function isAsciiLetterCode$1(code) {
|
|
1256
|
+
return isAsciiUppercaseLetterCode$1(code) || isAsciiLowercaseLetterCode(code);
|
|
1257
1257
|
}
|
|
1258
|
-
function isAsciiDigitCode(code) {
|
|
1258
|
+
function isAsciiDigitCode$1(code) {
|
|
1259
1259
|
return code >= 48 && code <= 57;
|
|
1260
1260
|
}
|
|
1261
1261
|
function isAsciiAlphaNumericCode(code) {
|
|
1262
|
-
return isAsciiLetterCode(code) || isAsciiDigitCode(code);
|
|
1262
|
+
return isAsciiLetterCode$1(code) || isAsciiDigitCode$1(code);
|
|
1263
1263
|
}
|
|
1264
1264
|
function staticAttributeValue(value) {
|
|
1265
1265
|
return { kind: "static", value };
|
|
@@ -2306,13 +2306,17 @@ function getNativeWrapperTransformInfo(node, componentName, nativeWrappers) {
|
|
|
2306
2306
|
if (nodeHasClickDirective(node) && role === "button") {
|
|
2307
2307
|
return { nativeWrappersValue: null, optionDataTestIdPrefixValue: null, semanticNameHint: null };
|
|
2308
2308
|
}
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2309
|
+
const inferredValueAttribute = inferred && !valueAttribute ? ["aria-label", "name", "id", "title", "label"].find((attributeName) => {
|
|
2310
|
+
return !!findAttributeByKey(node, attributeName) || !!findDirectiveByName(node, "bind", attributeName);
|
|
2311
|
+
}) : void 0;
|
|
2312
|
+
const resolvedValueAttribute = valueAttribute ?? inferredValueAttribute;
|
|
2313
|
+
if (resolvedValueAttribute) {
|
|
2314
|
+
const value = getDataTestIdValueFromValueAttribute(node, componentName, resolvedValueAttribute, role);
|
|
2315
|
+
const attrStatic = findAttributeByKey(node, resolvedValueAttribute);
|
|
2312
2316
|
if (attrStatic?.value?.content) {
|
|
2313
2317
|
return { nativeWrappersValue: value || null, optionDataTestIdPrefixValue: null, semanticNameHint: attrStatic.value.content };
|
|
2314
2318
|
}
|
|
2315
|
-
const attrDynamic = findDirectiveByName(node, "bind",
|
|
2319
|
+
const attrDynamic = findDirectiveByName(node, "bind", resolvedValueAttribute);
|
|
2316
2320
|
if (attrDynamic && "exp" in attrDynamic && attrDynamic.exp && "ast" in attrDynamic.exp && attrDynamic.exp.ast) {
|
|
2317
2321
|
const { name } = getClickHandlerNameFromAst(attrDynamic.exp.ast);
|
|
2318
2322
|
if (name) {
|
|
@@ -2893,8 +2897,8 @@ function isAllCapsOrDigits(value) {
|
|
|
2893
2897
|
}
|
|
2894
2898
|
for (let i = 0; i < value.length; i++) {
|
|
2895
2899
|
const c = value.charCodeAt(i);
|
|
2896
|
-
const isUpper = isAsciiUppercaseLetterCode(c);
|
|
2897
|
-
const isDigit = isAsciiDigitCode(c);
|
|
2900
|
+
const isUpper = isAsciiUppercaseLetterCode$1(c);
|
|
2901
|
+
const isDigit = isAsciiDigitCode$1(c);
|
|
2898
2902
|
if (!isUpper && !isDigit) {
|
|
2899
2903
|
return false;
|
|
2900
2904
|
}
|
|
@@ -2906,7 +2910,7 @@ function startsWithDigit(value) {
|
|
|
2906
2910
|
return false;
|
|
2907
2911
|
}
|
|
2908
2912
|
const c = value.charCodeAt(0);
|
|
2909
|
-
return isAsciiDigitCode(c);
|
|
2913
|
+
return isAsciiDigitCode$1(c);
|
|
2910
2914
|
}
|
|
2911
2915
|
function stripNonIdentifierChars(value) {
|
|
2912
2916
|
let out = "";
|
|
@@ -3945,10 +3949,10 @@ function debugLog(message) {
|
|
|
3945
3949
|
}
|
|
3946
3950
|
}
|
|
3947
3951
|
function isIdentifierStartCode(code) {
|
|
3948
|
-
return code === 95 || code === 36 || isAsciiLetterCode(code);
|
|
3952
|
+
return code === 95 || code === 36 || isAsciiLetterCode$1(code);
|
|
3949
3953
|
}
|
|
3950
3954
|
function isIdentifierPartCode(code) {
|
|
3951
|
-
return isIdentifierStartCode(code) || isAsciiDigitCode(code);
|
|
3955
|
+
return isIdentifierStartCode(code) || isAsciiDigitCode$1(code);
|
|
3952
3956
|
}
|
|
3953
3957
|
function isValidJsIdentifier(name) {
|
|
3954
3958
|
if (!name.length)
|
|
@@ -7452,10 +7456,17 @@ function getConstructor(childrenComponent, componentHierarchyMap, attachmentsFor
|
|
|
7452
7456
|
});
|
|
7453
7457
|
}
|
|
7454
7458
|
const TESTID_CLICK_EVENT_NAME = "__testid_event__";
|
|
7455
|
-
const CLICK_EVENT_NAME = TESTID_CLICK_EVENT_NAME;
|
|
7456
|
-
const inferredNativeWrapperConfigByLookup = /* @__PURE__ */ new Map();
|
|
7457
|
-
const inferredSfcPathByLookup = /* @__PURE__ */ new Map();
|
|
7458
7459
|
const indexedVueSfcPathsByRoots = /* @__PURE__ */ new Map();
|
|
7460
|
+
const resolvedSfcPathByLookup = /* @__PURE__ */ new Map();
|
|
7461
|
+
function isAsciiUppercaseLetterCode(code) {
|
|
7462
|
+
return code >= 65 && code <= 90;
|
|
7463
|
+
}
|
|
7464
|
+
function isAsciiLetterCode(code) {
|
|
7465
|
+
return code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
7466
|
+
}
|
|
7467
|
+
function isAsciiDigitCode(code) {
|
|
7468
|
+
return code >= 48 && code <= 57;
|
|
7469
|
+
}
|
|
7459
7470
|
function toKebabCaseTag(tag) {
|
|
7460
7471
|
let result = "";
|
|
7461
7472
|
let previousWasSeparator = false;
|
|
@@ -7471,8 +7482,7 @@ function toKebabCaseTag(tag) {
|
|
|
7471
7482
|
}
|
|
7472
7483
|
const previous = i > 0 ? tag[i - 1] : "";
|
|
7473
7484
|
const previousCode = previous ? previous.charCodeAt(0) : 0;
|
|
7474
|
-
const
|
|
7475
|
-
const shouldInsertSeparator = hasPrevious && isAsciiUppercaseLetterCode(code) && (isAsciiLetterCode(previousCode) || isAsciiDigitCode(previousCode)) && !previousWasSeparator;
|
|
7485
|
+
const shouldInsertSeparator = i > 0 && isAsciiUppercaseLetterCode(code) && (isAsciiLetterCode(previousCode) || isAsciiDigitCode(previousCode)) && !previousWasSeparator;
|
|
7476
7486
|
if (shouldInsertSeparator) {
|
|
7477
7487
|
result += "-";
|
|
7478
7488
|
}
|
|
@@ -7481,90 +7491,7 @@ function toKebabCaseTag(tag) {
|
|
|
7481
7491
|
}
|
|
7482
7492
|
return result;
|
|
7483
7493
|
}
|
|
7484
|
-
function
|
|
7485
|
-
const attr = element.props.find((prop) => {
|
|
7486
|
-
return prop.type === compilerCore.NodeTypes.ATTRIBUTE && prop.name === name;
|
|
7487
|
-
});
|
|
7488
|
-
return attr?.value?.content?.trim() || null;
|
|
7489
|
-
}
|
|
7490
|
-
function getNativeHtmlControlRole(element) {
|
|
7491
|
-
const tag = (element.tag || "").toLowerCase();
|
|
7492
|
-
const type = (getStaticAttributeContent(element, "type") || "").toLowerCase();
|
|
7493
|
-
if (tag === "textarea") {
|
|
7494
|
-
return "input";
|
|
7495
|
-
}
|
|
7496
|
-
if (tag === "select") {
|
|
7497
|
-
return "select";
|
|
7498
|
-
}
|
|
7499
|
-
if (tag !== "input") {
|
|
7500
|
-
return null;
|
|
7501
|
-
}
|
|
7502
|
-
if (type === "radio") {
|
|
7503
|
-
return "radio";
|
|
7504
|
-
}
|
|
7505
|
-
if (type === "checkbox") {
|
|
7506
|
-
return "checkbox";
|
|
7507
|
-
}
|
|
7508
|
-
return "input";
|
|
7509
|
-
}
|
|
7510
|
-
function normalizeControlLabelText(value) {
|
|
7511
|
-
const normalized = (value ?? "").replace(/\*/g, " ").replace(/\s+/g, " ").trim();
|
|
7512
|
-
return normalized || null;
|
|
7513
|
-
}
|
|
7514
|
-
function getLabelNodeText(labelNode) {
|
|
7515
|
-
for (const child of labelNode.children || []) {
|
|
7516
|
-
if (child.type === compilerCore.NodeTypes.TEXT) {
|
|
7517
|
-
const normalized2 = normalizeControlLabelText(child.content);
|
|
7518
|
-
if (normalized2) {
|
|
7519
|
-
return normalized2;
|
|
7520
|
-
}
|
|
7521
|
-
continue;
|
|
7522
|
-
}
|
|
7523
|
-
if (child.type !== compilerCore.NodeTypes.ELEMENT) {
|
|
7524
|
-
continue;
|
|
7525
|
-
}
|
|
7526
|
-
if (getNativeHtmlControlRole(child)) {
|
|
7527
|
-
continue;
|
|
7528
|
-
}
|
|
7529
|
-
const normalized = normalizeControlLabelText(getInnerText(child));
|
|
7530
|
-
if (normalized) {
|
|
7531
|
-
return normalized;
|
|
7532
|
-
}
|
|
7533
|
-
}
|
|
7534
|
-
return normalizeControlLabelText(getInnerText(labelNode));
|
|
7535
|
-
}
|
|
7536
|
-
function getAssociatedLabelText(element, hierarchyMap2) {
|
|
7537
|
-
let parent = hierarchyMap2.get(element) || null;
|
|
7538
|
-
while (parent) {
|
|
7539
|
-
if (parent.tag === "label") {
|
|
7540
|
-
return getLabelNodeText(parent);
|
|
7541
|
-
}
|
|
7542
|
-
parent = hierarchyMap2.get(parent) || null;
|
|
7543
|
-
}
|
|
7544
|
-
const id = getStaticAttributeContent(element, "id");
|
|
7545
|
-
if (!id) {
|
|
7546
|
-
return null;
|
|
7547
|
-
}
|
|
7548
|
-
const candidates = /* @__PURE__ */ new Set();
|
|
7549
|
-
for (const child of hierarchyMap2.keys()) {
|
|
7550
|
-
candidates.add(child);
|
|
7551
|
-
}
|
|
7552
|
-
for (const maybeParent of hierarchyMap2.values()) {
|
|
7553
|
-
if (maybeParent) {
|
|
7554
|
-
candidates.add(maybeParent);
|
|
7555
|
-
}
|
|
7556
|
-
}
|
|
7557
|
-
for (const candidate of candidates) {
|
|
7558
|
-
if (candidate.tag !== "label") {
|
|
7559
|
-
continue;
|
|
7560
|
-
}
|
|
7561
|
-
if (getStaticAttributeContent(candidate, "for") === id) {
|
|
7562
|
-
return getLabelNodeText(candidate);
|
|
7563
|
-
}
|
|
7564
|
-
}
|
|
7565
|
-
return null;
|
|
7566
|
-
}
|
|
7567
|
-
function normalizeSearchRoots(wrapperSearchRoots) {
|
|
7494
|
+
function normalizeWrapperSearchRoots(wrapperSearchRoots) {
|
|
7568
7495
|
const normalized = /* @__PURE__ */ new Set();
|
|
7569
7496
|
for (const root of wrapperSearchRoots) {
|
|
7570
7497
|
const resolved = path.resolve(root);
|
|
@@ -7639,14 +7566,14 @@ function buildVueSfcPathIndex(searchRoots) {
|
|
|
7639
7566
|
indexedVueSfcPathsByRoots.set(indexKey, index);
|
|
7640
7567
|
return index;
|
|
7641
7568
|
}
|
|
7642
|
-
function
|
|
7569
|
+
function resolveSfcPathForTag(tag, vueFilesPathMap, wrapperSearchRoots = []) {
|
|
7643
7570
|
const registeredPath = vueFilesPathMap?.get(tag);
|
|
7644
|
-
const normalizedSearchRoots =
|
|
7571
|
+
const normalizedSearchRoots = normalizeWrapperSearchRoots(wrapperSearchRoots);
|
|
7645
7572
|
const lookupKey = `${tag}
|
|
7646
7573
|
${registeredPath ?? ""}
|
|
7647
7574
|
${buildSearchRootsKey(normalizedSearchRoots)}`;
|
|
7648
|
-
if (
|
|
7649
|
-
return
|
|
7575
|
+
if (resolvedSfcPathByLookup.has(lookupKey)) {
|
|
7576
|
+
return resolvedSfcPathByLookup.get(lookupKey) ?? null;
|
|
7650
7577
|
}
|
|
7651
7578
|
const candidateNames = [`${tag}.vue`, `${toKebabCaseTag(tag)}.vue`];
|
|
7652
7579
|
const directCandidates = [
|
|
@@ -7655,11 +7582,11 @@ ${buildSearchRootsKey(normalizedSearchRoots)}`;
|
|
|
7655
7582
|
].filter((value) => !!value);
|
|
7656
7583
|
const directMatch = directCandidates.find((candidatePath) => fs.existsSync(candidatePath));
|
|
7657
7584
|
if (directMatch) {
|
|
7658
|
-
|
|
7585
|
+
resolvedSfcPathByLookup.set(lookupKey, directMatch);
|
|
7659
7586
|
return directMatch;
|
|
7660
7587
|
}
|
|
7661
7588
|
if (normalizedSearchRoots.length === 0) {
|
|
7662
|
-
|
|
7589
|
+
resolvedSfcPathByLookup.set(lookupKey, null);
|
|
7663
7590
|
return null;
|
|
7664
7591
|
}
|
|
7665
7592
|
const index = buildVueSfcPathIndex(normalizedSearchRoots);
|
|
@@ -7686,9 +7613,685 @@ ${buildSearchRootsKey(normalizedSearchRoots)}`;
|
|
|
7686
7613
|
}
|
|
7687
7614
|
}
|
|
7688
7615
|
}
|
|
7689
|
-
|
|
7616
|
+
resolvedSfcPathByLookup.set(lookupKey, bestMatch);
|
|
7690
7617
|
return bestMatch;
|
|
7691
7618
|
}
|
|
7619
|
+
function walkBabel(node, visitor) {
|
|
7620
|
+
visitor(node);
|
|
7621
|
+
const keys = types.VISITOR_KEYS[node.type] ?? [];
|
|
7622
|
+
const record = node;
|
|
7623
|
+
for (const key of keys) {
|
|
7624
|
+
const value = record[key];
|
|
7625
|
+
if (Array.isArray(value)) {
|
|
7626
|
+
for (const child of value) {
|
|
7627
|
+
if (child && typeof child === "object" && "type" in child) {
|
|
7628
|
+
walkBabel(child, visitor);
|
|
7629
|
+
}
|
|
7630
|
+
}
|
|
7631
|
+
continue;
|
|
7632
|
+
}
|
|
7633
|
+
if (value && typeof value === "object" && "type" in value) {
|
|
7634
|
+
walkBabel(value, visitor);
|
|
7635
|
+
}
|
|
7636
|
+
}
|
|
7637
|
+
}
|
|
7638
|
+
function unwrapExpression(expression) {
|
|
7639
|
+
let current = expression;
|
|
7640
|
+
while (types.isTSAsExpression(current) || types.isTSTypeAssertion(current) || types.isTSNonNullExpression(current)) {
|
|
7641
|
+
current = current.expression;
|
|
7642
|
+
}
|
|
7643
|
+
return current;
|
|
7644
|
+
}
|
|
7645
|
+
function getStaticObjectKey(node) {
|
|
7646
|
+
if (types.isIdentifier(node)) {
|
|
7647
|
+
return node.name;
|
|
7648
|
+
}
|
|
7649
|
+
if (types.isStringLiteral(node)) {
|
|
7650
|
+
return node.value;
|
|
7651
|
+
}
|
|
7652
|
+
return null;
|
|
7653
|
+
}
|
|
7654
|
+
function getBooleanObjectProperty(object, propertyName) {
|
|
7655
|
+
for (const property of object.properties) {
|
|
7656
|
+
if (!types.isObjectProperty(property) || property.computed) {
|
|
7657
|
+
continue;
|
|
7658
|
+
}
|
|
7659
|
+
if (getStaticObjectKey(property.key) !== propertyName || !types.isBooleanLiteral(property.value)) {
|
|
7660
|
+
continue;
|
|
7661
|
+
}
|
|
7662
|
+
return property.value.value;
|
|
7663
|
+
}
|
|
7664
|
+
return null;
|
|
7665
|
+
}
|
|
7666
|
+
function getOptionsObject(expression) {
|
|
7667
|
+
if (!expression) {
|
|
7668
|
+
return null;
|
|
7669
|
+
}
|
|
7670
|
+
const unwrapped = unwrapExpression(expression);
|
|
7671
|
+
if (types.isObjectExpression(unwrapped)) {
|
|
7672
|
+
return unwrapped;
|
|
7673
|
+
}
|
|
7674
|
+
if (!types.isCallExpression(unwrapped) || unwrapped.arguments.length === 0) {
|
|
7675
|
+
return null;
|
|
7676
|
+
}
|
|
7677
|
+
const firstArgument = unwrapped.arguments[0];
|
|
7678
|
+
return firstArgument && types.isObjectExpression(firstArgument) ? firstArgument : null;
|
|
7679
|
+
}
|
|
7680
|
+
function parseScriptStatements(source, lang) {
|
|
7681
|
+
if (!source.trim()) {
|
|
7682
|
+
return [];
|
|
7683
|
+
}
|
|
7684
|
+
const plugins = ["decorators-legacy"];
|
|
7685
|
+
if (lang === "ts" || lang === "tsx") {
|
|
7686
|
+
plugins.push("typescript");
|
|
7687
|
+
}
|
|
7688
|
+
if (lang === "jsx" || lang === "tsx") {
|
|
7689
|
+
plugins.push("jsx");
|
|
7690
|
+
}
|
|
7691
|
+
return parser.parse(source, { sourceType: "module", plugins }).program.body;
|
|
7692
|
+
}
|
|
7693
|
+
function getFunctionBody(functionNode) {
|
|
7694
|
+
return functionNode.body;
|
|
7695
|
+
}
|
|
7696
|
+
function findFunctionDeclarations(statements) {
|
|
7697
|
+
const functions = /* @__PURE__ */ new Map();
|
|
7698
|
+
for (const statement of statements) {
|
|
7699
|
+
if (types.isFunctionDeclaration(statement) && statement.id) {
|
|
7700
|
+
functions.set(statement.id.name, statement);
|
|
7701
|
+
continue;
|
|
7702
|
+
}
|
|
7703
|
+
if (!types.isVariableDeclaration(statement)) {
|
|
7704
|
+
continue;
|
|
7705
|
+
}
|
|
7706
|
+
for (const declaration of statement.declarations) {
|
|
7707
|
+
if (!types.isIdentifier(declaration.id) || !declaration.init) {
|
|
7708
|
+
continue;
|
|
7709
|
+
}
|
|
7710
|
+
const init = types.isExpression(declaration.init) ? unwrapExpression(declaration.init) : declaration.init;
|
|
7711
|
+
if (types.isArrowFunctionExpression(init) || types.isFunctionExpression(init)) {
|
|
7712
|
+
functions.set(declaration.id.name, init);
|
|
7713
|
+
}
|
|
7714
|
+
}
|
|
7715
|
+
}
|
|
7716
|
+
return functions;
|
|
7717
|
+
}
|
|
7718
|
+
function expressionForwardsTestId(expression, testIdAttribute, attrsObjectNames, attrsFunctionNames) {
|
|
7719
|
+
const unwrapped = unwrapExpression(expression);
|
|
7720
|
+
if (types.isIdentifier(unwrapped)) {
|
|
7721
|
+
return attrsObjectNames.has(unwrapped.name);
|
|
7722
|
+
}
|
|
7723
|
+
if (types.isCallExpression(unwrapped) && types.isIdentifier(unwrapped.callee)) {
|
|
7724
|
+
return attrsFunctionNames.has(unwrapped.callee.name);
|
|
7725
|
+
}
|
|
7726
|
+
if (types.isObjectExpression(unwrapped)) {
|
|
7727
|
+
let forwards = false;
|
|
7728
|
+
for (const property of unwrapped.properties) {
|
|
7729
|
+
if (property.type === "SpreadElement") {
|
|
7730
|
+
forwards = types.isExpression(property.argument) && expressionForwardsTestId(property.argument, testIdAttribute, attrsObjectNames, attrsFunctionNames);
|
|
7731
|
+
continue;
|
|
7732
|
+
}
|
|
7733
|
+
if (property.computed) {
|
|
7734
|
+
forwards = false;
|
|
7735
|
+
continue;
|
|
7736
|
+
}
|
|
7737
|
+
if (getStaticObjectKey(property.key) === testIdAttribute) {
|
|
7738
|
+
forwards = types.isObjectProperty(property) && types.isExpression(property.value) && expressionReadsTestId(property.value, testIdAttribute, attrsObjectNames, attrsFunctionNames);
|
|
7739
|
+
}
|
|
7740
|
+
}
|
|
7741
|
+
return forwards;
|
|
7742
|
+
}
|
|
7743
|
+
return false;
|
|
7744
|
+
}
|
|
7745
|
+
function expressionReadsTestId(expression, testIdAttribute, attrsObjectNames, attrsFunctionNames) {
|
|
7746
|
+
const unwrapped = unwrapExpression(expression);
|
|
7747
|
+
if (!types.isMemberExpression(unwrapped) || !types.isExpression(unwrapped.object)) {
|
|
7748
|
+
return false;
|
|
7749
|
+
}
|
|
7750
|
+
if (!expressionForwardsTestId(unwrapped.object, testIdAttribute, attrsObjectNames, attrsFunctionNames)) {
|
|
7751
|
+
return false;
|
|
7752
|
+
}
|
|
7753
|
+
if (!unwrapped.computed && types.isIdentifier(unwrapped.property)) {
|
|
7754
|
+
return unwrapped.property.name === testIdAttribute;
|
|
7755
|
+
}
|
|
7756
|
+
return types.isStringLiteral(unwrapped.property) && unwrapped.property.value === testIdAttribute;
|
|
7757
|
+
}
|
|
7758
|
+
function collectExcludedKeys(expression, keyName) {
|
|
7759
|
+
const unwrapped = unwrapExpression(expression);
|
|
7760
|
+
if (types.isLogicalExpression(unwrapped) && unwrapped.operator === "&&") {
|
|
7761
|
+
const left = collectExcludedKeys(unwrapped.left, keyName);
|
|
7762
|
+
const right = collectExcludedKeys(unwrapped.right, keyName);
|
|
7763
|
+
if (!left || !right) {
|
|
7764
|
+
return null;
|
|
7765
|
+
}
|
|
7766
|
+
return /* @__PURE__ */ new Set([...left, ...right]);
|
|
7767
|
+
}
|
|
7768
|
+
if (unwrapped.type !== "BinaryExpression" || unwrapped.operator !== "!==" && unwrapped.operator !== "!=") {
|
|
7769
|
+
return null;
|
|
7770
|
+
}
|
|
7771
|
+
if (types.isIdentifier(unwrapped.left, { name: keyName }) && types.isStringLiteral(unwrapped.right)) {
|
|
7772
|
+
return /* @__PURE__ */ new Set([unwrapped.right.value]);
|
|
7773
|
+
}
|
|
7774
|
+
if (types.isStringLiteral(unwrapped.left) && types.isIdentifier(unwrapped.right, { name: keyName })) {
|
|
7775
|
+
return /* @__PURE__ */ new Set([unwrapped.left.value]);
|
|
7776
|
+
}
|
|
7777
|
+
return null;
|
|
7778
|
+
}
|
|
7779
|
+
function getSingleStatement(statement) {
|
|
7780
|
+
if (types.isBlockStatement(statement)) {
|
|
7781
|
+
return statement.body.length === 1 ? statement.body[0] : null;
|
|
7782
|
+
}
|
|
7783
|
+
return statement;
|
|
7784
|
+
}
|
|
7785
|
+
function tryGetForwardedAccumulator(statement, testIdAttribute, attrsObjectNames, attrsFunctionNames) {
|
|
7786
|
+
if (!types.isForInStatement(statement) || !types.isExpression(statement.right)) {
|
|
7787
|
+
return null;
|
|
7788
|
+
}
|
|
7789
|
+
if (!expressionForwardsTestId(statement.right, testIdAttribute, attrsObjectNames, attrsFunctionNames)) {
|
|
7790
|
+
return null;
|
|
7791
|
+
}
|
|
7792
|
+
let keyName = null;
|
|
7793
|
+
if (types.isVariableDeclaration(statement.left) && statement.left.declarations.length === 1) {
|
|
7794
|
+
const declaration = statement.left.declarations[0];
|
|
7795
|
+
keyName = types.isIdentifier(declaration.id) ? declaration.id.name : null;
|
|
7796
|
+
} else if (types.isIdentifier(statement.left)) {
|
|
7797
|
+
keyName = statement.left.name;
|
|
7798
|
+
}
|
|
7799
|
+
if (!keyName) {
|
|
7800
|
+
return null;
|
|
7801
|
+
}
|
|
7802
|
+
const bodyStatement = getSingleStatement(statement.body);
|
|
7803
|
+
if (!bodyStatement || !types.isIfStatement(bodyStatement) || !types.isExpression(bodyStatement.test)) {
|
|
7804
|
+
return null;
|
|
7805
|
+
}
|
|
7806
|
+
const excludedKeys = collectExcludedKeys(bodyStatement.test, keyName);
|
|
7807
|
+
if (!excludedKeys || excludedKeys.has(testIdAttribute) || bodyStatement.alternate) {
|
|
7808
|
+
return null;
|
|
7809
|
+
}
|
|
7810
|
+
const consequent = getSingleStatement(bodyStatement.consequent);
|
|
7811
|
+
if (!consequent || !types.isExpressionStatement(consequent) || !types.isAssignmentExpression(consequent.expression, { operator: "=" })) {
|
|
7812
|
+
return null;
|
|
7813
|
+
}
|
|
7814
|
+
const { left, right } = consequent.expression;
|
|
7815
|
+
if (!types.isMemberExpression(left) || !left.computed || !types.isIdentifier(left.object) || !types.isIdentifier(left.property, { name: keyName })) {
|
|
7816
|
+
return null;
|
|
7817
|
+
}
|
|
7818
|
+
if (!types.isMemberExpression(right) || !right.computed || !types.isIdentifier(right.property, { name: keyName }) || !types.isExpression(right.object)) {
|
|
7819
|
+
return null;
|
|
7820
|
+
}
|
|
7821
|
+
if (!expressionForwardsTestId(right.object, testIdAttribute, attrsObjectNames, attrsFunctionNames)) {
|
|
7822
|
+
return null;
|
|
7823
|
+
}
|
|
7824
|
+
return left.object.name;
|
|
7825
|
+
}
|
|
7826
|
+
function functionForwardsTestId(functionNode, testIdAttribute, globalAttrsObjectNames, attrsFunctionNames) {
|
|
7827
|
+
const body = getFunctionBody(functionNode);
|
|
7828
|
+
if (types.isExpression(body)) {
|
|
7829
|
+
return expressionForwardsTestId(body, testIdAttribute, globalAttrsObjectNames, attrsFunctionNames);
|
|
7830
|
+
}
|
|
7831
|
+
const localAttrsObjectNames = new Set(globalAttrsObjectNames);
|
|
7832
|
+
for (const statement of body.body) {
|
|
7833
|
+
if (types.isVariableDeclaration(statement)) {
|
|
7834
|
+
for (const declaration of statement.declarations) {
|
|
7835
|
+
if (types.isIdentifier(declaration.id) && declaration.init && types.isExpression(declaration.init)) {
|
|
7836
|
+
if (expressionForwardsTestId(declaration.init, testIdAttribute, localAttrsObjectNames, attrsFunctionNames)) {
|
|
7837
|
+
localAttrsObjectNames.add(declaration.id.name);
|
|
7838
|
+
}
|
|
7839
|
+
continue;
|
|
7840
|
+
}
|
|
7841
|
+
if (!types.isObjectPattern(declaration.id) || !declaration.init || !types.isExpression(declaration.init)) {
|
|
7842
|
+
continue;
|
|
7843
|
+
}
|
|
7844
|
+
if (!expressionForwardsTestId(declaration.init, testIdAttribute, localAttrsObjectNames, attrsFunctionNames)) {
|
|
7845
|
+
continue;
|
|
7846
|
+
}
|
|
7847
|
+
const excludedKeys = /* @__PURE__ */ new Set();
|
|
7848
|
+
let restName = null;
|
|
7849
|
+
for (const property of declaration.id.properties) {
|
|
7850
|
+
if (types.isRestElement(property) && types.isIdentifier(property.argument)) {
|
|
7851
|
+
restName = property.argument.name;
|
|
7852
|
+
continue;
|
|
7853
|
+
}
|
|
7854
|
+
if (types.isObjectProperty(property)) {
|
|
7855
|
+
const key = getStaticObjectKey(property.key);
|
|
7856
|
+
if (key) {
|
|
7857
|
+
excludedKeys.add(key);
|
|
7858
|
+
}
|
|
7859
|
+
}
|
|
7860
|
+
}
|
|
7861
|
+
if (restName && !excludedKeys.has(testIdAttribute)) {
|
|
7862
|
+
localAttrsObjectNames.add(restName);
|
|
7863
|
+
}
|
|
7864
|
+
}
|
|
7865
|
+
continue;
|
|
7866
|
+
}
|
|
7867
|
+
const accumulatorName = tryGetForwardedAccumulator(
|
|
7868
|
+
statement,
|
|
7869
|
+
testIdAttribute,
|
|
7870
|
+
localAttrsObjectNames,
|
|
7871
|
+
attrsFunctionNames
|
|
7872
|
+
);
|
|
7873
|
+
if (accumulatorName) {
|
|
7874
|
+
localAttrsObjectNames.add(accumulatorName);
|
|
7875
|
+
continue;
|
|
7876
|
+
}
|
|
7877
|
+
if (types.isReturnStatement(statement) && statement.argument && types.isExpression(statement.argument)) {
|
|
7878
|
+
if (expressionForwardsTestId(statement.argument, testIdAttribute, localAttrsObjectNames, attrsFunctionNames)) {
|
|
7879
|
+
return true;
|
|
7880
|
+
}
|
|
7881
|
+
}
|
|
7882
|
+
}
|
|
7883
|
+
return body.body.some((statement) => {
|
|
7884
|
+
return types.isReturnStatement(statement) && !!statement.argument && types.isExpression(statement.argument) && expressionForwardsTestId(statement.argument, testIdAttribute, localAttrsObjectNames, attrsFunctionNames);
|
|
7885
|
+
});
|
|
7886
|
+
}
|
|
7887
|
+
function analyzeScriptForwardingMetadata(scriptBlocks, testIdAttribute) {
|
|
7888
|
+
const statements = scriptBlocks.flatMap((block) => parseScriptStatements(block.content, block.lang));
|
|
7889
|
+
const useAttrsCalleeNames = /* @__PURE__ */ new Set(["useAttrs"]);
|
|
7890
|
+
let inheritAttrs = true;
|
|
7891
|
+
for (const statement of statements) {
|
|
7892
|
+
if (types.isImportDeclaration(statement) && statement.source.value === "vue") {
|
|
7893
|
+
for (const specifier of statement.specifiers) {
|
|
7894
|
+
if (types.isImportSpecifier(specifier) && types.isIdentifier(specifier.imported, { name: "useAttrs" })) {
|
|
7895
|
+
useAttrsCalleeNames.add(specifier.local.name);
|
|
7896
|
+
}
|
|
7897
|
+
}
|
|
7898
|
+
}
|
|
7899
|
+
if (types.isExportDefaultDeclaration(statement)) {
|
|
7900
|
+
const declaration = statement.declaration;
|
|
7901
|
+
const options = types.isExpression(declaration) ? getOptionsObject(declaration) : null;
|
|
7902
|
+
const configured = options ? getBooleanObjectProperty(options, "inheritAttrs") : null;
|
|
7903
|
+
if (configured !== null) {
|
|
7904
|
+
inheritAttrs = configured;
|
|
7905
|
+
}
|
|
7906
|
+
}
|
|
7907
|
+
}
|
|
7908
|
+
for (const statement of statements) {
|
|
7909
|
+
walkBabel(statement, (node) => {
|
|
7910
|
+
if (!types.isCallExpression(node) || !types.isIdentifier(node.callee, { name: "defineOptions" })) {
|
|
7911
|
+
return;
|
|
7912
|
+
}
|
|
7913
|
+
const options = node.arguments[0];
|
|
7914
|
+
if (!options || !types.isObjectExpression(options)) {
|
|
7915
|
+
return;
|
|
7916
|
+
}
|
|
7917
|
+
const configured = getBooleanObjectProperty(options, "inheritAttrs");
|
|
7918
|
+
if (configured !== null) {
|
|
7919
|
+
inheritAttrs = configured;
|
|
7920
|
+
}
|
|
7921
|
+
});
|
|
7922
|
+
}
|
|
7923
|
+
const attrsObjectNames = /* @__PURE__ */ new Set(["$attrs"]);
|
|
7924
|
+
for (const statement of statements) {
|
|
7925
|
+
walkBabel(statement, (node) => {
|
|
7926
|
+
if (node.type !== "VariableDeclarator") {
|
|
7927
|
+
return;
|
|
7928
|
+
}
|
|
7929
|
+
const declaration = node;
|
|
7930
|
+
if (!declaration.init || !types.isCallExpression(declaration.init)) {
|
|
7931
|
+
return;
|
|
7932
|
+
}
|
|
7933
|
+
if (!types.isIdentifier(declaration.init.callee) || !useAttrsCalleeNames.has(declaration.init.callee.name)) {
|
|
7934
|
+
return;
|
|
7935
|
+
}
|
|
7936
|
+
if (types.isIdentifier(declaration.id)) {
|
|
7937
|
+
attrsObjectNames.add(declaration.id.name);
|
|
7938
|
+
return;
|
|
7939
|
+
}
|
|
7940
|
+
if (!types.isObjectPattern(declaration.id)) {
|
|
7941
|
+
return;
|
|
7942
|
+
}
|
|
7943
|
+
const excludedKeys = /* @__PURE__ */ new Set();
|
|
7944
|
+
let restName = null;
|
|
7945
|
+
for (const property of declaration.id.properties) {
|
|
7946
|
+
if (types.isRestElement(property) && types.isIdentifier(property.argument)) {
|
|
7947
|
+
restName = property.argument.name;
|
|
7948
|
+
continue;
|
|
7949
|
+
}
|
|
7950
|
+
if (types.isObjectProperty(property)) {
|
|
7951
|
+
const key = getStaticObjectKey(property.key);
|
|
7952
|
+
if (key) {
|
|
7953
|
+
excludedKeys.add(key);
|
|
7954
|
+
}
|
|
7955
|
+
}
|
|
7956
|
+
}
|
|
7957
|
+
if (restName && !excludedKeys.has(testIdAttribute)) {
|
|
7958
|
+
attrsObjectNames.add(restName);
|
|
7959
|
+
}
|
|
7960
|
+
});
|
|
7961
|
+
}
|
|
7962
|
+
let aliasesChanged = true;
|
|
7963
|
+
while (aliasesChanged) {
|
|
7964
|
+
aliasesChanged = false;
|
|
7965
|
+
for (const statement of statements) {
|
|
7966
|
+
if (!types.isVariableDeclaration(statement)) {
|
|
7967
|
+
continue;
|
|
7968
|
+
}
|
|
7969
|
+
for (const declaration of statement.declarations) {
|
|
7970
|
+
if (!types.isIdentifier(declaration.id) || attrsObjectNames.has(declaration.id.name) || !declaration.init || !types.isExpression(declaration.init)) {
|
|
7971
|
+
continue;
|
|
7972
|
+
}
|
|
7973
|
+
if (expressionForwardsTestId(declaration.init, testIdAttribute, attrsObjectNames, /* @__PURE__ */ new Set())) {
|
|
7974
|
+
attrsObjectNames.add(declaration.id.name);
|
|
7975
|
+
aliasesChanged = true;
|
|
7976
|
+
}
|
|
7977
|
+
}
|
|
7978
|
+
}
|
|
7979
|
+
}
|
|
7980
|
+
const functions = findFunctionDeclarations(statements);
|
|
7981
|
+
const attrsFunctionNames = /* @__PURE__ */ new Set();
|
|
7982
|
+
let changed = true;
|
|
7983
|
+
while (changed) {
|
|
7984
|
+
changed = false;
|
|
7985
|
+
for (const [name, functionNode] of functions) {
|
|
7986
|
+
if (attrsFunctionNames.has(name)) {
|
|
7987
|
+
continue;
|
|
7988
|
+
}
|
|
7989
|
+
if (functionForwardsTestId(functionNode, testIdAttribute, attrsObjectNames, attrsFunctionNames)) {
|
|
7990
|
+
attrsFunctionNames.add(name);
|
|
7991
|
+
changed = true;
|
|
7992
|
+
}
|
|
7993
|
+
}
|
|
7994
|
+
}
|
|
7995
|
+
return { inheritAttrs, attrsObjectNames, attrsFunctionNames };
|
|
7996
|
+
}
|
|
7997
|
+
function getStaticAttributeContent$1(element, name) {
|
|
7998
|
+
const attribute = element.props.find((prop) => {
|
|
7999
|
+
return prop.type === compilerCore.NodeTypes.ATTRIBUTE && prop.name === name;
|
|
8000
|
+
});
|
|
8001
|
+
return attribute?.value?.content?.trim() || null;
|
|
8002
|
+
}
|
|
8003
|
+
function mapExplicitAriaRole(role) {
|
|
8004
|
+
switch (role.toLowerCase()) {
|
|
8005
|
+
case "button":
|
|
8006
|
+
case "checkbox":
|
|
8007
|
+
case "grid":
|
|
8008
|
+
case "link":
|
|
8009
|
+
case "radio":
|
|
8010
|
+
case "tab":
|
|
8011
|
+
return role.toLowerCase();
|
|
8012
|
+
case "radiogroup":
|
|
8013
|
+
return "radio";
|
|
8014
|
+
case "combobox":
|
|
8015
|
+
case "listbox":
|
|
8016
|
+
return "select";
|
|
8017
|
+
case "searchbox":
|
|
8018
|
+
case "spinbutton":
|
|
8019
|
+
case "textbox":
|
|
8020
|
+
return "input";
|
|
8021
|
+
case "switch":
|
|
8022
|
+
return "toggle";
|
|
8023
|
+
default:
|
|
8024
|
+
return null;
|
|
8025
|
+
}
|
|
8026
|
+
}
|
|
8027
|
+
function hasAttribute(element, name) {
|
|
8028
|
+
return element.props.some((prop) => {
|
|
8029
|
+
if (prop.type === compilerCore.NodeTypes.ATTRIBUTE) {
|
|
8030
|
+
return prop.name === name;
|
|
8031
|
+
}
|
|
8032
|
+
return prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === name;
|
|
8033
|
+
});
|
|
8034
|
+
}
|
|
8035
|
+
function getElementControlRole(element) {
|
|
8036
|
+
const explicitRole = getStaticAttributeContent$1(element, "role");
|
|
8037
|
+
if (explicitRole) {
|
|
8038
|
+
return mapExplicitAriaRole(explicitRole);
|
|
8039
|
+
}
|
|
8040
|
+
const tag = element.tag.toLowerCase();
|
|
8041
|
+
const type = (getStaticAttributeContent$1(element, "type") || "").toLowerCase();
|
|
8042
|
+
if (tag === "input" || tag === "uinput") {
|
|
8043
|
+
if (type === "radio") {
|
|
8044
|
+
return "radio";
|
|
8045
|
+
}
|
|
8046
|
+
if (type === "checkbox") {
|
|
8047
|
+
return "checkbox";
|
|
8048
|
+
}
|
|
8049
|
+
return "input";
|
|
8050
|
+
}
|
|
8051
|
+
if (tag === "textarea" || tag === "utextarea") {
|
|
8052
|
+
return "input";
|
|
8053
|
+
}
|
|
8054
|
+
if (tag === "select" || tag === "uselect") {
|
|
8055
|
+
return "select";
|
|
8056
|
+
}
|
|
8057
|
+
if (tag === "vselect") {
|
|
8058
|
+
return "vselect";
|
|
8059
|
+
}
|
|
8060
|
+
if (tag === "button" || tag === "ubutton") {
|
|
8061
|
+
return "button";
|
|
8062
|
+
}
|
|
8063
|
+
if (tag === "router-link" || tag === "routerlink") {
|
|
8064
|
+
return "link";
|
|
8065
|
+
}
|
|
8066
|
+
if ((tag === "a" || tag === "ua") && hasAttribute(element, "href")) {
|
|
8067
|
+
return "link";
|
|
8068
|
+
}
|
|
8069
|
+
return null;
|
|
8070
|
+
}
|
|
8071
|
+
function isComponentLikeTag(tag) {
|
|
8072
|
+
if (!tag) {
|
|
8073
|
+
return false;
|
|
8074
|
+
}
|
|
8075
|
+
return isAsciiUppercaseLetterCode(tag.charCodeAt(0)) || tag.includes("-");
|
|
8076
|
+
}
|
|
8077
|
+
function parseTemplateExpression(source) {
|
|
8078
|
+
try {
|
|
8079
|
+
return parser.parseExpression(source, { plugins: ["typescript"] });
|
|
8080
|
+
} catch {
|
|
8081
|
+
return null;
|
|
8082
|
+
}
|
|
8083
|
+
}
|
|
8084
|
+
function directiveExpressionSource(directive) {
|
|
8085
|
+
if (!directive.exp) {
|
|
8086
|
+
return "";
|
|
8087
|
+
}
|
|
8088
|
+
return directive.exp.loc?.source || (directive.exp.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION ? directive.exp.content : "");
|
|
8089
|
+
}
|
|
8090
|
+
function elementExplicitlyForwardsTestId(element, testIdAttribute, scriptMetadata) {
|
|
8091
|
+
for (const prop of element.props) {
|
|
8092
|
+
if (prop.type !== compilerCore.NodeTypes.DIRECTIVE || prop.name !== "bind" || !prop.exp) {
|
|
8093
|
+
continue;
|
|
8094
|
+
}
|
|
8095
|
+
const source = directiveExpressionSource(prop);
|
|
8096
|
+
const expression = parseTemplateExpression(source);
|
|
8097
|
+
if (!expression) {
|
|
8098
|
+
continue;
|
|
8099
|
+
}
|
|
8100
|
+
if (!prop.arg) {
|
|
8101
|
+
if (expressionForwardsTestId(expression, testIdAttribute, scriptMetadata.attrsObjectNames, scriptMetadata.attrsFunctionNames)) {
|
|
8102
|
+
return true;
|
|
8103
|
+
}
|
|
8104
|
+
continue;
|
|
8105
|
+
}
|
|
8106
|
+
if (prop.arg.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic && prop.arg.content === testIdAttribute && expressionReadsTestId(expression, testIdAttribute, scriptMetadata.attrsObjectNames, scriptMetadata.attrsFunctionNames)) {
|
|
8107
|
+
return true;
|
|
8108
|
+
}
|
|
8109
|
+
}
|
|
8110
|
+
return false;
|
|
8111
|
+
}
|
|
8112
|
+
function walkTemplate(node, visitor) {
|
|
8113
|
+
if (node.type === compilerCore.NodeTypes.ELEMENT) {
|
|
8114
|
+
visitor(node);
|
|
8115
|
+
for (const child of node.children) {
|
|
8116
|
+
walkTemplate(child, visitor);
|
|
8117
|
+
}
|
|
8118
|
+
return;
|
|
8119
|
+
}
|
|
8120
|
+
if (node.type === compilerCore.NodeTypes.ROOT) {
|
|
8121
|
+
for (const child of node.children) {
|
|
8122
|
+
walkTemplate(child, visitor);
|
|
8123
|
+
}
|
|
8124
|
+
}
|
|
8125
|
+
}
|
|
8126
|
+
function getRenderedRootElements(ast) {
|
|
8127
|
+
const rendered = ast.children.filter((child) => {
|
|
8128
|
+
return child.type !== compilerCore.NodeTypes.COMMENT && !(child.type === compilerCore.NodeTypes.TEXT && child.content.trim() === "");
|
|
8129
|
+
});
|
|
8130
|
+
if (rendered.length !== 1 || rendered[0]?.type !== compilerCore.NodeTypes.ELEMENT || rendered[0].tag === "template") {
|
|
8131
|
+
return [];
|
|
8132
|
+
}
|
|
8133
|
+
return [rendered[0]];
|
|
8134
|
+
}
|
|
8135
|
+
function analyzeWrapperContractFromSfc(options) {
|
|
8136
|
+
const { descriptor } = compilerSfc.parse(options.source, { filename: options.filePath });
|
|
8137
|
+
const template = descriptor.template?.content ?? "";
|
|
8138
|
+
if (!template.trim()) {
|
|
8139
|
+
return {
|
|
8140
|
+
role: null,
|
|
8141
|
+
targetRoles: [],
|
|
8142
|
+
forwardedTestIdTargetOffsets: /* @__PURE__ */ new Set(),
|
|
8143
|
+
forwardedTestIdTargetSfcOffsets: /* @__PURE__ */ new Set(),
|
|
8144
|
+
explicitlyForwardedTestIdTargetOffsets: /* @__PURE__ */ new Set(),
|
|
8145
|
+
explicitlyForwardedTestIdTargetSfcOffsets: /* @__PURE__ */ new Set()
|
|
8146
|
+
};
|
|
8147
|
+
}
|
|
8148
|
+
const scriptMetadata = analyzeScriptForwardingMetadata(
|
|
8149
|
+
[descriptor.script, descriptor.scriptSetup].filter((block) => !!block).map((block) => ({ content: block.content, lang: block.lang })),
|
|
8150
|
+
options.testIdAttribute
|
|
8151
|
+
);
|
|
8152
|
+
const ast = compilerDom.parse(template, { comments: false });
|
|
8153
|
+
const targets = /* @__PURE__ */ new Map();
|
|
8154
|
+
const explicitTargetOffsets = /* @__PURE__ */ new Set();
|
|
8155
|
+
if (scriptMetadata.inheritAttrs) {
|
|
8156
|
+
for (const element of getRenderedRootElements(ast)) {
|
|
8157
|
+
targets.set(element.loc.start.offset, element);
|
|
8158
|
+
}
|
|
8159
|
+
}
|
|
8160
|
+
walkTemplate(ast, (element) => {
|
|
8161
|
+
if (elementExplicitlyForwardsTestId(element, options.testIdAttribute, scriptMetadata)) {
|
|
8162
|
+
targets.set(element.loc.start.offset, element);
|
|
8163
|
+
explicitTargetOffsets.add(element.loc.start.offset);
|
|
8164
|
+
}
|
|
8165
|
+
});
|
|
8166
|
+
const targetRoles = [...targets.values()].map((element) => {
|
|
8167
|
+
const directRole = getElementControlRole(element);
|
|
8168
|
+
if (directRole) {
|
|
8169
|
+
return directRole;
|
|
8170
|
+
}
|
|
8171
|
+
if (isComponentLikeTag(element.tag)) {
|
|
8172
|
+
return options.resolveNestedContract(element.tag)?.role ?? null;
|
|
8173
|
+
}
|
|
8174
|
+
return null;
|
|
8175
|
+
});
|
|
8176
|
+
const uniqueRoles = new Set(targetRoles);
|
|
8177
|
+
const role = uniqueRoles.size === 1 && !uniqueRoles.has(null) ? targetRoles[0] ?? null : null;
|
|
8178
|
+
const templateContentStartOffset = descriptor.template?.loc.start.offset ?? 0;
|
|
8179
|
+
const toSfcOffsets = (offsets) => new Set(
|
|
8180
|
+
[...offsets].map((offset) => offset + templateContentStartOffset)
|
|
8181
|
+
);
|
|
8182
|
+
return {
|
|
8183
|
+
role,
|
|
8184
|
+
targetRoles,
|
|
8185
|
+
forwardedTestIdTargetOffsets: new Set(targets.keys()),
|
|
8186
|
+
forwardedTestIdTargetSfcOffsets: toSfcOffsets(targets.keys()),
|
|
8187
|
+
explicitlyForwardedTestIdTargetOffsets: explicitTargetOffsets,
|
|
8188
|
+
explicitlyForwardedTestIdTargetSfcOffsets: toSfcOffsets(explicitTargetOffsets)
|
|
8189
|
+
};
|
|
8190
|
+
}
|
|
8191
|
+
function resolveWrapperContractForTag(options) {
|
|
8192
|
+
const normalizedSearchRoots = normalizeWrapperSearchRoots(options.wrapperSearchRoots ?? []);
|
|
8193
|
+
const memo = /* @__PURE__ */ new Map();
|
|
8194
|
+
const resolving = /* @__PURE__ */ new Set();
|
|
8195
|
+
const resolveTag = (tag) => {
|
|
8196
|
+
const first = tag.charCodeAt(0);
|
|
8197
|
+
if (!isAsciiUppercaseLetterCode(first) && !tag.includes("-")) {
|
|
8198
|
+
return null;
|
|
8199
|
+
}
|
|
8200
|
+
const filePath = resolveSfcPathForTag(tag, options.vueFilesPathMap, normalizedSearchRoots);
|
|
8201
|
+
if (!filePath) {
|
|
8202
|
+
return null;
|
|
8203
|
+
}
|
|
8204
|
+
const normalizedPath = path.normalize(filePath);
|
|
8205
|
+
if (memo.has(normalizedPath)) {
|
|
8206
|
+
return memo.get(normalizedPath) ?? null;
|
|
8207
|
+
}
|
|
8208
|
+
if (resolving.has(normalizedPath)) {
|
|
8209
|
+
return null;
|
|
8210
|
+
}
|
|
8211
|
+
const source = fs.readFileSync(normalizedPath, "utf8");
|
|
8212
|
+
resolving.add(normalizedPath);
|
|
8213
|
+
try {
|
|
8214
|
+
const contract = analyzeWrapperContractFromSfc({
|
|
8215
|
+
filePath: normalizedPath,
|
|
8216
|
+
source,
|
|
8217
|
+
testIdAttribute: options.testIdAttribute,
|
|
8218
|
+
resolveNestedContract: resolveTag
|
|
8219
|
+
});
|
|
8220
|
+
memo.set(normalizedPath, contract);
|
|
8221
|
+
return contract;
|
|
8222
|
+
} finally {
|
|
8223
|
+
resolving.delete(normalizedPath);
|
|
8224
|
+
}
|
|
8225
|
+
};
|
|
8226
|
+
return resolveTag(options.tag);
|
|
8227
|
+
}
|
|
8228
|
+
const CLICK_EVENT_NAME = TESTID_CLICK_EVENT_NAME;
|
|
8229
|
+
function getStaticAttributeContent(element, name) {
|
|
8230
|
+
const attr = element.props.find((prop) => {
|
|
8231
|
+
return prop.type === compilerCore.NodeTypes.ATTRIBUTE && prop.name === name;
|
|
8232
|
+
});
|
|
8233
|
+
return attr?.value?.content?.trim() || null;
|
|
8234
|
+
}
|
|
8235
|
+
function getNativeHtmlControlRole(element) {
|
|
8236
|
+
return getElementControlRole(element);
|
|
8237
|
+
}
|
|
8238
|
+
function normalizeControlLabelText(value) {
|
|
8239
|
+
const normalized = (value ?? "").replace(/\*/g, " ").replace(/\s+/g, " ").trim();
|
|
8240
|
+
return normalized || null;
|
|
8241
|
+
}
|
|
8242
|
+
function getLabelNodeText(labelNode) {
|
|
8243
|
+
for (const child of labelNode.children || []) {
|
|
8244
|
+
if (child.type === compilerCore.NodeTypes.TEXT) {
|
|
8245
|
+
const normalized2 = normalizeControlLabelText(child.content);
|
|
8246
|
+
if (normalized2) {
|
|
8247
|
+
return normalized2;
|
|
8248
|
+
}
|
|
8249
|
+
continue;
|
|
8250
|
+
}
|
|
8251
|
+
if (child.type !== compilerCore.NodeTypes.ELEMENT) {
|
|
8252
|
+
continue;
|
|
8253
|
+
}
|
|
8254
|
+
if (getNativeHtmlControlRole(child)) {
|
|
8255
|
+
continue;
|
|
8256
|
+
}
|
|
8257
|
+
const normalized = normalizeControlLabelText(getInnerText(child));
|
|
8258
|
+
if (normalized) {
|
|
8259
|
+
return normalized;
|
|
8260
|
+
}
|
|
8261
|
+
}
|
|
8262
|
+
return normalizeControlLabelText(getInnerText(labelNode));
|
|
8263
|
+
}
|
|
8264
|
+
function getAssociatedLabelText(element, hierarchyMap2) {
|
|
8265
|
+
let parent = hierarchyMap2.get(element) || null;
|
|
8266
|
+
while (parent) {
|
|
8267
|
+
if (parent.tag === "label") {
|
|
8268
|
+
return getLabelNodeText(parent);
|
|
8269
|
+
}
|
|
8270
|
+
parent = hierarchyMap2.get(parent) || null;
|
|
8271
|
+
}
|
|
8272
|
+
const id = getStaticAttributeContent(element, "id");
|
|
8273
|
+
if (!id) {
|
|
8274
|
+
return null;
|
|
8275
|
+
}
|
|
8276
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
8277
|
+
for (const child of hierarchyMap2.keys()) {
|
|
8278
|
+
candidates.add(child);
|
|
8279
|
+
}
|
|
8280
|
+
for (const maybeParent of hierarchyMap2.values()) {
|
|
8281
|
+
if (maybeParent) {
|
|
8282
|
+
candidates.add(maybeParent);
|
|
8283
|
+
}
|
|
8284
|
+
}
|
|
8285
|
+
for (const candidate of candidates) {
|
|
8286
|
+
if (candidate.tag !== "label") {
|
|
8287
|
+
continue;
|
|
8288
|
+
}
|
|
8289
|
+
if (getStaticAttributeContent(candidate, "for") === id) {
|
|
8290
|
+
return getLabelNodeText(candidate);
|
|
8291
|
+
}
|
|
8292
|
+
}
|
|
8293
|
+
return null;
|
|
8294
|
+
}
|
|
7692
8295
|
function trimLeadingSeparators(value) {
|
|
7693
8296
|
if (!value) {
|
|
7694
8297
|
return "";
|
|
@@ -7741,11 +8344,11 @@ function tryExtractStableHintFromConditionalExpressionSource(source) {
|
|
|
7741
8344
|
return false;
|
|
7742
8345
|
const isUnderscore = (ch) => ch === 95;
|
|
7743
8346
|
const first = v.charCodeAt(0);
|
|
7744
|
-
if (!isAsciiLetterCode(first))
|
|
8347
|
+
if (!isAsciiLetterCode$1(first))
|
|
7745
8348
|
return false;
|
|
7746
8349
|
for (let i = 1; i < v.length; i += 1) {
|
|
7747
8350
|
const ch = v.charCodeAt(i);
|
|
7748
|
-
if (isAsciiLetterCode(ch) || isAsciiDigitCode(ch) || isUnderscore(ch)) {
|
|
8351
|
+
if (isAsciiLetterCode$1(ch) || isAsciiDigitCode$1(ch) || isUnderscore(ch)) {
|
|
7749
8352
|
continue;
|
|
7750
8353
|
}
|
|
7751
8354
|
return false;
|
|
@@ -7802,150 +8405,6 @@ function tryExtractStableHintFromConditionalExpressionSource(source) {
|
|
|
7802
8405
|
return null;
|
|
7803
8406
|
}
|
|
7804
8407
|
}
|
|
7805
|
-
function tryInferNativeWrapperRoleFromSfc(tag, vueFilesPathMap, wrapperSearchRoots = [], seenTags = /* @__PURE__ */ new Set()) {
|
|
7806
|
-
const first = tag.charCodeAt(0);
|
|
7807
|
-
const isUpper = isAsciiUppercaseLetterCode(first);
|
|
7808
|
-
if (!isUpper)
|
|
7809
|
-
return null;
|
|
7810
|
-
if (seenTags.has(tag)) {
|
|
7811
|
-
return null;
|
|
7812
|
-
}
|
|
7813
|
-
const normalizedSearchRoots = normalizeSearchRoots(wrapperSearchRoots);
|
|
7814
|
-
const cacheKey = `${tag}
|
|
7815
|
-
${vueFilesPathMap?.get(tag) ?? ""}
|
|
7816
|
-
${buildSearchRootsKey(normalizedSearchRoots)}`;
|
|
7817
|
-
const cached = inferredNativeWrapperConfigByLookup.get(cacheKey);
|
|
7818
|
-
if (cached)
|
|
7819
|
-
return cached.role ? cached : null;
|
|
7820
|
-
const filePath = tryResolveSfcPathForTag(tag, vueFilesPathMap, normalizedSearchRoots);
|
|
7821
|
-
if (!filePath) {
|
|
7822
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7823
|
-
return null;
|
|
7824
|
-
}
|
|
7825
|
-
let source = "";
|
|
7826
|
-
try {
|
|
7827
|
-
source = fs.readFileSync(filePath, "utf8");
|
|
7828
|
-
} catch {
|
|
7829
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7830
|
-
return null;
|
|
7831
|
-
}
|
|
7832
|
-
let template = "";
|
|
7833
|
-
try {
|
|
7834
|
-
const { descriptor } = compilerSfc.parse(source, { filename: filePath });
|
|
7835
|
-
template = descriptor.template?.content ?? "";
|
|
7836
|
-
} catch {
|
|
7837
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7838
|
-
return null;
|
|
7839
|
-
}
|
|
7840
|
-
if (!template.trim()) {
|
|
7841
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7842
|
-
return null;
|
|
7843
|
-
}
|
|
7844
|
-
try {
|
|
7845
|
-
const ast = compilerDom.parse(template, { comments: false });
|
|
7846
|
-
const renderedRoots = ast.children.filter((child) => {
|
|
7847
|
-
return child.type !== compilerCore.NodeTypes.COMMENT && !(child.type === compilerCore.NodeTypes.TEXT && child.content.trim() === "");
|
|
7848
|
-
});
|
|
7849
|
-
if (renderedRoots.length !== 1) {
|
|
7850
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7851
|
-
return null;
|
|
7852
|
-
}
|
|
7853
|
-
const nextSeen = new Set(seenTags);
|
|
7854
|
-
nextSeen.add(tag);
|
|
7855
|
-
const isComponentLikeTag = (value) => {
|
|
7856
|
-
if (!value)
|
|
7857
|
-
return false;
|
|
7858
|
-
const code = value.charCodeAt(0);
|
|
7859
|
-
return isAsciiUppercaseLetterCode(code) || value.includes("-");
|
|
7860
|
-
};
|
|
7861
|
-
const getStaticTypeAttribute = (element) => {
|
|
7862
|
-
const typeAttr = element.props.find((prop) => {
|
|
7863
|
-
return prop.type === compilerCore.NodeTypes.ATTRIBUTE && prop.name === "type";
|
|
7864
|
-
});
|
|
7865
|
-
return (typeAttr?.value?.content ?? "").toLowerCase();
|
|
7866
|
-
};
|
|
7867
|
-
const hasHrefAttribute = (element) => {
|
|
7868
|
-
return element.props.some((prop) => {
|
|
7869
|
-
if (prop.type === compilerCore.NodeTypes.ATTRIBUTE) {
|
|
7870
|
-
return prop.name === "href";
|
|
7871
|
-
}
|
|
7872
|
-
if (prop.type === compilerCore.NodeTypes.DIRECTIVE) {
|
|
7873
|
-
const directive = prop;
|
|
7874
|
-
return directive.name === "bind" && directive.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && directive.arg.content === "href";
|
|
7875
|
-
}
|
|
7876
|
-
return false;
|
|
7877
|
-
});
|
|
7878
|
-
};
|
|
7879
|
-
let inferRoleFromNode;
|
|
7880
|
-
const inferRoleFromElement = (element) => {
|
|
7881
|
-
const elementTag = (element.tag || "").toLowerCase();
|
|
7882
|
-
const inputType = getStaticTypeAttribute(element);
|
|
7883
|
-
if (elementTag === "input" || elementTag === "uinput") {
|
|
7884
|
-
if (inputType === "radio")
|
|
7885
|
-
return { role: "radio" };
|
|
7886
|
-
if (inputType === "checkbox")
|
|
7887
|
-
return { role: "checkbox" };
|
|
7888
|
-
return { role: "input" };
|
|
7889
|
-
}
|
|
7890
|
-
if (elementTag === "textarea" || elementTag === "utextarea")
|
|
7891
|
-
return { role: "input" };
|
|
7892
|
-
if (elementTag === "select" || elementTag === "uselect")
|
|
7893
|
-
return { role: "select" };
|
|
7894
|
-
if (elementTag === "vselect")
|
|
7895
|
-
return { role: "vselect" };
|
|
7896
|
-
if (elementTag === "button" || elementTag === "ubutton")
|
|
7897
|
-
return { role: "button" };
|
|
7898
|
-
if (elementTag === "router-link" || elementTag === "routerlink")
|
|
7899
|
-
return { role: "link" };
|
|
7900
|
-
if ((elementTag === "a" || elementTag === "ua") && hasHrefAttribute(element))
|
|
7901
|
-
return { role: "link" };
|
|
7902
|
-
if (isComponentLikeTag(element.tag) && element.tag !== tag) {
|
|
7903
|
-
const nested = tryInferNativeWrapperRoleFromSfc(element.tag, vueFilesPathMap, normalizedSearchRoots, nextSeen);
|
|
7904
|
-
if (nested)
|
|
7905
|
-
return nested;
|
|
7906
|
-
}
|
|
7907
|
-
for (const child of element.children ?? []) {
|
|
7908
|
-
const inferred2 = inferRoleFromNode(child);
|
|
7909
|
-
if (inferred2)
|
|
7910
|
-
return inferred2;
|
|
7911
|
-
}
|
|
7912
|
-
return null;
|
|
7913
|
-
};
|
|
7914
|
-
inferRoleFromNode = (node) => {
|
|
7915
|
-
if (!node || typeof node !== "object")
|
|
7916
|
-
return null;
|
|
7917
|
-
if (node.type === compilerCore.NodeTypes.ELEMENT) {
|
|
7918
|
-
return inferRoleFromElement(node);
|
|
7919
|
-
}
|
|
7920
|
-
if (node.type === compilerCore.NodeTypes.ROOT || node.type === compilerCore.NodeTypes.IF_BRANCH || node.type === compilerCore.NodeTypes.FOR) {
|
|
7921
|
-
for (const child of node.children ?? []) {
|
|
7922
|
-
const inferred2 = inferRoleFromNode(child);
|
|
7923
|
-
if (inferred2)
|
|
7924
|
-
return inferred2;
|
|
7925
|
-
}
|
|
7926
|
-
return null;
|
|
7927
|
-
}
|
|
7928
|
-
if (node.type === compilerCore.NodeTypes.IF) {
|
|
7929
|
-
for (const branch of node.branches ?? []) {
|
|
7930
|
-
const inferred2 = inferRoleFromNode(branch);
|
|
7931
|
-
if (inferred2)
|
|
7932
|
-
return inferred2;
|
|
7933
|
-
}
|
|
7934
|
-
}
|
|
7935
|
-
return null;
|
|
7936
|
-
};
|
|
7937
|
-
const inferred = inferRoleFromNode(ast);
|
|
7938
|
-
if (inferred) {
|
|
7939
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, inferred);
|
|
7940
|
-
return inferred;
|
|
7941
|
-
}
|
|
7942
|
-
} catch {
|
|
7943
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7944
|
-
return null;
|
|
7945
|
-
}
|
|
7946
|
-
inferredNativeWrapperConfigByLookup.set(cacheKey, { role: "" });
|
|
7947
|
-
return null;
|
|
7948
|
-
}
|
|
7949
8408
|
function tryWrapClickDirectiveForTestEvents(element, testIdAttribute, resolvedRuntimeTestId) {
|
|
7950
8409
|
const jsStringLiteral = (value) => {
|
|
7951
8410
|
return JSON.stringify(value);
|
|
@@ -8090,7 +8549,7 @@ function tryWrapClickDirectiveForTestEvents(element, testIdAttribute, resolvedRu
|
|
|
8090
8549
|
}
|
|
8091
8550
|
let previousFileName = "";
|
|
8092
8551
|
const hierarchyMap = /* @__PURE__ */ new Map();
|
|
8093
|
-
function createTestIdTransform(componentName, componentHierarchyMap, nativeWrappers = {},
|
|
8552
|
+
function createTestIdTransform(componentName, componentHierarchyMap, nativeWrappers = {}, skipTestIdGenerationInsideComponents = [], viewsDirAbs, options = {}) {
|
|
8094
8553
|
const existingIdBehavior = options.existingIdBehavior ?? "error";
|
|
8095
8554
|
const testIdAttribute = (options.testIdAttribute || "data-testid").trim() || "data-testid";
|
|
8096
8555
|
const nameCollisionBehavior = options.nameCollisionBehavior ?? "error";
|
|
@@ -8101,6 +8560,21 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8101
8560
|
const annotatorMetadata = options.annotatorMetadata ?? null;
|
|
8102
8561
|
const crossFileKeyRegistry = options.crossFileKeyRegistry;
|
|
8103
8562
|
const optionKeyAttribute = options.optionKeyAttribute ?? {};
|
|
8563
|
+
const resolvedNativeWrappers = Object.fromEntries(
|
|
8564
|
+
Object.entries(nativeWrappers).map(([tag, config]) => [tag, { ...config }])
|
|
8565
|
+
);
|
|
8566
|
+
const wrapperContractByTag = /* @__PURE__ */ new Map();
|
|
8567
|
+
const getWrapperContract = (tag) => {
|
|
8568
|
+
if (!wrapperContractByTag.has(tag)) {
|
|
8569
|
+
wrapperContractByTag.set(tag, resolveWrapperContractForTag({
|
|
8570
|
+
tag,
|
|
8571
|
+
vueFilesPathMap,
|
|
8572
|
+
wrapperSearchRoots,
|
|
8573
|
+
testIdAttribute
|
|
8574
|
+
}));
|
|
8575
|
+
}
|
|
8576
|
+
return wrapperContractByTag.get(tag) ?? null;
|
|
8577
|
+
};
|
|
8104
8578
|
const safeRealpath2 = (p) => {
|
|
8105
8579
|
try {
|
|
8106
8580
|
return fs.existsSync(p) ? fs.realpathSync(p) : p;
|
|
@@ -8152,7 +8626,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8152
8626
|
}
|
|
8153
8627
|
};
|
|
8154
8628
|
return (node, context) => {
|
|
8155
|
-
if (
|
|
8629
|
+
if (skipTestIdGenerationInsideComponents.includes(componentName)) {
|
|
8156
8630
|
return;
|
|
8157
8631
|
}
|
|
8158
8632
|
if (node.type === compilerCore.NodeTypes.IF) {
|
|
@@ -8217,13 +8691,13 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8217
8691
|
}
|
|
8218
8692
|
return deps;
|
|
8219
8693
|
})();
|
|
8220
|
-
const
|
|
8694
|
+
const isComponentLikeTag2 = (tag) => {
|
|
8221
8695
|
if (!tag) return false;
|
|
8222
8696
|
const first = tag.charCodeAt(0);
|
|
8223
|
-
const isUpper = isAsciiUppercaseLetterCode(first);
|
|
8697
|
+
const isUpper = isAsciiUppercaseLetterCode$1(first);
|
|
8224
8698
|
return isUpper || tag.includes("-");
|
|
8225
8699
|
};
|
|
8226
|
-
if (
|
|
8700
|
+
if (isComponentLikeTag2(element.tag)) {
|
|
8227
8701
|
dependencies.usedComponentSet.add(element.tag);
|
|
8228
8702
|
if (crossFileKeyRegistry && context.scopes.vSlot > 0) {
|
|
8229
8703
|
const findSlotTemplate = () => {
|
|
@@ -8251,31 +8725,38 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8251
8725
|
}
|
|
8252
8726
|
}
|
|
8253
8727
|
}
|
|
8254
|
-
const
|
|
8728
|
+
const ownWrapperContract = getWrapperContract(componentName);
|
|
8729
|
+
const elementStartOffset = element.loc.start.offset;
|
|
8730
|
+
const isExplicitFallthroughTarget = ownWrapperContract?.explicitlyForwardedTestIdTargetOffsets.has(elementStartOffset) || ownWrapperContract?.explicitlyForwardedTestIdTargetSfcOffsets.has(elementStartOffset);
|
|
8731
|
+
if (!dependencies.isView && isExplicitFallthroughTarget) {
|
|
8732
|
+
return;
|
|
8733
|
+
}
|
|
8734
|
+
const existingWrapperConfig = resolvedNativeWrappers[element.tag];
|
|
8255
8735
|
if (!existingWrapperConfig) {
|
|
8256
|
-
const
|
|
8257
|
-
if (
|
|
8258
|
-
|
|
8259
|
-
} else if (element.tag.endsWith("Button") && !
|
|
8260
|
-
|
|
8736
|
+
const contract = getWrapperContract(element.tag);
|
|
8737
|
+
if (contract?.role) {
|
|
8738
|
+
resolvedNativeWrappers[element.tag] = { role: contract.role, inferred: true };
|
|
8739
|
+
} else if (element.tag.endsWith("Button") && !resolveSfcPathForTag(element.tag, vueFilesPathMap, wrapperSearchRoots)) {
|
|
8740
|
+
resolvedNativeWrappers[element.tag] = { role: "button" };
|
|
8261
8741
|
} else if (element.tag === "DxDataGrid") {
|
|
8262
|
-
|
|
8742
|
+
resolvedNativeWrappers[element.tag] = { role: "grid" };
|
|
8263
8743
|
}
|
|
8264
8744
|
} else if (!existingWrapperConfig.role) {
|
|
8265
|
-
const
|
|
8266
|
-
if (!
|
|
8745
|
+
const contract = getWrapperContract(element.tag);
|
|
8746
|
+
if (!contract?.role) {
|
|
8267
8747
|
const loc = element.loc?.start;
|
|
8268
8748
|
const locationHint = loc ? `${loc.line}:${loc.column}` : "unknown";
|
|
8749
|
+
const targetRoles = contract?.targetRoles.length ? contract.targetRoles.map((role) => role ?? "non-interactive").join(", ") : "no forwarded test-id target";
|
|
8269
8750
|
throw new Error(
|
|
8270
8751
|
`[vue-pom-generator] Could not infer a native role for declared wrapper <${element.tag}> in ${componentName} (${context.filename ?? "unknown"}:${locationHint}).
|
|
8271
|
-
|
|
8752
|
+
Resolved fallthrough targets: ${targetRoles}. The generator requires one stable role across every target.
|
|
8272
8753
|
|
|
8273
8754
|
Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role: "button", ... } }).`
|
|
8274
8755
|
);
|
|
8275
8756
|
}
|
|
8276
|
-
|
|
8757
|
+
resolvedNativeWrappers[element.tag] = {
|
|
8277
8758
|
...existingWrapperConfig,
|
|
8278
|
-
role:
|
|
8759
|
+
role: contract.role
|
|
8279
8760
|
};
|
|
8280
8761
|
}
|
|
8281
8762
|
const getBestAvailableKeyInfo = () => {
|
|
@@ -8385,7 +8866,7 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
|
|
|
8385
8866
|
}
|
|
8386
8867
|
let cachedTagSuffix = null;
|
|
8387
8868
|
const getTagSuffix = () => {
|
|
8388
|
-
cachedTagSuffix ??= formatTagName(element,
|
|
8869
|
+
cachedTagSuffix ??= formatTagName(element, resolvedNativeWrappers);
|
|
8389
8870
|
return cachedTagSuffix;
|
|
8390
8871
|
};
|
|
8391
8872
|
const getNativeRoleFromTagSuffix = () => getTagSuffix().slice(1);
|
|
@@ -8432,12 +8913,12 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
|
|
|
8432
8913
|
annotatorMetadata
|
|
8433
8914
|
});
|
|
8434
8915
|
};
|
|
8435
|
-
const { nativeWrappersValue, optionDataTestIdPrefixValue, semanticNameHint } = getNativeWrapperTransformInfo(element, componentName,
|
|
8916
|
+
const { nativeWrappersValue, optionDataTestIdPrefixValue, semanticNameHint } = getNativeWrapperTransformInfo(element, componentName, resolvedNativeWrappers);
|
|
8436
8917
|
const handlerDirective = element.props.find((p) => {
|
|
8437
8918
|
return p.type === compilerCore.NodeTypes.DIRECTIVE && p.name === "bind" && p.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && p.arg.content === "handler" && !!p.exp;
|
|
8438
8919
|
}) ?? null;
|
|
8439
8920
|
const handlerInfo = handlerDirective ? nodeHandlerAttributeInfo(element) : null;
|
|
8440
|
-
if (
|
|
8921
|
+
if (resolvedNativeWrappers[element.tag]?.role === "button" && handlerDirective && !handlerInfo) {
|
|
8441
8922
|
const loc = element.loc?.start;
|
|
8442
8923
|
const locationHint = loc ? `${loc.line}:${loc.column}` : "unknown";
|
|
8443
8924
|
const handlerSource = (handlerDirective.exp?.loc?.source ?? "").trim() || "<unknown>";
|
|
@@ -8468,7 +8949,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8468
8949
|
}
|
|
8469
8950
|
upsertAttribute(element, "option-data-testid-prefix", optionDataTestIdPrefixValue);
|
|
8470
8951
|
}
|
|
8471
|
-
const nativeRole =
|
|
8952
|
+
const nativeRole = resolvedNativeWrappers[element.tag]?.role ?? element.tag;
|
|
8472
8953
|
const wrapperHintCandidates = [
|
|
8473
8954
|
semanticNameHint,
|
|
8474
8955
|
getStaticAttributeContent(element, "title"),
|
|
@@ -8538,7 +9019,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8538
9019
|
const innerText = getInnerText(element) || null;
|
|
8539
9020
|
const toDirective = nodeHasToDirective(element);
|
|
8540
9021
|
if (toDirective) {
|
|
8541
|
-
const dataTestId = generateToDirectiveDataTestId(componentName, element, toDirective, context, hierarchyMap,
|
|
9022
|
+
const dataTestId = generateToDirectiveDataTestId(componentName, element, toDirective, context, hierarchyMap, resolvedNativeWrappers);
|
|
8542
9023
|
const target = tryResolveToDirectiveTargetComponentName(toDirective);
|
|
8543
9024
|
const routeNameHint = toDirectiveObjectFieldNameValue(toDirective);
|
|
8544
9025
|
const existing = tryGetExistingElementDataTestId(element, testIdAttribute);
|
|
@@ -8559,7 +9040,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8559
9040
|
});
|
|
8560
9041
|
return;
|
|
8561
9042
|
}
|
|
8562
|
-
if (handlerInfo &&
|
|
9043
|
+
if (handlerInfo && resolvedNativeWrappers[element.tag]) {
|
|
8563
9044
|
const testId = getHandlerAttributeValueDataTestId(handlerInfo.semanticNameHint);
|
|
8564
9045
|
applyResolvedDataTestIdForElement({
|
|
8565
9046
|
preferredGeneratedValue: testId,
|
|
@@ -8568,6 +9049,15 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8568
9049
|
});
|
|
8569
9050
|
return;
|
|
8570
9051
|
}
|
|
9052
|
+
const inferredWrapperRole = resolvedNativeWrappers[element.tag]?.inferred ? resolvedNativeWrappers[element.tag]?.role : null;
|
|
9053
|
+
if (inferredWrapperRole && innerText) {
|
|
9054
|
+
applyResolvedDataTestIdForElement({
|
|
9055
|
+
preferredGeneratedValue: staticAttributeValue(`${componentName}-${innerText}-${inferredWrapperRole}`),
|
|
9056
|
+
nativeRoleOverride: inferredWrapperRole,
|
|
9057
|
+
semanticNameHint: innerText
|
|
9058
|
+
});
|
|
9059
|
+
return;
|
|
9060
|
+
}
|
|
8571
9061
|
const existingElementDataTestId = tryGetExistingElementDataTestId(element, testIdAttribute);
|
|
8572
9062
|
const shouldPreserveExisting = existingElementDataTestId && existingIdBehavior === "preserve";
|
|
8573
9063
|
const clickDirective = tryGetClickDirective(element);
|
|
@@ -8594,7 +9084,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8594
9084
|
}
|
|
8595
9085
|
if (existingElementDataTestId) {
|
|
8596
9086
|
const inferredRole = getNativeRoleFromTagSuffix().toLowerCase();
|
|
8597
|
-
const isRecognizedInteractiveRole = inferredRole === "button" || inferredRole === "input" || inferredRole === "select" || inferredRole === "vselect" || inferredRole === "checkbox" || inferredRole === "toggle" || inferredRole === "radio" || inferredRole === "grid" || inferredRole === "link" || inferredRole === "tab" ||
|
|
9087
|
+
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);
|
|
8598
9088
|
if (!isRecognizedInteractiveRole) {
|
|
8599
9089
|
return;
|
|
8600
9090
|
}
|
|
@@ -8817,7 +9307,7 @@ function createVuePluginWithTestIds(options) {
|
|
|
8817
9307
|
componentHierarchyMap,
|
|
8818
9308
|
crossFileKeyRegistry,
|
|
8819
9309
|
vueFilesPathMap,
|
|
8820
|
-
|
|
9310
|
+
skipTestIdGenerationInsideComponents,
|
|
8821
9311
|
getViewsDirAbs,
|
|
8822
9312
|
testIdAttribute,
|
|
8823
9313
|
accessibilityAudit,
|
|
@@ -8875,7 +9365,7 @@ function createVuePluginWithTestIds(options) {
|
|
|
8875
9365
|
componentName,
|
|
8876
9366
|
componentHierarchyMap,
|
|
8877
9367
|
nativeWrappers,
|
|
8878
|
-
|
|
9368
|
+
skipTestIdGenerationInsideComponents,
|
|
8879
9369
|
viewsDirAbs,
|
|
8880
9370
|
{
|
|
8881
9371
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -8933,7 +9423,7 @@ function createVuePluginWithTestIds(options) {
|
|
|
8933
9423
|
componentName,
|
|
8934
9424
|
componentHierarchyMap,
|
|
8935
9425
|
nativeWrappers,
|
|
8936
|
-
|
|
9426
|
+
skipTestIdGenerationInsideComponents,
|
|
8937
9427
|
viewsDirAbs,
|
|
8938
9428
|
{
|
|
8939
9429
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -9093,7 +9583,7 @@ function createBuildProcessorPlugin(options) {
|
|
|
9093
9583
|
projectRootRef,
|
|
9094
9584
|
nativeWrappers,
|
|
9095
9585
|
optionKeyAttribute,
|
|
9096
|
-
|
|
9586
|
+
skipTestIdGenerationInsideComponents,
|
|
9097
9587
|
getWrapperSearchRoots,
|
|
9098
9588
|
getResolvedRouterEntry,
|
|
9099
9589
|
loggerRef
|
|
@@ -9215,7 +9705,7 @@ function createBuildProcessorPlugin(options) {
|
|
|
9215
9705
|
componentName,
|
|
9216
9706
|
componentHierarchyMap,
|
|
9217
9707
|
nativeWrappers,
|
|
9218
|
-
|
|
9708
|
+
skipTestIdGenerationInsideComponents,
|
|
9219
9709
|
getViewsDirAbs(),
|
|
9220
9710
|
{
|
|
9221
9711
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -9348,7 +9838,7 @@ function createDevProcessorPlugin(options) {
|
|
|
9348
9838
|
elementMetadata,
|
|
9349
9839
|
nativeWrappers,
|
|
9350
9840
|
optionKeyAttribute,
|
|
9351
|
-
|
|
9841
|
+
skipTestIdGenerationInsideComponents,
|
|
9352
9842
|
getPageDirs,
|
|
9353
9843
|
getComponentDirs,
|
|
9354
9844
|
getLayoutDirs,
|
|
@@ -9571,7 +10061,7 @@ function createDevProcessorPlugin(options) {
|
|
|
9571
10061
|
componentName,
|
|
9572
10062
|
provisionalHierarchy,
|
|
9573
10063
|
nativeWrappers,
|
|
9574
|
-
|
|
10064
|
+
skipTestIdGenerationInsideComponents,
|
|
9575
10065
|
getViewsDirAbs(),
|
|
9576
10066
|
{
|
|
9577
10067
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -9917,7 +10407,7 @@ function createInternalPlugins(options) {
|
|
|
9917
10407
|
vueFilesPathMap,
|
|
9918
10408
|
nativeWrappers,
|
|
9919
10409
|
optionKeyAttribute,
|
|
9920
|
-
|
|
10410
|
+
skipTestIdGenerationInsideComponents,
|
|
9921
10411
|
getPageDirs,
|
|
9922
10412
|
getComponentDirs,
|
|
9923
10413
|
getLayoutDirs,
|
|
@@ -9969,7 +10459,7 @@ function createInternalPlugins(options) {
|
|
|
9969
10459
|
projectRootRef,
|
|
9970
10460
|
nativeWrappers,
|
|
9971
10461
|
optionKeyAttribute,
|
|
9972
|
-
|
|
10462
|
+
skipTestIdGenerationInsideComponents,
|
|
9973
10463
|
getWrapperSearchRoots,
|
|
9974
10464
|
getResolvedRouterEntry: resolveRouterEntry2,
|
|
9975
10465
|
loggerRef
|
|
@@ -9978,7 +10468,7 @@ function createInternalPlugins(options) {
|
|
|
9978
10468
|
elementMetadata,
|
|
9979
10469
|
nativeWrappers,
|
|
9980
10470
|
optionKeyAttribute,
|
|
9981
|
-
|
|
10471
|
+
skipTestIdGenerationInsideComponents,
|
|
9982
10472
|
getPageDirs,
|
|
9983
10473
|
getComponentDirs,
|
|
9984
10474
|
getLayoutDirs,
|
|
@@ -10233,7 +10723,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10233
10723
|
wrapperSearchRoots: injection.wrapperSearchRoots,
|
|
10234
10724
|
nativeWrappers: injection.nativeWrappers,
|
|
10235
10725
|
optionKeyAttribute: injection.optionKeyAttribute,
|
|
10236
|
-
|
|
10726
|
+
skipTestIdGenerationInsideComponents: injection.skipTestIdGenerationInsideComponents,
|
|
10237
10727
|
existingIdBehavior: injection.existingIdBehavior,
|
|
10238
10728
|
testIdAttribute: injection.attribute
|
|
10239
10729
|
})
|
|
@@ -10241,7 +10731,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10241
10731
|
const resolvedInjectionOptions = resolvedInjectionOptionsRef.current;
|
|
10242
10732
|
const nativeWrappers = resolvedInjectionOptions.nativeWrappers;
|
|
10243
10733
|
const optionKeyAttribute = resolvedInjectionOptions.optionKeyAttribute;
|
|
10244
|
-
const
|
|
10734
|
+
const skipTestIdGenerationInsideComponents = resolvedInjectionOptions.skipTestIdGenerationInsideComponents;
|
|
10245
10735
|
const testIdAttribute = resolvedInjectionOptions.testIdAttribute;
|
|
10246
10736
|
const routerEntry = !isNuxt ? vueGenerationOptions?.router?.entry : void 0;
|
|
10247
10737
|
const routerType = isNuxt ? "nuxt" : vueGenerationOptions?.router?.type ?? "vue-router";
|
|
@@ -10355,7 +10845,10 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10355
10845
|
}
|
|
10356
10846
|
};
|
|
10357
10847
|
const getViewsDirAbs = () => resolveFromProjectRoot(projectRootRef.current, getViewsDir());
|
|
10358
|
-
const getWrapperSearchRootsAbs = () =>
|
|
10848
|
+
const getWrapperSearchRootsAbs = () => Array.from(new Set([
|
|
10849
|
+
...getSourceDirs(),
|
|
10850
|
+
...getWrapperSearchRoots()
|
|
10851
|
+
].map((root) => resolveFromProjectRoot(projectRootRef.current, root))));
|
|
10359
10852
|
const { elementMetadata, semanticNameMap, componentHierarchyMap, crossFileKeyRegistry, vueFilesPathMap } = sharedState;
|
|
10360
10853
|
const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions } = createVuePluginWithTestIds({
|
|
10361
10854
|
vueOptions,
|
|
@@ -10369,7 +10862,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10369
10862
|
componentHierarchyMap,
|
|
10370
10863
|
crossFileKeyRegistry,
|
|
10371
10864
|
vueFilesPathMap,
|
|
10372
|
-
|
|
10865
|
+
skipTestIdGenerationInsideComponents,
|
|
10373
10866
|
getViewsDirAbs,
|
|
10374
10867
|
testIdAttribute,
|
|
10375
10868
|
accessibilityAudit: resolvedGenerationOptions.accessibilityAudit,
|
|
@@ -10390,7 +10883,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10390
10883
|
vueFilesPathMap,
|
|
10391
10884
|
nativeWrappers,
|
|
10392
10885
|
optionKeyAttribute,
|
|
10393
|
-
|
|
10886
|
+
skipTestIdGenerationInsideComponents,
|
|
10394
10887
|
getPageDirs,
|
|
10395
10888
|
getComponentDirs,
|
|
10396
10889
|
getLayoutDirs,
|