Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix behavior of Context#resolve when resolving a context function that returns a Chunk #622

Merged
merged 1 commit into from
Apr 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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