Skip to content

Commit

Permalink
Extract stripTestSelectors() function
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed May 6, 2021
1 parent 9510095 commit e5a93fa
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions strip-test-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ function isTestSelector(attribute) {
return TEST_SELECTOR_PREFIX.test(attribute);
}

function stripTestSelectors(node) {
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);
});
}

function StripTestSelectorsTransform() {
this.syntax = null;
}
Expand All @@ -21,17 +35,7 @@ StripTestSelectorsTransform.prototype.transform = function(ast) {
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);
});
stripTestSelectors(node);
}
});

Expand Down

0 comments on commit e5a93fa

Please sign in to comment.