This commit is contained in:
harttle
2017-04-24 21:31:56 +08:00
parent 2632e3e97e
commit ed20fe6072
3 changed files with 1138 additions and 1126 deletions
+79 -67
View File
@@ -508,9 +508,9 @@ module.exports = function (options) {
var match = lexical.filterLine.exec(str);
assert(match, 'illegal filter: ' + str);
var name = match[1],
argList = match[2] || '',
filter = filters[name];
var name = match[1];
var argList = match[2] || '';
var filter = filters[name];
if (typeof filter !== 'function') {
if (options.strict_filters) {
throw new TypeError('undefined filter: ' + name);
@@ -521,10 +521,6 @@ module.exports = function (options) {
};
this.args = [];
return this;
//return {
//name: name,
//error: new TypeError(`undefined filter: ${name}`)
//};
}
var args = [];
@@ -631,25 +627,48 @@ function matchValue(str) {
}
function parseLiteral(str) {
var res;
if (res = str.match(numberLine)) {
var res = str.match(numberLine);
if (res) {
return Number(str);
}
if (res = str.match(boolLine)) {
res = str.match(boolLine);
if (res) {
return str.toLowerCase() === 'true';
}
if (res = str.match(quotedLine)) {
res = str.match(quotedLine);
if (res) {
return str.slice(1, -1);
}
}
module.exports = {
quoted: quoted, number: number, bool: bool, literal: literal, filter: filter, integer: integer,
hash: hash, hashCapture: hashCapture,
range: range, rangeCapture: rangeCapture,
identifier: identifier, value: value, quoteBalanced: quoteBalanced, operators: operators,
quotedLine: quotedLine, numberLine: numberLine, boolLine: boolLine, rangeLine: rangeLine, literalLine: literalLine, filterLine: filterLine, tagLine: tagLine,
isLiteral: isLiteral, isVariable: isVariable, parseLiteral: parseLiteral, isRange: isRange, matchValue: matchValue, isInteger: isInteger
quoted: quoted,
number: number,
bool: bool,
literal: literal,
filter: filter,
integer: integer,
hash: hash,
hashCapture: hashCapture,
range: range,
rangeCapture: rangeCapture,
identifier: identifier,
value: value,
quoteBalanced: quoteBalanced,
operators: operators,
quotedLine: quotedLine,
numberLine: numberLine,
boolLine: boolLine,
rangeLine: rangeLine,
literalLine: literalLine,
filterLine: filterLine,
tagLine: tagLine,
isLiteral: isLiteral,
isVariable: isVariable,
parseLiteral: parseLiteral,
isRange: isRange,
matchValue: matchValue,
isInteger: isInteger
};
},{}],9:[function(require,module,exports){
@@ -657,10 +676,10 @@ module.exports = {
var operators = {
'==': function _(l, r) {
return l == r;
return l === r;
},
'!=': function _(l, r) {
return l != r;
return l !== r;
},
'>': function _(l, r) {
return l !== null && r !== null && l > r;
@@ -697,7 +716,6 @@ var ParseError = require('./util/error.js').ParseError;
var assert = require('./util/assert.js');
module.exports = function (Tag, Filter) {
var stream = {
init: function init(tokens) {
this.tokens = tokens;
@@ -720,7 +738,7 @@ module.exports = function (Tag, Filter) {
var token;
while (!this.stopRequested && (token = this.tokens.shift())) {
if (this.trigger('token', token)) continue;
if (token.type == 'tag' && this.trigger('tag:' + token.name, token)) {
if (token.type === 'tag' && this.trigger('tag:' + token.name, token)) {
continue;
}
var template = parseToken(token, this.tokens);
@@ -736,8 +754,8 @@ module.exports = function (Tag, Filter) {
};
function parse(tokens) {
var token,
templates = [];
var token;
var templates = [];
while (token = tokens.shift()) {
templates.push(parseToken(token, tokens));
}
@@ -986,32 +1004,30 @@ var Scope = {
* accessSeq("foo[bar.coo]") // ['foo', 'bar'], for bar.coo == 'bar'
*/
propertyAccessSeq: function propertyAccessSeq(str) {
var seq = [],
name = '';
var seq = [];
var name = '';
for (var i = 0; i < str.length; i++) {
if (str[i] === '[') {
seq.push(name);
name = '';
var delemiter = str[i + 1];
// foo[bar.coo]
if (delemiter !== "'" && delemiter !== '"') {
// foo[bar.coo]
var j = matchRightBracket(str, i + 1);
assert(j !== -1, 'unbalanced []: ' + str);
name = str.slice(i + 1, j);
// foo[1]
if (lexical.isInteger(name)) {
// foo[1]
seq.push(name);
}
} else {
// foo["bar"]
else {
seq.push(this.get(name));
}
name = '';
i = j;
}
} else {
// foo["bar"]
else {
j = str.indexOf(delemiter, i + 2);
assert(j !== -1, 'unbalanced ' + delemiter + ': ' + str);
name = str.slice(i + 2, j);
@@ -1019,14 +1035,12 @@ var Scope = {
name = '';
i = j + 2;
}
}
} else if (str[i] === '.') {
// foo.bar
else if (str[i] === ".") {
seq.push(name);
name = '';
}
} else {
// foo.bar
else {
name += str[i];
}
}
@@ -1078,8 +1092,8 @@ var assert = require('../src/util/assert.js');
function evalExp(exp, scope) {
assert(scope, 'unable to evalExp: scope undefined');
var operatorREs = lexical.operators,
match;
var operatorREs = lexical.operators;
var match;
for (var i = 0; i < operatorREs.length; i++) {
var operatorRE = operatorREs[i];
var expRE = new RegExp('^(' + lexical.quoteBalanced.source + ')(' + operatorRE.source + ')(' + lexical.quoteBalanced.source + ')$');
@@ -1092,8 +1106,8 @@ function evalExp(exp, scope) {
}
if (match = exp.match(lexical.rangeLine)) {
var low = evalValue(match[1], scope),
high = evalValue(match[2], scope);
var low = evalValue(match[1], scope);
var high = evalValue(match[2], scope);
var range = [];
for (var j = low; j <= high; j++) {
range.push(j);
@@ -1121,7 +1135,7 @@ function isTruthy(val) {
}
function isFalsy(val) {
return false === val || undefined === val || null === val;;
return val === false || undefined === val || val === null;
}
module.exports = {
@@ -1138,12 +1152,12 @@ var Syntax = require('./syntax.js');
var assert = require('./util/assert.js');
function hash(markup, scope) {
var obj = {},
match;
var obj = {};
var match;
lexical.hashCapture.lastIndex = 0;
while (match = lexical.hashCapture.exec(markup)) {
var k = match[1],
v = match[2];
var k = match[1];
var v = match[2];
obj[k] = Syntax.evalValue(v, scope);
}
return obj;
@@ -1220,9 +1234,9 @@ function parse(html, filepath, options) {
var tokens = [];
var syntax = /({%-?([\s\S]*?)-?%})|({{([\s\S]*?)}})/g;
var result, htmlFragment, token;
var lastMatchEnd = 0,
lastMatchBegin = -1,
parsedLinesCount = 0;
var lastMatchEnd = 0;
var lastMatchBegin = -1;
var parsedLinesCount = 0;
while ((result = syntax.exec(html)) !== null) {
// passed html fragments
@@ -1234,8 +1248,8 @@ function parse(html, filepath, options) {
value: htmlFragment
});
}
// tag appeared
if (result[1]) {
// tag appeared
token = factory('tag', 1, result);
var match = token.value.match(lexical.tagLine);
@@ -1246,9 +1260,8 @@ function parse(html, filepath, options) {
token.args = match[2];
tokens.push(token);
}
} else {
// output
else {
token = factory('output', 3, result);
tokens.push(token);
}
@@ -1311,7 +1324,7 @@ function assert(predicate, message) {
if (message instanceof Error) {
throw message;
}
var message = message || 'expect ' + predicate + ' to be true';
message = message || 'expect ' + predicate + ' to be true';
throw new AssertionError(message);
}
}
@@ -1506,12 +1519,12 @@ exports.anySeries = anySeries;
exports.mapSeries = mapSeries;
},{"any-promise":3}],20:[function(require,module,exports){
"use strict";
'use strict';
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
var monthNamesShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
var dayNames = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var dayNamesShort = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var monthNamesShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var dayNamesShort = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
var suffixes = {
1: 'st',
2: 'nd',
@@ -1575,7 +1588,7 @@ var _number = {
}
};
var format_codes = {
var formatCodes = {
a: function a(d) {
return dayNamesShort[d.getDay()];
},
@@ -1667,12 +1680,12 @@ var format_codes = {
var tz = d.getTimezoneOffset() / 60 * 100;
return (tz > 0 ? '-' : '+') + _number.pad(Math.abs(tz), 4);
},
"%": function _() {
'%': function _() {
return '%';
}
};
format_codes.h = format_codes.b;
format_codes.N = format_codes.L;
formatCodes.h = formatCodes.b;
formatCodes.N = formatCodes.L;
var strftime = function strftime(d, format) {
var output = '';
@@ -1693,7 +1706,7 @@ var strftime = function strftime(d, format) {
// Add the format code
var ch = results[0].charAt(1);
var func = format_codes[ch];
var func = formatCodes[ch];
output += func ? func.call(this, d) : '%' + ch;
}
};
@@ -1717,7 +1730,7 @@ function isString(value) {
function isError(value) {
var signature = Object.prototype.toString.call(value);
// [object XXXError]
return signature.substr(-6, 5) === 'Error' || typeof value.message == 'string' && typeof value.name == 'string';
return signature.substr(-6, 5) === 'Error' || typeof value.message === 'string' && typeof value.name === 'string';
}
/*
@@ -1778,8 +1791,8 @@ function echo(prefix) {
}
function uniq(arr) {
var u = {},
a = [];
var u = {};
var a = [];
for (var i = 0, l = arr.length; i < l; ++i) {
if (u.hasOwnProperty(arr[i])) {
continue;
@@ -2066,8 +2079,8 @@ module.exports = function (liquid) {
this.templates = [];
this.elseTemplates = [];
var p,
stream = liquid.parser.parseStream(remainTokens).on('start', function () {
var p;
var stream = liquid.parser.parseStream(remainTokens).on('start', function () {
return p = _this.templates;
}).on('tag:else', function () {
return p = _this.elseTemplates;
@@ -2368,7 +2381,6 @@ module.exports = function (liquid) {
var Promise = require('any-promise');
module.exports = function (liquid) {
liquid.registerTag('raw', {
parse: function parse(tagToken, remainTokens) {
var _this = this;
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "shopify-liquid",
"version": "1.7.9",
"version": "1.8.0",
"description": "A feature-rich Liquid template engine for Node.js and browsers, with compliance with the Ruby version.",
"main": "index.js",
"scripts": {