Skip to content

Commit 79a9868

Browse files
authored
fix(fmt): allow expressions used as key-value pair in css template literals (#29369)
1 parent ffe8ce6 commit 79a9868

File tree

8 files changed

+19
-9
lines changed

8 files changed

+19
-9
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ dprint-core = "=0.67.4"
293293
dprint-plugin-json = "=0.20.0"
294294
dprint-plugin-jupyter = "=0.2.0"
295295
dprint-plugin-markdown = "=0.18.0"
296-
dprint-plugin-typescript = "=0.95.3"
296+
dprint-plugin-typescript = "=0.95.4"
297297
env_logger = "=0.11.6"
298298
eszip = "=0.88.0"
299299
fancy-regex = "=0.14.0"

cli/tools/fmt.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,11 +619,14 @@ fn format_embedded_css(
619619
ignore_file_comment_directive: "malva-ignore-file".into(),
620620
},
621621
};
622-
// Wraps the text in a css block of `a { ... }`
623-
// to make it valid css (scss)
622+
// Wraps the text in a css block of `a { ... ;}`
623+
// to make it valid css
624+
// Note: We choose LESS for the syntax because it allows us to use
625+
// @variable for both property values and mixins, which is convenient
626+
// for handling placeholders used as both properties and mixins.
624627
let text = malva::format_text(
625-
&format!("a{{\n{}\n}}", text),
626-
malva::Syntax::Scss,
628+
&format!("a{{\n{}\n;}}", text),
629+
malva::Syntax::Less,
627630
&options,
628631
)?;
629632
let mut buf = vec![];

tests/specs/fmt/external_formatter/badly_formatted.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ margin: 0.5rem;
88

99
&:not(:first-child) {
1010
${(props) => props.vertical ? "margin-top" : "margin-left"}: 1rem;
11+
${OTHER_STYLES};
1112
}
1213
}
1314
`;
@@ -16,7 +17,7 @@ cssString = css`
1617
border: 1px red solid;
1718
background-color: red;
1819
border-radius: 4px;
19-
`
20+
${OTHER_STYLES}`
2021

2122
nestedCssString = tw`
2223
animate-pulse
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Error formatting: [WILDLINE]syntax_error_in_css.js
2-
Error formatting tagged template literal at line 0: syntax error at line 3, col 10: component value is expected
2+
Error formatting tagged template literal at line 0: syntax error at line 1, col 1: expect token `(`, but found `{`
33
error: Failed to format 1 of 1 checked file

tests/specs/fmt/external_formatter/well_formatted.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const EqualDivider = styled.div`
88

99
&:not(:first-child) {
1010
${(props) => props.vertical ? "margin-top" : "margin-left"}: 1rem;
11+
${OTHER_STYLES};
1112
}
1213
}
1314
`;
@@ -16,6 +17,7 @@ cssString = css`
1617
border: 1px red solid;
1718
background-color: red;
1819
border-radius: 4px;
20+
${OTHER_STYLES};
1921
`;
2022

2123
nestedCssString = tw`

tests/specs/fmt/external_formatter/well_formatted_unstable_sql.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const EqualDivider = styled.div`
88

99
&:not(:first-child) {
1010
${(props) => props.vertical ? "margin-top" : "margin-left"}: 1rem;
11+
${OTHER_STYLES};
1112
}
1213
}
1314
`;
@@ -16,6 +17,7 @@ cssString = css`
1617
border: 1px red solid;
1718
background-color: red;
1819
border-radius: 4px;
20+
${OTHER_STYLES};
1921
`;
2022

2123
nestedCssString = tw`

tests/specs/fmt/external_formatter/well_formatted_use_tabs.out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const EqualDivider = styled.div`
88

99
&:not(:first-child) {
1010
${(props) => props.vertical ? "margin-top" : "margin-left"}: 1rem;
11+
${OTHER_STYLES};
1112
}
1213
}
1314
`;
@@ -16,6 +17,7 @@ cssString = css`
1617
border: 1px red solid;
1718
background-color: red;
1819
border-radius: 4px;
20+
${OTHER_STYLES};
1921
`;
2022

2123
nestedCssString = tw`

0 commit comments

Comments
 (0)