From 024589079277b339289ff4fde89732c099552ece Mon Sep 17 00:00:00 2001 From: "alexander.akait" Date: Fri, 16 Dec 2022 00:29:53 +0300 Subject: [PATCH] feat(css/parser): normalize and improve function name --- .../swc_atoms/scripts/add-from-cargo-check.sh | 0 crates/swc_atoms/words.txt | 263 ++++++ crates/swc_css_ast/src/base.rs | 11 +- crates/swc_css_parser/src/parser/input.rs | 39 +- .../swc_css_parser/src/parser/syntax/mod.rs | 41 +- crates/swc_css_parser/src/parser/util.rs | 3 +- .../src/parser/values_and_units/mod.rs | 803 ++++++++++-------- .../tests/fixture/at-rule/import/output.json | 10 +- .../fixture/at-rule/keyframe/output.json | 8 +- .../fixture/at-rule/supports/output.json | 2 +- .../fixture/at-rule/supports/span.swc-stderr | 12 +- .../fixture/at-rule/unknown/span.swc-stderr | 2 +- .../fixture/dashed-ident/span.swc-stderr | 2 +- .../fixture/function/unknown/output.json | 62 +- .../fixture/function/unknown/span.swc-stderr | 56 +- .../tests/fixture/function/url/output.json | 2 +- .../tests/fixture/value/color/output.json | 6 +- .../tests/fixture/value/url/output.json | 6 +- .../media/wrong-stylesheet/span.swc-stderr | 2 +- .../at-rule/page/without-page/span.swc-stderr | 2 +- .../supports/non-standard-prelude/output.json | 4 +- .../non-standard-prelude/span.swc-stderr | 8 +- .../recovery/cdo-and-cdc/span.swc-stderr | 2 +- .../declaration/important-1/span.swc-stderr | 2 +- .../declaration/important/span.swc-stderr | 32 +- .../declaration/wrong-name/span.swc-stderr | 2 +- .../delim-token/at-sign/span.swc-stderr | 2 +- .../tests/recovery/hacks/span.swc-stderr | 2 +- .../tests/recovery/ie-progid/output.json | 4 +- .../rules/unclosed-brackets/span.swc-stderr | 4 +- .../basic/span.swc-stderr | 4 +- crates/swc_css_visit/src/lib.rs | 7 +- 32 files changed, 873 insertions(+), 532 deletions(-) mode change 100644 => 100755 crates/swc_atoms/scripts/add-from-cargo-check.sh diff --git a/crates/swc_atoms/scripts/add-from-cargo-check.sh b/crates/swc_atoms/scripts/add-from-cargo-check.sh old mode 100644 new mode 100755 diff --git a/crates/swc_atoms/words.txt b/crates/swc_atoms/words.txt index 7d2c95e95dcb..60532c1f995a 100644 --- a/crates/swc_atoms/words.txt +++ b/crates/swc_atoms/words.txt @@ -1,8 +1,50 @@ * +-infinity +-moz-activehyperlinktext -moz-any +-moz-buttondefault +-moz-buttonhoverface +-moz-buttonhovertext -moz-calc +-moz-cellhighlight +-moz-cellhighlighttext +-moz-combobox +-moz-comboboxtext +-moz-default-background-color +-moz-default-color +-moz-dialog +-moz-dialogtext -moz-document +-moz-dragtargetzone +-moz-eventreerow +-moz-html-cellhighlight +-moz-html-cellhighlighttext +-moz-hyperlinktext -moz-keyframes +-moz-mac-accentdarkestshadow +-moz-mac-accentdarkshadow +-moz-mac-accentface +-moz-mac-accentlightesthighlight +-moz-mac-accentlightshadow +-moz-mac-accentregularhighlight +-moz-mac-accentregularshadow +-moz-mac-chrome-active +-moz-mac-chrome-inactive +-moz-mac-focusring +-moz-mac-menuselect +-moz-mac-menushadow +-moz-mac-menutextselect +-moz-menubarhovertext +-moz-menubartext +-moz-menuhover +-moz-menuhovertext +-moz-nativehyperlinktext +-moz-oddtreerow +-moz-visitedhyperlinktext +-moz-win-accentcolor +-moz-win-accentcolortext +-moz-win-communicationstext +-moz-win-mediatext -ms-keyframes -ms-viewport -o-keyframes @@ -591,16 +633,22 @@ _extends _toConsumableArray a abbr +abs abstract accent-color accept accesskey +acos acronym action +activeborder +activecaption +activetext actuate add address after +aliceblue align-content align-items align-self @@ -634,7 +682,9 @@ animation-timing-function annotation annotation-xml anonymous +antiquewhite any +appWorkspace appearance apple-touch-icon apple-touch-icon-precomposed @@ -646,6 +696,8 @@ application/ld+json application/x-javascript application/xhtml+xml apply +aqua +aquamarine arcrole area arguments @@ -655,10 +707,13 @@ aria-owns article as aside +asin aspect-ratio assert asserts async +atan +atan2 attributeName attributeType attributename @@ -668,8 +723,10 @@ auto autocomplete await azimuth +azure b backdrop-filter +background background-attachment background-blend-mode background-clip @@ -692,15 +749,21 @@ bdi bdo before begin +beige bgsound big bigint +bisque +black +blanchedalmond blink block block-overflow block-size blocking blockquote +blue +blueviolet body bold boolean @@ -766,24 +829,38 @@ break break-after break-before break-inside +brown +burlywood button +buttonborder +buttonface +buttonhighlight +buttonshadow +buttontext +cadetblue calc calcMode calcmode call canvas canvastext +cap caption caption-side +captiontext caret-color caret-shape case catch center +ch character-variant charset +chartreuse +chocolate circle cite +clamp class classid clear @@ -800,6 +877,7 @@ col colgroup collection color +color-contrast color-index color-mix color-profile @@ -816,6 +894,7 @@ column-width command concat const +constant constructor contain contain-intrinsic-block-size @@ -828,12 +907,23 @@ content-box content-security-policy contenteditable continue +coral +cornflowerblue +cornsilk +cos counter-increment counter-reset counter-set counter-style +cqb +cqh +cqi +cqmax +cqmin +cqw createClass createReactClass +crimson crossorigin cubic-bezier cue @@ -843,12 +933,34 @@ currentColor currentcolor cursor custom-media +cyan d +darkblue +darkcyan +darkgoldenrod +darkgray +darkgreen +darkgrey +darkkhaki +darkmagenta +darkolivegreen +darkorange +darkorchid +darkred +darksalmon +darkseagreen +darkslateblue +darkslategray +darkslategrey +darkturquoise +darkviolet data datalist dd debugger declare +deeppink +deepskyblue default definitionURL definitionurl @@ -866,6 +978,8 @@ dfn dialog diffuseConstant diffuseconstant +dimgray +dimgrey dir direction discard @@ -876,6 +990,7 @@ div dl do document +dodgerblue dpcm dpi dppx @@ -886,6 +1001,7 @@ dvi dvmax dvmin dvw +e ease ease-in ease-in-out @@ -906,6 +1022,7 @@ env eval even ex +exp export exportparts extends @@ -961,7 +1078,9 @@ fespecularlighting fespotlight fetile feturbulence +field fieldset +fieldtext figcaption figure file @@ -972,6 +1091,7 @@ filter filterUnits filterunits finally +firebrick first-child first-letter first-line @@ -984,6 +1104,7 @@ flex-grow flex-shrink flex-wrap float +floralwhite flow flow-root font @@ -1017,26 +1138,38 @@ for forced-color-adjust foreignObject foreignobject +forestgreen form formaction format +fr frame frameset from from-image +fuchsia function future g +gainsboro get +ghostwhite global glyph glyphRef glyphref +gold +goldenrod grad gradientTransform gradientUnits gradienttransform gradientunits +gray +graytext +green +greenyellow +grey grid grid-auto-columns grid-auto-flow @@ -1064,11 +1197,14 @@ headers height hgroup highlight +highlighttext historical-forms hkern +honeydew horizontal-tb host host-context +hotpink hr href hsl @@ -1078,6 +1214,7 @@ http-equiv hwb hyphenate-character hyphens +hypot hz i ic @@ -1098,7 +1235,15 @@ import important importmap in +inactiveborder +inactivecaption +inactivecaptiontext +indianred +indigo infer +infinity +infobackground +infotext inherit initial initial-letter @@ -1127,6 +1272,7 @@ itemprop itemref itemtype iterator +ivory jump-end jump-start justify-content @@ -1150,12 +1296,17 @@ keypoints keysplines keytimes keywords +khaki khz +lab label lang language last-child last-of-type +lavender +lavenderblush +lawngreen layer lch left @@ -1164,6 +1315,7 @@ left-middle left-top legacy legend +lemonchiffon length lengthAdjust lengthadjust @@ -1171,6 +1323,23 @@ let letter-spacing lh li +lightblue +lightcoral +lightcyan +lightgoldenrodyellow +lightgray +lightgreen +lightgrey +lightpink +lightsalmon +lightseagreen +lightskyblue +lightslategray +lightslategrey +lightsteelblue +lightyellow +lime +limegreen limitingConeAngle limitingconeangle line @@ -1181,12 +1350,15 @@ line-height-step linear linearGradient lineargradient +linen link +linktext list-item list-style-image list-style-type listing local +log longdesc lr lr-tb @@ -1198,6 +1370,7 @@ lvi lvmax lvmin lvw +magenta main malignmark manual @@ -1222,6 +1395,8 @@ markerWidth markerheight markerunits markerwidth +marktext +maroon marquee mask mask-border-mode @@ -1252,6 +1427,7 @@ math-shift math-style matrix matrix3d +max max-aspect-ratio max-block-size max-color @@ -1268,12 +1444,24 @@ max-width maxlength media medium +mediumaquamarine +mediumblue +mediumorchid +mediumpurple +mediumseagreen +mediumslateblue +mediumspringgreen +mediumturquoise +mediumvioletred menu +menutext meta metadata meter mglyph mi +midnightblue +min min-aspect-ratio min-block-size min-color @@ -1286,12 +1474,16 @@ min-inline-size min-monochrome min-resolution min-width +mintcream missing-glyph +mistyrose mix-blend-mode mixed mm mn mo +moccasin +mod module monochrome mozmm @@ -1300,7 +1492,10 @@ ms mtext name namespace +nan nav +navajowhite +navy nest never new @@ -1335,6 +1530,9 @@ offset-rotate oklab oklch ol +oldlace +olive +olivedrab onabort onafterprint onautocomplete @@ -1440,6 +1638,9 @@ opentype optgroup option or +orange +orangered +orchid order ornaments orphans @@ -1481,7 +1682,12 @@ page-break-after page-break-before page-break-inside paint-order +palegoldenrod +palegreen +paleturquoise +palevioletred panose-1 +papayawhip param part past @@ -1496,14 +1702,19 @@ patterncontentunits patterntransform patternunits pc +peachpuff perspective +peru +pi picture ping +pink place-content place-items place-self placeholder plaintext +plum pointer-events points pointsAtX @@ -1516,6 +1727,8 @@ polygon polyline position poster +pow +powderblue pre preload preserveAlpha @@ -1532,6 +1745,7 @@ property protected pt public +purple px q rad @@ -1542,7 +1756,9 @@ rbc rcap rch readonly +rebeccapurple rect +red refX refY refx @@ -1577,6 +1793,7 @@ right-top rl rlh role +rosybrown rotate rotate3d rotateX @@ -1590,6 +1807,7 @@ row row-gap rows rowspan +royalblue rp rt rtc @@ -1602,8 +1820,11 @@ ruby-position ruby-text run-in s +saddlebrown +salmon samp sandbox +sandybrown satisfies scale scale3d @@ -1645,11 +1866,17 @@ scroll-snap-type-x scroll-snap-type-y scroll-timeline-axis scroll-timeline-name +scrollbar scrollbar-color scrollbar-gutter scrollbar-width +seagreen +seashell section select +selecteditem +selecteditemtext +selector separate set shadow @@ -1659,6 +1886,10 @@ shape-outside show sideways-lr sideways-rl +sienna +sign +silver +sin size sizes skew @@ -1666,10 +1897,15 @@ skewX skewY skewx skewy +skyblue +slateblue +slategray +slategrey slice slot slotted small +snow solid solidColor source @@ -1684,6 +1920,8 @@ specularexponent speculationrules spreadMethod spreadmethod +springgreen +sqrt src srcdoc srcset @@ -1693,6 +1931,7 @@ startoffset static stdDeviation stddeviation +steelblue step-end step-start steps @@ -1715,6 +1954,7 @@ super supports surfaceScale surfacescale +svb svg svh svi @@ -1734,6 +1974,7 @@ table-cell table-layout tableValues tablevalues +tan target targetX targetY @@ -1744,6 +1985,7 @@ tb-lr tb-rl tbody td +teal template text text-align-last @@ -1779,11 +2021,18 @@ tfoot th thead this +thistle +threeddarkshadow +threedface +threedhighlight +threedlightshadow +threedshadow throw time title to toString +tomato top top-center top-left @@ -1814,6 +2063,7 @@ try tspan tt turn +turquoise type typeof u @@ -1844,6 +2094,8 @@ viewTarget viewbox viewport viewtarget +violet +visitedtext vkern vmax vmin @@ -1851,12 +2103,18 @@ void vw wbr weight +wheat where while +white white-space +whitesmoke widows width will-change +window +windowframe +windowtext with woff woff2 @@ -1881,8 +2139,13 @@ xml:space xmlns xmlns:xlink xmp +xyz +xyz-d50 +xyz-d65 yChannelSelector ychannelselector +yellow +yellowgreen yield z-index zoom diff --git a/crates/swc_css_ast/src/base.rs b/crates/swc_css_ast/src/base.rs index 215e51b37201..1a1e5aec85af 100644 --- a/crates/swc_css_ast/src/base.rs +++ b/crates/swc_css_ast/src/base.rs @@ -100,12 +100,21 @@ impl Take for SimpleBlock { } } +#[ast_node] +#[derive(Eq, Hash, Is, EqIgnoreSpan)] +pub enum FunctionName { + #[tag("Ident")] + Ident(Ident), + #[tag("DashedIdent")] + DashedIdent(DashedIdent), +} + #[ast_node("Function")] #[derive(Eq, Hash, EqIgnoreSpan)] pub struct Function { /// Span starting from the `lo` of identifier and to the end of `)`. pub span: Span, - pub name: Ident, + pub name: FunctionName, pub value: Vec, } diff --git a/crates/swc_css_parser/src/parser/input.rs b/crates/swc_css_parser/src/parser/input.rs index adced3631088..6aa0455f0581 100644 --- a/crates/swc_css_parser/src/parser/input.rs +++ b/crates/swc_css_parser/src/parser/input.rs @@ -1,8 +1,8 @@ use std::{borrow::Cow, fmt::Debug, mem::take}; -use swc_atoms::{Atom, JsWord}; +use swc_atoms::Atom; use swc_common::{BytePos, Span, Spanned, SyntaxContext}; -use swc_css_ast::{ComponentValue, ListOfComponentValues, Token, TokenAndSpan}; +use swc_css_ast::{ComponentValue, FunctionName, ListOfComponentValues, Token, TokenAndSpan}; use super::PResult; use crate::error::{Error, ErrorKind}; @@ -224,7 +224,7 @@ type SpanLike = (BytePos, BytePos); #[derive(Debug)] enum TokenOrBlock<'a> { Token(&'a TokenAndSpan), - Function(Box<(Span, JsWord, Atom)>), + Function(Box<(Span, FunctionName)>), LBracket(SpanLike), LParen(SpanLike), LBrace(SpanLike), @@ -279,11 +279,7 @@ impl<'a> Input<'a> { function.name.span_hi() + BytePos(1), Default::default(), ), - function.name.value.clone(), - match &function.name.raw { - Some(raw) => raw.clone(), - _ => Atom::from(function.name.value.clone()), - }, + function.name.clone(), )))); } @@ -381,13 +377,26 @@ impl<'a> Input<'a> { TokenOrBlock::Token(token_and_span) => { return Ok(Cow::Borrowed(token_and_span)) } - TokenOrBlock::Function(function) => TokenAndSpan { - span: function.0, - token: Token::Function { - value: function.1, - raw: function.2, - }, - }, + TokenOrBlock::Function(function) => { + let name = match function.1 { + FunctionName::Ident(name) => match name.raw { + Some(raw) => (name.value, raw), + _ => (name.value.clone(), Atom::from(name.value)), + }, + FunctionName::DashedIdent(name) => match name.raw { + Some(raw) => (name.value, raw), + _ => (name.value.clone(), Atom::from(name.value)), + }, + }; + + TokenAndSpan { + span: function.0, + token: Token::Function { + value: name.0, + raw: name.1, + }, + } + } TokenOrBlock::LBracket(span) => TokenAndSpan { span: Span::new(span.0, span.1, Default::default()), token: Token::LBracket, diff --git a/crates/swc_css_parser/src/parser/syntax/mod.rs b/crates/swc_css_parser/src/parser/syntax/mod.rs index 9efae7729416..b1110a279d80 100644 --- a/crates/swc_css_parser/src/parser/syntax/mod.rs +++ b/crates/swc_css_parser/src/parser/syntax/mod.rs @@ -148,7 +148,8 @@ where unreachable!() } }; - let name = if at_keyword_name.0.starts_with("--") { + let is_dashed_ident = at_keyword_name.0.starts_with("--"); + let name = if is_dashed_ident { AtRuleName::DashedIdent(DashedIdent { span: Span::new(span.lo + BytePos(1), span.hi, Default::default()), value: at_keyword_name.0, @@ -195,7 +196,7 @@ where at_rule.span = span!(self, span.lo); // Canonicalization against a grammar - if self.ctx.need_canonicalize { + if !is_dashed_ident && self.ctx.need_canonicalize { at_rule = self.canonicalize_at_rule_prelude(at_rule)?; } @@ -213,7 +214,7 @@ where at_rule.span = span!(self, span.lo); // Canonicalization against a grammar - if self.ctx.need_canonicalize { + if !is_dashed_ident && self.ctx.need_canonicalize { at_rule = self.canonicalize_at_rule_prelude(at_rule)?; at_rule = self.canonicalize_at_rule_block(at_rule)?; } @@ -604,16 +605,21 @@ where // // Return nothing. let span = self.input.cur_span(); - let is_dashed_ident = match cur!(self) { - Token::Ident { value, .. } => value.starts_with("--"), + let declaration_name = match cur!(self) { + Token::Ident { value, .. } => value, _ => { return Err(Error::new(span, ErrorKind::Expected("ident"))); } }; + let is_dashed_ident = declaration_name.starts_with("--"); let name = if is_dashed_ident { - DeclarationName::DashedIdent(self.parse()?) + let ident = self.parse()?; + + DeclarationName::DashedIdent(ident) } else { - DeclarationName::Ident(self.parse()?) + let ident = self.parse()?; + + DeclarationName::Ident(ident) }; let mut declaration = Declaration { span: Default::default(), @@ -918,16 +924,25 @@ where // Create a function with its name equal to the value of the current input token // and with its value initially set to an empty list. let span = self.input.cur_span(); - let ident = match bump!(self) { + let function_name = match bump!(self) { Token::Function { value, raw } => (value, raw), _ => { unreachable!() } }; - let name = Ident { - span: Span::new(span.lo, span.hi - BytePos(1), Default::default()), - value: ident.0, - raw: Some(ident.1), + let is_dashed_ident = function_name.0.starts_with("--"); + let name = if is_dashed_ident { + FunctionName::DashedIdent(DashedIdent { + span: Span::new(span.lo, span.hi - BytePos(1), Default::default()), + value: function_name.0, + raw: Some(function_name.1), + }) + } else { + FunctionName::Ident(Ident { + span: Span::new(span.lo, span.hi - BytePos(1), Default::default()), + value: function_name.0.to_ascii_lowercase(), + raw: Some(function_name.1), + }) }; let mut function = Function { span: Default::default(), @@ -970,7 +985,7 @@ where function.span = span!(self, span.lo); // Canonicalization against a grammar - if self.ctx.need_canonicalize { + if !is_dashed_ident && self.ctx.need_canonicalize { function = self.canonicalize_function_value(function)?; } diff --git a/crates/swc_css_parser/src/parser/util.rs b/crates/swc_css_parser/src/parser/util.rs index 59aa82996c11..5c172ddf52eb 100644 --- a/crates/swc_css_parser/src/parser/util.rs +++ b/crates/swc_css_parser/src/parser/util.rs @@ -267,11 +267,10 @@ where &mut self, mut function: Function, ) -> PResult { - let function_name = function.name.value.to_ascii_lowercase(); let locv = self.create_locv(function.value); function.value = match self.parse_according_to_grammar(&locv, |parser| { - parser.parse_function_values(&function_name) + parser.parse_function_values(&function.name) }) { Ok(values) => values, Err(err) => { 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 78c66420b2c6..bfc9ee6a8d8a 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 @@ -48,12 +48,23 @@ where return Ok(ComponentValue::Url(self.parse()?)); } - Token::Function { value, .. } => match &*value.to_ascii_lowercase() { - "url" | "src" => { + Token::Function { value, .. } => match value.to_ascii_lowercase() { + js_word!("url") | js_word!("src") => { return Ok(ComponentValue::Url(self.parse()?)); } - "rgb" | "rgba" | "hsl" | "hsla" | "hwb" | "lab" | "lch" | "oklab" | "oklch" - | "color" | "device-cmyk" | "color-mix" | "color-contrast" => { + js_word!("rgb") + | js_word!("rgba") + | js_word!("hsl") + | js_word!("hsla") + | js_word!("hwb") + | js_word!("lab") + | js_word!("lch") + | js_word!("oklab") + | js_word!("oklch") + | js_word!("color") + | js_word!("device-cmyk") + | js_word!("color-mix") + | js_word!("color-contrast") => { return Ok(ComponentValue::Color(self.parse()?)); } _ => { @@ -184,12 +195,33 @@ where } // TODO use `JsWord` - pub fn parse_function_values(&mut self, function_name: &str) -> PResult> { + pub fn parse_function_values( + &mut self, + function_name: &FunctionName, + ) -> PResult> { + let function_name = match function_name { + FunctionName::Ident(name) => &name.value, + FunctionName::DashedIdent(_) => { + return Err(Error::new(Default::default(), ErrorKind::Ignore)) + } + }; + let mut values = vec![]; - match function_name { - "calc" | "-moz-calc" | "-webkit-calc" | "sin" | "cos" | "tan" | "asin" | "acos" - | "atan" | "sqrt" | "exp" | "abs" | "sign" => { + match *function_name { + js_word!("calc") + | js_word!("-moz-calc") + | js_word!("-webkit-calc") + | js_word!("sin") + | js_word!("cos") + | js_word!("tan") + | js_word!("asin") + | js_word!("acos") + | js_word!("atan") + | js_word!("sqrt") + | js_word!("exp") + | js_word!("abs") + | js_word!("sign") => { self.input.skip_ws(); let calc_sum = ComponentValue::CalcSum(self.parse()?); @@ -204,7 +236,7 @@ where return Err(Error::new(span, ErrorKind::Unexpected("value"))); } } - "min" | "max" | "hypot" => { + js_word!("min") | js_word!("max") | js_word!("hypot") => { self.input.skip_ws(); let calc_sum = ComponentValue::CalcSum(self.parse()?); @@ -233,7 +265,7 @@ where return Err(Error::new(span, ErrorKind::Unexpected("value"))); } } - "clamp" => { + js_word!("clamp") => { self.input.skip_ws(); let calc_sum = ComponentValue::CalcSum(self.parse()?); @@ -274,7 +306,7 @@ where self.input.skip_ws(); } - "round" => { + js_word!("round") => { self.input.skip_ws(); if is!(self, "ident") { @@ -318,7 +350,7 @@ where self.input.skip_ws(); } - "mod" | "rem" | "atan2" | "pow" => { + js_word!("mod") | js_word!("rem") | js_word!("atan2") | js_word!("pow") => { self.input.skip_ws(); let calc_sum = ComponentValue::CalcSum(self.parse()?); @@ -343,7 +375,7 @@ where self.input.skip_ws(); } - "log" => { + js_word!("log") => { self.input.skip_ws(); let calc_sum = ComponentValue::CalcSum(self.parse()?); @@ -364,7 +396,7 @@ where self.input.skip_ws(); } } - "rgb" | "rgba" | "hsl" | "hsla" => { + js_word!("rgb") | js_word!("rgba") | js_word!("hsl") | js_word!("hsla") => { self.input.skip_ws(); let mut has_variable = false; @@ -394,8 +426,8 @@ where _ => {} } - match function_name { - "rgb" | "rgba" => { + match *function_name { + js_word!("rgb") | js_word!("rgba") => { let percentage_or_number_or_none = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("percentage") => { @@ -442,7 +474,7 @@ where self.input.skip_ws(); } - "hsl" | "hsla" => { + js_word!("hsl") | js_word!("hsla") => { let hue_or_none = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("number") | tok!("dimension") => { @@ -507,8 +539,8 @@ where is_legacy_syntax = false; } - match function_name { - "rgb" | "rgba" => { + match *function_name { + js_word!("rgb") | js_word!("rgba") => { let percentage_or_number = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("percentage") => { @@ -553,7 +585,7 @@ where self.input.skip_ws(); } - "hsl" | "hsla" => { + js_word!("hsl") | js_word!("hsla") => { let percentage_or_none = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("percentage") => { @@ -623,8 +655,8 @@ where } } - match function_name { - "rgb" | "rgba" => { + match *function_name { + js_word!("rgb") | js_word!("rgba") => { let percentage_or_number = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("percentage") => { @@ -669,7 +701,7 @@ where self.input.skip_ws(); } - "hsl" | "hsla" => { + js_word!("hsl") | js_word!("hsla") => { let percentage_or_none = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("percentage") => { @@ -801,7 +833,12 @@ where self.input.skip_ws(); } } - "hwb" | "lab" | "lch" | "oklab" | "oklch" | "device-cmyk" => { + js_word!("hwb") + | js_word!("lab") + | js_word!("lch") + | js_word!("oklab") + | js_word!("oklch") + | js_word!("device-cmyk") => { self.input.skip_ws(); let mut has_variable = false; @@ -809,7 +846,7 @@ where match cur!(self) { Token::Ident { value, .. } if matches_eq_ignore_ascii_case!(value, js_word!("from")) - && function_name != "device-cmyk" => + && *function_name != js_word!("device-cmyk") => { values.push(ComponentValue::Ident(self.parse()?)); @@ -829,8 +866,8 @@ where _ => {} } - match function_name { - "hwb" => { + match *function_name { + js_word!("hwb") => { let hue_or_none = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("number") | tok!("dimension") => { @@ -874,7 +911,7 @@ where self.input.skip_ws(); } - "lab" | "lch" | "oklab" | "oklch" => { + js_word!("lab") | js_word!("lch") | js_word!("oklab") | js_word!("oklch") => { let percentage_or_none = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("percentage") => { @@ -919,7 +956,7 @@ where self.input.skip_ws(); } - "device-cmyk" => { + js_word!("device-cmyk") => { let cmyk_component = self.try_parse_variable_function( |parser, _| Ok(Some(ComponentValue::CmykComponent(parser.parse()?))), &mut has_variable, @@ -937,8 +974,8 @@ where } if !is_one_of!(self, EOF, "/") { - match function_name { - "hwb" => { + match *function_name { + js_word!("hwb") => { let percentage_or_none = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("percentage") => { @@ -984,7 +1021,10 @@ where self.input.skip_ws(); } - "lab" | "lch" | "oklab" | "oklch" => { + js_word!("lab") + | js_word!("lch") + | js_word!("oklab") + | js_word!("oklch") => { let number_or_none = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("percentage") => { @@ -1033,7 +1073,7 @@ where self.input.skip_ws(); } - "device-cmyk" => { + js_word!("device-cmyk") => { let cmyk_component = self.try_parse_variable_function( |parser, _| { Ok(Some(ComponentValue::CmykComponent(parser.parse()?))) @@ -1054,8 +1094,8 @@ where } if !is_one_of!(self, EOF, "/") { - match function_name { - "hwb" => { + match *function_name { + js_word!("hwb") => { let percentage_or_none = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("percentage") => { @@ -1101,7 +1141,7 @@ where self.input.skip_ws(); } - "lab" | "oklab" => { + js_word!("lab") | js_word!("oklab") => { let number_or_none = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("percentage") => { @@ -1150,7 +1190,7 @@ where self.input.skip_ws(); } - "lch" | "oklch" => { + js_word!("lch") | js_word!("oklch") => { let hue_or_none = self.try_parse_variable_function( |parser, has_variable_before| match cur!(parser) { tok!("number") | tok!("dimension") => { @@ -1196,7 +1236,7 @@ where self.input.skip_ws(); } - "device-cmyk" => { + js_word!("device-cmyk") => { let cmyk_component = self.try_parse_variable_function( |parser, _| { Ok(Some(ComponentValue::CmykComponent(parser.parse()?))) @@ -1242,7 +1282,7 @@ where Token::Function { value, .. } if is_math_function(value) => { Ok(Some(ComponentValue::Function(parser.parse()?))) } - tok!("ident") if !matches!(function_name, "device-cmyk") => { + tok!("ident") if !matches!(*function_name, js_word!("device-cmyk")) => { let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { @@ -1278,7 +1318,7 @@ where self.input.skip_ws(); } } - "color" => { + js_word!("color") => { self.input.skip_ws(); let mut has_variable = false; @@ -1317,7 +1357,10 @@ where Ok(Some(ComponentValue::DashedIdent(parser.parse()?))) } else { if matches_eq_ignore_ascii_case!( - &**value, "xyz", "xyz-d50", "xyz-d65" + value, + js_word!("xyz"), + js_word!("xyz-d50"), + js_word!("xyz-d65") ) { is_xyz = true } else { @@ -1403,7 +1446,10 @@ where Token::Function { value, .. } if is_math_function(value) || matches_eq_ignore_ascii_case!( - &**value, "var", "env", "constant" + value, + js_word!("var"), + js_word!("env"), + js_word!("constant") ) => { ComponentValue::Function(self.parse()?) @@ -1532,7 +1578,7 @@ where Token::Function { value, .. } if is_math_function(value) => { Ok(Some(ComponentValue::Function(parser.parse()?))) } - tok!("ident") if !matches!(function_name, "device-cmyk") => { + tok!("ident") if !matches!(*function_name, js_word!("device-cmyk")) => { let ident: Box = parser.parse()?; if ident.value.eq_str_ignore_ascii_case("none") { @@ -1570,7 +1616,7 @@ where self.input.skip_ws(); } - "selector" if self.ctx.in_supports_at_rule => { + js_word!("selector") if self.ctx.in_supports_at_rule => { self.input.skip_ws(); let selector = ComponentValue::ComplexSelector(self.parse()?); @@ -1579,7 +1625,7 @@ where self.input.skip_ws(); } - "layer" if self.ctx.in_import_at_rule => { + js_word!("layer") if self.ctx.in_import_at_rule => { self.input.skip_ws(); if is!(self, EOF) { @@ -1612,7 +1658,7 @@ where )); } } - "supports" if self.ctx.in_import_at_rule => { + js_word!("supports") if self.ctx.in_import_at_rule => { self.input.skip_ws(); if !is!(self, EOF) { @@ -1678,7 +1724,12 @@ where match cur!(self) { Token::Function { value, .. } - if matches_eq_ignore_ascii_case!(&**value, "var", "env", "constant") => + if matches_eq_ignore_ascii_case!( + value, + js_word!("var"), + js_word!("env"), + js_word!("constant") + ) => { *has_before_variable = true; @@ -1812,7 +1863,12 @@ where match bump!(self) { Token::Ident { value, raw, .. } => { if matches_eq_ignore_ascii_case!( - &*value, "initial", "inherit", "unset", "revert", "default" + value, + js_word!("initial"), + js_word!("inherit"), + js_word!("unset"), + js_word!("revert"), + js_word!("default") ) { return Err(Error::new(span, ErrorKind::InvalidCustomIdent(value))); } @@ -3205,8 +3261,12 @@ where tok!("dimension") => Ok(CalcValue::Dimension(self.parse()?)), tok!("percentage") => Ok(CalcValue::Percentage(self.parse()?)), Token::Ident { value, .. } => { - match &*value.to_ascii_lowercase() { - "e" | "pi" | "infinity" | "-infinity" | "nan" => {} + match value.to_ascii_lowercase() { + js_word!("e") + | js_word!("pi") + | js_word!("infinity") + | js_word!("-infinity") + | js_word!("nan") => {} _ => { let span = self.input.cur_span(); @@ -3293,337 +3353,388 @@ where } pub(crate) fn is_math_function(name: &str) -> bool { - matches!( - &*name.to_ascii_lowercase(), - "calc" - | "-moz-calc" - | "-webkit-calc" - | "sin" - | "cos" - | "tan" - | "asin" - | "acos" - | "atan" - | "sqrt" - | "exp" - | "abs" - | "sign" - | "min" - | "max" - | "hypot" - | "clamp" - | "round" - | "mod" - | "rem" - | "atan2" - | "pow" - | "log" + matches_eq_ignore_ascii_case!( + name, + js_word!("calc"), + js_word!("-moz-calc"), + js_word!("-webkit-calc"), + js_word!("sin"), + js_word!("cos"), + js_word!("tan"), + js_word!("asin"), + js_word!("acos"), + js_word!("atan"), + js_word!("sqrt"), + js_word!("exp"), + js_word!("abs"), + js_word!("sign"), + js_word!("min"), + js_word!("max"), + js_word!("hypot"), + js_word!("clamp"), + js_word!("round"), + js_word!("mod"), + js_word!("rem"), + js_word!("atan2"), + js_word!("pow"), + js_word!("log") ) } fn is_absolute_color_base_function(name: &str) -> bool { - matches!( - &*name.to_ascii_lowercase(), - "rgb" - | "rgba" - | "hsl" - | "hsla" - | "hwb" - | "lab" - | "lch" - | "oklab" - | "oklch" - | "color" - | "color-mix" - | "color-contrast" + matches_eq_ignore_ascii_case!( + name, + js_word!("rgb"), + js_word!("rgba"), + js_word!("hsl"), + js_word!("hsla"), + js_word!("hwb"), + js_word!("lab"), + js_word!("lch"), + js_word!("oklab"), + js_word!("oklch"), + js_word!("color"), + js_word!("color-mix"), + js_word!("color-contrast") ) } fn is_system_color(name: &str) -> bool { - matches!( - &*name.to_ascii_lowercase(), - "canvas" - | "canvastext" - | "linktext" - | "visitedtext" - | "activetext" - | "buttonface" - | "buttontext" - | "buttonborder" - | "field" - | "fieldtext" - | "highlight" - | "highlighttext" - | "selecteditem" - | "selecteditemtext" - | "mark" - | "marktext" - | "graytext" - // Deprecated - | "activeborder" - | "activecaption" - | "appWorkspace" - | "background" - | "buttonhighlight" - | "buttonshadow" - | "captiontext" - | "inactiveborder" - | "inactivecaption" - | "inactivecaptiontext" - | "infobackground" - | "infotext" - | "menu" - | "menutext" - | "scrollbar" - | "threeddarkshadow" - | "threedface" - | "threedhighlight" - | "threedlightshadow" - | "threedshadow" - | "window" - | "windowframe" - | "windowtext" - // Mozilla System Color Extensions - | "-moz-buttondefault" - | "-moz-buttonhoverface" - | "-moz-buttonhovertext" - | "-moz-cellhighlight" - | "-moz-cellhighlighttext" - | "-moz-combobox" - | "-moz-comboboxtext" - | "-moz-dialog" - | "-moz-dialogtext" - | "-moz-dragtargetzone" - | "-moz-eventreerow" - | "-moz-html-cellhighlight" - | "-moz-html-cellhighlighttext" - | "-moz-mac-accentdarkestshadow" - | "-moz-mac-accentdarkshadow" - | "-moz-mac-accentface" - | "-moz-mac-accentlightesthighlight" - | "-moz-mac-accentlightshadow" - | "-moz-mac-accentregularhighlight" - | "-moz-mac-accentregularshadow" - | "-moz-mac-chrome-active" - | "-moz-mac-chrome-inactive" - | "-moz-mac-focusring" - | "-moz-mac-menuselect" - | "-moz-mac-menushadow" - | "-moz-mac-menutextselect" - | "-moz-menuhover" - | "-moz-menuhovertext" - | "-moz-menubartext" - | "-moz-menubarhovertext" - | "-moz-nativehyperlinktext" - | "-moz-oddtreerow" - | "-moz-win-communicationstext" - | "-moz-win-mediatext" - | "-moz-win-accentcolor" - | "-moz-win-accentcolortext" - // Mozilla Color Preference Extensions - | "-moz-activehyperlinktext" - | "-moz-default-background-color" - | "-moz-default-color" - | "-moz-hyperlinktext" - | "-moz-visitedhyperlinktext" + matches_eq_ignore_ascii_case!( + name, + js_word!("canvas"), + js_word!("canvastext"), + js_word!("linktext"), + js_word!("visitedtext"), + js_word!("activetext"), + js_word!("buttonface"), + js_word!("buttontext"), + js_word!("buttonborder"), + js_word!("field"), + js_word!("fieldtext"), + js_word!("highlight"), + js_word!("highlighttext"), + js_word!("selecteditem"), + js_word!("selecteditemtext"), + js_word!("mark"), + js_word!("marktext"), + js_word!("graytext"), + // Deprecated + js_word!("activeborder"), + js_word!("activecaption"), + js_word!("appWorkspace"), + js_word!("background"), + js_word!("buttonhighlight"), + js_word!("buttonshadow"), + js_word!("captiontext"), + js_word!("inactiveborder"), + js_word!("inactivecaption"), + js_word!("inactivecaptiontext"), + js_word!("infobackground"), + js_word!("infotext"), + js_word!("menu"), + js_word!("menutext"), + js_word!("scrollbar"), + js_word!("threeddarkshadow"), + js_word!("threedface"), + js_word!("threedhighlight"), + js_word!("threedlightshadow"), + js_word!("threedshadow"), + js_word!("window"), + js_word!("windowframe"), + js_word!("windowtext"), + // Mozilla System Color Extensions + js_word!("-moz-buttondefault"), + js_word!("-moz-buttonhoverface"), + js_word!("-moz-buttonhovertext"), + js_word!("-moz-cellhighlight"), + js_word!("-moz-cellhighlighttext"), + js_word!("-moz-combobox"), + js_word!("-moz-comboboxtext"), + js_word!("-moz-dialog"), + js_word!("-moz-dialogtext"), + js_word!("-moz-dragtargetzone"), + js_word!("-moz-eventreerow"), + js_word!("-moz-html-cellhighlight"), + js_word!("-moz-html-cellhighlighttext"), + js_word!("-moz-mac-accentdarkestshadow"), + js_word!("-moz-mac-accentdarkshadow"), + js_word!("-moz-mac-accentface"), + js_word!("-moz-mac-accentlightesthighlight"), + js_word!("-moz-mac-accentlightshadow"), + js_word!("-moz-mac-accentregularhighlight"), + js_word!("-moz-mac-accentregularshadow"), + js_word!("-moz-mac-chrome-active"), + js_word!("-moz-mac-chrome-inactive"), + js_word!("-moz-mac-focusring"), + js_word!("-moz-mac-menuselect"), + js_word!("-moz-mac-menushadow"), + js_word!("-moz-mac-menutextselect"), + js_word!("-moz-menuhover"), + js_word!("-moz-menuhovertext"), + js_word!("-moz-menubartext"), + js_word!("-moz-menubarhovertext"), + js_word!("-moz-nativehyperlinktext"), + js_word!("-moz-oddtreerow"), + js_word!("-moz-win-communicationstext"), + js_word!("-moz-win-mediatext"), + js_word!("-moz-win-accentcolor"), + js_word!("-moz-win-accentcolortext"), + // Mozilla Color Preference Extensions + js_word!("-moz-activehyperlinktext"), + js_word!("-moz-default-background-color"), + js_word!("-moz-default-color"), + js_word!("-moz-hyperlinktext"), + js_word!("-moz-visitedhyperlinktext") ) } fn is_named_color(name: &str) -> bool { - matches!( - &*name.to_ascii_lowercase(), - "aliceblue" - | "antiquewhite" - | "aqua" - | "aquamarine" - | "azure" - | "beige" - | "bisque" - | "black" - | "blanchedalmond" - | "blue" - | "blueviolet" - | "brown" - | "burlywood" - | "cadetblue" - | "chartreuse" - | "chocolate" - | "coral" - | "cornflowerblue" - | "cornsilk" - | "crimson" - | "cyan" - | "darkblue" - | "darkcyan" - | "darkgoldenrod" - | "darkgray" - | "darkgreen" - | "darkgrey" - | "darkkhaki" - | "darkmagenta" - | "darkolivegreen" - | "darkorange" - | "darkorchid" - | "darkred" - | "darksalmon" - | "darkseagreen" - | "darkslateblue" - | "darkslategray" - | "darkslategrey" - | "darkturquoise" - | "darkviolet" - | "deeppink" - | "deepskyblue" - | "dimgray" - | "dimgrey" - | "dodgerblue" - | "firebrick" - | "floralwhite" - | "forestgreen" - | "fuchsia" - | "gainsboro" - | "ghostwhite" - | "gold" - | "goldenrod" - | "gray" - | "green" - | "greenyellow" - | "grey" - | "honeydew" - | "hotpink" - | "indianred" - | "indigo" - | "ivory" - | "khaki" - | "lavender" - | "lavenderblush" - | "lawngreen" - | "lemonchiffon" - | "lightblue" - | "lightcoral" - | "lightcyan" - | "lightgoldenrodyellow" - | "lightgray" - | "lightgreen" - | "lightgrey" - | "lightpink" - | "lightsalmon" - | "lightseagreen" - | "lightskyblue" - | "lightslategray" - | "lightslategrey" - | "lightsteelblue" - | "lightyellow" - | "lime" - | "limegreen" - | "linen" - | "magenta" - | "maroon" - | "mediumaquamarine" - | "mediumblue" - | "mediumorchid" - | "mediumpurple" - | "mediumseagreen" - | "mediumslateblue" - | "mediumspringgreen" - | "mediumturquoise" - | "mediumvioletred" - | "midnightblue" - | "mintcream" - | "mistyrose" - | "moccasin" - | "navajowhite" - | "navy" - | "oldlace" - | "olive" - | "olivedrab" - | "orange" - | "orangered" - | "orchid" - | "palegoldenrod" - | "palegreen" - | "paleturquoise" - | "palevioletred" - | "papayawhip" - | "peachpuff" - | "peru" - | "pink" - | "plum" - | "powderblue" - | "purple" - | "rebeccapurple" - | "red" - | "rosybrown" - | "royalblue" - | "saddlebrown" - | "salmon" - | "sandybrown" - | "seagreen" - | "seashell" - | "sienna" - | "silver" - | "skyblue" - | "slateblue" - | "slategray" - | "slategrey" - | "snow" - | "springgreen" - | "steelblue" - | "tan" - | "teal" - | "thistle" - | "tomato" - | "turquoise" - | "violet" - | "wheat" - | "white" - | "whitesmoke" - | "yellow" - | "yellowgreen" + matches_eq_ignore_ascii_case!( + name, + js_word!("aliceblue"), + js_word!("antiquewhite"), + js_word!("aqua"), + js_word!("aquamarine"), + js_word!("azure"), + js_word!("beige"), + js_word!("bisque"), + js_word!("black"), + js_word!("blanchedalmond"), + js_word!("blue"), + js_word!("blueviolet"), + js_word!("brown"), + js_word!("burlywood"), + js_word!("cadetblue"), + js_word!("chartreuse"), + js_word!("chocolate"), + js_word!("coral"), + js_word!("cornflowerblue"), + js_word!("cornsilk"), + js_word!("crimson"), + js_word!("cyan"), + js_word!("darkblue"), + js_word!("darkcyan"), + js_word!("darkgoldenrod"), + js_word!("darkgray"), + js_word!("darkgreen"), + js_word!("darkgrey"), + js_word!("darkkhaki"), + js_word!("darkmagenta"), + js_word!("darkolivegreen"), + js_word!("darkorange"), + js_word!("darkorchid"), + js_word!("darkred"), + js_word!("darksalmon"), + js_word!("darkseagreen"), + js_word!("darkslateblue"), + js_word!("darkslategray"), + js_word!("darkslategrey"), + js_word!("darkturquoise"), + js_word!("darkviolet"), + js_word!("deeppink"), + js_word!("deepskyblue"), + js_word!("dimgray"), + js_word!("dimgrey"), + js_word!("dodgerblue"), + js_word!("firebrick"), + js_word!("floralwhite"), + js_word!("forestgreen"), + js_word!("fuchsia"), + js_word!("gainsboro"), + js_word!("ghostwhite"), + js_word!("gold"), + js_word!("goldenrod"), + js_word!("gray"), + js_word!("green"), + js_word!("greenyellow"), + js_word!("grey"), + js_word!("honeydew"), + js_word!("hotpink"), + js_word!("indianred"), + js_word!("indigo"), + js_word!("ivory"), + js_word!("khaki"), + js_word!("lavender"), + js_word!("lavenderblush"), + js_word!("lawngreen"), + js_word!("lemonchiffon"), + js_word!("lightblue"), + js_word!("lightcoral"), + js_word!("lightcyan"), + js_word!("lightgoldenrodyellow"), + js_word!("lightgray"), + js_word!("lightgreen"), + js_word!("lightgrey"), + js_word!("lightpink"), + js_word!("lightsalmon"), + js_word!("lightseagreen"), + js_word!("lightskyblue"), + js_word!("lightslategray"), + js_word!("lightslategrey"), + js_word!("lightsteelblue"), + js_word!("lightyellow"), + js_word!("lime"), + js_word!("limegreen"), + js_word!("linen"), + js_word!("magenta"), + js_word!("maroon"), + js_word!("mediumaquamarine"), + js_word!("mediumblue"), + js_word!("mediumorchid"), + js_word!("mediumpurple"), + js_word!("mediumseagreen"), + js_word!("mediumslateblue"), + js_word!("mediumspringgreen"), + js_word!("mediumturquoise"), + js_word!("mediumvioletred"), + js_word!("midnightblue"), + js_word!("mintcream"), + js_word!("mistyrose"), + js_word!("moccasin"), + js_word!("navajowhite"), + js_word!("navy"), + js_word!("oldlace"), + js_word!("olive"), + js_word!("olivedrab"), + js_word!("orange"), + js_word!("orangered"), + js_word!("orchid"), + js_word!("palegoldenrod"), + js_word!("palegreen"), + js_word!("paleturquoise"), + js_word!("palevioletred"), + js_word!("papayawhip"), + js_word!("peachpuff"), + js_word!("peru"), + js_word!("pink"), + js_word!("plum"), + js_word!("powderblue"), + js_word!("purple"), + js_word!("rebeccapurple"), + js_word!("red"), + js_word!("rosybrown"), + js_word!("royalblue"), + js_word!("saddlebrown"), + js_word!("salmon"), + js_word!("sandybrown"), + js_word!("seagreen"), + js_word!("seashell"), + js_word!("sienna"), + js_word!("silver"), + js_word!("skyblue"), + js_word!("slateblue"), + js_word!("slategray"), + js_word!("slategrey"), + js_word!("snow"), + js_word!("springgreen"), + js_word!("steelblue"), + js_word!("tan"), + js_word!("teal"), + js_word!("thistle"), + js_word!("tomato"), + js_word!("turquoise"), + js_word!("violet"), + js_word!("wheat"), + js_word!("white"), + js_word!("whitesmoke"), + js_word!("yellow"), + js_word!("yellowgreen") ) } fn is_length_unit(unit: &str) -> bool { - matches!( - &*unit.to_ascii_lowercase(), - "em" | "rem" | - "ex" | "rex" | - "cap" | "rcap" | - "ch" | "rch" | - "ic" | "ric" | - "lh" | "rlh" | + matches_eq_ignore_ascii_case!( + unit, + js_word!("em"), + js_word!("rem"), + js_word!("ex"), + js_word!("rex"), + js_word!("cap"), + js_word!("rcap"), + js_word!("ch"), + js_word!("rch"), + js_word!("ic"), + js_word!("ric"), + js_word!("lh"), + js_word!("rlh"), // Viewport-percentage Lengths - "vw" | "svw" | "lvw" | "dvw" | - "vh" | "svh" | "lvh" | "dvh" | - "vi" | "svi" | "lvi" | "dvi" | - "vb" | "svb" | "lvb" | "dvb" | - "vmin" | "svmin" | "lvmin" | "dvmin" | - "vmax" | "svmax" | "lvmax" | "dvmax" | + js_word!("vw"), + js_word!("svw"), + js_word!("lvw"), + js_word!("dvw"), + js_word!("vh"), + js_word!("svh"), + js_word!("lvh"), + js_word!("dvh"), + js_word!("vi"), + js_word!("svi"), + js_word!("lvi"), + js_word!("dvi"), + js_word!("vb"), + js_word!("svb"), + js_word!("lvb"), + js_word!("dvb"), + js_word!("vmin"), + js_word!("svmin"), + js_word!("lvmin"), + js_word!("dvmin"), + js_word!("vmax"), + js_word!("svmax"), + js_word!("lvmax"), + js_word!("dvmax"), // Absolute lengths - "cm" | "mm" | "q" | "in" | "pc" | "pt" | "px" | "mozmm" + js_word!("cm"), + js_word!("mm"), + js_word!("q"), + js_word!("in"), + js_word!("pc"), + js_word!("pt"), + js_word!("px"), + js_word!("mozmm") ) } fn is_container_lengths_unit(unit: &str) -> bool { - matches_eq_ignore_ascii_case!(unit, "cqw", "cqh", "cqi", "cqb", "cqmin", "cqmax") + matches_eq_ignore_ascii_case!( + unit, + js_word!("cqw"), + js_word!("cqh"), + js_word!("cqi"), + js_word!("cqb"), + js_word!("cqmin"), + js_word!("cqmax") + ) } fn is_angle_unit(unit: &str) -> bool { - matches_eq_ignore_ascii_case!(unit, "deg", "grad", "rad", "turn") + matches_eq_ignore_ascii_case!( + unit, + js_word!("deg"), + js_word!("grad"), + js_word!("rad"), + js_word!("turn") + ) } fn is_time_unit(unit: &str) -> bool { - matches_eq_ignore_ascii_case!(unit, "s", "ms") + matches_eq_ignore_ascii_case!(unit, js_word!("s"), js_word!("ms")) } fn is_frequency_unit(unit: &str) -> bool { - matches_eq_ignore_ascii_case!(unit, "hz", "khz") + matches_eq_ignore_ascii_case!(unit, js_word!("hz"), js_word!("khz")) } fn is_resolution_unit(unit: &str) -> bool { - matches_eq_ignore_ascii_case!(unit, "dpi", "dpcm", "dppx", "x") + matches_eq_ignore_ascii_case!( + unit, + js_word!("dpi"), + js_word!("dpcm"), + js_word!("dppx"), + js_word!("x") + ) } fn is_flex_unit(unit: &str) -> bool { - matches_eq_ignore_ascii_case!(unit, "fr") + matches_eq_ignore_ascii_case!(unit, js_word!("fr")) } 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 0251ea8ee94d..2620ca19f11f 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 @@ -412,7 +412,7 @@ "end": 194, "ctxt": 0 }, - "value": "URL", + "value": "url", "raw": "URL" }, "value": { @@ -1057,7 +1057,7 @@ "end": 494, "ctxt": 0 }, - "value": "LAYER", + "value": "layer", "raw": "LAYER" }, "value": [ @@ -1547,7 +1547,7 @@ "end": 709, "ctxt": 0 }, - "value": "SUPPORTS", + "value": "supports", "raw": "SUPPORTS" }, "value": [ @@ -9192,7 +9192,7 @@ "end": 4755, "ctxt": 0 }, - "value": "LAYER", + "value": "layer", "raw": "LAYER" }, "value": [ @@ -9239,7 +9239,7 @@ "end": 4773, "ctxt": 0 }, - "value": "SUPPORTS", + "value": "supports", "raw": "SUPPORTS" }, "value": [ diff --git a/crates/swc_css_parser/tests/fixture/at-rule/keyframe/output.json b/crates/swc_css_parser/tests/fixture/at-rule/keyframe/output.json index 3df6f83876ea..b72f2b1f277b 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/keyframe/output.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/keyframe/output.json @@ -256,7 +256,7 @@ "end": 158, "ctxt": 0 }, - "value": "translateX", + "value": "translatex", "raw": "translateX" }, "value": [ @@ -354,7 +354,7 @@ "end": 209, "ctxt": 0 }, - "value": "translateX", + "value": "translatex", "raw": "translateX" }, "value": [ @@ -1566,7 +1566,7 @@ "end": 718, "ctxt": 0 }, - "value": "translateX", + "value": "translatex", "raw": "translateX" }, "value": [ @@ -1664,7 +1664,7 @@ "end": 769, "ctxt": 0 }, - "value": "translateX", + "value": "translatex", "raw": "translateX" }, "value": [ diff --git a/crates/swc_css_parser/tests/fixture/at-rule/supports/output.json b/crates/swc_css_parser/tests/fixture/at-rule/supports/output.json index aeca4634604e..4724a819c7c1 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/supports/output.json +++ b/crates/swc_css_parser/tests/fixture/at-rule/supports/output.json @@ -4161,7 +4161,7 @@ "ctxt": 0 }, "name": { - "type": "Ident", + "type": "DashedIdent", "span": { "start": 1709, "end": 1718, diff --git a/crates/swc_css_parser/tests/fixture/at-rule/supports/span.swc-stderr b/crates/swc_css_parser/tests/fixture/at-rule/supports/span.swc-stderr index b9ddb238f2a5..faabc5086200 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/supports/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/at-rule/supports/span.swc-stderr @@ -6331,7 +6331,7 @@ 52 | [--self] { `---- - x Ident + x DashedIdent ,-[$DIR/tests/fixture/at-rule/supports/input.css:50:1] 50 | 51 | @supports (--element(".minwidth")) { @@ -8977,7 +8977,7 @@ 89 | } `---- - x Ident { value: Atom('black' type=inline), raw: "black" } + x Ident { value: Atom('black' type=static), raw: "black" } ,-[$DIR/tests/fixture/at-rule/supports/input.css:87:1] 87 | from { 88 | color: black; @@ -9163,7 +9163,7 @@ 92 | } `---- - x Ident { value: Atom('white' type=inline), raw: "white" } + x Ident { value: Atom('white' type=static), raw: "white" } ,-[$DIR/tests/fixture/at-rule/supports/input.css:90:1] 90 | to { 91 | color: white @@ -9527,7 +9527,7 @@ 101 | body { `---- - x Ident { value: Atom('green' type=inline), raw: "green" } + x Ident { value: Atom('green' type=static), raw: "green" } ,-[$DIR/tests/fixture/at-rule/supports/input.css:99:1] 99 | 100 | @supports (--foo: green) { @@ -11493,7 +11493,7 @@ 126 | } `---- - x Ident { value: Atom('black' type=inline), raw: "black" } + x Ident { value: Atom('black' type=static), raw: "black" } ,-[$DIR/tests/fixture/at-rule/supports/input.css:124:1] 124 | from { 125 | color: black; @@ -11679,7 +11679,7 @@ 129 | } `---- - x Ident { value: Atom('white' type=inline), raw: "white" } + x Ident { value: Atom('white' type=static), raw: "white" } ,-[$DIR/tests/fixture/at-rule/supports/input.css:127:1] 127 | to { 128 | color: white diff --git a/crates/swc_css_parser/tests/fixture/at-rule/unknown/span.swc-stderr b/crates/swc_css_parser/tests/fixture/at-rule/unknown/span.swc-stderr index a4d2759ae0ce..2c976df68a55 100644 --- a/crates/swc_css_parser/tests/fixture/at-rule/unknown/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/at-rule/unknown/span.swc-stderr @@ -6686,7 +6686,7 @@ 50 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/fixture/at-rule/unknown/input.css:48:1] 48 | 49 | color: red; diff --git a/crates/swc_css_parser/tests/fixture/dashed-ident/span.swc-stderr b/crates/swc_css_parser/tests/fixture/dashed-ident/span.swc-stderr index b8ca49d6dc76..0e347a84c50c 100644 --- a/crates/swc_css_parser/tests/fixture/dashed-ident/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/dashed-ident/span.swc-stderr @@ -307,7 +307,7 @@ 8 | } `---- - x Ident { value: Atom('blue' type=inline), raw: "blue" } + x Ident { value: Atom('blue' type=static), raw: "blue" } ,-[$DIR/tests/fixture/dashed-ident/input.css:6:1] 6 | .foo { 7 | --fg-color: blue; diff --git a/crates/swc_css_parser/tests/fixture/function/unknown/output.json b/crates/swc_css_parser/tests/fixture/function/unknown/output.json index bc1b4957efad..f7fd2db97d8d 100644 --- a/crates/swc_css_parser/tests/fixture/function/unknown/output.json +++ b/crates/swc_css_parser/tests/fixture/function/unknown/output.json @@ -182,7 +182,7 @@ "ctxt": 0 }, "name": { - "type": "Ident", + "type": "DashedIdent", "span": { "start": 38, "end": 42, @@ -193,31 +193,20 @@ }, "value": [ { - "type": "Length", + "type": "PreservedToken", "span": { "start": 43, "end": 48, "ctxt": 0 }, - "value": { - "type": "Number", - "span": { - "start": 43, - "end": 46, - "ctxt": 0 - }, - "value": 100.0, - "raw": "100" - }, - "unit": { - "type": "Ident", - "span": { - "start": 46, - "end": 48, - "ctxt": 0 - }, - "value": "px", - "raw": "px" + "token": { + "Dimension": { + "value": 100.0, + "raw_value": "100", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } ] @@ -251,7 +240,7 @@ "ctxt": 0 }, "name": { - "type": "Ident", + "type": "DashedIdent", "span": { "start": 61, "end": 69, @@ -262,31 +251,20 @@ }, "value": [ { - "type": "Length", + "type": "PreservedToken", "span": { "start": 70, "end": 75, "ctxt": 0 }, - "value": { - "type": "Number", - "span": { - "start": 70, - "end": 73, - "ctxt": 0 - }, - "value": 100.0, - "raw": "100" - }, - "unit": { - "type": "Ident", - "span": { - "start": 73, - "end": 75, - "ctxt": 0 - }, - "value": "px", - "raw": "px" + "token": { + "Dimension": { + "value": 100.0, + "raw_value": "100", + "unit": "px", + "type": "integer", + "raw_unit": "px" + } } } ] diff --git a/crates/swc_css_parser/tests/fixture/function/unknown/span.swc-stderr b/crates/swc_css_parser/tests/fixture/function/unknown/span.swc-stderr index 3a96280fd479..f68d505f0b51 100644 --- a/crates/swc_css_parser/tests/fixture/function/unknown/span.swc-stderr +++ b/crates/swc_css_parser/tests/fixture/function/unknown/span.swc-stderr @@ -235,7 +235,7 @@ 4 | prod: --fn--fn(100px); `---- - x Ident + x DashedIdent ,-[$DIR/tests/fixture/function/unknown/input.css:2:1] 2 | prod: fn(100px); 3 | prod: --fn(100px); @@ -251,15 +251,7 @@ 4 | prod: --fn--fn(100px); `---- - x Dimension - ,-[$DIR/tests/fixture/function/unknown/input.css:2:1] - 2 | prod: fn(100px); - 3 | prod: --fn(100px); - : ^^^^^ - 4 | prod: --fn--fn(100px); - `---- - - x Length + x Dimension(DimensionToken { value: 100.0, raw_value: "100", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/function/unknown/input.css:2:1] 2 | prod: fn(100px); 3 | prod: --fn(100px); @@ -267,22 +259,6 @@ 4 | prod: --fn--fn(100px); `---- - x Number - ,-[$DIR/tests/fixture/function/unknown/input.css:2:1] - 2 | prod: fn(100px); - 3 | prod: --fn(100px); - : ^^^ - 4 | prod: --fn--fn(100px); - `---- - - x Ident - ,-[$DIR/tests/fixture/function/unknown/input.css:2:1] - 2 | prod: fn(100px); - 3 | prod: --fn(100px); - : ^^ - 4 | prod: --fn--fn(100px); - `---- - x ComponentValue ,-[$DIR/tests/fixture/function/unknown/input.css:3:1] 3 | prod: --fn(100px); @@ -331,7 +307,7 @@ 5 | } `---- - x Ident + x DashedIdent ,-[$DIR/tests/fixture/function/unknown/input.css:3:1] 3 | prod: --fn(100px); 4 | prod: --fn--fn(100px); @@ -347,34 +323,10 @@ 5 | } `---- - x Dimension - ,-[$DIR/tests/fixture/function/unknown/input.css:3:1] - 3 | prod: --fn(100px); - 4 | prod: --fn--fn(100px); - : ^^^^^ - 5 | } - `---- - - x Length + x Dimension(DimensionToken { value: 100.0, raw_value: "100", unit: Atom('px' type=static), type_flag: Integer, raw_unit: "px" }) ,-[$DIR/tests/fixture/function/unknown/input.css:3:1] 3 | prod: --fn(100px); 4 | prod: --fn--fn(100px); : ^^^^^ 5 | } `---- - - x Number - ,-[$DIR/tests/fixture/function/unknown/input.css:3:1] - 3 | prod: --fn(100px); - 4 | prod: --fn--fn(100px); - : ^^^ - 5 | } - `---- - - x Ident - ,-[$DIR/tests/fixture/function/unknown/input.css:3:1] - 3 | prod: --fn(100px); - 4 | prod: --fn--fn(100px); - : ^^ - 5 | } - `---- diff --git a/crates/swc_css_parser/tests/fixture/function/url/output.json b/crates/swc_css_parser/tests/fixture/function/url/output.json index c7a7d370cabb..83275e10329f 100644 --- a/crates/swc_css_parser/tests/fixture/function/url/output.json +++ b/crates/swc_css_parser/tests/fixture/function/url/output.json @@ -269,7 +269,7 @@ "end": 229, "ctxt": 0 }, - "value": "URL", + "value": "url", "raw": "URL" }, "value": { diff --git a/crates/swc_css_parser/tests/fixture/value/color/output.json b/crates/swc_css_parser/tests/fixture/value/color/output.json index 801b97e22d17..8312047f21e4 100644 --- a/crates/swc_css_parser/tests/fixture/value/color/output.json +++ b/crates/swc_css_parser/tests/fixture/value/color/output.json @@ -491,7 +491,7 @@ "end": 171, "ctxt": 0 }, - "value": "rGb", + "value": "rgb", "raw": "rGb" }, "value": [ @@ -2419,7 +2419,7 @@ "end": 812, "ctxt": 0 }, - "value": "rGbA", + "value": "rgba", "raw": "rGbA" }, "value": [ @@ -3850,7 +3850,7 @@ "end": 1299, "ctxt": 0 }, - "value": "HsL", + "value": "hsl", "raw": "HsL" }, "value": [ 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 d31c7707527d..e04ed1949976 100644 --- a/crates/swc_css_parser/tests/fixture/value/url/output.json +++ b/crates/swc_css_parser/tests/fixture/value/url/output.json @@ -369,7 +369,7 @@ "end": 291, "ctxt": 0 }, - "value": "URL", + "value": "url", "raw": "URL" }, "value": { @@ -419,7 +419,7 @@ "end": 346, "ctxt": 0 }, - "value": "URL", + "value": "url", "raw": "\\URL" }, "value": { @@ -1087,7 +1087,7 @@ "end": 948, "ctxt": 0 }, - "value": "SRC", + "value": "src", "raw": "SRC" }, "value": { diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/span.swc-stderr index 6ff43bff90de..cc71c206b1ca 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/span.swc-stderr @@ -164,7 +164,7 @@ 3 | main { `---- - x Ident { value: Atom('teal' type=inline), raw: "teal" } + x Ident { value: Atom('teal' type=static), raw: "teal" } ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:1:1] 1 | @media print { 2 | color: teal; diff --git a/crates/swc_css_parser/tests/recovery/at-rule/page/without-page/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/page/without-page/span.swc-stderr index 21884afd8628..50c6c382ce15 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/page/without-page/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/page/without-page/span.swc-stderr @@ -232,7 +232,7 @@ 4 | } `---- - x Ident { value: Atom('blue' type=inline), raw: "blue" } + x Ident { value: Atom('blue' type=static), raw: "blue" } ,-[$DIR/tests/recovery/at-rule/page/without-page/input.css:2:1] 2 | content: "foo"; 3 | color: blue; diff --git a/crates/swc_css_parser/tests/recovery/at-rule/supports/non-standard-prelude/output.json b/crates/swc_css_parser/tests/recovery/at-rule/supports/non-standard-prelude/output.json index b70b5d1f831a..e84c0c5f34ca 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/supports/non-standard-prelude/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/supports/non-standard-prelude/output.json @@ -47,7 +47,7 @@ "ctxt": 0 }, "name": { - "type": "Ident", + "type": "DashedIdent", "span": { "start": 12, "end": 21, @@ -1496,7 +1496,7 @@ "ctxt": 0 }, "name": { - "type": "Ident", + "type": "DashedIdent", "span": { "start": 356, "end": 362, diff --git a/crates/swc_css_parser/tests/recovery/at-rule/supports/non-standard-prelude/span.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/supports/non-standard-prelude/span.swc-stderr index fef4cfbacf92..ddab4187ca14 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/supports/non-standard-prelude/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/supports/non-standard-prelude/span.swc-stderr @@ -95,7 +95,7 @@ 2 | [--self] { `---- - x Ident + x DashedIdent ,-[$DIR/tests/recovery/at-rule/supports/non-standard-prelude/input.css:1:1] 1 | @supports (--element(".minwidth", { "minWidth": 300 })) { : ^^^^^^^^^ @@ -1428,7 +1428,7 @@ 20 | * { background: red; } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/at-rule/supports/non-standard-prelude/input.css:18:1] 18 | 19 | @supports ([color: red]) { @@ -1836,7 +1836,7 @@ 24 | * { background: red; } `---- - x Ident + x DashedIdent ,-[$DIR/tests/recovery/at-rule/supports/non-standard-prelude/input.css:22:1] 22 | 23 | @supports ([[[[[{ --func(color: { red }) }]]]]]) { @@ -1940,7 +1940,7 @@ 24 | * { background: red; } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/at-rule/supports/non-standard-prelude/input.css:22:1] 22 | 23 | @supports ([[[[[{ --func(color: { red }) }]]]]]) { diff --git a/crates/swc_css_parser/tests/recovery/cdo-and-cdc/span.swc-stderr b/crates/swc_css_parser/tests/recovery/cdo-and-cdc/span.swc-stderr index 0097a5c9a9a1..32284f02ee53 100644 --- a/crates/swc_css_parser/tests/recovery/cdo-and-cdc/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/cdo-and-cdc/span.swc-stderr @@ -651,7 +651,7 @@ 21 | } `---- - x Ident { value: Atom('blue' type=inline), raw: "blue" } + x Ident { value: Atom('blue' type=static), raw: "blue" } ,-[$DIR/tests/recovery/cdo-and-cdc/input.css:19:1] 19 | 20 | color: blue; diff --git a/crates/swc_css_parser/tests/recovery/declaration/important-1/span.swc-stderr b/crates/swc_css_parser/tests/recovery/declaration/important-1/span.swc-stderr index 8148a37168b3..f48170bd0f89 100644 --- a/crates/swc_css_parser/tests/recovery/declaration/important-1/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/declaration/important-1/span.swc-stderr @@ -123,7 +123,7 @@ 3 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important-1/input.css:1:1] 1 | a { 2 | color: red !importan; diff --git a/crates/swc_css_parser/tests/recovery/declaration/important/span.swc-stderr b/crates/swc_css_parser/tests/recovery/declaration/important/span.swc-stderr index c13df6614162..233e5d5985ba 100644 --- a/crates/swc_css_parser/tests/recovery/declaration/important/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/declaration/important/span.swc-stderr @@ -136,7 +136,7 @@ 3 | } `---- - x Ident { value: Atom('white' type=inline), raw: "white" } + x Ident { value: Atom('white' type=static), raw: "white" } ,-[$DIR/tests/recovery/declaration/important/input.css:1:1] 1 | .a { 2 | color: white !!important; @@ -312,7 +312,7 @@ 7 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:5:1] 5 | .class { 6 | color: red red red !important !important; @@ -344,7 +344,7 @@ 7 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:5:1] 5 | .class { 6 | color: red red red !important !important; @@ -376,7 +376,7 @@ 7 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:5:1] 5 | .class { 6 | color: red red red !important !important; @@ -568,7 +568,7 @@ 11 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:9:1] 9 | .class { 10 | color: red red red !important!important ; @@ -600,7 +600,7 @@ 11 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:9:1] 9 | .class { 10 | color: red red red !important!important ; @@ -632,7 +632,7 @@ 11 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:9:1] 9 | .class { 10 | color: red red red !important!important ; @@ -824,7 +824,7 @@ 15 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:13:1] 13 | .class { 14 | color: red red red /* test*/ !important /*test*/ !important /*test*/ ; @@ -856,7 +856,7 @@ 15 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:13:1] 13 | .class { 14 | color: red red red /* test*/ !important /*test*/ !important /*test*/ ; @@ -888,7 +888,7 @@ 15 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:13:1] 13 | .class { 14 | color: red red red /* test*/ !important /*test*/ !important /*test*/ ; @@ -1096,7 +1096,7 @@ 19 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:17:1] 17 | .class { 18 | color: red red red !important !important!important; @@ -1128,7 +1128,7 @@ 19 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:17:1] 17 | .class { 18 | color: red red red !important !important!important; @@ -1160,7 +1160,7 @@ 19 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:17:1] 17 | .class { 18 | color: red red red !important !important!important; @@ -1400,7 +1400,7 @@ 23 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:21:1] 21 | .class { 22 | color: red red red /* test */ ! /*test */ important /* test */ ! /* test */ important /* test */; @@ -1432,7 +1432,7 @@ 23 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:21:1] 21 | .class { 22 | color: red red red /* test */ ! /*test */ important /* test */ ! /* test */ important /* test */; @@ -1464,7 +1464,7 @@ 23 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/important/input.css:21:1] 21 | .class { 22 | color: red red red /* test */ ! /*test */ important /* test */ ! /* test */ important /* test */; diff --git a/crates/swc_css_parser/tests/recovery/declaration/wrong-name/span.swc-stderr b/crates/swc_css_parser/tests/recovery/declaration/wrong-name/span.swc-stderr index 82785580a6f0..20a945caec17 100644 --- a/crates/swc_css_parser/tests/recovery/declaration/wrong-name/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/declaration/wrong-name/span.swc-stderr @@ -147,7 +147,7 @@ 3 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/declaration/wrong-name/input.css:1:1] 1 | a { 2 | 20: red; diff --git a/crates/swc_css_parser/tests/recovery/delim-token/at-sign/span.swc-stderr b/crates/swc_css_parser/tests/recovery/delim-token/at-sign/span.swc-stderr index 8e05da56c4a2..922af9c42c23 100644 --- a/crates/swc_css_parser/tests/recovery/delim-token/at-sign/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/delim-token/at-sign/span.swc-stderr @@ -155,7 +155,7 @@ 3 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/delim-token/at-sign/input.css:1:1] 1 | a { 2 | color: @ red; diff --git a/crates/swc_css_parser/tests/recovery/hacks/span.swc-stderr b/crates/swc_css_parser/tests/recovery/hacks/span.swc-stderr index 9b202a91121e..3b7e84b60e68 100644 --- a/crates/swc_css_parser/tests/recovery/hacks/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/hacks/span.swc-stderr @@ -19316,7 +19316,7 @@ 245 | _background: white; `---- - x Ident { value: Atom('black' type=inline), raw: "black" } + x Ident { value: Atom('black' type=static), raw: "black" } ,-[$DIR/tests/recovery/hacks/input.css:243:1] 243 | a { 244 | *color : black; diff --git a/crates/swc_css_parser/tests/recovery/ie-progid/output.json b/crates/swc_css_parser/tests/recovery/ie-progid/output.json index 4346cf1b2618..6b96b7803807 100644 --- a/crates/swc_css_parser/tests/recovery/ie-progid/output.json +++ b/crates/swc_css_parser/tests/recovery/ie-progid/output.json @@ -456,7 +456,7 @@ "end": 172, "ctxt": 0 }, - "value": "Blur", + "value": "blur", "raw": "Blur" }, "value": [ @@ -608,7 +608,7 @@ "end": 227, "ctxt": 0 }, - "value": "Wheel", + "value": "wheel", "raw": "Wheel" }, "value": [ diff --git a/crates/swc_css_parser/tests/recovery/rules/unclosed-brackets/span.swc-stderr b/crates/swc_css_parser/tests/recovery/rules/unclosed-brackets/span.swc-stderr index 6aae0fa43412..53916c801409 100644 --- a/crates/swc_css_parser/tests/recovery/rules/unclosed-brackets/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/rules/unclosed-brackets/span.swc-stderr @@ -285,7 +285,7 @@ : ^^^ `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/rules/unclosed-brackets/input.css:4:1] 4 | 5 | .class { color: red } @@ -448,7 +448,7 @@ : ^^^^ `---- - x Ident { value: Atom('blue' type=inline), raw: "blue" } + x Ident { value: Atom('blue' type=static), raw: "blue" } ,-[$DIR/tests/recovery/rules/unclosed-brackets/input.css:6:1] 6 | 7 | .class { color: blue } diff --git a/crates/swc_css_parser/tests/recovery/style-blocks-contents/basic/span.swc-stderr b/crates/swc_css_parser/tests/recovery/style-blocks-contents/basic/span.swc-stderr index f880d2694f33..16c03af5d304 100644 --- a/crates/swc_css_parser/tests/recovery/style-blocks-contents/basic/span.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/style-blocks-contents/basic/span.swc-stderr @@ -399,7 +399,7 @@ 7 | } `---- - x Ident { value: Atom('green' type=inline), raw: "green" } + x Ident { value: Atom('green' type=static), raw: "green" } ,-[$DIR/tests/recovery/style-blocks-contents/basic/input.css:5:1] 5 | ident 6 | color: green; @@ -834,7 +834,7 @@ 15 | } `---- - x Ident { value: Atom('red' type=inline), raw: "red" } + x Ident { value: Atom('red' type=static), raw: "red" } ,-[$DIR/tests/recovery/style-blocks-contents/basic/input.css:13:1] 13 | ident 14 | color: red diff --git a/crates/swc_css_visit/src/lib.rs b/crates/swc_css_visit/src/lib.rs index 79ea37dbd2ae..27189d764aa5 100644 --- a/crates/swc_css_visit/src/lib.rs +++ b/crates/swc_css_visit/src/lib.rs @@ -154,9 +154,14 @@ define!({ pub value: DelimiterValue, } + pub enum FunctionName { + Ident(Ident), + DashedIdent(DashedIdent), + } + pub struct Function { pub span: Span, - pub name: Ident, + pub name: FunctionName, pub value: Vec, }