Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(css_parser,css_formatter): distinguish regular, custom, and dashed identifiers #1353

Merged
merged 3 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 19 additions & 65 deletions crates/biome_css_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 30 additions & 84 deletions crates/biome_css_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/biome_css_formatter/src/css/any/declaration_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl FormatRule<AnyCssDeclarationName> for FormatAnyCssDeclarationName {
fn fmt(&self, node: &AnyCssDeclarationName, f: &mut CssFormatter) -> FormatResult<()> {
match node {
AnyCssDeclarationName::CssIdentifier(node) => node.format().fmt(f),
AnyCssDeclarationName::CssCustomProperty(node) => node.format().fmt(f),
AnyCssDeclarationName::CssDashedIdentifier(node) => node.format().fmt(f),
}
}
}
2 changes: 1 addition & 1 deletion crates/biome_css_formatter/src/css/any/keyframe_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ impl FormatRule<AnyCssKeyframeName> for FormatAnyCssKeyframeName {
type Context = CssFormatContext;
fn fmt(&self, node: &AnyCssKeyframeName, f: &mut CssFormatter) -> FormatResult<()> {
match node {
AnyCssKeyframeName::CssIdentifier(node) => node.format().fmt(f),
AnyCssKeyframeName::CssCustomIdentifier(node) => node.format().fmt(f),
AnyCssKeyframeName::CssString(node) => node.format().fmt(f),
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/biome_css_formatter/src/css/any/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ impl FormatRule<AnyCssValue> for FormatAnyCssValue {
fn fmt(&self, node: &AnyCssValue, f: &mut CssFormatter) -> FormatResult<()> {
match node {
AnyCssValue::CssIdentifier(node) => node.format().fmt(f),
AnyCssValue::CssCustomIdentifier(node) => node.format().fmt(f),
AnyCssValue::CssDashedIdentifier(node) => node.format().fmt(f),
AnyCssValue::CssString(node) => node.format().fmt(f),
AnyCssValue::CssNumber(node) => node.format().fmt(f),
AnyCssValue::AnyCssDimension(node) => node.format().fmt(f),
AnyCssValue::CssRatio(node) => node.format().fmt(f),
AnyCssValue::AnyCssFunction(node) => node.format().fmt(f),
AnyCssValue::CssCustomProperty(node) => node.format().fmt(f),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CssCustomProperty is now CssDashedIdentifier and just directly wraps the IDENT token, rather than wrapping around an entire CssIdentifier node. This seems to be how most other parsers are handling this as well (SWC, LightningCSS, etc.).

AnyCssValue::CssColor(node) => node.format().fmt(f),
}
}
Expand Down
13 changes: 13 additions & 0 deletions crates/biome_css_formatter/src/css/auxiliary/custom_identifier.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::prelude::*;
use biome_css_syntax::{CssCustomIdentifier, CssCustomIdentifierFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatCssCustomIdentifier;
impl FormatNodeRule<CssCustomIdentifier> for FormatCssCustomIdentifier {
fn fmt_fields(&self, node: &CssCustomIdentifier, f: &mut CssFormatter) -> FormatResult<()> {
let CssCustomIdentifierFields { value_token } = node.as_fields();

write!(f, [value_token.format()])
}
}
Loading
Loading