stencilproject / Stencil

Stencil is a simple and powerful template language for Swift.
https://stencil.fuller.li
BSD 2-Clause "Simplified" License
2.34k stars 224 forks source link

always evaluate block.super even if it is not used #267

Closed ilyapuchka closed 2 years ago

ilyapuchka commented 5 years ago

Resolves #266

The issue is caused by the fact that we were trying to avoid rendering block.super when it is not used in a child template by searching for such variable inside block node. The problem is that if inside this node there are other nodes, i.e. {% if %} then we are not searching inside them. We could potentially search for it recursively, but this can lead to unneeded code and runtime complexity. Instead we can always render it when rendering extend node.

This will come at a cost of possibly unneeded rendering of the block (which still may be cheeper than going through nodes tree searching for it) and any errors in the base block being reported for {% extends %} node (see changed test case) instead of {{ block.super }}.

Searching for block.super would not work reliably for error reporting any way because we are searching only for first occasion of block.super node, where at runtime actual rendering may be happening in another place (i.e. in a different branch of if node).

Alternatively we could render the content of block.super lazily by storing closure instead of rendered value in the context, but quick change like that resulted in infinite recursion and probably requires more changes to make it work.

ilyapuchka commented 5 years ago

@djbe I don't think I have it

SwiftGen-Eve commented 2 years ago

Hey 👋 I'm Eve, the friendly bot watching over Stencil 🤖

Thanks a lot for your contribution!


Seems like everything is in order 👍 You did a good job here! 🤝

Generated by :no_entry_sign: Danger