From 044f5d3b5958fd64d5ba96ae2e27d98a60bfcc16 Mon Sep 17 00:00:00 2001 From: Seth Kinast Date: Wed, 8 Apr 2015 16:47:04 -0700 Subject: [PATCH] Fix behavior of `Context#resolve` when resolving a context function that returns a Chunk --- lib/dust.js | 6 +++--- test/jasmine-test/spec/coreTests.js | 33 +++++++++++++++++++---------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/lib/dust.js b/lib/dust.js index a55cbff9..4964441e 100644 --- a/lib/dust.js +++ b/lib/dust.js @@ -469,10 +469,10 @@ return body; } chunk = new Chunk().render(body, this); - if(!body.__dustBody) { - return chunk; + if(chunk instanceof Chunk) { + return chunk.data.join(''); // ie7 perf } - return chunk.data.join(''); // ie7 perf + return chunk; }; Context.prototype.getTemplateName = function() { diff --git a/test/jasmine-test/spec/coreTests.js b/test/jasmine-test/spec/coreTests.js index 16bac7e7..f297b8f4 100755 --- a/test/jasmine-test/spec/coreTests.js +++ b/test/jasmine-test/spec/coreTests.js @@ -267,26 +267,37 @@ var coreTests = [ }, { name: "context.resolve", - source: "{#foo bar=\"{baz} is baz \" literal=\"literal \" func=func chunkFunc=\"{chunkFunc}\" ref=ref}Fail{/foo}", + source: ['{#foo', + 'bar="{baz} is baz "', + 'literal="literal "', + 'func=func', + 'chunkFunc="{chunkFunc}"', + 'indirectChunkFunc=indirectChunkFunc', + 'ref=ref', + '}Fail{/foo}'].join(' '), context: { foo: function(chunk, context, bodies, params) { - chunk.write(context.resolve(params.bar)); - chunk.write(context.resolve(params.literal)); - chunk.write(context.resolve(params.func)); - chunk.write(context.resolve(params.chunkFunc)); - chunk.write(context.resolve(params.ref)); - return chunk; + chunk.write(context.resolve(params.bar)); + chunk.write(context.resolve(params.literal)); + chunk.write(context.resolve(params.func)); + chunk.write(context.resolve(params.chunkFunc)); + chunk.write(context.resolve(params.indirectChunkFunc)); + chunk.write(context.resolve(params.ref)); + return chunk; }, baz: "baz", ref: "ref", func: function() { - return "func "; + return "func "; }, chunkFunc: function(chunk) { - return chunk.write('chunk '); - } + return chunk.write('chunk '); + }, + indirectChunkFunc: function(chunk) { + return chunk.write('indirect '); + } }, - expected: "baz is baz literal func chunk ref", + expected: "baz is baz literal func chunk indirect ref", message: "context.resolve() taps parameters from the context" }, {