Skip to content

Commit

Permalink
feat(css_parser): better handling for Dimensions (#1375)
Browse files Browse the repository at this point in the history
  • Loading branch information
faultyserver authored Dec 30, 2023
1 parent 73c5244 commit 8061a77
Show file tree
Hide file tree
Showing 47 changed files with 4,863 additions and 4,486 deletions.
34 changes: 20 additions & 14 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.

58 changes: 29 additions & 29 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.

1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/css/any/dimension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ impl FormatRule<AnyCssDimension> for FormatAnyCssDimension {
match node {
AnyCssDimension::CssRegularDimension(node) => node.format().fmt(f),
AnyCssDimension::CssPercentage(node) => node.format().fmt(f),
AnyCssDimension::CssUnknownDimension(node) => node.format().fmt(f),
}
}
}
2 changes: 1 addition & 1 deletion crates/biome_css_formatter/src/css/value/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! This is a generated file. Don't modify it by hand! Run 'cargo codegen formatter' to re-generate the file.
pub(crate) mod number;
pub(crate) mod percent_dimension;
pub(crate) mod percentage;
pub(crate) mod ratio;
pub(crate) mod regular_dimension;
pub(crate) mod string;
pub(crate) mod unknown_dimension;
13 changes: 0 additions & 13 deletions crates/biome_css_formatter/src/css/value/percent_dimension.rs

This file was deleted.

4 changes: 2 additions & 2 deletions crates/biome_css_formatter/src/css/value/percentage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ pub(crate) struct FormatCssPercentage;
impl FormatNodeRule<CssPercentage> for FormatCssPercentage {
fn fmt_fields(&self, node: &CssPercentage, f: &mut CssFormatter) -> FormatResult<()> {
let CssPercentageFields {
value,
value_token,
reminder_token,
} = node.as_fields();

write!(f, [value.format(), reminder_token.format()])
write!(f, [value_token.format(), reminder_token.format()])
}
}
21 changes: 12 additions & 9 deletions crates/biome_css_formatter/src/css/value/regular_dimension.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
use crate::prelude::*;
use crate::{prelude::*, utils::string_utils::FormatTokenAsLowercase};
use biome_css_syntax::{CssRegularDimension, CssRegularDimensionFields};
use biome_formatter::write;

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

write!(f, [value.format()])?;

if let Ok(unit) = unit {
write!(f, [unit.format()])?;
}

Ok(())
write!(
f,
[
FormatTokenAsLowercase::from(value_token?),
FormatTokenAsLowercase::from(unit_token?),
]
)
}
}
23 changes: 23 additions & 0 deletions crates/biome_css_formatter/src/css/value/unknown_dimension.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use crate::{prelude::*, utils::string_utils::FormatTokenAsLowercase};
use biome_css_syntax::{CssUnknownDimension, CssUnknownDimensionFields};
use biome_formatter::write;

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

let var_name = write!(
f,
[
FormatTokenAsLowercase::from(value_token?),
FormatTokenAsLowercase::from(unit_token?),
]
);
var_name
}
}
24 changes: 12 additions & 12 deletions crates/biome_css_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3970,43 +3970,43 @@ impl IntoFormat<CssFormatContext> for biome_css_syntax::CssRegularDimension {
)
}
}
impl FormatRule<biome_css_syntax::CssPercentDimension>
for crate::css::value::percent_dimension::FormatCssPercentDimension
impl FormatRule<biome_css_syntax::CssUnknownDimension>
for crate::css::value::unknown_dimension::FormatCssUnknownDimension
{
type Context = CssFormatContext;
#[inline(always)]
fn fmt(
&self,
node: &biome_css_syntax::CssPercentDimension,
node: &biome_css_syntax::CssUnknownDimension,
f: &mut CssFormatter,
) -> FormatResult<()> {
FormatNodeRule::<biome_css_syntax::CssPercentDimension>::fmt(self, node, f)
FormatNodeRule::<biome_css_syntax::CssUnknownDimension>::fmt(self, node, f)
}
}
impl AsFormat<CssFormatContext> for biome_css_syntax::CssPercentDimension {
impl AsFormat<CssFormatContext> for biome_css_syntax::CssUnknownDimension {
type Format<'a> = FormatRefWithRule<
'a,
biome_css_syntax::CssPercentDimension,
crate::css::value::percent_dimension::FormatCssPercentDimension,
biome_css_syntax::CssUnknownDimension,
crate::css::value::unknown_dimension::FormatCssUnknownDimension,
>;
fn format(&self) -> Self::Format<'_> {
#![allow(clippy::default_constructed_unit_structs)]
FormatRefWithRule::new(
self,
crate::css::value::percent_dimension::FormatCssPercentDimension::default(),
crate::css::value::unknown_dimension::FormatCssUnknownDimension::default(),
)
}
}
impl IntoFormat<CssFormatContext> for biome_css_syntax::CssPercentDimension {
impl IntoFormat<CssFormatContext> for biome_css_syntax::CssUnknownDimension {
type Format = FormatOwnedWithRule<
biome_css_syntax::CssPercentDimension,
crate::css::value::percent_dimension::FormatCssPercentDimension,
biome_css_syntax::CssUnknownDimension,
crate::css::value::unknown_dimension::FormatCssUnknownDimension,
>;
fn into_format(self) -> Self::Format {
#![allow(clippy::default_constructed_unit_structs)]
FormatOwnedWithRule::new(
self,
crate::css::value::percent_dimension::FormatCssPercentDimension::default(),
crate::css::value::unknown_dimension::FormatCssUnknownDimension::default(),
)
}
}
Expand Down
7 changes: 5 additions & 2 deletions crates/biome_css_formatter/tests/quick_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ mod language {
// use this test check if your snippet prints as you wish, without using a snapshot
fn quick_test() {
let src = r#"
@container style(--responsive: true) { }
div {
prod: fn(100px);
prod: --fn(100px);
prod: --fn--fn(100px);
}
"#;
let parse = parse_css(src, CssParserOptions::default());
Expand Down
Loading

0 comments on commit 8061a77

Please sign in to comment.