Skip to content

Commit

Permalink
Merge pull request #720 from chancancode/patch-1
Browse files Browse the repository at this point in the history
Resolve class based transform deprecation
  • Loading branch information
Turbo87 authored May 25, 2021
2 parents 220626c + 328d092 commit 91a582e
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions transform-test-selector-params-to-hash-pairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,43 @@

let TEST_SELECTOR_PREFIX = /data-test-.*/;

function TransformTestSelectorParamsToHashPairs() {
this.syntax = null;
}

function isTestSelectorParam(param) {
return param.type === 'PathExpression'
&& TEST_SELECTOR_PREFIX.test(param.original);
}

TransformTestSelectorParamsToHashPairs.prototype.transform = function(ast) {
let b = this.syntax.builders;
let walker = new this.syntax.Walker();
module.exports = function(env) {
let b = env.syntax.builders;
let transform = (node) => {
if ('sexpr' in node) {
node = node.sexpr;
}

walker.visit(ast, function(node) {
if (node.type === 'MustacheStatement' || node.type === 'BlockStatement') {
if ('sexpr' in node) {
node = node.sexpr;
}
let testSelectorParams = [];
let otherParams = [];

let testSelectorParams = [];
let otherParams = [];
node.params.forEach(function(param) {
if (isTestSelectorParam(param)) {
testSelectorParams.push(param);
} else {
otherParams.push(param);
}
});

node.params.forEach(function(param) {
if (isTestSelectorParam(param)) {
testSelectorParams.push(param);
} else {
otherParams.push(param);
}
});
node.params = otherParams;

node.params = otherParams;
testSelectorParams.forEach(function(param) {
let pair = b.pair(param.original, b.boolean(true));
node.hash.pairs.push(pair);
});
};

testSelectorParams.forEach(function(param) {
let pair = b.pair(param.original, b.boolean(true));
node.hash.pairs.push(pair);
});
}
});
return {
name: 'TransformTestSelectorParamsToHashPairs',

return ast;
visitor: {
MustacheStatement: transform,
BlockStatement: transform,
},
};
};

module.exports = TransformTestSelectorParamsToHashPairs;

0 comments on commit 91a582e

Please sign in to comment.