Skip to content

Commit

Permalink
Fix behavior of Context#resolve when resolving a context function t…
Browse files Browse the repository at this point in the history
…hat returns a Chunk
  • Loading branch information
Seth Kinast committed Apr 9, 2015
1 parent 5d44883 commit 044f5d3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
6 changes: 3 additions & 3 deletions lib/dust.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
33 changes: 22 additions & 11 deletions test/jasmine-test/spec/coreTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
{
Expand Down

0 comments on commit 044f5d3

Please sign in to comment.