Child and local scope handling by TemplateContext #48
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I believe this addresses the source of variables leaking into parent scope like in issue #45. This affects the
include
andfor
statements.One thing I did was change TemplateContext.EnterChildScope from returning a
Scope
to returningvoid
. This is because the TemplateContext.ReleaseScope method should be called and not theScope
object'sReleaseScope
. I want to encourage callers to use TemplateContext's Release Scope method. Calling code can still technically call the Scope object's ReleaseScope method directly by accessing it via the TemplateContext.LocalScope property, but the result of doing so is undefined behavior.This could be further refactored by introducing an interface that the Scope class would implement. The interface would not surface the
ReleaseScope
method. The TemplateContext.LocalScope property would be of this type of interface instead of Scope, and further guarding calling code calling TemplateContext.LocalScope.ReleaseScope directly.