feat: rename to defaultOperators and Operators

This commit is contained in:
Jason Etcovitch
2021-02-04 09:11:28 +08:00
committed by Jun Yang
parent 18055c8855
commit 8734e2e6ce
6 changed files with 55 additions and 55 deletions
+4 -4
View File
@@ -3,7 +3,7 @@ import { Template } from './template/template'
import { Cache } from './cache/cache'
import { LRU } from './cache/lru'
import { FS } from './fs/fs'
import { Operators, OperatorMap } from './render/operator'
import { defaultOperators, Operators } from './render/operator'
export interface LiquidOptions {
/** A directory or an array of directories from where to resolve layout and include templates, and the filename passed to `.renderFile()`. If it's an array, the files are looked up in the order they occur in the array. Defaults to `["."]` */
@@ -49,7 +49,7 @@ export interface LiquidOptions {
/** Whether or not to keep value type when writing the Output. Defaults to `false`. */
keepOutputType?: boolean;
/** An object of operators for conditional statements. Defaults to the regular Liquid operators. */
operators?: OperatorMap;
operators?: Operators;
}
interface NormalizedOptions extends LiquidOptions {
@@ -78,7 +78,7 @@ export interface NormalizedFullOptions extends NormalizedOptions {
greedy: boolean;
globals: object;
keepOutputType: boolean;
operators: OperatorMap;
operators: Operators;
}
export const defaultOptions: NormalizedFullOptions = {
@@ -102,7 +102,7 @@ export const defaultOptions: NormalizedFullOptions = {
lenientIf: false,
globals: {},
keepOutputType: false,
operators: Operators
operators: defaultOperators
}
export function normalize (options?: LiquidOptions): NormalizedOptions {
+4 -4
View File
@@ -11,16 +11,16 @@ import { parseStringLiteral } from '../parser/parse-string-literal'
import { Context } from '../context/context'
import { range, toValue } from '../util/underscore'
import { Tokenizer } from '../parser/tokenizer'
import { OperatorMap } from '../render/operator'
import { Operators } from '../render/operator'
import { UndefinedVariableError, InternalUndefinedVariableError } from '../util/error'
export class Expression {
private operands: any[] = []
private postfix: Token[]
private lenient: boolean
private operators: OperatorMap
private operators: Operators
public constructor (str: string, operators: OperatorMap, lenient = false) {
public constructor (str: string, operators: Operators, lenient = false) {
const tokenizer = new Tokenizer(str)
this.postfix = [...toPostfix(tokenizer.readExpression())]
this.lenient = lenient
@@ -75,7 +75,7 @@ export function evalQuotedToken (token: QuotedToken) {
return parseStringLiteral(token.getText())
}
function evalOperatorToken (operators: OperatorMap, token: OperatorToken, lhs: any, rhs: any, ctx: Context) {
function evalOperatorToken (operators: Operators, token: OperatorToken, lhs: any, rhs: any, ctx: Context) {
const impl = operators[token.operator]
return impl(lhs, rhs, ctx)
}
+2 -2
View File
@@ -3,11 +3,11 @@ import { Context } from '../context/context'
import { isFunction } from '../util/underscore'
import { isTruthy } from '../render/boolean'
export interface OperatorMap {
export interface Operators {
[key: string]: (lhs: any, rhs: any, ctx: Context) => boolean;
}
export const Operators: OperatorMap = {
export const defaultOperators: Operators = {
'==': (l: any, r: any) => {
if (isComparable(l)) return l.equals(r)
if (isComparable(r)) return r.equals(l)
+1 -1
View File
@@ -19,4 +19,4 @@ export { Tokenizer } from './parser/tokenizer'
export { Hash } from './template/tag/hash'
export { evalToken, evalQuotedToken } from './render/expression'
export { toPromise, toThenable, toValue } from './util/async'
export { Operators, OperatorMap } from './render/operator'
export { defaultOperators, Operators } from './render/operator'