Open smaili opened 9 years ago
Include currently intentionally doesn't create a new scope, to allow you to "include" files containing variable declarations, function declarations, and mixins. Unfortunately, this leads to the problem you are describing. I think the best non-breaking ways of fixing this will be via the proposed import
syntax, which is more akin to ES6's import
syntax, and via ES6's let
keyword, which we should support in the future, and which could be made to follow the more restrictive scoping rules.
@ForbesLindesay, what's wrong with just checking whether there is a var
before the variable name? Or is that easier said than done?
True, if we did scope var
locally to the include, you could still assign without the bar to expose something to the rest of the template. It would be a huge breaking change at this point though.
Output:
As you can see,
includer
never gets past the first iteration due to theincludee
overwriting the value ofi
, which should not happen sinceincludee
'svar i = 0
should create a new scope.