Skip to content

Commit

Permalink
Preserve compiler backwards compatibility with pre-2.7 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sethkinast committed Apr 18, 2015
1 parent 6fc3953 commit d47c299
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/dust.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,12 @@
Chunk.prototype.partial = function(elem, context, partialContext, params) {
var head;

if(params === undefined) {
// Compatibility for < 2.7.0 where `partialContext` did not exist
params = partialContext;
partialContext = context;
}

if (!dust.isEmptyObject(params)) {
partialContext = partialContext.clone();
head = partialContext.pop();
Expand Down
12 changes: 12 additions & 0 deletions test/jasmine-test/spec/coreTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,18 @@ var coreTests = [
expected: "Hello Mick! You have 30 new messages.",
message: "should test partial with dynamic name and a context"
},
{
name: "backcompat (< 2.7.0) compiler with no partial context",
source: '{#oldPartial/}',
context: { "name": "Mick",
"count": 30,
oldPartial: function(chunk, context, bodies, params) {
return chunk.partial("partial", context, params);
}
},
expected: "Hello Mick! You have 30 new messages.",
message: "should preserve partials backwards compatibility with compilers pre-2.7"
},
{
name: "partial with blocks and inline params",
source: '{>partial_with_blocks name=n count="{c}"/}',
Expand Down

0 comments on commit d47c299

Please sign in to comment.