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 issue #669: Rollback pull requests #643 and #664 #670

Merged
merged 1 commit into from
Aug 17, 2018
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
5 changes: 2 additions & 3 deletions mustache.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,10 @@
*/
Writer.prototype.parse = function parse (template, tags) {
var cache = this.cache;
var cacheKey = template + ':' + (tags || mustache.tags).join(':');
var tokens = cache[cacheKey];
var tokens = cache[template];

if (tokens == null)
tokens = cache[cacheKey] = parseTemplate(template, tags);
tokens = cache[template] = parseTemplate(template, tags);

return tokens;
};
Expand Down
47 changes: 0 additions & 47 deletions test/parse-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ var expectations = {
: [ [ '#', 'foo', 0, 8, [ [ '#', 'a', 11, 17, [ [ 'text', ' ', 18, 22 ], [ 'name', 'b', 22, 27 ], [ 'text', '\n', 27, 28 ] ], 30 ] ], 37 ] ]
};

beforeEach(function (){
Mustache.clearCache();
});

describe('Mustache.parse', function () {

for (var template in expectations) {
Expand Down Expand Up @@ -107,47 +103,4 @@ 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);
});
});

describe('when parsing a template with the same tags second time, return the cached tokens', function () {
it('returns the same tokens for the latter parse', function () {
var template = '{{foo}}[bar]';
var parsedResult1 = Mustache.parse(template);
var parsedResult2 = Mustache.parse(template);

assert.deepEqual(parsedResult1, parsedResult2);
assert.ok(parsedResult1 === parsedResult2);
});
});

});