linkedin/dustjs — pull request #174 by juliangoacher (2012-10-12 11:23:00+00:00)
Title: Fix path resolution in nested scopes.

This PR provides a fix for dotted path resolution within nested context scopes.

I've seen the discussion at https://github.com/linkedin/dustjs/issues/100 but still think there are good reasons for having this functionality.

Motivations:

* Variable names should be resolved in a consistent manner, there shouldn't be two different methods producing different results depending on whether the variable reference is judged to be a path or not.

* Variable name resolution could and should follow the same rules as used for nested scopes in Javascript.

Scopes can be nested in dust.js using Context.push(..). Nested scopes should be equivalent to the following JS:

var person = { name: 'John' };
var settee = { color: 'red' };
(function() {
var person = { name: 'Jack' };
(function() {
var person = { name: 'Harry' };
console.log( person.name, settee.color );
})();
console.log( person.name, settee.color );
})();

There is no confusion at any point here about which data item any variable name references, despite some names appearing in three different scopes. Using dotted notation doesn't in any way complicate the situation.

* We make heavy use of Context.push to create local template scopes without polluting the global scope, and often these scopes are nested 3 or 4 deep. It doesn't make sense that templates in a nested scope loose visibility of any variable that requires a dotted path reference, while keeping visibility of those variables that don't.

* The work arounds - {#breaking}{#the}{#path}{#into}{#sections} or using a helper - are ugly and unwieldy.

This PR also addresses problems with incorrect 'this' references when invoking function values.