Skip to content

Commit

Permalink
Fix the output of format (whitespace-only) blocks inside inline parti…
Browse files Browse the repository at this point in the history
…als.

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
  • Loading branch information
Seth Kinast committed Mar 10, 2015
1 parent 6fffa4b commit 4cbe3a4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@
},

format: function(context, node) {
return '.w(' + escape(node[1] + node[2]) + ')';
return '.w(' + escape(node[1]) + ')';
},

reference: function(context, node) {
Expand Down
34 changes: 33 additions & 1 deletion test/jasmine-test/spec/coreTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}\n{/foo}{+foo/}",
context: {},
expected: "\n",
message: "whitespace on: whitespace-only block is preserved",
config: { whitespace: true }
},
{
name: "whitespace off: whitespace-only block",
source: "{<foo}\n{/foo}{+foo/}",
context: {},
expected: "",
message: "whitespace off: whitespace-only block is removed",
config: { whitespace: false }
},
{
name: "whitespace off: multiline text block runs together",
source: ["<p>",
" foo bar baz",
Expand Down

0 comments on commit 4cbe3a4

Please sign in to comment.