-
Notifications
You must be signed in to change notification settings - Fork 641
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 scoping issues with macros and includes. #667
Conversation
@oyyd I'd welcome your review on this, if you have time. |
@@ -831,7 +831,8 @@ var Compiler = Object.extend({ | |||
'[' + argNames.join(', ') + '], ', | |||
'[' + kwargNames.join(', ') + '], ', | |||
'function (' + realNames.join(', ') + ') {', | |||
'frame = frame.push(true);', | |||
'callerFrame = frame;', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be var callerFrame = frame;
? Global variables may cause potential bugs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good catch! That was just an oversight on my part. Will fix.
Hi @carljm. Everything looks good except the line of my comment. Good job 👍 |
Thanks for the review; corrected the accidental global variable. Merging. |
Fix scoping issues with macros and includes.
* 2.x: (43 commits) Bump versions for dev. Update maintenance docs. Revert accidental changes to mocha.js. Bump version to 2.4.0. Update changelog. Merge pull request #694 from mariusbuescher/master Add note about include and blocks; update wrapping of templating docs. Merge pull request #688 from pra85/patch-1 Rename all test templates to use .j2 extension. Update changelog. Revert "make include statements trigger async conversion inside if/for statements (fixes #372)" Merge pull request #672 from TrySound/yargs Update changelog. Split backported and non-backported portions of #667 in changelog. More acks in changelog. Merge pull request #668 from oyyd/cn-doc Don't allow included templates to write to the including scope. Update changelog for opts.dev fix. Split include tests. Fix references to env dev opt. ...
This improves the fix for #577 and #561, expanding the fix for the latter to also cover includes, as well as macros.
The previous fix for #577 (PR #653) didn't take into account nested scopes within macros, which would happily bypass the
isolate
property of their parent frame and go right up into the calling frame.A better fix for that is to make the macro frame actually completely isolated from the calling frame, breaking the parent relationship. This also fixes #666.
For includes (#561) we want included templates to see variables in the including scope, but we don't ever want to write to the including scope. So we still need an
isolateWrites
attr on the frame, but it's specific to writes only, and (unlike in #653) it is respected not only at the originating level of the write, but also if a write from a child frame tries to go through it to its parent.