forked from mainmatter/ember-test-selectors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strip-test-selectors.js
41 lines (31 loc) · 1006 Bytes
/
strip-test-selectors.js
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
31
32
33
34
35
36
37
38
39
40
41
'use strict';
/* eslint-env node */
let TEST_SELECTOR_PREFIX = /data-test-.*/;
function isTestSelector(attribute) {
return TEST_SELECTOR_PREFIX.test(attribute);
}
function StripTestSelectorsTransform() {
this.syntax = null;
}
StripTestSelectorsTransform.prototype.transform = function(ast) {
let walker = new this.syntax.Walker();
walker.visit(ast, function(node) {
if (node.type === 'ElementNode') {
node.attributes = node.attributes.filter(function(attribute) {
return !isTestSelector(attribute.name);
});
} else if (node.type === 'MustacheStatement' || node.type === 'BlockStatement') {
if ('sexpr' in node) {
node = node.sexpr;
}
node.params = node.params.filter(function(param) {
return !isTestSelector(param.original);
});
node.hash.pairs = node.hash.pairs.filter(function(pair) {
return !isTestSelector(pair.key);
});
}
});
return ast;
};
module.exports = StripTestSelectorsTransform;