|
1 | 1 | import constants from '../../constants'; |
| 2 | +import { nodeSerializer } from '../../utils'; |
2 | 3 |
|
3 | 4 | const resultKeys = constants.resultGroups; |
4 | 5 |
|
@@ -43,19 +44,8 @@ export default function processAggregate(results, options) { |
43 | 44 | if (Array.isArray(ruleResult.nodes) && ruleResult.nodes.length > 0) { |
44 | 45 | ruleResult.nodes = ruleResult.nodes.map(subResult => { |
45 | 46 | if (typeof subResult.node === 'object') { |
46 | | - subResult.html = subResult.node.source; |
47 | | - if (options.elementRef && !subResult.node.fromFrame) { |
48 | | - subResult.element = subResult.node.element; |
49 | | - } |
50 | | - if (options.selectors !== false || subResult.node.fromFrame) { |
51 | | - subResult.target = subResult.node.selector; |
52 | | - } |
53 | | - if (options.ancestry) { |
54 | | - subResult.ancestry = subResult.node.ancestry; |
55 | | - } |
56 | | - if (options.xpath) { |
57 | | - subResult.xpath = subResult.node.xpath; |
58 | | - } |
| 47 | + const serialElm = trimElementSpec(subResult.node, options); |
| 48 | + Object.assign(subResult, serialElm); |
59 | 49 | } |
60 | 50 | delete subResult.result; |
61 | 51 | delete subResult.node; |
@@ -86,23 +76,32 @@ function normalizeRelatedNodes(node, options) { |
86 | 76 | .filter(checkRes => Array.isArray(checkRes.relatedNodes)) |
87 | 77 | .forEach(checkRes => { |
88 | 78 | checkRes.relatedNodes = checkRes.relatedNodes.map(relatedNode => { |
89 | | - const res = { |
90 | | - html: relatedNode?.source ?? 'Undefined' |
91 | | - }; |
92 | | - if (options.elementRef && !relatedNode?.fromFrame) { |
93 | | - res.element = relatedNode?.element ?? null; |
94 | | - } |
95 | | - if (options.selectors !== false || relatedNode?.fromFrame) { |
96 | | - res.target = relatedNode?.selector ?? [':root']; |
97 | | - } |
98 | | - if (options.ancestry) { |
99 | | - res.ancestry = relatedNode?.ancestry ?? [':root']; |
100 | | - } |
101 | | - if (options.xpath) { |
102 | | - res.xpath = relatedNode?.xpath ?? ['/']; |
103 | | - } |
104 | | - return res; |
| 79 | + return trimElementSpec(relatedNode, options); |
105 | 80 | }); |
106 | 81 | }); |
107 | 82 | }); |
108 | 83 | } |
| 84 | + |
| 85 | +function trimElementSpec(elmSpec = {}, runOptions) { |
| 86 | + // Pass options to limit which properties are calculated |
| 87 | + elmSpec = nodeSerializer.dqElmToSpec(elmSpec, runOptions); |
| 88 | + const serialElm = {}; |
| 89 | + if (axe._audit.noHtml) { |
| 90 | + serialElm.html = null; |
| 91 | + } else { |
| 92 | + serialElm.html = elmSpec.source ?? 'Undefined'; |
| 93 | + } |
| 94 | + if (runOptions.elementRef && !elmSpec.fromFrame) { |
| 95 | + serialElm.element = elmSpec.element ?? null; |
| 96 | + } |
| 97 | + if (runOptions.selectors !== false || elmSpec.fromFrame) { |
| 98 | + serialElm.target = elmSpec.selector ?? [':root']; |
| 99 | + } |
| 100 | + if (runOptions.ancestry) { |
| 101 | + serialElm.ancestry = elmSpec.ancestry ?? [':root']; |
| 102 | + } |
| 103 | + if (runOptions.xpath) { |
| 104 | + serialElm.xpath = elmSpec.xpath ?? ['/']; |
| 105 | + } |
| 106 | + return serialElm; |
| 107 | +} |
0 commit comments