compiler
compiler copied to clipboard
🐛 BUG: Astro components convert last newline character (trailing newline at end-of-file) into a space
What version of astro are you using?
v1.0.0-beta.40
Are you using an SSR adapter? If so, which one?
None
What package manager are you using?
npm
What operating system are you using?
Linux
Describe the Bug
Astro components are not POSIX compliant because if you add a new empty line at the end of the file, it gets converted to a space.
This code (Foo.astro):
<>foo</>(\n, new line)
(EOF, empty line)

If you call it like <p><Foo /></p>, the result is <p>foo </p> (with an ending space that affects the html render).
POSIX define a line as:
3.206 Line A sequence of zero or more non-
<newline>characters plus a terminatingcharacter.
So astro components should let you finish the file with an empty new line. Astro maybe needs to call trim() internally so it gets deleted and not converted into a space.
Link to Minimal Reproducible Example
https://codesandbox.io/s/withered-breeze-9t904k?file=/src/pages/index.astro
Participation
- [ ] I am willing to submit a pull request for this issue.
This is a compiler issue, moving to that repo.
Finally closed in https://github.com/withastro/compiler/pull/698