-
Notifications
You must be signed in to change notification settings - Fork 285
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
Fix all whitespace specs #215
base: master
Are you sure you want to change the base?
Conversation
This reverts commit d611bed.
A few comments (thanks for digging into this):
|
|
I'm starting to warmup to just making this the default and removing the old whitespace behavior as it appears to be close enough in running all my current tests. I'd still like to avoid allocating at runtime - currently there are essentially no objects allocated while running a template - by optimizing the way indentation is done. Maybe through remembering where the '\n's are while we are doing the initial compile and inserting the indentation in the appendText call. I haven't looked at it closely enough to see if that is feasible. Also it appears that the limited recursion stuff isn't working right now but haven't tracked down why - probably because the indent writer replacing it. |
Alright, I will create an alternative implementation with Should I then remove whitespace backwards compatibility from the parser or only disable it by default? What do you mean by "limited recursion stuff"? |
I think we can remove it. The differences are pretty small and I don't think it will be disruptive except perhaps for tests which can be pretty easily updated. Right now the compiler notices if your partials are recursive, i.e. a partial eventually includes itself, and when it sees that it uses a DepthLimitedWriter at runtime in order to ensure that we don't blow up the stack. With the IndentWriter that behavior was removed. If we move to compile time for that stuff we should be able to get away without a writer though it is tricky. If you would rather I work on it, I can. |
I had the time to think about the allocation problem for a while now. Actually passing the indent as
After the final newline of The indentation can only be rendered when we render the next text, so we must keep in mind that the output is at the start of a line and keep a stack of indentations with each partial. This logic is basically what is already implemented with the For the whitespace-fixed version we currently need one allocation per partial call: The allocation of the The only other way I see is to have an implementation where we keep a stack of indents (e.g. an Array List) that we build up and take down during rendering. However this will make wrapping the the writer very complicated (e.g. for Another problem you mentioned was the reparsing of the output for new lines during rendering. I created #216 to avoid this problem. However I have to say I am not really happy with it because of the new complications described there. Summing up, I'd be happy to see a better solution by you, because after trying out a lot of approaches I don't feel I can improve mine anymore :-( |
Ran into the same problem when I tried to convert your patch. Thinking about it some more as it is really close. |
It's been almost a month now. Is there still any progress on this? If not it would be great to have at least the slow version of whitespace-correct mustache available so we can use it in our project (it does not affect the original implementation anyway). If this is not desired please tell me, then I'll create a fork and use that instead. |
Can you fork then for now? The issue is that if I merge this in I'll have to support this form of it going forward and I would rather have it natively support whitespace spec compliance. Just haven't had time to work on it and figure out how to handle the case we both ran into. |
This work builds upon #212 and finishes whitespace handling for all other spec cases.
All fixes are only in the parser. I took special care that the changes only take place if the "whitespace" flag is set. Otherwise the parser behaves exactly as before.