mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
Size can also be used with dot notation (#25)
* Size can also be used with dot notation (for example, {{ my_string.size }}).
* Fixed test failed.
* Optimization
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
const _ = require('./util/underscore.js');
|
||||
const lexical = require('./lexical.js');
|
||||
const assert = require('./util/assert.js');
|
||||
const toStr = Object.prototype.toString;
|
||||
|
||||
var Scope = {
|
||||
getAll: function() {
|
||||
@@ -75,7 +76,16 @@ var Scope = {
|
||||
throw new TypeError('undefined variable');
|
||||
}
|
||||
var variable = obj[varName];
|
||||
var lastName = paths.pop();
|
||||
paths.forEach(p => variable = variable[p]);
|
||||
if (undefined !== lastName) {
|
||||
if (lastName === 'size' &&
|
||||
(toStr.call(variable) === '[object Array]'
|
||||
|| toStr.call(variable) === '[object String]')) {
|
||||
return variable.length;
|
||||
}
|
||||
variable = variable[lastName]
|
||||
}
|
||||
return variable;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user