Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve class based transform deprecation #720

Merged
merged 1 commit into from
May 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;