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

Writer.prototype.parse to cache by tags in addition to template string #643

Merged
merged 2 commits into from Aug 26, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion mustache.js
Expand Up @@ -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;
};
Expand Down
32 changes: 32 additions & 0 deletions test/parse-test.js
Expand Up @@ -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, ['(', ')']);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are parenthesis, not braces, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my bad. I'll fix it.


var oldTags = Mustache.tags;
Mustache.tags = ['[', ']'];
var parsedWithBrackets = Mustache.parse(template);
Mustache.tags = oldTags;

assert.notDeepEqual(parsedWithBrackets, parsedWithBraces);
});
});

});