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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: line feeds without comments are being suppressed #15064
Comments
Hey @jlowcs! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly. If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite. |
This is expected. Changes in #14979. |
Kind of. We are using @svgr/cli to generate SVG React components, and it uses babel under the hood. So this change is suppressing all double line feeds in the output (which is supposed to still be readable). |
We can probably live without those, it's just not ideal 馃槄 |
Can you show a before and after file? |
before: /*
* This file is generated by icons/template.js
*/
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { COMMON, CommonProps } from '../constants';
import theme from '../theme';
import sizeStyle, { IconSizeProps } from '../lib/iconSize';
const SvgComponent = (props: React.SVGProps<SVGSVGElement>) => (
<svg width="1em" height="1em" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" role="img" {...props}>
<path
d="M255.708 445.235c-10.138 0-19.79-4.48-26.368-12.211L18.19 183.91c-12.34-14.54-10.523-36.352 4.018-48.691 14.567-12.365 36.353-10.573 48.717 3.993l184.808 218.01 185.013-218.01c12.314-14.54 34.176-16.332 48.692-3.993 14.566 12.365 16.358 34.176 3.993 48.717l-211.38 249.088a34.529 34.529 0 0 1-26.343 12.21"
fill="currentColor"
fillRule="evenodd"
/>
</svg>
);
type Props = CommonProps & IconSizeProps;
const SvgBracketDown = styled(SvgComponent)<Props>`
${sizeStyle}
${COMMON}
`;
SvgBracketDown.defaultProps = {
theme,
// override default role set to img on generated icons
role: 'none',
};
SvgBracketDown.propTypes = {
...sizeStyle.propTypes,
...COMMON.propTypes,
theme: PropTypes.object, // eslint-disable-line react/forbid-prop-types
};
SvgBracketDown.displayName = 'IconBracketDown';
export default SvgBracketDown; after: /*
* This file is generated by icons/template.js
*/
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { COMMON, CommonProps } from '../constants';
import theme from '../theme';
import sizeStyle, { IconSizeProps } from '../lib/iconSize';
const SvgComponent = (props: React.SVGProps<SVGSVGElement>) => (
<svg width="1em" height="1em" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg" role="img" {...props}>
<path
d="M255.708 445.235c-10.138 0-19.79-4.48-26.368-12.211L18.19 183.91c-12.34-14.54-10.523-36.352 4.018-48.691 14.567-12.365 36.353-10.573 48.717 3.993l184.808 218.01 185.013-218.01c12.314-14.54 34.176-16.332 48.692-3.993 14.566 12.365 16.358 34.176 3.993 48.717l-211.38 249.088a34.529 34.529 0 0 1-26.343 12.21"
fill="currentColor"
fillRule="evenodd"
/>
</svg>
);
type Props = CommonProps & IconSizeProps;
const SvgBracketDown = styled(SvgComponent)<Props>`
${sizeStyle}
${COMMON}
`;
SvgBracketDown.defaultProps = {
theme,
// override default role set to img on generated icons
role: 'none',
};
SvgBracketDown.propTypes = {
...sizeStyle.propTypes,
...COMMON.propTypes,
theme: PropTypes.object, // eslint-disable-line react/forbid-prop-types
};
SvgBracketDown.displayName = 'IconBracketDown';
export default SvgBracketDown; But tbh those files are a bit of a mess to begin with. Still, if we wanted to make them a bit better and easier to read, we'd still not be able to rely on line feeds. |
To be honest, it's all good for me. |
Babel currently does not preserve whitespaces because the AST does not record such information. You can give |
I was bitten by this issue too. After upgrading I can confirm that it was caused by @JLHwung, I don't get your comment. After looking into #14979, #15036 there was a lot of work done in The AST stores the location information for each node, and @babel/generator uses it to handle new lines for comments: https://github.com/babel/babel/blob/main/packages/babel-generator/src/printer.ts#L1023 |
@dfernandez79 |
@dfernandez79 |
Thank you for taking the time to answer. I'm looking into the SVGR project to see if I can set the At the moment I added that configuration to SVGR (it allows passing configuration to |
馃捇
How are you using Babel?
@babel/cli
Input code
REPL
Configuration file name
No response
Configuration
No response
Current and expected behavior
Current output:
Expected output:
Environment
Possible solution
No response
Additional context
This wasn't happening with 7.19.4.
The text was updated successfully, but these errors were encountered: