From 328d0925b132bd9ca2307a895467be1c29593d64 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Mon, 24 May 2021 23:54:23 -0700 Subject: [PATCH] Resolve class based transform deprecation ember-source 3.27+: Using class based template compilation plugins is deprecated, please update to the functional style --- ...form-test-selector-params-to-hash-pairs.js | 59 +++++++++---------- 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/transform-test-selector-params-to-hash-pairs.js b/transform-test-selector-params-to-hash-pairs.js index 9d9d3ae6..80b881e9 100644 --- a/transform-test-selector-params-to-hash-pairs.js +++ b/transform-test-selector-params-to-hash-pairs.js @@ -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;