8
8
// ----------------------------------------------------------------------------
9
9
import { dom } from 'aria-query' ;
10
10
import { runVirtualRule } from 'axe-core' ;
11
- import { elementType } from 'jsx-ast-utils' ;
11
+ import { elementType , getLiteralPropValue , getProp } from 'jsx-ast-utils' ;
12
12
import { generateObjSchema } from '../util/schemas' ;
13
- import JSXVirtualNode from '../util/JSXVirtualNode' ;
14
13
15
14
const schema = generateObjSchema ( {
16
15
ignoreNonDOM : {
@@ -33,19 +32,24 @@ module.exports = {
33
32
// If true, then do not run rule.
34
33
const options = context . options [ 0 ] || { } ;
35
34
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 ) ;
38
37
if ( ignoreNonDOM && ! isDOMNode ) {
39
38
return ;
40
39
}
41
40
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 } ) ;
47
52
48
- const { violations } = runVirtualRule ( 'autocomplete-valid' , vNode ) ;
49
53
if ( violations . length === 0 ) {
50
54
return ;
51
55
}
0 commit comments