velocityjs
Advanced tools
Comparing version 0.3.4 to 0.3.5
{ | ||
"name": "velocityjs", | ||
"description": "Velocity Template Language(VTL) for JavaScript", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "velocity template" |
@@ -126,2 +126,4 @@ module.exports = function(Velocity, utils, BLOCK_TYPES){ | ||
utils.forEach(ast.args, this.getReferences, this); | ||
var guid = utils.guid(); | ||
@@ -132,3 +134,3 @@ var contextId = 'macro:' + guid; | ||
variable: this._getArgus(macro.args), | ||
maps: ast.args, | ||
maps: ast.args || [], | ||
context: {} | ||
@@ -135,0 +137,0 @@ }; |
@@ -59,2 +59,3 @@ var Parser = require('../../parse/index'); | ||
setRef: function(ast, text, isMaps){ | ||
var paths = getPath(ast); | ||
@@ -61,0 +62,0 @@ var last = paths.pop(); |
@@ -106,20 +106,33 @@ module.exports = function(Velocity, utils){ | ||
var fns = this.fns.context; | ||
var isNoPass = true; | ||
fns = fns[ast.id]; | ||
var fn = null; | ||
if (fns) { | ||
utils.each(ast.path, function(a){ | ||
if (typeof fns[a.id] === 'function') { | ||
var args = null; | ||
var fn; | ||
utils.forEach(ast.path, function(a){ | ||
if (typeof fn !== 'function') { | ||
fn = fns[a.id]; | ||
} else { | ||
return; | ||
} | ||
fn = fns[a.id]; | ||
var _arg = []; | ||
utils.forEach(args, function(arg){ | ||
_arg.push(arg.value); | ||
}); | ||
return !fn; | ||
}, this); | ||
if (a.type === 'method') { | ||
if (typeof fn === 'function') { | ||
args = a.args; | ||
isNoPass = false; | ||
} | ||
} else { | ||
fns = fns[a.id]; | ||
} | ||
fn.apply(this, _arg); | ||
}); | ||
var _arg = []; | ||
utils.forEach(args, function(arg){ | ||
_arg.push(arg.value); | ||
}); | ||
fn && fn.apply && fn.apply(this, _arg); | ||
} | ||
@@ -132,2 +145,4 @@ | ||
if (ast.type !== 'references') return; | ||
if (this.isFn(ast)) { | ||
@@ -165,2 +180,5 @@ | ||
ret['real'] = ret.maps? ret.maps[index]: ref; | ||
if (ret['real'] && ret['real'].type !== 'references') { | ||
ret['real'] = undefined; | ||
} | ||
return true; | ||
@@ -171,4 +189,6 @@ } | ||
if (ret.type === 'macro' && ret.real) { | ||
//递归查找上层 | ||
if (ret.type === 'macro' && ret.real && !this.context[ref.id]) { | ||
// see: https://github.com/shepherdwind/velocity.js/issues/13 | ||
// 最后一个判断,防止死循环 | ||
// 递归查找上层 | ||
var _local = this.getLocal(ret.real); | ||
@@ -175,0 +195,0 @@ if (_local.isGlobal === false && _local.real) { |
404579
3428