diff --git a/src/drop/blank-drop.ts b/src/drop/blank-drop.ts index 01b0f5d96..24234b026 100644 --- a/src/drop/blank-drop.ts +++ b/src/drop/blank-drop.ts @@ -1,11 +1,11 @@ import { isNil, isString } from '../util/underscore' -import { isDrop } from '../drop/idrop' +import { Drop } from '../drop/drop' import { EmptyDrop } from '../drop/empty-drop' export class BlankDrop extends EmptyDrop { equals (value: any) { if (value === false) return true - if (isNil(isDrop(value) ? value.valueOf() : value)) return true + if (isNil(value instanceof Drop ? value.valueOf() : value)) return true if (isString(value)) return /^\s*$/.test(value) return super.equals(value) } diff --git a/src/drop/drop.ts b/src/drop/drop.ts index a402063fb..792416e3f 100644 --- a/src/drop/drop.ts +++ b/src/drop/drop.ts @@ -1,2 +1,6 @@ export abstract class Drop { + abstract valueOf(): any; + + liquid_method_missing (name: string) { // eslint-disable-line + } } diff --git a/src/drop/empty-drop.ts b/src/drop/empty-drop.ts index fb6bb1331..8cd095c58 100644 --- a/src/drop/empty-drop.ts +++ b/src/drop/empty-drop.ts @@ -1,9 +1,8 @@ import { Drop } from './drop' import { IComparable } from './icomparable' import { isObject, isString, isArray } from '../util/underscore' -import { IDrop } from '../drop/idrop' -export class EmptyDrop extends Drop implements IDrop, IComparable { +export class EmptyDrop extends Drop implements IComparable { equals (value: any) { if (isString(value) || isArray(value)) return value.length === 0 if (isObject(value)) return Object.keys(value).length === 0 diff --git a/src/drop/idrop.ts b/src/drop/idrop.ts deleted file mode 100644 index 0110260c7..000000000 --- a/src/drop/idrop.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Drop } from './drop' -import { isFunction } from '../util/underscore' - -export interface IDrop { - valueOf(): any -} - -export function isDrop (value: any): value is IDrop { - return value instanceof Drop && isFunction((value as any).valueOf) -} diff --git a/src/drop/null-drop.ts b/src/drop/null-drop.ts index 29a45960a..5475b99eb 100644 --- a/src/drop/null-drop.ts +++ b/src/drop/null-drop.ts @@ -1,12 +1,11 @@ import { Drop } from './drop' import { IComparable } from './icomparable' import { isNil } from '../util/underscore' -import { IDrop, isDrop } from '../drop/idrop' import { BlankDrop } from '../drop/blank-drop' -export class NullDrop extends Drop implements IDrop, IComparable { +export class NullDrop extends Drop implements IComparable { equals (value: any) { - return isNil(isDrop(value) ? value.valueOf() : value) || value instanceof BlankDrop + return isNil(value instanceof Drop ? value.valueOf() : value) || value instanceof BlankDrop } gt () { return false diff --git a/src/render/syntax.ts b/src/render/syntax.ts index efadc1890..fe2f1a214 100644 --- a/src/render/syntax.ts +++ b/src/render/syntax.ts @@ -6,7 +6,7 @@ import { isComparable } from '../drop/icomparable' import { NullDrop } from '../drop/null-drop' import { EmptyDrop } from '../drop/empty-drop' import { BlankDrop } from '../drop/blank-drop' -import { isDrop } from '../drop/idrop' +import { Drop } from '../drop/drop' const binaryOperators: {[key: string]: (lhs: any, rhs: any) => boolean} = { '==': (l: any, r: any) => { @@ -74,7 +74,7 @@ export function parseExp (exp: string, scope: Scope): any { export function evalExp (str: string, scope: Scope): any { const value = parseExp(str, scope) - return isDrop(value) ? value.valueOf() : value + return value instanceof Drop ? value.valueOf() : value } function parseValue (str: string, scope: Scope): any { @@ -93,7 +93,7 @@ function parseValue (str: string, scope: Scope): any { export function evalValue (str: string, scope: Scope): any { const value = parseValue(str, scope) - return isDrop(value) ? value.valueOf() : value + return value instanceof Drop ? value.valueOf() : value } export function isTruthy (val: any): boolean {