Open dfernandez79 opened 1 year ago
Previously babel didn't preserve newlines, it just added them forever. https://github.com/babel/babel/issues/15064#issuecomment-1351776560
SVGR allows passing options to Babel.
I tried this:
.svgrc
{
"typescript": true,
"jsx": {"babelConfig": {"retainLines": true}}
}
Then:
npx @svgr/cli test.svg
I get the output file using Typescript (so svgr is reading the config), but the retainLines
option didn't have any effect.
https://babeljs.io/docs/en/options#generatoropts Have you tried setting it as a generator option?
{"babelConfig": {generatoropts:{"retainLines": true}}}
retainLines
did not work for me.
Temporarily I'm fixing this by adding ${'\n'}
and then running prettier --write to fix the issue.
https://babeljs.io/docs/en/options#generatoropts Have you tried setting it as a generator option?
{"babelConfig": {generatoropts:{"retainLines": true}}}
Thanks for the suggestion! I tried it, but it didn't work:
{
"typescript": true,
"jsx": {
"babelConfig": { "generatorOpts": {"retainLines": true } }
}
}
@roni-castro-db thanks! that hack worked for me
I did some research.
.svgrrc
instead of .svgrc
.This sucks and I haven't thought of a good solution.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
💥 Regression Report
The upgrade of
@babel/generator
tov7.20.5
ignores new lines from the templateRelated Babel issue (closed as "won't fix"): https://github.com/babel/babel/issues/15064
The babel generator caused this issue. But, it will affect users of SVGR that are sensitive to the output format (ie. tests that compare SVGR output or lint checks). In theory, it shouldn't affect the runtime behavior.
Last working version
Worked up to version: 6.3.1 (==> it worked when @babel/generator resolves to pre-7.20, but you can reproduce this issue in 6.3.1 and a newer babel version that matches the semver in @svgr/core)
Stopped working in version: 6.5.1
Forcing NPM to use
@babel/generator
7.18.3 works.To Reproduce
Use a test file (like the one from the playground):
Then run
@svgr/cli
with the default options:Output:
The output ignores the new lines in the
defaultTemplate
: https://github.com/gregberge/svgr/blob/main/packages/babel-plugin-transform-svg-component/src/defaultTemplate.tsExpected behavior
The output should preserve the new lines of the template: