/*
Transform the AST with the supplied transform rules.
@param {Object} options Doctor options.
@param {AstNode} ast AST.
@param {function} cb Function to call when transformation is complete.
488273
function transform(options, ast, cb) {

  var transformObj = {
    options: options
  };

  function queueNodeWalk(node, cb) {
    if (options._walkQueue) {
      options._walkQueue.push(node);
    }
  }

  function eachNodeRule(node, rule) {
    if (rule.transform) {
      if (typeof rule.transform === 'function') {
        node._walk = queueNodeWalk;
        rule.transform(node, transformObj);
        delete node._walk;
      }
    }
  }

  var rules = u.toArray(options.transform || 'default');

  nast.walkWithRules(options, rules, 'transform', ast, eachNodeRule, cb);
}
161010
function transform(transformerCtx, options) {
    var html = options.template;
    for (var i = 0; i < transformers.length; i++) {
        html = transformers[i](html, transformerCtx, options);
    }
    return html;
}
43471
function(cb) {
        var timeout;
        this.chain(function(next) {
            function evaluate() {
                var ccb = cb.bind(api);
                var result = ccb();
                if (result) {
                    clearInterval(poll);
                    if (timeout !== undefined) clearTimeout(timeout);
                    next();
                }
            }
            var api = this;
            var poll = setInterval(evaluate, api._untilInterval || 30);
            // to set a timeout for condition to be met, set the _untilTimeout property to ms value
            if (api.untilTimeout) {
                timeout = setTimeout(function() {
                    if (poll !== undefined) {
                        clearInterval(poll);
                        // to catch timeout of until conditions, set onUntilTimeout handler
                        if (api.onUntilTimeout) api.onUntilTimeout(next);
                        // otherwise execution flow simply continues as if condition was met
                        else next();
                    }
                }, api.untilTimeout);
            }
        });
        return this;
    }
952940
function transformCss (cssText, transform) {
  let node = parseCss(cssText)

  if (typeof transform === 'function') {
    node = transformNode(node, transform)
  }

  return toCssText(node)
}
331750
function updateFormRules(cb) {

    //Filters out any conditional statements that are no longer valid.
    function filterConditionalStatements(rule) {
      return _.filter(rule.ruleConditionalStatements, function(ruleCondStatement) {
        var sourceField = ruleCondStatement.sourceField.toString();

        if (invalidFields[sourceField]) {
          /**
           * If the user flagged the field in this rule for deletion, flag the rule for deletion.
           */
          if (ruleDeletionFlags[sourceField]) {
            rulesFlaggedForDeletion[rule._id.toString()] = true;
          }
          return false;
        } else {
          return true;
        }
      });
    }

    var updatedFieldRules = _.map(form.fieldRules, function(fieldRule) {
      var filteredConditionalStatements = filterConditionalStatements(fieldRule);
      var filteredTargets = _.filter(fieldRule.targetField, function(targetField) {
        if (invalidFields[targetField]) {
          return false;
        } else {
          return true;
        }
      });

      fieldRule.ruleConditionalStatements = filteredConditionalStatements;
      fieldRule.targetField = filteredTargets;
      return fieldRule;
    });

    var updatedPageRules = _.map(form.pageRules, function(pageRule) {
      pageRule.ruleConditionalStatements = filterConditionalStatements(pageRule);
      return pageRule;
    });

    fieldRulesToDelete = _.filter(updatedFieldRules, function(fieldRule) {
      var targetFields = fieldRule.targetField;
      var conditionalStatements = fieldRule.ruleConditionalStatements;
      var fieldRuleId = fieldRule._id.toString();

      return targetFields.length === 0 || conditionalStatements.length === 0 || rulesFlaggedForDeletion[fieldRuleId];
    });

    pageRulesToDelete = _.filter(updatedPageRules, function(pageRule) {
      var conditionalStatements = pageRule.ruleConditionalStatements;
      var pageRuleId = pageRule._id.toString();

      return conditionalStatements.length === 0 || rulesFlaggedForDeletion[pageRuleId];
    });

    fieldRulesToDelete = _.map(fieldRulesToDelete, function(fieldRule) {
      return fieldRule._id.toString();
    });

    pageRulesToDelete = _.map(pageRulesToDelete, function(pageRule) {
      return pageRule._id.toString();
    });

    //Now have all the rules that need to be deleted, these rules need to be removed from the field and page rules
    updatedFieldRules = _.filter(updatedFieldRules, function(updatedFieldRule) {
      return fieldRulesToDelete.indexOf(updatedFieldRule._id.toString()) === -1;
    });


    updatedPageRules = _.filter(updatedPageRules, function(updatedPageRule) {
      return pageRulesToDelete.indexOf(updatedPageRule._id.toString()) === -1;
    });

    form.fieldRules = updatedFieldRules;
    form.pageRules = updatedPageRules;

    form.save(function(err) {
      return cb(err);
    });
  }
