Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dust.js has started outputting 'line,2 line,4 line,13 line,6' in weird places #556

Closed
lkmill opened this issue Mar 10, 2015 · 9 comments · Fixed by #557
Closed

Dust.js has started outputting 'line,2 line,4 line,13 line,6' in weird places #556

lkmill opened this issue Mar 10, 2015 · 9 comments · Fixed by #557
Labels

Comments

@lkmill
Copy link

lkmill commented Mar 10, 2015

Come DustJS 2.6.0 it has started outputting line,[number] in random places. It seems to be affected by the dust.config.whitespace setting. Weirdly enough I got the unwanted output when dust.config.whitespace = false on a DO droplet (Node v0.10.33), while I got it when dust.config.whitespace = true on my workstation. Downgrading to v2.5.1 resolved the problem.

I precompile all my templates.

I am pressed for time the coming weeks, but if nobody else is experiencing this I could dig some more to find out exactly where the error occurs.

@sethkinast
Copy link
Contributor

Thanks for the report. Can you provide a template that shows the issue?

@lkmill
Copy link
Author

lkmill commented Mar 10, 2015

Hi, seems to be for blocks containing only linebreaks. Not that you should have these all over the place, but many of my boilerplate logic seems to have them anyway.

dust.compile('{<test}\n{/test}{<test2}\n{/test2}', 'test')

outputs

(function(dust){
  dust.register("test",body_0);
  var blocks={"test":body_1,"test2":body_2};
  function body_0(chk,ctx){
    ctx=ctx.shiftBlocks(blocks);
    return chk;
  }
  body_0.__dustBody=!0;
  function body_1(chk,ctx){
    ctx=ctx.shiftBlocks(blocks);
    return chk.w("\nline,1");
  }
  body_1.__dustBody=!0;
  function body_2(chk,ctx){
    ctx=ctx.shiftBlocks(blocks);
    return chk.w("\nline,2");
  }
  body_2.__dustBody=!0;return body_0;
})(dust);

EDIT: i seem to be able to get the same error for all empty {<NAME}{/NAME} blocks on my live apps when compiling dust templates. could reproduce it using the simple example above though.

@sethkinast
Copy link
Contributor

Thanks, I know the commit to look at. Looks like this is an edge case that has never been tested.

That should be enough info for the problem to be fixed. Thanks again for the report.

@sethkinast
Copy link
Contributor

Repro:

echo "{<test}\n{/test}{<test2}\n{/test2}" | node_modules/.bin/dustc --name test --whitespace
INFO: No files to compile. Write template code and use ^D to exit
(function(dust){dust.register("test",body_0);var blocks={"test":body_1,"test2":body_2};function body_0(chk,ctx){ctx=ctx.shiftBlocks(blocks);return chk.w("\nline,1");}body_0.__dustBody=!0;function body_1(chk,ctx){ctx=ctx.shiftBlocks(blocks);return chk.w("\\n");}body_1.__dustBody=!0;function body_2(chk,ctx){ctx=ctx.shiftBlocks(blocks);return chk.w("\\n");}body_2.__dustBody=!0;return body_0;})(dust);

@sethkinast
Copy link
Contributor

Target commit 374bbdb

@sethkinast
Copy link
Contributor

Incidentally the dust.config.whitespace setting only affects the template compilation, not the rendering-- so that's why you were seeing it happen on both your desktop and server, because I assume you sent precompiled templates to the server.

@lkmill
Copy link
Author

lkmill commented Mar 10, 2015

Nah I wasnt, my Node applications compile all templates on start up. But
good to hear you know what's up.

On 10 March 2015 at 19:12, Seth Kinast notifications@github.com wrote:

Incidentally the dust.config.whitespace setting only affects the template
compilation, not the rendering-- so that's why you were seeing it happen on
both your desktop and server, because I assume you sent precompiled
templates to the server.


Reply to this email directly or view it on GitHub
#556 (comment).

sethkinast pushed a commit to sethkinast/dustjs that referenced this issue Mar 10, 2015
sethkinast pushed a commit to sethkinast/dustjs that referenced this issue Mar 10, 2015
…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 linkedin#531 since it's such an edge case.

Closes linkedin#556
sethkinast pushed a commit to sethkinast/dustjs that referenced this issue Mar 10, 2015
…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 linkedin#531 since it's such an edge case.

Closes linkedin#556
@sethkinast sethkinast added the bug label Mar 10, 2015
@sethkinast
Copy link
Contributor

We have released 2.6.1 with a fix. Thanks for taking the time to report!

@lkmill
Copy link
Author

lkmill commented Mar 12, 2015

Cheers!

On 12 March 2015 at 01:38, Seth Kinast notifications@github.com wrote:

We have released 2.6.1 with a fix. Thanks for taking the time to report!


Reply to this email directly or view it on GitHub
#556 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants