mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-14 20:00:39 -07:00
fix: proper error message for filter syntax error, #610
This commit is contained in:
@@ -57,7 +57,7 @@ export class Tokenizer {
|
||||
readFilter (): FilterToken | null {
|
||||
this.skipBlank()
|
||||
if (this.end()) return null
|
||||
assert(this.peek() === '|', () => `unexpected token at ${this.snapshot()}`)
|
||||
assert(this.peek() === '|', () => `expected "|" before filter`)
|
||||
this.p++
|
||||
const begin = this.p
|
||||
const name = this.readIdentifier()
|
||||
@@ -72,6 +72,10 @@ export class Tokenizer {
|
||||
this.skipBlank()
|
||||
assert(this.end() || this.peek() === ',' || this.peek() === '|', () => `unexpected character ${this.snapshot()}`)
|
||||
} while (this.peek() === ',')
|
||||
} else if (this.peek() === '|' || this.end()) {
|
||||
// do nothing
|
||||
} else {
|
||||
throw new Error('expected ":" after filter name')
|
||||
}
|
||||
return new FilterToken(name.getText(), args, this.input, begin, this.p, this.file)
|
||||
}
|
||||
|
||||
@@ -426,4 +426,9 @@ describe('Issues', function () {
|
||||
'2023-01-05T12:00:00+0000'
|
||||
expect(html).toEqual(expected)
|
||||
})
|
||||
it('#610 should throw missing ":" after filter name', () => {
|
||||
const engine = new Liquid()
|
||||
const fn = () => engine.parseAndRenderSync("{%- assign module = '' | split '' -%}")
|
||||
expect(fn).toThrow(/expected ":" after filter name/)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user