@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.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,686 @@ ${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, elementTag) {
|
|
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
|
+
return elementTag === "input" || elementTag === "uinput" ? "input" : "select";
|
|
8016
|
+
case "listbox":
|
|
8017
|
+
return "select";
|
|
8018
|
+
case "searchbox":
|
|
8019
|
+
case "spinbutton":
|
|
8020
|
+
case "textbox":
|
|
8021
|
+
return "input";
|
|
8022
|
+
case "switch":
|
|
8023
|
+
return "toggle";
|
|
8024
|
+
default:
|
|
8025
|
+
return null;
|
|
8026
|
+
}
|
|
8027
|
+
}
|
|
8028
|
+
function hasAttribute(element, name) {
|
|
8029
|
+
return element.props.some((prop) => {
|
|
8030
|
+
if (prop.type === compilerCore.NodeTypes.ATTRIBUTE) {
|
|
8031
|
+
return prop.name === name;
|
|
8032
|
+
}
|
|
8033
|
+
return prop.type === compilerCore.NodeTypes.DIRECTIVE && prop.name === "bind" && prop.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && prop.arg.content === name;
|
|
8034
|
+
});
|
|
8035
|
+
}
|
|
8036
|
+
function getElementControlRole(element) {
|
|
8037
|
+
const tag = element.tag.toLowerCase();
|
|
8038
|
+
const explicitRole = getStaticAttributeContent$1(element, "role");
|
|
8039
|
+
if (explicitRole) {
|
|
8040
|
+
return mapExplicitAriaRole(explicitRole, tag);
|
|
8041
|
+
}
|
|
8042
|
+
const type = (getStaticAttributeContent$1(element, "type") || "").toLowerCase();
|
|
8043
|
+
if (tag === "input" || tag === "uinput") {
|
|
8044
|
+
if (type === "radio") {
|
|
8045
|
+
return "radio";
|
|
8046
|
+
}
|
|
8047
|
+
if (type === "checkbox") {
|
|
8048
|
+
return "checkbox";
|
|
8049
|
+
}
|
|
8050
|
+
return "input";
|
|
8051
|
+
}
|
|
8052
|
+
if (tag === "textarea" || tag === "utextarea") {
|
|
8053
|
+
return "input";
|
|
8054
|
+
}
|
|
8055
|
+
if (tag === "select" || tag === "uselect") {
|
|
8056
|
+
return "select";
|
|
8057
|
+
}
|
|
8058
|
+
if (tag === "vselect") {
|
|
8059
|
+
return "vselect";
|
|
8060
|
+
}
|
|
8061
|
+
if (tag === "button" || tag === "ubutton") {
|
|
8062
|
+
return "button";
|
|
8063
|
+
}
|
|
8064
|
+
if (tag === "router-link" || tag === "routerlink") {
|
|
8065
|
+
return "link";
|
|
8066
|
+
}
|
|
8067
|
+
if ((tag === "a" || tag === "ua") && hasAttribute(element, "href")) {
|
|
8068
|
+
return "link";
|
|
8069
|
+
}
|
|
8070
|
+
return null;
|
|
8071
|
+
}
|
|
8072
|
+
function isComponentLikeTag(tag) {
|
|
8073
|
+
if (!tag) {
|
|
8074
|
+
return false;
|
|
8075
|
+
}
|
|
8076
|
+
return isAsciiUppercaseLetterCode(tag.charCodeAt(0)) || tag.includes("-");
|
|
8077
|
+
}
|
|
8078
|
+
function parseTemplateExpression(source) {
|
|
8079
|
+
try {
|
|
8080
|
+
return parser.parseExpression(source, { plugins: ["typescript"] });
|
|
8081
|
+
} catch {
|
|
8082
|
+
return null;
|
|
8083
|
+
}
|
|
8084
|
+
}
|
|
8085
|
+
function directiveExpressionSource(directive) {
|
|
8086
|
+
if (!directive.exp) {
|
|
8087
|
+
return "";
|
|
8088
|
+
}
|
|
8089
|
+
return directive.exp.loc?.source || (directive.exp.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION ? directive.exp.content : "");
|
|
8090
|
+
}
|
|
8091
|
+
function elementExplicitlyForwardsTestId(element, testIdAttribute, scriptMetadata) {
|
|
8092
|
+
for (const prop of element.props) {
|
|
8093
|
+
if (prop.type !== compilerCore.NodeTypes.DIRECTIVE || prop.name !== "bind" || !prop.exp) {
|
|
8094
|
+
continue;
|
|
8095
|
+
}
|
|
8096
|
+
const source = directiveExpressionSource(prop);
|
|
8097
|
+
const expression = parseTemplateExpression(source);
|
|
8098
|
+
if (!expression) {
|
|
8099
|
+
continue;
|
|
8100
|
+
}
|
|
8101
|
+
if (!prop.arg) {
|
|
8102
|
+
if (expressionForwardsTestId(expression, testIdAttribute, scriptMetadata.attrsObjectNames, scriptMetadata.attrsFunctionNames)) {
|
|
8103
|
+
return true;
|
|
8104
|
+
}
|
|
8105
|
+
continue;
|
|
8106
|
+
}
|
|
8107
|
+
if (prop.arg.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && prop.arg.isStatic && prop.arg.content === testIdAttribute && expressionReadsTestId(expression, testIdAttribute, scriptMetadata.attrsObjectNames, scriptMetadata.attrsFunctionNames)) {
|
|
8108
|
+
return true;
|
|
8109
|
+
}
|
|
8110
|
+
}
|
|
8111
|
+
return false;
|
|
8112
|
+
}
|
|
8113
|
+
function walkTemplate(node, visitor) {
|
|
8114
|
+
if (node.type === compilerCore.NodeTypes.ELEMENT) {
|
|
8115
|
+
visitor(node);
|
|
8116
|
+
for (const child of node.children) {
|
|
8117
|
+
walkTemplate(child, visitor);
|
|
8118
|
+
}
|
|
8119
|
+
return;
|
|
8120
|
+
}
|
|
8121
|
+
if (node.type === compilerCore.NodeTypes.ROOT) {
|
|
8122
|
+
for (const child of node.children) {
|
|
8123
|
+
walkTemplate(child, visitor);
|
|
8124
|
+
}
|
|
8125
|
+
}
|
|
8126
|
+
}
|
|
8127
|
+
function getRenderedRootElements(ast) {
|
|
8128
|
+
const rendered = ast.children.filter((child) => {
|
|
8129
|
+
return child.type !== compilerCore.NodeTypes.COMMENT && !(child.type === compilerCore.NodeTypes.TEXT && child.content.trim() === "");
|
|
8130
|
+
});
|
|
8131
|
+
if (rendered.length !== 1 || rendered[0]?.type !== compilerCore.NodeTypes.ELEMENT || rendered[0].tag === "template") {
|
|
8132
|
+
return [];
|
|
8133
|
+
}
|
|
8134
|
+
return [rendered[0]];
|
|
8135
|
+
}
|
|
8136
|
+
function analyzeWrapperContractFromSfc(options) {
|
|
8137
|
+
const { descriptor } = compilerSfc.parse(options.source, { filename: options.filePath });
|
|
8138
|
+
const template = descriptor.template?.content ?? "";
|
|
8139
|
+
if (!template.trim()) {
|
|
8140
|
+
return {
|
|
8141
|
+
role: null,
|
|
8142
|
+
targetRoles: [],
|
|
8143
|
+
forwardedTestIdTargetOffsets: /* @__PURE__ */ new Set(),
|
|
8144
|
+
forwardedTestIdTargetSfcOffsets: /* @__PURE__ */ new Set(),
|
|
8145
|
+
explicitlyForwardedTestIdTargetOffsets: /* @__PURE__ */ new Set(),
|
|
8146
|
+
explicitlyForwardedTestIdTargetSfcOffsets: /* @__PURE__ */ new Set()
|
|
8147
|
+
};
|
|
8148
|
+
}
|
|
8149
|
+
const scriptMetadata = analyzeScriptForwardingMetadata(
|
|
8150
|
+
[descriptor.script, descriptor.scriptSetup].filter((block) => !!block).map((block) => ({ content: block.content, lang: block.lang })),
|
|
8151
|
+
options.testIdAttribute
|
|
8152
|
+
);
|
|
8153
|
+
const ast = compilerDom.parse(template, { comments: false });
|
|
8154
|
+
const targets = /* @__PURE__ */ new Map();
|
|
8155
|
+
const explicitTargetOffsets = /* @__PURE__ */ new Set();
|
|
8156
|
+
if (scriptMetadata.inheritAttrs) {
|
|
8157
|
+
for (const element of getRenderedRootElements(ast)) {
|
|
8158
|
+
targets.set(element.loc.start.offset, element);
|
|
8159
|
+
}
|
|
8160
|
+
}
|
|
8161
|
+
walkTemplate(ast, (element) => {
|
|
8162
|
+
if (elementExplicitlyForwardsTestId(element, options.testIdAttribute, scriptMetadata)) {
|
|
8163
|
+
targets.set(element.loc.start.offset, element);
|
|
8164
|
+
explicitTargetOffsets.add(element.loc.start.offset);
|
|
8165
|
+
}
|
|
8166
|
+
});
|
|
8167
|
+
const targetRoles = [...targets.values()].map((element) => {
|
|
8168
|
+
const directRole = getElementControlRole(element);
|
|
8169
|
+
if (directRole) {
|
|
8170
|
+
return directRole;
|
|
8171
|
+
}
|
|
8172
|
+
if (isComponentLikeTag(element.tag)) {
|
|
8173
|
+
return options.resolveNestedContract(element.tag)?.role ?? null;
|
|
8174
|
+
}
|
|
8175
|
+
return null;
|
|
8176
|
+
});
|
|
8177
|
+
const uniqueRoles = new Set(targetRoles);
|
|
8178
|
+
const role = uniqueRoles.size === 1 && !uniqueRoles.has(null) ? targetRoles[0] ?? null : null;
|
|
8179
|
+
const templateContentStartOffset = descriptor.template?.loc.start.offset ?? 0;
|
|
8180
|
+
const toSfcOffsets = (offsets) => new Set(
|
|
8181
|
+
[...offsets].map((offset) => offset + templateContentStartOffset)
|
|
8182
|
+
);
|
|
8183
|
+
return {
|
|
8184
|
+
role,
|
|
8185
|
+
targetRoles,
|
|
8186
|
+
forwardedTestIdTargetOffsets: new Set(targets.keys()),
|
|
8187
|
+
forwardedTestIdTargetSfcOffsets: toSfcOffsets(targets.keys()),
|
|
8188
|
+
explicitlyForwardedTestIdTargetOffsets: explicitTargetOffsets,
|
|
8189
|
+
explicitlyForwardedTestIdTargetSfcOffsets: toSfcOffsets(explicitTargetOffsets)
|
|
8190
|
+
};
|
|
8191
|
+
}
|
|
8192
|
+
function resolveWrapperContractForTag(options) {
|
|
8193
|
+
const normalizedSearchRoots = normalizeWrapperSearchRoots(options.wrapperSearchRoots ?? []);
|
|
8194
|
+
const memo = /* @__PURE__ */ new Map();
|
|
8195
|
+
const resolving = /* @__PURE__ */ new Set();
|
|
8196
|
+
const resolveTag = (tag) => {
|
|
8197
|
+
const first = tag.charCodeAt(0);
|
|
8198
|
+
if (!isAsciiUppercaseLetterCode(first) && !tag.includes("-")) {
|
|
8199
|
+
return null;
|
|
8200
|
+
}
|
|
8201
|
+
const filePath = resolveSfcPathForTag(tag, options.vueFilesPathMap, normalizedSearchRoots);
|
|
8202
|
+
if (!filePath) {
|
|
8203
|
+
return null;
|
|
8204
|
+
}
|
|
8205
|
+
const normalizedPath = path.normalize(filePath);
|
|
8206
|
+
if (memo.has(normalizedPath)) {
|
|
8207
|
+
return memo.get(normalizedPath) ?? null;
|
|
8208
|
+
}
|
|
8209
|
+
if (resolving.has(normalizedPath)) {
|
|
8210
|
+
return null;
|
|
8211
|
+
}
|
|
8212
|
+
const source = fs.readFileSync(normalizedPath, "utf8");
|
|
8213
|
+
resolving.add(normalizedPath);
|
|
8214
|
+
try {
|
|
8215
|
+
const contract = analyzeWrapperContractFromSfc({
|
|
8216
|
+
filePath: normalizedPath,
|
|
8217
|
+
source,
|
|
8218
|
+
testIdAttribute: options.testIdAttribute,
|
|
8219
|
+
resolveNestedContract: resolveTag
|
|
8220
|
+
});
|
|
8221
|
+
memo.set(normalizedPath, contract);
|
|
8222
|
+
return contract;
|
|
8223
|
+
} finally {
|
|
8224
|
+
resolving.delete(normalizedPath);
|
|
8225
|
+
}
|
|
8226
|
+
};
|
|
8227
|
+
return resolveTag(options.tag);
|
|
8228
|
+
}
|
|
8229
|
+
const CLICK_EVENT_NAME = TESTID_CLICK_EVENT_NAME;
|
|
8230
|
+
function getStaticAttributeContent(element, name) {
|
|
8231
|
+
const attr = element.props.find((prop) => {
|
|
8232
|
+
return prop.type === compilerCore.NodeTypes.ATTRIBUTE && prop.name === name;
|
|
8233
|
+
});
|
|
8234
|
+
return attr?.value?.content?.trim() || null;
|
|
8235
|
+
}
|
|
8236
|
+
function getNativeHtmlControlRole(element) {
|
|
8237
|
+
return getElementControlRole(element);
|
|
8238
|
+
}
|
|
8239
|
+
function normalizeControlLabelText(value) {
|
|
8240
|
+
const normalized = (value ?? "").replace(/\*/g, " ").replace(/\s+/g, " ").trim();
|
|
8241
|
+
return normalized || null;
|
|
8242
|
+
}
|
|
8243
|
+
function getLabelNodeText(labelNode) {
|
|
8244
|
+
for (const child of labelNode.children || []) {
|
|
8245
|
+
if (child.type === compilerCore.NodeTypes.TEXT) {
|
|
8246
|
+
const normalized2 = normalizeControlLabelText(child.content);
|
|
8247
|
+
if (normalized2) {
|
|
8248
|
+
return normalized2;
|
|
8249
|
+
}
|
|
8250
|
+
continue;
|
|
8251
|
+
}
|
|
8252
|
+
if (child.type !== compilerCore.NodeTypes.ELEMENT) {
|
|
8253
|
+
continue;
|
|
8254
|
+
}
|
|
8255
|
+
if (getNativeHtmlControlRole(child)) {
|
|
8256
|
+
continue;
|
|
8257
|
+
}
|
|
8258
|
+
const normalized = normalizeControlLabelText(getInnerText(child));
|
|
8259
|
+
if (normalized) {
|
|
8260
|
+
return normalized;
|
|
8261
|
+
}
|
|
8262
|
+
}
|
|
8263
|
+
return normalizeControlLabelText(getInnerText(labelNode));
|
|
8264
|
+
}
|
|
8265
|
+
function getAssociatedLabelText(element, hierarchyMap2) {
|
|
8266
|
+
let parent = hierarchyMap2.get(element) || null;
|
|
8267
|
+
while (parent) {
|
|
8268
|
+
if (parent.tag === "label") {
|
|
8269
|
+
return getLabelNodeText(parent);
|
|
8270
|
+
}
|
|
8271
|
+
parent = hierarchyMap2.get(parent) || null;
|
|
8272
|
+
}
|
|
8273
|
+
const id = getStaticAttributeContent(element, "id");
|
|
8274
|
+
if (!id) {
|
|
8275
|
+
return null;
|
|
8276
|
+
}
|
|
8277
|
+
const candidates = /* @__PURE__ */ new Set();
|
|
8278
|
+
for (const child of hierarchyMap2.keys()) {
|
|
8279
|
+
candidates.add(child);
|
|
8280
|
+
}
|
|
8281
|
+
for (const maybeParent of hierarchyMap2.values()) {
|
|
8282
|
+
if (maybeParent) {
|
|
8283
|
+
candidates.add(maybeParent);
|
|
8284
|
+
}
|
|
8285
|
+
}
|
|
8286
|
+
for (const candidate of candidates) {
|
|
8287
|
+
if (candidate.tag !== "label") {
|
|
8288
|
+
continue;
|
|
8289
|
+
}
|
|
8290
|
+
if (getStaticAttributeContent(candidate, "for") === id) {
|
|
8291
|
+
return getLabelNodeText(candidate);
|
|
8292
|
+
}
|
|
8293
|
+
}
|
|
8294
|
+
return null;
|
|
8295
|
+
}
|
|
7692
8296
|
function trimLeadingSeparators(value) {
|
|
7693
8297
|
if (!value) {
|
|
7694
8298
|
return "";
|
|
@@ -7741,11 +8345,11 @@ function tryExtractStableHintFromConditionalExpressionSource(source) {
|
|
|
7741
8345
|
return false;
|
|
7742
8346
|
const isUnderscore = (ch) => ch === 95;
|
|
7743
8347
|
const first = v.charCodeAt(0);
|
|
7744
|
-
if (!isAsciiLetterCode(first))
|
|
8348
|
+
if (!isAsciiLetterCode$1(first))
|
|
7745
8349
|
return false;
|
|
7746
8350
|
for (let i = 1; i < v.length; i += 1) {
|
|
7747
8351
|
const ch = v.charCodeAt(i);
|
|
7748
|
-
if (isAsciiLetterCode(ch) || isAsciiDigitCode(ch) || isUnderscore(ch)) {
|
|
8352
|
+
if (isAsciiLetterCode$1(ch) || isAsciiDigitCode$1(ch) || isUnderscore(ch)) {
|
|
7749
8353
|
continue;
|
|
7750
8354
|
}
|
|
7751
8355
|
return false;
|
|
@@ -7802,150 +8406,6 @@ function tryExtractStableHintFromConditionalExpressionSource(source) {
|
|
|
7802
8406
|
return null;
|
|
7803
8407
|
}
|
|
7804
8408
|
}
|
|
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
8409
|
function tryWrapClickDirectiveForTestEvents(element, testIdAttribute, resolvedRuntimeTestId) {
|
|
7950
8410
|
const jsStringLiteral = (value) => {
|
|
7951
8411
|
return JSON.stringify(value);
|
|
@@ -8090,7 +8550,7 @@ function tryWrapClickDirectiveForTestEvents(element, testIdAttribute, resolvedRu
|
|
|
8090
8550
|
}
|
|
8091
8551
|
let previousFileName = "";
|
|
8092
8552
|
const hierarchyMap = /* @__PURE__ */ new Map();
|
|
8093
|
-
function createTestIdTransform(componentName, componentHierarchyMap, nativeWrappers = {},
|
|
8553
|
+
function createTestIdTransform(componentName, componentHierarchyMap, nativeWrappers = {}, skipTestIdGenerationInsideComponents = [], viewsDirAbs, options = {}) {
|
|
8094
8554
|
const existingIdBehavior = options.existingIdBehavior ?? "error";
|
|
8095
8555
|
const testIdAttribute = (options.testIdAttribute || "data-testid").trim() || "data-testid";
|
|
8096
8556
|
const nameCollisionBehavior = options.nameCollisionBehavior ?? "error";
|
|
@@ -8101,6 +8561,21 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8101
8561
|
const annotatorMetadata = options.annotatorMetadata ?? null;
|
|
8102
8562
|
const crossFileKeyRegistry = options.crossFileKeyRegistry;
|
|
8103
8563
|
const optionKeyAttribute = options.optionKeyAttribute ?? {};
|
|
8564
|
+
const resolvedNativeWrappers = Object.fromEntries(
|
|
8565
|
+
Object.entries(nativeWrappers).map(([tag, config]) => [tag, { ...config }])
|
|
8566
|
+
);
|
|
8567
|
+
const wrapperContractByTag = /* @__PURE__ */ new Map();
|
|
8568
|
+
const getWrapperContract = (tag) => {
|
|
8569
|
+
if (!wrapperContractByTag.has(tag)) {
|
|
8570
|
+
wrapperContractByTag.set(tag, resolveWrapperContractForTag({
|
|
8571
|
+
tag,
|
|
8572
|
+
vueFilesPathMap,
|
|
8573
|
+
wrapperSearchRoots,
|
|
8574
|
+
testIdAttribute
|
|
8575
|
+
}));
|
|
8576
|
+
}
|
|
8577
|
+
return wrapperContractByTag.get(tag) ?? null;
|
|
8578
|
+
};
|
|
8104
8579
|
const safeRealpath2 = (p) => {
|
|
8105
8580
|
try {
|
|
8106
8581
|
return fs.existsSync(p) ? fs.realpathSync(p) : p;
|
|
@@ -8152,7 +8627,7 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8152
8627
|
}
|
|
8153
8628
|
};
|
|
8154
8629
|
return (node, context) => {
|
|
8155
|
-
if (
|
|
8630
|
+
if (skipTestIdGenerationInsideComponents.includes(componentName)) {
|
|
8156
8631
|
return;
|
|
8157
8632
|
}
|
|
8158
8633
|
if (node.type === compilerCore.NodeTypes.IF) {
|
|
@@ -8217,13 +8692,13 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8217
8692
|
}
|
|
8218
8693
|
return deps;
|
|
8219
8694
|
})();
|
|
8220
|
-
const
|
|
8695
|
+
const isComponentLikeTag2 = (tag) => {
|
|
8221
8696
|
if (!tag) return false;
|
|
8222
8697
|
const first = tag.charCodeAt(0);
|
|
8223
|
-
const isUpper = isAsciiUppercaseLetterCode(first);
|
|
8698
|
+
const isUpper = isAsciiUppercaseLetterCode$1(first);
|
|
8224
8699
|
return isUpper || tag.includes("-");
|
|
8225
8700
|
};
|
|
8226
|
-
if (
|
|
8701
|
+
if (isComponentLikeTag2(element.tag)) {
|
|
8227
8702
|
dependencies.usedComponentSet.add(element.tag);
|
|
8228
8703
|
if (crossFileKeyRegistry && context.scopes.vSlot > 0) {
|
|
8229
8704
|
const findSlotTemplate = () => {
|
|
@@ -8251,31 +8726,38 @@ function createTestIdTransform(componentName, componentHierarchyMap, nativeWrapp
|
|
|
8251
8726
|
}
|
|
8252
8727
|
}
|
|
8253
8728
|
}
|
|
8254
|
-
const
|
|
8729
|
+
const ownWrapperContract = getWrapperContract(componentName);
|
|
8730
|
+
const elementStartOffset = element.loc.start.offset;
|
|
8731
|
+
const isExplicitFallthroughTarget = ownWrapperContract?.explicitlyForwardedTestIdTargetOffsets.has(elementStartOffset) || ownWrapperContract?.explicitlyForwardedTestIdTargetSfcOffsets.has(elementStartOffset);
|
|
8732
|
+
if (!dependencies.isView && isExplicitFallthroughTarget) {
|
|
8733
|
+
return;
|
|
8734
|
+
}
|
|
8735
|
+
const existingWrapperConfig = resolvedNativeWrappers[element.tag];
|
|
8255
8736
|
if (!existingWrapperConfig) {
|
|
8256
|
-
const
|
|
8257
|
-
if (
|
|
8258
|
-
|
|
8259
|
-
} else if (element.tag.endsWith("Button") && !
|
|
8260
|
-
|
|
8737
|
+
const contract = getWrapperContract(element.tag);
|
|
8738
|
+
if (contract?.role) {
|
|
8739
|
+
resolvedNativeWrappers[element.tag] = { role: contract.role, inferred: true };
|
|
8740
|
+
} else if (element.tag.endsWith("Button") && !resolveSfcPathForTag(element.tag, vueFilesPathMap, wrapperSearchRoots)) {
|
|
8741
|
+
resolvedNativeWrappers[element.tag] = { role: "button" };
|
|
8261
8742
|
} else if (element.tag === "DxDataGrid") {
|
|
8262
|
-
|
|
8743
|
+
resolvedNativeWrappers[element.tag] = { role: "grid" };
|
|
8263
8744
|
}
|
|
8264
8745
|
} else if (!existingWrapperConfig.role) {
|
|
8265
|
-
const
|
|
8266
|
-
if (!
|
|
8746
|
+
const contract = getWrapperContract(element.tag);
|
|
8747
|
+
if (!contract?.role) {
|
|
8267
8748
|
const loc = element.loc?.start;
|
|
8268
8749
|
const locationHint = loc ? `${loc.line}:${loc.column}` : "unknown";
|
|
8750
|
+
const targetRoles = contract?.targetRoles.length ? contract.targetRoles.map((role) => role ?? "non-interactive").join(", ") : "no forwarded test-id target";
|
|
8269
8751
|
throw new Error(
|
|
8270
8752
|
`[vue-pom-generator] Could not infer a native role for declared wrapper <${element.tag}> in ${componentName} (${context.filename ?? "unknown"}:${locationHint}).
|
|
8271
|
-
|
|
8753
|
+
Resolved fallthrough targets: ${targetRoles}. The generator requires one stable role across every target.
|
|
8272
8754
|
|
|
8273
8755
|
Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role: "button", ... } }).`
|
|
8274
8756
|
);
|
|
8275
8757
|
}
|
|
8276
|
-
|
|
8758
|
+
resolvedNativeWrappers[element.tag] = {
|
|
8277
8759
|
...existingWrapperConfig,
|
|
8278
|
-
role:
|
|
8760
|
+
role: contract.role
|
|
8279
8761
|
};
|
|
8280
8762
|
}
|
|
8281
8763
|
const getBestAvailableKeyInfo = () => {
|
|
@@ -8385,7 +8867,7 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
|
|
|
8385
8867
|
}
|
|
8386
8868
|
let cachedTagSuffix = null;
|
|
8387
8869
|
const getTagSuffix = () => {
|
|
8388
|
-
cachedTagSuffix ??= formatTagName(element,
|
|
8870
|
+
cachedTagSuffix ??= formatTagName(element, resolvedNativeWrappers);
|
|
8389
8871
|
return cachedTagSuffix;
|
|
8390
8872
|
};
|
|
8391
8873
|
const getNativeRoleFromTagSuffix = () => getTagSuffix().slice(1);
|
|
@@ -8432,12 +8914,12 @@ Fix: set \`role\` explicitly in nativeWrappers (e.g. { "${element.tag}": { role:
|
|
|
8432
8914
|
annotatorMetadata
|
|
8433
8915
|
});
|
|
8434
8916
|
};
|
|
8435
|
-
const { nativeWrappersValue, optionDataTestIdPrefixValue, semanticNameHint } = getNativeWrapperTransformInfo(element, componentName,
|
|
8917
|
+
const { nativeWrappersValue, optionDataTestIdPrefixValue, semanticNameHint } = getNativeWrapperTransformInfo(element, componentName, resolvedNativeWrappers);
|
|
8436
8918
|
const handlerDirective = element.props.find((p) => {
|
|
8437
8919
|
return p.type === compilerCore.NodeTypes.DIRECTIVE && p.name === "bind" && p.arg?.type === compilerCore.NodeTypes.SIMPLE_EXPRESSION && p.arg.content === "handler" && !!p.exp;
|
|
8438
8920
|
}) ?? null;
|
|
8439
8921
|
const handlerInfo = handlerDirective ? nodeHandlerAttributeInfo(element) : null;
|
|
8440
|
-
if (
|
|
8922
|
+
if (resolvedNativeWrappers[element.tag]?.role === "button" && handlerDirective && !handlerInfo) {
|
|
8441
8923
|
const loc = element.loc?.start;
|
|
8442
8924
|
const locationHint = loc ? `${loc.line}:${loc.column}` : "unknown";
|
|
8443
8925
|
const handlerSource = (handlerDirective.exp?.loc?.source ?? "").trim() || "<unknown>";
|
|
@@ -8468,7 +8950,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8468
8950
|
}
|
|
8469
8951
|
upsertAttribute(element, "option-data-testid-prefix", optionDataTestIdPrefixValue);
|
|
8470
8952
|
}
|
|
8471
|
-
const nativeRole =
|
|
8953
|
+
const nativeRole = resolvedNativeWrappers[element.tag]?.role ?? element.tag;
|
|
8472
8954
|
const wrapperHintCandidates = [
|
|
8473
8955
|
semanticNameHint,
|
|
8474
8956
|
getStaticAttributeContent(element, "title"),
|
|
@@ -8538,7 +9020,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8538
9020
|
const innerText = getInnerText(element) || null;
|
|
8539
9021
|
const toDirective = nodeHasToDirective(element);
|
|
8540
9022
|
if (toDirective) {
|
|
8541
|
-
const dataTestId = generateToDirectiveDataTestId(componentName, element, toDirective, context, hierarchyMap,
|
|
9023
|
+
const dataTestId = generateToDirectiveDataTestId(componentName, element, toDirective, context, hierarchyMap, resolvedNativeWrappers);
|
|
8542
9024
|
const target = tryResolveToDirectiveTargetComponentName(toDirective);
|
|
8543
9025
|
const routeNameHint = toDirectiveObjectFieldNameValue(toDirective);
|
|
8544
9026
|
const existing = tryGetExistingElementDataTestId(element, testIdAttribute);
|
|
@@ -8559,7 +9041,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8559
9041
|
});
|
|
8560
9042
|
return;
|
|
8561
9043
|
}
|
|
8562
|
-
if (handlerInfo &&
|
|
9044
|
+
if (handlerInfo && resolvedNativeWrappers[element.tag]) {
|
|
8563
9045
|
const testId = getHandlerAttributeValueDataTestId(handlerInfo.semanticNameHint);
|
|
8564
9046
|
applyResolvedDataTestIdForElement({
|
|
8565
9047
|
preferredGeneratedValue: testId,
|
|
@@ -8568,6 +9050,15 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8568
9050
|
});
|
|
8569
9051
|
return;
|
|
8570
9052
|
}
|
|
9053
|
+
const inferredWrapperRole = resolvedNativeWrappers[element.tag]?.inferred ? resolvedNativeWrappers[element.tag]?.role : null;
|
|
9054
|
+
if (inferredWrapperRole && innerText) {
|
|
9055
|
+
applyResolvedDataTestIdForElement({
|
|
9056
|
+
preferredGeneratedValue: staticAttributeValue(`${componentName}-${innerText}-${inferredWrapperRole}`),
|
|
9057
|
+
nativeRoleOverride: inferredWrapperRole,
|
|
9058
|
+
semanticNameHint: innerText
|
|
9059
|
+
});
|
|
9060
|
+
return;
|
|
9061
|
+
}
|
|
8571
9062
|
const existingElementDataTestId = tryGetExistingElementDataTestId(element, testIdAttribute);
|
|
8572
9063
|
const shouldPreserveExisting = existingElementDataTestId && existingIdBehavior === "preserve";
|
|
8573
9064
|
const clickDirective = tryGetClickDirective(element);
|
|
@@ -8594,7 +9085,7 @@ Fix: remove the explicit ${attrLabel}, or change existingIdBehavior to "overwrit
|
|
|
8594
9085
|
}
|
|
8595
9086
|
if (existingElementDataTestId) {
|
|
8596
9087
|
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" ||
|
|
9088
|
+
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
9089
|
if (!isRecognizedInteractiveRole) {
|
|
8599
9090
|
return;
|
|
8600
9091
|
}
|
|
@@ -8817,7 +9308,7 @@ function createVuePluginWithTestIds(options) {
|
|
|
8817
9308
|
componentHierarchyMap,
|
|
8818
9309
|
crossFileKeyRegistry,
|
|
8819
9310
|
vueFilesPathMap,
|
|
8820
|
-
|
|
9311
|
+
skipTestIdGenerationInsideComponents,
|
|
8821
9312
|
getViewsDirAbs,
|
|
8822
9313
|
testIdAttribute,
|
|
8823
9314
|
accessibilityAudit,
|
|
@@ -8875,7 +9366,7 @@ function createVuePluginWithTestIds(options) {
|
|
|
8875
9366
|
componentName,
|
|
8876
9367
|
componentHierarchyMap,
|
|
8877
9368
|
nativeWrappers,
|
|
8878
|
-
|
|
9369
|
+
skipTestIdGenerationInsideComponents,
|
|
8879
9370
|
viewsDirAbs,
|
|
8880
9371
|
{
|
|
8881
9372
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -8933,7 +9424,7 @@ function createVuePluginWithTestIds(options) {
|
|
|
8933
9424
|
componentName,
|
|
8934
9425
|
componentHierarchyMap,
|
|
8935
9426
|
nativeWrappers,
|
|
8936
|
-
|
|
9427
|
+
skipTestIdGenerationInsideComponents,
|
|
8937
9428
|
viewsDirAbs,
|
|
8938
9429
|
{
|
|
8939
9430
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -9093,7 +9584,7 @@ function createBuildProcessorPlugin(options) {
|
|
|
9093
9584
|
projectRootRef,
|
|
9094
9585
|
nativeWrappers,
|
|
9095
9586
|
optionKeyAttribute,
|
|
9096
|
-
|
|
9587
|
+
skipTestIdGenerationInsideComponents,
|
|
9097
9588
|
getWrapperSearchRoots,
|
|
9098
9589
|
getResolvedRouterEntry,
|
|
9099
9590
|
loggerRef
|
|
@@ -9215,7 +9706,7 @@ function createBuildProcessorPlugin(options) {
|
|
|
9215
9706
|
componentName,
|
|
9216
9707
|
componentHierarchyMap,
|
|
9217
9708
|
nativeWrappers,
|
|
9218
|
-
|
|
9709
|
+
skipTestIdGenerationInsideComponents,
|
|
9219
9710
|
getViewsDirAbs(),
|
|
9220
9711
|
{
|
|
9221
9712
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -9348,7 +9839,7 @@ function createDevProcessorPlugin(options) {
|
|
|
9348
9839
|
elementMetadata,
|
|
9349
9840
|
nativeWrappers,
|
|
9350
9841
|
optionKeyAttribute,
|
|
9351
|
-
|
|
9842
|
+
skipTestIdGenerationInsideComponents,
|
|
9352
9843
|
getPageDirs,
|
|
9353
9844
|
getComponentDirs,
|
|
9354
9845
|
getLayoutDirs,
|
|
@@ -9571,7 +10062,7 @@ function createDevProcessorPlugin(options) {
|
|
|
9571
10062
|
componentName,
|
|
9572
10063
|
provisionalHierarchy,
|
|
9573
10064
|
nativeWrappers,
|
|
9574
|
-
|
|
10065
|
+
skipTestIdGenerationInsideComponents,
|
|
9575
10066
|
getViewsDirAbs(),
|
|
9576
10067
|
{
|
|
9577
10068
|
existingIdBehavior: resolveExistingIdBehavior(existingIdBehavior, componentName),
|
|
@@ -9917,7 +10408,7 @@ function createInternalPlugins(options) {
|
|
|
9917
10408
|
vueFilesPathMap,
|
|
9918
10409
|
nativeWrappers,
|
|
9919
10410
|
optionKeyAttribute,
|
|
9920
|
-
|
|
10411
|
+
skipTestIdGenerationInsideComponents,
|
|
9921
10412
|
getPageDirs,
|
|
9922
10413
|
getComponentDirs,
|
|
9923
10414
|
getLayoutDirs,
|
|
@@ -9969,7 +10460,7 @@ function createInternalPlugins(options) {
|
|
|
9969
10460
|
projectRootRef,
|
|
9970
10461
|
nativeWrappers,
|
|
9971
10462
|
optionKeyAttribute,
|
|
9972
|
-
|
|
10463
|
+
skipTestIdGenerationInsideComponents,
|
|
9973
10464
|
getWrapperSearchRoots,
|
|
9974
10465
|
getResolvedRouterEntry: resolveRouterEntry2,
|
|
9975
10466
|
loggerRef
|
|
@@ -9978,7 +10469,7 @@ function createInternalPlugins(options) {
|
|
|
9978
10469
|
elementMetadata,
|
|
9979
10470
|
nativeWrappers,
|
|
9980
10471
|
optionKeyAttribute,
|
|
9981
|
-
|
|
10472
|
+
skipTestIdGenerationInsideComponents,
|
|
9982
10473
|
getPageDirs,
|
|
9983
10474
|
getComponentDirs,
|
|
9984
10475
|
getLayoutDirs,
|
|
@@ -10233,7 +10724,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10233
10724
|
wrapperSearchRoots: injection.wrapperSearchRoots,
|
|
10234
10725
|
nativeWrappers: injection.nativeWrappers,
|
|
10235
10726
|
optionKeyAttribute: injection.optionKeyAttribute,
|
|
10236
|
-
|
|
10727
|
+
skipTestIdGenerationInsideComponents: injection.skipTestIdGenerationInsideComponents,
|
|
10237
10728
|
existingIdBehavior: injection.existingIdBehavior,
|
|
10238
10729
|
testIdAttribute: injection.attribute
|
|
10239
10730
|
})
|
|
@@ -10241,7 +10732,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10241
10732
|
const resolvedInjectionOptions = resolvedInjectionOptionsRef.current;
|
|
10242
10733
|
const nativeWrappers = resolvedInjectionOptions.nativeWrappers;
|
|
10243
10734
|
const optionKeyAttribute = resolvedInjectionOptions.optionKeyAttribute;
|
|
10244
|
-
const
|
|
10735
|
+
const skipTestIdGenerationInsideComponents = resolvedInjectionOptions.skipTestIdGenerationInsideComponents;
|
|
10245
10736
|
const testIdAttribute = resolvedInjectionOptions.testIdAttribute;
|
|
10246
10737
|
const routerEntry = !isNuxt ? vueGenerationOptions?.router?.entry : void 0;
|
|
10247
10738
|
const routerType = isNuxt ? "nuxt" : vueGenerationOptions?.router?.type ?? "vue-router";
|
|
@@ -10355,7 +10846,10 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10355
10846
|
}
|
|
10356
10847
|
};
|
|
10357
10848
|
const getViewsDirAbs = () => resolveFromProjectRoot(projectRootRef.current, getViewsDir());
|
|
10358
|
-
const getWrapperSearchRootsAbs = () =>
|
|
10849
|
+
const getWrapperSearchRootsAbs = () => Array.from(new Set([
|
|
10850
|
+
...getSourceDirs(),
|
|
10851
|
+
...getWrapperSearchRoots()
|
|
10852
|
+
].map((root) => resolveFromProjectRoot(projectRootRef.current, root))));
|
|
10359
10853
|
const { elementMetadata, semanticNameMap, componentHierarchyMap, crossFileKeyRegistry, vueFilesPathMap } = sharedState;
|
|
10360
10854
|
const { metadataCollectorPlugin, internalVuePlugin, templateCompilerOptions } = createVuePluginWithTestIds({
|
|
10361
10855
|
vueOptions,
|
|
@@ -10369,7 +10863,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10369
10863
|
componentHierarchyMap,
|
|
10370
10864
|
crossFileKeyRegistry,
|
|
10371
10865
|
vueFilesPathMap,
|
|
10372
|
-
|
|
10866
|
+
skipTestIdGenerationInsideComponents,
|
|
10373
10867
|
getViewsDirAbs,
|
|
10374
10868
|
testIdAttribute,
|
|
10375
10869
|
accessibilityAudit: resolvedGenerationOptions.accessibilityAudit,
|
|
@@ -10390,7 +10884,7 @@ function createVuePomGeneratorPlugins(options = {}) {
|
|
|
10390
10884
|
vueFilesPathMap,
|
|
10391
10885
|
nativeWrappers,
|
|
10392
10886
|
optionKeyAttribute,
|
|
10393
|
-
|
|
10887
|
+
skipTestIdGenerationInsideComponents,
|
|
10394
10888
|
getPageDirs,
|
|
10395
10889
|
getComponentDirs,
|
|
10396
10890
|
getLayoutDirs,
|