Code coverage report for src/helper/jsonify/index.js

Statements: 27.08% (13 / 48)      Branches: 0% (0 / 21)      Functions: 0% (0 / 4)      Lines: 28.89% (13 / 45)      Ignored: none     

All files » src/helper/jsonify/ » index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 941 1   1       1 1   1                                                                                                                                                     1 1 1 1 1 1   1  
var utils = require('../../utils');
var Helper = require('../index');
 
function Jsonify(){
  this.init.apply(this, arguments);
}
 
var TRIM = /[\t\n\r]+/g;
var BLOCK_TYPES = ['if', 'foreach', 'macro', 'noescape'];
 
Jsonify.prototype = {
 
  constructor: Jsonify,
 
  init: function(asts, context, macros){
 
    this.fns = {
      context: context || {},
      macros: macros || {}
    };
 
    this.context = {};
    this.leafs   = [];
 
    this.asts       = asts;
    this.local      = {};
    this.macros     = {};
    this.conditions = [];
    this.cache      = {};
 
    this._render(this.asts);
  },
 
  getRefText: Helper.getRefText,
 
  _render: function(asts){
 
    var block = [];
    var index = 0;
 
    utils.forEach(asts, function(ast){
      var type = ast.type;
 
      //foreach if macro时,index加一
      if (BLOCK_TYPES.indexOf(type) > -1) index ++;
 
      if (type === 'comment') return;
 
      if (index) {
        type === 'end' && index--;
        if (index) {
          block.push(ast);
          return;
        }
      }
 
      switch(type) {
        case 'references':
        this.getReferences(ast);
        break;
 
        case 'set':
        break;
 
        case 'macro_call':
        this.getMacro(ast);
        break;
 
        case 'end':
        //使用slice获取block的拷贝
        this.getBlock(block.slice());
        block = [];
        break;
 
        default:
        if (utils.isArray(ast)) this.getBlock(ast);
        break;
 
      }
    }, this);
 
  }
 
};
 
require('./references')(Jsonify, utils);
require('./jsonify')(Jsonify, utils);
require('./block')(Jsonify, utils, BLOCK_TYPES);
require('../../compile/expression')(Jsonify, utils);
require('../../compile/literal')(Jsonify, utils);
require('../../compile/set')(Jsonify, utils);
 
module.exports = Jsonify;