/* eslint-env node */
var 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) {
  var b = this.syntax.builders;
  var traverse = this.syntax.traverse;

  traverse(ast, {
    MustacheStatement: function(node) {
      var testSelectorParams = [];
      var otherParams = [];

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

      node.params = otherParams;

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

  return ast;
};

module.exports = TransformTestSelectorParamsToHashPairs;

/* eslint-env node */
var 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) {
  var b = this.syntax.builders;
  var walker = new this.syntax.Walker();

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

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

      node.params = otherParams;

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

  return ast;
};

module.exports = TransformTestSelectorParamsToHashPairs;

Use "Walker" class instead of traverse()
Use "Walker" class instead of traverse()

for Ember 1.13 compat
