Closed rschristian closed 2 years ago
Good catch. It looks like leading whitespace should be removed from JSXText nodes if it contains a newline, and likewise for trailing whitespace (babel repl examples):
value = value.replace(/(^\s*\n\s*|\s*\n\s*$)/g, '');
Ah, cheers. Might've forgotten to strip the trailing whitespace too.
Describe the bug New lines are replaced with a space character if they occur within a text node, but this is incorrect. New lines between tags and text nodes, regardless of whether they're in a text node, should be ignored.
To Reproduce
This is a format that tools like Prettier will generate, putting the punctuation on a new line after the end of the anchor tag. After building with WMR, however, this gets transformed into a space:
Expected behavior New lines between tags and text nodes should be ignored, no extra whitespace.
Bug occurs with:
wmr
orwmr start
(development)wmr build
(production)wmr serve
Additional context Just seems to be missing logic here: https://github.com/preactjs/wmr/blob/3401a9bfa6491d25108ad68688c067a7e17d0de5/packages/wmr/src/lib/acorn-traverse.js#L880-L894
Working on a fix myself and trying to see if there are any other inconsistencies at the moment.