Przeglądaj źródła

prevent value from being returned by Context.prototype.lookup if lookupHit is false

pull/618/head
raymond.lam 9 lat temu
rodzic
commit
78ed7a0839
3 zmienionych plików z 11 dodań i 7 usunięć
  1. +9
    -7
      mustache.js
  2. +1
    -0
      test/_files/dot_notation.mustache
  3. +1
    -0
      test/_files/dot_notation.txt

+ 9
- 7
mustache.js Wyświetl plik

@@ -377,11 +377,11 @@
if (cache.hasOwnProperty(name)) {
value = cache[name];
} else {
var context = this, names, index, lookupHit = false;
var context = this, intermediateValue, names, index, lookupHit = false;

while (context) {
if (name.indexOf('.') > 0) {
value = context.view;
intermediateValue = context.view;
names = name.split('.');
index = 0;

@@ -396,19 +396,21 @@
* This is specially necessary for when the value has been set to
* `undefined` and we want to avoid looking up parent contexts.
**/
while (value != null && index < names.length) {
while (intermediateValue != null && index < names.length) {
if (index === names.length - 1)
lookupHit = hasProperty(value, names[index]);
lookupHit = hasProperty(intermediateValue, names[index]);

value = value[names[index++]];
intermediateValue = intermediateValue[names[index++]];
}
} else {
value = context.view[name];
intermediateValue = context.view[name];
lookupHit = hasProperty(context.view, name);
}

if (lookupHit)
if (lookupHit) {
value = intermediateValue;
break;
}

context = context.parent;
}


+ 1
- 0
test/_files/dot_notation.mustache Wyświetl plik

@@ -7,3 +7,4 @@
<h2>Test truthy false values:</h2>
<p>Zero: {{truthy.zero}}</p>
<p>False: {{truthy.notTrue}}</p>
<p>length of string should not be rendered: {{price.currency.name.length}}</p>

+ 1
- 0
test/_files/dot_notation.txt Wyświetl plik

@@ -7,3 +7,4 @@
<h2>Test truthy false values:</h2>
<p>Zero: 0</p>
<p>False: false</p>
<p>length of string should not be rendered: </p>

Ładowanie…
Anuluj
Zapisz