all files / liquidjs/tags/ increment.js

100% Statements 12/12
100% Branches 2/2
100% Functions 3/3
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19   131×              
const Liquid = require('..')
const assert = require('../src/util/assert.js')
const lexical = Liquid.lexical
 
module.exports = function (liquid) {
  liquid.registerTag('increment', {
    parse: function (token) {
      var match = token.args.match(lexical.identifier)
      assert(match, `illegal identifier ${token.args}`)
      this.variable = match[0]
    },
    render: function (scope, hash) {
      var v = scope.get(this.variable)
      if (typeof v !== 'number') v = 0
      scope.set(this.variable, v + 1)
    }
  })
}