feat: expose FilterToken to filter this, #762

This commit is contained in:
Yang Jun
2024-10-16 22:07:25 +08:00
committed by Jun Yang
parent 59da3fa543
commit d705888c8d
7 changed files with 36 additions and 20 deletions
+9
View File
@@ -515,4 +515,13 @@ describe('Issues', function () {
expect(LiquidError.is(err) && err.originalError).toHaveProperty('message', 'intended')
}
})
it('getting current line number and template name from a filter #762', () => {
const engine = new Liquid()
engine.registerFilter('pos', function (val: string) {
const [line, col] = this.token.getPosition()
return `[${line},${col}] ${val}`
})
const result = engine.parseAndRenderSync(`\n{{ "foo" | pos }}`)
expect(result).toEqual('\n[2,12] foo')
})
})