Skip to content
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

Open
asariley opened this issue Aug 15, 2016 · 4 comments
Open

compiling templates with partials does not detect cycles #22

asariley opened this issue Aug 15, 2016 · 4 comments

Comments

@asariley
Copy link
Contributor

While the spec does say "Don't make cycles in your partials" it would be better to error out somehow than to loop infinitely.

@JustusAdam
Copy link
Owner

JustusAdam commented Aug 15, 2016

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.

@asariley
Copy link
Contributor Author

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 IO is needed at substitution time.

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.

@JustusAdam
Copy link
Owner

Yes partials are expanded at runtime, however the partials are (by default) read at compilation time.
I know this is slightly against the proposed semantics and now that I say that it might be interesting to offer a different expansion strategy where it compiles templates at expansion time, but that is a topic for another issue.

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.

@JustusAdam
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants