From 9167dfda7079fedfc4402ec1f4557ade8b0e2414 Mon Sep 17 00:00:00 2001 From: Seth Kinast Date: Mon, 27 Apr 2015 10:51:08 -0700 Subject: [PATCH] Evaluate truth test bodies inside a @select before resolving the select. Fixes #134 --- lib/dust-helpers.js | 8 ++++---- test/jasmine-test/spec/helpersTests.js | 21 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/dust-helpers.js b/lib/dust-helpers.js index 3a901e5..6eb3376 100644 --- a/lib/dust-helpers.js +++ b/lib/dust-helpers.js @@ -128,14 +128,14 @@ function filter(chunk, context, bodies, params, helperName, test) { value = coerce(context.resolve(params.value), type); if (test(key, value)) { + if(body) { + chunk = chunk.render(body, context); + } if (selectState) { selectState.isResolved = true; } - if(body) { - return chunk.render(body, context); - } } else if (skip) { - return chunk.render(skip, context); + chunk = chunk.render(skip, context); } return chunk; } diff --git a/test/jasmine-test/spec/helpersTests.js b/test/jasmine-test/spec/helpersTests.js index 0cd1a49..939a460 100644 --- a/test/jasmine-test/spec/helpersTests.js +++ b/test/jasmine-test/spec/helpersTests.js @@ -1061,6 +1061,27 @@ }, expected: "done done outside default default outside", message: "should test select helper with params in an outer section" + }, + { + name: "select with nested @eq", + source: ['{@select key=selectKey}', + '{@eq value=1}One', + '{@eq key=test value=5}Correct!{/eq}', + '{@select}', + '{@eq key=test value=5}InnerCorrect!{/eq}', + '{@eq key=test value=5}Bug! True, but inner select is resolved.{/eq}', + '{/select}', + '{/eq}', + '{@eq value=1}Bug! True, but select is resolved.{:else}Bug! Not false{/eq}', + '{@eq key=key value=2}Bug! True, but select is resolved.{:else}Bug! Not false{/eq}', + '{/select}'].join(''), + context: { + selectKey: 1, + test: 5, + key: 2 + }, + expected: "OneCorrect!InnerCorrect!", + message: "Truth tests should only be skipped at the top level of a select" } ] },