195313
function(model, settings, objs, options, cb) {
      var m;
      if (settings == null) {
        settings = {};
      }
      if (objs == null) {
        objs = {};
      }
      if (options == null) {
        options = {};
      }
      if (cb == null) {
        cb = function() {};
      }
      Hoek.assert(model, i18n.assertModuleRequired);
      if (_.isFunction(options)) {
        cb = options;
        options = {};
      }
      m = new model(objs);
      return m.save(function(err) {
        if (err) {
          return cb(err);
        }
        return cb(null, m, true);
      });
    }
219251
function(cb) {
        var method = cb ? 'on' : 'off';
        this[method]('change', function(model) {
          var newModel = this._updateModel(model);
          if(_.isFunction(cb)){
            cb.call(this, newModel);
          }
        }, this);
      }
461920
function CLIEngine(options) {

  /**
   * Stored options for this instance
   * @type {Object}
   */
  this.options = assign(Object.create(defaultOptions), options || {});

  // load in additional rules
  if (this.options.rulePaths) {
    this.options.rulePaths.forEach(function(rulesdir) {
      rules.load(rulesdir);
    });
  }
}
183662
public Node transform(AstNode node) {
        switch (node.getType()) {
          case Token.ARRAYCOMP:
              return transformArrayComp((ArrayComprehension)node);
          case Token.ARRAYLIT:
              return transformArrayLiteral((ArrayLiteral)node);
          case Token.BLOCK:
              return transformBlock(node);
          case Token.BREAK:
              return transformBreak((BreakStatement)node);
          case Token.CALL:
              return transformFunctionCall((FunctionCall)node);
          case Token.CONTINUE:
              return transformContinue((ContinueStatement)node);
          case Token.DO:
              return transformDoLoop((DoLoop)node);
          case Token.EMPTY:
              return node;
          case Token.FOR:
              if (node instanceof ForInLoop) {
                  return transformForInLoop((ForInLoop)node);
              }
              return transformForLoop((ForLoop)node);
          case Token.FUNCTION:
              return transformFunction((FunctionNode)node);
          case Token.GENEXPR:
              return transformGenExpr((GeneratorExpression)node);
          case Token.GETELEM:
              return transformElementGet((ElementGet)node);
          case Token.GETPROP:
              return transformPropertyGet((PropertyGet)node);
          case Token.HOOK:
              return transformCondExpr((ConditionalExpression)node);
          case Token.IF:
              return transformIf((IfStatement)node);

          case Token.TRUE:
          case Token.FALSE:
          case Token.THIS:
          case Token.NULL:
          case Token.DEBUGGER:
              return transformLiteral(node);

          case Token.NAME:
              return transformName((Name)node);
          case Token.NUMBER:
              return transformNumber((NumberLiteral)node);
          case Token.NEW:
              return transformNewExpr((NewExpression)node);
          case Token.OBJECTLIT:
              return transformObjectLiteral((ObjectLiteral)node);
          case Token.REGEXP:
              return transformRegExp((RegExpLiteral)node);
          case Token.RETURN:
              return transformReturn((ReturnStatement)node);
          case Token.SCRIPT:
              return transformScript((ScriptNode)node);
          case Token.STRING:
              return transformString((StringLiteral)node);
          case Token.SWITCH:
              return transformSwitch((SwitchStatement)node);
          case Token.THROW:
              return transformThrow((ThrowStatement)node);
          case Token.TRY:
              return transformTry((TryStatement)node);
          case Token.WHILE:
              return transformWhileLoop((WhileLoop)node);
          case Token.WITH:
              return transformWith((WithStatement)node);
          case Token.YIELD:
              return transformYield((Yield)node);
          default:
              if (node instanceof ExpressionStatement) {
                  return transformExprStmt((ExpressionStatement)node);
              }
              if (node instanceof Assignment) {
                  return transformAssignment((Assignment)node);
              }
              if (node instanceof UnaryExpression) {
                  return transformUnary((UnaryExpression)node);
              }
              if (node instanceof XmlMemberGet) {
                  return transformXmlMemberGet((XmlMemberGet)node);
              }
              if (node instanceof InfixExpression) {
                  return transformInfix((InfixExpression)node);
              }
              if (node instanceof VariableDeclaration) {
                  return transformVariables((VariableDeclaration)node);
              }
              if (node instanceof ParenthesizedExpression) {
                  return transformParenExpr((ParenthesizedExpression)node);
              }
              if (node instanceof LabeledStatement) {
                  return transformLabeledStatement((LabeledStatement)node);
              }
              if (node instanceof LetNode) {
                  return transformLetNode((LetNode)node);
              }
              if (node instanceof XmlRef) {
                  return transformXmlRef((XmlRef)node);
              }
              if (node instanceof XmlLiteral) {
                  return transformXmlLiteral((XmlLiteral)node);
              }
              throw new IllegalArgumentException("Can't transform: " + node);
        }
    }
