From afbb2089db00e3ac9ad7841e61780f2a0f0fb3af Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 16 Jul 2010 22:18:16 -0400 Subject: [PATCH] pass all tests in both interpreter and compiler mode --- mustache.js | 62 +++++++++++++++++++++++++------------------ test/unit.compiler.js | 14 +++------- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/mustache.js b/mustache.js index ade8120..d830e55 100644 --- a/mustache.js +++ b/mustache.js @@ -575,19 +575,22 @@ var Mustache = function() { var result = value.call(contextStack[contextStack.length-1], mustacheFragment, function(resultFragment) { var tempStream = []; - var old_send_func = that.send_func; - that.send_func = function(text) { tempStream.push(text); }; + var old_send_func = that.user_send_func; + that.user_send_func = function(text) { tempStream.push(text); }; tokens = that.tokenize(resultFragment, openTag, closeTag); that.parse(that.createParserContext(tokens, partials, openTag, closeTag), contextStack); - that.send_func = old_send_func; + that.user_send_func = old_send_func; return tempStream.join(''); }); this.user_send_func(result); - } + } else if (value) { + tokens = this.tokenize(mustacheFragment, openTag, closeTag); + this.parse(this.createParserContext(tokens, partials, openTag, closeTag), contextStack); + } } else { throw new ParserException('Unknown section type ' + sectionType); } @@ -632,30 +635,35 @@ var Mustache = function() { throw new ParserException('Unknown partial \'' + key + '\''); } - var old_user_send_func = this.user_send_func; - var commands = []; - this.user_send_func = function(command) { commands.push(command); }; - - var tokens = this.tokenize(partials[key], openTag, closeTag); - this.parse(this.createParserContext(tokens, partials, openTag, closeTag), reserved); - - this.user_send_func = old_user_send_func; - - var that = this; - this.user_send_func(function(contextStack, send_func) { - var res = that.find_in_stack(key, contextStack); - if (that.is_object(res)) { - contextStack.push(res); - } + if (!this.is_function(partials[key])) { + var old_user_send_func = this.user_send_func; + var commands = []; + this.user_send_func = function(command) { commands.push(command); }; + + var tokens = this.tokenize(partials[key], openTag, closeTag); + partials[key] = function() {}; // blank out the paritals so that infinite recursion doesn't happen + this.parse(this.createParserContext(tokens, partials, openTag, closeTag), reserved); - for (var i=0,n=commands.length; ithis is an object\n

one of its attributes is a list

\n \n', + '\n

this is an object

\n

one of its attributes is a list

\n \n\n', 'Lazy match of Section and Inverted Section' ); }); @@ -536,15 +536,7 @@ test("Demo", function() { } }; - var expected_result = [ - '

Colors

', - ' ', - '' - ].join('\n'); + var expected_result = '

Colors

\n\n \n\n'; equals( Mustache.to_html(