Permalink
Browse files

Merge pull request #643 from raymond-lam/issue617

Writer.prototype.parse to cache by tags in addition to template string
  • Loading branch information...
2 parents 23beb3a + 198a565 commit b283da5c8c26dbf78c357a1f67bfed26d18f5e32 @dasilvacontin dasilvacontin committed Aug 26, 2017
Showing with 33 additions and 1 deletion.
  1. +1 −1 mustache.js
  2. +32 −0 test/parse-test.js
View
@@ -447,7 +447,7 @@
var tokens = cache[template];
if (tokens == null)
- tokens = cache[template] = parseTemplate(template, tags);
+ tokens = cache[template + ':' + (tags || mustache.tags).join(':')] = parseTemplate(template, tags);
return tokens;
};
View
@@ -103,4 +103,36 @@ describe('Mustache.parse', function () {
});
});
+ describe('when parsing a template without tags specified followed by the same template with tags specified', function() {
+ it('returns different tokens for the latter parse', function() {
+ var template = "{{foo}}[bar]";
+ var parsedWithBraces = Mustache.parse(template);
+ var parsedWithBrackets = Mustache.parse(template, ['[', ']']);
+ assert.notDeepEqual(parsedWithBrackets, parsedWithBraces);
+ });
+ });
+
+ describe('when parsing a template with tags specified followed by the same template with different tags specified', function() {
+ it('returns different tokens for the latter parse', function() {
+ var template = "(foo)[bar]";
+ var parsedWithParens = Mustache.parse(template, ['(', ')']);
+ var parsedWithBrackets = Mustache.parse(template, ['[', ']']);
+ assert.notDeepEqual(parsedWithBrackets, parsedWithParens);
+ });
+ });
+
+ describe('when parsing a template after already having parsed that template with a different Mustache.tags', function() {
+ it('returns different tokens for the latter parse', function() {
+ var template = "{{foo}}[bar]";
+ var parsedWithBraces = Mustache.parse(template);
+
+ var oldTags = Mustache.tags;
+ Mustache.tags = ['[', ']'];
+ var parsedWithBrackets = Mustache.parse(template);
+ Mustache.tags = oldTags;
+
+ assert.notDeepEqual(parsedWithBrackets, parsedWithBraces);
+ });
+ });
+
});

0 comments on commit b283da5

Please sign in to comment.