Skip to content

Commit 3519c7b

Browse files
committed
chore: Remove axe VirtualNode abstraction
1 parent 9ac55c4 commit 3519c7b

File tree

3 files changed

+14
-167
lines changed

3 files changed

+14
-167
lines changed

__tests__/src/util/JSXVirtualNode-test.js

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/rules/autocomplete-valid.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@
88
// ----------------------------------------------------------------------------
99
import { dom } from 'aria-query';
1010
import { runVirtualRule } from 'axe-core';
11-
import { elementType } from 'jsx-ast-utils';
11+
import { elementType, getLiteralPropValue, getProp } from 'jsx-ast-utils';
1212
import { generateObjSchema } from '../util/schemas';
13-
import JSXVirtualNode from '../util/JSXVirtualNode';
1413

1514
const schema = generateObjSchema({
1615
ignoreNonDOM: {
@@ -33,19 +32,24 @@ module.exports = {
3332
// If true, then do not run rule.
3433
const options = context.options[0] || {};
3534
const ignoreNonDOM = !!options.ignoreNonDOM;
36-
const nodeName = elementType(node);
37-
const isDOMNode = dom.get(nodeName);
35+
const elType = elementType(node);
36+
const isDOMNode = dom.get(elType);
3837
if (ignoreNonDOM && !isDOMNode) {
3938
return;
4039
}
4140

42-
// If not a DOM node, assume an input element
43-
const vNode = new JSXVirtualNode({
44-
props: { nodeName: isDOMNode ? nodeName : 'input' },
45-
attrs: node.attributes,
46-
});
41+
const attr = (attrName) => {
42+
const value = getLiteralPropValue(getProp(node.attributes, attrName));
43+
return (typeof value === 'string' ? value : null);
44+
};
45+
const props = {
46+
nodeName: isDOMNode ? elType : 'input',
47+
nodeType: 1,
48+
};
49+
const hasAttr = attrName => attr(attrName) !== null;
50+
51+
const { violations } = runVirtualRule('autocomplete-valid', { attr, props, hasAttr });
4752

48-
const { violations } = runVirtualRule('autocomplete-valid', vNode);
4953
if (violations.length === 0) {
5054
return;
5155
}

src/util/JSXVirtualNode.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)