Skip to content

Commit

Permalink
Merge pull request #700 from Turbo87/functional
Browse files Browse the repository at this point in the history
Convert class based template compilation plugin to functional style
  • Loading branch information
Turbo87 authored May 6, 2021
2 parents 9510095 + f999127 commit 21f06ae
Showing 1 changed file with 19 additions and 29 deletions.
48 changes: 19 additions & 29 deletions strip-test-selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,24 @@ 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);
});
module.exports = function() {
return {
name: 'strip-test-selectors',

visitor: {
ElementNode(node) {
node.attributes = node.attributes.filter(attribute => !isTestSelector(attribute.name));
},

MustacheStatement(node) {
node.params = node.params.filter(param => !isTestSelector(param.original));
node.hash.pairs = node.hash.pairs.filter(pair => !isTestSelector(pair.key));
},

BlockStatement(node) {
node.params = node.params.filter(param => !isTestSelector(param.original));
node.hash.pairs = node.hash.pairs.filter(pair => !isTestSelector(pair.key));
},
}
});

return ast;
};
};

module.exports = StripTestSelectorsTransform;

0 comments on commit 21f06ae

Please sign in to comment.