Skip to content

block.super does not work with strictVariables: true #806

@kamikadzem22

Description

@kamikadzem22

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions