liquidjs
liquidjs copied to clipboard
block.super does not work with strictVariables: true
I tried to use {{block.super}} while using templates with strictVariables: true and got undefined variable error.
It seem to be happening because of block.ts tag is pushing BlockDrop with generators that return undefined (?) on yield and as previously there was no yield in getFromScope => readProperty (context.ts) it was not a problem on strict checking before changing to promises in
bbf00f3
// to test it
it('should support block.super while strictVariables', async function () {
mock({
'/parent.html': '{% block css %}<link href="base.css" rel="stylesheet">{% endblock %}'
})
const src = '{% layout "parent.html" %}' +
'{%block css%}{{block.super}}<link href="extra.css" rel="stylesheet">{%endblock%}'
const html = await liquid.parseAndRender(src, undefined, {strictVariables: true})
const output = '<link href="base.css" rel="stylesheet"><link href="extra.css" rel="stylesheet">'
return expect(html).toBe(output)
})
● tags/layout › should support block.super while strictVariables
undefined variable: block.super, line:1, col:42
>> 1| {% layout "parent.html" %}{%block css%}{{block.super}}<link href="extra.css" rel="stylesheet">{%endblock%}
^
UndefinedVariableError: undefined variable: block.super, line:1, col:42
57 | } catch (e) {
58 | if (lenient && (e as Error).name === 'InternalUndefinedVariableError') return null
> 59 | throw (new UndefinedVariableError(e as Error, token))
| ^
60 | }
61 | }
62 |
at evalPropertyAccessToken (src/render/expression.ts:59:12)
at evalPropertyAccessToken.throw (<anonymous>)
at src/util/async.ts:10:28
at Generator.throw (<anonymous>)
at rejected (src/util/async.ts:6:65)
From InternalUndefinedVariableError: undefined variable: block.super
at Context._getFromScope (src/context/context.ts:91:15)
at _getFromScope.next (<anonymous>)
at src/util/async.ts:10:28
at fulfilled (src/util/async.ts:5:58)
Thanks for the investigation! Will look into this in a couple of days, and feel free to file a PR if you’re interested.