forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
30 lines (26 loc) · 842 Bytes
/
setup.js
File metadata and controls
30 lines (26 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { getFlattenedTree, getSelectorData } from '../utils';
import { setupGlobals } from './run/globals-setup';
/**
* Setup axe-core so axe.common functions can work properly.
* @param {Node} [node=document.documentElement] optional node. NOTE: passing in anything other than body or the documentElement may result in incomplete results.
*/
function setup(node) {
if (axe._tree) {
throw new Error(
'Axe is already setup. Call `axe.teardown()` before calling `axe.setup` again.'
);
}
// Normalize document
if (
node &&
typeof node.documentElement === 'object' &&
typeof node.defaultView === 'object'
) {
node = node.documentElement;
}
setupGlobals(node);
axe._tree = getFlattenedTree(node);
axe._selectorData = getSelectorData(axe._tree);
return axe._tree[0];
}
export default setup;