feat: more flexible squared property read expression, fixes #643 (#646)

* fix: more flexible squared property read expression, fixes #643

* fix: unecessary error wrapping in browser bundles

* style: update code style and types

* perf: use token.value when evalToken
This commit is contained in:
Jun Yang
2023-08-23 00:45:49 +08:00
committed by GitHub
parent dc6a301387
commit 660d9be55f
22 changed files with 261 additions and 167 deletions
+14
View File
@@ -7,4 +7,18 @@ describe('browser', function () {
message: 'output "{{huh" not closed, line:1, col:1'
})
})
it('should throw tokenization error for invalid filter syntax', async () => {
const engine = new LiquidUMD()
const message = 'expected filter name, line:1, col:10'
const stack = [
'>> 1| {{ foo | ^ }}',
' ^',
`TokenizationError: ${message}`
].join('\n')
await expect(engine.parseAndRender('{{ foo | ^ }}')).rejects.toMatchObject({
message,
stack: expect.stringContaining(stack),
name: 'TokenizationError'
})
})
})
+10
View File
@@ -454,4 +454,14 @@ describe('Issues', function () {
const result = engine.parseAndRenderSync(template, { product })
expect(result).toEqual('This is a love potion!')
})
it('#643 Error When Accessing Subproperty of Bracketed Reference', () => {
const engine = new Liquid()
const tpl = '{{ ["Key String with Spaces"].subpropertyKey }}'
const ctx = {
'Key String with Spaces': {
subpropertyKey: 'FOO'
}
}
expect(engine.parseAndRenderSync(tpl, ctx)).toEqual('FOO')
})
})