Skip to content

Commit

Permalink
Resolve class based transform deprecation
Browse files Browse the repository at this point in the history
ember-source 3.27+: Using class based template compilation plugins is deprecated, please update to the functional style
  • Loading branch information
chancancode authored May 25, 2021
1 parent ff03808 commit 5909a52
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 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();

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

let testSelectorParams = [];
let otherParams = [];

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

node.params = otherParams;

testSelectorParams.forEach(function(param) {
let pair = b.pair(param.original, b.boolean(true));
node.hash.pairs.push(pair);
});
module.exports = function(env) {
let b = env.syntax.builders;
let transform = (node) => {
if ('sexpr' in node) {
node = node.sexpr;
}
});

return ast;
};
let testSelectorParams = [];
let otherParams = [];

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

node.params = otherParams;

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

return {
name: 'TransformTestSelectorParamsToHashPairs',

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

0 comments on commit 5909a52

Please sign in to comment.