From 4cbe3a409f66c8e8a640d5b0d490bdc173accc87 Mon Sep 17 00:00:00 2001 From: Seth Kinast Date: Tue, 10 Mar 2015 11:49:22 -0700 Subject: [PATCH] Fix the output of format (whitespace-only) blocks inside inline partials. When whitespace compression is on, format blocks are optimized away. When whitespace compression is off, format blocks are usually coerced into buffers. But if there are no buffers (which is basically only possible within an inline partial, since you're not going to compile a template that's a bunch of newlines and nothing else), we visit `compiler.nodes.format`, which didn't get updated as part of #531 since it's such an edge case. Closes #556 --- lib/compiler.js | 2 +- test/jasmine-test/spec/coreTests.js | 34 ++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index aebd15a4..e672e6f5 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -233,7 +233,7 @@ }, format: function(context, node) { - return '.w(' + escape(node[1] + node[2]) + ')'; + return '.w(' + escape(node[1]) + ')'; }, reference: function(context, node) { diff --git a/test/jasmine-test/spec/coreTests.js b/test/jasmine-test/spec/coreTests.js index 33202bac..94dd4e94 100755 --- a/test/jasmine-test/spec/coreTests.js +++ b/test/jasmine-test/spec/coreTests.js @@ -1776,7 +1776,39 @@ var coreTests = [ { name: "whitespace test", tests: [ - { + { + name: "whitespace on: whitespace-only template", + source: "\n ", + context: {}, + expected: "\n ", + message: "whitespace on: whitespace-only template is preserved", + config: { whitespace: true } + }, + { + name: "whitespace off: whitespace-only template", + source: "\n ", + context: {}, + expected: "", + message: "whitespace off: whitespace-only template is removed", + config: { whitespace: false } + }, + { + name: "whitespace on: whitespace-only block", + source: "{", " foo bar baz",