chore(release): 7.3.0 [skip ci]

# [7.3.0](https://github.com/harttle/liquidjs/compare/v7.2.2...v7.3.0) (2019-02-24)

### Features

* nil/null/empty/blank literals, resolves [#102](https://github.com/harttle/liquidjs/issues/102) ([88c9e96](https://github.com/harttle/liquidjs/commit/88c9e96))
This commit is contained in:
semantic-release-bot
2019-02-24 13:55:31 +00:00
parent 88c9e96392
commit f9f35ebd6c
18 changed files with 379 additions and 52 deletions
+7
View File
@@ -1,3 +1,10 @@
# [7.3.0](https://github.com/harttle/liquidjs/compare/v7.2.2...v7.3.0) (2019-02-24)
### Features
* nil/null/empty/blank literals, resolves [#102](https://github.com/harttle/liquidjs/issues/102) ([88c9e96](https://github.com/harttle/liquidjs/commit/88c9e96))
## [7.2.2](https://github.com/harttle/liquidjs/compare/v7.2.1...v7.2.2) (2019-02-23)
+155 -18
View File
@@ -1,5 +1,5 @@
/*
* liquidjs@7.2.2, https://github.com/harttle/liquidjs
* liquidjs@7.3.0, https://github.com/harttle/liquidjs
* (c) 2016-2019 harttle
* Released under the MIT License.
*/
@@ -418,7 +418,7 @@ var Scope = /** @class */ (function () {
Scope.prototype.readProperty = function (obj, key) {
var val;
if (isNil(obj)) {
val = undefined;
val = obj;
}
else {
obj = toLiquid(obj);
@@ -840,13 +840,136 @@ var Render = /** @class */ (function () {
return Render;
}());
var operators$1 = {
'==': function (l, r) { return l === r; },
'!=': function (l, r) { return l !== r; },
'>': function (l, r) { return l !== null && r !== null && l > r; },
'<': function (l, r) { return l !== null && r !== null && l < r; },
'>=': function (l, r) { return l !== null && r !== null && l >= r; },
'<=': function (l, r) { return l !== null && r !== null && l <= r; },
function isComparable(arg) {
return arg && isFunction(arg.equals);
}
var Drop = /** @class */ (function () {
function Drop() {
}
return Drop;
}());
function isDrop(value) {
return value instanceof Drop && isFunction(value.value);
}
var EmptyDrop = /** @class */ (function (_super) {
__extends(EmptyDrop, _super);
function EmptyDrop() {
return _super !== null && _super.apply(this, arguments) || this;
}
EmptyDrop.prototype.equals = function (value) {
if (isString(value) || isArray(value))
return value.length === 0;
if (isObject(value))
return Object.keys(value).length === 0;
return false;
};
EmptyDrop.prototype.gt = function () {
return false;
};
EmptyDrop.prototype.geq = function () {
return false;
};
EmptyDrop.prototype.lt = function () {
return false;
};
EmptyDrop.prototype.leq = function () {
return false;
};
EmptyDrop.prototype.value = function () {
return '';
};
return EmptyDrop;
}(Drop));
var BlankDrop = /** @class */ (function (_super) {
__extends(BlankDrop, _super);
function BlankDrop() {
return _super !== null && _super.apply(this, arguments) || this;
}
BlankDrop.prototype.equals = function (value) {
if (value === false)
return true;
if (isNil(isDrop(value) ? value.value() : value))
return true;
if (isString(value))
return /^\s*$/.test(value);
return _super.prototype.equals.call(this, value);
};
return BlankDrop;
}(EmptyDrop));
var NullDrop = /** @class */ (function (_super) {
__extends(NullDrop, _super);
function NullDrop() {
return _super !== null && _super.apply(this, arguments) || this;
}
NullDrop.prototype.equals = function (value) {
return isNil(isDrop(value) ? value.value() : value) || value instanceof BlankDrop;
};
NullDrop.prototype.gt = function () {
return false;
};
NullDrop.prototype.geq = function () {
return false;
};
NullDrop.prototype.lt = function () {
return false;
};
NullDrop.prototype.leq = function () {
return false;
};
NullDrop.prototype.value = function () {
return null;
};
return NullDrop;
}(Drop));
var binaryOperators = {
'==': function (l, r) {
if (isComparable(l))
return l.equals(r);
if (isComparable(r))
return r.equals(l);
return l === r;
},
'!=': function (l, r) {
if (isComparable(l))
return !l.equals(r);
if (isComparable(r))
return !r.equals(l);
return l !== r;
},
'>': function (l, r) {
if (isComparable(l))
return l.gt(r);
if (isComparable(r))
return r.lt(l);
return l > r;
},
'<': function (l, r) {
if (isComparable(l))
return l.lt(r);
if (isComparable(r))
return r.gt(l);
return l < r;
},
'>=': function (l, r) {
if (isComparable(l))
return l.geq(r);
if (isComparable(r))
return r.leq(l);
return l >= r;
},
'<=': function (l, r) {
if (isComparable(l))
return l.leq(r);
if (isComparable(r))
return r.geq(l);
return l <= r;
},
'contains': function (l, r) {
if (!l)
return false;
@@ -857,28 +980,32 @@ var operators$1 = {
'and': function (l, r) { return isTruthy(l) && isTruthy(r); },
'or': function (l, r) { return isTruthy(l) || isTruthy(r); }
};
function evalExp(exp, scope) {
assert(scope, 'unable to evalExp: scope undefined');
function parseExp(exp, scope) {
assert(scope, 'unable to parseExp: scope undefined');
var operatorREs = operators;
var match;
for (var i = 0; i < operatorREs.length; i++) {
var operatorRE = operatorREs[i];
var expRE = new RegExp("^(" + quoteBalanced.source + ")(" + operatorRE.source + ")(" + quoteBalanced.source + ")$");
if ((match = exp.match(expRE))) {
var l = evalExp(match[1], scope);
var op = operators$1[match[2].trim()];
var r = evalExp(match[3], scope);
var l = parseExp(match[1], scope);
var op = binaryOperators[match[2].trim()];
var r = parseExp(match[3], scope);
return op(l, r);
}
}
if ((match = exp.match(rangeLine))) {
var low = evalValue(match[1], scope);
var high = evalValue(match[2], scope);
var low = parseValue(match[1], scope);
var high = parseValue(match[2], scope);
return range(low, high + 1);
}
return evalValue(exp, scope);
return parseValue(exp, scope);
}
function evalValue(str, scope) {
function evalExp(str, scope) {
var value$$1 = parseExp(str, scope);
return isDrop(value$$1) ? value$$1.value() : value$$1;
}
function parseValue(str, scope) {
if (!str)
return null;
str = str.trim();
@@ -886,12 +1013,22 @@ function evalValue(str, scope) {
return true;
if (str === 'false')
return false;
if (str === 'nil' || str === 'null')
return new NullDrop();
if (str === 'empty')
return new EmptyDrop();
if (str === 'blank')
return new BlankDrop();
if (!isNaN(Number(str)))
return Number(str);
if ((str[0] === '"' || str[0] === "'") && str[0] === last(str))
return str.slice(1, -1);
return scope.get(str);
}
function evalValue(str, scope) {
var value$$1 = parseValue(str, scope);
return isDrop(value$$1) ? value$$1.value() : value$$1;
}
function isTruthy(val) {
return !isFalsy(val);
}
+1 -1
View File
File diff suppressed because one or more lines are too long
+155 -18
View File
@@ -1,5 +1,5 @@
/*
* liquidjs@7.2.2, https://github.com/harttle/liquidjs
* liquidjs@7.3.0, https://github.com/harttle/liquidjs
* (c) 2016-2019 harttle
* Released under the MIT License.
*/
@@ -406,7 +406,7 @@
Scope.prototype.readProperty = function (obj, key) {
var val;
if (isNil(obj)) {
val = undefined;
val = obj;
}
else {
obj = toLiquid(obj);
@@ -865,13 +865,136 @@
return Render;
}());
var operators$1 = {
'==': function (l, r) { return l === r; },
'!=': function (l, r) { return l !== r; },
'>': function (l, r) { return l !== null && r !== null && l > r; },
'<': function (l, r) { return l !== null && r !== null && l < r; },
'>=': function (l, r) { return l !== null && r !== null && l >= r; },
'<=': function (l, r) { return l !== null && r !== null && l <= r; },
function isComparable(arg) {
return arg && isFunction(arg.equals);
}
var Drop = /** @class */ (function () {
function Drop() {
}
return Drop;
}());
function isDrop(value) {
return value instanceof Drop && isFunction(value.value);
}
var EmptyDrop = /** @class */ (function (_super) {
__extends(EmptyDrop, _super);
function EmptyDrop() {
return _super !== null && _super.apply(this, arguments) || this;
}
EmptyDrop.prototype.equals = function (value) {
if (isString(value) || isArray(value))
return value.length === 0;
if (isObject(value))
return Object.keys(value).length === 0;
return false;
};
EmptyDrop.prototype.gt = function () {
return false;
};
EmptyDrop.prototype.geq = function () {
return false;
};
EmptyDrop.prototype.lt = function () {
return false;
};
EmptyDrop.prototype.leq = function () {
return false;
};
EmptyDrop.prototype.value = function () {
return '';
};
return EmptyDrop;
}(Drop));
var BlankDrop = /** @class */ (function (_super) {
__extends(BlankDrop, _super);
function BlankDrop() {
return _super !== null && _super.apply(this, arguments) || this;
}
BlankDrop.prototype.equals = function (value) {
if (value === false)
return true;
if (isNil(isDrop(value) ? value.value() : value))
return true;
if (isString(value))
return /^\s*$/.test(value);
return _super.prototype.equals.call(this, value);
};
return BlankDrop;
}(EmptyDrop));
var NullDrop = /** @class */ (function (_super) {
__extends(NullDrop, _super);
function NullDrop() {
return _super !== null && _super.apply(this, arguments) || this;
}
NullDrop.prototype.equals = function (value) {
return isNil(isDrop(value) ? value.value() : value) || value instanceof BlankDrop;
};
NullDrop.prototype.gt = function () {
return false;
};
NullDrop.prototype.geq = function () {
return false;
};
NullDrop.prototype.lt = function () {
return false;
};
NullDrop.prototype.leq = function () {
return false;
};
NullDrop.prototype.value = function () {
return null;
};
return NullDrop;
}(Drop));
var binaryOperators = {
'==': function (l, r) {
if (isComparable(l))
return l.equals(r);
if (isComparable(r))
return r.equals(l);
return l === r;
},
'!=': function (l, r) {
if (isComparable(l))
return !l.equals(r);
if (isComparable(r))
return !r.equals(l);
return l !== r;
},
'>': function (l, r) {
if (isComparable(l))
return l.gt(r);
if (isComparable(r))
return r.lt(l);
return l > r;
},
'<': function (l, r) {
if (isComparable(l))
return l.lt(r);
if (isComparable(r))
return r.gt(l);
return l < r;
},
'>=': function (l, r) {
if (isComparable(l))
return l.geq(r);
if (isComparable(r))
return r.leq(l);
return l >= r;
},
'<=': function (l, r) {
if (isComparable(l))
return l.leq(r);
if (isComparable(r))
return r.geq(l);
return l <= r;
},
'contains': function (l, r) {
if (!l)
return false;
@@ -882,28 +1005,32 @@
'and': function (l, r) { return isTruthy(l) && isTruthy(r); },
'or': function (l, r) { return isTruthy(l) || isTruthy(r); }
};
function evalExp(exp, scope) {
assert(scope, 'unable to evalExp: scope undefined');
function parseExp(exp, scope) {
assert(scope, 'unable to parseExp: scope undefined');
var operatorREs = operators;
var match;
for (var i = 0; i < operatorREs.length; i++) {
var operatorRE = operatorREs[i];
var expRE = new RegExp("^(" + quoteBalanced.source + ")(" + operatorRE.source + ")(" + quoteBalanced.source + ")$");
if ((match = exp.match(expRE))) {
var l = evalExp(match[1], scope);
var op = operators$1[match[2].trim()];
var r = evalExp(match[3], scope);
var l = parseExp(match[1], scope);
var op = binaryOperators[match[2].trim()];
var r = parseExp(match[3], scope);
return op(l, r);
}
}
if ((match = exp.match(rangeLine))) {
var low = evalValue(match[1], scope);
var high = evalValue(match[2], scope);
var low = parseValue(match[1], scope);
var high = parseValue(match[2], scope);
return range(low, high + 1);
}
return evalValue(exp, scope);
return parseValue(exp, scope);
}
function evalValue(str, scope) {
function evalExp(str, scope) {
var value$$1 = parseExp(str, scope);
return isDrop(value$$1) ? value$$1.value() : value$$1;
}
function parseValue(str, scope) {
if (!str)
return null;
str = str.trim();
@@ -911,12 +1038,22 @@
return true;
if (str === 'false')
return false;
if (str === 'nil' || str === 'null')
return new NullDrop();
if (str === 'empty')
return new EmptyDrop();
if (str === 'blank')
return new BlankDrop();
if (!isNaN(Number(str)))
return Number(str);
if ((str[0] === '"' || str[0] === "'") && str[0] === last(str))
return str.slice(1, -1);
return scope.get(str);
}
function evalValue(str, scope) {
var value$$1 = parseValue(str, scope);
return isDrop(value$$1) ? value$$1.value() : value$$1;
}
function isTruthy(val) {
return !isFalsy(val);
}
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+4
View File
@@ -0,0 +1,4 @@
import { EmptyDrop } from 'src/drop/empty-drop';
export declare class BlankDrop extends EmptyDrop {
equals(value: any): boolean;
}
+2
View File
@@ -0,0 +1,2 @@
export declare abstract class Drop {
}
+11
View File
@@ -0,0 +1,11 @@
import { Drop } from './drop';
import { IComparable } from './icomparable';
import { IDrop } from 'src/drop/idrop';
export declare class EmptyDrop extends Drop implements IDrop, IComparable {
equals(value: any): boolean;
gt(): boolean;
geq(): boolean;
lt(): boolean;
leq(): boolean;
value(): string;
}
+8
View File
@@ -0,0 +1,8 @@
export interface IComparable {
equals: (rhs: any) => boolean;
gt: (rhs: any) => boolean;
geq: (rhs: any) => boolean;
lt: (rhs: any) => boolean;
leq: (rhs: any) => boolean;
}
export declare function isComparable(arg: any): arg is IComparable;
+4
View File
@@ -0,0 +1,4 @@
export interface IDrop {
value(): any;
}
export declare function isDrop(value: any): value is IDrop;
+11
View File
@@ -0,0 +1,11 @@
import { Drop } from './drop';
import { IComparable } from './icomparable';
import { IDrop } from 'src/drop/idrop';
export declare class NullDrop extends Drop implements IDrop, IComparable {
equals(value: any): boolean;
gt(): boolean;
geq(): boolean;
lt(): boolean;
leq(): boolean;
value(): null;
}
+2 -1
View File
@@ -1,5 +1,6 @@
import Scope from 'src/scope/scope';
export declare function evalExp(exp: string, scope: Scope): any;
export declare function parseExp(exp: string, scope: Scope): any;
export declare function evalExp(str: string, scope: Scope): any;
export declare function evalValue(str: string, scope: Scope): any;
export declare function isTruthy(val: any): boolean;
export declare function isFalsy(val: any): boolean;
+9 -4
View File
@@ -1,22 +1,27 @@
import { NormalizedFullOptions } from '../liquid-options';
import BlockMode from './block-mode';
import IContext from './icontext';
export declare type Context = {
[key: string]: any;
liquid_method_missing?: (key: string) => any;
to_liquid?: () => any;
toLiquid?: () => any;
};
export default class Scope {
opts: NormalizedFullOptions;
contexts: Array<IContext>;
contexts: Array<Context>;
blocks: object;
groups: {
[key: string]: number;
};
blockMode: BlockMode;
constructor(ctx?: object, opts?: NormalizedFullOptions);
getAll(): IContext;
getAll(): Context;
get(path: string): any;
set(path: string, v: any): void;
unshift(ctx: object): number;
push(ctx: object): number;
pop(ctx?: object): object | undefined;
findContextFor(key: string, filter?: ((conttext: object) => boolean)): IContext | null;
findContextFor(key: string, filter?: ((conttext: object) => boolean)): Context | null;
private readProperty;
propertyAccessSeq(str: string): string[];
}
+5 -5
View File
@@ -1,12 +1,12 @@
export declare function isString(value: any): boolean;
export declare function isFunction(value: any): boolean;
export declare function isString(value: any): value is string;
export declare function isFunction(value: any): value is Function;
export declare function promisify<T1, T2>(fn: (arg1: T1, cb: (err: Error | null, result: T2) => void) => void): (arg1: T1) => Promise<T2>;
export declare function promisify<T1, T2, T3>(fn: (arg1: T1, arg2: T2, cb: (err: Error | null, result: T3) => void) => void): (arg1: T1, arg2: T2) => Promise<T3>;
export declare function stringify(value: any): string;
export declare function create<T1 extends object, T2 extends T1 = T1>(proto: T1): T2;
export declare function isNil(value: any): boolean;
export declare function isArray(value: any): boolean;
export declare function isError(value: any): boolean;
export declare function isArray(value: any): value is any[];
export declare function isError(value: any): value is Error;
export declare function forOwn<T>(object: {
[key: string]: T;
} | undefined, iteratee: ((val: T, key: string, obj: {
@@ -16,6 +16,6 @@ export declare function forOwn<T>(object: {
};
export declare function last<T>(arr: T[]): T;
export declare function last(arr: string): string;
export declare function isObject(value: any): boolean;
export declare function isObject(value: any): value is object;
export declare function range(start: number, stop?: number, step?: number): number[];
export declare function padStart(str: any, length: number, ch?: string): any;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "liquidjs",
"version": "7.2.2",
"version": "7.3.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "liquidjs",
"version": "7.2.2",
"version": "7.3.0",
"description": "Liquid template engine by pure JavaScript: compatible to shopify, easy to extend.",
"main": "dist/liquid.common.js",
"types": "dist/liquid.d.ts",