diff --git a/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery-1/input.css b/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery-1/input.css new file mode 100644 index 000000000000..45663b488a74 --- /dev/null +++ b/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery-1/input.css @@ -0,0 +1,7 @@ +a {}; + +b {}; + +c { } + +c {color: red; } diff --git a/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery-1/output.css b/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery-1/output.css new file mode 100644 index 000000000000..31594f07a56c --- /dev/null +++ b/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery-1/output.css @@ -0,0 +1,10 @@ +a {} +; + +b {} +; + +c {} +c { + color: red; +} diff --git a/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery-1/output.min.css b/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery-1/output.min.css new file mode 100644 index 000000000000..dd5a25ce57b4 --- /dev/null +++ b/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery-1/output.min.css @@ -0,0 +1,5 @@ +a{}; + +b {}; + +c {}c{color:red} diff --git a/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery/input.css b/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery/input.css index a5f49a31ce01..282a4d1cfa2b 100644 --- a/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery/input.css +++ b/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery/input.css @@ -17,8 +17,6 @@ $bad foo { color: red } $bad: rule; -/* TODO: FIX ME */ -/* a {}; b {}; */ a { div.major { color: blue } color: red } a { div:hover { color: blue } color: red } diff --git a/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery/output.css b/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery/output.css index 5dc1bedfd5d7..61b4504646e3 100644 --- a/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery/output.css +++ b/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery/output.css @@ -18,9 +18,10 @@ $bad foo { color: red; } $bad: rule; + + a { - div.major { color: blue } -color: red } + div.major { color: blue } color: red } a { div: hover {color:blue} color:red; } diff --git a/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery/output.min.css b/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery/output.min.css index d44a2ea3edb0..97b9cc7cae2c 100644 --- a/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery/output.min.css +++ b/crates/swc_css_codegen/tests/fixture/qualified_rule/recovery/output.min.css @@ -1,2 +1,4 @@ -{}{color:red}#broken# {color:red}$bad{color:red}$bad {color:red}$bad foo{color:red}$bad foo {color:red}$bad: rule;a{div.major { color: blue }color: red } -a {div:hover{color:blue}color:red}a{div:hover{color:blue};color:red} +{}{color:red}#broken# {color:red}$bad{color:red}$bad {color:red}$bad foo{color:red}$bad foo {color:red}$bad: rule; + + +a {div.major { color: blue } color: red }a{div:hover{color:blue}color:red}a{div:hover{color:blue};color:red} diff --git a/crates/swc_css_minifier/tests/fixture/compress-at-rule/layer/input.css b/crates/swc_css_minifier/tests/fixture/compress-at-rule/layer/input.css index a36428125cdd..106ec1d881c3 100644 --- a/crates/swc_css_minifier/tests/fixture/compress-at-rule/layer/input.css +++ b/crates/swc_css_minifier/tests/fixture/compress-at-rule/layer/input.css @@ -31,18 +31,30 @@ @layer { @layer foo { - color: red; + .class { + color: red; + } } @layer foo { - color: red; + .class { + color: red; + } } } @layer { - @layer foo { color: red; } + @layer foo { + .class { + color: red; + } + } } @layer { - @layer foo { color: red; } + @layer foo { + .class { + color: red; + } + } } @layer framework { diff --git a/crates/swc_css_minifier/tests/fixture/compress-at-rule/layer/output.min.css b/crates/swc_css_minifier/tests/fixture/compress-at-rule/layer/output.min.css index 1f8cdc674dc5..a7c924a8a9ec 100644 --- a/crates/swc_css_minifier/tests/fixture/compress-at-rule/layer/output.min.css +++ b/crates/swc_css_minifier/tests/fixture/compress-at-rule/layer/output.min.css @@ -1 +1 @@ -@layer default,theme,components;@layer foo.bar;@layer foo.bar,baz;@layer a{@layer b{div{color:yellow;margin:0}}}@layer framework{@layer base{p{margin-block:.75em}}@layer theme{p{color:#222}}}@layer framework.theme{blockquote{color:rebeccapurple}}@layer{@layer foo{color: red;color: red;color: red;color: red;}}@layer framework{h1,h2{color:maroon;background:white}@media(prefers-color-scheme:dark){h1,h2{color:red;background:black}}}@layer foo{.foo{color:red;background:#fff}.baz{color:#fff}} +@layer default,theme,components;@layer foo.bar;@layer foo.bar,baz;@layer a{@layer b{div{color:yellow;margin:0}}}@layer framework{@layer base{p{margin-block:.75em}}@layer theme{p{color:#222}}}@layer framework.theme{blockquote{color:rebeccapurple}}@layer{@layer foo{.class{color:red}}}@layer framework{h1,h2{color:maroon;background:white}@media(prefers-color-scheme:dark){h1,h2{color:red;background:black}}}@layer foo{.foo{color:red;background:#fff}.baz{color:#fff}} diff --git a/crates/swc_css_parser/src/parser/at_rules/mod.rs b/crates/swc_css_parser/src/parser/at_rules/mod.rs index 4a4ff825a371..0418646cd822 100644 --- a/crates/swc_css_parser/src/parser/at_rules/mod.rs +++ b/crates/swc_css_parser/src/parser/at_rules/mod.rs @@ -171,7 +171,7 @@ where parser.input.skip_ws(); let prelude = if is!(parser, Ident) { - let mut name_list = vec![]; + let mut name_list: Vec = vec![]; while is!(parser, Ident) { name_list.push(parser.parse()?); @@ -185,23 +185,26 @@ where } } - match name_list.len() == 1 { - // Block - true => Some(AtRulePrelude::LayerPrelude(LayerPrelude::Name( - name_list.remove(0), - ))), - // Statement - false => { - let first = name_list[0].span; - let last = name_list[name_list.len() - 1].span; - - Some(AtRulePrelude::LayerPrelude(LayerPrelude::NameList( - LayerNameList { - name_list, - span: Span::new(first.lo, last.hi, Default::default()), - }, - ))) + if is!(parser, ";") { + let first = name_list[0].span; + let last = name_list[name_list.len() - 1].span; + + Some(AtRulePrelude::LayerPrelude(LayerPrelude::NameList( + LayerNameList { + name_list, + span: Span::new(first.lo, last.hi, Default::default()), + }, + ))) + } else { + if name_list.len() > 1 { + let span = parser.input.cur_span(); + + return Err(Error::new(span, ErrorKind::Expected("';' token"))); } + + Some(AtRulePrelude::LayerPrelude(LayerPrelude::Name( + name_list.remove(0), + ))) } } else { None diff --git a/crates/swc_css_parser/src/parser/input.rs b/crates/swc_css_parser/src/parser/input.rs index 2aed4e43eda8..68173aa6c9ae 100644 --- a/crates/swc_css_parser/src/parser/input.rs +++ b/crates/swc_css_parser/src/parser/input.rs @@ -1,7 +1,8 @@ use std::{fmt::Debug, mem::take}; -use swc_common::{BytePos, Span, SyntaxContext}; -use swc_css_ast::{Token, TokenAndSpan}; +use swc_atoms::JsWord; +use swc_common::{BytePos, Span, Spanned, SyntaxContext}; +use swc_css_ast::{ComponentValue, ListOfComponentValues, Token, TokenAndSpan}; use super::PResult; use crate::error::{Error, ErrorKind}; @@ -264,3 +265,281 @@ impl<'a> Iterator for TokensInput<'a> { Some(token_and_span) } } + +#[derive(Debug)] +pub struct ListOfComponentValuesState { + idx: Vec, + balance_stack: Vec, +} + +#[derive(Debug)] +pub struct ListOfComponentValuesInput<'a> { + list: &'a ListOfComponentValues, + idx: Vec, + balance_stack: Vec, +} + +#[derive(Debug, Clone)] +#[allow(clippy::enum_variant_names)] +enum BalanceToken { + /// `]` + RBracket, + + /// `)` + RParen, + + /// `}` + RBrace, +} + +#[derive(Debug)] +pub enum TokenOrBlock { + Token(TokenAndSpan), + Function(Span, JsWord, JsWord), + LBracket(Span), + LParen(Span), + LBrace(Span), + RParen(Span), + RBracket(Span), + RBrace(Span), +} + +impl<'a> ListOfComponentValuesInput<'a> { + pub fn new(list: &'a ListOfComponentValues) -> Self { + let mut idx = Vec::with_capacity(16); + + idx.push(0); + + ListOfComponentValuesInput { + list, + idx, + balance_stack: Vec::with_capacity(16), + } + } + + fn get_component_value( + &mut self, + list: &'a [ComponentValue], + deep: usize, + ) -> Option { + let index = match self.idx.get(deep) { + Some(index) => index, + _ => return None, + }; + + match list.get(*index) { + Some(ComponentValue::PreservedToken(token_and_span)) => { + Some(TokenOrBlock::Token(token_and_span.clone())) + } + Some(ComponentValue::Function(function)) => { + if self.idx.len() - 1 == deep { + return Some(TokenOrBlock::Function( + Span::new( + function.span_lo(), + function.name.span_hi() + BytePos(1), + Default::default(), + ), + function.name.value.clone(), + match &function.name.raw { + Some(raw) => raw.clone(), + _ => function.name.value.clone(), + }, + )); + } + + let res = self.get_component_value(&function.value, deep + 1); + + if res.is_none() { + return Some(TokenOrBlock::RParen(Span::new( + function.span_hi() - BytePos(1), + function.span_hi(), + Default::default(), + ))); + } + + res + } + Some(ComponentValue::SimpleBlock(simple_block)) => { + if self.idx.len() - 1 == deep { + let close = match simple_block.name.token { + Token::LBracket => TokenOrBlock::LBracket(simple_block.name.span), + Token::LParen => TokenOrBlock::LParen(simple_block.name.span), + Token::LBrace => TokenOrBlock::LBrace(simple_block.name.span), + _ => { + unreachable!(); + } + }; + + return Some(close); + } + + let res = self.get_component_value(&simple_block.value, deep + 1); + + if res.is_none() { + let span = Span::new( + simple_block.span_hi() - BytePos(1), + simple_block.span_hi(), + Default::default(), + ); + let close = match simple_block.name.token { + Token::LBracket => TokenOrBlock::RBracket(span), + Token::LParen => TokenOrBlock::RParen(span), + Token::LBrace => TokenOrBlock::RBrace(span), + _ => { + unreachable!(); + } + }; + + return Some(close); + } + + res + } + None => return None, + _ => { + unreachable!("Not allowed in the list of component values") + } + } + } + + fn cur(&mut self) -> PResult { + let token_and_span = match self.get_component_value(&self.list.children, 0) { + Some(token_or_block) => match token_or_block { + TokenOrBlock::Token(token_and_span) => token_and_span, + TokenOrBlock::Function(span, value, raw) => TokenAndSpan { + span, + token: Token::Function { value, raw }, + }, + TokenOrBlock::LBracket(span) => TokenAndSpan { + span, + token: Token::LBracket, + }, + TokenOrBlock::LBrace(span) => TokenAndSpan { + span, + token: Token::LBrace, + }, + TokenOrBlock::LParen(span) => TokenAndSpan { + span, + token: Token::LParen, + }, + TokenOrBlock::RBracket(span) => TokenAndSpan { + span, + token: Token::RBracket, + }, + TokenOrBlock::RBrace(span) => TokenAndSpan { + span, + token: Token::RBrace, + }, + TokenOrBlock::RParen(span) => TokenAndSpan { + span, + token: Token::RParen, + }, + }, + None => { + let bp = self.list.span.hi; + let span = Span::new(bp, bp, SyntaxContext::empty()); + + return Err(Error::new(span, ErrorKind::Eof)); + } + }; + + Ok(token_and_span) + } +} + +impl<'a> ParserInput for ListOfComponentValuesInput<'a> { + type State = ListOfComponentValuesState; + + fn start_pos(&mut self) -> BytePos { + self.list.span.lo + } + + fn state(&mut self) -> Self::State { + ListOfComponentValuesState { + idx: self.idx.clone(), + balance_stack: self.balance_stack.clone(), + } + } + + fn reset(&mut self, state: &Self::State) { + self.idx = state.idx.clone(); + self.balance_stack = state.balance_stack.clone(); + } + + fn take_errors(&mut self) -> Vec { + vec![] + } + + fn skip_ws(&mut self) -> Option { + let mut last_pos = None; + + while let Ok(TokenAndSpan { + token: tok!(" "), + span, + }) = self.cur() + { + last_pos = Some(span.hi); + + if let Some(idx) = self.idx.last_mut() { + *idx += 1; + } + } + + last_pos + } +} + +impl<'a> Iterator for ListOfComponentValuesInput<'a> { + type Item = TokenAndSpan; + + fn next(&mut self) -> Option { + let token_and_span = match self.cur() { + Ok(token_and_span) => token_and_span, + _ => return None, + }; + + match &token_and_span.token { + Token::Function { .. } | Token::LParen | Token::LBracket | Token::LBrace => { + self.idx.push(0); + + let balance = match &token_and_span.token { + Token::Function { .. } | Token::LParen => BalanceToken::RParen, + Token::LBracket => BalanceToken::RBracket, + Token::LBrace => BalanceToken::RBrace, + _ => { + unreachable!(); + } + }; + + self.balance_stack.push(balance); + } + token => { + match token { + Token::RBrace | Token::RBracket | Token::RParen => { + if let Some(last) = self.balance_stack.last() { + match (token, last) { + (Token::RBrace, BalanceToken::RBrace) + | (Token::RParen, BalanceToken::RParen) + | (Token::RBracket, BalanceToken::RBracket) => { + self.balance_stack.pop(); + self.idx.pop(); + } + _ => {} + } + } + } + _ => {} + } + + let index = match self.idx.last_mut() { + Some(index) => index, + _ => return None, + }; + + *index += 1; + } + } + + Some(token_and_span) + } +} diff --git a/crates/swc_css_parser/src/parser/selectors/mod.rs b/crates/swc_css_parser/src/parser/selectors/mod.rs index a1421bcc5756..f2eefb6d1114 100644 --- a/crates/swc_css_parser/src/parser/selectors/mod.rs +++ b/crates/swc_css_parser/src/parser/selectors/mod.rs @@ -957,6 +957,8 @@ where } "nth-child" | "nth-last-child" | "nth-of-type" | "nth-last-of-type" | "nth-col" | "nth-last-col" => { + self.input.skip_ws(); + let an_plus_b = self.parse()?; children.push(PseudoClassSelectorChildren::AnPlusB(an_plus_b)); @@ -1168,8 +1170,6 @@ where I: ParserInput, { fn parse(&mut self) -> PResult { - self.input.skip_ws(); - let span = self.input.cur_span(); match cur!(self) { diff --git a/crates/swc_css_parser/src/parser/syntax/mod.rs b/crates/swc_css_parser/src/parser/syntax/mod.rs index e2681c00d0a3..6b2fa6a21290 100644 --- a/crates/swc_css_parser/src/parser/syntax/mod.rs +++ b/crates/swc_css_parser/src/parser/syntax/mod.rs @@ -121,19 +121,62 @@ where I: ParserInput, { fn parse(&mut self) -> PResult { + let create_prelude = |p: &mut Parser, + list: Vec| + -> PResult { + let list_of_component_values = p.create_locv(list); + + match p.parse_according_to_grammar::(&list_of_component_values) { + Ok(selector_list) => { + if p.ctx.is_trying_legacy_nesting { + let selector_list = + p.legacy_nested_selector_list_to_modern_selector_list(selector_list)?; + + Ok(QualifiedRulePrelude::SelectorList(selector_list)) + } else { + Ok(QualifiedRulePrelude::SelectorList(selector_list)) + } + } + Err(err) => { + if p.ctx.is_trying_legacy_nesting { + match p.parse_according_to_grammar::( + &list_of_component_values, + ) { + Ok(relative_selector_list) => { + let selector_list = p + .legacy_relative_selector_list_to_modern_selector_list( + relative_selector_list, + )?; + + Ok(QualifiedRulePrelude::SelectorList(selector_list)) + } + _ => Err(err), + } + } else { + p.errors.push(err); + + let list_of_component_values = p + .parse_according_to_grammar::( + &list_of_component_values, + )?; + + Ok(QualifiedRulePrelude::ListOfComponentValues( + list_of_component_values, + )) + } + } + } + }; + let span = self.input.cur_span(); // Create a new qualified rule with its prelude initially set to an empty list, // and its value initially set to nothing. - let mut prelude = QualifiedRulePrelude::ListOfComponentValues(ListOfComponentValues { - span: Default::default(), - children: vec![], - }); + let mut prelude = vec![]; // Repeatedly consume the next input token: loop { // // This is a parse error. Return nothing. - // But we return for error recovery blocks if is!(self, EOF) { let span = self.input.cur_span(); @@ -145,85 +188,38 @@ where // Consume a simple block and assign it to the qualified rule’s block. Return the // qualified rule. tok!("{") => { - let ctx = Ctx { - block_contents_grammar: BlockContentsGrammar::StyleBlock, - ..self.ctx - }; - let block = self.with_ctx(ctx).parse_as::()?; + let mut block = self + .with_ctx(Ctx { + block_contents_grammar: BlockContentsGrammar::NoGrammar, + ..self.ctx + }) + .parse_as::()?; + + block.value = self + .parse_according_to_grammar::>( + &self.create_locv(block.value), + )? + .into_iter() + .map(ComponentValue::StyleBlock) + .collect(); return Ok(QualifiedRule { span: span!(self, span.lo), - prelude, + prelude: create_prelude(self, prelude)?, block, }); } // Reconsume the current input token. Consume a component value. Append the returned // value to the qualified rule’s prelude. _ => { - let state = self.input.state(); - let selector_list: PResult = self.parse(); - - prelude = match selector_list { - Ok(mut selector_list) => { - if self.ctx.is_trying_legacy_nesting { - selector_list = self - .legacy_nested_selector_list_to_modern_selector_list( - selector_list, - )?; - } - - QualifiedRulePrelude::SelectorList(selector_list) - } - Err(err) => { - if self.ctx.is_trying_legacy_nesting { - self.input.reset(&state); - - let relative_selector_list: PResult = - self.parse(); - - match relative_selector_list { - Ok(relative_selector_list) => { - let selector_list = self - .legacy_relative_selector_list_to_modern_selector_list( - relative_selector_list, - )?; - - QualifiedRulePrelude::SelectorList(selector_list) - } - _ => { - return Err(err); - } - } - } else { - self.errors.push(err); - self.input.reset(&state); - - let span = self.input.cur_span(); - let mut children = vec![]; - - while !is_one_of!(self, EOF, "{") { - if is!(self, ";") { - let span = self.input.cur_span(); - - return Err(Error::new( - span, - ErrorKind::UnexpectedChar(';'), - )); - } - - if let Some(token_and_span) = self.input.bump() { - children - .push(ComponentValue::PreservedToken(token_and_span)); - } - } + let component_value = self + .with_ctx(Ctx { + block_contents_grammar: BlockContentsGrammar::NoGrammar, + ..self.ctx + }) + .parse_as::()?; - QualifiedRulePrelude::ListOfComponentValues(ListOfComponentValues { - span: span!(self, span.lo), - children, - }) - } - } - }; + prelude.push(component_value); } } } @@ -262,7 +258,14 @@ where // Reconsume the current input token. Consume an at-rule, and append the result to // rules. tok!("@") => { - rules.push(StyleBlock::AtRule(self.parse()?)); + let ctx = Ctx { + block_contents_grammar: BlockContentsGrammar::StyleBlock, + ..self.ctx + }; + + rules.push(StyleBlock::AtRule(Box::new( + self.with_ctx(ctx).parse_as::()?, + ))); } // // Initialize a temporary list initially filled with the current input token. As @@ -301,7 +304,7 @@ where let span = self.input.cur_span(); let mut children = vec![]; - while !is_one_of!(self, EOF, "}") { + while !is_one_of!(self, EOF) { if let Some(token_and_span) = self.input.bump() { children.push(ComponentValue::PreservedToken(token_and_span)); } @@ -933,3 +936,32 @@ where }) } } + +impl Parse for Parser +where + I: ParserInput, +{ + fn parse(&mut self) -> PResult { + let span = self.input.cur_span(); + let ctx = Ctx { + block_contents_grammar: BlockContentsGrammar::NoGrammar, + ..self.ctx + }; + let mut children = vec![]; + + loop { + if is!(self, EOF) { + break; + } + + let components_value = self.with_ctx(ctx).parse_as::()?; + + children.push(components_value); + } + + Ok(ListOfComponentValues { + span: span!(self, span.lo), + children, + }) + } +} diff --git a/crates/swc_css_parser/src/parser/util.rs b/crates/swc_css_parser/src/parser/util.rs index 9425484a60bd..26677edcad78 100644 --- a/crates/swc_css_parser/src/parser/util.rs +++ b/crates/swc_css_parser/src/parser/util.rs @@ -1,9 +1,10 @@ use std::ops::{Deref, DerefMut}; -use swc_common::DUMMY_SP; +use swc_common::{Span, Spanned, SyntaxContext, DUMMY_SP}; use swc_css_ast::*; use super::{input::ParserInput, Ctx, PResult, Parse, Parser}; +use crate::parser::input::ListOfComponentValuesInput; impl Parser where @@ -13,7 +14,9 @@ where #[inline] pub(super) fn with_ctx(&mut self, ctx: Ctx) -> WithCtx { let orig_ctx = self.ctx; + self.ctx = ctx; + WithCtx { orig_ctx, inner: self, @@ -28,6 +31,33 @@ where self.parse() } + pub(super) fn create_locv(&self, children: Vec) -> ListOfComponentValues { + let span = match (children.first(), children.last()) { + (Some(first), Some(last)) => { + Span::new(first.span_lo(), last.span_hi(), SyntaxContext::empty()) + } + _ => DUMMY_SP, + }; + + ListOfComponentValues { span, children } + } + + pub(super) fn parse_according_to_grammar<'a, T>( + &mut self, + list_of_component_values: &'a ListOfComponentValues, + ) -> PResult + where + Parser>: Parse, + { + let lexer = ListOfComponentValuesInput::new(list_of_component_values); + let mut parser = Parser::new(lexer, self.config); + let res = parser.with_ctx(self.ctx).parse_as(); + + self.errors.extend(parser.take_errors()); + + res + } + pub(super) fn legacy_nested_selector_list_to_modern_selector_list( &mut self, mut selector_list: SelectorList, 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 2c9dad53613f..823adcd697b5 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 @@ -19,6 +19,10 @@ where // The production matches any sequence of one or more // tokens, so long as the sequence does not contain ... loop { + if is!(self, EOF) { + break; + } + match cur!(self) { // ... , , tok!("bad-string") | tok!("bad-url") => { @@ -95,6 +99,10 @@ where // The production matches any sequence of one or more tokens, // so long as the sequence ... loop { + if is!(self, EOF) { + break; + } + match cur!(self) { // ... , , tok!("bad-string") | tok!("bad-url") => { diff --git a/crates/swc_css_parser/tests/fixture/value/custom-property/output.json b/crates/swc_css_parser/tests/fixture/value/custom-property/output.json index ed47d2b1b077..00bef82f08c6 100644 --- a/crates/swc_css_parser/tests/fixture/value/custom-property/output.json +++ b/crates/swc_css_parser/tests/fixture/value/custom-property/output.json @@ -3146,7 +3146,7 @@ "type": "Declaration", "span": { "start": 1242, - "end": 1250, + "end": 1249, "ctxt": 0 }, "name": { @@ -3244,7 +3244,7 @@ "type": "Declaration", "span": { "start": 1263, - "end": 1272, + "end": 1271, "ctxt": 0 }, "name": { diff --git a/crates/swc_css_parser/tests/fixture/value/custom-property/span.rust-debug b/crates/swc_css_parser/tests/fixture/value/custom-property/span.rust-debug index cc0fcaa86ba5..c8e50b273ba7 100644 --- a/crates/swc_css_parser/tests/fixture/value/custom-property/span.rust-debug +++ b/crates/swc_css_parser/tests/fixture/value/custom-property/span.rust-debug @@ -3779,19 +3779,19 @@ x ComponentValue ,-[$DIR/tests/fixture/value/custom-property/input.css:60:1] 60 | :root {--foo: } - : ^^^^^^^^ + : ^^^^^^^ `---- x StyleBlock ,-[$DIR/tests/fixture/value/custom-property/input.css:60:1] 60 | :root {--foo: } - : ^^^^^^^^ + : ^^^^^^^ `---- x Declaration ,-[$DIR/tests/fixture/value/custom-property/input.css:60:1] 60 | :root {--foo: } - : ^^^^^^^^ + : ^^^^^^^ `---- x DeclarationName @@ -3871,20 +3871,23 @@ x ComponentValue ,-[$DIR/tests/fixture/value/custom-property/input.css:62:5] - 62 | ,-> --foo: - 63 | `-> } + 62 | --foo: + : ^^^^^^^^ + 63 | } `---- x StyleBlock ,-[$DIR/tests/fixture/value/custom-property/input.css:62:5] - 62 | ,-> --foo: - 63 | `-> } + 62 | --foo: + : ^^^^^^^^ + 63 | } `---- x Declaration ,-[$DIR/tests/fixture/value/custom-property/input.css:62:5] - 62 | ,-> --foo: - 63 | `-> } + 62 | --foo: + : ^^^^^^^^ + 63 | } `---- x DeclarationName diff --git a/crates/swc_css_parser/tests/recovery/at-rule/extra-semi/output.json b/crates/swc_css_parser/tests/recovery/at-rule/extra-semi/output.json index 2afe01f36f75..58a5110e17c3 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/extra-semi/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/extra-semi/output.json @@ -2,7 +2,7 @@ "type": "Stylesheet", "span": { "start": 1, - "end": 45, + "end": 47, "ctxt": 0 }, "rules": [ @@ -47,76 +47,92 @@ "block": null }, { - "type": "ListOfComponentValues", + "type": "QualifiedRule", "span": { "start": 17, - "end": 44, + "end": 46, "ctxt": 0 }, - "children": [ - { - "type": "PreservedToken", - "span": { - "start": 17, - "end": 18, - "ctxt": 0 - }, - "token": "Semi" + "prelude": { + "type": "ListOfComponentValues", + "span": { + "start": 17, + "end": 27, + "ctxt": 0 }, - { - "type": "PreservedToken", - "span": { - "start": 18, - "end": 20, - "ctxt": 0 + "children": [ + { + "type": "PreservedToken", + "span": { + "start": 17, + "end": 18, + "ctxt": 0 + }, + "token": "Semi" }, - "token": { - "WhiteSpace": { - "value": "\n\n" + { + "type": "PreservedToken", + "span": { + "start": 18, + "end": 20, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": "\n\n" + } } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 20, - "end": 21, - "ctxt": 0 }, - "token": { - "Delim": { - "value": "." + { + "type": "PreservedToken", + "span": { + "start": 20, + "end": 21, + "ctxt": 0 + }, + "token": { + "Delim": { + "value": "." + } } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 21, - "end": 26, - "ctxt": 0 }, - "token": { - "Ident": { - "value": "color", - "raw": "color" + { + "type": "PreservedToken", + "span": { + "start": 21, + "end": 26, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "color", + "raw": "color" + } } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 26, - "end": 27, - "ctxt": 0 }, - "token": { - "WhiteSpace": { - "value": " " + { + "type": "PreservedToken", + "span": { + "start": 26, + "end": 27, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": " " + } } } + ] + }, + "block": { + "type": "SimpleBlock", + "span": { + "start": 27, + "end": 46, + "ctxt": 0 }, - { + "name": { "type": "PreservedToken", "span": { "start": 27, @@ -125,79 +141,40 @@ }, "token": "LBrace" }, - { - "type": "PreservedToken", - "span": { - "start": 28, - "end": 33, - "ctxt": 0 - }, - "token": { - "WhiteSpace": { - "value": "\n " - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 33, - "end": 38, - "ctxt": 0 - }, - "token": { - "Ident": { + "value": [ + { + "type": "Declaration", + "span": { + "start": 33, + "end": 43, + "ctxt": 0 + }, + "name": { + "type": "Ident", + "span": { + "start": 33, + "end": 38, + "ctxt": 0 + }, "value": "color", "raw": "color" - } + }, + "value": [ + { + "type": "Ident", + "span": { + "start": 40, + "end": 43, + "ctxt": 0 + }, + "value": "red", + "raw": "red" + } + ], + "important": null } - }, - { - "type": "PreservedToken", - "span": { - "start": 38, - "end": 39, - "ctxt": 0 - }, - "token": "Colon" - }, - { - "type": "PreservedToken", - "span": { - "start": 39, - "end": 40, - "ctxt": 0 - }, - "token": { - "WhiteSpace": { - "value": " " - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 40, - "end": 43, - "ctxt": 0 - }, - "token": { - "Ident": { - "value": "red", - "raw": "red" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 43, - "end": 44, - "ctxt": 0 - }, - "token": "Semi" - } - ] + ] + } } ] } diff --git a/crates/swc_css_parser/tests/recovery/at-rule/extra-semi/output.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/extra-semi/output.swc-stderr index 5a5fc87dc88f..c2c03bb778bd 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/extra-semi/output.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/extra-semi/output.swc-stderr @@ -4,9 +4,3 @@ 1 | @import "x.css";; : ^ `---- - - x Unexpected character `';'` - ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:1:1] - 1 | @import "x.css";; - : ^ - `---- diff --git a/crates/swc_css_parser/tests/recovery/at-rule/extra-semi/span.rust-debug b/crates/swc_css_parser/tests/recovery/at-rule/extra-semi/span.rust-debug index 3c0d9708a994..f56584674cd1 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/extra-semi/span.rust-debug +++ b/crates/swc_css_parser/tests/recovery/at-rule/extra-semi/span.rust-debug @@ -4,8 +4,8 @@ 1 | ,-> @import "x.css";; 2 | | 3 | | .color { - 4 | `-> color: red; - 5 | } + 4 | | color: red; + 5 | `-> } `---- x Rule @@ -43,7 +43,17 @@ 1 | ,-> @import "x.css";; 2 | | 3 | | .color { - 4 | `-> color: red; + 4 | | color: red; + 5 | `-> } + `---- + + x QualifiedRule + ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:1:1] + 1 | ,-> @import "x.css";; + 2 | | + 3 | | .color { + 4 | | color: red; + 5 | `-> } `---- x ComponentValue @@ -110,10 +120,11 @@ : ^ `---- - x ComponentValue + x SimpleBlock ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:3:1] - 3 | .color { - : ^ + 3 | ,-> .color { + 4 | | color: red; + 5 | `-> } `---- x LBrace @@ -123,52 +134,33 @@ `---- x ComponentValue - ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:3:1] - 3 | ,-> .color { - 4 | `-> color: red; - `---- - - x WhiteSpace { value: Atom(' - | ' type=inline) } - ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:3:1] - 3 | ,-> .color { - 4 | `-> color: red; - `---- - - x ComponentValue - ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:4:5] - 4 | color: red; - : ^^^^^ - `---- - - x Ident { value: Atom('color' type=static), raw: Atom('color' type=static) } ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:4:5] 4 | color: red; - : ^^^^^ + : ^^^^^^^^^^ `---- - x ComponentValue + x StyleBlock ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:4:5] 4 | color: red; - : ^ + : ^^^^^^^^^^ `---- - x Colon + x Declaration ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:4:5] 4 | color: red; - : ^ + : ^^^^^^^^^^ `---- - x ComponentValue + x DeclarationName ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:4:5] 4 | color: red; - : ^ + : ^^^^^ `---- - x WhiteSpace { value: Atom(' ' type=inline) } + x Ident ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:4:5] 4 | color: red; - : ^ + : ^^^^^ `---- x ComponentValue @@ -177,20 +169,8 @@ : ^^^ `---- - x Ident { value: Atom('red' type=inline), raw: Atom('red' type=inline) } + x Ident ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:4:5] 4 | color: red; : ^^^ `---- - - x ComponentValue - ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:4:5] - 4 | color: red; - : ^ - `---- - - x Semi - ,-[$DIR/tests/recovery/at-rule/extra-semi/input.css:4:5] - 4 | color: red; - : ^ - `---- diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/output.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/output.swc-stderr index 01f72aada8df..b939d3ebbea3 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/output.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/invalid-nesting/output.swc-stderr @@ -1,12 +1,6 @@ - x Expected function or ident tokens - ,-[$DIR/tests/recovery/at-rule/media/invalid-nesting/input.css:2:5] - 2 | max-inline-size: 1024px; - : ^ - `---- - - x Unexpected character `';'` - ,-[$DIR/tests/recovery/at-rule/media/invalid-nesting/input.css:2:5] - 2 | max-inline-size: 1024px; - : ^ + x Unexpected end of file + ,-[$DIR/tests/recovery/at-rule/media/invalid-nesting/input.css:3:3] + 3 | + : ^ `---- diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/output.json b/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/output.json index 10a3ff48db17..e2d132ba47f2 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/output.json +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/output.json @@ -72,135 +72,118 @@ }, "value": [ { - "type": "ListOfComponentValues", + "type": "QualifiedRule", "span": { "start": 20, - "end": 32, + "end": 72, "ctxt": 0 }, - "children": [ - { - "type": "PreservedToken", - "span": { - "start": 20, - "end": 25, - "ctxt": 0 - }, - "token": { - "Ident": { - "value": "color", - "raw": "color" - } - } + "prelude": { + "type": "ListOfComponentValues", + "span": { + "start": 20, + "end": 42, + "ctxt": 0 }, - { - "type": "PreservedToken", - "span": { - "start": 25, - "end": 26, - "ctxt": 0 + "children": [ + { + "type": "PreservedToken", + "span": { + "start": 20, + "end": 25, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "color", + "raw": "color" + } + } }, - "token": "Colon" - }, - { - "type": "PreservedToken", - "span": { - "start": 26, - "end": 27, - "ctxt": 0 + { + "type": "PreservedToken", + "span": { + "start": 25, + "end": 26, + "ctxt": 0 + }, + "token": "Colon" }, - "token": { - "WhiteSpace": { - "value": " " + { + "type": "PreservedToken", + "span": { + "start": 26, + "end": 27, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": " " + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 27, + "end": 31, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "teal", + "raw": "teal" + } } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 27, - "end": 31, - "ctxt": 0 }, - "token": { - "Ident": { - "value": "teal", - "raw": "teal" + { + "type": "PreservedToken", + "span": { + "start": 31, + "end": 32, + "ctxt": 0 + }, + "token": "Semi" + }, + { + "type": "PreservedToken", + "span": { + "start": 32, + "end": 37, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": "\n " + } } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 31, - "end": 32, - "ctxt": 0 }, - "token": "Semi" - } - ] - }, - { - "type": "QualifiedRule", - "span": { - "start": 37, - "end": 72, - "ctxt": 0 - }, - "prelude": { - "type": "SelectorList", - "span": { - "start": 37, - "end": 41, - "ctxt": 0 - }, - "children": [ { - "type": "ComplexSelector", + "type": "PreservedToken", "span": { "start": 37, "end": 41, "ctxt": 0 }, - "children": [ - { - "type": "CompoundSelector", - "span": { - "start": 37, - "end": 41, - "ctxt": 0 - }, - "nestingSelector": null, - "typeSelector": { - "type": "TagNameSelector", - "span": { - "start": 37, - "end": 41, - "ctxt": 0 - }, - "name": { - "type": "WqName", - "span": { - "start": 37, - "end": 41, - "ctxt": 0 - }, - "prefix": null, - "value": { - "type": "Ident", - "span": { - "start": 37, - "end": 41, - "ctxt": 0 - }, - "value": "main", - "raw": "main" - } - } - }, - "subclassSelectors": [] + "token": { + "Ident": { + "value": "main", + "raw": "main" } - ] + } + }, + { + "type": "PreservedToken", + "span": { + "start": 41, + "end": 42, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": " " + } + } } ] }, diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/output.swc-stderr b/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/output.swc-stderr index 4fe1f6fafb0d..69aac67df065 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/output.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/output.swc-stderr @@ -4,9 +4,3 @@ 2 | color: teal; : ^ `---- - - x Unexpected character `';'` - ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:2:5] - 2 | color: teal; - : ^ - `---- diff --git a/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/span.rust-debug b/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/span.rust-debug index e697cf3f075e..61370c3e0518 100644 --- a/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/span.rust-debug +++ b/crates/swc_css_parser/tests/recovery/at-rule/media/wrong-stylesheet/span.rust-debug @@ -83,14 +83,26 @@ x ComponentValue ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:2:5] - 2 | color: teal; - : ^^^^^^^^^^^^ + 2 | ,-> color: teal; + 3 | | main { + 4 | | color: orange; + 5 | `-> } `---- x Rule ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:2:5] - 2 | color: teal; - : ^^^^^^^^^^^^ + 2 | ,-> color: teal; + 3 | | main { + 4 | | color: orange; + 5 | `-> } + `---- + + x QualifiedRule + ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:2:5] + 2 | ,-> color: teal; + 3 | | main { + 4 | | color: orange; + 5 | `-> } `---- x ComponentValue @@ -154,66 +166,40 @@ `---- x ComponentValue - ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:3:5] - 3 | ,-> main { - 4 | | color: orange; - 5 | `-> } - `---- - - x Rule - ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:3:5] - 3 | ,-> main { - 4 | | color: orange; - 5 | `-> } - `---- - - x QualifiedRule - ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:3:5] - 3 | ,-> main { - 4 | | color: orange; - 5 | `-> } - `---- - - x SelectorList - ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:3:5] - 3 | main { - : ^^^^ - `---- - - x ComplexSelector - ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:3:5] - 3 | main { - : ^^^^ + ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:2:5] + 2 | ,-> color: teal; + 3 | `-> main { `---- - x CompoundSelector - ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:3:5] - 3 | main { - : ^^^^ + x WhiteSpace { value: Atom(' + | ' type=inline) } + ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:2:5] + 2 | ,-> color: teal; + 3 | `-> main { `---- - x TypeSelector + x ComponentValue ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:3:5] 3 | main { : ^^^^ `---- - x TagNameSelector + x Ident { value: Atom('main' type=static), raw: Atom('main' type=static) } ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:3:5] 3 | main { : ^^^^ `---- - x WqName + x ComponentValue ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:3:5] 3 | main { - : ^^^^ + : ^ `---- - x Ident + x WhiteSpace { value: Atom(' ' type=inline) } ,-[$DIR/tests/recovery/at-rule/media/wrong-stylesheet/input.css:3:5] 3 | main { - : ^^^^ + : ^ `---- x SimpleBlock diff --git a/crates/swc_css_parser/tests/recovery/comments/bad-comment-1/output.swc-stderr b/crates/swc_css_parser/tests/recovery/comments/bad-comment-1/output.swc-stderr index fdb451d16410..7cbea7c537f0 100644 --- a/crates/swc_css_parser/tests/recovery/comments/bad-comment-1/output.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/comments/bad-comment-1/output.swc-stderr @@ -1,10 +1,4 @@ - x Invalid selector - ,-[$DIR/tests/recovery/comments/bad-comment-1/input.css:1:1] - 1 | // comment - : ^ - `---- - x Unexpected end of file ,-[$DIR/tests/recovery/comments/bad-comment-1/input.css:1:1] 1 | // comment diff --git a/crates/swc_css_parser/tests/recovery/hacks/output.swc-stderr b/crates/swc_css_parser/tests/recovery/hacks/output.swc-stderr index f4846839d18e..d9849cca967d 100644 --- a/crates/swc_css_parser/tests/recovery/hacks/output.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/hacks/output.swc-stderr @@ -11,12 +11,6 @@ : ^ `---- - x Expected function or ident tokens - ,-[$DIR/tests/recovery/hacks/input.css:112:5] - 112 | &property: value; - : ^ - `---- - x Expected important ,-[$DIR/tests/recovery/hacks/input.css:180:1] 180 | .selector { property: value !ie; } @@ -215,8 +209,8 @@ : ^ `---- - x Unexpected character `';'` - ,-[$DIR/tests/recovery/hacks/input.css:112:5] - 112 | &property: value; - : ^ + x Unexpected end of file + ,-[$DIR/tests/recovery/hacks/input.css:114:1] + 114 | } + : ^ `---- diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-1/output.json b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-1/output.json index 32f41ea797af..5b11cbe1cbeb 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-1/output.json +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-1/output.json @@ -22,49 +22,50 @@ }, "children": [ { - "type": "PreservedToken", + "type": "SimpleBlock", "span": { "start": 1, - "end": 2, + "end": 8, "ctxt": 0 }, - "token": "LBracket" - }, - { - "type": "PreservedToken", - "span": { - "start": 2, - "end": 6, - "ctxt": 0 + "name": { + "type": "PreservedToken", + "span": { + "start": 1, + "end": 2, + "ctxt": 0 + }, + "token": "LBracket" }, - "token": { - "Ident": { - "value": "href", - "raw": "href" + "value": [ + { + "type": "PreservedToken", + "span": { + "start": 2, + "end": 6, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "href", + "raw": "href" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 6, + "end": 7, + "ctxt": 0 + }, + "token": { + "Delim": { + "value": "=" + } + } } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 6, - "end": 7, - "ctxt": 0 - }, - "token": { - "Delim": { - "value": "=" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 7, - "end": 8, - "ctxt": 0 - }, - "token": "RBracket" + ] }, { "type": "PreservedToken", diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-1/span.rust-debug b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-1/span.rust-debug index d444a059c57c..9335b520cb23 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-1/span.rust-debug +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-1/span.rust-debug @@ -20,7 +20,13 @@ x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-1/input.css:1:1] 1 | [href=] {} - : ^ + : ^^^^^^^ + `---- + + x SimpleBlock + ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-1/input.css:1:1] + 1 | [href=] {} + : ^^^^^^^ `---- x LBracket @@ -53,18 +59,6 @@ : ^ `---- - x ComponentValue - ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-1/input.css:1:1] - 1 | [href=] {} - : ^ - `---- - - x RBracket - ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-1/input.css:1:1] - 1 | [href=] {} - : ^ - `---- - x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-1/input.css:1:1] 1 | [href=] {} diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-2/output.json b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-2/output.json index 3d7da890df56..3f0743d0ede6 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-2/output.json +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-2/output.json @@ -22,76 +22,77 @@ }, "children": [ { - "type": "PreservedToken", + "type": "SimpleBlock", "span": { "start": 1, - "end": 2, - "ctxt": 0 - }, - "token": "LBracket" - }, - { - "type": "PreservedToken", - "span": { - "start": 2, - "end": 6, - "ctxt": 0 - }, - "token": { - "Ident": { - "value": "href", - "raw": "href" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 6, - "end": 7, - "ctxt": 0 - }, - "token": { - "Delim": { - "value": "#" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 7, - "end": 8, + "end": 15, "ctxt": 0 }, - "token": { - "Delim": { - "value": "=" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 8, - "end": 14, - "ctxt": 0 + "name": { + "type": "PreservedToken", + "span": { + "start": 1, + "end": 2, + "ctxt": 0 + }, + "token": "LBracket" }, - "token": { - "String": { - "value": "test", - "raw": "\"test\"" + "value": [ + { + "type": "PreservedToken", + "span": { + "start": 2, + "end": 6, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "href", + "raw": "href" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 6, + "end": 7, + "ctxt": 0 + }, + "token": { + "Delim": { + "value": "#" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 7, + "end": 8, + "ctxt": 0 + }, + "token": { + "Delim": { + "value": "=" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 8, + "end": 14, + "ctxt": 0 + }, + "token": { + "String": { + "value": "test", + "raw": "\"test\"" + } + } } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 14, - "end": 15, - "ctxt": 0 - }, - "token": "RBracket" + ] }, { "type": "PreservedToken", diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-2/span.rust-debug b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-2/span.rust-debug index 228380d051bf..9200a830276b 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-2/span.rust-debug +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-2/span.rust-debug @@ -20,7 +20,13 @@ x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-2/input.css:1:1] 1 | [href#="test"] {} - : ^ + : ^^^^^^^^^^^^^^ + `---- + + x SimpleBlock + ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-2/input.css:1:1] + 1 | [href#="test"] {} + : ^^^^^^^^^^^^^^ `---- x LBracket @@ -77,18 +83,6 @@ : ^^^^^^ `---- - x ComponentValue - ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-2/input.css:1:1] - 1 | [href#="test"] {} - : ^ - `---- - - x RBracket - ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-2/input.css:1:1] - 1 | [href#="test"] {} - : ^ - `---- - x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-2/input.css:1:1] 1 | [href#="test"] {} diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-3/output.json b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-3/output.json index 20f3ab55af1c..75d34c77228d 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-3/output.json +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-3/output.json @@ -36,155 +36,156 @@ } }, { - "type": "PreservedToken", + "type": "SimpleBlock", "span": { "start": 2, - "end": 3, - "ctxt": 0 - }, - "token": "LBracket" - }, - { - "type": "PreservedToken", - "span": { - "start": 3, - "end": 8, - "ctxt": 0 - }, - "token": { - "Ident": { - "value": "title", - "raw": "title" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 8, - "end": 9, - "ctxt": 0 - }, - "token": { - "WhiteSpace": { - "value": " " - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 9, - "end": 10, - "ctxt": 0 - }, - "token": { - "Delim": { - "value": "*" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 10, - "end": 11, - "ctxt": 0 - }, - "token": { - "WhiteSpace": { - "value": " " - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 11, - "end": 12, - "ctxt": 0 - }, - "token": { - "Delim": { - "value": "=" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 12, - "end": 13, - "ctxt": 0 - }, - "token": { - "WhiteSpace": { - "value": " " - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 13, - "end": 20, - "ctxt": 0 - }, - "token": { - "String": { - "value": "title", - "raw": "\"title\"" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 20, - "end": 21, - "ctxt": 0 - }, - "token": { - "WhiteSpace": { - "value": " " - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 21, - "end": 22, + "end": 24, "ctxt": 0 }, - "token": { - "Ident": { - "value": "i", - "raw": "i" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 22, - "end": 23, - "ctxt": 0 + "name": { + "type": "PreservedToken", + "span": { + "start": 2, + "end": 3, + "ctxt": 0 + }, + "token": "LBracket" }, - "token": { - "WhiteSpace": { - "value": " " + "value": [ + { + "type": "PreservedToken", + "span": { + "start": 3, + "end": 8, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "title", + "raw": "title" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 8, + "end": 9, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": " " + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 9, + "end": 10, + "ctxt": 0 + }, + "token": { + "Delim": { + "value": "*" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 10, + "end": 11, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": " " + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 11, + "end": 12, + "ctxt": 0 + }, + "token": { + "Delim": { + "value": "=" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 12, + "end": 13, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": " " + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 13, + "end": 20, + "ctxt": 0 + }, + "token": { + "String": { + "value": "title", + "raw": "\"title\"" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 20, + "end": 21, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": " " + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 21, + "end": 22, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "i", + "raw": "i" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 22, + "end": 23, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": " " + } + } } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 23, - "end": 24, - "ctxt": 0 - }, - "token": "RBracket" + ] }, { "type": "PreservedToken", diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-3/span.rust-debug b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-3/span.rust-debug index b0d176b40e33..89dfacb3c358 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-3/span.rust-debug +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-3/span.rust-debug @@ -35,7 +35,13 @@ x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-3/input.css:1:1] 1 | a[title * = "title" i ] { - : ^ + : ^^^^^^^^^^^^^^^^^^^^^^ + `---- + + x SimpleBlock + ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-3/input.css:1:1] + 1 | a[title * = "title" i ] { + : ^^^^^^^^^^^^^^^^^^^^^^ `---- x LBracket @@ -164,18 +170,6 @@ : ^ `---- - x ComponentValue - ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-3/input.css:1:1] - 1 | a[title * = "title" i ] { - : ^ - `---- - - x RBracket - ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-3/input.css:1:1] - 1 | a[title * = "title" i ] { - : ^ - `---- - x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-3/input.css:1:1] 1 | a[title * = "title" i ] { diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-4/output.json b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-4/output.json index f888fd60e096..61b523f356f9 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-4/output.json +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-4/output.json @@ -36,76 +36,77 @@ } }, { - "type": "PreservedToken", + "type": "SimpleBlock", "span": { "start": 2, - "end": 3, - "ctxt": 0 - }, - "token": "LBracket" - }, - { - "type": "PreservedToken", - "span": { - "start": 3, - "end": 8, - "ctxt": 0 - }, - "token": { - "Ident": { - "value": "title", - "raw": "title" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 8, - "end": 9, - "ctxt": 0 - }, - "token": { - "Delim": { - "value": "%" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 9, - "end": 10, + "end": 18, "ctxt": 0 }, - "token": { - "Delim": { - "value": "=" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 10, - "end": 17, - "ctxt": 0 + "name": { + "type": "PreservedToken", + "span": { + "start": 2, + "end": 3, + "ctxt": 0 + }, + "token": "LBracket" }, - "token": { - "String": { - "value": "title", - "raw": "\"title\"" + "value": [ + { + "type": "PreservedToken", + "span": { + "start": 3, + "end": 8, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "title", + "raw": "title" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 8, + "end": 9, + "ctxt": 0 + }, + "token": { + "Delim": { + "value": "%" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 9, + "end": 10, + "ctxt": 0 + }, + "token": { + "Delim": { + "value": "=" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 10, + "end": 17, + "ctxt": 0 + }, + "token": { + "String": { + "value": "title", + "raw": "\"title\"" + } + } } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 17, - "end": 18, - "ctxt": 0 - }, - "token": "RBracket" + ] }, { "type": "PreservedToken", diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-4/span.rust-debug b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-4/span.rust-debug index b692198d3d0e..b7c8047f2a5b 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-4/span.rust-debug +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher-4/span.rust-debug @@ -35,7 +35,13 @@ x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-4/input.css:1:1] 1 | a[title%="title"] { - : ^ + : ^^^^^^^^^^^^^^^^ + `---- + + x SimpleBlock + ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-4/input.css:1:1] + 1 | a[title%="title"] { + : ^^^^^^^^^^^^^^^^ `---- x LBracket @@ -92,18 +98,6 @@ : ^^^^^^^ `---- - x ComponentValue - ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-4/input.css:1:1] - 1 | a[title%="title"] { - : ^ - `---- - - x RBracket - ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-4/input.css:1:1] - 1 | a[title%="title"] { - : ^ - `---- - x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher-4/input.css:1:1] 1 | a[title%="title"] { diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher/output.json b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher/output.json index 65b3aac467f5..7bc8c787b373 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher/output.json +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher/output.json @@ -22,76 +22,77 @@ }, "children": [ { - "type": "PreservedToken", + "type": "SimpleBlock", "span": { "start": 1, - "end": 2, - "ctxt": 0 - }, - "token": "LBracket" - }, - { - "type": "PreservedToken", - "span": { - "start": 2, - "end": 6, - "ctxt": 0 - }, - "token": { - "Ident": { - "value": "href", - "raw": "href" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 6, - "end": 7, - "ctxt": 0 - }, - "token": { - "Delim": { - "value": "=" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 7, - "end": 8, + "end": 15, "ctxt": 0 }, - "token": { - "Delim": { - "value": "=" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 8, - "end": 14, - "ctxt": 0 + "name": { + "type": "PreservedToken", + "span": { + "start": 1, + "end": 2, + "ctxt": 0 + }, + "token": "LBracket" }, - "token": { - "String": { - "value": ".org", - "raw": "\".org\"" + "value": [ + { + "type": "PreservedToken", + "span": { + "start": 2, + "end": 6, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "href", + "raw": "href" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 6, + "end": 7, + "ctxt": 0 + }, + "token": { + "Delim": { + "value": "=" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 7, + "end": 8, + "ctxt": 0 + }, + "token": { + "Delim": { + "value": "=" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 8, + "end": 14, + "ctxt": 0 + }, + "token": { + "String": { + "value": ".org", + "raw": "\".org\"" + } + } } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 14, - "end": 15, - "ctxt": 0 - }, - "token": "RBracket" + ] }, { "type": "PreservedToken", diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher/span.rust-debug b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher/span.rust-debug index 31f5a40b8913..c2e4e423d334 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher/span.rust-debug +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-matcher/span.rust-debug @@ -20,7 +20,13 @@ x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher/input.css:1:1] 1 | [href==".org"] {} - : ^ + : ^^^^^^^^^^^^^^ + `---- + + x SimpleBlock + ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher/input.css:1:1] + 1 | [href==".org"] {} + : ^^^^^^^^^^^^^^ `---- x LBracket @@ -77,18 +83,6 @@ : ^^^^^^ `---- - x ComponentValue - ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher/input.css:1:1] - 1 | [href==".org"] {} - : ^ - `---- - - x RBracket - ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher/input.css:1:1] - 1 | [href==".org"] {} - : ^ - `---- - x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/invalid-matcher/input.css:1:1] 1 | [href==".org"] {} diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-modifier/output.json b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-modifier/output.json index 441f7e3cd22f..91ef35b8b0aa 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-modifier/output.json +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-modifier/output.json @@ -22,90 +22,91 @@ }, "children": [ { - "type": "PreservedToken", + "type": "SimpleBlock", "span": { "start": 1, - "end": 2, - "ctxt": 0 - }, - "token": "LBracket" - }, - { - "type": "PreservedToken", - "span": { - "start": 2, - "end": 6, - "ctxt": 0 - }, - "token": { - "Ident": { - "value": "href", - "raw": "href" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 6, - "end": 7, - "ctxt": 0 - }, - "token": { - "Delim": { - "value": "=" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 7, - "end": 13, - "ctxt": 0 - }, - "token": { - "String": { - "value": "test", - "raw": "\"test\"" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 13, - "end": 14, + "end": 18, "ctxt": 0 }, - "token": { - "WhiteSpace": { - "value": " " - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 14, - "end": 17, - "ctxt": 0 + "name": { + "type": "PreservedToken", + "span": { + "start": 1, + "end": 2, + "ctxt": 0 + }, + "token": "LBracket" }, - "token": { - "String": { - "value": "z", - "raw": "\"z\"" + "value": [ + { + "type": "PreservedToken", + "span": { + "start": 2, + "end": 6, + "ctxt": 0 + }, + "token": { + "Ident": { + "value": "href", + "raw": "href" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 6, + "end": 7, + "ctxt": 0 + }, + "token": { + "Delim": { + "value": "=" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 7, + "end": 13, + "ctxt": 0 + }, + "token": { + "String": { + "value": "test", + "raw": "\"test\"" + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 13, + "end": 14, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": " " + } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 14, + "end": 17, + "ctxt": 0 + }, + "token": { + "String": { + "value": "z", + "raw": "\"z\"" + } + } } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 17, - "end": 18, - "ctxt": 0 - }, - "token": "RBracket" + ] }, { "type": "PreservedToken", diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-modifier/span.rust-debug b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-modifier/span.rust-debug index 35262ce34866..a5aab6124a23 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-modifier/span.rust-debug +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/invalid-modifier/span.rust-debug @@ -20,7 +20,13 @@ x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/invalid-modifier/input.css:1:1] 1 | [href="test" "z"] {} - : ^ + : ^^^^^^^^^^^^^^^^^ + `---- + + x SimpleBlock + ,-[$DIR/tests/recovery/selector/attribute/invalid-modifier/input.css:1:1] + 1 | [href="test" "z"] {} + : ^^^^^^^^^^^^^^^^^ `---- x LBracket @@ -89,18 +95,6 @@ : ^^^ `---- - x ComponentValue - ,-[$DIR/tests/recovery/selector/attribute/invalid-modifier/input.css:1:1] - 1 | [href="test" "z"] {} - : ^ - `---- - - x RBracket - ,-[$DIR/tests/recovery/selector/attribute/invalid-modifier/input.css:1:1] - 1 | [href="test" "z"] {} - : ^ - `---- - x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/invalid-modifier/input.css:1:1] 1 | [href="test" "z"] {} diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/unclosed/output.json b/crates/swc_css_parser/tests/recovery/selector/attribute/unclosed/output.json index d75dc6154a18..6ca83c16d8a9 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/unclosed/output.json +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/unclosed/output.json @@ -2,111 +2,95 @@ "type": "Stylesheet", "span": { "start": 1, - "end": 19, + "end": 17, "ctxt": 0 }, "rules": [ { - "type": "QualifiedRule", + "type": "ListOfComponentValues", "span": { "start": 1, - "end": 18, + "end": 17, "ctxt": 0 }, - "prelude": { - "type": "ListOfComponentValues", - "span": { - "start": 1, - "end": 14, - "ctxt": 0 - }, - "children": [ - { - "type": "PreservedToken", - "span": { - "start": 1, - "end": 2, - "ctxt": 0 - }, - "token": { - "Delim": { - "value": "." - } + "children": [ + { + "type": "PreservedToken", + "span": { + "start": 1, + "end": 2, + "ctxt": 0 + }, + "token": { + "Delim": { + "value": "." } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 2, + "end": 7, + "ctxt": 0 }, - { - "type": "PreservedToken", - "span": { - "start": 2, - "end": 7, - "ctxt": 0 - }, - "token": { - "Ident": { - "value": "class", - "raw": "class" - } + "token": { + "Ident": { + "value": "class", + "raw": "class" } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 7, + "end": 8, + "ctxt": 0 }, - { - "type": "PreservedToken", - "span": { - "start": 7, - "end": 8, - "ctxt": 0 - }, - "token": "LBracket" + "token": "LBracket" + }, + { + "type": "PreservedToken", + "span": { + "start": 8, + "end": 12, + "ctxt": 0 }, - { - "type": "PreservedToken", - "span": { - "start": 8, - "end": 12, - "ctxt": 0 - }, - "token": { - "Ident": { - "value": "attr", - "raw": "attr" - } + "token": { + "Ident": { + "value": "attr", + "raw": "attr" } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 12, + "end": 13, + "ctxt": 0 }, - { - "type": "PreservedToken", - "span": { - "start": 12, - "end": 13, - "ctxt": 0 - }, - "token": { - "Delim": { - "value": "=" - } + "token": { + "Delim": { + "value": "=" } + } + }, + { + "type": "PreservedToken", + "span": { + "start": 13, + "end": 14, + "ctxt": 0 }, - { - "type": "PreservedToken", - "span": { - "start": 13, - "end": 14, - "ctxt": 0 - }, - "token": { - "WhiteSpace": { - "value": " " - } + "token": { + "WhiteSpace": { + "value": " " } } - ] - }, - "block": { - "type": "SimpleBlock", - "span": { - "start": 14, - "end": 18, - "ctxt": 0 }, - "name": { + { "type": "PreservedToken", "span": { "start": 14, @@ -115,8 +99,20 @@ }, "token": "LBrace" }, - "value": [] - } + { + "type": "PreservedToken", + "span": { + "start": 15, + "end": 17, + "ctxt": 0 + }, + "token": { + "WhiteSpace": { + "value": "\n\n" + } + } + } + ] } ] } diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/unclosed/output.swc-stderr b/crates/swc_css_parser/tests/recovery/selector/attribute/unclosed/output.swc-stderr index 3522f94b21c8..30907168ff5e 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/unclosed/output.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/unclosed/output.swc-stderr @@ -1,6 +1,6 @@ - x Invalid attribute matcher value - ,-[$DIR/tests/recovery/selector/attribute/unclosed/input.css:1:1] - 1 | .class[attr= { - : ^ + x Unexpected end of file + ,-[$DIR/tests/recovery/selector/attribute/unclosed/input.css:3:3] + 3 | + : ^ `---- diff --git a/crates/swc_css_parser/tests/recovery/selector/attribute/unclosed/span.rust-debug b/crates/swc_css_parser/tests/recovery/selector/attribute/unclosed/span.rust-debug index 893920721cbe..c844961a521b 100644 --- a/crates/swc_css_parser/tests/recovery/selector/attribute/unclosed/span.rust-debug +++ b/crates/swc_css_parser/tests/recovery/selector/attribute/unclosed/span.rust-debug @@ -2,22 +2,15 @@ x Stylesheet ,-[$DIR/tests/recovery/selector/attribute/unclosed/input.css:1:1] 1 | ,-> .class[attr= { - 2 | | - 3 | `-> } + 2 | `-> + 3 | } `---- x Rule ,-[$DIR/tests/recovery/selector/attribute/unclosed/input.css:1:1] 1 | ,-> .class[attr= { - 2 | | - 3 | `-> } - `---- - - x QualifiedRule - ,-[$DIR/tests/recovery/selector/attribute/unclosed/input.css:1:1] - 1 | ,-> .class[attr= { - 2 | | - 3 | `-> } + 2 | `-> + 3 | } `---- x ComponentValue @@ -92,11 +85,10 @@ : ^ `---- - x SimpleBlock + x ComponentValue ,-[$DIR/tests/recovery/selector/attribute/unclosed/input.css:1:1] - 1 | ,-> .class[attr= { - 2 | | - 3 | `-> } + 1 | .class[attr= { + : ^ `---- x LBrace @@ -104,3 +96,19 @@ 1 | .class[attr= { : ^ `---- + + x ComponentValue + ,-[$DIR/tests/recovery/selector/attribute/unclosed/input.css:1:1] + 1 | ,-> .class[attr= { + 2 | `-> + 3 | } + `---- + + x WhiteSpace { value: Atom(' + | + | ' type=inline) } + ,-[$DIR/tests/recovery/selector/attribute/unclosed/input.css:1:1] + 1 | ,-> .class[attr= { + 2 | `-> + 3 | } + `---- diff --git a/crates/swc_css_parser/tests/recovery/selector/pseudo-class/invalid-function/output.json b/crates/swc_css_parser/tests/recovery/selector/pseudo-class/invalid-function/output.json index 4bf07dbe8647..65fdde9b78d6 100644 --- a/crates/swc_css_parser/tests/recovery/selector/pseudo-class/invalid-function/output.json +++ b/crates/swc_css_parser/tests/recovery/selector/pseudo-class/invalid-function/output.json @@ -44,42 +44,39 @@ } }, { - "type": "PreservedToken", + "type": "Function", "span": { "start": 3, - "end": 13, + "end": 15, "ctxt": 0 }, - "token": { - "Function": { - "value": "nth-child", - "raw": "nth-child" - } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 13, - "end": 14, - "ctxt": 0 + "name": { + "type": "Ident", + "span": { + "start": 3, + "end": 12, + "ctxt": 0 + }, + "value": "nth-child", + "raw": "nth-child" }, - "token": { - "Number": { - "value": 2.0, - "raw": "2", - "type": "integer" + "value": [ + { + "type": "PreservedToken", + "span": { + "start": 13, + "end": 14, + "ctxt": 0 + }, + "token": { + "Number": { + "value": 2.0, + "raw": "2", + "type": "integer" + } + } } - } - }, - { - "type": "PreservedToken", - "span": { - "start": 14, - "end": 15, - "ctxt": 0 - }, - "token": "RParen" + ] }, { "type": "PreservedToken", diff --git a/crates/swc_css_parser/tests/recovery/selector/pseudo-class/invalid-function/span.rust-debug b/crates/swc_css_parser/tests/recovery/selector/pseudo-class/invalid-function/span.rust-debug index 496fdec497ba..5facd0348c49 100644 --- a/crates/swc_css_parser/tests/recovery/selector/pseudo-class/invalid-function/span.rust-debug +++ b/crates/swc_css_parser/tests/recovery/selector/pseudo-class/invalid-function/span.rust-debug @@ -47,37 +47,31 @@ x ComponentValue ,-[$DIR/tests/recovery/selector/pseudo-class/invalid-function/input.css:1:1] 1 | : nth-child(2) { - : ^^^^^^^^^^ + : ^^^^^^^^^^^^ `---- - x Function { value: Atom('nth-child' type=static), raw: Atom('nth-child' type=static) } + x Function ,-[$DIR/tests/recovery/selector/pseudo-class/invalid-function/input.css:1:1] 1 | : nth-child(2) { - : ^^^^^^^^^^ + : ^^^^^^^^^^^^ `---- - x ComponentValue + x Ident ,-[$DIR/tests/recovery/selector/pseudo-class/invalid-function/input.css:1:1] 1 | : nth-child(2) { - : ^ - `---- - - x Number { value: 2.0, raw: Atom('2' type=inline), type_flag: Integer } - ,-[$DIR/tests/recovery/selector/pseudo-class/invalid-function/input.css:1:1] - 1 | : nth-child(2) { - : ^ + : ^^^^^^^^^ `---- x ComponentValue ,-[$DIR/tests/recovery/selector/pseudo-class/invalid-function/input.css:1:1] 1 | : nth-child(2) { - : ^ + : ^ `---- - x RParen + x Number { value: 2.0, raw: Atom('2' type=inline), type_flag: Integer } ,-[$DIR/tests/recovery/selector/pseudo-class/invalid-function/input.css:1:1] 1 | : nth-child(2) { - : ^ + : ^ `---- x ComponentValue diff --git a/crates/swc_css_parser/tests/recovery/simple-block/unclosed-in-function/output.swc-stderr b/crates/swc_css_parser/tests/recovery/simple-block/unclosed-in-function/output.swc-stderr index 7a0734052c92..7f7e00c0315f 100644 --- a/crates/swc_css_parser/tests/recovery/simple-block/unclosed-in-function/output.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/simple-block/unclosed-in-function/output.swc-stderr @@ -11,6 +11,12 @@ : ^ `---- + x Expected Declaration value + ,-[$DIR/tests/recovery/simple-block/unclosed-in-function/input.css:3:1] + 3 | } + : ^ + `---- + x Unexpected end of file ,-[$DIR/tests/recovery/simple-block/unclosed-in-function/input.css:3:3] 3 | diff --git a/crates/swc_css_parser/tests/recovery/style-blocks-contents/basic/output.swc-stderr b/crates/swc_css_parser/tests/recovery/style-blocks-contents/basic/output.swc-stderr index 122fa282dcd6..6ba9ffebf6c8 100644 --- a/crates/swc_css_parser/tests/recovery/style-blocks-contents/basic/output.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/style-blocks-contents/basic/output.swc-stderr @@ -23,14 +23,8 @@ : ^ `---- - x Invalid selector - ,-[$DIR/tests/recovery/style-blocks-contents/basic/input.css:39:5] - 39 | & test; - : ^ - `---- - - x Unexpected character `';'` - ,-[$DIR/tests/recovery/style-blocks-contents/basic/input.css:39:5] - 39 | & test; - : ^ + x Unexpected end of file + ,-[$DIR/tests/recovery/style-blocks-contents/basic/input.css:40:1] + 40 | } + : ^ `---- diff --git a/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-2/output.swc-stderr b/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-2/output.swc-stderr index 1e3ca5e5604f..4c1d145d5338 100644 --- a/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-2/output.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested-2/output.swc-stderr @@ -1,12 +1,6 @@ - x Invalid selector - ,-[$DIR/tests/recovery/style-blocks-contents/invalid-nested-2/input.css:3:5] - 3 | & test; - : ^ - `---- - - x Unexpected character `';'` - ,-[$DIR/tests/recovery/style-blocks-contents/invalid-nested-2/input.css:3:5] - 3 | & test; - : ^ + x Unexpected end of file + ,-[$DIR/tests/recovery/style-blocks-contents/invalid-nested-2/input.css:5:1] + 5 | } + : ^ `---- diff --git a/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested/output.swc-stderr b/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested/output.swc-stderr index 60288595cd46..1c99aacdda4a 100644 --- a/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested/output.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/style-blocks-contents/invalid-nested/output.swc-stderr @@ -1,12 +1,6 @@ - x Invalid selector - ,-[$DIR/tests/recovery/style-blocks-contents/invalid-nested/input.css:3:5] - 3 | & test; - : ^ - `---- - - x Unexpected character `';'` - ,-[$DIR/tests/recovery/style-blocks-contents/invalid-nested/input.css:3:5] - 3 | & test; - : ^ + x Unexpected end of file + ,-[$DIR/tests/recovery/style-blocks-contents/invalid-nested/input.css:5:1] + 5 | } + : ^ `---- diff --git a/crates/swc_css_parser/tests/recovery/vercel/001/output.swc-stderr b/crates/swc_css_parser/tests/recovery/vercel/001/output.swc-stderr index 5f1a5d867eda..7769a28d46a6 100644 --- a/crates/swc_css_parser/tests/recovery/vercel/001/output.swc-stderr +++ b/crates/swc_css_parser/tests/recovery/vercel/001/output.swc-stderr @@ -1,10 +1,4 @@ - x Invalid selector - ,-[$DIR/tests/recovery/vercel/001/input.css:15:1] - 15 | } - : ^ - `---- - x Unexpected end of file ,-[$DIR/tests/recovery/vercel/001/input.css:15:3] 15 |