mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
refactor: rewrite expression evaluation, fix #130
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { last } from '../util/underscore'
|
||||
import { NullDrop } from '../drop/null-drop'
|
||||
import { EmptyDrop } from '../drop/empty-drop'
|
||||
import { BlankDrop } from '../drop/blank-drop'
|
||||
|
||||
type literal = true | false | NullDrop | EmptyDrop | BlankDrop | number | string
|
||||
|
||||
export function parseLiteral (str: string): literal | undefined {
|
||||
str = str.trim()
|
||||
|
||||
if (str === 'true') 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)
|
||||
}
|
||||
Reference in New Issue
Block a user