This commit is contained in:
harttle
2017-08-03 13:56:09 +08:00
parent 31397a4862
commit 6f82b914cb
3 changed files with 46 additions and 37 deletions
+44 -34
View File
@@ -1006,46 +1006,52 @@ var Scope = {
propertyAccessSeq: function propertyAccessSeq(str) { propertyAccessSeq: function propertyAccessSeq(str) {
var seq = []; var seq = [];
var name = ''; var name = '';
for (var i = 0; i < str.length; i++) { var j;
if (str[i] === '[') { var i = 0;
seq.push(name); while (i < str.length) {
name = ''; switch (str[i]) {
case '[':
push();
var delemiter = str[i + 1]; var delemiter = str[i + 1];
if (delemiter !== "'" && delemiter !== '"') { if (/['"]/.test(delemiter)) {
// foo[bar.coo]
var j = matchRightBracket(str, i + 1);
assert(j !== -1, 'unbalanced []: ' + str);
name = str.slice(i + 1, j);
if (lexical.isInteger(name)) {
// foo[1]
seq.push(name);
} else {
// foo["bar"] // foo["bar"]
seq.push(this.get(name)); j = str.indexOf(delemiter, i + 2);
assert(j !== -1, 'unbalanced ' + delemiter + ': ' + str);
name = str.slice(i + 2, j);
push();
i = j + 2;
} else {
// foo[bar.coo]
j = matchRightBracket(str, i + 1);
assert(j !== -1, 'unbalanced []: ' + str);
name = str.slice(i + 1, j);
if (!lexical.isInteger(name)) {
// foo[bar] vs. foo[1]
name = this.get(name);
}
push();
i = j + 1;
} }
name = ''; break;
i = j; case '.':
} else { // foo.bar, foo[0].bar
// foo["bar"] push();
j = str.indexOf(delemiter, i + 2); i++;
assert(j !== -1, 'unbalanced ' + delemiter + ': ' + str); break;
name = str.slice(i + 2, j); default:
seq.push(name); // foo.bar
name = ''; name += str[i];
i = j + 2; i++;
}
} else if (str[i] === '.') {
// foo.bar
seq.push(name);
name = '';
} else {
// foo.bar
name += str[i];
} }
} }
if (name.length) seq.push(name); push();
return seq; return seq;
function push() {
if (name.length) seq.push(name);
name = '';
}
} }
}; };
@@ -1259,6 +1265,10 @@ function parse(html, filepath, options) {
token.name = match[1]; token.name = match[1];
token.args = match[2]; token.args = match[2];
// get last line indentation
var lineStart = (htmlFragment || '').split('\n');
token.indent = lineStart[lineStart.length - 1].length;
tokens.push(token); tokens.push(token);
} else { } else {
// output // output
+1 -2
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "liquidjs", "name": "liquidjs",
"version": "1.9.1", "version": "1.9.2",
"description": "A Liquid template engine for Node.js and browsers, with all shopify/liquid features.", "description": "A Liquid template engine for Node.js and browsers, with all shopify/liquid features.",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {