-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
compiling templates with partials does not detect cycles #22
Comments
That's difficult though because partials can be conditional and the conditional could be scoped and therefore change value in each partial call. Mustache may be too strong as a language. Properly detecting such cycle is probably close to solving the halting problem. A solution would be to introduce some form of cap on recursion depth in partials. We'd have to basically build a partial stack and track the size thereof, throwing an error if a predetermined size is exceeded. |
Well currently, because the compilation process expands all partials, so this type of conditional nuance is not supported anyways. The spec says that partials should be expanded at run time which unfortunately seems to imply I think there may be a slight tweak to the compilation process that will allow it to support these kind of runtime cycles. But I need to explore the idea a bit more. Failing that, I think the recursion depth idea is a good way to mitigate the infinite loop issue. |
Yes partials are expanded at runtime, however the partials are (by default) read at compilation time. I understand what you mean with the infinite loop now. The compilation step does some state propagation to avoid recompiling templates, perhaps this could be tweaked to insert the template before it has actually been compiled. |
When I designed this I went for ease of use, and that's why the partials are bundled with the Template itself. The recursive problem could be solved by splitting apart partials cache and templates and using a flat cache rather than a nested one. |
While the spec does say "Don't make cycles in your partials" it would be better to error out somehow than to loop infinitely.
The text was updated successfully, but these errors were encountered: