diff --git a/crates/swc_css_ast/src/base.rs b/crates/swc_css_ast/src/base.rs index 41483f89dc24..5e4327191c87 100644 --- a/crates/swc_css_ast/src/base.rs +++ b/crates/swc_css_ast/src/base.rs @@ -88,65 +88,65 @@ pub struct ListOfComponentValues { pub enum ComponentValue { // No grammar #[tag("TokenAndSpan")] - PreservedToken(TokenAndSpan), + PreservedToken(Box), #[tag("Function")] - Function(Function), + Function(Box), #[tag("SimpleBlock")] - SimpleBlock(SimpleBlock), + SimpleBlock(Box), // Block Contents grammar #[tag("DeclarationOrAtRule")] - DeclarationOrAtRule(DeclarationOrAtRule), + DeclarationOrAtRule(Box), #[tag("Rule")] - Rule(Rule), + Rule(Box), #[tag("StyleBlock")] - StyleBlock(StyleBlock), + StyleBlock(Box), #[tag("KeyframeBlock")] - KeyframeBlock(KeyframeBlock), + KeyframeBlock(Box), // Arbitrary Contents grammar #[tag("Ident")] - Ident(Ident), + Ident(Box), #[tag("DashedIdent")] - DashedIdent(DashedIdent), + DashedIdent(Box), #[tag("String")] - Str(Str), + Str(Box), #[tag("Url")] - Url(Url), + Url(Box), #[tag("Integer")] - Integer(Integer), + Integer(Box), #[tag("Number")] - Number(Number), + Number(Box), #[tag("Percentage")] - Percentage(Percentage), + Percentage(Box), #[tag("Dimension")] - Dimension(Dimension), + Dimension(Box), #[tag("Ratio")] - Ratio(Ratio), + Ratio(Box), #[tag("UnicodeRange")] - UnicodeRange(UnicodeRange), + UnicodeRange(Box), #[tag("Color")] - Color(Color), + Color(Box), #[tag("AlphaValue")] - AlphaValue(AlphaValue), + AlphaValue(Box), #[tag("Hue")] - Hue(Hue), + Hue(Box), #[tag("CmykComponent")] - CmykComponent(CmykComponent), + CmykComponent(Box), #[tag("Delimiter")] - Delimiter(Delimiter), + Delimiter(Box), // Special function Contents grammar #[tag("CalcSum")] - CalcSum(CalcSum), + CalcSum(Box), #[tag("ComplexSelector")] - ComplexSelector(ComplexSelector), + ComplexSelector(Box), #[tag("LayerName")] - LayerName(LayerName), + LayerName(Box), #[tag("SupportsCondition")] - SupportsCondition(SupportsCondition), + SupportsCondition(Box), #[tag("Declaration")] - Declaration(Declaration), + Declaration(Box), } #[ast_node] diff --git a/crates/swc_css_ast/src/token.rs b/crates/swc_css_ast/src/token.rs index fad76ed6f68f..cba51899df7c 100644 --- a/crates/swc_css_ast/src/token.rs +++ b/crates/swc_css_ast/src/token.rs @@ -35,6 +35,21 @@ pub enum NumberType { Number, } +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EqIgnoreSpan)] +#[cfg_attr( + feature = "rkyv", + derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize) +)] +pub struct DimensionToken { + pub value: f64, + pub raw_value: Atom, + #[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))] + pub unit: JsWord, + #[serde(rename = "type")] + pub type_flag: NumberType, + pub raw_unit: Atom, +} + #[derive(Debug, Clone, PartialEq, Serialize, Deserialize, EqIgnoreSpan)] #[cfg_attr( feature = "rkyv", @@ -54,20 +69,17 @@ pub enum Token { value: JsWord, raw: Atom, }, - Function { #[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))] value: JsWord, raw: Atom, }, - /// `@` AtKeyword { #[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))] value: JsWord, raw: Atom, }, - /// `#` Hash { is_id: bool, @@ -75,95 +87,62 @@ pub enum Token { value: JsWord, raw: Atom, }, - String { #[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))] value: JsWord, raw: Atom, }, - BadString { - raw_value: Atom, + raw: Atom, }, - /// `url(value)` Url { - #[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))] - name: JsWord, - raw_name: Atom, #[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))] value: JsWord, - raw_value: Atom, + /// Name and value + raw: Box<(Atom, Atom)>, }, - BadUrl { - #[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))] - name: JsWord, - raw_name: Atom, - raw_value: Atom, + raw: Atom, }, - Delim { value: char, }, - Number { value: f64, raw: Atom, #[serde(rename = "type")] type_flag: NumberType, }, - Percentage { value: f64, raw: Atom, }, - - Dimension { - value: f64, - raw_value: Atom, - #[cfg_attr(feature = "rkyv", with(swc_atoms::EncodeJsWord))] - unit: JsWord, - raw_unit: Atom, - #[serde(rename = "type")] - type_flag: NumberType, - }, - + Dimension(Box), /// One or more whitespace. WhiteSpace { value: Atom, }, - /// `` CDC, - /// `:`` Colon, - /// `;` Semi, - /// `,` Comma, - /// `[` LBracket, - /// `]` RBracket, - /// `(` LParen, - /// `)` RParen, - /// `{` LBrace, - /// `}` RBrace, } @@ -187,40 +166,36 @@ impl Hash for Token { } match self { - Token::Ident { value, raw } - | Token::Function { value, raw } - | Token::AtKeyword { value, raw } - | Token::String { value, raw } => { + Token::Ident { value, raw } => { value.hash(state); raw.hash(state); } - Token::BadString { raw_value } => { - raw_value.hash(state); + Token::Function { value, raw } => { + value.hash(state); + raw.hash(state); + } + Token::AtKeyword { value, raw } => { + value.hash(state); + raw.hash(state); + } + Token::String { value, raw } => { + value.hash(state); + raw.hash(state); + } + Token::BadString { raw } => { + raw.hash(state); } Token::Hash { value, raw, is_id } => { value.hash(state); raw.hash(state); is_id.hash(state); } - Token::Url { - name, - raw_name, - value, - raw_value, - } => { - name.hash(state); - raw_name.hash(state); + Token::Url { value, raw } => { value.hash(state); - raw_value.hash(state); + raw.hash(state); } - Token::BadUrl { - name, - raw_name, - raw_value, - } => { - name.hash(state); - raw_name.hash(state); - raw_value.hash(state); + Token::BadUrl { raw, .. } => { + raw.hash(state); } Token::Delim { value } => { value.hash(state); @@ -238,20 +213,14 @@ impl Hash for Token { integer_decode(*value).hash(state); raw.hash(state); } - Token::Dimension { - value, - raw_value, - unit, - raw_unit, - type_flag, - } => { - integer_decode(*value).hash(state); - raw_value.hash(state); - unit.hash(state); - raw_unit.hash(state); - type_flag.hash(state); + Token::Dimension(dimension) => { + integer_decode(dimension.value).hash(state); + dimension.unit.hash(state); + dimension.type_flag.hash(state); + dimension.raw_value.hash(state); + dimension.raw_unit.hash(state); } - Token::WhiteSpace { value } => { + Token::WhiteSpace { value, .. } => { value.hash(state); } Token::CDO diff --git a/crates/swc_css_codegen/src/lib.rs b/crates/swc_css_codegen/src/lib.rs index d4782526aea3..1cdbbc16396a 100644 --- a/crates/swc_css_codegen/src/lib.rs +++ b/crates/swc_css_codegen/src/lib.rs @@ -1159,32 +1159,62 @@ where let need_delim = match node { ComponentValue::SimpleBlock(_) | ComponentValue::Function(_) - | ComponentValue::Color(Color::Function(_)) - | ComponentValue::Color(Color::AbsoluteColorBase( - AbsoluteColorBase::Function(_), - )) | ComponentValue::Delimiter(_) | ComponentValue::Str(_) | ComponentValue::Url(_) | ComponentValue::Percentage(_) => match next { - Some(ComponentValue::Delimiter(Delimiter { - value: DelimiterValue::Comma, - .. - })) => false, + Some(ComponentValue::Delimiter(delimiter)) + if matches!( + **delimiter, + Delimiter { + value: DelimiterValue::Comma, + .. + } + ) => + { + false + } _ => !self.config.minify, }, + ComponentValue::Color(color) + if matches!( + **color, + Color::AbsoluteColorBase(AbsoluteColorBase::Function(_)) + | Color::Function(_) + ) => + { + match next { + Some(ComponentValue::Delimiter(delimiter)) + if matches!( + **delimiter, + Delimiter { + value: DelimiterValue::Comma, + .. + } + ) => + { + false + } + _ => !self.config.minify, + } + } ComponentValue::Ident(_) | ComponentValue::DashedIdent(_) => match next { - Some(ComponentValue::SimpleBlock(SimpleBlock { name, .. })) => { - if name.token == Token::LParen { + Some(ComponentValue::SimpleBlock(simple_block)) => { + if simple_block.name.token == Token::LParen { true } else { !self.config.minify } } - Some(ComponentValue::Color(Color::AbsoluteColorBase( - AbsoluteColorBase::HexColor(_), - ))) - | Some(ComponentValue::Str(_)) => !self.config.minify, + Some(ComponentValue::Color(color)) + if matches!( + **color, + Color::AbsoluteColorBase(AbsoluteColorBase::HexColor(_),) + ) => + { + !self.config.minify + } + Some(ComponentValue::Str(_)) => !self.config.minify, Some(ComponentValue::Delimiter(_)) => false, Some(ComponentValue::Number(n)) => { if self.config.minify { @@ -1197,7 +1227,7 @@ where } Some(ComponentValue::Dimension(dimension)) => { if self.config.minify { - let value = match dimension { + let value = match &**dimension { Dimension::Length(i) => i.value.value, Dimension::Angle(i) => i.value.value, Dimension::Time(i) => i.value.value, @@ -1217,10 +1247,15 @@ where _ => true, }, _ => match next { - Some(ComponentValue::SimpleBlock(_)) - | Some(ComponentValue::Color(Color::AbsoluteColorBase( - AbsoluteColorBase::HexColor(_), - ))) => !self.config.minify, + Some(ComponentValue::SimpleBlock(_)) => !self.config.minify, + Some(ComponentValue::Color(color)) + if matches!( + &**color, + Color::AbsoluteColorBase(AbsoluteColorBase::HexColor(_)) + ) => + { + !self.config.minify + } Some(ComponentValue::Delimiter(_)) => false, _ => true, }, @@ -1320,8 +1355,8 @@ where formatting_newline!(self); decrease_indent!(self); } - ComponentValue::StyleBlock(i) => { - match i { + ComponentValue::StyleBlock(node) => { + match &**node { StyleBlock::AtRule(_) | StyleBlock::QualifiedRule(_) => { formatting_newline!(self); } @@ -1346,8 +1381,8 @@ where decrease_indent!(self); } - ComponentValue::DeclarationOrAtRule(i) => { - match i { + ComponentValue::DeclarationOrAtRule(node) => { + match &**node { DeclarationOrAtRule::AtRule(_) => { formatting_newline!(self); } @@ -1955,15 +1990,12 @@ where write_raw!(self, span, &percentage); } - Token::Dimension { - raw_value, - raw_unit, - .. - } => { - let mut dimension = String::with_capacity(raw_value.len() + raw_unit.len()); + Token::Dimension(token) => { + let mut dimension = + String::with_capacity(token.raw_value.len() + token.raw_unit.len()); - dimension.push_str(raw_value); - dimension.push_str(raw_unit); + dimension.push_str(&token.raw_value); + dimension.push_str(&token.raw_unit); write_raw!(self, span, &dimension); } @@ -1978,39 +2010,24 @@ where write_raw!(self, span, &function); } - Token::BadString { raw_value } => { - write_str!(self, span, raw_value); + Token::BadString { raw } => { + write_str!(self, span, raw); } Token::String { raw, .. } => { write_str!(self, span, raw); } - Token::Url { - raw_name, - raw_value, - .. - } => { - let mut url = String::with_capacity(raw_name.len() + raw_value.len() + 2); + Token::Url { raw, .. } => { + let mut url = String::with_capacity(raw.0.len() + raw.1.len() + 2); - url.push_str(raw_name); + url.push_str(&raw.0); url.push('('); - url.push_str(raw_value); + url.push_str(&raw.1); url.push(')'); write_str!(self, span, &url); } - Token::BadUrl { - raw_name, - raw_value, - .. - } => { - let mut bad_url = String::with_capacity(raw_value.len() + 2); - - bad_url.push_str(raw_name); - bad_url.push('('); - bad_url.push_str(raw_value); - bad_url.push(')'); - - write_str!(self, span, &bad_url); + Token::BadUrl { raw, .. } => { + write_str!(self, span, raw); } Token::Comma => { write_raw!(self, span, ","); @@ -2035,7 +2052,7 @@ where write_raw!(self, span, &hash); } - Token::WhiteSpace { value, .. } => { + Token::WhiteSpace { value } => { write_str!(self, span, value); } Token::CDC => { diff --git a/crates/swc_css_codegen/tests/fixture.rs b/crates/swc_css_codegen/tests/fixture.rs index c0fa305aa557..4fd5a859e97d 100644 --- a/crates/swc_css_codegen/tests/fixture.rs +++ b/crates/swc_css_codegen/tests/fixture.rs @@ -233,12 +233,12 @@ impl VisitMut for NormalizeTest { n.visit_mut_children_with(self); match n { - ComponentValue::Number(Number { value, .. }) if value.fract() == 0.0 => { - *n = ComponentValue::Integer(Integer { + ComponentValue::Number(number) if number.value.fract() == 0.0 => { + *n = ComponentValue::Integer(Box::new(Integer { span: Default::default(), - value: value.round() as i64, + value: number.value.round() as i64, raw: None, - }) + })) } _ => {} } @@ -382,7 +382,7 @@ impl VisitMut for NormalizeTest { n.visit_mut_children_with(self); if let Token::WhiteSpace { .. } = &n.token { - n.token = Token::WhiteSpace { value: "".into() } + n.token = Token::WhiteSpace { value: "".into() }; } } diff --git a/crates/swc_css_codegen/tests/fixture/values/url/1/input.css b/crates/swc_css_codegen/tests/fixture/values/url/1/input.css index a01c4913e9e0..d89c6d8dfefb 100644 --- a/crates/swc_css_codegen/tests/fixture/values/url/1/input.css +++ b/crates/swc_css_codegen/tests/fixture/values/url/1/input.css @@ -63,3 +63,7 @@ div { .foo { background: url(__ident__); } + +.foo { + background: url(foo bar); +} diff --git a/crates/swc_css_codegen/tests/fixture/values/url/1/output.css b/crates/swc_css_codegen/tests/fixture/values/url/1/output.css index c30d0aa65477..5c87d7219ba0 100644 --- a/crates/swc_css_codegen/tests/fixture/values/url/1/output.css +++ b/crates/swc_css_codegen/tests/fixture/values/url/1/output.css @@ -53,3 +53,6 @@ div { .foo { background: url(__ident__); } +.foo { + background: url(foo bar); +} diff --git a/crates/swc_css_codegen/tests/fixture/values/url/1/output.min.css b/crates/swc_css_codegen/tests/fixture/values/url/1/output.min.css index f83e944c74a9..bc74529286bb 100644 --- a/crates/swc_css_codegen/tests/fixture/values/url/1/output.min.css +++ b/crates/swc_css_codegen/tests/fixture/values/url/1/output.min.css @@ -1 +1 @@ -div{background:url(https://example.com/image.png);background:url(https://example.com/image.png);background:url(https://example.com/image.png);background:url("https://example.com/image.png");background:url("https://example.com/image.png");background:url("https://example.com/image.png");background:url("https://example.com/image.png");background:url(data:image/png;base64,iRxVB0);background:url(#IDofSVGpath);background:url("//aa.com/img.svg"prefetch);background:url("//aa.com/img.svg"foo bar baz func(test));background:url("http://example.com/image.svg"param(--color var(--primary-color)));background:url();background:url("");background:url("");--foo:"http://www.example.com/pinkish.gif";background:src("http://www.example.com/pinkish.gif");background:src("http://www.example.com/pinkish.gif");background:src(var(--foo));background:url(https://example.com/image.png);background:url(https://example.com/image.png);background:url(https://example.com/image.png);background:url(https://example.com/image.png);background:url(image.png힙)}div{background:url(foo.img)red}*{background:url("foo");background:url("f o");background:url("f o");background:url("foo)");background:url("(foo");background:url("(foo)");background:url('"foo"')}.bar{background:url(http://example.com/image.svg param(--color var(--primary-color)))}.baz{background:url("http://example.com/image.svg"param(--color var(--primary-color)))}.foo{background:url(__ident__)} +div{background:url(https://example.com/image.png);background:url(https://example.com/image.png);background:url(https://example.com/image.png);background:url("https://example.com/image.png");background:url("https://example.com/image.png");background:url("https://example.com/image.png");background:url("https://example.com/image.png");background:url(data:image/png;base64,iRxVB0);background:url(#IDofSVGpath);background:url("//aa.com/img.svg"prefetch);background:url("//aa.com/img.svg"foo bar baz func(test));background:url("http://example.com/image.svg"param(--color var(--primary-color)));background:url();background:url("");background:url("");--foo:"http://www.example.com/pinkish.gif";background:src("http://www.example.com/pinkish.gif");background:src("http://www.example.com/pinkish.gif");background:src(var(--foo));background:url(https://example.com/image.png);background:url(https://example.com/image.png);background:url(https://example.com/image.png);background:url(https://example.com/image.png);background:url(image.png힙)}div{background:url(foo.img)red}*{background:url("foo");background:url("f o");background:url("f o");background:url("foo)");background:url("(foo");background:url("(foo)");background:url('"foo"')}.bar{background:url(http://example.com/image.svg param(--color var(--primary-color)))}.baz{background:url("http://example.com/image.svg"param(--color var(--primary-color)))}.foo{background:url(__ident__)}.foo{background:url(foo bar)} diff --git a/crates/swc_css_compat/src/lib.rs b/crates/swc_css_compat/src/lib.rs index 3e9f0997d54b..485214058c30 100644 --- a/crates/swc_css_compat/src/lib.rs +++ b/crates/swc_css_compat/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(box_patterns)] #![allow(clippy::vec_box)] pub mod nesting; diff --git a/crates/swc_css_compat/src/nesting.rs b/crates/swc_css_compat/src/nesting.rs index 45c09b1659b5..c5b79a172da4 100644 --- a/crates/swc_css_compat/src/nesting.rs +++ b/crates/swc_css_compat/src/nesting.rs @@ -231,14 +231,14 @@ impl NestingHandler { for value in rule.block.value.take() { match value { - ComponentValue::StyleBlock(StyleBlock::QualifiedRule(mut nested)) => { + ComponentValue::StyleBlock(box StyleBlock::QualifiedRule(mut nested)) => { self.process_prelude(&rule.prelude, &mut nested.prelude); nested_rules.push(Rule::QualifiedRule(nested)); continue; } - ComponentValue::StyleBlock(StyleBlock::AtRule(ref at_rule)) => { + ComponentValue::StyleBlock(box StyleBlock::AtRule(ref at_rule)) => { if let Some( AtRulePrelude::MediaPrelude(..) | AtRulePrelude::SupportsPrelude(..) @@ -252,7 +252,9 @@ impl NestingHandler { for n in &block.value { match n { - ComponentValue::StyleBlock(StyleBlock::QualifiedRule(n)) => { + ComponentValue::StyleBlock(box StyleBlock::QualifiedRule( + n, + )) => { let mut q = n.clone(); self.process_prelude(&rule.prelude, &mut q.prelude); @@ -284,7 +286,9 @@ impl NestingHandler { nested_of_media.insert( 0, - ComponentValue::StyleBlock(StyleBlock::QualifiedRule(rule)), + ComponentValue::StyleBlock(Box::new( + StyleBlock::QualifiedRule(rule), + )), ); } @@ -340,12 +344,14 @@ impl VisitMut for NestingHandler { for n in n.take() { match n { - ComponentValue::StyleBlock(StyleBlock::QualifiedRule(mut n)) => { + ComponentValue::StyleBlock(box StyleBlock::QualifiedRule(mut n)) => { let mut rules = self.extract_nested_rules(&mut n); rules.visit_mut_with(self); - new.push(ComponentValue::StyleBlock(StyleBlock::QualifiedRule(n))); + new.push(ComponentValue::StyleBlock(Box::new( + StyleBlock::QualifiedRule(n), + ))); new.extend(rules.into_iter().map(rule_to_component_value)); } @@ -361,8 +367,10 @@ impl VisitMut for NestingHandler { fn rule_to_component_value(rule: Rule) -> ComponentValue { match rule { - Rule::QualifiedRule(q) => ComponentValue::StyleBlock(StyleBlock::QualifiedRule(q)), - Rule::AtRule(r) => ComponentValue::StyleBlock(StyleBlock::AtRule(r)), - Rule::ListOfComponentValues(..) => ComponentValue::Rule(rule), + Rule::QualifiedRule(q) => { + ComponentValue::StyleBlock(Box::new(StyleBlock::QualifiedRule(q))) + } + Rule::AtRule(r) => ComponentValue::StyleBlock(Box::new(StyleBlock::AtRule(r))), + Rule::ListOfComponentValues(..) => ComponentValue::Rule(Box::new(rule)), } } diff --git a/crates/swc_css_lints/src/rules/font_family_no_duplicate_names.rs b/crates/swc_css_lints/src/rules/font_family_no_duplicate_names.rs index 423e053250f2..a7ebf0838756 100644 --- a/crates/swc_css_lints/src/rules/font_family_no_duplicate_names.rs +++ b/crates/swc_css_lints/src/rules/font_family_no_duplicate_names.rs @@ -47,7 +47,7 @@ impl FontFamilyNoDuplicateNames { Option::<(String, Span)>::None, ), |(mut fonts, last_identifier), item| match item { - ComponentValue::Ident(Ident { value, span, .. }) => { + ComponentValue::Ident(box Ident { value, span, .. }) => { if let Some((mut identifier, last_span)) = last_identifier { identifier.push(' '); identifier.push_str(value); @@ -56,7 +56,7 @@ impl FontFamilyNoDuplicateNames { (fonts, Some((value.to_string(), *span))) } } - ComponentValue::Str(Str { + ComponentValue::Str(box Str { raw: Some(raw), span, .. @@ -64,7 +64,7 @@ impl FontFamilyNoDuplicateNames { fonts.push((FontNameKind::from(raw), *span)); (fonts, None) } - ComponentValue::Delimiter(Delimiter { + ComponentValue::Delimiter(box Delimiter { value: DelimiterValue::Comma, .. }) => { diff --git a/crates/swc_css_lints/src/rules/unit_no_unknown.rs b/crates/swc_css_lints/src/rules/unit_no_unknown.rs index 1c8d2594a3e3..1dc832834c32 100644 --- a/crates/swc_css_lints/src/rules/unit_no_unknown.rs +++ b/crates/swc_css_lints/src/rules/unit_no_unknown.rs @@ -51,8 +51,8 @@ impl Visit for UnitNoUnknown { fn visit_component_value(&mut self, component_value: &ComponentValue) { if let ComponentValue::PreservedToken( - token_and_span @ TokenAndSpan { - token: Token::Dimension { unit, .. }, + token_and_span @ box TokenAndSpan { + token: Token::Dimension(box DimensionToken { unit, .. }), .. }, ) = component_value diff --git a/crates/swc_css_minifier/src/compressor/alpha_value.rs b/crates/swc_css_minifier/src/compressor/alpha_value.rs index 1444b468f615..6caeda8961d5 100644 --- a/crates/swc_css_minifier/src/compressor/alpha_value.rs +++ b/crates/swc_css_minifier/src/compressor/alpha_value.rs @@ -48,17 +48,17 @@ impl Compressor { } match component_value { - ComponentValue::Percentage(Percentage { + ComponentValue::Percentage(box Percentage { span, value: number, }) if number.value % 10.0 == 0.0 => { let new_value = number.value / 100.0; - *component_value = ComponentValue::Number(Number { + *component_value = ComponentValue::Number(Box::new(Number { span: *span, value: new_value, raw: None, - }); + })); } _ => {} } diff --git a/crates/swc_css_minifier/src/compressor/angle.rs b/crates/swc_css_minifier/src/compressor/angle.rs index e2bf64db8094..7bae189ba893 100644 --- a/crates/swc_css_minifier/src/compressor/angle.rs +++ b/crates/swc_css_minifier/src/compressor/angle.rs @@ -12,7 +12,7 @@ impl Compressor { ) { if self.ctx.in_transform_function { match &component_value { - ComponentValue::Dimension(Dimension::Angle(Angle { + ComponentValue::Dimension(box Dimension::Angle(Angle { value: Number { value: number_value, @@ -21,11 +21,11 @@ impl Compressor { span, .. })) if *number_value == 0.0 => { - *component_value = ComponentValue::Number(Number { + *component_value = ComponentValue::Number(Box::new(Number { span: *span, value: 0.0, raw: None, - }); + })); } _ => {} } diff --git a/crates/swc_css_minifier/src/compressor/calc_sum.rs b/crates/swc_css_minifier/src/compressor/calc_sum.rs index 4386152b5934..77bc5ba1d854 100644 --- a/crates/swc_css_minifier/src/compressor/calc_sum.rs +++ b/crates/swc_css_minifier/src/compressor/calc_sum.rs @@ -977,11 +977,11 @@ impl Compressor { match &component_value { // Transform "calc(calc-sum)" into "simple value" when calc-sum is not a complex // expression - ComponentValue::Function(Function { name, value, .. }) + ComponentValue::Function(box Function { name, value, .. }) if is_calc_function_name(name) && value.len() == 1 => { match &value[0] { - ComponentValue::CalcSum(CalcSum { + ComponentValue::CalcSum(box CalcSum { expressions: calc_sum_expressions, .. }) if calc_sum_expressions.len() == 1 => match &calc_sum_expressions[0] { diff --git a/crates/swc_css_minifier/src/compressor/color.rs b/crates/swc_css_minifier/src/compressor/color.rs index 6119c74227a0..d2f7011726a7 100644 --- a/crates/swc_css_minifier/src/compressor/color.rs +++ b/crates/swc_css_minifier/src/compressor/color.rs @@ -162,34 +162,34 @@ macro_rules! make_color { raw: None, }, value: vec![ - ComponentValue::Number(Number { + ComponentValue::Number(Box::new(Number { span: DUMMY_SP, value: r, raw: None, - }), - ComponentValue::Delimiter(Delimiter { + })), + ComponentValue::Delimiter(Box::new(Delimiter { span: DUMMY_SP, value: DelimiterValue::Comma, - }), - ComponentValue::Number(Number { + })), + ComponentValue::Number(Box::new(Number { span: DUMMY_SP, value: g, raw: None, - }), - ComponentValue::Delimiter(Delimiter { + })), + ComponentValue::Delimiter(Box::new(Delimiter { span: DUMMY_SP, value: DelimiterValue::Comma, - }), - ComponentValue::Number(Number { + })), + ComponentValue::Number(Box::new(Number { span: DUMMY_SP, value: b, raw: None, - }), - ComponentValue::Delimiter(Delimiter { + })), + ComponentValue::Delimiter(Box::new(Delimiter { span: DUMMY_SP, value: DelimiterValue::Comma, - }), - ComponentValue::AlphaValue(alpha_value), + })), + ComponentValue::AlphaValue(Box::new(alpha_value)), ], })) } @@ -262,7 +262,7 @@ impl Compressor { fn get_alpha_value(&self, alpha_value: Option<&&ComponentValue>) -> Option { match alpha_value { - Some(ComponentValue::AlphaValue(AlphaValue::Number(Number { value, .. }))) => { + Some(ComponentValue::AlphaValue(box AlphaValue::Number(Number { value, .. }))) => { if *value > 1.0 { return Some(1.0); } else if *value < 0.0 { @@ -271,7 +271,7 @@ impl Compressor { Some(*value) } - Some(ComponentValue::AlphaValue(AlphaValue::Percentage(Percentage { + Some(ComponentValue::AlphaValue(box AlphaValue::Percentage(Percentage { value: Number { value, .. }, .. }))) => { @@ -283,7 +283,7 @@ impl Compressor { Some(*value / 100.0) } - Some(ComponentValue::Ident(Ident { value, .. })) + Some(ComponentValue::Ident(box Ident { value, .. })) if value.to_ascii_lowercase() == js_word!("none") => { Some(0.0) @@ -295,7 +295,7 @@ impl Compressor { fn get_hue(&self, hue: Option<&&ComponentValue>) -> Option { match hue { - Some(ComponentValue::Hue(hue)) => { + Some(ComponentValue::Hue(box hue)) => { let mut value = match hue { Hue::Number(Number { value, .. }) => *value, Hue::Angle(Angle { @@ -320,7 +320,7 @@ impl Compressor { Some(value) } - Some(ComponentValue::Ident(Ident { value, .. })) + Some(ComponentValue::Ident(box Ident { value, .. })) if value.to_ascii_lowercase() == js_word!("none") => { Some(0.0) @@ -331,7 +331,7 @@ impl Compressor { fn get_percentage(&self, percentage: Option<&&ComponentValue>) -> Option { match percentage { - Some(ComponentValue::Percentage(Percentage { + Some(ComponentValue::Percentage(box Percentage { value: Number { value, .. }, .. })) => { @@ -343,7 +343,7 @@ impl Compressor { Some(*value / 100.0) } - Some(ComponentValue::Ident(Ident { value, .. })) + Some(ComponentValue::Ident(box Ident { value, .. })) if value.to_ascii_lowercase() == js_word!("none") => { Some(0.0) @@ -357,7 +357,7 @@ impl Compressor { number_or_percentage: Option<&&ComponentValue>, ) -> Option { match number_or_percentage { - Some(ComponentValue::Number(Number { value, .. })) => { + Some(ComponentValue::Number(box Number { value, .. })) => { if *value > 255.0 { return Some(255.0); } else if *value < 0.0 { @@ -366,7 +366,7 @@ impl Compressor { Some(*value) } - Some(ComponentValue::Percentage(Percentage { + Some(ComponentValue::Percentage(box Percentage { value: Number { value, .. }, .. })) => { @@ -378,7 +378,7 @@ impl Compressor { Some((2.55 * *value).round()) } - Some(ComponentValue::Ident(Ident { value, .. })) + Some(ComponentValue::Ident(box Ident { value, .. })) if value.to_ascii_lowercase() == js_word!("none") => { Some(0.0) @@ -435,7 +435,7 @@ impl Compressor { .filter(|n| { !matches!( n, - ComponentValue::Delimiter(Delimiter { + ComponentValue::Delimiter(box Delimiter { value: DelimiterValue::Comma | DelimiterValue::Solidus, .. }) @@ -473,7 +473,7 @@ impl Compressor { .filter(|n| { !matches!( n, - ComponentValue::Delimiter(Delimiter { + ComponentValue::Delimiter(box Delimiter { value: DelimiterValue::Comma | DelimiterValue::Solidus, .. }) @@ -513,7 +513,7 @@ impl Compressor { .filter(|n| { !matches!( n, - ComponentValue::Delimiter(Delimiter { + ComponentValue::Delimiter(box Delimiter { value: DelimiterValue::Comma | DelimiterValue::Solidus, .. }) diff --git a/crates/swc_css_minifier/src/compressor/container.rs b/crates/swc_css_minifier/src/compressor/container.rs index 45e64b331119..5e850c8ee008 100644 --- a/crates/swc_css_minifier/src/compressor/container.rs +++ b/crates/swc_css_minifier/src/compressor/container.rs @@ -10,7 +10,7 @@ impl Compressor { if is_calc_function_name(name) && value.len() == 1 => { match &value[0] { - ComponentValue::CalcSum(CalcSum { + ComponentValue::CalcSum(box CalcSum { expressions: calc_sum_expressions, .. }) if calc_sum_expressions.len() == 1 => match &calc_sum_expressions[0] { @@ -23,13 +23,13 @@ impl Compressor { { match transform_calc_value_into_component_value(calc_value) { Some(ComponentValue::Function(function)) => { - *n = SizeFeatureValue::Function(function); + *n = SizeFeatureValue::Function(*function); } Some(ComponentValue::Dimension(dimension)) => { - *n = SizeFeatureValue::Dimension(dimension); + *n = SizeFeatureValue::Dimension(*dimension); } Some(ComponentValue::Number(number)) => { - *n = SizeFeatureValue::Number(number); + *n = SizeFeatureValue::Number(*number); } _ => {} } diff --git a/crates/swc_css_minifier/src/compressor/declaration.rs b/crates/swc_css_minifier/src/compressor/declaration.rs index 06d6fc43bceb..7bda7d80d493 100644 --- a/crates/swc_css_minifier/src/compressor/declaration.rs +++ b/crates/swc_css_minifier/src/compressor/declaration.rs @@ -15,7 +15,7 @@ impl Compressor { for value in declaration.value.iter() { match value { - outside_node @ ComponentValue::Ident(Ident { value, .. }) + outside_node @ ComponentValue::Ident(box Ident { value, .. }) if matches!( value.to_ascii_lowercase(), js_word!("block") | js_word!("inline") | js_word!("run-in") @@ -23,7 +23,7 @@ impl Compressor { { outside = Some(outside_node); } - inside_node @ ComponentValue::Ident(Ident { value, .. }) + inside_node @ ComponentValue::Ident(box Ident { value, .. }) if matches!( value.to_ascii_lowercase(), js_word!("flow") @@ -36,10 +36,11 @@ impl Compressor { { inside = Some(inside_node); } - list_item_node @ ComponentValue::Ident(Ident { value, .. }) + list_item_node @ ComponentValue::Ident(box Ident { value, .. }) if value.to_ascii_lowercase() == js_word!("list-item") => { - if let Some(ComponentValue::Ident(Ident { value, .. })) = inside { + if let Some(ComponentValue::Ident(box Ident { value, .. })) = inside + { if !matches!( value.to_ascii_lowercase(), js_word!("flow") | js_word!("flow-root") @@ -60,7 +61,7 @@ impl Compressor { // `run-in flow` -> `run-in` ( Some(outside), - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: inside_value, .. })), @@ -70,12 +71,12 @@ impl Compressor { } // `block flow-root` -> `flow-root` ( - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: outside_value, .. })), Some( - inside @ ComponentValue::Ident(Ident { + inside @ ComponentValue::Ident(box Ident { value: inside_value, .. }), @@ -88,12 +89,12 @@ impl Compressor { } // `inline flow-root` -> `inline-block` ( - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: outside_value, span, .. })), - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: inside_value, .. })), @@ -101,19 +102,19 @@ impl Compressor { ) if outside_value.to_ascii_lowercase() == js_word!("inline") && inside_value.to_ascii_lowercase() == js_word!("flow-root") => { - declaration.value = vec![ComponentValue::Ident(Ident { + declaration.value = vec![ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("inline-block"), raw: None, - })]; + }))]; } // `block flow list-item` -> `list-item` ( - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: outside_value, .. })), - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: inside_value, .. })), @@ -125,7 +126,7 @@ impl Compressor { } // `block list-item` -> `list-item` ( - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: outside_value, .. })), @@ -137,7 +138,7 @@ impl Compressor { // `flow list-item` -> `list-item` ( None, - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: inside_value, .. })), @@ -148,12 +149,12 @@ impl Compressor { // `inline flow list-item` -> `inline list-item` ( Some( - outside @ ComponentValue::Ident(Ident { + outside @ ComponentValue::Ident(box Ident { value: outside_value, .. }), ), - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: inside_value, .. })), @@ -167,12 +168,12 @@ impl Compressor { // `block grid` -> `grid` // `block table` -> `table` ( - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: outside_value, .. })), Some( - inside @ ComponentValue::Ident(Ident { + inside @ ComponentValue::Ident(box Ident { value: inside_value, .. }), @@ -188,12 +189,12 @@ impl Compressor { } // `inline ruby` -> `ruby` ( - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: outside_value, .. })), Some( - inside @ ComponentValue::Ident(Ident { + inside @ ComponentValue::Ident(box Ident { value: inside_value, .. }), @@ -334,23 +335,23 @@ impl Compressor { .take() .into_iter() .map(|node| match node { - ComponentValue::Ident(Ident { value, span, .. }) + ComponentValue::Ident(box Ident { value, span, .. }) if value.to_ascii_lowercase() == js_word!("normal") => { - ComponentValue::Number(Number { + ComponentValue::Number(Box::new(Number { span, value: 400.0, raw: None, - }) + })) } - ComponentValue::Ident(Ident { value, span, .. }) + ComponentValue::Ident(box Ident { value, span, .. }) if value.to_ascii_lowercase() == js_word!("bold") => { - ComponentValue::Number(Number { + ComponentValue::Number(Box::new(Number { span, value: 700.0, raw: None, - }) + })) } _ => node, }) @@ -365,12 +366,12 @@ impl Compressor { let second = declaration.value.get(1); if let ( - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { span, value: first_value, .. })), - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: second_value, .. })), @@ -381,18 +382,18 @@ impl Compressor { second_value.to_ascii_lowercase(), ) { (js_word!("repeat"), js_word!("no-repeat")) => { - declaration.value = vec![ComponentValue::Ident(Ident { + declaration.value = vec![ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("repeat-x"), raw: None, - })]; + }))]; } (js_word!("no-repeat"), js_word!("repeat")) => { - declaration.value = vec![ComponentValue::Ident(Ident { + declaration.value = vec![ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("repeat-y"), raw: None, - })]; + }))]; } (js_word!("repeat"), js_word!("repeat")) | (js_word!("space"), js_word!("space")) @@ -436,17 +437,17 @@ impl Compressor { declaration.value.insert( 0, if self.is_ident_shorter_than_str(to_be_identify) { - ComponentValue::Ident(Ident { + ComponentValue::Ident(Box::new(Ident { span: ident.span, value: to_be_identify.into(), raw: None, - }) + })) } else { - ComponentValue::Str(Str { + ComponentValue::Str(Box::new(Str { span: ident.span, value: to_be_identify.into(), raw: None, - }) + })) }, ); } @@ -469,17 +470,17 @@ impl Compressor { } to_be_identify => { if self.is_ident_shorter_than_str(to_be_identify) { - ComponentValue::Ident(Ident { + ComponentValue::Ident(Box::new(Ident { span: ident.span, value: to_be_identify.into(), raw: None, - }) + })) } else { - ComponentValue::Str(Str { + ComponentValue::Str(Box::new(Str { span: ident.span, value: to_be_identify.into(), raw: None, - }) + })) } } } @@ -500,12 +501,12 @@ impl Compressor { ) -> bool { match (node_1, node_2) { ( - Some(ComponentValue::Dimension(Dimension::Length(Length { + Some(ComponentValue::Dimension(box Dimension::Length(Length { value: value_1, unit: unit_1, .. }))), - Some(ComponentValue::Dimension(Dimension::Length(Length { + Some(ComponentValue::Dimension(box Dimension::Length(Length { value: value_2, unit: unit_2, .. @@ -516,15 +517,15 @@ impl Compressor { true } ( - Some(ComponentValue::Integer(Integer { value: 0, .. })), - Some(ComponentValue::Integer(Integer { value: 0, .. })), + Some(ComponentValue::Integer(box Integer { value: 0, .. })), + Some(ComponentValue::Integer(box Integer { value: 0, .. })), ) => true, ( - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: first_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: second_number, .. })), @@ -540,12 +541,12 @@ impl Compressor { ) -> bool { match (node_1, node_2) { ( - Some(ComponentValue::Dimension(Dimension::Length(Length { + Some(ComponentValue::Dimension(box Dimension::Length(Length { value: value_1, unit: unit_1, .. }))), - Some(ComponentValue::Dimension(Dimension::Length(Length { + Some(ComponentValue::Dimension(box Dimension::Length(Length { value: value_2, unit: unit_2, .. @@ -556,19 +557,19 @@ impl Compressor { true } ( - Some(ComponentValue::Percentage(Percentage { value: value_1, .. })), - Some(ComponentValue::Percentage(Percentage { value: value_2, .. })), + Some(ComponentValue::Percentage(box Percentage { value: value_1, .. })), + Some(ComponentValue::Percentage(box Percentage { value: value_2, .. })), ) if value_1.value == value_2.value => true, ( - Some(ComponentValue::Integer(Integer { value: 0, .. })), - Some(ComponentValue::Integer(Integer { value: 0, .. })), + Some(ComponentValue::Integer(box Integer { value: 0, .. })), + Some(ComponentValue::Integer(box Integer { value: 0, .. })), ) => true, ( - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: first_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: second_number, .. })), @@ -583,8 +584,8 @@ impl Compressor { node_2: Option<&ComponentValue>, ) -> bool { matches!((node_1, node_2), ( - Some(ComponentValue::Ident(Ident { value: value_1, .. })), - Some(ComponentValue::Ident(Ident { value: value_2, .. })), + Some(ComponentValue::Ident(box Ident { value: value_1, .. })), + Some(ComponentValue::Ident(box Ident { value: value_2, .. })), ) if value_1.to_ascii_lowercase() == value_2.to_ascii_lowercase()) } } diff --git a/crates/swc_css_minifier/src/compressor/easing_function.rs b/crates/swc_css_minifier/src/compressor/easing_function.rs index 29da26532bc1..75c4865bf4d2 100644 --- a/crates/swc_css_minifier/src/compressor/easing_function.rs +++ b/crates/swc_css_minifier/src/compressor/easing_function.rs @@ -6,7 +6,7 @@ use super::Compressor; impl Compressor { pub(super) fn compress_easing_function(&mut self, component_value: &mut ComponentValue) { match component_value { - ComponentValue::Function(Function { + ComponentValue::Function(box Function { name, value: function_value, span, @@ -14,10 +14,10 @@ impl Compressor { && function_value.len() == 7 => { if let ( - ComponentValue::Number(Number { value: first, .. }), - ComponentValue::Number(Number { value: second, .. }), - ComponentValue::Number(Number { value: third, .. }), - ComponentValue::Number(Number { value: fourth, .. }), + ComponentValue::Number(box Number { value: first, .. }), + ComponentValue::Number(box Number { value: second, .. }), + ComponentValue::Number(box Number { value: third, .. }), + ComponentValue::Number(box Number { value: fourth, .. }), ) = ( &function_value[0], &function_value[2], @@ -25,39 +25,39 @@ impl Compressor { &function_value[6], ) { if *first == 0.0 && *second == 0.0 && *third == 1.0 && *fourth == 1.0 { - *component_value = ComponentValue::Ident(Ident { + *component_value = ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("linear"), raw: None, - }) + })) } else if *first == 0.25 && *second == 0.1 && *third == 0.25 && *fourth == 1.0 { - *component_value = ComponentValue::Ident(Ident { + *component_value = ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("ease"), raw: None, - }) + })) } else if *first == 0.42 && *second == 0.0 && *third == 1.0 && *fourth == 1.0 { - *component_value = ComponentValue::Ident(Ident { + *component_value = ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("ease-in"), raw: None, - }) + })) } else if *first == 0.0 && *second == 0.0 && *third == 0.58 && *fourth == 1.0 { - *component_value = ComponentValue::Ident(Ident { + *component_value = ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("ease-out"), raw: None, - }) + })) } else if *first == 0.42 && *second == 0.0 && *third == 0.58 && *fourth == 1.0 { - *component_value = ComponentValue::Ident(Ident { + *component_value = ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("ease-in-out"), raw: None, - }) + })) } } } - ComponentValue::Function(Function { + ComponentValue::Function(box Function { name, value: function_value, span, @@ -66,45 +66,45 @@ impl Compressor { { match (&function_value[0], &function_value[2]) { ( - ComponentValue::Number(Number { + ComponentValue::Number(box Number { value: number_value, .. }), - ComponentValue::Ident(Ident { + ComponentValue::Ident(box Ident { value: ident_value, .. }), ) if *number_value == 1.0 => match ident_value.to_ascii_lowercase() { js_word!("start") | js_word!("jump-start") => { - *component_value = ComponentValue::Ident(Ident { + *component_value = ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("step-start"), raw: None, - }) + })) } js_word!("end") | js_word!("jump-end") => { - *component_value = ComponentValue::Ident(Ident { + *component_value = ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("step-end"), raw: None, - }) + })) } _ => {} }, ( - ComponentValue::Number(Number { .. }), - ComponentValue::Ident(Ident { + ComponentValue::Number(box Number { .. }), + ComponentValue::Ident(box Ident { value: ident_value, .. }), ) if ident_value.to_ascii_lowercase() == js_word!("jump-start") => { - function_value[2] = ComponentValue::Ident(Ident { + function_value[2] = ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("start"), raw: None, - }) + })) } ( ComponentValue::Number(number), - ComponentValue::Ident(Ident { + ComponentValue::Ident(box Ident { value: ident_value, .. }), ) => match ident_value.to_ascii_lowercase() { diff --git a/crates/swc_css_minifier/src/compressor/length.rs b/crates/swc_css_minifier/src/compressor/length.rs index 768268e8f62b..d52c8689be17 100644 --- a/crates/swc_css_minifier/src/compressor/length.rs +++ b/crates/swc_css_minifier/src/compressor/length.rs @@ -124,7 +124,7 @@ impl Compressor { if let ComponentValue::Dimension(dimension) = n { if let Some(number) = self.length_to_zero(dimension) { - *n = ComponentValue::Number(number) + *n = ComponentValue::Number(Box::new(number)) } } } diff --git a/crates/swc_css_minifier/src/compressor/math/mod.rs b/crates/swc_css_minifier/src/compressor/math/mod.rs index cb4e31f1bd29..31fb1940b374 100644 --- a/crates/swc_css_minifier/src/compressor/math/mod.rs +++ b/crates/swc_css_minifier/src/compressor/math/mod.rs @@ -9,65 +9,65 @@ pub fn is_calc_function_name(ident: &Ident) -> bool { pub fn transform_calc_value_into_component_value(calc_value: &CalcValue) -> Option { match &calc_value { - CalcValue::Number(n) => Some(ComponentValue::Number(n.clone())), - CalcValue::Dimension(Dimension::Length(l)) => { - Some(ComponentValue::Dimension(Dimension::Length(Length { + CalcValue::Number(n) => Some(ComponentValue::Number(Box::new(n.clone()))), + CalcValue::Dimension(Dimension::Length(l)) => Some(ComponentValue::Dimension(Box::new( + Dimension::Length(Length { span: l.span, value: l.value.clone(), unit: l.unit.clone(), - }))) - } - CalcValue::Dimension(Dimension::Angle(a)) => { - Some(ComponentValue::Dimension(Dimension::Angle(Angle { + }), + ))), + CalcValue::Dimension(Dimension::Angle(a)) => Some(ComponentValue::Dimension(Box::new( + Dimension::Angle(Angle { span: a.span, value: a.value.clone(), unit: a.unit.clone(), - }))) - } + }), + ))), CalcValue::Dimension(Dimension::Time(t)) => { - Some(ComponentValue::Dimension(Dimension::Time(Time { + Some(ComponentValue::Dimension(Box::new(Dimension::Time(Time { span: t.span, value: t.value.clone(), unit: t.unit.clone(), - }))) + })))) } - CalcValue::Dimension(Dimension::Frequency(f)) => { - Some(ComponentValue::Dimension(Dimension::Frequency(Frequency { + CalcValue::Dimension(Dimension::Frequency(f)) => Some(ComponentValue::Dimension(Box::new( + Dimension::Frequency(Frequency { span: f.span, value: f.value.clone(), unit: f.unit.clone(), - }))) - } + }), + ))), CalcValue::Dimension(Dimension::Resolution(r)) => Some(ComponentValue::Dimension( - Dimension::Resolution(Resolution { + Box::new(Dimension::Resolution(Resolution { span: r.span, value: r.value.clone(), unit: r.unit.clone(), - }), + })), )), CalcValue::Dimension(Dimension::Flex(f)) => { - Some(ComponentValue::Dimension(Dimension::Flex(Flex { + Some(ComponentValue::Dimension(Box::new(Dimension::Flex(Flex { span: f.span, value: f.value.clone(), unit: f.unit.clone(), - }))) + })))) } CalcValue::Dimension(Dimension::UnknownDimension(u)) => Some(ComponentValue::Dimension( - Dimension::UnknownDimension(UnknownDimension { + Box::new(Dimension::UnknownDimension(UnknownDimension { span: u.span, value: u.value.clone(), unit: u.unit.clone(), - }), + })), )), - CalcValue::Percentage(p) => Some(ComponentValue::Percentage(Percentage { + CalcValue::Percentage(p) => Some(ComponentValue::Percentage(Box::new(Percentage { span: p.span, value: p.value.clone(), - })), - CalcValue::Function(f) => Some(ComponentValue::Function(Function { + }))), + CalcValue::Function(f) => Some(ComponentValue::Function(Box::new(Function { span: f.span, name: f.name.clone(), value: f.value.to_vec(), - })), + }))), CalcValue::Constant(_) => { // https://www.w3.org/TR/css-values-4/#calc-constants // "These keywords are only usable within a calculation" diff --git a/crates/swc_css_minifier/src/compressor/media.rs b/crates/swc_css_minifier/src/compressor/media.rs index 1d9a2d1b9684..6c8d2b25fbf8 100644 --- a/crates/swc_css_minifier/src/compressor/media.rs +++ b/crates/swc_css_minifier/src/compressor/media.rs @@ -336,7 +336,7 @@ impl Compressor { if is_calc_function_name(name) && value.len() == 1 => { match &value[0] { - ComponentValue::CalcSum(CalcSum { + ComponentValue::CalcSum(box CalcSum { expressions: calc_sum_expressions, .. }) if calc_sum_expressions.len() == 1 => match &calc_sum_expressions[0] { @@ -349,13 +349,13 @@ impl Compressor { { match transform_calc_value_into_component_value(calc_value) { Some(ComponentValue::Function(function)) => { - *n = MediaFeatureValue::Function(function); + *n = MediaFeatureValue::Function(*function); } Some(ComponentValue::Dimension(dimension)) => { - *n = MediaFeatureValue::Dimension(dimension); + *n = MediaFeatureValue::Dimension(*dimension); } Some(ComponentValue::Number(number)) => { - *n = MediaFeatureValue::Number(number); + *n = MediaFeatureValue::Number(*number); } _ => {} } diff --git a/crates/swc_css_minifier/src/compressor/mod.rs b/crates/swc_css_minifier/src/compressor/mod.rs index 6c8e31e9fd87..380c11d99beb 100644 --- a/crates/swc_css_minifier/src/compressor/mod.rs +++ b/crates/swc_css_minifier/src/compressor/mod.rs @@ -405,15 +405,15 @@ impl VisitMut for Compressor { { self.need_utf8_at_rule = true; } - Token::BadString { - raw_value: value, .. + Token::BadString { raw: value, .. } if !contains_only_ascii_characters(value) => { + self.need_utf8_at_rule = true; } - | Token::BadUrl { - raw_value: value, .. - } if !contains_only_ascii_characters(value) => { + Token::BadUrl { raw: value, .. } if !contains_only_ascii_characters(value) => { self.need_utf8_at_rule = true; } - Token::Dimension { unit: value, .. } if !contains_only_ascii_characters(value) => { + Token::Dimension(box DimensionToken { unit: value, .. }) + if !contains_only_ascii_characters(value) => + { self.need_utf8_at_rule = true; } _ => {} diff --git a/crates/swc_css_minifier/src/compressor/rules.rs b/crates/swc_css_minifier/src/compressor/rules.rs index a5a7560b3b62..37c1ea09f03d 100644 --- a/crates/swc_css_minifier/src/compressor/rules.rs +++ b/crates/swc_css_minifier/src/compressor/rules.rs @@ -138,7 +138,7 @@ impl Compressor { }); } ParentNode::SimpleBlock(simple_block) => simple_block.value.retain(|rule| match rule { - ComponentValue::Rule(Rule::AtRule(box at_rule)) => discarder(at_rule), + ComponentValue::Rule(box Rule::AtRule(box at_rule)) => discarder(at_rule), _ => true, }), } @@ -451,33 +451,37 @@ impl Compressor { simple_block.value.retain_mut(|rule| { let result = match rule { - ComponentValue::Rule(Rule::AtRule(box AtRule { + ComponentValue::Rule(box Rule::AtRule(box AtRule { block: Some(block), .. })) - | ComponentValue::Rule(Rule::QualifiedRule(box QualifiedRule { block, .. })) - | ComponentValue::StyleBlock(StyleBlock::QualifiedRule(box QualifiedRule { - block, - .. + | ComponentValue::Rule(box Rule::QualifiedRule(box QualifiedRule { + block, .. })) - | ComponentValue::StyleBlock(StyleBlock::AtRule(box AtRule { - block: Some(block), + | ComponentValue::StyleBlock(box StyleBlock::QualifiedRule(box QualifiedRule { + block, .. })) - | ComponentValue::DeclarationOrAtRule(DeclarationOrAtRule::AtRule(box AtRule { + | ComponentValue::StyleBlock(box StyleBlock::AtRule(box AtRule { block: Some(block), .. })) - | ComponentValue::KeyframeBlock(KeyframeBlock { block, .. }) + | ComponentValue::DeclarationOrAtRule(box DeclarationOrAtRule::AtRule( + box AtRule { + block: Some(block), .. + }, + )) + | ComponentValue::KeyframeBlock(box KeyframeBlock { block, .. }) if block.value.is_empty() => { false } - ComponentValue::Rule(Rule::AtRule(box at_rule @ AtRule { .. })) + ComponentValue::Rule(box Rule::AtRule(box at_rule @ AtRule { .. })) if prev_rule.is_some() && self.is_mergeable_at_rule(at_rule) => { - if let Some(ComponentValue::Rule(Rule::AtRule(box prev_rule))) = &prev_rule { + if let Some(ComponentValue::Rule(box Rule::AtRule(box prev_rule))) = &prev_rule + { if let Some(at_rule) = self.try_merge_at_rule(prev_rule, at_rule) { - *rule = ComponentValue::Rule(Rule::AtRule(Box::new(at_rule))); + *rule = ComponentValue::Rule(Box::new(Rule::AtRule(Box::new(at_rule)))); remove_rules_list.push(prev_index); } @@ -485,15 +489,16 @@ impl Compressor { true } - ComponentValue::StyleBlock(StyleBlock::AtRule(box at_rule @ AtRule { .. })) + ComponentValue::StyleBlock(box StyleBlock::AtRule(box at_rule @ AtRule { .. })) if prev_rule.is_some() && self.is_mergeable_at_rule(at_rule) => { - if let Some(ComponentValue::StyleBlock(StyleBlock::AtRule(box prev_rule))) = + if let Some(ComponentValue::StyleBlock(box StyleBlock::AtRule(box prev_rule))) = &prev_rule { if let Some(at_rule) = self.try_merge_at_rule(prev_rule, at_rule) { - *rule = - ComponentValue::StyleBlock(StyleBlock::AtRule(Box::new(at_rule))); + *rule = ComponentValue::StyleBlock(Box::new(StyleBlock::AtRule( + Box::new(at_rule), + ))); remove_rules_list.push(prev_index); } @@ -501,17 +506,18 @@ impl Compressor { true } - ComponentValue::Rule(Rule::QualifiedRule( + ComponentValue::Rule(box Rule::QualifiedRule( box qualified_rule @ QualifiedRule { .. }, )) if prev_rule.is_some() => { - if let Some(ComponentValue::Rule(Rule::QualifiedRule(box prev_rule))) = + if let Some(ComponentValue::Rule(box Rule::QualifiedRule(box prev_rule))) = &prev_rule { if let Some(qualified_rule) = self.try_merge_qualified_rules(prev_rule, qualified_rule) { - *rule = - ComponentValue::Rule(Rule::QualifiedRule(Box::new(qualified_rule))); + *rule = ComponentValue::Rule(Box::new(Rule::QualifiedRule(Box::new( + qualified_rule, + )))); remove_rules_list.push(prev_index); } @@ -519,18 +525,18 @@ impl Compressor { true } - ComponentValue::StyleBlock(StyleBlock::QualifiedRule( + ComponentValue::StyleBlock(box StyleBlock::QualifiedRule( box qualified_rule @ QualifiedRule { .. }, )) if prev_rule.is_some() => { - if let Some(ComponentValue::StyleBlock(StyleBlock::QualifiedRule( + if let Some(ComponentValue::StyleBlock(box StyleBlock::QualifiedRule( box prev_rule, ))) = &prev_rule { if let Some(qualified_rule) = self.try_merge_qualified_rules(prev_rule, qualified_rule) { - *rule = ComponentValue::StyleBlock(StyleBlock::QualifiedRule( - Box::new(qualified_rule), + *rule = ComponentValue::StyleBlock(Box::new( + StyleBlock::QualifiedRule(Box::new(qualified_rule)), )); remove_rules_list.push(prev_index); @@ -550,16 +556,16 @@ impl Compressor { if result { match rule { - ComponentValue::Rule(Rule::AtRule(box at_rule)) - | ComponentValue::StyleBlock(StyleBlock::AtRule(box at_rule)) + ComponentValue::Rule(box Rule::AtRule(box at_rule)) + | ComponentValue::StyleBlock(box StyleBlock::AtRule(box at_rule)) if self.is_mergeable_at_rule(at_rule) => { prev_index = index; prev_rule = Some(rule.clone()); } - ComponentValue::Rule(Rule::QualifiedRule(_)) - | ComponentValue::StyleBlock(StyleBlock::QualifiedRule(_)) => { + ComponentValue::Rule(box Rule::QualifiedRule(_)) + | ComponentValue::StyleBlock(box StyleBlock::QualifiedRule(_)) => { prev_index = index; prev_rule = Some(rule.clone()); } diff --git a/crates/swc_css_minifier/src/compressor/transform_function.rs b/crates/swc_css_minifier/src/compressor/transform_function.rs index 967ae55573db..9e1d9ff3d031 100644 --- a/crates/swc_css_minifier/src/compressor/transform_function.rs +++ b/crates/swc_css_minifier/src/compressor/transform_function.rs @@ -6,7 +6,7 @@ use super::Compressor; impl Compressor { pub(super) fn compress_transform_function(&self, component_value: &mut ComponentValue) { match component_value { - ComponentValue::Function(Function { + ComponentValue::Function(box Function { name, value: function_value, .. @@ -16,7 +16,7 @@ impl Compressor { match (function_value.get(0), function_value.get(2)) { ( Some(first), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: second_number, .. })), @@ -24,7 +24,7 @@ impl Compressor { *function_value = vec![first.clone()]; } ( - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: first_number, .. })), @@ -40,7 +40,7 @@ impl Compressor { _ => {} } } - ComponentValue::Function(Function { + ComponentValue::Function(box Function { name, value: function_value, .. @@ -53,11 +53,11 @@ impl Compressor { function_value.get(4), ) { ( - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: first_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: second_number, .. })), @@ -73,7 +73,7 @@ impl Compressor { _ => {} } } - ComponentValue::Function(Function { + ComponentValue::Function(box Function { name, value: function_value, .. @@ -83,12 +83,12 @@ impl Compressor { match (function_value.get(0), function_value.get(2)) { ( Some( - first @ ComponentValue::Number(Number { + first @ ComponentValue::Number(box Number { value: first_number, .. }), ), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: second_number, .. })), @@ -97,7 +97,7 @@ impl Compressor { } ( Some(first), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: second_number, .. })), @@ -110,7 +110,7 @@ impl Compressor { *function_value = vec![first.clone()]; } ( - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: first_number, .. })), @@ -126,7 +126,7 @@ impl Compressor { _ => {} } } - ComponentValue::Function(Function { + ComponentValue::Function(box Function { name, value: function_value, .. @@ -140,11 +140,11 @@ impl Compressor { ) { ( Some(first), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: second_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: third_number, .. })), @@ -157,12 +157,12 @@ impl Compressor { *function_value = vec![first.clone()]; } ( - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: first_number, .. })), Some(second), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: third_number, .. })), @@ -175,11 +175,11 @@ impl Compressor { *function_value = vec![second.clone()]; } ( - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: first_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: second_number, .. })), @@ -195,7 +195,7 @@ impl Compressor { _ => {} } } - ComponentValue::Function(Function { + ComponentValue::Function(box Function { name, value: function_value, .. @@ -230,11 +230,11 @@ impl Compressor { Some(first_comma), Some(second), Some(second_comma), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: third_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: fourth_number, .. })), @@ -242,38 +242,38 @@ impl Compressor { Some(fifth_comma), Some(sixth), Some(sixth_comma), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: seventh_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: eighth_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: ninth_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: tenth_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: eleventh_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: twelfth_number, .. })), Some(thirteenth), Some(thirteenth_comma), Some(fourteenth), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: fifteenth_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: sixteenth_number, .. })), @@ -310,7 +310,7 @@ impl Compressor { _ => {} } } - ComponentValue::Function(Function { + ComponentValue::Function(box Function { name, value: function_value, .. @@ -324,15 +324,15 @@ impl Compressor { function_value.get(6), ) { ( - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: first_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: second_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: third_number, .. })), @@ -346,15 +346,15 @@ impl Compressor { *function_value = vec![fourth_value.clone()]; } ( - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: first_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: second_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: third_number, .. })), @@ -368,15 +368,15 @@ impl Compressor { *function_value = vec![fourth_value.clone()]; } ( - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: first_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: second_number, .. })), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: third_number, .. })), @@ -392,7 +392,7 @@ impl Compressor { _ => {} } } - ComponentValue::Function(Function { + ComponentValue::Function(box Function { name, value: function_value, .. @@ -406,7 +406,7 @@ impl Compressor { }; } - ComponentValue::Function(Function { + ComponentValue::Function(box Function { name, value: function_value, .. @@ -416,7 +416,7 @@ impl Compressor { match (function_value.get(0), function_value.get(2)) { ( Some(first), - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: second_number, .. })), @@ -430,7 +430,7 @@ impl Compressor { } ( - Some(ComponentValue::Number(Number { + Some(ComponentValue::Number(box Number { value: first_number, .. })), diff --git a/crates/swc_css_modules/src/imports.rs b/crates/swc_css_modules/src/imports.rs index 6a90d04eeb3f..f7caa2c8377a 100644 --- a/crates/swc_css_modules/src/imports.rs +++ b/crates/swc_css_modules/src/imports.rs @@ -49,10 +49,10 @@ impl Visit for Analyzer { if let DeclarationName::Ident(name) = &d.name { if &*name.value == "composes" { - // comoses: name from 'foo.css' + // composes: name from 'foo.css' if d.value.len() >= 3 { if let ( - ComponentValue::Ident(Ident { + ComponentValue::Ident(box Ident { value: js_word!("from"), .. }), diff --git a/crates/swc_css_modules/src/lib.rs b/crates/swc_css_modules/src/lib.rs index a4d7964fa5c8..8cebe35f19c2 100644 --- a/crates/swc_css_modules/src/lib.rs +++ b/crates/swc_css_modules/src/lib.rs @@ -1,3 +1,5 @@ +#![feature(box_patterns)] + use rustc_hash::FxHashMap; use serde::Serialize; use swc_atoms::{js_word, JsWord}; @@ -233,8 +235,8 @@ where n.visit_mut_children_with(self); n.retain(|v| match v { - ComponentValue::StyleBlock(StyleBlock::Declaration(d)) - | ComponentValue::DeclarationOrAtRule(DeclarationOrAtRule::Declaration(d)) => { + ComponentValue::StyleBlock(box StyleBlock::Declaration(d)) + | ComponentValue::DeclarationOrAtRule(box DeclarationOrAtRule::Declaration(d)) => { if let DeclarationName::Ident(ident) = &d.name { if &*ident.value == "composes" { return false; @@ -254,18 +256,20 @@ where if let Some(composes_for_current) = &mut self.data.composes_for_current { if let DeclarationName::Ident(name) = &n.name { if &*name.value == "composes" { - // comoses: name from 'foo.css' + // composes: name from 'foo.css' if n.value.len() >= 3 { match (&n.value[n.value.len() - 2], &n.value[n.value.len() - 1]) { ( - ComponentValue::Ident(Ident { + ComponentValue::Ident(box Ident { value: js_word!("from"), .. }), ComponentValue::Str(import_source), ) => { for class_name in n.value.iter().take(n.value.len() - 2) { - if let ComponentValue::Ident(Ident { value, .. }) = class_name { + if let ComponentValue::Ident(box Ident { value, .. }) = + class_name + { composes_for_current.push(CssClassName::Import { name: value.clone(), from: import_source.value.clone(), @@ -276,17 +280,19 @@ where return; } ( - ComponentValue::Ident(Ident { + ComponentValue::Ident(box Ident { value: js_word!("from"), .. }), - ComponentValue::Ident(Ident { + ComponentValue::Ident(box Ident { value: js_word!("global"), .. }), ) => { for class_name in n.value.iter().take(n.value.len() - 2) { - if let ComponentValue::Ident(Ident { value, .. }) = class_name { + if let ComponentValue::Ident(box Ident { value, .. }) = + class_name + { composes_for_current.push(CssClassName::Global { name: value.clone(), }); @@ -299,7 +305,7 @@ where } for class_name in n.value.iter() { - if let ComponentValue::Ident(Ident { value, .. }) = class_name { + if let ComponentValue::Ident(box Ident { value, .. }) = class_name { if let Some(value) = self.data.orig_to_renamed.get(value) { composes_for_current.push(CssClassName::Local { name: value.clone(), @@ -318,7 +324,7 @@ where for v in &mut n.value { if can_change { - if let ComponentValue::Ident(Ident { value, raw, .. }) = v { + if let ComponentValue::Ident(box Ident { value, raw, .. }) = v { *raw = None; rename( @@ -330,18 +336,22 @@ where ); can_change = false; } - } else if let ComponentValue::Delimiter(Delimiter { - value: DelimiterValue::Comma, - .. - }) = v - { - can_change = true; + } else if let ComponentValue::Delimiter(delimiter) = v { + if matches!( + &**delimiter, + Delimiter { + value: DelimiterValue::Comma, + .. + } + ) { + can_change = true; + } } } } js_word!("animation-name") => { for v in &mut n.value { - if let ComponentValue::Ident(Ident { value, raw, .. }) = v { + if let ComponentValue::Ident(box Ident { value, raw, .. }) = v { *raw = None; rename( diff --git a/crates/swc_css_parser/src/lexer/mod.rs b/crates/swc_css_parser/src/lexer/mod.rs index 132485d08b8f..e4b39cdf7df8 100644 --- a/crates/swc_css_parser/src/lexer/mod.rs +++ b/crates/swc_css_parser/src/lexer/mod.rs @@ -2,7 +2,7 @@ use std::{cell::RefCell, char::REPLACEMENT_CHARACTER, rc::Rc}; use swc_atoms::{js_word, Atom, JsWord}; use swc_common::{input::Input, BytePos, Span}; -use swc_css_ast::{NumberType, Token, TokenAndSpan}; +use swc_css_ast::{DimensionToken, NumberType, Token, TokenAndSpan}; use crate::{ error::{Error, ErrorKind}, @@ -26,7 +26,6 @@ where buf: Rc>, raw_buf: Rc>, sub_buf: Rc>, - sub_raw_buf: Rc>, errors: Rc>>, } @@ -47,7 +46,6 @@ where buf: Rc::new(RefCell::new(String::with_capacity(256))), raw_buf: Rc::new(RefCell::new(String::with_capacity(256))), sub_buf: Rc::new(RefCell::new(String::with_capacity(32))), - sub_raw_buf: Rc::new(RefCell::new(String::with_capacity(32))), errors: Default::default(), } } @@ -90,21 +88,6 @@ where op(self, &mut buf, &mut raw) } - - fn with_sub_buf_and_raw_buf(&mut self, op: F) -> LexResult - where - F: for<'any> FnOnce(&mut Lexer, &mut String, &mut String) -> LexResult, - { - let b = self.sub_buf.clone(); - let r = self.sub_raw_buf.clone(); - let mut sub_buf = b.borrow_mut(); - let mut sub_raw_buf = r.borrow_mut(); - - sub_buf.clear(); - sub_raw_buf.clear(); - - op(self, &mut sub_buf, &mut sub_raw_buf) - } } impl Iterator for Lexer { @@ -555,32 +538,19 @@ where // If the next 3 input code points would start an identifier, then: if self.would_start_ident(next_first, next_second, next_third)? { + // Swap logic to avoid create empty strings, because it doesn't make sense + // + // Consume a name. Set the ’s unit to the returned value. + let ident_sequence = self.read_ident_sequence()?; // Create a with the same value and type flag as number, and a // unit set initially to the empty string. - let mut token = Token::Dimension { + let token = Token::Dimension(Box::new(DimensionToken { value: number.0, raw_value: number.1, - unit: js_word!(""), - raw_unit: "".into(), + unit: ident_sequence.0, + raw_unit: ident_sequence.1, type_flag: number.2, - }; - - // Consume a name. Set the ’s unit to the returned value. - let ident_sequence = self.read_ident_sequence()?; - - match token { - Token::Dimension { - ref mut unit, - ref mut raw_unit, - .. - } => { - *unit = ident_sequence.0; - *raw_unit = ident_sequence.1; - } - _ => { - unreachable!(); - } - } + })); // Return the . return Ok(token); @@ -730,7 +700,7 @@ where l.reconsume(); return Ok(Token::BadString { - raw_value: (&**raw).into(), + raw: (&**raw).into(), }); } @@ -804,10 +774,8 @@ where // Return the . Some(')') => { return Ok(Token::Url { - name: name.0, - raw_name: name.1, value: (&**out).into(), - raw_value: (&**raw).into(), + raw: Box::new((name.1, (&**raw).into())), }); } @@ -817,10 +785,8 @@ where l.emit_error(ErrorKind::UnterminatedUrl); return Ok(Token::Url { - name: name.0, - raw_name: name.1, value: (&**out).into(), - raw_value: (&**raw).into(), + raw: Box::new((name.1, (&**raw).into())), }); } @@ -853,10 +819,8 @@ where raw.push_str(&whitespaces); return Ok(Token::Url { - name: name.0, - raw_name: name.1, value: (&**out).into(), - raw_value: (&**raw).into(), + raw: Box::new((name.1, (&**raw).into())), }); } None => { @@ -865,10 +829,8 @@ where raw.push_str(&whitespaces); return Ok(Token::Url { - name: name.0, - raw_name: name.1, value: (&**out).into(), - raw_value: (&**raw).into(), + raw: Box::new((name.1, (&**raw).into())), }); } _ => {} @@ -876,18 +838,14 @@ where // otherwise, consume the remnants of a bad url, create a , // and return it. - out.push_str(&whitespaces); raw.push_str(&whitespaces); let remnants = l.read_bad_url_remnants()?; - out.push_str(&remnants.0); - raw.push_str(&remnants.1); + raw.push_str(&remnants); return Ok(Token::BadUrl { - name: name.0, - raw_name: name.1, - raw_value: (&**raw).into(), + raw: Atom::new(format!("{}{}{}", name.1, "(", raw)), }); } @@ -902,15 +860,11 @@ where let remnants = l.read_bad_url_remnants()?; - out.push(c); - out.push_str(&remnants.0); raw.push(c); - raw.push_str(&remnants.1); + raw.push_str(&remnants); return Ok(Token::BadUrl { - name: name.0, - raw_name: name.1, - raw_value: (&**raw).into(), + raw: Atom::new(format!("{}{}{}", name.1, "(", raw)), }); } @@ -933,15 +887,11 @@ where let remnants = l.read_bad_url_remnants()?; - out.push(c); - out.push_str(&remnants.0); raw.push(c); - raw.push_str(&remnants.1); + raw.push_str(&remnants); return Ok(Token::BadUrl { - name: name.0, - raw_name: name.1, - raw_value: (&**raw).into(), + raw: Atom::new(format!("{}{}{}", name.1, "(", raw)), }); } } @@ -1337,8 +1287,8 @@ where // its sole use is to consume enough of the input stream to reach a recovery // point where normal tokenizing can resume. But for recovery purpose we return // bad URL remnants. - fn read_bad_url_remnants(&mut self) -> LexResult<(String, String)> { - self.with_sub_buf_and_raw_buf(|l, buf, raw| { + fn read_bad_url_remnants(&mut self) -> LexResult { + self.with_sub_buf(|l, raw| { // Repeatedly consume the next input code point from the stream: loop { l.consume(); @@ -1347,7 +1297,9 @@ where // U+0029 RIGHT PARENTHESIS ()) // EOF // Return. - Some(')') => { + Some(c @ ')') => { + raw.push(c); + break; } None => { @@ -1359,20 +1311,18 @@ where // ("\)") to be encountered without ending the . let escaped = l.read_escape()?; - buf.push(escaped.0); raw.push(c); raw.push_str(&escaped.1); } // anything else // Do nothing. Some(c) => { - buf.push(c); raw.push(c); } } } - Ok(((&**buf).into(), (&**raw).into())) + Ok((&**raw).into()) }) } } diff --git a/crates/swc_css_parser/src/lib.rs b/crates/swc_css_parser/src/lib.rs index c026f2302b73..198ca84c0106 100644 --- a/crates/swc_css_parser/src/lib.rs +++ b/crates/swc_css_parser/src/lib.rs @@ -1,3 +1,4 @@ +#![feature(box_patterns)] #![cfg_attr(docsrs, feature(doc_cfg))] #![deny(unused_must_use)] #![deny(clippy::all)] diff --git a/crates/swc_css_parser/src/macros.rs b/crates/swc_css_parser/src/macros.rs index 136e148a2cea..87bce72aa087 100644 --- a/crates/swc_css_parser/src/macros.rs +++ b/crates/swc_css_parser/src/macros.rs @@ -55,10 +55,6 @@ macro_rules! tok { swc_css_ast::Token::Delim { value: '%', .. } }; - ("--") => { - swc_css_ast::Token::MinusMinus - }; - (",") => { swc_css_ast::Token::Comma }; @@ -128,7 +124,7 @@ macro_rules! tok { }; ("=") => { - swc_css_ast::Token::Delim { value: '=', .. } + swc_css_ast::Token::Delim { value: '=', .. } }; (" ") => { @@ -156,7 +152,7 @@ macro_rules! tok { }; ("/") => { - swc_css_ast::Token::Delim { value: '/', .. } + swc_css_ast::Token::Delim { value: '/', .. } }; ("<") => { diff --git a/crates/swc_css_parser/src/parser/at_rules/mod.rs b/crates/swc_css_parser/src/parser/at_rules/mod.rs index 226a3fc78544..be522e1975c8 100644 --- a/crates/swc_css_parser/src/parser/at_rules/mod.rs +++ b/crates/swc_css_parser/src/parser/at_rules/mod.rs @@ -435,7 +435,7 @@ where let declaration_list: Vec = self.parse()?; let declaration_list: Vec = declaration_list .into_iter() - .map(ComponentValue::DeclarationOrAtRule) + .map(|node| ComponentValue::DeclarationOrAtRule(Box::new(node))) .collect(); declaration_list @@ -449,7 +449,7 @@ where let style_blocks = self.with_ctx(ctx).parse_as::>()?; let style_blocks: Vec = style_blocks .into_iter() - .map(ComponentValue::StyleBlock) + .map(|node| ComponentValue::StyleBlock(Box::new(node))) .collect(); style_blocks @@ -460,8 +460,10 @@ where ..self.ctx }; let rule_list = self.with_ctx(ctx).parse_as::>()?; - let rule_list: Vec = - rule_list.into_iter().map(ComponentValue::Rule).collect(); + let rule_list: Vec = rule_list + .into_iter() + .map(|node| ComponentValue::Rule(Box::new(node))) + .collect(); rule_list } @@ -470,7 +472,7 @@ where let declaration_list: Vec = self.parse()?; let declaration_list: Vec = declaration_list .into_iter() - .map(ComponentValue::DeclarationOrAtRule) + .map(|node| ComponentValue::DeclarationOrAtRule(Box::new(node))) .collect(); declaration_list @@ -486,15 +488,17 @@ where let style_blocks: Vec = self.parse()?; let style_blocks: Vec = style_blocks .into_iter() - .map(ComponentValue::StyleBlock) + .map(|node| ComponentValue::StyleBlock(Box::new(node))) .collect(); style_blocks } _ => { let rule_list = self.parse_as::>()?; - let rule_list: Vec = - rule_list.into_iter().map(ComponentValue::Rule).collect(); + let rule_list: Vec = rule_list + .into_iter() + .map(|node| ComponentValue::Rule(Box::new(node))) + .collect(); rule_list } @@ -504,7 +508,7 @@ where let declaration_list: Vec = self.parse()?; let declaration_list: Vec = declaration_list .into_iter() - .map(ComponentValue::DeclarationOrAtRule) + .map(|node| ComponentValue::DeclarationOrAtRule(Box::new(node))) .collect(); declaration_list @@ -517,7 +521,7 @@ where let declaration_list = self.with_ctx(ctx).parse_as::>()?; let declaration_list: Vec = declaration_list .into_iter() - .map(ComponentValue::DeclarationOrAtRule) + .map(|node| ComponentValue::DeclarationOrAtRule(Box::new(node))) .collect(); declaration_list @@ -534,7 +538,7 @@ where let declaration_list: Vec = self.parse()?; let declaration_list: Vec = declaration_list .into_iter() - .map(ComponentValue::DeclarationOrAtRule) + .map(|node| ComponentValue::DeclarationOrAtRule(Box::new(node))) .collect(); declaration_list @@ -543,7 +547,7 @@ where let declaration_list: Vec = self.parse()?; let declaration_list: Vec = declaration_list .into_iter() - .map(ComponentValue::DeclarationOrAtRule) + .map(|node| ComponentValue::DeclarationOrAtRule(Box::new(node))) .collect(); declaration_list @@ -573,7 +577,7 @@ where ErrorKind::Unexpected("at-rules are not allowed here"), )); - ComponentValue::Rule(Rule::AtRule(at_rule)) + ComponentValue::Rule(Box::new(Rule::AtRule(at_rule))) } Rule::QualifiedRule(qualified_rule) => { let locv = match qualified_rule.prelude { @@ -606,23 +610,23 @@ where Ok(keyframes_selectors) }) { Ok(keyframes_selectors) => { - ComponentValue::KeyframeBlock(KeyframeBlock { + ComponentValue::KeyframeBlock(Box::new(KeyframeBlock { span: qualified_rule.span, prelude: keyframes_selectors, block: qualified_rule.block, - }) + })) } Err(err) => { self.errors.push(err); - ComponentValue::Rule(Rule::ListOfComponentValues(Box::new( - locv, + ComponentValue::Rule(Box::new(Rule::ListOfComponentValues( + Box::new(locv), ))) } } } Rule::ListOfComponentValues(locv) => { - ComponentValue::Rule(Rule::ListOfComponentValues(locv)) + ComponentValue::Rule(Box::new(Rule::ListOfComponentValues(locv))) } }) .collect(); @@ -631,8 +635,10 @@ where } js_word!("layer") => { let rule_list = self.parse_as::>()?; - let rule_list: Vec = - rule_list.into_iter().map(ComponentValue::Rule).collect(); + let rule_list: Vec = rule_list + .into_iter() + .map(|node| ComponentValue::Rule(Box::new(node))) + .collect(); rule_list } @@ -641,15 +647,17 @@ where let style_blocks: Vec = self.parse()?; let style_blocks: Vec = style_blocks .into_iter() - .map(ComponentValue::StyleBlock) + .map(|node| ComponentValue::StyleBlock(Box::new(node))) .collect(); style_blocks } _ => { let rule_list = self.parse_as::>()?; - let rule_list: Vec = - rule_list.into_iter().map(ComponentValue::Rule).collect(); + let rule_list: Vec = rule_list + .into_iter() + .map(|node| ComponentValue::Rule(Box::new(node))) + .collect(); rule_list } @@ -663,7 +671,7 @@ where let style_blocks: Vec = self.parse()?; let style_blocks: Vec = style_blocks .into_iter() - .map(ComponentValue::StyleBlock) + .map(|node| ComponentValue::StyleBlock(Box::new(node))) .collect(); style_blocks @@ -677,7 +685,7 @@ where .parse_as::>()?; let declaration_list: Vec = declaration_list .into_iter() - .map(ComponentValue::DeclarationOrAtRule) + .map(|node| ComponentValue::DeclarationOrAtRule(Box::new(node))) .collect(); declaration_list @@ -703,7 +711,7 @@ where let declaration_list: Vec = self.parse()?; let declaration_list: Vec = declaration_list .into_iter() - .map(ComponentValue::DeclarationOrAtRule) + .map(|node| ComponentValue::DeclarationOrAtRule(Box::new(node))) .collect(); declaration_list @@ -712,7 +720,7 @@ where let declaration_list: Vec = self.parse()?; let declaration_list: Vec = declaration_list .into_iter() - .map(ComponentValue::DeclarationOrAtRule) + .map(|node| ComponentValue::DeclarationOrAtRule(Box::new(node))) .collect(); declaration_list @@ -722,15 +730,17 @@ where let style_blocks: Vec = self.parse()?; let style_blocks: Vec = style_blocks .into_iter() - .map(ComponentValue::StyleBlock) + .map(|node| ComponentValue::StyleBlock(Box::new(node))) .collect(); style_blocks } _ => { let rule_list = self.parse_as::>()?; - let rule_list: Vec = - rule_list.into_iter().map(ComponentValue::Rule).collect(); + let rule_list: Vec = rule_list + .into_iter() + .map(|node| ComponentValue::Rule(Box::new(node))) + .collect(); rule_list } @@ -739,7 +749,7 @@ where let declaration_list: Vec = self.parse()?; let declaration_list: Vec = declaration_list .into_iter() - .map(ComponentValue::DeclarationOrAtRule) + .map(|node| ComponentValue::DeclarationOrAtRule(Box::new(node))) .collect(); declaration_list @@ -815,7 +825,7 @@ where { let span = self.input.cur_span(); let pseudo = match bump!(self) { - Token::Function { value, raw, .. } => Ident { + Token::Function { value, raw } => Ident { span: span!(self, span.lo), value, raw: Some(raw), @@ -2473,7 +2483,7 @@ where } match bump!(self) { - Token::Ident { value, raw } => { + Token::Ident { value, raw, .. } => { if !value.starts_with("--") { return Err(Error::new( span, diff --git a/crates/swc_css_parser/src/parser/input.rs b/crates/swc_css_parser/src/parser/input.rs index b892a0c1a646..3ef45f9a4f0c 100644 --- a/crates/swc_css_parser/src/parser/input.rs +++ b/crates/swc_css_parser/src/parser/input.rs @@ -220,15 +220,15 @@ pub enum InputType<'a> { } #[derive(Debug)] -pub enum TokenOrBlock { - Token(TokenAndSpan), - Function(Span, JsWord, Atom), - LBracket(Span), - LParen(Span), - LBrace(Span), - RParen(Span), - RBracket(Span), - RBrace(Span), +enum TokenOrBlock { + Token(Box), + Function(Box<(Span, JsWord, Atom)>), + LBracket(Box), + LParen(Box), + LBrace(Box), + RParen(Box), + RBracket(Box), + RBrace(Box), } impl<'a> Input<'a> { @@ -271,7 +271,7 @@ impl<'a> Input<'a> { } Some(ComponentValue::Function(function)) => { if self.idx.len() - 1 == deep { - return Some(TokenOrBlock::Function( + return Some(TokenOrBlock::Function(Box::new(( Span::new( function.span_lo(), function.name.span_hi() + BytePos(1), @@ -282,17 +282,17 @@ impl<'a> Input<'a> { Some(raw) => raw.clone(), _ => Atom::from(function.name.value.clone()), }, - )); + )))); } let res = self.get_component_value(&function.value, deep + 1); if res.is_none() { - return Some(TokenOrBlock::RParen(Span::new( + return Some(TokenOrBlock::RParen(Box::new(Span::new( function.span_hi() - BytePos(1), function.span_hi(), Default::default(), - ))); + )))); } res @@ -300,9 +300,9 @@ impl<'a> Input<'a> { Some(ComponentValue::SimpleBlock(simple_block)) => { if self.idx.len() - 1 == deep { let close = match simple_block.name.token { - Token::LBracket => TokenOrBlock::LBracket(simple_block.name.span), - Token::LParen => TokenOrBlock::LParen(simple_block.name.span), - Token::LBrace => TokenOrBlock::LBrace(simple_block.name.span), + Token::LBracket => TokenOrBlock::LBracket(Box::new(simple_block.name.span)), + Token::LParen => TokenOrBlock::LParen(Box::new(simple_block.name.span)), + Token::LBrace => TokenOrBlock::LBrace(Box::new(simple_block.name.span)), _ => { unreachable!(); } @@ -320,9 +320,9 @@ impl<'a> Input<'a> { Default::default(), ); let close = match simple_block.name.token { - Token::LBracket => TokenOrBlock::RBracket(span), - Token::LParen => TokenOrBlock::RParen(span), - Token::LBrace => TokenOrBlock::RBrace(span), + Token::LBracket => TokenOrBlock::RBracket(Box::new(span)), + Token::LParen => TokenOrBlock::RParen(Box::new(span)), + Token::LBrace => TokenOrBlock::RBrace(Box::new(span)), _ => { unreachable!(); } @@ -368,33 +368,36 @@ impl<'a> Input<'a> { InputType::ListOfComponentValues(input) => { let token_and_span = match self.get_component_value(&input.children, 0) { Some(token_or_block) => match token_or_block { - TokenOrBlock::Token(token_and_span) => token_and_span, - TokenOrBlock::Function(span, value, raw) => TokenAndSpan { - span, - token: Token::Function { value, raw }, + TokenOrBlock::Token(token_and_span) => *token_and_span, + TokenOrBlock::Function(function) => TokenAndSpan { + span: function.0, + token: Token::Function { + value: function.1, + raw: function.2, + }, }, TokenOrBlock::LBracket(span) => TokenAndSpan { - span, + span: *span, token: Token::LBracket, }, TokenOrBlock::LBrace(span) => TokenAndSpan { - span, + span: *span, token: Token::LBrace, }, TokenOrBlock::LParen(span) => TokenAndSpan { - span, + span: *span, token: Token::LParen, }, TokenOrBlock::RBracket(span) => TokenAndSpan { - span, + span: *span, token: Token::RBracket, }, TokenOrBlock::RBrace(span) => TokenAndSpan { - span, + span: *span, token: Token::RBrace, }, TokenOrBlock::RParen(span) => TokenAndSpan { - span, + span: *span, token: Token::RParen, }, }, diff --git a/crates/swc_css_parser/src/parser/selectors/mod.rs b/crates/swc_css_parser/src/parser/selectors/mod.rs index 2ec9a1ea0e98..c318e09c38e5 100644 --- a/crates/swc_css_parser/src/parser/selectors/mod.rs +++ b/crates/swc_css_parser/src/parser/selectors/mod.rs @@ -70,7 +70,8 @@ where while !is_one_of!(parser, EOF, ",", ")") { if let Some(token_and_span) = parser.input.bump() { - children.push(ComponentValue::PreservedToken(token_and_span)); + children + .push(ComponentValue::PreservedToken(Box::new(token_and_span))); } } @@ -224,7 +225,8 @@ where while !is_one_of!(parser, EOF, ",", ")") { if let Some(token_and_span) = parser.input.bump() { - children.push(ComponentValue::PreservedToken(token_and_span)); + children + .push(ComponentValue::PreservedToken(Box::new(token_and_span))); } } @@ -1266,7 +1268,7 @@ where } tok!("dimension") => { let dimension = match bump!(self) { - Token::Dimension { value, raw_value, unit, .. } => (value, raw_value, unit), + Token::Dimension(box DimensionToken { value, raw_value, unit, .. }) => (value, raw_value, unit), _ => { unreachable!(); } @@ -1283,7 +1285,6 @@ where a = Some(dimension.0 as i32); a_raw = Some(dimension.1); - n_value = (*dimension.2).to_string(); } _ => { @@ -1418,7 +1419,7 @@ where } match bump!(self) { - Token::Ident { value, raw } => Ok(CustomHighlightName { + Token::Ident { value, raw, .. } => Ok(CustomHighlightName { span, value, raw: Some(raw), diff --git a/crates/swc_css_parser/src/parser/syntax/mod.rs b/crates/swc_css_parser/src/parser/syntax/mod.rs index 756efee6a3ce..1006685e592e 100644 --- a/crates/swc_css_parser/src/parser/syntax/mod.rs +++ b/crates/swc_css_parser/src/parser/syntax/mod.rs @@ -344,7 +344,7 @@ where ); list_of_component_values .children - .push(ComponentValue::PreservedToken(token_and_span)); + .push(ComponentValue::PreservedToken(Box::new(token_and_span))); } } // @@ -494,7 +494,7 @@ where ); list_of_component_values .children - .push(ComponentValue::PreservedToken(token_and_span)); + .push(ComponentValue::PreservedToken(Box::new(token_and_span))); } } // @@ -521,7 +521,7 @@ where let cur = self.input.bump().unwrap(); let mut temporary_list = ListOfComponentValues { span: Default::default(), - children: vec![ComponentValue::PreservedToken(cur)], + children: vec![ComponentValue::PreservedToken(Box::new(cur))], }; while !is_one_of!(self, ";", EOF) { @@ -651,7 +651,7 @@ where match &component_value { // Optimization for step 6 - ComponentValue::PreservedToken(TokenAndSpan { + ComponentValue::PreservedToken(box TokenAndSpan { span, token: Token::Delim { value: '!', .. }, .. @@ -670,7 +670,7 @@ where exclamation_point_span = Some(*span); } - ComponentValue::PreservedToken(TokenAndSpan { + ComponentValue::PreservedToken(box TokenAndSpan { token: Token::WhiteSpace { .. }, .. }) => match (&exclamation_point_span, &important_ident) { @@ -688,7 +688,7 @@ where } }, ComponentValue::PreservedToken( - token_and_span @ TokenAndSpan { + token_and_span @ box TokenAndSpan { token: Token::Ident { value, .. }, .. }, @@ -736,7 +736,7 @@ where Default::default(), ); let value = match important_ident.token { - Token::Ident { value, raw } => (value, raw), + Token::Ident { value, raw, .. } => (value, raw), _ => { unreachable!(); } @@ -805,16 +805,16 @@ where ..self.ctx } }) - .parse_as::()?; + .parse_as::>()?; Ok(ComponentValue::Function(function)) } // Otherwise, return the current input token. _ => { - let token = self.input.bump(); + let token_and_span = self.input.bump(); - match token { - Some(t) => Ok(ComponentValue::PreservedToken(t)), + match token_and_span { + Some(t) => Ok(ComponentValue::PreservedToken(Box::new(t))), _ => { unreachable!(); } diff --git a/crates/swc_css_parser/src/parser/util.rs b/crates/swc_css_parser/src/parser/util.rs index 532885502ac6..61247dfd4ee0 100644 --- a/crates/swc_css_parser/src/parser/util.rs +++ b/crates/swc_css_parser/src/parser/util.rs @@ -241,7 +241,7 @@ where }, )? .into_iter() - .map(ComponentValue::DeclarationOrAtRule) + .map(|node| ComponentValue::DeclarationOrAtRule(Box::new(node))) .collect(), _ => self .parse_according_to_grammar( @@ -256,7 +256,7 @@ where }, )? .into_iter() - .map(ComponentValue::StyleBlock) + .map(|node| ComponentValue::StyleBlock(Box::new(node))) .collect(), }; @@ -378,7 +378,7 @@ where component_value: &ComponentValue, ) -> PResult<()> { match component_value { - ComponentValue::PreservedToken(TokenAndSpan { + ComponentValue::PreservedToken(box TokenAndSpan { span, token: Token::BadString { .. }, }) => { @@ -387,7 +387,7 @@ where ErrorKind::Unexpected("bad string in declaration value"), )); } - ComponentValue::PreservedToken(TokenAndSpan { + ComponentValue::PreservedToken(box TokenAndSpan { span, token: Token::BadUrl { .. }, }) => { @@ -396,7 +396,7 @@ where ErrorKind::Unexpected("bad url in declaration value"), )); } - ComponentValue::PreservedToken(TokenAndSpan { + ComponentValue::PreservedToken(box TokenAndSpan { span, token: Token::RParen, }) => { @@ -405,7 +405,7 @@ where ErrorKind::Unexpected("')' in declaration value"), )); } - ComponentValue::PreservedToken(TokenAndSpan { + ComponentValue::PreservedToken(box TokenAndSpan { span, token: Token::RBracket, }) => { @@ -414,7 +414,7 @@ where ErrorKind::Unexpected("']' in declaration value"), )); } - ComponentValue::PreservedToken(TokenAndSpan { + ComponentValue::PreservedToken(box TokenAndSpan { span, token: Token::RBrace, }) => { @@ -423,7 +423,7 @@ where ErrorKind::Unexpected("'}' in declaration value"), )); } - ComponentValue::PreservedToken(TokenAndSpan { + ComponentValue::PreservedToken(box TokenAndSpan { span, token: Token::Semi, }) => { @@ -432,7 +432,7 @@ where ErrorKind::Unexpected("';' in declaration value"), )); } - ComponentValue::PreservedToken(TokenAndSpan { + ComponentValue::PreservedToken(box TokenAndSpan { span, token: Token::Delim { value: '!' }, }) => { diff --git a/crates/swc_css_parser/src/parser/values_and_units/mod.rs b/crates/swc_css_parser/src/parser/values_and_units/mod.rs index 823a72744724..d5566b6be551 100644 --- a/crates/swc_css_parser/src/parser/values_and_units/mod.rs +++ b/crates/swc_css_parser/src/parser/values_and_units/mod.rs @@ -1,3 +1,4 @@ +use swc_atoms::js_word; use swc_common::{BytePos, Span}; use swc_css_ast::*; @@ -103,7 +104,7 @@ where } }; - return Ok(ComponentValue::SimpleBlock(block)); + return Ok(ComponentValue::SimpleBlock(Box::new(block))); } tok!("#") => { @@ -405,7 +406,7 @@ where tok!("ident") => { is_legacy_syntax = false; - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -446,7 +447,7 @@ where Ok(Some(ComponentValue::Hue(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -516,7 +517,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") if !is_legacy_syntax => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -560,7 +561,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -632,7 +633,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") if !is_legacy_syntax => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -676,7 +677,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -763,7 +764,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -837,7 +838,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -882,7 +883,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -945,7 +946,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -994,7 +995,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -1062,7 +1063,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -1111,7 +1112,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -1157,7 +1158,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -1240,7 +1241,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") if !matches!(function_name, "device-cmyk") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -1349,7 +1350,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -1404,7 +1405,7 @@ where ComponentValue::Function(self.parse()?) } tok!("ident") => { - let ident: Ident = self.parse()?; + let ident: Box = self.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { ComponentValue::Ident(ident) @@ -1435,7 +1436,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -1476,7 +1477,7 @@ where Ok(Some(ComponentValue::Percentage(parser.parse()?))) } tok!("ident") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -1528,7 +1529,7 @@ where Ok(Some(ComponentValue::Function(parser.parse()?))) } tok!("ident") if !matches!(function_name, "device-cmyk") => { - let ident: Ident = parser.parse()?; + let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { Ok(Some(ComponentValue::Ident(ident))) @@ -1589,7 +1590,7 @@ where )); } - let layer_name = self.parse_as::()?; + let layer_name = self.parse_as::>()?; values.push(ComponentValue::LayerName(layer_name)); @@ -1642,7 +1643,7 @@ where if is_one_of!(self, ";", ":") { let tok = self.input.bump().unwrap(); - ComponentValue::PreservedToken(tok) + ComponentValue::PreservedToken(Box::new(tok)) } else { return Err(Error::new( self.input.cur_span(), @@ -1805,7 +1806,7 @@ where } match bump!(self) { - Token::Ident { value, raw } => { + Token::Ident { value, raw, .. } => { match &*value.to_ascii_lowercase() { "initial" | "inherit" | "unset" | "revert" | "default" => { return Err(Error::new(span, ErrorKind::InvalidCustomIdent(value))); @@ -1838,7 +1839,7 @@ where } match bump!(self) { - Token::Ident { value, raw } => { + Token::Ident { value, raw, .. } => { if !value.starts_with("--") { return Err(Error::new( span, @@ -1878,7 +1879,7 @@ where } match bump!(self) { - Token::Ident { value, raw } => { + Token::Ident { value, raw, .. } => { if !value.starts_with("--") { return Err(Error::new( span, @@ -1916,7 +1917,7 @@ where } match bump!(self) { - Token::Ident { value, raw } => Ok(Ident { + Token::Ident { value, raw, .. } => Ok(Ident { span, value, raw: Some(raw), @@ -1940,7 +1941,7 @@ where } match cur!(self) { - Token::Dimension { unit, .. } => { + Token::Dimension(box DimensionToken { unit, .. }) => { match unit { // unit if is_length_unit(unit) @@ -1980,13 +1981,13 @@ where } match bump!(self) { - Token::Dimension { + Token::Dimension(box DimensionToken { value, - raw_value, unit, + raw_value, raw_unit, .. - } => { + }) => { // TODO validate let unit_len = raw_unit.len() as u32; @@ -2024,13 +2025,13 @@ where } match bump!(self) { - Token::Dimension { + Token::Dimension(box DimensionToken { value, - raw_value, unit, + raw_value, raw_unit, .. - } => { + }) => { if !is_angle_unit(&unit) { return Err(Error::new( span, @@ -2073,13 +2074,13 @@ where } match bump!(self) { - Token::Dimension { + Token::Dimension(box DimensionToken { value, - raw_value, unit, + raw_value, raw_unit, .. - } => { + }) => { if !is_time_unit(&unit) { return Err(Error::new(span, ErrorKind::Expected("'s' or 'ms' units"))); } @@ -2119,13 +2120,13 @@ where } match bump!(self) { - Token::Dimension { + Token::Dimension(box DimensionToken { value, - raw_value, unit, + raw_value, raw_unit, .. - } => { + }) => { if !is_frequency_unit(&unit) { return Err(Error::new(span, ErrorKind::Expected("'Hz' or 'kHz' units"))); } @@ -2165,13 +2166,13 @@ where } match bump!(self) { - Token::Dimension { + Token::Dimension(box DimensionToken { value, - raw_value, unit, + raw_value, raw_unit, .. - } => { + }) => { if !is_resolution_unit(&unit) { return Err(Error::new( span, @@ -2214,13 +2215,13 @@ where } match bump!(self) { - Token::Dimension { + Token::Dimension(box DimensionToken { value, - raw_value, unit, + raw_value, raw_unit, .. - } => { + }) => { if !is_flex_unit(&unit) { return Err(Error::new(span, ErrorKind::Expected("'fr' unit"))); } @@ -2260,13 +2261,13 @@ where } match bump!(self) { - Token::Dimension { + Token::Dimension(box DimensionToken { value, - raw_value, unit, + raw_value, raw_unit, .. - } => { + }) => { let unit_len = raw_unit.len() as u32; Ok(UnknownDimension { @@ -2535,17 +2536,12 @@ where } match bump!(self) { - Token::Url { - name, - raw_name, - value, - raw_value, - } => { - let name_length = raw_name.len() as u32; + Token::Url { value, raw } => { + let name_length = raw.0.len() as u32; let name = Ident { span: Span::new(span.lo, span.lo + BytePos(name_length), Default::default()), - value: name, - raw: Some(raw_name), + value: js_word!("url"), + raw: Some(raw.0), }; let value = Some(Box::new(UrlValue::Raw(UrlValueRaw { span: Span::new( @@ -2554,7 +2550,7 @@ where Default::default(), ), value, - raw: Some(raw_value), + raw: Some(raw.1), }))); Ok(Url { @@ -2768,19 +2764,19 @@ where } } tok!("dimension") => { - let dimension = match bump!(self) { - Token::Dimension { + let raw = match bump!(self) { + Token::Dimension(box DimensionToken { raw_value, raw_unit, .. - } => (raw_value, raw_unit), + }) => (raw_value, raw_unit), _ => { unreachable!(); } }; - unicode_range.push_str(&dimension.0); - unicode_range.push_str(&dimension.1); + unicode_range.push_str(&raw.0); + unicode_range.push_str(&raw.1); } tok!("number") => { let number = match bump!(self) { @@ -2798,19 +2794,19 @@ where } // u '?'* tok!("dimension") => { - let dimension = match bump!(self) { - Token::Dimension { + let raw = match bump!(self) { + Token::Dimension(box DimensionToken { raw_value, raw_unit, .. - } => (raw_value, raw_unit), + }) => (raw_value, raw_unit), _ => { unreachable!(); } }; - unicode_range.push_str(&dimension.0); - unicode_range.push_str(&dimension.1); + unicode_range.push_str(&raw.0); + unicode_range.push_str(&raw.1); loop { if !is!(self, "?") { diff --git a/crates/swc_css_parser/tests/fixture/at-rule/import/output.json b/crates/swc_css_parser/tests/fixture/at-rule/import/output.json index 37f0119b50c1..0251ea8ee94d 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/import/output.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/import/output.json @@ -354,7 +354,7 @@ "end": 168, "ctxt": 0 }, - "value": "URL", + "value": "url", "raw": "URL" }, "value": { @@ -2098,7 +2098,7 @@ "end": 931, "ctxt": 0 }, - "value": "URL", + "value": "url", "raw": "URL" }, "value": { diff --git a/crates/swc_css_parser/tests/fixture/at-rule/media/output.json b/crates/swc_css_parser/tests/fixture/at-rule/media/output.json index b8e8bbc881a4..49aac26b5c3c 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/media/output.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/media/output.json @@ -15244,8 +15244,8 @@ "value": 600.0, "raw_value": "600", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } @@ -15701,8 +15701,8 @@ "value": 600.0, "raw_value": "600", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } @@ -16095,8 +16095,8 @@ "value": 100.0, "raw_value": "100", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } @@ -16217,8 +16217,8 @@ "value": 100.0, "raw_value": "100", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/fixture/at-rule/media/span.swc-stderr b/crates/swc_css_parser/tests/fixture/at-rule/media/span.swc-stderr index c56a06090fd2..4e9523e657b7 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/media/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/at-rule/media/span.swc-stderr @@ -21443,7 +21443,7 @@ 143 | @media (height foo bar) {} `---- - x Dimension { value: 600.0, raw_value: "600", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 600.0, raw_value: "600", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/at-rule/media/input.css:141:1] 141 | 142 | @media (height << 600px) {} @@ -21987,7 +21987,7 @@ 146 | @media screen and (min-width: ) {} `---- - x Dimension { value: 600.0, raw_value: "600", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 600.0, raw_value: "600", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/at-rule/media/input.css:144:1] 144 | @media (height foo("bar")) {} 145 | @media (height + 600px) {} @@ -22467,7 +22467,7 @@ 149 | @media screen and func(100px) {} `---- - x Dimension { value: 100.0, raw_value: "100", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 100.0, raw_value: "100", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/at-rule/media/input.css:147:1] 147 | @media (aspect-ratio: 12/) {} 148 | @media func(100px) {} @@ -22611,7 +22611,7 @@ 150 | @media(min-width:calc(10px + 10px)) {} `---- - x Dimension { value: 100.0, raw_value: "100", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 100.0, raw_value: "100", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/at-rule/media/input.css:148:1] 148 | @media func(100px) {} 149 | @media screen and func(100px) {} diff --git a/crates/swc_css_parser/tests/fixture/function/calc/output.json b/crates/swc_css_parser/tests/fixture/function/calc/output.json index 620195d6a2d8..ebbef9ab2284 100644 --- a/crates/swc_css_parser/tests/fixture/function/calc/output.json +++ b/crates/swc_css_parser/tests/fixture/function/calc/output.json @@ -374,8 +374,8 @@ "value": 30.0, "raw_value": "30", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/fixture/function/calc/span.swc-stderr b/crates/swc_css_parser/tests/fixture/function/calc/span.swc-stderr index 5fb133277016..2d93fe1be54c 100644 --- a/crates/swc_css_parser/tests/fixture/function/calc/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/function/calc/span.swc-stderr @@ -685,7 +685,7 @@ : ^^^^ `---- - x Dimension { value: 30.0, raw_value: "30", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 30.0, raw_value: "30", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/function/calc/input.css:5:1] 5 | div { 6 | --width: calc(10% + 30px); diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/unknown/output.json b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/unknown/output.json index 531f1c88f2ce..71a4535db3af 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/unknown/output.json +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/unknown/output.json @@ -1769,10 +1769,11 @@ }, "token": { "Url": { - "name": "url", - "raw_name": "url", "value": "foo.png", - "raw_value": "foo.png" + "raw": [ + "url", + "foo.png" + ] } } } diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/unknown/span.swc-stderr b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/unknown/span.swc-stderr index b5c6be92f01a..d194e17558d2 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-class/unknown/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-class/unknown/span.swc-stderr @@ -2037,7 +2037,7 @@ 16 | :unknown({!}) {} `---- - x Url { name: Atom('url' type=static), raw_name: "url", value: Atom('foo.png' type=inline), raw_value: "foo.png" } + x Url { value: Atom('foo.png' type=inline), raw: ("url", "foo.png") } ,-[$DIR/tests/fixture/selector/pseudo-class/unknown/input.css:14:1] 14 | :unknown('string') {} 15 | :unknown(url(foo.png)) {} diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-element/unknown/output.json b/crates/swc_css_parser/tests/fixture/selector/pseudo-element/unknown/output.json index 46d3f3756c15..7d9e18785a86 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-element/unknown/output.json +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-element/unknown/output.json @@ -1769,10 +1769,11 @@ }, "token": { "Url": { - "name": "url", - "raw_name": "url", "value": "foo.png", - "raw_value": "foo.png" + "raw": [ + "url", + "foo.png" + ] } } } diff --git a/crates/swc_css_parser/tests/fixture/selector/pseudo-element/unknown/span.swc-stderr b/crates/swc_css_parser/tests/fixture/selector/pseudo-element/unknown/span.swc-stderr index 8430db1bf489..35f4a040668f 100644 --- a/crates/swc_css_parser/tests/fixture/selector/pseudo-element/unknown/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/selector/pseudo-element/unknown/span.swc-stderr @@ -2036,7 +2036,7 @@ 16 | ::unknown({!}) {} `---- - x Url { name: Atom('url' type=static), raw_name: "url", value: Atom('foo.png' type=inline), raw_value: "foo.png" } + x Url { value: Atom('foo.png' type=inline), raw: ("url", "foo.png") } ,-[$DIR/tests/fixture/selector/pseudo-element/unknown/input.css:14:1] 14 | ::unknown('string') {} 15 | ::unknown(url(foo.png)) {} diff --git a/crates/swc_css_parser/tests/fixture/style-block/output.json b/crates/swc_css_parser/tests/fixture/style-block/output.json index f09f84066081..0496b0a2b704 100644 --- a/crates/swc_css_parser/tests/fixture/style-block/output.json +++ b/crates/swc_css_parser/tests/fixture/style-block/output.json @@ -3461,8 +3461,8 @@ "value": 100.0, "raw_value": "100", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, @@ -4382,8 +4382,8 @@ "value": 16.0, "raw_value": "16", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, @@ -4457,8 +4457,8 @@ "value": 16.0, "raw_value": "16", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, diff --git a/crates/swc_css_parser/tests/fixture/style-block/span.swc-stderr b/crates/swc_css_parser/tests/fixture/style-block/span.swc-stderr index 49453217bc5c..29643a091773 100644 --- a/crates/swc_css_parser/tests/fixture/style-block/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/style-block/span.swc-stderr @@ -4843,7 +4843,7 @@ 93 | } `---- - x Dimension { value: 100.0, raw_value: "100", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 100.0, raw_value: "100", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/style-block/input.css:91:1] 91 | @mixin mobile { 92 | height: 100px; @@ -5950,7 +5950,7 @@ 112 | height: 16px; `---- - x Dimension { value: 16.0, raw_value: "16", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 16.0, raw_value: "16", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/style-block/input.css:110:1] 110 | --small-icon: { 111 | width: 16px; @@ -6046,7 +6046,7 @@ 113 | } `---- - x Dimension { value: 16.0, raw_value: "16", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 16.0, raw_value: "16", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/style-block/input.css:111:1] 111 | width: 16px; 112 | height: 16px; diff --git a/crates/swc_css_parser/tests/fixture/value/custom-property/output.json b/crates/swc_css_parser/tests/fixture/value/custom-property/output.json index b95052817214..c4b16b637314 100644 --- a/crates/swc_css_parser/tests/fixture/value/custom-property/output.json +++ b/crates/swc_css_parser/tests/fixture/value/custom-property/output.json @@ -632,8 +632,8 @@ "value": 100.0, "raw_value": "100", "unit": "vw", - "raw_unit": "vw", - "type": "integer" + "type": "integer", + "raw_unit": "vw" } } } @@ -2811,8 +2811,8 @@ "value": 16.0, "raw_value": "16", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, @@ -2886,8 +2886,8 @@ "value": 16.0, "raw_value": "16", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, diff --git a/crates/swc_css_parser/tests/fixture/value/custom-property/span.swc-stderr b/crates/swc_css_parser/tests/fixture/value/custom-property/span.swc-stderr index 344e38f4b57d..ac780685d12d 100644 --- a/crates/swc_css_parser/tests/fixture/value/custom-property/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/value/custom-property/span.swc-stderr @@ -1110,7 +1110,7 @@ 19 | --color: #06c; `---- - x Dimension { value: 100.0, raw_value: "100", unit: Atom('vw' type=static), raw_unit: "vw", type_flag: Integer } + x Dimension(DimensionToken { value: 100.0, raw_value: "100", unit: Atom('vw' type=static), type_flag: Integer, raw_unit: "vw" }) ,-[$DIR/tests/fixture/value/custom-property/input.css:17:1] 17 | --number: 1; 18 | --unit: 100vw; @@ -4154,7 +4154,7 @@ 54 | height: 16px; `---- - x Dimension { value: 16.0, raw_value: "16", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 16.0, raw_value: "16", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/value/custom-property/input.css:52:1] 52 | --small-icon: { 53 | width: 16px; @@ -4250,7 +4250,7 @@ 55 | } `---- - x Dimension { value: 16.0, raw_value: "16", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 16.0, raw_value: "16", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/value/custom-property/input.css:53:1] 53 | width: 16px; 54 | height: 16px; diff --git a/crates/swc_css_parser/tests/fixture/value/url/output.json b/crates/swc_css_parser/tests/fixture/value/url/output.json index 5150246736df..d680a6cefad5 100644 --- a/crates/swc_css_parser/tests/fixture/value/url/output.json +++ b/crates/swc_css_parser/tests/fixture/value/url/output.json @@ -169,7 +169,7 @@ "end": 78, "ctxt": 0 }, - "value": "URL", + "value": "url", "raw": "URL" }, "value": { @@ -219,7 +219,7 @@ "end": 131, "ctxt": 0 }, - "value": "URL", + "value": "url", "raw": "\\URL" }, "value": { @@ -1409,7 +1409,7 @@ "end": 1299, "ctxt": 0 }, - "value": "URL", + "value": "url", "raw": "URL" }, "value": { diff --git a/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/output.json b/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/output.json index 1f7fc4cae200..acd26f25221d 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/output.json +++ b/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/output.json @@ -322,8 +322,8 @@ "value": 12.0, "raw_value": "12", "unit": "em", - "raw_unit": "em", - "type": "integer" + "type": "integer", + "raw_unit": "em" } } } @@ -360,8 +360,8 @@ "value": 75.0, "raw_value": "75", "unit": "ms", - "raw_unit": "ms", - "type": "integer" + "type": "integer", + "raw_unit": "ms" } } } diff --git a/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/span.swc-stderr b/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/span.swc-stderr index 82fd3d17afb5..01a68ef825e7 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/vendor/rome/custom-properties/span.swc-stderr @@ -540,7 +540,7 @@ 9 | --time: 75ms; `---- - x Dimension { value: 12.0, raw_value: "12", unit: Atom('em' type=static), raw_unit: "em", type_flag: Integer } + x Dimension(DimensionToken { value: 12.0, raw_value: "12", unit: Atom('em' type=static), type_flag: Integer, raw_unit: "em" }) ,-[$DIR/tests/fixture/vendor/rome/custom-properties/input.css:7:1] 7 | --number: 37; 8 | --length: 12em; @@ -596,7 +596,7 @@ 10 | --function: foo(); `---- - x Dimension { value: 75.0, raw_value: "75", unit: Atom('ms' type=static), raw_unit: "ms", type_flag: Integer } + x Dimension(DimensionToken { value: 75.0, raw_value: "75", unit: Atom('ms' type=static), type_flag: Integer, raw_unit: "ms" }) ,-[$DIR/tests/fixture/vendor/rome/custom-properties/input.css:8:1] 8 | --length: 12em; 9 | --time: 75ms; diff --git a/crates/swc_css_parser/tests/fixture/vendor/rome/functions/output.json b/crates/swc_css_parser/tests/fixture/vendor/rome/functions/output.json index 84b131fd9f96..b498570daf25 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/rome/functions/output.json +++ b/crates/swc_css_parser/tests/fixture/vendor/rome/functions/output.json @@ -110,8 +110,8 @@ "value": 2.0, "raw_value": "2", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/fixture/vendor/rome/functions/span.swc-stderr b/crates/swc_css_parser/tests/fixture/vendor/rome/functions/span.swc-stderr index 0abbc539504a..d9179edbec9b 100644 --- a/crates/swc_css_parser/tests/fixture/vendor/rome/functions/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/vendor/rome/functions/span.swc-stderr @@ -144,7 +144,7 @@ 3 | border: var(--fancy); `---- - x Dimension { value: 2.0, raw_value: "2", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 2.0, raw_value: "2", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/vendor/rome/functions/input.css:1:1] 1 | .style { 2 | --fancy: 2px; diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/output.json index d9e2a7bbcee8..034b55a2a34d 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/output.json @@ -163,8 +163,8 @@ "value": 900.0, "raw_value": "900", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } @@ -275,8 +275,8 @@ "value": 1200.0, "raw_value": "1200", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/span.swc-stderr index 51a080481c35..797d467f8ab1 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/condition-and-or/span.swc-stderr @@ -149,7 +149,7 @@ : ^^^^^ `---- - x Dimension { value: 900.0, raw_value: "900", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 900.0, raw_value: "900", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/condition-and-or/input.css:1:1] 1 | @media screen and (min-width: 900px) or (min-width: 1200px) {} : ^^^^^ @@ -251,7 +251,7 @@ : ^^^^^^ `---- - x Dimension { value: 1200.0, raw_value: "1200", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 1200.0, raw_value: "1200", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/condition-and-or/input.css:1:1] 1 | @media screen and (min-width: 900px) or (min-width: 1200px) {} : ^^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/output.json index 7ecfa37e4b24..252edfd51ef4 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/output.json @@ -73,8 +73,8 @@ "value": 20.0, "raw_value": "20", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, @@ -112,8 +112,8 @@ "value": 20.0, "raw_value": "20", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/span.swc-stderr index 5f79ee167c1e..71450206a19f 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name-1/span.swc-stderr @@ -65,7 +65,7 @@ : ^^^^ `---- - x Dimension { value: 20.0, raw_value: "20", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 20.0, raw_value: "20", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-name-1/input.css:1:1] 1 | @media (20px: 20px) {} : ^^^^ @@ -101,7 +101,7 @@ : ^^^^ `---- - x Dimension { value: 20.0, raw_value: "20", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 20.0, raw_value: "20", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-name-1/input.css:1:1] 1 | @media (20px: 20px) {} : ^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/output.json index f53122a49a9f..c480334823dc 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/output.json @@ -109,8 +109,8 @@ "value": 20.0, "raw_value": "20", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/span.swc-stderr index bc4558018adf..408c7229c75e 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-name/span.swc-stderr @@ -101,7 +101,7 @@ : ^^^^ `---- - x Dimension { value: 20.0, raw_value: "20", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 20.0, raw_value: "20", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-name/input.css:1:1] 1 | @media ("min-width": 20px) {} : ^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/output.json index 57392c3f68a7..cc5ec0879ed5 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/output.json @@ -73,8 +73,8 @@ "value": 400.0, "raw_value": "400", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, @@ -182,8 +182,8 @@ "value": 700.0, "raw_value": "700", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/span.swc-stderr index 5880eb3048f5..3c0e790f1af6 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-2/span.swc-stderr @@ -65,7 +65,7 @@ : ^^^^^ `---- - x Dimension { value: 400.0, raw_value: "400", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 400.0, raw_value: "400", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-range-2/input.css:1:1] 1 | @media (400px > "width" > 700px) {} : ^^^^^ @@ -161,7 +161,7 @@ : ^^^^^ `---- - x Dimension { value: 700.0, raw_value: "700", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 700.0, raw_value: "700", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-range-2/input.css:1:1] 1 | @media (400px > "width" > 700px) {} : ^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/output.json index d8b94af14edc..635829644101 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/output.json @@ -73,8 +73,8 @@ "value": 400.0, "raw_value": "400", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, @@ -234,8 +234,8 @@ "value": 700.0, "raw_value": "700", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/span.swc-stderr index b7ed8d453866..dbc7f21250ea 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-3/span.swc-stderr @@ -65,7 +65,7 @@ : ^^^^^ `---- - x Dimension { value: 400.0, raw_value: "400", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 400.0, raw_value: "400", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-range-3/input.css:1:1] 1 | @media (400px > = width > = 700px) {} : ^^^^^ @@ -209,7 +209,7 @@ : ^^^^^ `---- - x Dimension { value: 700.0, raw_value: "700", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 700.0, raw_value: "700", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-range-3/input.css:1:1] 1 | @media (400px > = width > = 700px) {} : ^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/output.json index ca3cb63c644f..19c04c403706 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/output.json @@ -73,8 +73,8 @@ "value": 400.0, "raw_value": "400", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, @@ -195,8 +195,8 @@ "value": 700.0, "raw_value": "700", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/span.swc-stderr index 076be557cd5c..26de2732496e 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-4/span.swc-stderr @@ -65,7 +65,7 @@ : ^^^^^ `---- - x Dimension { value: 400.0, raw_value: "400", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 400.0, raw_value: "400", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-range-4/input.css:1:1] 1 | @media (400px >= width ! 700px) {} : ^^^^^ @@ -173,7 +173,7 @@ : ^^^^^ `---- - x Dimension { value: 700.0, raw_value: "700", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 700.0, raw_value: "700", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-range-4/input.css:1:1] 1 | @media (400px >= width ! 700px) {} : ^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/output.json index e836aed452ae..417c643e8066 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/output.json @@ -73,8 +73,8 @@ "value": 400.0, "raw_value": "400", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, @@ -208,8 +208,8 @@ "value": 700.0, "raw_value": "700", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/span.swc-stderr index b956cd317d8e..0889c36b2617 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-5/span.swc-stderr @@ -65,7 +65,7 @@ : ^^^^^ `---- - x Dimension { value: 400.0, raw_value: "400", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 400.0, raw_value: "400", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-range-5/input.css:1:1] 1 | @media (400px <= width >= 700px) {} : ^^^^^ @@ -185,7 +185,7 @@ : ^^^^^ `---- - x Dimension { value: 700.0, raw_value: "700", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 700.0, raw_value: "700", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-range-5/input.css:1:1] 1 | @media (400px <= width >= 700px) {} : ^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/output.json index b30bbb9507a2..fb120ee98874 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/output.json @@ -73,8 +73,8 @@ "value": 400.0, "raw_value": "400", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, @@ -208,8 +208,8 @@ "value": 700.0, "raw_value": "700", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/span.swc-stderr index a89d8d7683a0..9a92dc3b2682 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/feature-range-6/span.swc-stderr @@ -65,7 +65,7 @@ : ^^^^^ `---- - x Dimension { value: 400.0, raw_value: "400", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 400.0, raw_value: "400", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-range-6/input.css:1:1] 1 | @media (400px >= width <= 700px) {} : ^^^^^ @@ -185,7 +185,7 @@ : ^^^^^ `---- - x Dimension { value: 700.0, raw_value: "700", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 700.0, raw_value: "700", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/feature-range-6/input.css:1:1] 1 | @media (400px >= width <= 700px) {} : ^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/output.json index 3bd845d4d2b1..81b0cdc677b1 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/output.json @@ -173,8 +173,8 @@ "value": 1024.0, "raw_value": "1024", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/span.swc-stderr index 3225a4788edd..ae5c79cc669d 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/span.swc-stderr @@ -218,7 +218,7 @@ 3 | } `---- - x Dimension { value: 1024.0, raw_value: "1024", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 1024.0, raw_value: "1024", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/at-rule/media/invalid-nesting/input.css:1:1] 1 | @media (min-width: 480px) { 2 | max-inline-size: 1024px; diff --git a/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/output.json b/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/output.json index a5b9b95669cf..c2e554ec09cf 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/output.json @@ -345,8 +345,8 @@ "value": 10.0, "raw_value": "10", "unit": "deg", - "raw_unit": "deg", - "type": "integer" + "type": "integer", + "raw_unit": "deg" } } } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/span.swc-stderr index 3da55b45b3d1..71998d91140d 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/supports/wrong-or-and/span.swc-stderr @@ -323,7 +323,7 @@ : ^^^^^ `---- - x Dimension { value: 10.0, raw_value: "10", unit: Atom('deg' type=static), raw_unit: "deg", type_flag: Integer } + x Dimension(DimensionToken { value: 10.0, raw_value: "10", unit: Atom('deg' type=static), type_flag: Integer, raw_unit: "deg" }) ,-[$DIR/tests/recovery/at-rule/supports/wrong-or-and/input.css:1:1] 1 | @supports (transition-property: color) or (animation-name: foo) and (transform: rotate(10deg)) {} : ^^^^^ diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/double-quotes/output.json b/crates/swc_css_parser/tests/recovery/bad-url-token/double-quotes/output.json index 16f777bb37f6..885559d880d0 100644 --- a/crates/swc_css_parser/tests/recovery/bad-url-token/double-quotes/output.json +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/double-quotes/output.json @@ -114,9 +114,7 @@ }, "token": { "BadUrl": { - "name": "url", - "raw_name": "url", - "raw_value": "image\".png" + "raw": "url(image\".png)" } } } diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/double-quotes/span.swc-stderr b/crates/swc_css_parser/tests/recovery/bad-url-token/double-quotes/span.swc-stderr index 3578e8893ff3..9c86c2e8210b 100644 --- a/crates/swc_css_parser/tests/recovery/bad-url-token/double-quotes/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/double-quotes/span.swc-stderr @@ -135,7 +135,7 @@ 3 | color: red; `---- - x BadUrl { name: Atom('url' type=static), raw_name: "url", raw_value: "image\".png" } + x BadUrl { raw: "url(image\".png)" } ,-[$DIR/tests/recovery/bad-url-token/double-quotes/input.css:1:1] 1 | div { 2 | background: url(image".png); diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/escaped/input.css b/crates/swc_css_parser/tests/recovery/bad-url-token/escaped/input.css new file mode 100644 index 000000000000..527bc55f35f3 --- /dev/null +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/escaped/input.css @@ -0,0 +1,3 @@ +a { + background: \url(te st); +} \ No newline at end of file diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/escaped/output.json b/crates/swc_css_parser/tests/recovery/bad-url-token/escaped/output.json new file mode 100644 index 000000000000..2e8d24fc3165 --- /dev/null +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/escaped/output.json @@ -0,0 +1,128 @@ +{ + "type": "Stylesheet", + "span": { + "start": 1, + "end": 35, + "ctxt": 0 + }, + "rules": [ + { + "type": "QualifiedRule", + "span": { + "start": 1, + "end": 35, + "ctxt": 0 + }, + "prelude": { + "type": "SelectorList", + "span": { + "start": 1, + "end": 2, + "ctxt": 0 + }, + "children": [ + { + "type": "ComplexSelector", + "span": { + "start": 1, + "end": 2, + "ctxt": 0 + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 1, + "end": 2, + "ctxt": 0 + }, + "nestingSelector": null, + "typeSelector": { + "type": "TagNameSelector", + "span": { + "start": 1, + "end": 2, + "ctxt": 0 + }, + "name": { + "type": "WqName", + "span": { + "start": 1, + "end": 2, + "ctxt": 0 + }, + "prefix": null, + "value": { + "type": "Ident", + "span": { + "start": 1, + "end": 2, + "ctxt": 0 + }, + "value": "a", + "raw": "a" + } + } + }, + "subclassSelectors": [] + } + ] + } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 3, + "end": 35, + "ctxt": 0 + }, + "name": { + "type": "PreservedToken", + "span": { + "start": 3, + "end": 4, + "ctxt": 0 + }, + "token": "LBrace" + }, + "value": [ + { + "type": "Declaration", + "span": { + "start": 9, + "end": 32, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 9, + "end": 19, + "ctxt": 0 + }, + "value": "background", + "raw": "background" + }, + "value": [ + { + "type": "PreservedToken", + "span": { + "start": 21, + "end": 32, + "ctxt": 0 + }, + "token": { + "BadUrl": { + "raw": "\\url(te st)" + } + } + } + ], + "important": null + } + ] + } + } + ] +} diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/escaped/output.swc-stderr b/crates/swc_css_parser/tests/recovery/bad-url-token/escaped/output.swc-stderr new file mode 100644 index 000000000000..3c53dd0086a5 --- /dev/null +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/escaped/output.swc-stderr @@ -0,0 +1,8 @@ + + x Unexpected bad url in declaration value + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + 2 | background: \url(te st); + : ^^^^^^^^^^^ + 3 | } + `---- diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/escaped/span.swc-stderr b/crates/swc_css_parser/tests/recovery/bad-url-token/escaped/span.swc-stderr new file mode 100644 index 000000000000..8b066554e811 --- /dev/null +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/escaped/span.swc-stderr @@ -0,0 +1,140 @@ + + x Stylesheet + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | ,-> a { + 2 | | background: \url(te st); + 3 | `-> } + `---- + + x Rule + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | ,-> a { + 2 | | background: \url(te st); + 3 | `-> } + `---- + + x QualifiedRule + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | ,-> a { + 2 | | background: \url(te st); + 3 | `-> } + `---- + + x SelectorList + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + : ^ + 2 | background: \url(te st); + `---- + + x ComplexSelector + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + : ^ + 2 | background: \url(te st); + `---- + + x CompoundSelector + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + : ^ + 2 | background: \url(te st); + `---- + + x TypeSelector + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + : ^ + 2 | background: \url(te st); + `---- + + x TagNameSelector + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + : ^ + 2 | background: \url(te st); + `---- + + x WqName + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + : ^ + 2 | background: \url(te st); + `---- + + x Ident + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + : ^ + 2 | background: \url(te st); + `---- + + x SimpleBlock + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | ,-> a { + 2 | | background: \url(te st); + 3 | `-> } + `---- + + x LBrace + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + : ^ + 2 | background: \url(te st); + `---- + + x ComponentValue + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + 2 | background: \url(te st); + : ^^^^^^^^^^^^^^^^^^^^^^^ + 3 | } + `---- + + x StyleBlock + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + 2 | background: \url(te st); + : ^^^^^^^^^^^^^^^^^^^^^^^ + 3 | } + `---- + + x Declaration + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + 2 | background: \url(te st); + : ^^^^^^^^^^^^^^^^^^^^^^^ + 3 | } + `---- + + x DeclarationName + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + 2 | background: \url(te st); + : ^^^^^^^^^^ + 3 | } + `---- + + x Ident + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + 2 | background: \url(te st); + : ^^^^^^^^^^ + 3 | } + `---- + + x ComponentValue + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + 2 | background: \url(te st); + : ^^^^^^^^^^^ + 3 | } + `---- + + x BadUrl { raw: "\\url(te st)" } + ,-[$DIR/tests/recovery/bad-url-token/escaped/input.css:1:1] + 1 | a { + 2 | background: \url(te st); + : ^^^^^^^^^^^ + 3 | } + `---- diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/invalid-escape/output.json b/crates/swc_css_parser/tests/recovery/bad-url-token/invalid-escape/output.json index cacec20971c3..ddea93b7de3e 100644 --- a/crates/swc_css_parser/tests/recovery/bad-url-token/invalid-escape/output.json +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/invalid-escape/output.json @@ -114,9 +114,7 @@ }, "token": { "BadUrl": { - "name": "url", - "raw_name": "url", - "raw_value": "image.png\\\n " + "raw": "url(image.png\\\n )" } } } diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/invalid-escape/span.swc-stderr b/crates/swc_css_parser/tests/recovery/bad-url-token/invalid-escape/span.swc-stderr index 59ee5e2f3dd9..871b0ca9b5c8 100644 --- a/crates/swc_css_parser/tests/recovery/bad-url-token/invalid-escape/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/invalid-escape/span.swc-stderr @@ -135,7 +135,7 @@ 4 | } `---- - x BadUrl { name: Atom('url' type=static), raw_name: "url", raw_value: "image.png\\\n " } + x BadUrl { raw: "url(image.png\\\n )" } ,-[$DIR/tests/recovery/bad-url-token/invalid-escape/input.css:1:1] 1 | div { 2 | ,-> background: url(image.png\ diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/left-parenthesis/output.json b/crates/swc_css_parser/tests/recovery/bad-url-token/left-parenthesis/output.json index 42e54f48eb4b..44ba1348cd52 100644 --- a/crates/swc_css_parser/tests/recovery/bad-url-token/left-parenthesis/output.json +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/left-parenthesis/output.json @@ -114,9 +114,7 @@ }, "token": { "BadUrl": { - "name": "url", - "raw_name": "url", - "raw_value": "image(.png" + "raw": "url(image(.png)" } } } diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/left-parenthesis/span.swc-stderr b/crates/swc_css_parser/tests/recovery/bad-url-token/left-parenthesis/span.swc-stderr index 3c4aa4d3884b..ee877a4586cc 100644 --- a/crates/swc_css_parser/tests/recovery/bad-url-token/left-parenthesis/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/left-parenthesis/span.swc-stderr @@ -135,7 +135,7 @@ 3 | color: red; `---- - x BadUrl { name: Atom('url' type=static), raw_name: "url", raw_value: "image(.png" } + x BadUrl { raw: "url(image(.png)" } ,-[$DIR/tests/recovery/bad-url-token/left-parenthesis/input.css:1:1] 1 | div { 2 | background: url(image(.png); diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/single-quotes/output.json b/crates/swc_css_parser/tests/recovery/bad-url-token/single-quotes/output.json index 3205f7476f8e..820bf4a4290b 100644 --- a/crates/swc_css_parser/tests/recovery/bad-url-token/single-quotes/output.json +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/single-quotes/output.json @@ -114,9 +114,7 @@ }, "token": { "BadUrl": { - "name": "url", - "raw_name": "url", - "raw_value": "image'.png" + "raw": "url(image'.png)" } } } diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/single-quotes/span.swc-stderr b/crates/swc_css_parser/tests/recovery/bad-url-token/single-quotes/span.swc-stderr index cbca903d9c8b..b364d479238c 100644 --- a/crates/swc_css_parser/tests/recovery/bad-url-token/single-quotes/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/single-quotes/span.swc-stderr @@ -135,7 +135,7 @@ 3 | color: red; `---- - x BadUrl { name: Atom('url' type=static), raw_name: "url", raw_value: "image'.png" } + x BadUrl { raw: "url(image'.png)" } ,-[$DIR/tests/recovery/bad-url-token/single-quotes/input.css:1:1] 1 | div { 2 | background: url(image'.png); diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/unclosed/input.css b/crates/swc_css_parser/tests/recovery/bad-url-token/unclosed/input.css new file mode 100644 index 000000000000..bf1e56dbb11d --- /dev/null +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/unclosed/input.css @@ -0,0 +1,3 @@ +.foo { + background: url(foo bar; +} \ No newline at end of file diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/unclosed/output.json b/crates/swc_css_parser/tests/recovery/bad-url-token/unclosed/output.json new file mode 100644 index 000000000000..6e4c44dfa8d5 --- /dev/null +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/unclosed/output.json @@ -0,0 +1,121 @@ +{ + "type": "Stylesheet", + "span": { + "start": 1, + "end": 38, + "ctxt": 0 + }, + "rules": [ + { + "type": "QualifiedRule", + "span": { + "start": 1, + "end": 38, + "ctxt": 0 + }, + "prelude": { + "type": "SelectorList", + "span": { + "start": 1, + "end": 5, + "ctxt": 0 + }, + "children": [ + { + "type": "ComplexSelector", + "span": { + "start": 1, + "end": 5, + "ctxt": 0 + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 1, + "end": 5, + "ctxt": 0 + }, + "nestingSelector": null, + "typeSelector": null, + "subclassSelectors": [ + { + "type": "ClassSelector", + "span": { + "start": 1, + "end": 5, + "ctxt": 0 + }, + "text": { + "type": "Ident", + "span": { + "start": 2, + "end": 5, + "ctxt": 0 + }, + "value": "foo", + "raw": "foo" + } + } + ] + } + ] + } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 6, + "end": 38, + "ctxt": 0 + }, + "name": { + "type": "PreservedToken", + "span": { + "start": 6, + "end": 7, + "ctxt": 0 + }, + "token": "LBrace" + }, + "value": [ + { + "type": "Declaration", + "span": { + "start": 12, + "end": 38, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 12, + "end": 22, + "ctxt": 0 + }, + "value": "background", + "raw": "background" + }, + "value": [ + { + "type": "PreservedToken", + "span": { + "start": 24, + "end": 38, + "ctxt": 0 + }, + "token": { + "BadUrl": { + "raw": "url(foo bar;\n}" + } + } + } + ], + "important": null + } + ] + } + } + ] +} diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/unclosed/output.swc-stderr b/crates/swc_css_parser/tests/recovery/bad-url-token/unclosed/output.swc-stderr new file mode 100644 index 000000000000..f582ea8ccc4e --- /dev/null +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/unclosed/output.swc-stderr @@ -0,0 +1,14 @@ + + x Unexpected bad url in declaration value + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + 2 | ,-> background: url(foo bar; + 3 | `-> } + `---- + + x Unexpected end of file, but expected '}' + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | ,-> .foo { + 2 | | background: url(foo bar; + 3 | `-> } + `---- diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/unclosed/span.swc-stderr b/crates/swc_css_parser/tests/recovery/bad-url-token/unclosed/span.swc-stderr new file mode 100644 index 000000000000..00fc387bff73 --- /dev/null +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/unclosed/span.swc-stderr @@ -0,0 +1,128 @@ + + x Stylesheet + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | ,-> .foo { + 2 | | background: url(foo bar; + 3 | `-> } + `---- + + x Rule + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | ,-> .foo { + 2 | | background: url(foo bar; + 3 | `-> } + `---- + + x QualifiedRule + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | ,-> .foo { + 2 | | background: url(foo bar; + 3 | `-> } + `---- + + x SelectorList + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + : ^^^^ + 2 | background: url(foo bar; + `---- + + x ComplexSelector + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + : ^^^^ + 2 | background: url(foo bar; + `---- + + x CompoundSelector + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + : ^^^^ + 2 | background: url(foo bar; + `---- + + x SubclassSelector + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + : ^^^^ + 2 | background: url(foo bar; + `---- + + x ClassSelector + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + : ^^^^ + 2 | background: url(foo bar; + `---- + + x Ident + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + : ^^^ + 2 | background: url(foo bar; + `---- + + x SimpleBlock + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | ,-> .foo { + 2 | | background: url(foo bar; + 3 | `-> } + `---- + + x LBrace + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + : ^ + 2 | background: url(foo bar; + `---- + + x ComponentValue + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + 2 | ,-> background: url(foo bar; + 3 | `-> } + `---- + + x StyleBlock + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + 2 | ,-> background: url(foo bar; + 3 | `-> } + `---- + + x Declaration + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + 2 | ,-> background: url(foo bar; + 3 | `-> } + `---- + + x DeclarationName + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + 2 | background: url(foo bar; + : ^^^^^^^^^^ + 3 | } + `---- + + x Ident + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + 2 | background: url(foo bar; + : ^^^^^^^^^^ + 3 | } + `---- + + x ComponentValue + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + 2 | ,-> background: url(foo bar; + 3 | `-> } + `---- + + x BadUrl { raw: "url(foo bar;\n}" } + ,-[$DIR/tests/recovery/bad-url-token/unclosed/input.css:1:1] + 1 | .foo { + 2 | ,-> background: url(foo bar; + 3 | `-> } + `---- diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace-in-middle/output.json b/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace-in-middle/output.json index c21c2da11bb7..5a1e5f9354e4 100644 --- a/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace-in-middle/output.json +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace-in-middle/output.json @@ -114,9 +114,7 @@ }, "token": { "BadUrl": { - "name": "url", - "raw_name": "url", - "raw_value": " ./image.jpg a " + "raw": "url( ./image.jpg a )" } } } diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace-in-middle/span.swc-stderr b/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace-in-middle/span.swc-stderr index 7395de24269a..0822c2ef1b05 100644 --- a/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace-in-middle/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace-in-middle/span.swc-stderr @@ -131,7 +131,7 @@ 3 | } `---- - x BadUrl { name: Atom('url' type=static), raw_name: "url", raw_value: " ./image.jpg a " } + x BadUrl { raw: "url( ./image.jpg a )" } ,-[$DIR/tests/recovery/bad-url-token/whitespace-in-middle/input.css:1:1] 1 | a { 2 | background-image: url( ./image.jpg a ); diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace/output.json b/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace/output.json index 7e58c723fbe2..a9f30fb5252f 100644 --- a/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace/output.json +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace/output.json @@ -114,9 +114,7 @@ }, "token": { "BadUrl": { - "name": "url", - "raw_name": "url", - "raw_value": "image.\n png" + "raw": "url(image.\n png)" } } } diff --git a/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace/span.swc-stderr b/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace/span.swc-stderr index 063cd4465856..52f5c9e56c4b 100644 --- a/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/bad-url-token/whitespace/span.swc-stderr @@ -139,7 +139,7 @@ 4 | color: red; `---- - x BadUrl { name: Atom('url' type=static), raw_name: "url", raw_value: "image.\n png" } + x BadUrl { raw: "url(image.\n png)" } ,-[$DIR/tests/recovery/bad-url-token/whitespace/input.css:1:1] 1 | div { 2 | ,-> background: url(image. diff --git a/crates/swc_css_parser/tests/recovery/declaration/bad-value/output.json b/crates/swc_css_parser/tests/recovery/declaration/bad-value/output.json index 4483d20d3f50..9f9709d2052b 100644 --- a/crates/swc_css_parser/tests/recovery/declaration/bad-value/output.json +++ b/crates/swc_css_parser/tests/recovery/declaration/bad-value/output.json @@ -174,9 +174,7 @@ }, "token": { "BadUrl": { - "name": "url", - "raw_name": "url", - "raw_value": "test test" + "raw": "url(test test)" } } } diff --git a/crates/swc_css_parser/tests/recovery/declaration/bad-value/span.swc-stderr b/crates/swc_css_parser/tests/recovery/declaration/bad-value/span.swc-stderr index 93085d94aace..a5660defa59a 100644 --- a/crates/swc_css_parser/tests/recovery/declaration/bad-value/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/declaration/bad-value/span.swc-stderr @@ -287,7 +287,7 @@ 5 | --foo: !; `---- - x BadUrl { name: Atom('url' type=static), raw_name: "url", raw_value: "test test" } + x BadUrl { raw: "url(test test)" } ,-[$DIR/tests/recovery/declaration/bad-value/input.css:3:1] 3 | value: ]; 4 | value: url(test test); diff --git a/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/output.json b/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/output.json index 1cae0d8ee427..5bf718998369 100644 --- a/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/output.json +++ b/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/output.json @@ -125,8 +125,8 @@ "value": 20.0, "raw_value": "20", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/span.swc-stderr b/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/span.swc-stderr index 14617f43498c..388dc0a7b7f5 100644 --- a/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/span.swc-stderr @@ -131,7 +131,7 @@ 3 | } `---- - x Dimension { value: 20.0, raw_value: "20", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 20.0, raw_value: "20", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/declaration/wrong-name-3/input.css:1:1] 1 | a { 2 | func(20px); diff --git a/crates/swc_css_parser/tests/recovery/function/bad-comment-2/output.json b/crates/swc_css_parser/tests/recovery/function/bad-comment-2/output.json index 95232e7864f1..1cef4b7d27a7 100644 --- a/crates/swc_css_parser/tests/recovery/function/bad-comment-2/output.json +++ b/crates/swc_css_parser/tests/recovery/function/bad-comment-2/output.json @@ -114,9 +114,7 @@ }, "token": { "BadUrl": { - "name": "url", - "raw_name": "url", - "raw_value": "\n /* test */\n \"test.png\"\n " + "raw": "url(\n /* test */\n \"test.png\"\n )" } } } diff --git a/crates/swc_css_parser/tests/recovery/function/bad-comment-2/span.swc-stderr b/crates/swc_css_parser/tests/recovery/function/bad-comment-2/span.swc-stderr index 2233bbed56a6..7afabb946705 100644 --- a/crates/swc_css_parser/tests/recovery/function/bad-comment-2/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/function/bad-comment-2/span.swc-stderr @@ -151,7 +151,7 @@ 6 | } `---- - x BadUrl { name: Atom('url' type=static), raw_name: "url", raw_value: "\n /* test */\n \"test.png\"\n " } + x BadUrl { raw: "url(\n /* test */\n \"test.png\"\n )" } ,-[$DIR/tests/recovery/function/bad-comment-2/input.css:1:1] 1 | a { 2 | ,-> background: url( diff --git a/crates/swc_css_parser/tests/recovery/function/bad-comment/output.json b/crates/swc_css_parser/tests/recovery/function/bad-comment/output.json index 0336f83f2cdf..c68a72f53d43 100644 --- a/crates/swc_css_parser/tests/recovery/function/bad-comment/output.json +++ b/crates/swc_css_parser/tests/recovery/function/bad-comment/output.json @@ -114,9 +114,7 @@ }, "token": { "BadUrl": { - "name": "url", - "raw_name": "url", - "raw_value": "\n /* test */\n test.png\n " + "raw": "url(\n /* test */\n test.png\n )" } } } diff --git a/crates/swc_css_parser/tests/recovery/function/bad-comment/span.swc-stderr b/crates/swc_css_parser/tests/recovery/function/bad-comment/span.swc-stderr index b97ea238bfc4..4f853d7ad4b6 100644 --- a/crates/swc_css_parser/tests/recovery/function/bad-comment/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/function/bad-comment/span.swc-stderr @@ -151,7 +151,7 @@ 6 | } `---- - x BadUrl { name: Atom('url' type=static), raw_name: "url", raw_value: "\n /* test */\n test.png\n " } + x BadUrl { raw: "url(\n /* test */\n test.png\n )" } ,-[$DIR/tests/recovery/function/bad-comment/input.css:1:1] 1 | a { 2 | ,-> background: url( diff --git a/crates/swc_css_parser/tests/recovery/function/calc/space/output.json b/crates/swc_css_parser/tests/recovery/function/calc/space/output.json index a23543142d39..307873d04b9b 100644 --- a/crates/swc_css_parser/tests/recovery/function/calc/space/output.json +++ b/crates/swc_css_parser/tests/recovery/function/calc/space/output.json @@ -128,8 +128,8 @@ "value": 2.0, "raw_value": "2", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, @@ -145,8 +145,8 @@ "value": 1.0, "raw_value": "+1", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } } diff --git a/crates/swc_css_parser/tests/recovery/function/calc/space/span.swc-stderr b/crates/swc_css_parser/tests/recovery/function/calc/space/span.swc-stderr index ed18eb93a4ab..bc6d9ef72a1d 100644 --- a/crates/swc_css_parser/tests/recovery/function/calc/space/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/function/calc/space/span.swc-stderr @@ -148,7 +148,7 @@ 3 | } `---- - x Dimension { value: 2.0, raw_value: "2", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 2.0, raw_value: "2", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/function/calc/space/input.css:1:1] 1 | .style { 2 | width: calc(2px+1px); @@ -164,7 +164,7 @@ 3 | } `---- - x Dimension { value: 1.0, raw_value: "+1", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 1.0, raw_value: "+1", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/function/calc/space/input.css:1:1] 1 | .style { 2 | width: calc(2px+1px); diff --git a/crates/swc_css_parser/tests/recovery/function/unclosed-2/output.json b/crates/swc_css_parser/tests/recovery/function/unclosed-2/output.json index d2a125ca7487..56a715cbfdb8 100644 --- a/crates/swc_css_parser/tests/recovery/function/unclosed-2/output.json +++ b/crates/swc_css_parser/tests/recovery/function/unclosed-2/output.json @@ -211,8 +211,8 @@ "value": 12.0, "raw_value": "12", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, diff --git a/crates/swc_css_parser/tests/recovery/function/unclosed-2/span.swc-stderr b/crates/swc_css_parser/tests/recovery/function/unclosed-2/span.swc-stderr index 70f85a2f95b8..faf8f291a07c 100644 --- a/crates/swc_css_parser/tests/recovery/function/unclosed-2/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/function/unclosed-2/span.swc-stderr @@ -247,7 +247,7 @@ 3 | } `---- - x Dimension { value: 12.0, raw_value: "12", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 12.0, raw_value: "12", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/function/unclosed-2/input.css:1:1] 1 | .style { 2 | grid-template-columns: repeat(4, [col-start] 12px diff --git a/crates/swc_css_parser/tests/recovery/function/unclosed/output.json b/crates/swc_css_parser/tests/recovery/function/unclosed/output.json index de11c9f5373c..ebfeb75ce3c9 100644 --- a/crates/swc_css_parser/tests/recovery/function/unclosed/output.json +++ b/crates/swc_css_parser/tests/recovery/function/unclosed/output.json @@ -128,8 +128,8 @@ "value": 500.0, "raw_value": "500", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, diff --git a/crates/swc_css_parser/tests/recovery/function/unclosed/span.swc-stderr b/crates/swc_css_parser/tests/recovery/function/unclosed/span.swc-stderr index 659b574c0450..5bdda11cb671 100644 --- a/crates/swc_css_parser/tests/recovery/function/unclosed/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/function/unclosed/span.swc-stderr @@ -143,7 +143,7 @@ 3 | } `---- - x Dimension { value: 500.0, raw_value: "500", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 500.0, raw_value: "500", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/function/unclosed/input.css:1:1] 1 | .style { 2 | width: min(500px; diff --git a/crates/swc_css_parser/tests/recovery/number/output.json b/crates/swc_css_parser/tests/recovery/number/output.json index 5ba5cefc6179..4002a7bd6c1c 100644 --- a/crates/swc_css_parser/tests/recovery/number/output.json +++ b/crates/swc_css_parser/tests/recovery/number/output.json @@ -117,8 +117,8 @@ "value": 10.1, "raw_value": "10.10", "unit": "px", - "raw_unit": "px", - "type": "number" + "type": "number", + "raw_unit": "px" } } }, @@ -183,8 +183,8 @@ "value": 10.0, "raw_value": "10", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, diff --git a/crates/swc_css_parser/tests/recovery/number/span.swc-stderr b/crates/swc_css_parser/tests/recovery/number/span.swc-stderr index 6dcaabed6380..e8e45ce8648d 100644 --- a/crates/swc_css_parser/tests/recovery/number/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/number/span.swc-stderr @@ -149,7 +149,7 @@ 3 | prop1: 10px `---- - x Dimension { value: 10.1, raw_value: "10.10", unit: Atom('px' type=static), raw_unit: "px", type_flag: Number } + x Dimension(DimensionToken { value: 10.1, raw_value: "10.10", unit: Atom('px' type=static), type_flag: Number, raw_unit: "px" }) ,-[$DIR/tests/recovery/number/input.css:1:1] 1 | a { 2 | prop: 10.10px @@ -229,7 +229,7 @@ 4 | prop2: 10 `---- - x Dimension { value: 10.0, raw_value: "10", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 10.0, raw_value: "10", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/number/input.css:2:1] 2 | prop: 10.10px 3 | prop1: 10px diff --git a/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/output.json b/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/output.json index a5dc7d99d4b9..f3f8a360c520 100644 --- a/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/output.json +++ b/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/output.json @@ -231,8 +231,8 @@ "value": 1.0, "raw_value": "1", "unit": "em", - "raw_unit": "em", - "type": "integer" + "type": "integer", + "raw_unit": "em" } } }, diff --git a/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/span.swc-stderr b/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/span.swc-stderr index 8b8e1ed0799b..fca6ca34985b 100644 --- a/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/span.swc-stderr @@ -296,7 +296,7 @@ 6 | } `---- - x Dimension { value: 1.0, raw_value: "1", unit: Atom('em' type=static), raw_unit: "em", type_flag: Integer } + x Dimension(DimensionToken { value: 1.0, raw_value: "1", unit: Atom('em' type=static), type_flag: Integer, raw_unit: "em" }) ,-[$DIR/tests/recovery/style-blocks-contents/invalid-nested-1/input.css:4:1] 4 | input { 5 | margin: 1em; diff --git a/crates/swc_css_parser/tests/recovery/unicode-range/output.json b/crates/swc_css_parser/tests/recovery/unicode-range/output.json index 339fc3cd6eac..d1a4dbdd859e 100644 --- a/crates/swc_css_parser/tests/recovery/unicode-range/output.json +++ b/crates/swc_css_parser/tests/recovery/unicode-range/output.json @@ -124,8 +124,8 @@ "value": 1.0, "raw_value": "+1", "unit": "Z1ee1-FFFFFF", - "raw_unit": "Z1ee1-FFFFFF", - "type": "integer" + "type": "integer", + "raw_unit": "Z1ee1-FFFFFF" } } } @@ -176,8 +176,8 @@ "value": 10.0, "raw_value": "+1e1", "unit": "ee1-FFZFFF", - "raw_unit": "ee1-FFZFFF", - "type": "number" + "type": "number", + "raw_unit": "ee1-FFZFFF" } } } diff --git a/crates/swc_css_parser/tests/recovery/unicode-range/span.swc-stderr b/crates/swc_css_parser/tests/recovery/unicode-range/span.swc-stderr index 54f85a408413..ab506c7e570c 100644 --- a/crates/swc_css_parser/tests/recovery/unicode-range/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/unicode-range/span.swc-stderr @@ -144,7 +144,7 @@ 3 | unicode-range: U+1e1ee1-FFZFFF; `---- - x Dimension { value: 1.0, raw_value: "+1", unit: Atom('Z1ee1-FFFFFF' type=dynamic), raw_unit: "Z1ee1-FFFFFF", type_flag: Integer } + x Dimension(DimensionToken { value: 1.0, raw_value: "+1", unit: Atom('Z1ee1-FFFFFF' type=dynamic), type_flag: Integer, raw_unit: "Z1ee1-FFFFFF" }) ,-[$DIR/tests/recovery/unicode-range/input.css:1:1] 1 | .class { 2 | unicode-range: U+1Z1ee1-FFFFFF; @@ -216,7 +216,7 @@ 4 | } `---- - x Dimension { value: 10.0, raw_value: "+1e1", unit: Atom('ee1-FFZFFF' type=dynamic), raw_unit: "ee1-FFZFFF", type_flag: Number } + x Dimension(DimensionToken { value: 10.0, raw_value: "+1e1", unit: Atom('ee1-FFZFFF' type=dynamic), type_flag: Number, raw_unit: "ee1-FFZFFF" }) ,-[$DIR/tests/recovery/unicode-range/input.css:2:1] 2 | unicode-range: U+1Z1ee1-FFFFFF; 3 | unicode-range: U+1e1ee1-FFZFFF; diff --git a/crates/swc_css_parser/tests/recovery/value/quotes/output.json b/crates/swc_css_parser/tests/recovery/value/quotes/output.json index 739ae033f81c..d1d0c650f8ef 100644 --- a/crates/swc_css_parser/tests/recovery/value/quotes/output.json +++ b/crates/swc_css_parser/tests/recovery/value/quotes/output.json @@ -134,7 +134,7 @@ }, "token": { "BadString": { - "raw_value": "\"tes" + "raw": "\"tes" } } }, @@ -174,7 +174,7 @@ }, "token": { "BadString": { - "raw_value": "\";" + "raw": "\";" } } } diff --git a/crates/swc_css_parser/tests/recovery/value/quotes/span.swc-stderr b/crates/swc_css_parser/tests/recovery/value/quotes/span.swc-stderr index 0ce0a3d5cc90..cf33f6bda8e0 100644 --- a/crates/swc_css_parser/tests/recovery/value/quotes/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/value/quotes/span.swc-stderr @@ -156,7 +156,7 @@ 3 | t"; `---- - x BadString { raw_value: "\"tes" } + x BadString { raw: "\"tes" } ,-[$DIR/tests/recovery/value/quotes/input.css:1:1] 1 | p::before { 2 | content: "tes @@ -204,7 +204,7 @@ 4 | } `---- - x BadString { raw_value: "\";" } + x BadString { raw: "\";" } ,-[$DIR/tests/recovery/value/quotes/input.css:2:1] 2 | content: "tes 3 | t"; diff --git a/crates/swc_css_parser/tests/recovery/value/string/newline/output.json b/crates/swc_css_parser/tests/recovery/value/string/newline/output.json index 1607251647d5..52d2e7ee37cc 100644 --- a/crates/swc_css_parser/tests/recovery/value/string/newline/output.json +++ b/crates/swc_css_parser/tests/recovery/value/string/newline/output.json @@ -114,7 +114,7 @@ }, "token": { "BadString": { - "raw_value": "\"" + "raw": "\"" } } } diff --git a/crates/swc_css_parser/tests/recovery/value/string/newline/span.swc-stderr b/crates/swc_css_parser/tests/recovery/value/string/newline/span.swc-stderr index dec255cfe8cd..892a68ceb02e 100644 --- a/crates/swc_css_parser/tests/recovery/value/string/newline/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/value/string/newline/span.swc-stderr @@ -121,7 +121,7 @@ : ^ `---- - x BadString { raw_value: "\"" } + x BadString { raw: "\"" } ,-[$DIR/tests/recovery/value/string/newline/input.css:1:1] 1 | a { 2 | prop: " diff --git a/crates/swc_css_parser/tests/recovery/value/url/basic/output.json b/crates/swc_css_parser/tests/recovery/value/url/basic/output.json index 48ea67f98d25..479730e0ece7 100644 --- a/crates/swc_css_parser/tests/recovery/value/url/basic/output.json +++ b/crates/swc_css_parser/tests/recovery/value/url/basic/output.json @@ -149,9 +149,7 @@ }, "token": { "BadUrl": { - "name": "url", - "raw_name": "url", - "raw_value": "var(--foo" + "raw": "url(var(--foo)" } } }, @@ -552,9 +550,7 @@ }, "token": { "BadUrl": { - "name": "url", - "raw_name": "url", - "raw_value": "image.png param(var(--url" + "raw": "url(image.png param(var(--url)" } } }, diff --git a/crates/swc_css_parser/tests/recovery/value/url/basic/span.swc-stderr b/crates/swc_css_parser/tests/recovery/value/url/basic/span.swc-stderr index a77fb944811e..7ed7693180c9 100644 --- a/crates/swc_css_parser/tests/recovery/value/url/basic/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/value/url/basic/span.swc-stderr @@ -223,7 +223,7 @@ 4 | background: url(image.png\999999); `---- - x BadUrl { name: Atom('url' type=static), raw_name: "url", raw_value: "var(--foo" } + x BadUrl { raw: "url(var(--foo)" } ,-[$DIR/tests/recovery/value/url/basic/input.css:2:1] 2 | --foo: "http://www.example.com/pinkish.gif"; 3 | background: url(var(--foo)); @@ -831,7 +831,7 @@ 14 | } `---- - x BadUrl { name: Atom('url' type=static), raw_name: "url", raw_value: "image.png param(var(--url" } + x BadUrl { raw: "url(image.png param(var(--url)" } ,-[$DIR/tests/recovery/value/url/basic/input.css:12:1] 12 | .foo { 13 | background: url(image.png param(var(--url))); diff --git a/crates/swc_css_parser/tests/recovery/value/url/parenthesis/output.json b/crates/swc_css_parser/tests/recovery/value/url/parenthesis/output.json index e6241c5aa5ce..90a70cf4fcc1 100644 --- a/crates/swc_css_parser/tests/recovery/value/url/parenthesis/output.json +++ b/crates/swc_css_parser/tests/recovery/value/url/parenthesis/output.json @@ -114,9 +114,7 @@ }, "token": { "BadUrl": { - "name": "url", - "raw_name": "url", - "raw_value": "test\\);\n}" + "raw": "url(test\\);\n}" } } } diff --git a/crates/swc_css_parser/tests/recovery/value/url/parenthesis/span.swc-stderr b/crates/swc_css_parser/tests/recovery/value/url/parenthesis/span.swc-stderr index 1f6ae721f169..02c1bd5b83c1 100644 --- a/crates/swc_css_parser/tests/recovery/value/url/parenthesis/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/value/url/parenthesis/span.swc-stderr @@ -127,7 +127,7 @@ 3 | `-> } `---- - x BadUrl { name: Atom('url' type=static), raw_name: "url", raw_value: "test\\);\n}" } + x BadUrl { raw: "url(test\\);\n}" } ,-[$DIR/tests/recovery/value/url/parenthesis/input.css:1:1] 1 | a { 2 | ,-> background: url(test\); diff --git a/crates/swc_css_parser/tests/recovery/vercel/004/output.json b/crates/swc_css_parser/tests/recovery/vercel/004/output.json index fe0ff6b3dce1..0aa03c837ba4 100644 --- a/crates/swc_css_parser/tests/recovery/vercel/004/output.json +++ b/crates/swc_css_parser/tests/recovery/vercel/004/output.json @@ -220,8 +220,8 @@ "value": 7.0, "raw_value": "7", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, diff --git a/crates/swc_css_parser/tests/recovery/vercel/004/span.swc-stderr b/crates/swc_css_parser/tests/recovery/vercel/004/span.swc-stderr index 7030a1a9597c..8f93ebf6c26e 100644 --- a/crates/swc_css_parser/tests/recovery/vercel/004/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/vercel/004/span.swc-stderr @@ -288,7 +288,7 @@ 5 | color: white; `---- - x Dimension { value: 7.0, raw_value: "7", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 7.0, raw_value: "7", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/vercel/004/input.css:3:1] 3 | __ident__ 4 | border-radius: 7px; diff --git a/crates/swc_css_parser/tests/recovery/vercel/005/output.json b/crates/swc_css_parser/tests/recovery/vercel/005/output.json index a7c3ca49c95c..a3c55442a090 100644 --- a/crates/swc_css_parser/tests/recovery/vercel/005/output.json +++ b/crates/swc_css_parser/tests/recovery/vercel/005/output.json @@ -155,8 +155,8 @@ "value": 7.0, "raw_value": "7", "unit": "px", - "raw_unit": "px", - "type": "integer" + "type": "integer", + "raw_unit": "px" } } }, diff --git a/crates/swc_css_parser/tests/recovery/vercel/005/span.swc-stderr b/crates/swc_css_parser/tests/recovery/vercel/005/span.swc-stderr index ddeecefd9fff..4a6e2949e60d 100644 --- a/crates/swc_css_parser/tests/recovery/vercel/005/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/vercel/005/span.swc-stderr @@ -216,7 +216,7 @@ 5 | color: white; `---- - x Dimension { value: 7.0, raw_value: "7", unit: Atom('px' type=static), raw_unit: "px", type_flag: Integer } + x Dimension(DimensionToken { value: 7.0, raw_value: "7", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/recovery/vercel/005/input.css:3:1] 3 | __ident__ 4 | border-radius: 7px; diff --git a/crates/swc_css_prefixer/src/prefixer.rs b/crates/swc_css_prefixer/src/prefixer.rs index 545185d40d5b..e2ab9db30a7d 100644 --- a/crates/swc_css_prefixer/src/prefixer.rs +++ b/crates/swc_css_prefixer/src/prefixer.rs @@ -133,7 +133,7 @@ impl VisitMut for CrossFadeFunctionReplacerOnLegacyVariant<'_> { for group in n.value.split_mut(|n| { matches!( n, - ComponentValue::Delimiter(Delimiter { + ComponentValue::Delimiter(delimiter) if matches!(&**delimiter, Delimiter { value: DelimiterValue::Comma, .. }) @@ -147,29 +147,26 @@ impl VisitMut for CrossFadeFunctionReplacerOnLegacyVariant<'_> { for n in group { match n { - ComponentValue::Percentage(Percentage { - value: Number { value, .. }, - .. - }) => { + ComponentValue::Percentage(percentage) => { if transparency_value.is_some() { return; } - transparency_value = Some(*value / 100.0); + transparency_value = Some(percentage.value.value / 100.0); } - ComponentValue::Number(Number { value, .. }) => { + ComponentValue::Number(number) => { if transparency_value.is_some() { return; } - transparency_value = Some(*value); + transparency_value = Some(number.value); } - ComponentValue::Integer(Integer { value, .. }) => { + ComponentValue::Integer(integer) => { if transparency_value.is_some() { return; } - transparency_value = Some((*value) as f64); + transparency_value = Some((integer.value) as f64); } _ => {} } @@ -207,15 +204,15 @@ impl VisitMut for CrossFadeFunctionReplacerOnLegacyVariant<'_> { .collect(); new_value.extend(vec![ - ComponentValue::Delimiter(Delimiter { + ComponentValue::Delimiter(Box::new(Delimiter { span: DUMMY_SP, value: DelimiterValue::Comma, - }), - ComponentValue::Number(Number { + })), + ComponentValue::Number(Box::new(Number { span: DUMMY_SP, value: transparency_value, raw: None, - }), + })), ]); n.value = new_value; @@ -247,9 +244,9 @@ impl VisitMut for ImageSetFunctionReplacerOnLegacyVariant<'_> { return; } - if let ComponentValue::Str(Str { span, value, .. }) = n { - *n = ComponentValue::Url(Url { - span: *span, + if let ComponentValue::Str(node) = n { + *n = ComponentValue::Url(Box::new(Url { + span: node.span, name: Ident { span: DUMMY_SP, value: js_word!("url"), @@ -257,11 +254,11 @@ impl VisitMut for ImageSetFunctionReplacerOnLegacyVariant<'_> { }, value: Some(Box::new(UrlValue::Str(Str { span: DUMMY_SP, - value: value.as_ref().into(), + value: node.value.as_ref().into(), raw: None, }))), modifiers: Some(vec![]), - }) + })) } } @@ -310,8 +307,8 @@ impl VisitMut for LinearGradientFunctionReplacerOnLegacyVariant<'_> { let first = n.value.get(0); match first { - Some(ComponentValue::Ident(Ident { value, .. })) - if value.as_ref().eq_ignore_ascii_case("to") => + Some(ComponentValue::Ident(ident)) + if ident.value.as_ref().eq_ignore_ascii_case("to") => { fn get_old_direction(direction: &str) -> Option<&str> { match direction { @@ -325,12 +322,12 @@ impl VisitMut for LinearGradientFunctionReplacerOnLegacyVariant<'_> { match (n.value.get(1), n.value.get(2)) { ( - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: first_value, span: first_span, .. })), - Some(ComponentValue::Ident(Ident { + Some(ComponentValue::Ident(box Ident { value: second_value, span: second_span, .. @@ -341,28 +338,28 @@ impl VisitMut for LinearGradientFunctionReplacerOnLegacyVariant<'_> { get_old_direction(second_value), ) { let new_value = vec![ - ComponentValue::Ident(Ident { + ComponentValue::Ident(Box::new(Ident { span: *first_span, value: new_first_direction.into(), raw: None, - }), - ComponentValue::Ident(Ident { + })), + ComponentValue::Ident(Box::new(Ident { span: *second_span, value: new_second_direction.into(), raw: None, - }), + })), ]; n.value.splice(0..3, new_value); } } - (Some(ComponentValue::Ident(Ident { value, span, .. })), Some(_)) => { + (Some(ComponentValue::Ident(box Ident { value, span, .. })), Some(_)) => { if let Some(new_direction) = get_old_direction(value) { - let new_value = vec![ComponentValue::Ident(Ident { + let new_value = vec![ComponentValue::Ident(Box::new(Ident { span: *span, value: new_direction.into(), raw: None, - })]; + }))]; n.value.splice(0..2, new_value); } @@ -370,7 +367,7 @@ impl VisitMut for LinearGradientFunctionReplacerOnLegacyVariant<'_> { _ => {} } } - Some(ComponentValue::Dimension(Dimension::Angle(Angle { + Some(ComponentValue::Dimension(box Dimension::Angle(Angle { value, unit, span, @@ -387,33 +384,33 @@ impl VisitMut for LinearGradientFunctionReplacerOnLegacyVariant<'_> { }; if angle == 0.0 { - n.value[0] = ComponentValue::Ident(Ident { + n.value[0] = ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("bottom"), raw: None, - }); + })); } else if angle == 90.0 { - n.value[0] = ComponentValue::Ident(Ident { + n.value[0] = ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("left"), raw: None, - }); + })); } else if angle == 180.0 { - n.value[0] = ComponentValue::Ident(Ident { + n.value[0] = ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("top"), raw: None, - }); + })); } else if angle == 270.0 { - n.value[0] = ComponentValue::Ident(Ident { + n.value[0] = ComponentValue::Ident(Box::new(Ident { span: *span, value: js_word!("right"), raw: None, - }); + })); } else { let new_value = ((450.0 - angle).abs() % 360.0 * 1000.0).round() / 1000.0; - n.value[0] = ComponentValue::Dimension(Dimension::Angle(Angle { + n.value[0] = ComponentValue::Dimension(Box::new(Dimension::Angle(Angle { span: *span, value: Number { span: value.span, @@ -425,18 +422,18 @@ impl VisitMut for LinearGradientFunctionReplacerOnLegacyVariant<'_> { value: js_word!("deg"), raw: None, }, - })); + }))); } } Some(_) | None => {} } if matches!(self.from, "radial-gradient" | "repeating-radial-gradient") { - let at_index = n.value.iter().position(|n| matches!(n, ComponentValue::Ident(Ident { value, .. }) if value.as_ref().eq_ignore_ascii_case("at"))); + let at_index = n.value.iter().position(|n| matches!(n, ComponentValue::Ident(box Ident { value, .. }) if value.as_ref().eq_ignore_ascii_case("at"))); let first_comma_index = n.value.iter().position(|n| { matches!( n, - ComponentValue::Delimiter(Delimiter { + ComponentValue::Delimiter(delimiter) if matches!(&**delimiter, Delimiter { value: DelimiterValue::Comma, .. }) @@ -447,10 +444,10 @@ impl VisitMut for LinearGradientFunctionReplacerOnLegacyVariant<'_> { let mut new_value = vec![]; new_value.append(&mut n.value[at_index + 1..first_comma_index].to_vec()); - new_value.append(&mut vec![ComponentValue::Delimiter(Delimiter { + new_value.append(&mut vec![ComponentValue::Delimiter(Box::new(Delimiter { span: DUMMY_SP, value: DelimiterValue::Comma, - })]); + }))]); new_value.append(&mut n.value[0..at_index].to_vec()); n.value.splice(0..first_comma_index, new_value); @@ -520,21 +517,21 @@ where macro_rules! to_ident { ($val:expr) => {{ - ComponentValue::Ident(Ident { + ComponentValue::Ident(Box::new(Ident { span: DUMMY_SP, value: $val.into(), raw: None, - }) + })) }}; } macro_rules! to_integer { ($val:expr) => {{ - ComponentValue::Integer(Integer { + ComponentValue::Integer(Box::new(Integer { span: DUMMY_SP, value: $val, raw: None, - }) + })) }}; } @@ -711,9 +708,9 @@ impl VisitMut for Prefixer { if let Some(ComponentValue::Declaration(declaration)) = supports.value.get(0) { conditions.push(SupportsConditionType::SupportsInParens( - SupportsInParens::Feature(SupportsFeature::Declaration(Box::new( + SupportsInParens::Feature(SupportsFeature::Declaration( declaration.clone(), - ))), + )), )); } @@ -732,10 +729,12 @@ impl VisitMut for Prefixer { import_conditions.supports = Some(Box::new(Function { span: supports.span, name: supports.name, - value: vec![ComponentValue::SupportsCondition(SupportsCondition { - span: DUMMY_SP, - conditions, - })], + value: vec![ComponentValue::SupportsCondition(Box::new( + SupportsCondition { + span: DUMMY_SP, + conditions, + }, + ))], })); } } @@ -1134,12 +1133,9 @@ impl VisitMut for Prefixer { match n { ComponentValue::DeclarationOrAtRule(_) => { - new.extend( - self.added_declarations - .drain(..) - .map(StyleBlock::Declaration) - .map(ComponentValue::StyleBlock), - ); + new.extend(self.added_declarations.drain(..).map(|node| { + ComponentValue::StyleBlock(Box::new(StyleBlock::Declaration(node))) + })); for mut n in take(&mut self.added_at_rules) { let old_rule_prefix = self.rule_prefix.take(); @@ -1148,7 +1144,9 @@ impl VisitMut for Prefixer { n.1.visit_mut_children_with(self); - new.push(ComponentValue::StyleBlock(StyleBlock::AtRule(n.1))); + new.push(ComponentValue::StyleBlock(Box::new(StyleBlock::AtRule( + n.1, + )))); self.rule_prefix = old_rule_prefix; } @@ -1161,7 +1159,9 @@ impl VisitMut for Prefixer { n.1.visit_mut_children_with(self); - new.push(ComponentValue::StyleBlock(StyleBlock::QualifiedRule(n.1))); + new.push(ComponentValue::StyleBlock(Box::new( + StyleBlock::QualifiedRule(n.1), + ))); self.rule_prefix = old_rule_prefix; } @@ -1173,18 +1173,17 @@ impl VisitMut for Prefixer { n.1.visit_mut_children_with(self); - new.push(ComponentValue::StyleBlock(StyleBlock::AtRule(n.1))); + new.push(ComponentValue::StyleBlock(Box::new(StyleBlock::AtRule( + n.1, + )))); self.rule_prefix = old_rule_prefix; } } ComponentValue::StyleBlock(_) => { - new.extend( - self.added_declarations - .drain(..) - .map(StyleBlock::Declaration) - .map(ComponentValue::StyleBlock), - ); + new.extend(self.added_declarations.drain(..).map(|node| { + ComponentValue::StyleBlock(Box::new(StyleBlock::Declaration(node))) + })); for mut n in take(&mut self.added_qualified_rules) { let old_rule_prefix = self.rule_prefix.take(); @@ -1193,7 +1192,9 @@ impl VisitMut for Prefixer { n.1.visit_mut_children_with(self); - new.push(ComponentValue::StyleBlock(StyleBlock::QualifiedRule(n.1))); + new.push(ComponentValue::StyleBlock(Box::new( + StyleBlock::QualifiedRule(n.1), + ))); self.rule_prefix = old_rule_prefix; } @@ -1205,7 +1206,9 @@ impl VisitMut for Prefixer { n.1.visit_mut_children_with(self); - new.push(ComponentValue::StyleBlock(StyleBlock::AtRule(n.1))); + new.push(ComponentValue::StyleBlock(Box::new(StyleBlock::AtRule( + n.1, + )))); self.rule_prefix = old_rule_prefix; } @@ -1393,12 +1396,12 @@ impl VisitMut for Prefixer { for n in simple_block.value.iter() { match n { - ComponentValue::DeclarationOrAtRule(DeclarationOrAtRule::Declaration( - declaration, - )) => { + ComponentValue::DeclarationOrAtRule( + box DeclarationOrAtRule::Declaration(declaration), + ) => { declarations.push(declaration); } - ComponentValue::StyleBlock(StyleBlock::Declaration(declaration)) => { + ComponentValue::StyleBlock(box StyleBlock::Declaration(declaration)) => { declarations.push(declaration); } _ => {} @@ -1480,9 +1483,10 @@ impl VisitMut for Prefixer { "animation" => { let need_prefix = n.value.iter().all(|n| match n { - ComponentValue::Ident(Ident { value, .. }) => { - !matches!(&*value.to_lowercase(), "reverse" | "alternate-reverse") - } + ComponentValue::Ident(ident) => !matches!( + &*ident.value.to_lowercase(), + "reverse" | "alternate-reverse" + ), _ => true, }); @@ -1512,8 +1516,8 @@ impl VisitMut for Prefixer { } "animation-direction" => { - if let ComponentValue::Ident(Ident { value, .. }) = &n.value[0] { - match &*value.to_lowercase() { + if let ComponentValue::Ident(ident) = &n.value[0] { + match &*ident.value.to_lowercase() { "alternate-reverse" | "reverse" => {} _ => { add_declaration!(Prefix::Webkit, "-webkit-animation-direction", None); @@ -1549,8 +1553,8 @@ impl VisitMut for Prefixer { } "background-clip" => { - if let ComponentValue::Ident(Ident { value, .. }) = &n.value[0] { - if &*value.to_lowercase() == "text" { + if let ComponentValue::Ident(ident) = &n.value[0] { + if &*ident.value.to_lowercase() == "text" { add_declaration!(Prefix::Webkit, "-webkit-background-clip", None); } } @@ -1719,23 +1723,23 @@ impl VisitMut for Prefixer { "flex" => { let spec_2009_value = match n.value.get(0) { - Some(ComponentValue::Ident(Ident { value, span, .. })) - if value.as_ref().eq_ignore_ascii_case("none") => + Some(ComponentValue::Ident(ident)) + if ident.value.as_ref().eq_ignore_ascii_case("none") => { - Some(ComponentValue::Integer(Integer { - span: *span, + Some(ComponentValue::Integer(Box::new(Integer { + span: ident.span, value: 0, raw: None, - })) + }))) } - Some(ComponentValue::Ident(Ident { value, span, .. })) - if value.as_ref().eq_ignore_ascii_case("auto") => + Some(ComponentValue::Ident(ident)) + if ident.value.as_ref().eq_ignore_ascii_case("auto") => { - Some(ComponentValue::Integer(Integer { - span: *span, + Some(ComponentValue::Integer(Box::new(Integer { + span: ident.span, value: 1, raw: None, - })) + }))) } Some(any) => Some(any.clone()), None => None, @@ -1770,23 +1774,27 @@ impl VisitMut for Prefixer { Some(Box::new(|| { let mut value = ms_value.clone(); - if let Some(ComponentValue::Integer(Integer { - value: 0, span, .. + if let Some(ComponentValue::Integer(box Integer { + value: 0, + span, + .. })) = value.get(2) { - value[2] = ComponentValue::Dimension(Dimension::Length(Length { - span: *span, - value: Number { - span: DUMMY_SP, - value: 0.0, - raw: None, + value[2] = ComponentValue::Dimension(Box::new(Dimension::Length( + Length { + span: *span, + value: Number { + span: DUMMY_SP, + value: 0.0, + raw: None, + }, + unit: Ident { + span: DUMMY_SP, + value: js_word!("px"), + raw: None, + }, }, - unit: Ident { - span: DUMMY_SP, - value: js_word!("px"), - raw: None, - }, - })); + ))); } value @@ -1816,23 +1824,23 @@ impl VisitMut for Prefixer { "flex-direction" => { let old_values = match n.value.get(0) { - Some(ComponentValue::Ident(Ident { value, .. })) - if value.as_ref().eq_ignore_ascii_case("row") => + Some(ComponentValue::Ident(ident)) + if ident.value.as_ref().eq_ignore_ascii_case("row") => { Some(("horizontal", "normal")) } - Some(ComponentValue::Ident(Ident { value, .. })) - if value.as_ref().eq_ignore_ascii_case("column") => + Some(ComponentValue::Ident(ident)) + if ident.value.as_ref().eq_ignore_ascii_case("column") => { Some(("vertical", "normal")) } - Some(ComponentValue::Ident(Ident { value, .. })) - if value.as_ref().eq_ignore_ascii_case("row-reverse") => + Some(ComponentValue::Ident(ident)) + if ident.value.as_ref().eq_ignore_ascii_case("row-reverse") => { Some(("horizontal", "reverse")) } - Some(ComponentValue::Ident(Ident { value, .. })) - if value.as_ref().eq_ignore_ascii_case("column-reverse") => + Some(ComponentValue::Ident(ident)) + if ident.value.as_ref().eq_ignore_ascii_case("column-reverse") => { Some(("vertical", "reverse")) } @@ -1876,7 +1884,7 @@ impl VisitMut for Prefixer { } "flex-flow" => { - let is_single_flex_wrap = matches!(n.value.get(0), Some(ComponentValue::Ident(Ident { value, .. })) if n.value.len() == 1 + let is_single_flex_wrap = matches!(n.value.get(0), Some(ComponentValue::Ident(box Ident { value, .. })) if n.value.len() == 1 && matches!( &*value.to_lowercase(), "wrap" | "nowrap" | "wrap-reverse" @@ -1886,23 +1894,23 @@ impl VisitMut for Prefixer { true => None, _ => { let get_old_values = |index: usize| match n.value.get(index) { - Some(ComponentValue::Ident(Ident { value, .. })) - if value.as_ref().eq_ignore_ascii_case("row") => + Some(ComponentValue::Ident(ident)) + if ident.value.as_ref().eq_ignore_ascii_case("row") => { Some(("horizontal", "normal")) } - Some(ComponentValue::Ident(Ident { value, .. })) - if value.as_ref().eq_ignore_ascii_case("column") => + Some(ComponentValue::Ident(ident)) + if ident.value.as_ref().eq_ignore_ascii_case("column") => { Some(("vertical", "normal")) } - Some(ComponentValue::Ident(Ident { value, .. })) - if value.as_ref().eq_ignore_ascii_case("row-reverse") => + Some(ComponentValue::Ident(ident)) + if ident.value.as_ref().eq_ignore_ascii_case("row-reverse") => { Some(("horizontal", "reverse")) } - Some(ComponentValue::Ident(Ident { value, .. })) - if value.as_ref().eq_ignore_ascii_case("column-reverse") => + Some(ComponentValue::Ident(ident)) + if ident.value.as_ref().eq_ignore_ascii_case("column-reverse") => { Some(("vertical", "reverse")) } @@ -1945,7 +1953,7 @@ impl VisitMut for Prefixer { } "justify-content" => { - let need_old_spec = !matches!(n.value.get(0), Some(ComponentValue::Ident(Ident { value, .. })) if value.as_ref().eq_ignore_ascii_case("space-around")); + let need_old_spec = !matches!(n.value.get(0), Some(ComponentValue::Ident(box Ident { value, .. })) if value.as_ref().eq_ignore_ascii_case("space-around")); if need_old_spec { add_declaration!( @@ -2003,7 +2011,7 @@ impl VisitMut for Prefixer { "order" => { let old_spec_num = match n.value.get(0) { - Some(ComponentValue::Integer(Integer { value, .. })) => Some(value + 1), + Some(ComponentValue::Integer(integer)) => Some(integer.value + 1), _ => None, }; @@ -2161,8 +2169,8 @@ impl VisitMut for Prefixer { "filter" => match &n.value[0] { ComponentValue::PreservedToken(_) => {} - ComponentValue::Function(Function { name, .. }) - if name.value.as_ref().eq_ignore_ascii_case("alpha") => {} + ComponentValue::Function(function) + if function.name.value.as_ref().eq_ignore_ascii_case("alpha") => {} _ => { add_declaration!(Prefix::Webkit, "-webkit-filter", None); } @@ -2304,8 +2312,8 @@ impl VisitMut for Prefixer { add_declaration!(Prefix::Webkit, "-webkit-user-select", None); add_declaration!(Prefix::Moz, "-moz-user-select", None); - if let ComponentValue::Ident(Ident { value, .. }) = &n.value[0] { - match &*value.to_lowercase() { + if let ComponentValue::Ident(ident) = &n.value[0] { + match &*ident.value.to_lowercase() { "contain" => { add_declaration!( Prefix::Ms, @@ -2326,9 +2334,9 @@ impl VisitMut for Prefixer { add_declaration!(Prefix::Moz, "-moz-transform", None); let has_3d_function = n.value.iter().any(|n| match n { - ComponentValue::Function(Function { name, .. }) + ComponentValue::Function(function) if matches!( - &*name.value.to_ascii_lowercase(), + &*function.name.value.to_ascii_lowercase(), "matrix3d" | "translate3d" | "translatez" @@ -2384,9 +2392,9 @@ impl VisitMut for Prefixer { "text-decoration" => { if n.value.len() == 1 { match &n.value[0] { - ComponentValue::Ident(Ident { value, .. }) + ComponentValue::Ident(ident) if matches!( - &*value.to_lowercase(), + &*ident.value.to_lowercase(), "none" | "underline" | "overline" @@ -2428,8 +2436,8 @@ impl VisitMut for Prefixer { } "text-decoration-skip-ink" => { - if let ComponentValue::Ident(Ident { value, .. }) = &n.value[0] { - match &*value.to_lowercase() { + if let ComponentValue::Ident(ident) = &n.value[0] { + match &*ident.value.to_lowercase() { "auto" => { add_declaration!( Prefix::Webkit, @@ -2449,8 +2457,8 @@ impl VisitMut for Prefixer { } "text-size-adjust" if n.value.len() == 1 => { - if let ComponentValue::Ident(Ident { value, .. }) = &n.value[0] { - if &*value.to_lowercase() == "none" { + if let ComponentValue::Ident(ident) = &n.value[0] { + if &*ident.value.to_lowercase() == "none" { add_declaration!(Prefix::Webkit, "-webkit-text-size-adjust", None); add_declaration!(Prefix::Moz, "-moz-text-size-adjust", None); add_declaration!(Prefix::Ms, "-ms-text-size-adjust", None); @@ -2546,8 +2554,8 @@ impl VisitMut for Prefixer { } if value.as_ref().eq_ignore_ascii_case("direction")) }) { Some(box Declaration { value, .. }) => match value.get(0) { - Some(ComponentValue::Ident(Ident { value, .. })) - if value.as_ref().eq_ignore_ascii_case("rtl") => + Some(ComponentValue::Ident(ident)) + if ident.value.as_ref().eq_ignore_ascii_case("rtl") => { Some("rtl") } @@ -2556,8 +2564,8 @@ impl VisitMut for Prefixer { _ => Some("ltr"), }; - if let ComponentValue::Ident(Ident { value, .. }) = &n.value[0] { - match &*value.to_lowercase() { + if let ComponentValue::Ident(ident) = &n.value[0] { + match &*ident.value.to_lowercase() { "vertical-lr" => { add_declaration!(Prefix::Webkit, "-webkit-writing-mode", None); @@ -2926,8 +2934,8 @@ impl VisitMut for Prefixer { } "overscroll-behavior" => { - if let ComponentValue::Ident(Ident { value, .. }) = &n.value[0] { - match &*value.to_lowercase() { + if let ComponentValue::Ident(ident) = &n.value[0] { + match &*ident.value.to_lowercase() { "auto" => { add_declaration!( Prefix::Ms, @@ -2961,8 +2969,8 @@ impl VisitMut for Prefixer { } "break-inside" => { - if let ComponentValue::Ident(Ident { value, .. }) = &n.value[0] { - match &*value.to_lowercase() { + if let ComponentValue::Ident(ident) = &n.value[0] { + match &*ident.value.to_lowercase() { "auto" | "avoid" => { add_declaration!(Prefix::Webkit, "-webkit-column-break-inside", None); } @@ -2972,8 +2980,8 @@ impl VisitMut for Prefixer { } "break-before" => { - if let ComponentValue::Ident(Ident { value, .. }) = &n.value[0] { - match &*value.to_lowercase() { + if let ComponentValue::Ident(ident) = &n.value[0] { + match &*ident.value.to_lowercase() { "auto" | "avoid" => { add_declaration!(Prefix::Webkit, "-webkit-column-break-before", None); } @@ -2990,8 +2998,8 @@ impl VisitMut for Prefixer { } "break-after" => { - if let ComponentValue::Ident(Ident { value, .. }) = &n.value[0] { - match &*value.to_lowercase() { + if let ComponentValue::Ident(ident) = &n.value[0] { + match &*ident.value.to_lowercase() { "auto" | "avoid" => { add_declaration!(Prefix::Webkit, "-webkit-column-break-after", None); } diff --git a/crates/swc_css_visit/src/lib.rs b/crates/swc_css_visit/src/lib.rs index dfedd13584a5..08459fde8ebe 100644 --- a/crates/swc_css_visit/src/lib.rs +++ b/crates/swc_css_visit/src/lib.rs @@ -23,36 +23,36 @@ define!({ } pub enum ComponentValue { - PreservedToken(TokenAndSpan), - Function(Function), - SimpleBlock(SimpleBlock), + PreservedToken(Box), + Function(Box), + SimpleBlock(Box), - DeclarationOrAtRule(DeclarationOrAtRule), - Rule(Rule), - StyleBlock(StyleBlock), - KeyframeBlock(KeyframeBlock), + DeclarationOrAtRule(Box), + Rule(Box), + StyleBlock(Box), + KeyframeBlock(Box), - Ident(Ident), - DashedIdent(DashedIdent), - Str(Str), - Url(Url), - Integer(Integer), - Number(Number), - Percentage(Percentage), - Dimension(Dimension), - Ratio(Ratio), - UnicodeRange(UnicodeRange), - Color(Color), - AlphaValue(AlphaValue), - Hue(Hue), - CmykComponent(CmykComponent), - Delimiter(Delimiter), - - CalcSum(CalcSum), - ComplexSelector(ComplexSelector), - LayerName(LayerName), - SupportsCondition(SupportsCondition), - Declaration(Declaration), + Ident(Box), + DashedIdent(Box), + Str(Box), + Url(Box), + Integer(Box), + Number(Box), + Percentage(Box), + Dimension(Box), + Ratio(Box), + UnicodeRange(Box), + Color(Box), + AlphaValue(Box), + Hue(Box), + CmykComponent(Box), + Delimiter(Box), + + CalcSum(Box), + ComplexSelector(Box), + LayerName(Box), + SupportsCondition(Box), + Declaration(Box), } pub struct Ident { diff --git a/crates/swc_html_minifier/src/lib.rs b/crates/swc_html_minifier/src/lib.rs index ff4c362f7ca9..936a0e8d8a1c 100644 --- a/crates/swc_html_minifier/src/lib.rs +++ b/crates/swc_html_minifier/src/lib.rs @@ -2336,7 +2336,9 @@ impl Minifier<'_> { let declaration_list: Vec = list_of_declarations .into_iter() - .map(swc_css_ast::ComponentValue::DeclarationOrAtRule) + .map(|node| { + swc_css_ast::ComponentValue::DeclarationOrAtRule(Box::new(node)) + }) .collect(); swc_css_ast::Stylesheet { @@ -2394,13 +2396,13 @@ impl Minifier<'_> { }, // TODO make the `compress_empty` option for CSS minifier and // remove it - value: vec![swc_css_ast::ComponentValue::Str( + value: vec![swc_css_ast::ComponentValue::Str(Box::new( swc_css_ast::Str { span: Default::default(), value: js_word!("placeholder"), raw: None, }, - )], + ))], }), } .into(),