Skip to content

Typescript types with tagged template literals (TSX) result in awkward formatting #5697

@inlightmedia

Description

@inlightmedia

Prettier 1.15.3
Playground link

--parser babylon

Input:

const StyledH1 = styled.div<StyledComponentProps>`
	font-size: 2.5em;
	font-weight: ${(props) => (props.strong ? 500 : 100)};
	font-family: ${constants.text.displayFont.fontFamily};
	letter-spacing: ${(props) => (props.light ? '0.04em' : 0)};
	color: ${(props) => props.textColor};
	${(props) =>
		props.center
			? ` display: flex;
                align-items: center;
                justify-content: center;
                text-align: center;`
			: ''} @media (max-width: ${(props) => (props.noBreakPoint ? '0' : constants.layout.breakpoint.break1)}px) {
		font-size: 2em;
	}
`;

Output:

const StyledH1 =
  styled.div <
  StyledComponentProps >
  `
	font-size: 2.5em;
	font-weight: ${props => (props.strong ? 500 : 100)};
	font-family: ${constants.text.displayFont.fontFamily};
	letter-spacing: ${props => (props.light ? "0.04em" : 0)};
	color: ${props => props.textColor};
	${props =>
    props.center
      ? ` display: flex;
                align-items: center;
                justify-content: center;
                text-align: center;`
      : ""} @media (max-width: ${props =>
    props.noBreakPoint ? "0" : constants.layout.breakpoint.break1}px) {
		font-size: 2em;
	}
`;

Expected behavior:

My issue is with the very first line where it multi-lines the angled brackets.

const StyledH1 = styled.div<StyledComponentProps>`
	font-size: 2.5em;
	font-weight: ${(props) => (props.strong ? 500 : 100)};
	font-family: ${constants.text.displayFont.fontFamily};
	letter-spacing: ${(props) => (props.light ? '0.04em' : 0)};
	color: ${(props) => props.textColor};
	${(props) =>
		props.center
			? ` display: flex;
                align-items: center;
                justify-content: center;
                text-align: center;`
			: ''} @media (max-width: ${(props) => (props.noBreakPoint ? '0' : constants.layout.breakpoint.break1)}px) {
		font-size: 2em;
	}
`;

This happens in ts and tsx files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:multiparserIssues with printing one language inside another, like CSS-in-JSlang:css/scss/lessIssues affecting CSS, Less or SCSSlang:javascriptIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.priority:highCode is printed in a way that alters the AST, breaks syntax, or is a significant regression. Urgent!

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions