diff --git a/glass-easel-stylesheet-compiler/src/js_bindings.rs b/glass-easel-stylesheet-compiler/src/js_bindings.rs index 2a07720..2b2e084 100644 --- a/glass-easel-stylesheet-compiler/src/js_bindings.rs +++ b/glass-easel-stylesheet-compiler/src/js_bindings.rs @@ -50,7 +50,13 @@ pub struct StyleSheetTransformer { #[wasm_bindgen] impl StyleSheetTransformer { #[wasm_bindgen(constructor)] - pub fn new(name: &str, s: &str, class_prefix: Option, rpx_ratio: f32, host_is: Option) -> Self { + pub fn new( + name: &str, + s: &str, + class_prefix: Option, + rpx_ratio: f32, + host_is: Option, + ) -> Self { let mut sst = crate::StyleSheetTransformer::from_css( name, s, @@ -72,7 +78,9 @@ impl StyleSheetTransformer { let mut low_priority_content = String::new(); low_priority.write_str(&mut low_priority_content).unwrap(); let mut low_priority_source_map = Vec::new(); - low_priority.write_source_map(&mut low_priority_source_map).unwrap(); + low_priority + .write_source_map(&mut low_priority_source_map) + .unwrap(); Self { warnings, diff --git a/glass-easel-stylesheet-compiler/src/lib.rs b/glass-easel-stylesheet-compiler/src/lib.rs index 124c0a0..03af567 100644 --- a/glass-easel-stylesheet-compiler/src/lib.rs +++ b/glass-easel-stylesheet-compiler/src/lib.rs @@ -4,8 +4,8 @@ use cssparser::{CowRcStr, ParseError, ParserInput, Token}; pub mod error; pub mod js_bindings; -mod step; pub mod output; +mod step; use output::StyleSheetOutput; use step::{StepParser, StepToken}; @@ -89,11 +89,19 @@ impl StyleSheetTransformer { } fn current_output(&self) -> &StyleSheetOutput { - if self.using_low_priority { &self.low_priority_output } else { &self.normal_output } + if self.using_low_priority { + &self.low_priority_output + } else { + &self.normal_output + } } fn current_output_mut(&mut self) -> &mut StyleSheetOutput { - if self.using_low_priority { &mut self.low_priority_output } else { &mut self.normal_output } + if self.using_low_priority { + &mut self.low_priority_output + } else { + &mut self.normal_output + } } fn append_nested_block( @@ -139,8 +147,14 @@ impl StyleSheetTransformer { self.current_output_mut().append_token(token, src) } - fn append_token_space_preserved(&mut self, token: StepToken, _input: &mut StepParser, src: Option) { - self.current_output_mut().append_token_space_preserved(token, src) + fn append_token_space_preserved( + &mut self, + token: StepToken, + _input: &mut StepParser, + src: Option, + ) { + self.current_output_mut() + .append_token_space_preserved(token, src) } fn cur_output_utf8_len(&self) -> usize { @@ -373,7 +387,9 @@ fn parse_at_rule( let next = input.next()?; match next.token.clone() { Token::CurlyBracketBlock => { - let at_rule_str = ss.get_output_segment(output_index..ss.cur_output_utf8_len()).to_string(); + let at_rule_str = ss + .get_output_segment(output_index..ss.cur_output_utf8_len()) + .to_string(); ss.wrap_at_rule_output(input, at_rule_str, |ss, input| { let close = ss.append_nested_block(next, input); if contain_rule_list { @@ -432,14 +448,18 @@ fn parse_qualified_rule(input: &mut StepParser, ss: &mut StyleSheetTransformer) let quoted_host_is = Token::QuotedString(host_is.clone().into()); let r = input.try_parse::<_, _, ParseError<()>>(|input| { input.expect_colon()?; - let Ok(next) = input.next() else { return Ok(()) }; + let Ok(next) = input.next() else { + return Ok(()); + }; let mut invalid = match &*next { Token::Ident(x) if x.as_bytes() == b"host" => None, Token::Function(x) if x.as_bytes() == b"host" => Some(input.position()), - _ => { return Err(input.new_custom_error(())) } + _ => return Err(input.new_custom_error(())), }; let next = loop { - let Ok(next) = input.next() else { return Ok(()) }; + let Ok(next) = input.next() else { + return Ok(()); + }; if *next != Token::CurlyBracketBlock { if invalid.is_none() { invalid = Some(input.position()); @@ -449,17 +469,26 @@ fn parse_qualified_rule(input: &mut StepParser, ss: &mut StyleSheetTransformer) } }; if let Some(pos) = invalid { - ss.add_warning( - error::ParseErrorKind::HostSelectorCombination, - pos..pos, - ); + ss.add_warning(error::ParseErrorKind::HostSelectorCombination, pos..pos); } else { ss.write_in_low_priority(input, |ss, input| { - ss.append_token(StepToken::wrap_at(Token::SquareBracketBlock, &next), input, None); - ss.append_token(StepToken::wrap_at(Token::Ident("is".into()), &next), input, None); + ss.append_token( + StepToken::wrap_at(Token::SquareBracketBlock, &next), + input, + None, + ); + ss.append_token( + StepToken::wrap_at(Token::Ident("is".into()), &next), + input, + None, + ); ss.append_token(StepToken::wrap_at(Token::Delim('='), &next), input, None); ss.append_token(StepToken::wrap_at(quoted_host_is, &next), input, None); - ss.append_token(StepToken::wrap_at(Token::CloseSquareBracket, &next), input, None); + ss.append_token( + StepToken::wrap_at(Token::CloseSquareBracket, &next), + input, + None, + ); let close = ss.append_nested_block(next, input); convert_rpx_in_block(input, ss, None); ss.append_nested_block_close(close, input); @@ -468,7 +497,7 @@ fn parse_qualified_rule(input: &mut StepParser, ss: &mut StyleSheetTransformer) Ok(()) }); if r.is_ok() { - return + return; } } loop { @@ -909,21 +938,18 @@ mod test { ); assert_eq!( trans.warnings().map(|x| x.kind.clone()).collect::>(), - [error::ParseErrorKind::HostSelectorCombination, error::ParseErrorKind::HostSelectorCombination], + [ + error::ParseErrorKind::HostSelectorCombination, + error::ParseErrorKind::HostSelectorCombination + ], ); let (output, lp) = trans.output_and_low_priority_output(); let mut s = Vec::new(); output.write(&mut s).unwrap(); - assert_eq!( - std::str::from_utf8(&s).unwrap(), - r#".a{color:green}"# - ); + assert_eq!(std::str::from_utf8(&s).unwrap(), r#".a{color:green}"#); let mut s = Vec::new(); lp.write(&mut s).unwrap(); - assert_eq!( - std::str::from_utf8(&s).unwrap(), - r#""# - ); + assert_eq!(std::str::from_utf8(&s).unwrap(), r#""#); } #[test] diff --git a/glass-easel-stylesheet-compiler/src/main.rs b/glass-easel-stylesheet-compiler/src/main.rs index 8b928ba..9ca01dc 100644 --- a/glass-easel-stylesheet-compiler/src/main.rs +++ b/glass-easel-stylesheet-compiler/src/main.rs @@ -86,7 +86,8 @@ fn main() { let (output, low_priority_output) = sst.output_and_low_priority_output(); if let Some(output_file) = args.low_priority_output { - let output_file = fs::File::create(output_file).expect("Failed to open or create output file"); + let output_file = + fs::File::create(output_file).expect("Failed to open or create output file"); low_priority_output.write(output_file).unwrap(); } else { let mut s = Vec::new(); @@ -100,7 +101,8 @@ fn main() { } if let Some(output_file) = args.output { - let output_file = fs::File::create(output_file).expect("Failed to open or create output file"); + let output_file = + fs::File::create(output_file).expect("Failed to open or create output file"); output.write(output_file).unwrap(); } else { let mut s = Vec::new(); diff --git a/glass-easel-stylesheet-compiler/src/output.rs b/glass-easel-stylesheet-compiler/src/output.rs index 4eefaf8..3292761 100644 --- a/glass-easel-stylesheet-compiler/src/output.rs +++ b/glass-easel-stylesheet-compiler/src/output.rs @@ -1,6 +1,6 @@ use std::fmt::Write; -use cssparser::{TokenSerializationType, ToCss, Token}; +use cssparser::{ToCss, Token, TokenSerializationType}; use sourcemap::{SourceMap, SourceMapBuilder}; use crate::step::StepToken; @@ -85,11 +85,7 @@ impl StyleSheetOutput { self.utf16_len += str::encode_utf16(&self.s[output_start_pos..]).count() as u32; } - pub(crate) fn append_token_space_preserved( - &mut self, - token: StepToken, - src: Option, - ) { + pub(crate) fn append_token_space_preserved(&mut self, token: StepToken, src: Option) { if let Token::WhiteSpace(_) = &*token { self.prev_ser_type = token.serialization_type(); self.s.push(' '); diff --git a/glass-easel-template-compiler/src/parse/tag.rs b/glass-easel-template-compiler/src/parse/tag.rs index 2b8446c..3ed92c3 100644 --- a/glass-easel-template-compiler/src/parse/tag.rs +++ b/glass-easel-template-compiler/src/parse/tag.rs @@ -52,10 +52,7 @@ impl Template { if ps.peek_str(""); - ps.add_warning( - ParseErrorKind::InvalidEndTag, - pos..ps.position(), - ); + ps.add_warning(ParseErrorKind::InvalidEndTag, pos..ps.position()); } } @@ -2017,13 +2014,15 @@ impl Element { x } else { let location = end_tag_start_location.start..close_location.end; - ps.add_warning( - ParseErrorKind::InvalidEndTag, - location.clone(), - ); - Ident { name: CompactString::new(""), location } + ps.add_warning(ParseErrorKind::InvalidEndTag, location.clone()); + Ident { + name: CompactString::new(""), + location, + } }; - if end_tag_name.name.len() > 0 && end_tag_name.name != tag_name.name.to_ascii_lowercase() { + if end_tag_name.name.len() > 0 + && end_tag_name.name != tag_name.name.to_ascii_lowercase() + { return None; } ps.skip_whitespace(); @@ -3280,12 +3279,7 @@ mod test { ParseErrorKind::UnexpectedCharacter, 12..16 ); - case!( - "
", - r#"
"#, - ParseErrorKind::InvalidEndTag, - 5..7 - ); + case!("
", r#"
"#, ParseErrorKind::InvalidEndTag, 5..7); } #[test] diff --git a/glass-easel-template-compiler/src/stringify/tag.rs b/glass-easel-template-compiler/src/stringify/tag.rs index 87f283b..e19e778 100644 --- a/glass-easel-template-compiler/src/stringify/tag.rs +++ b/glass-easel-template-compiler/src/stringify/tag.rs @@ -232,7 +232,13 @@ impl Stringify for Element { "mark", attr.prefix_location.as_ref().unwrap_or(&attr.name.location), ); - write_attr(stringifier, Some(prefix), &attr.name, &attr.value, Some(attr.is_value_unspecified))?; + write_attr( + stringifier, + Some(prefix), + &attr.name, + &attr.value, + Some(attr.is_value_unspecified), + )?; } for ev in event_bindings.iter() { let prefix = if ev.is_catch { @@ -410,7 +416,13 @@ impl Stringify for Element { "model", attr.prefix_location.as_ref().unwrap_or(&attr.name.location), )); - write_attr(stringifier, prefix, &attr.name, &attr.value, Some(attr.is_value_unspecified))?; + write_attr( + stringifier, + prefix, + &attr.name, + &attr.value, + Some(attr.is_value_unspecified), + )?; } for attr in change_attributes.iter() { let prefix = ( @@ -435,7 +447,13 @@ impl Stringify for Element { "data", attr.prefix_location.as_ref().unwrap_or(&attr.name.location), ); - write_attr(stringifier, Some(prefix), &attr.name, &attr.value, Some(attr.is_value_unspecified))?; + write_attr( + stringifier, + Some(prefix), + &attr.name, + &attr.value, + Some(attr.is_value_unspecified), + )?; } for attr in generics.iter() { write_static_attr(