Skip to content

Commit 4cbe3a4

Browse files
author
Seth Kinast
committed
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
1 parent 6fffa4b commit 4cbe3a4

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

lib/compiler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
},
234234

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

239239
reference: function(context, node) {

test/jasmine-test/spec/coreTests.js

+33-1
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,39 @@ var coreTests = [
17761776
{
17771777
name: "whitespace test",
17781778
tests: [
1779-
{
1779+
{
1780+
name: "whitespace on: whitespace-only template",
1781+
source: "\n ",
1782+
context: {},
1783+
expected: "\n ",
1784+
message: "whitespace on: whitespace-only template is preserved",
1785+
config: { whitespace: true }
1786+
},
1787+
{
1788+
name: "whitespace off: whitespace-only template",
1789+
source: "\n ",
1790+
context: {},
1791+
expected: "",
1792+
message: "whitespace off: whitespace-only template is removed",
1793+
config: { whitespace: false }
1794+
},
1795+
{
1796+
name: "whitespace on: whitespace-only block",
1797+
source: "{<foo}\n{/foo}{+foo/}",
1798+
context: {},
1799+
expected: "\n",
1800+
message: "whitespace on: whitespace-only block is preserved",
1801+
config: { whitespace: true }
1802+
},
1803+
{
1804+
name: "whitespace off: whitespace-only block",
1805+
source: "{<foo}\n{/foo}{+foo/}",
1806+
context: {},
1807+
expected: "",
1808+
message: "whitespace off: whitespace-only block is removed",
1809+
config: { whitespace: false }
1810+
},
1811+
{
17801812
name: "whitespace off: multiline text block runs together",
17811813
source: ["<p>",
17821814
" foo bar baz",

0 commit comments

Comments
 (0)