Skip to content

Commit

Permalink
fix: lenientIf not working for the umd bundle, closes #313
Browse files Browse the repository at this point in the history
  • Loading branch information
harttle committed Feb 19, 2021
1 parent 2430672 commit 2e66e8b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/render/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { parseStringLiteral } from '../parser/parse-string-literal'
import { Context } from '../context/context'
import { range } from '../util/underscore'
import { Operators } from '../render/operator'
import { UndefinedVariableError, InternalUndefinedVariableError } from '../util/error'
import { UndefinedVariableError } from '../util/error'

export class Expression {
private postfix: Token[]
Expand Down Expand Up @@ -52,7 +52,7 @@ function evalPropertyAccessToken (token: PropertyAccessToken, ctx: Context, leni
try {
return ctx.get([variable, ...props])
} catch (e) {
if (lenient && e instanceof InternalUndefinedVariableError) return null
if (lenient && e.name === 'InternalUndefinedVariableError') return null
throw (new UndefinedVariableError(e, token))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class RenderError extends LiquidError {
super.update()
}
public static is (obj: any): obj is RenderError {
return obj instanceof RenderError
return obj.name === 'RenderError'
}
}

Expand Down
9 changes: 9 additions & 0 deletions test/e2e/issues.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Liquid } from '../..'
import { Liquid as LiquidUMD } from '../../dist/liquid.browser.umd.js'
import { expect, use } from 'chai'
import * as chaiAsPromised from 'chai-as-promised'

Expand Down Expand Up @@ -78,4 +79,12 @@ describe('Issues', function () {
)
expect(html).to.equal('BAR')
})
it('#313 lenientIf not working as expected in umd', async () => {
const engine = new LiquidUMD({
strictVariables: true,
lenientIf: true
})
const html = await engine.parseAndRender(`{{ name | default: "default name" }}`)
expect(html).to.equal('default name')
})
})

0 comments on commit 2e66e8b

Please sign in to comment.