From 983ab9143514a08f3448062ab6b0e97dec31e679 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Fri, 11 Nov 2022 10:27:19 +0300 Subject: [PATCH] refactor(css/parser): Refactor parser (#6395) --- crates/swc_css_ast/src/base.rs | 6 +- .../swc_css_parser/src/parser/syntax/mod.rs | 114 +-- crates/swc_css_parser/src/parser/util.rs | 9 + .../tests/fixture/style-block/input.css | 24 + .../tests/fixture/style-block/output.json | 749 +++++++++++++++- .../tests/fixture/style-block/span.rust-debug | 817 +++++++++++++++++- .../fixture/stylesheet/cdo-and-cdc/input.css | 7 + .../stylesheet/cdo-and-cdc/output.json | 240 +++++ .../stylesheet/cdo-and-cdc/span.rust-debug | 233 +++++ .../at-rule/font-face/output.swc-stderr | 4 +- .../tests/recovery/cdo-and-cdc/input.css | 6 + .../tests/recovery/cdo-and-cdc/output.json | 216 ++++- .../recovery/cdo-and-cdc/output.swc-stderr | 38 +- .../recovery/cdo-and-cdc/span.rust-debug | 219 ++++- .../declaration/important-1/input.css | 3 + .../declaration/important-1/output.json | 169 ++++ .../declaration/important-1/output.swc-stderr | 12 + .../declaration/important-1/span.rust-debug | 154 ++++ .../declaration/wrong-name-2/input.css | 3 + .../declaration/wrong-name-2/output.json | 132 +++ .../wrong-name-2/output.swc-stderr | 6 + .../declaration/wrong-name-2/span.rust-debug | 118 +++ .../declaration/wrong-name-3/input.css | 3 + .../declaration/wrong-name-3/output.json | 150 ++++ .../wrong-name-3/output.swc-stderr | 6 + .../declaration/wrong-name-3/span.rust-debug | 130 +++ .../recovery/declaration/wrong-name/input.css | 3 + .../declaration/wrong-name/output.json | 164 ++++ .../declaration/wrong-name/output.swc-stderr | 12 + .../declaration/wrong-name/span.rust-debug | 148 ++++ .../nested-unclosed}/input.css | 0 .../nested-unclosed}/output.json | 0 .../nested-unclosed}/output.swc-stderr | 2 +- .../nested-unclosed}/span.rust-debug | 52 +- .../tests/recovery/hacks/output.swc-stderr | 140 +-- .../simple-block/unclosed-1/input.css | 1 + .../simple-block/unclosed-1/output.json | 77 ++ .../simple-block/unclosed-1/output.swc-stderr | 6 + .../simple-block/unclosed-1/span.rust-debug | 66 ++ .../simple-block/unclosed-2/input.css | 3 + .../simple-block/unclosed-2/output.json | 193 +++++ .../simple-block/unclosed-2/output.swc-stderr | 13 + .../simple-block/unclosed-2/span.rust-debug | 184 ++++ .../simple-block/unclosed-3/input.css | 2 + .../simple-block/unclosed-3/output.json | 125 +++ .../simple-block/unclosed-3/output.swc-stderr | 6 + .../simple-block/unclosed-3/span.rust-debug | 114 +++ .../unclosed-in-function/input.css | 3 - .../unclosed-in-function/output.json | 233 ----- .../unclosed-in-function/output.swc-stderr | 25 - .../recovery/simple-block/unclosed/input.css | 4 + .../simple-block/unclosed/output.json | 242 ++++++ .../simple-block/unclosed/output.swc-stderr | 14 + .../simple-block/unclosed/span.rust-debug | 236 +++++ .../basic/output.swc-stderr | 4 +- .../invalid-nested-1/input.css | 7 + .../invalid-nested-1/output.json | 282 ++++++ .../invalid-nested-1/output.swc-stderr | 6 + .../invalid-nested-1/span.rust-debug | 292 +++++++ .../invalid-nested-2/output.swc-stderr | 4 +- .../invalid-nested/output.swc-stderr | 4 +- crates/swc_css_visit/src/lib.rs | 4 +- 62 files changed, 5789 insertions(+), 450 deletions(-) create mode 100644 crates/swc_css_parser/tests/fixture/stylesheet/cdo-and-cdc/input.css create mode 100644 crates/swc_css_parser/tests/fixture/stylesheet/cdo-and-cdc/output.json create mode 100644 crates/swc_css_parser/tests/fixture/stylesheet/cdo-and-cdc/span.rust-debug create mode 100644 crates/swc_css_parser/tests/recovery/declaration/important-1/input.css create mode 100644 crates/swc_css_parser/tests/recovery/declaration/important-1/output.json create mode 100644 crates/swc_css_parser/tests/recovery/declaration/important-1/output.swc-stderr create mode 100644 crates/swc_css_parser/tests/recovery/declaration/important-1/span.rust-debug create mode 100644 crates/swc_css_parser/tests/recovery/declaration/wrong-name-2/input.css create mode 100644 crates/swc_css_parser/tests/recovery/declaration/wrong-name-2/output.json create mode 100644 crates/swc_css_parser/tests/recovery/declaration/wrong-name-2/output.swc-stderr create mode 100644 crates/swc_css_parser/tests/recovery/declaration/wrong-name-2/span.rust-debug create mode 100644 crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/input.css create mode 100644 crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/output.json create mode 100644 crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/output.swc-stderr create mode 100644 crates/swc_css_parser/tests/recovery/declaration/wrong-name-3/span.rust-debug create mode 100644 crates/swc_css_parser/tests/recovery/declaration/wrong-name/input.css create mode 100644 crates/swc_css_parser/tests/recovery/declaration/wrong-name/output.json create mode 100644 crates/swc_css_parser/tests/recovery/declaration/wrong-name/output.swc-stderr create mode 100644 crates/swc_css_parser/tests/recovery/declaration/wrong-name/span.rust-debug rename crates/swc_css_parser/tests/recovery/{function-token => function/nested-unclosed}/input.css (100%) rename crates/swc_css_parser/tests/recovery/{function-token => function/nested-unclosed}/output.json (100%) rename crates/swc_css_parser/tests/recovery/{function-token => function/nested-unclosed}/output.swc-stderr (57%) rename crates/swc_css_parser/tests/recovery/{function-token => function/nested-unclosed}/span.rust-debug (50%) create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-1/input.css create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-1/output.json create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-1/output.swc-stderr create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-1/span.rust-debug create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-2/input.css create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-2/output.json create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-2/output.swc-stderr create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-2/span.rust-debug create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-3/input.css create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-3/output.json create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-3/output.swc-stderr create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-3/span.rust-debug delete mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-in-function/input.css delete mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-in-function/output.json delete mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed-in-function/output.swc-stderr create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed/input.css create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed/output.json create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed/output.swc-stderr create mode 100644 crates/swc_css_parser/tests/recovery/simple-block/unclosed/span.rust-debug create mode 100644 crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/input.css create mode 100644 crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/output.json create mode 100644 crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/output.swc-stderr create mode 100644 crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-1/span.rust-debug diff --git a/crates/swc_css_ast/src/base.rs b/crates/swc_css_ast/src/base.rs index 3f42ef291458..41483f89dc24 100644 --- a/crates/swc_css_ast/src/base.rs +++ b/crates/swc_css_ast/src/base.rs @@ -49,14 +49,14 @@ pub enum QualifiedRulePrelude { #[ast_node] #[derive(Eq, Hash, Is, EqIgnoreSpan)] pub enum StyleBlock { - #[tag("ListOfComponentValues")] - ListOfComponentValues(ListOfComponentValues), #[tag("AtRule")] AtRule(Box), #[tag("Declaration")] Declaration(Box), #[tag("QualifiedRule")] QualifiedRule(Box), + #[tag("ListOfComponentValues")] + ListOfComponentValues(Box), } #[ast_node("SimpleBlock")] @@ -158,7 +158,7 @@ pub enum DeclarationOrAtRule { AtRule(Box), // For recovery mode #[tag("ListOfComponentValues")] - ListOfComponentValues(ListOfComponentValues), + ListOfComponentValues(Box), } #[ast_node("Declaration")] diff --git a/crates/swc_css_parser/src/parser/syntax/mod.rs b/crates/swc_css_parser/src/parser/syntax/mod.rs index dcdaabad6fb7..639dff8819e9 100644 --- a/crates/swc_css_parser/src/parser/syntax/mod.rs +++ b/crates/swc_css_parser/src/parser/syntax/mod.rs @@ -362,10 +362,9 @@ where // Otherwise, append a to the qualified rule’s prelude. tok!(";") => { if self.ctx.mixed_with_declarations { - return Err(Error::new( - span!(self, span.lo), - ErrorKind::EofButExpected("'{'"), - )); + let span = self.input.cur_span(); + + return Err(Error::new(span, ErrorKind::Expected("'{'"))); } else { let component_value = self.parse_as::()?; @@ -505,19 +504,17 @@ where temporary_list.children.push(component_value); } - let decl_or_list_of_component_values = match self - .parse_according_to_grammar::(&temporary_list, |parser| { - parser.parse_as() - }) { - Ok(decl) => StyleBlock::Declaration(Box::new(decl)), - Err(err) => { - self.errors.push(err); + let decl_or_list_of_component_values = + match self.parse_declaration_from_temporary_list(&temporary_list) { + Ok(decl) => StyleBlock::Declaration(Box::new(decl)), + Err(err) => { + self.errors.push(err); - temporary_list.span = span!(self, span.lo); + temporary_list.span = span!(self, span.lo); - StyleBlock::ListOfComponentValues(temporary_list) - } - }; + StyleBlock::ListOfComponentValues(Box::new(temporary_list)) + } + }; declarations.push(decl_or_list_of_component_values); } @@ -528,6 +525,7 @@ where let state = self.input.state(); let qualified_rule = self .with_ctx(Ctx { + block_contents_grammar: BlockContentsGrammar::StyleBlock, mixed_with_declarations: true, ..self.ctx }) @@ -550,7 +548,6 @@ where children: vec![], }; - // TODO verify error recovery (copied from prev spec) while !is_one_of!(self, ";", EOF) { let component_value = self.parse_as::()?; @@ -559,8 +556,9 @@ where list_of_component_values.span = span!(self, span.lo); - declarations - .push(StyleBlock::ListOfComponentValues(list_of_component_values)); + declarations.push(StyleBlock::ListOfComponentValues(Box::new( + list_of_component_values, + ))); } }; } @@ -615,7 +613,14 @@ where // Reconsume the current input token. Consume an at-rule. Append the returned rule // to the list of declarations. tok!("@") => { - declarations.push(DeclarationOrAtRule::AtRule(self.parse()?)); + let at_rule = self + .with_ctx(Ctx { + block_contents_grammar: BlockContentsGrammar::DeclarationList, + ..self.ctx + }) + .parse_as::()?; + + declarations.push(DeclarationOrAtRule::AtRule(Box::new(at_rule))); } // // Initialize a temporary list initially filled with the current input token. As @@ -625,9 +630,10 @@ where // it to the list of declarations. tok!("ident") => { let span = self.input.cur_span(); + let cur = self.input.bump().unwrap(); let mut temporary_list = ListOfComponentValues { span: Default::default(), - children: vec![], + children: vec![ComponentValue::PreservedToken(cur)], }; while !is_one_of!(self, ";", EOF) { @@ -636,19 +642,17 @@ where temporary_list.children.push(component_value); } - let decl_or_list_of_component_values = match self - .parse_according_to_grammar::(&temporary_list, |parser| { - parser.parse_as() - }) { - Ok(decl) => DeclarationOrAtRule::Declaration(Box::new(decl)), - Err(err) => { - self.errors.push(err); + let decl_or_list_of_component_values = + match self.parse_declaration_from_temporary_list(&temporary_list) { + Ok(decl) => DeclarationOrAtRule::Declaration(Box::new(decl)), + Err(err) => { + self.errors.push(err); - temporary_list.span = span!(self, span.lo); + temporary_list.span = span!(self, span.lo); - DeclarationOrAtRule::ListOfComponentValues(temporary_list) - } - }; + DeclarationOrAtRule::ListOfComponentValues(Box::new(temporary_list)) + } + }; declarations.push(decl_or_list_of_component_values); } @@ -664,9 +668,7 @@ where self.errors.push(Error::new( span, - ErrorKind::Expected( - "whitespace, semicolon, EOF, at-keyword or ident token", - ), + ErrorKind::Expected("whitespace, ';', '@', ident or EOF"), )); // For recovery mode @@ -683,9 +685,9 @@ where list_of_component_values.span = span!(self, span.lo); - declarations.push(DeclarationOrAtRule::ListOfComponentValues( + declarations.push(DeclarationOrAtRule::ListOfComponentValues(Box::new( list_of_component_values, - )); + ))); } } } @@ -718,7 +720,7 @@ where let is_dashed_ident = match cur!(self) { Token::Ident { value, .. } => value.starts_with("--"), _ => { - return Err(Error::new(span, ErrorKind::Expected("Ident"))); + return Err(Error::new(span, ErrorKind::Expected("ident"))); } }; let name = if is_dashed_ident { @@ -879,30 +881,31 @@ where } // Grammar parsing - let locv = self.create_locv(declaration.value); + let list_of_component_values = self.create_locv(declaration.value); - declaration.value = match self.parse_according_to_grammar(&locv, |parser| { - let mut values = vec![]; + declaration.value = + match self.parse_according_to_grammar(&list_of_component_values, |parser| { + let mut values = vec![]; - loop { - if is!(parser, EOF) { - break; + loop { + if is!(parser, EOF) { + break; + } + + values.push(parser.parse_generic_value()?); } - values.push(parser.parse_generic_value()?); - } + Ok(values) + }) { + Ok(values) => values, + Err(err) => { + if *err.kind() != ErrorKind::Ignore { + self.errors.push(err); + } - Ok(values) - }) { - Ok(values) => values, - Err(err) => { - if *err.kind() != ErrorKind::Ignore { - self.errors.push(err); + list_of_component_values.children } - - locv.children - } - }; + }; // 8. Return the declaration. Ok(declaration) @@ -1098,6 +1101,7 @@ where function.span = span!(self, span.lo); + // Grammar parsing match self.ctx.block_contents_grammar { BlockContentsGrammar::DeclarationList => {} _ => { diff --git a/crates/swc_css_parser/src/parser/util.rs b/crates/swc_css_parser/src/parser/util.rs index 726d656ce7cd..56be179d66fe 100644 --- a/crates/swc_css_parser/src/parser/util.rs +++ b/crates/swc_css_parser/src/parser/util.rs @@ -7,6 +7,7 @@ use super::{ input::{Input, InputType, ParserInput}, Ctx, Error, PResult, Parse, Parser, }; +use crate::parser::BlockContentsGrammar; impl Parser where @@ -77,6 +78,7 @@ where let state = self.input.state(); let qualified_rule = self .with_ctx(Ctx { + block_contents_grammar: BlockContentsGrammar::StyleBlock, mixed_with_declarations: true, ..self.ctx }) @@ -114,6 +116,13 @@ where Err(_) => None, } } + + pub(super) fn parse_declaration_from_temporary_list( + &mut self, + temporary_list: &ListOfComponentValues, + ) -> PResult { + self.parse_according_to_grammar::(temporary_list, |parser| parser.parse_as()) + } } pub(super) struct WithCtx<'w, I: 'w + ParserInput> { diff --git a/crates/swc_css_parser/tests/fixture/style-block/input.css b/crates/swc_css_parser/tests/fixture/style-block/input.css index db67eb9b2394..10944b545fde 100644 --- a/crates/swc_css_parser/tests/fixture/style-block/input.css +++ b/crates/swc_css_parser/tests/fixture/style-block/input.css @@ -113,3 +113,27 @@ a/**/ } ; } + +a { + color: red; + + .class { + color: green; + } + + color: blue; +} + +.foo { + color: red; + + + .bar { + color: blue; + } +} + +article { + color: green; + & { color: blue; } + color: red; +} 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 5e27126585a7..f09f84066081 100644 --- a/crates/swc_css_parser/tests/fixture/style-block/output.json +++ b/crates/swc_css_parser/tests/fixture/style-block/output.json @@ -2,7 +2,7 @@ "type": "Stylesheet", "span": { "start": 1, - "end": 1444, + "end": 1664, "ctxt": 0 }, "rules": [ @@ -4491,6 +4491,753 @@ } ] } + }, + { + "type": "QualifiedRule", + "span": { + "start": 1445, + "end": 1526, + "ctxt": 0 + }, + "prelude": { + "type": "SelectorList", + "span": { + "start": 1445, + "end": 1446, + "ctxt": 0 + }, + "children": [ + { + "type": "ComplexSelector", + "span": { + "start": 1445, + "end": 1446, + "ctxt": 0 + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 1445, + "end": 1446, + "ctxt": 0 + }, + "nestingSelector": null, + "typeSelector": { + "type": "TagNameSelector", + "span": { + "start": 1445, + "end": 1446, + "ctxt": 0 + }, + "name": { + "type": "WqName", + "span": { + "start": 1445, + "end": 1446, + "ctxt": 0 + }, + "prefix": null, + "value": { + "type": "Ident", + "span": { + "start": 1445, + "end": 1446, + "ctxt": 0 + }, + "value": "a", + "raw": "a" + } + } + }, + "subclassSelectors": [] + } + ] + } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 1447, + "end": 1526, + "ctxt": 0 + }, + "name": { + "type": "PreservedToken", + "span": { + "start": 1447, + "end": 1448, + "ctxt": 0 + }, + "token": "LBrace" + }, + "value": [ + { + "type": "Declaration", + "span": { + "start": 1453, + "end": 1463, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 1453, + "end": 1458, + "ctxt": 0 + }, + "value": "color", + "raw": "color" + }, + "value": [ + { + "type": "Ident", + "span": { + "start": 1460, + "end": 1463, + "ctxt": 0 + }, + "value": "red", + "raw": "red" + } + ], + "important": null + }, + { + "type": "Declaration", + "span": { + "start": 1512, + "end": 1523, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 1512, + "end": 1517, + "ctxt": 0 + }, + "value": "color", + "raw": "color" + }, + "value": [ + { + "type": "Ident", + "span": { + "start": 1519, + "end": 1523, + "ctxt": 0 + }, + "value": "blue", + "raw": "blue" + } + ], + "important": null + }, + { + "type": "QualifiedRule", + "span": { + "start": 1470, + "end": 1506, + "ctxt": 0 + }, + "prelude": { + "type": "RelativeSelectorList", + "span": { + "start": 1470, + "end": 1476, + "ctxt": 0 + }, + "children": [ + { + "type": "RelativeSelector", + "span": { + "start": 1470, + "end": 1476, + "ctxt": 0 + }, + "combinator": null, + "selector": { + "type": "ComplexSelector", + "span": { + "start": 1470, + "end": 1476, + "ctxt": 0 + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 1470, + "end": 1476, + "ctxt": 0 + }, + "nestingSelector": null, + "typeSelector": null, + "subclassSelectors": [ + { + "type": "ClassSelector", + "span": { + "start": 1470, + "end": 1476, + "ctxt": 0 + }, + "text": { + "type": "Ident", + "span": { + "start": 1471, + "end": 1476, + "ctxt": 0 + }, + "value": "class", + "raw": "class" + } + } + ] + } + ] + } + } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 1477, + "end": 1506, + "ctxt": 0 + }, + "name": { + "type": "PreservedToken", + "span": { + "start": 1477, + "end": 1478, + "ctxt": 0 + }, + "token": "LBrace" + }, + "value": [ + { + "type": "Declaration", + "span": { + "start": 1487, + "end": 1499, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 1487, + "end": 1492, + "ctxt": 0 + }, + "value": "color", + "raw": "color" + }, + "value": [ + { + "type": "Ident", + "span": { + "start": 1494, + "end": 1499, + "ctxt": 0 + }, + "value": "green", + "raw": "green" + } + ], + "important": null + } + ] + } + } + ] + } + }, + { + "type": "QualifiedRule", + "span": { + "start": 1528, + "end": 1593, + "ctxt": 0 + }, + "prelude": { + "type": "SelectorList", + "span": { + "start": 1528, + "end": 1532, + "ctxt": 0 + }, + "children": [ + { + "type": "ComplexSelector", + "span": { + "start": 1528, + "end": 1532, + "ctxt": 0 + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 1528, + "end": 1532, + "ctxt": 0 + }, + "nestingSelector": null, + "typeSelector": null, + "subclassSelectors": [ + { + "type": "ClassSelector", + "span": { + "start": 1528, + "end": 1532, + "ctxt": 0 + }, + "text": { + "type": "Ident", + "span": { + "start": 1529, + "end": 1532, + "ctxt": 0 + }, + "value": "foo", + "raw": "foo" + } + } + ] + } + ] + } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 1533, + "end": 1593, + "ctxt": 0 + }, + "name": { + "type": "PreservedToken", + "span": { + "start": 1533, + "end": 1534, + "ctxt": 0 + }, + "token": "LBrace" + }, + "value": [ + { + "type": "Declaration", + "span": { + "start": 1539, + "end": 1549, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 1539, + "end": 1544, + "ctxt": 0 + }, + "value": "color", + "raw": "color" + }, + "value": [ + { + "type": "Ident", + "span": { + "start": 1546, + "end": 1549, + "ctxt": 0 + }, + "value": "red", + "raw": "red" + } + ], + "important": null + }, + { + "type": "QualifiedRule", + "span": { + "start": 1556, + "end": 1591, + "ctxt": 0 + }, + "prelude": { + "type": "RelativeSelectorList", + "span": { + "start": 1556, + "end": 1562, + "ctxt": 0 + }, + "children": [ + { + "type": "RelativeSelector", + "span": { + "start": 1556, + "end": 1562, + "ctxt": 0 + }, + "combinator": { + "type": "Combinator", + "span": { + "start": 1556, + "end": 1557, + "ctxt": 0 + }, + "value": "+" + }, + "selector": { + "type": "ComplexSelector", + "span": { + "start": 1558, + "end": 1562, + "ctxt": 0 + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 1558, + "end": 1562, + "ctxt": 0 + }, + "nestingSelector": null, + "typeSelector": null, + "subclassSelectors": [ + { + "type": "ClassSelector", + "span": { + "start": 1558, + "end": 1562, + "ctxt": 0 + }, + "text": { + "type": "Ident", + "span": { + "start": 1559, + "end": 1562, + "ctxt": 0 + }, + "value": "bar", + "raw": "bar" + } + } + ] + } + ] + } + } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 1563, + "end": 1591, + "ctxt": 0 + }, + "name": { + "type": "PreservedToken", + "span": { + "start": 1563, + "end": 1564, + "ctxt": 0 + }, + "token": "LBrace" + }, + "value": [ + { + "type": "Declaration", + "span": { + "start": 1573, + "end": 1584, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 1573, + "end": 1578, + "ctxt": 0 + }, + "value": "color", + "raw": "color" + }, + "value": [ + { + "type": "Ident", + "span": { + "start": 1580, + "end": 1584, + "ctxt": 0 + }, + "value": "blue", + "raw": "blue" + } + ], + "important": null + } + ] + } + } + ] + } + }, + { + "type": "QualifiedRule", + "span": { + "start": 1595, + "end": 1663, + "ctxt": 0 + }, + "prelude": { + "type": "SelectorList", + "span": { + "start": 1595, + "end": 1602, + "ctxt": 0 + }, + "children": [ + { + "type": "ComplexSelector", + "span": { + "start": 1595, + "end": 1602, + "ctxt": 0 + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 1595, + "end": 1602, + "ctxt": 0 + }, + "nestingSelector": null, + "typeSelector": { + "type": "TagNameSelector", + "span": { + "start": 1595, + "end": 1602, + "ctxt": 0 + }, + "name": { + "type": "WqName", + "span": { + "start": 1595, + "end": 1602, + "ctxt": 0 + }, + "prefix": null, + "value": { + "type": "Ident", + "span": { + "start": 1595, + "end": 1602, + "ctxt": 0 + }, + "value": "article", + "raw": "article" + } + } + }, + "subclassSelectors": [] + } + ] + } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 1603, + "end": 1663, + "ctxt": 0 + }, + "name": { + "type": "PreservedToken", + "span": { + "start": 1603, + "end": 1604, + "ctxt": 0 + }, + "token": "LBrace" + }, + "value": [ + { + "type": "Declaration", + "span": { + "start": 1609, + "end": 1621, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 1609, + "end": 1614, + "ctxt": 0 + }, + "value": "color", + "raw": "color" + }, + "value": [ + { + "type": "Ident", + "span": { + "start": 1616, + "end": 1621, + "ctxt": 0 + }, + "value": "green", + "raw": "green" + } + ], + "important": null + }, + { + "type": "Declaration", + "span": { + "start": 1650, + "end": 1660, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 1650, + "end": 1655, + "ctxt": 0 + }, + "value": "color", + "raw": "color" + }, + "value": [ + { + "type": "Ident", + "span": { + "start": 1657, + "end": 1660, + "ctxt": 0 + }, + "value": "red", + "raw": "red" + } + ], + "important": null + }, + { + "type": "QualifiedRule", + "span": { + "start": 1627, + "end": 1645, + "ctxt": 0 + }, + "prelude": { + "type": "RelativeSelectorList", + "span": { + "start": 1627, + "end": 1628, + "ctxt": 0 + }, + "children": [ + { + "type": "RelativeSelector", + "span": { + "start": 1627, + "end": 1628, + "ctxt": 0 + }, + "combinator": null, + "selector": { + "type": "ComplexSelector", + "span": { + "start": 1627, + "end": 1628, + "ctxt": 0 + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 1627, + "end": 1628, + "ctxt": 0 + }, + "nestingSelector": { + "type": "NestingSelector", + "span": { + "start": 1627, + "end": 1628, + "ctxt": 0 + } + }, + "typeSelector": null, + "subclassSelectors": [] + } + ] + } + } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 1629, + "end": 1645, + "ctxt": 0 + }, + "name": { + "type": "PreservedToken", + "span": { + "start": 1629, + "end": 1630, + "ctxt": 0 + }, + "token": "LBrace" + }, + "value": [ + { + "type": "Declaration", + "span": { + "start": 1631, + "end": 1642, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 1631, + "end": 1636, + "ctxt": 0 + }, + "value": "color", + "raw": "color" + }, + "value": [ + { + "type": "Ident", + "span": { + "start": 1638, + "end": 1642, + "ctxt": 0 + }, + "value": "blue", + "raw": "blue" + } + ], + "important": null + } + ] + } + } + ] + } } ] } diff --git a/crates/swc_css_parser/tests/fixture/style-block/span.rust-debug b/crates/swc_css_parser/tests/fixture/style-block/span.rust-debug index 98fec0e4cd91..ed8574640e54 100644 --- a/crates/swc_css_parser/tests/fixture/style-block/span.rust-debug +++ b/crates/swc_css_parser/tests/fixture/style-block/span.rust-debug @@ -115,7 +115,31 @@ 112 | | height: 16px; 113 | | } 114 | | ; - 115 | `-> } + 115 | | } + 116 | | + 117 | | a { + 118 | | color: red; + 119 | | + 120 | | .class { + 121 | | color: green; + 122 | | } + 123 | | + 124 | | color: blue; + 125 | | } + 126 | | + 127 | | .foo { + 128 | | color: red; + 129 | | + 130 | | + .bar { + 131 | | color: blue; + 132 | | } + 133 | | } + 134 | | + 135 | | article { + 136 | | color: green; + 137 | | & { color: blue; } + 138 | | color: red; + 139 | `-> } `---- x Rule @@ -4808,3 +4832,794 @@ 112 | ,-> height: 16px; 113 | `-> } `---- + + x Rule + ,-[$DIR/tests/fixture/style-block/input.css:117:1] + 117 | ,-> a { + 118 | | color: red; + 119 | | + 120 | | .class { + 121 | | color: green; + 122 | | } + 123 | | + 124 | | color: blue; + 125 | `-> } + `---- + + x QualifiedRule + ,-[$DIR/tests/fixture/style-block/input.css:117:1] + 117 | ,-> a { + 118 | | color: red; + 119 | | + 120 | | .class { + 121 | | color: green; + 122 | | } + 123 | | + 124 | | color: blue; + 125 | `-> } + `---- + + x SelectorList + ,-[$DIR/tests/fixture/style-block/input.css:117:1] + 117 | a { + : ^ + `---- + + x ComplexSelector + ,-[$DIR/tests/fixture/style-block/input.css:117:1] + 117 | a { + : ^ + `---- + + x CompoundSelector + ,-[$DIR/tests/fixture/style-block/input.css:117:1] + 117 | a { + : ^ + `---- + + x TypeSelector + ,-[$DIR/tests/fixture/style-block/input.css:117:1] + 117 | a { + : ^ + `---- + + x TagNameSelector + ,-[$DIR/tests/fixture/style-block/input.css:117:1] + 117 | a { + : ^ + `---- + + x WqName + ,-[$DIR/tests/fixture/style-block/input.css:117:1] + 117 | a { + : ^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:117:1] + 117 | a { + : ^ + `---- + + x SimpleBlock + ,-[$DIR/tests/fixture/style-block/input.css:117:1] + 117 | ,-> a { + 118 | | color: red; + 119 | | + 120 | | .class { + 121 | | color: green; + 122 | | } + 123 | | + 124 | | color: blue; + 125 | `-> } + `---- + + x LBrace + ,-[$DIR/tests/fixture/style-block/input.css:117:1] + 117 | a { + : ^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:118:5] + 118 | color: red; + : ^^^^^^^^^^ + `---- + + x StyleBlock + ,-[$DIR/tests/fixture/style-block/input.css:118:5] + 118 | color: red; + : ^^^^^^^^^^ + `---- + + x Declaration + ,-[$DIR/tests/fixture/style-block/input.css:118:5] + 118 | color: red; + : ^^^^^^^^^^ + `---- + + x DeclarationName + ,-[$DIR/tests/fixture/style-block/input.css:118:5] + 118 | color: red; + : ^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:118:5] + 118 | color: red; + : ^^^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:118:5] + 118 | color: red; + : ^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:118:5] + 118 | color: red; + : ^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:124:5] + 124 | color: blue; + : ^^^^^^^^^^^ + `---- + + x StyleBlock + ,-[$DIR/tests/fixture/style-block/input.css:124:5] + 124 | color: blue; + : ^^^^^^^^^^^ + `---- + + x Declaration + ,-[$DIR/tests/fixture/style-block/input.css:124:5] + 124 | color: blue; + : ^^^^^^^^^^^ + `---- + + x DeclarationName + ,-[$DIR/tests/fixture/style-block/input.css:124:5] + 124 | color: blue; + : ^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:124:5] + 124 | color: blue; + : ^^^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:124:5] + 124 | color: blue; + : ^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:124:5] + 124 | color: blue; + : ^^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:120:5] + 120 | ,-> .class { + 121 | | color: green; + 122 | `-> } + `---- + + x StyleBlock + ,-[$DIR/tests/fixture/style-block/input.css:120:5] + 120 | ,-> .class { + 121 | | color: green; + 122 | `-> } + `---- + + x QualifiedRule + ,-[$DIR/tests/fixture/style-block/input.css:120:5] + 120 | ,-> .class { + 121 | | color: green; + 122 | `-> } + `---- + + x RelativeSelectorList + ,-[$DIR/tests/fixture/style-block/input.css:120:5] + 120 | .class { + : ^^^^^^ + `---- + + x RelativeSelector + ,-[$DIR/tests/fixture/style-block/input.css:120:5] + 120 | .class { + : ^^^^^^ + `---- + + x ComplexSelector + ,-[$DIR/tests/fixture/style-block/input.css:120:5] + 120 | .class { + : ^^^^^^ + `---- + + x CompoundSelector + ,-[$DIR/tests/fixture/style-block/input.css:120:5] + 120 | .class { + : ^^^^^^ + `---- + + x SubclassSelector + ,-[$DIR/tests/fixture/style-block/input.css:120:5] + 120 | .class { + : ^^^^^^ + `---- + + x ClassSelector + ,-[$DIR/tests/fixture/style-block/input.css:120:5] + 120 | .class { + : ^^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:120:5] + 120 | .class { + : ^^^^^ + `---- + + x SimpleBlock + ,-[$DIR/tests/fixture/style-block/input.css:120:5] + 120 | ,-> .class { + 121 | | color: green; + 122 | `-> } + `---- + + x LBrace + ,-[$DIR/tests/fixture/style-block/input.css:120:5] + 120 | .class { + : ^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:121:9] + 121 | color: green; + : ^^^^^^^^^^^^ + `---- + + x StyleBlock + ,-[$DIR/tests/fixture/style-block/input.css:121:9] + 121 | color: green; + : ^^^^^^^^^^^^ + `---- + + x Declaration + ,-[$DIR/tests/fixture/style-block/input.css:121:9] + 121 | color: green; + : ^^^^^^^^^^^^ + `---- + + x DeclarationName + ,-[$DIR/tests/fixture/style-block/input.css:121:9] + 121 | color: green; + : ^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:121:9] + 121 | color: green; + : ^^^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:121:9] + 121 | color: green; + : ^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:121:9] + 121 | color: green; + : ^^^^^ + `---- + + x Rule + ,-[$DIR/tests/fixture/style-block/input.css:127:1] + 127 | ,-> .foo { + 128 | | color: red; + 129 | | + 130 | | + .bar { + 131 | | color: blue; + 132 | | } + 133 | `-> } + `---- + + x QualifiedRule + ,-[$DIR/tests/fixture/style-block/input.css:127:1] + 127 | ,-> .foo { + 128 | | color: red; + 129 | | + 130 | | + .bar { + 131 | | color: blue; + 132 | | } + 133 | `-> } + `---- + + x SelectorList + ,-[$DIR/tests/fixture/style-block/input.css:127:1] + 127 | .foo { + : ^^^^ + `---- + + x ComplexSelector + ,-[$DIR/tests/fixture/style-block/input.css:127:1] + 127 | .foo { + : ^^^^ + `---- + + x CompoundSelector + ,-[$DIR/tests/fixture/style-block/input.css:127:1] + 127 | .foo { + : ^^^^ + `---- + + x SubclassSelector + ,-[$DIR/tests/fixture/style-block/input.css:127:1] + 127 | .foo { + : ^^^^ + `---- + + x ClassSelector + ,-[$DIR/tests/fixture/style-block/input.css:127:1] + 127 | .foo { + : ^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:127:1] + 127 | .foo { + : ^^^ + `---- + + x SimpleBlock + ,-[$DIR/tests/fixture/style-block/input.css:127:1] + 127 | ,-> .foo { + 128 | | color: red; + 129 | | + 130 | | + .bar { + 131 | | color: blue; + 132 | | } + 133 | `-> } + `---- + + x LBrace + ,-[$DIR/tests/fixture/style-block/input.css:127:1] + 127 | .foo { + : ^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:128:5] + 128 | color: red; + : ^^^^^^^^^^ + `---- + + x StyleBlock + ,-[$DIR/tests/fixture/style-block/input.css:128:5] + 128 | color: red; + : ^^^^^^^^^^ + `---- + + x Declaration + ,-[$DIR/tests/fixture/style-block/input.css:128:5] + 128 | color: red; + : ^^^^^^^^^^ + `---- + + x DeclarationName + ,-[$DIR/tests/fixture/style-block/input.css:128:5] + 128 | color: red; + : ^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:128:5] + 128 | color: red; + : ^^^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:128:5] + 128 | color: red; + : ^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:128:5] + 128 | color: red; + : ^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | ,-> + .bar { + 131 | | color: blue; + 132 | `-> } + `---- + + x StyleBlock + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | ,-> + .bar { + 131 | | color: blue; + 132 | `-> } + `---- + + x QualifiedRule + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | ,-> + .bar { + 131 | | color: blue; + 132 | `-> } + `---- + + x RelativeSelectorList + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | + .bar { + : ^^^^^^ + `---- + + x RelativeSelector + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | + .bar { + : ^^^^^^ + `---- + + x Combinator + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | + .bar { + : ^ + `---- + + x ComplexSelector + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | + .bar { + : ^^^^ + `---- + + x CompoundSelector + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | + .bar { + : ^^^^ + `---- + + x SubclassSelector + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | + .bar { + : ^^^^ + `---- + + x ClassSelector + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | + .bar { + : ^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | + .bar { + : ^^^ + `---- + + x SimpleBlock + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | ,-> + .bar { + 131 | | color: blue; + 132 | `-> } + `---- + + x LBrace + ,-[$DIR/tests/fixture/style-block/input.css:130:5] + 130 | + .bar { + : ^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:131:9] + 131 | color: blue; + : ^^^^^^^^^^^ + `---- + + x StyleBlock + ,-[$DIR/tests/fixture/style-block/input.css:131:9] + 131 | color: blue; + : ^^^^^^^^^^^ + `---- + + x Declaration + ,-[$DIR/tests/fixture/style-block/input.css:131:9] + 131 | color: blue; + : ^^^^^^^^^^^ + `---- + + x DeclarationName + ,-[$DIR/tests/fixture/style-block/input.css:131:9] + 131 | color: blue; + : ^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:131:9] + 131 | color: blue; + : ^^^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:131:9] + 131 | color: blue; + : ^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:131:9] + 131 | color: blue; + : ^^^^ + `---- + + x Rule + ,-[$DIR/tests/fixture/style-block/input.css:135:1] + 135 | ,-> article { + 136 | | color: green; + 137 | | & { color: blue; } + 138 | | color: red; + 139 | `-> } + `---- + + x QualifiedRule + ,-[$DIR/tests/fixture/style-block/input.css:135:1] + 135 | ,-> article { + 136 | | color: green; + 137 | | & { color: blue; } + 138 | | color: red; + 139 | `-> } + `---- + + x SelectorList + ,-[$DIR/tests/fixture/style-block/input.css:135:1] + 135 | article { + : ^^^^^^^ + `---- + + x ComplexSelector + ,-[$DIR/tests/fixture/style-block/input.css:135:1] + 135 | article { + : ^^^^^^^ + `---- + + x CompoundSelector + ,-[$DIR/tests/fixture/style-block/input.css:135:1] + 135 | article { + : ^^^^^^^ + `---- + + x TypeSelector + ,-[$DIR/tests/fixture/style-block/input.css:135:1] + 135 | article { + : ^^^^^^^ + `---- + + x TagNameSelector + ,-[$DIR/tests/fixture/style-block/input.css:135:1] + 135 | article { + : ^^^^^^^ + `---- + + x WqName + ,-[$DIR/tests/fixture/style-block/input.css:135:1] + 135 | article { + : ^^^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:135:1] + 135 | article { + : ^^^^^^^ + `---- + + x SimpleBlock + ,-[$DIR/tests/fixture/style-block/input.css:135:1] + 135 | ,-> article { + 136 | | color: green; + 137 | | & { color: blue; } + 138 | | color: red; + 139 | `-> } + `---- + + x LBrace + ,-[$DIR/tests/fixture/style-block/input.css:135:1] + 135 | article { + : ^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:136:5] + 136 | color: green; + : ^^^^^^^^^^^^ + `---- + + x StyleBlock + ,-[$DIR/tests/fixture/style-block/input.css:136:5] + 136 | color: green; + : ^^^^^^^^^^^^ + `---- + + x Declaration + ,-[$DIR/tests/fixture/style-block/input.css:136:5] + 136 | color: green; + : ^^^^^^^^^^^^ + `---- + + x DeclarationName + ,-[$DIR/tests/fixture/style-block/input.css:136:5] + 136 | color: green; + : ^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:136:5] + 136 | color: green; + : ^^^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:136:5] + 136 | color: green; + : ^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:136:5] + 136 | color: green; + : ^^^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:138:5] + 138 | color: red; + : ^^^^^^^^^^ + `---- + + x StyleBlock + ,-[$DIR/tests/fixture/style-block/input.css:138:5] + 138 | color: red; + : ^^^^^^^^^^ + `---- + + x Declaration + ,-[$DIR/tests/fixture/style-block/input.css:138:5] + 138 | color: red; + : ^^^^^^^^^^ + `---- + + x DeclarationName + ,-[$DIR/tests/fixture/style-block/input.css:138:5] + 138 | color: red; + : ^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:138:5] + 138 | color: red; + : ^^^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:138:5] + 138 | color: red; + : ^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:138:5] + 138 | color: red; + : ^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^^^^^^^^^^^^^^^^^^ + `---- + + x StyleBlock + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^^^^^^^^^^^^^^^^^^ + `---- + + x QualifiedRule + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^^^^^^^^^^^^^^^^^^ + `---- + + x RelativeSelectorList + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^ + `---- + + x RelativeSelector + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^ + `---- + + x ComplexSelector + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^ + `---- + + x CompoundSelector + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^ + `---- + + x NestingSelector + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^ + `---- + + x SimpleBlock + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^^^^^^^^^^^^^^^^ + `---- + + x LBrace + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^^^^^^^^^^^ + `---- + + x StyleBlock + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^^^^^^^^^^^ + `---- + + x Declaration + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^^^^^^^^^^^ + `---- + + x DeclarationName + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^^^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/style-block/input.css:137:5] + 137 | & { color: blue; } + : ^^^^ + `---- diff --git a/crates/swc_css_parser/tests/fixture/stylesheet/cdo-and-cdc/input.css b/crates/swc_css_parser/tests/fixture/stylesheet/cdo-and-cdc/input.css new file mode 100644 index 000000000000..a2a788b18f1c --- /dev/null +++ b/crates/swc_css_parser/tests/fixture/stylesheet/cdo-and-cdc/input.css @@ -0,0 +1,7 @@ + a { + color: red; +} diff --git a/crates/swc_css_parser/tests/fixture/stylesheet/cdo-and-cdc/output.json b/crates/swc_css_parser/tests/fixture/stylesheet/cdo-and-cdc/output.json new file mode 100644 index 000000000000..66cce07d9a6e --- /dev/null +++ b/crates/swc_css_parser/tests/fixture/stylesheet/cdo-and-cdc/output.json @@ -0,0 +1,240 @@ +{ + "type": "Stylesheet", + "span": { + "start": 1, + "end": 55, + "ctxt": 0 + }, + "rules": [ + { + "type": "QualifiedRule", + "span": { + "start": 6, + "end": 27, + "ctxt": 0 + }, + "prelude": { + "type": "SelectorList", + "span": { + "start": 6, + "end": 7, + "ctxt": 0 + }, + "children": [ + { + "type": "ComplexSelector", + "span": { + "start": 6, + "end": 7, + "ctxt": 0 + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 6, + "end": 7, + "ctxt": 0 + }, + "nestingSelector": null, + "typeSelector": { + "type": "TagNameSelector", + "span": { + "start": 6, + "end": 7, + "ctxt": 0 + }, + "name": { + "type": "WqName", + "span": { + "start": 6, + "end": 7, + "ctxt": 0 + }, + "prefix": null, + "value": { + "type": "Ident", + "span": { + "start": 6, + "end": 7, + "ctxt": 0 + }, + "value": "a", + "raw": "a" + } + } + }, + "subclassSelectors": [] + } + ] + } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 8, + "end": 27, + "ctxt": 0 + }, + "name": { + "type": "PreservedToken", + "span": { + "start": 8, + "end": 9, + "ctxt": 0 + }, + "token": "LBrace" + }, + "value": [ + { + "type": "Declaration", + "span": { + "start": 14, + "end": 24, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 14, + "end": 19, + "ctxt": 0 + }, + "value": "color", + "raw": "color" + }, + "value": [ + { + "type": "Ident", + "span": { + "start": 21, + "end": 24, + "ctxt": 0 + }, + "value": "red", + "raw": "red" + } + ], + "important": null + } + ] + } + }, + { + "type": "QualifiedRule", + "span": { + "start": 33, + "end": 54, + "ctxt": 0 + }, + "prelude": { + "type": "SelectorList", + "span": { + "start": 33, + "end": 34, + "ctxt": 0 + }, + "children": [ + { + "type": "ComplexSelector", + "span": { + "start": 33, + "end": 34, + "ctxt": 0 + }, + "children": [ + { + "type": "CompoundSelector", + "span": { + "start": 33, + "end": 34, + "ctxt": 0 + }, + "nestingSelector": null, + "typeSelector": { + "type": "TagNameSelector", + "span": { + "start": 33, + "end": 34, + "ctxt": 0 + }, + "name": { + "type": "WqName", + "span": { + "start": 33, + "end": 34, + "ctxt": 0 + }, + "prefix": null, + "value": { + "type": "Ident", + "span": { + "start": 33, + "end": 34, + "ctxt": 0 + }, + "value": "a", + "raw": "a" + } + } + }, + "subclassSelectors": [] + } + ] + } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 35, + "end": 54, + "ctxt": 0 + }, + "name": { + "type": "PreservedToken", + "span": { + "start": 35, + "end": 36, + "ctxt": 0 + }, + "token": "LBrace" + }, + "value": [ + { + "type": "Declaration", + "span": { + "start": 41, + "end": 51, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 41, + "end": 46, + "ctxt": 0 + }, + "value": "color", + "raw": "color" + }, + "value": [ + { + "type": "Ident", + "span": { + "start": 48, + "end": 51, + "ctxt": 0 + }, + "value": "red", + "raw": "red" + } + ], + "important": null + } + ] + } + } + ] +} diff --git a/crates/swc_css_parser/tests/fixture/stylesheet/cdo-and-cdc/span.rust-debug b/crates/swc_css_parser/tests/fixture/stylesheet/cdo-and-cdc/span.rust-debug new file mode 100644 index 000000000000..1697926aab61 --- /dev/null +++ b/crates/swc_css_parser/tests/fixture/stylesheet/cdo-and-cdc/span.rust-debug @@ -0,0 +1,233 @@ + + x Stylesheet + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:1:1] + 1 | ,-> a { + 6 | | color: red; + 7 | `-> } + `---- + + x Rule + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:1:1] + 1 | ,-> a { + 6 | | color: red; + 7 | `-> } + `---- + + x QualifiedRule + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:5:1] + 5 | ,-> --> a { + 6 | | color: red; + 7 | `-> } + `---- + + x SelectorList + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:5:1] + 5 | --> a { + : ^ + `---- + + x ComplexSelector + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:5:1] + 5 | --> a { + : ^ + `---- + + x CompoundSelector + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:5:1] + 5 | --> a { + : ^ + `---- + + x TypeSelector + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:5:1] + 5 | --> a { + : ^ + `---- + + x TagNameSelector + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:5:1] + 5 | --> a { + : ^ + `---- + + x WqName + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:5:1] + 5 | --> a { + : ^ + `---- + + x Ident + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:5:1] + 5 | --> a { + : ^ + `---- + + x SimpleBlock + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:5:1] + 5 | ,-> --> a { + 6 | | color: red; + 7 | `-> } + `---- + + x LBrace + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:5:1] + 5 | --> a { + : ^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:6:5] + 6 | color: red; + : ^^^^^^^^^^ + `---- + + x StyleBlock + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:6:5] + 6 | color: red; + : ^^^^^^^^^^ + `---- + + x Declaration + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:6:5] + 6 | color: red; + : ^^^^^^^^^^ + `---- + + x DeclarationName + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:6:5] + 6 | color: red; + : ^^^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:6:5] + 6 | color: red; + : ^^^^^ + `---- + + x ComponentValue + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:6:5] + 6 | color: red; + : ^^^ + `---- + + x Ident + ,-[$DIR/tests/fixture/stylesheet/cdo-and-cdc/input.css:6:5] + 6 | color: red; + : ^^^ + `---- diff --git a/crates/swc_css_parser/tests/recovery/at-rule/font-face/output.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/font-face/output.swc-stderr index 29f8c9bce3c5..8655c556acd1 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/font-face/output.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/font-face/output.swc-stderr @@ -23,13 +23,13 @@ : ^^^ `---- - x Expected whitespace, semicolon, EOF, at-keyword or ident token + x Expected whitespace, ';', '@', ident or EOF ,-[$DIR/tests/recovery/at-rule/font-face/input.css:10:5] 10 | 123 : ^^^ `---- - x Expected whitespace, semicolon, EOF, at-keyword or ident token + x Expected whitespace, ';', '@', ident or EOF ,-[$DIR/tests/recovery/at-rule/font-face/input.css:14:5] 14 | 123; : ^^^ diff --git a/crates/swc_css_parser/tests/recovery/cdo-and-cdc/input.css b/crates/swc_css_parser/tests/recovery/cdo-and-cdc/input.css index dc6bb6562d83..9ede63d0b3cb 100644 --- a/crates/swc_css_parser/tests/recovery/cdo-and-cdc/input.css +++ b/crates/swc_css_parser/tests/recovery/cdo-and-cdc/input.css @@ -30,3 +30,9 @@ test color: blue; } + +a { + ; + : ^ + `---- + x Invalid selector ,-[$DIR/tests/recovery/cdo-and-cdc/input.css:1:1] 1 | : ^^^ `---- + x Invalid selector + ,-[$DIR/tests/recovery/cdo-and-cdc/input.css:35:5] + 35 | - 19 | | - 20 | `-> color: blue; - `---- - - x Unexpected end of file, but expected '{' - ,-[$DIR/tests/recovery/cdo-and-cdc/input.css:25:1] - 25 | ,-> ; - `---- - x Unexpected token ,-[$DIR/tests/recovery/cdo-and-cdc/input.css:5:1] 5 | ; 30 | | 31 | | color: blue; - 32 | `-> } + 32 | | } + 33 | | + 34 | | a { + 35 | |