소스 검색

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

pull/618/head
raymond.lam 9 년 전
부모
커밋
78ed7a0839
3개의 변경된 파일11개의 추가작업 그리고 7개의 파일을 삭제
  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 파일 보기

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


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


@@ -396,19 +396,21 @@
* This is specially necessary for when the value has been set to * This is specially necessary for when the value has been set to
* `undefined` and we want to avoid looking up parent contexts. * `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) if (index === names.length - 1)
lookupHit = hasProperty(value, names[index]);
lookupHit = hasProperty(intermediateValue, names[index]);


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


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


context = context.parent; context = context.parent;
} }


+ 1
- 0
test/_files/dot_notation.mustache 파일 보기

@@ -7,3 +7,4 @@
<h2>Test truthy false values:</h2> <h2>Test truthy false values:</h2>
<p>Zero: {{truthy.zero}}</p> <p>Zero: {{truthy.zero}}</p>
<p>False: {{truthy.notTrue}}</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 파일 보기

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

불러오는 중...
취소
저장