1070282
function transform(chunk, encoding, cb) {
    // Allow objects straight through
    if (_.isPlainObject(chunk)) return cb(null, chunk);

    async.eachSeries(
      tokenize(chunk.toString('utf8')),
      (output, next) => transclude.call(this, output, next),
      err => {
        if (err) inputBuffer = '';
        cb(err);
      }
    );
  }
1203305
function createRules(rulesToCreate, cb) {

    function addRule(ruleToCreate, addRuleCallback) {
      var fr = new rulesModel(ruleToCreate);

      fr.save(function(err, frdoc) {
        if (err) {
          return addRuleCallback(err);
        }
        return addRuleCallback(null, frdoc);
      });
    }

    async.map(rulesToCreate, addRule, cb);
  }
319888
function wrap_cb(fn, P) {
  return function (params) {
    return new P(function (resolve, reject) {
      fn(params, function (err) { return !err ? resolve() : reject(err); });
    });
  };
}
1006578
function(model, id, settings, options, cb) {
      var defaultSelect, query;
      if (settings == null) {
        settings = {};
      }
      if (options == null) {
        options = {};
      }
      if (cb == null) {
        cb = function() {};
      }
      Hoek.assert(model, i18n.assertModuleRequired);
      Hoek.assert(id, i18n.assertIdRequired);
      defaultSelect = settings.defaultSelect || null;
      if (_.isFunction(options)) {
        cb = options;
        options = {};
      }
      options.select || (options.select = defaultSelect);
      query = model.findOne({
        _id: asObjectId(id)
      });
      if (options.select && options.select.length > 0) {
        query = query.select(options.select);
      }
      return query.exec(cb);
    }
586212
function(option) {

  // Swap alias and name around.
  if (option.name && option.alias && option.name.length > option.alias.length) {
    var name = option.alias;
    option.alias = option.name;
    option.name = name;
  }

  var defaults = {
    alias: null,
    kind: 'boolean'
  };
  var keys = Object.keys(option);
  _.each(defaults, function(val, key) {
    if (!_.contains(keys, key)) {
      option[key] = val;
    }
  });
}
58109
function replaceTeamPolicies (params, cb) {
      let promise = null
      if (typeof cb !== 'function') [promise, cb] = asyncify()

      const { id, organizationId, policies } = params
      const tasks = [
        (job, next) => {
          Joi.validate({ id, organizationId, policies }, validationRules.replaceTeamPolicies, (err) => {
            if (err) return next(Boom.badRequest(err))
            next()
          })
        },
        (job, next) => {
          job.teamId = id
          job.organizationId = organizationId
          job.policies = utils.preparePolicies(policies)
          next()
        },
        (job, next) => {
          utils.checkPoliciesOrg(job.client, job.policies, job.organizationId, next)
        },
        clearTeamPolicies,
        insertTeamPolicies
      ]

      db.withTransaction(tasks, (err, res) => {
        if (err) return cb(err)
        teamOps.readTeam({ id, organizationId }, cb)
      })

      return promise
    }
473389
function (id, options, cb) {
    if (arguments.length !== 3) {
      cb = options;
      options = {};
    }
    var self = this;
    var model = this.get(id);
    if (model){
      return cb(null, model);
    }
    function done() {
      var model = self.get(id);
      if (model) {
        if (cb){
          cb(null, model);
        }
      } else {
        cb(new Error('not found'));
      }
    }
    if (options.all) {
      this.fetch({
        callback: done
      });
    } else {
      this.fetchById(id, cb);
    }
  }
7643
function (name, cb) {
    var i, j, cbs=this._callbacks[name], jsTemp=[];

    /* I'm not sure if this is necessary; in C++, iterating over a
     * collection and modifying it at the same time is a no-no.
     */

    for (j in cbs) {
      if (cbs.hasOwnProperty(j) && cbs[j] === cb) {
        jsTemp.push(j);
      }
    }

    for (i=0; i<jsTemp.length; i++) {
      j = jsTemp[i];
      delete cbs[j];
    }
  }