From c0de17778cd31208d5e1822713e0df0097b0ab22 Mon Sep 17 00:00:00 2001 From: Sahab Yazdani Date: Tue, 30 Nov 2010 19:53:56 -0800 Subject: [PATCH] Be smarter about when the parser context needs reconstruction. --- mustache.js | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/mustache.js b/mustache.js index 29a005a..c362e4b 100644 --- a/mustache.js +++ b/mustache.js @@ -451,13 +451,13 @@ var Mustache = function() { case '#': case '^': parserContext.stack[parserContext.stack.length-1].depth++; - parserContext.stack[parserContext.stack.length-1].content.push(parserContext.openTag + parserContext.token()); + parserContext.stack[parserContext.stack.length-1].content.push(parserContext.openTag, parserContext.token()); return 'endSectionScan'; case '/': parserContext.stack.push({tagType:'endSection'}); return 'simpleKeyName'; default: - parserContext.stack[parserContext.stack.length-1].content.push(parserContext.openTag + parserContext.token()); + parserContext.stack[parserContext.stack.length-1].content.push(parserContext.openTag, parserContext.token()); return 'endSectionScan'; } }, @@ -512,7 +512,7 @@ var Mustache = function() { if (--section.depth === 0) { if (section.key === key) { this.commandSet.section.call(this, section.sectionType, - section.content.join(''), + section.content, key, contextStack, parserContext.partials, @@ -524,7 +524,7 @@ var Mustache = function() { throw new ParserException('Unbalanced open/close section tags'); } } else { - section.content.push('{{/' + key + '}}'); + section.content.push('{{', '/', key, '}}'); parserContext.stack.push(section); @@ -634,7 +634,7 @@ var Mustache = function() { contextStack.pop(); } }, - section: function(sectionType, mustacheFragment, key, contextStack, partials, openTag, closeTag) { + section: function(sectionType, fragmentTokens, key, contextStack, partials, openTag, closeTag) { // by @langalex, support for arrays of strings var that = this; function create_context(_context) { @@ -659,29 +659,24 @@ var Mustache = function() { if (sectionType==='invertedSection') { if (!value || this.is_array(value) && value.length === 0) { // false or empty list, render it - tokens = this.tokenize(mustacheFragment, openTag, closeTag); - - this.parse(this.createParserContext(tokens, partials, openTag, closeTag), contextStack); + this.parse(this.createParserContext(fragmentTokens, partials, openTag, closeTag), contextStack); } } else if (sectionType==='section') { if (this.is_array(value)) { // Enumerable, Let's loop! - tokens = this.tokenize(mustacheFragment, openTag, closeTag); - for (var i=0, n=value.length; i