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

Unexpected trimming of whitespace after loop #472

Closed
mlafeldt opened this issue Nov 4, 2021 · 3 comments · Fixed by #473
Closed

Unexpected trimming of whitespace after loop #472

mlafeldt opened this issue Nov 4, 2021 · 3 comments · Fixed by #473
Labels

Comments

@mlafeldt
Copy link

mlafeldt commented Nov 4, 2021

Given a template like this:

{{#each routes}}
import { default as {{this.handler}} } from '{{this.file_path}}'
{{/each}}

addEventListener('fetch', (event) => {
  event.respondWith(handleEvent(event))
})

handlebars 4.1.3 will remove the empty line after the loop (in fact, it will remove all empty lines if there are any):

import { default as __hello_handler } from './hello.js'
import { default as __world_index_handler } from './world/index.js'
import { default as __index_handler } from './index.js'
addEventListener('fetch', (event) => {
  event.respondWith(handleEvent(event))
})

I'm wondering why that happens though? I don't use ~ or anything else that controls whitespace. My understanding is that rendering should not change any non-templating bits.

@mlafeldt
Copy link
Author

mlafeldt commented Nov 4, 2021

Might be related to #468

@sunng87 sunng87 added the bug label Nov 4, 2021
@sunng87
Copy link
Owner

sunng87 commented Nov 4, 2021

I can reproduce this issue. Thanks for reporting.

It has something to do with our empty line trimming strategy. We should trim at most one line. I will create a fix in days.

sunng87 added a commit that referenced this issue Nov 5, 2021
fix: trim at most one line directives #472
@sunng87
Copy link
Owner

sunng87 commented Nov 6, 2021

Released in 4.1.4

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