add and use error classes for undefined variables

cleans up funky message-matching code in expression.ts for lenient.
This commit is contained in:
sschuldenzucker
2020-12-06 22:58:08 +08:00
committed by Jun Yang
parent ca18a579a1
commit d8f9091a12
3 changed files with 26 additions and 5 deletions
+2 -1
View File
@@ -3,6 +3,7 @@ import { __assign } from 'tslib'
import { NormalizedFullOptions, defaultOptions } from '../liquid-options'
import { Scope } from './scope'
import { isArray, isNil, isString, isFunction, toLiquid } from '../util/underscore'
import { InternalUndefinedVariableError } from '../util/error'
export class Context {
private scopes: Scope[] = [{}]
@@ -42,7 +43,7 @@ export class Context {
return paths.reduce((scope, path) => {
scope = readProperty(scope, path)
if (isNil(scope) && this.opts.strictVariables) {
throw new TypeError(`undefined variable: ${path}`)
throw new InternalUndefinedVariableError(path)
}
return scope
}, scope)