2022-01-16 08:33:06 +03:00
|
|
|
#![allow(clippy::needless_update)]
|
|
|
|
|
2021-08-19 08:16:32 +03:00
|
|
|
use std::path::PathBuf;
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
use swc_common::{errors::Handler, input::SourceFileInput, Span, Spanned};
|
2021-08-20 10:48:08 +03:00
|
|
|
use swc_css_ast::*;
|
2021-08-19 08:16:32 +03:00
|
|
|
use swc_css_parser::{
|
|
|
|
lexer::Lexer,
|
2021-08-25 05:46:17 +03:00
|
|
|
parse_tokens,
|
|
|
|
parser::{input::ParserInput, Parser, ParserConfig},
|
2021-08-19 08:16:32 +03:00
|
|
|
};
|
2021-11-28 04:12:02 +03:00
|
|
|
use swc_css_visit::{Visit, VisitWith};
|
2021-08-19 08:16:32 +03:00
|
|
|
use testing::NormalizedOutput;
|
|
|
|
|
2021-12-01 20:07:49 +03:00
|
|
|
pub struct Invalid {
|
|
|
|
pub span: Span,
|
|
|
|
}
|
|
|
|
|
2021-09-08 04:19:14 +03:00
|
|
|
#[testing::fixture("tests/fixture/**/input.css")]
|
|
|
|
fn tokens_input(input: PathBuf) {
|
2021-09-28 12:58:56 +03:00
|
|
|
testing::run_test2(false, |cm, handler| {
|
2021-09-08 04:19:14 +03:00
|
|
|
let fm = cm.load_file(&input).unwrap();
|
|
|
|
|
|
|
|
let tokens = {
|
2021-10-15 17:21:33 +03:00
|
|
|
let mut lexer = Lexer::new(SourceFileInput::from(&*fm), Default::default());
|
2021-09-08 04:19:14 +03:00
|
|
|
let mut tokens = vec![];
|
|
|
|
|
2022-06-12 06:28:23 +03:00
|
|
|
while let Some(token_and_span) = lexer.next() {
|
|
|
|
tokens.push(token_and_span);
|
2021-09-08 04:19:14 +03:00
|
|
|
}
|
2022-06-12 06:28:23 +03:00
|
|
|
|
2021-09-08 04:19:14 +03:00
|
|
|
Tokens {
|
|
|
|
span: Span::new(fm.start_pos, fm.end_pos, Default::default()),
|
|
|
|
tokens,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-09-28 12:58:56 +03:00
|
|
|
let mut errors = vec![];
|
2021-11-28 04:12:02 +03:00
|
|
|
let _ss: Stylesheet = parse_tokens(
|
2021-10-15 17:21:33 +03:00
|
|
|
&tokens,
|
|
|
|
ParserConfig {
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
&mut errors,
|
|
|
|
)
|
|
|
|
.expect("failed to parse tokens");
|
2021-09-28 12:58:56 +03:00
|
|
|
|
|
|
|
for err in errors {
|
|
|
|
err.to_diagnostics(&handler).emit();
|
|
|
|
}
|
2021-09-08 04:19:14 +03:00
|
|
|
|
2021-09-28 12:58:56 +03:00
|
|
|
if handler.has_errors() {
|
|
|
|
return Err(());
|
|
|
|
}
|
|
|
|
|
2021-09-08 04:19:14 +03:00
|
|
|
Ok(())
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
2021-10-15 17:21:33 +03:00
|
|
|
fn test_pass(input: PathBuf, config: ParserConfig) {
|
2021-08-19 08:16:32 +03:00
|
|
|
testing::run_test2(false, |cm, handler| {
|
|
|
|
let ref_json_path = input.parent().unwrap().join("output.json");
|
|
|
|
|
|
|
|
let fm = cm.load_file(&input).unwrap();
|
2021-10-15 17:21:33 +03:00
|
|
|
let lexer = Lexer::new(SourceFileInput::from(&*fm), config);
|
|
|
|
let mut parser = Parser::new(lexer, config);
|
2021-08-19 08:16:32 +03:00
|
|
|
|
|
|
|
let stylesheet = parser.parse_all();
|
|
|
|
|
|
|
|
match stylesheet {
|
|
|
|
Ok(stylesheet) => {
|
|
|
|
let actual_json = serde_json::to_string_pretty(&stylesheet)
|
|
|
|
.map(NormalizedOutput::from)
|
|
|
|
.expect("failed to serialize stylesheet");
|
|
|
|
|
2021-08-25 05:46:17 +03:00
|
|
|
actual_json.clone().compare_to_file(&ref_json_path).unwrap();
|
|
|
|
|
2021-10-15 17:21:33 +03:00
|
|
|
if !config.allow_wrong_line_comments {
|
2022-06-12 06:28:23 +03:00
|
|
|
let mut errors = vec![];
|
|
|
|
|
2021-10-15 17:21:33 +03:00
|
|
|
let mut lexer = Lexer::new(SourceFileInput::from(&*fm), Default::default());
|
2021-08-25 05:46:17 +03:00
|
|
|
let mut tokens = Tokens {
|
|
|
|
span: Span::new(fm.start_pos, fm.end_pos, Default::default()),
|
|
|
|
tokens: vec![],
|
|
|
|
};
|
|
|
|
|
2022-06-12 06:28:23 +03:00
|
|
|
while let Some(token_and_span) = lexer.next() {
|
|
|
|
tokens.tokens.push(token_and_span);
|
2021-08-25 05:46:17 +03:00
|
|
|
}
|
|
|
|
|
2022-06-12 06:28:23 +03:00
|
|
|
errors.extend(lexer.take_errors());
|
|
|
|
|
2021-10-15 17:21:33 +03:00
|
|
|
let ss_tok: Stylesheet = parse_tokens(
|
|
|
|
&tokens,
|
|
|
|
ParserConfig {
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
&mut errors,
|
|
|
|
)
|
|
|
|
.expect("failed to parse token");
|
2021-08-25 05:46:17 +03:00
|
|
|
|
2021-09-28 12:58:56 +03:00
|
|
|
for err in errors {
|
|
|
|
err.to_diagnostics(&handler).emit();
|
|
|
|
}
|
|
|
|
|
2021-08-25 05:46:17 +03:00
|
|
|
let json_from_tokens = serde_json::to_string_pretty(&ss_tok)
|
|
|
|
.map(NormalizedOutput::from)
|
|
|
|
.expect("failed to serialize stylesheet from tokens");
|
|
|
|
|
|
|
|
assert_eq!(actual_json, json_from_tokens);
|
|
|
|
}
|
2021-08-19 08:16:32 +03:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
let mut d = err.to_diagnostics(&handler);
|
|
|
|
d.note(&format!("current token = {}", parser.dump_cur()));
|
|
|
|
|
|
|
|
d.emit();
|
|
|
|
|
|
|
|
Err(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap();
|
|
|
|
}
|
|
|
|
|
2021-10-15 17:21:33 +03:00
|
|
|
#[testing::fixture("tests/fixture/**/input.css")]
|
|
|
|
fn pass(input: PathBuf) {
|
|
|
|
test_pass(
|
|
|
|
input,
|
|
|
|
ParserConfig {
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[testing::fixture("tests/line-comment/**/input.css")]
|
2021-11-28 04:12:02 +03:00
|
|
|
fn line_comments(input: PathBuf) {
|
2021-10-15 17:21:33 +03:00
|
|
|
test_pass(
|
|
|
|
input,
|
|
|
|
ParserConfig {
|
|
|
|
allow_wrong_line_comments: true,
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-09-29 08:38:49 +03:00
|
|
|
#[testing::fixture("tests/recovery/**/input.css")]
|
|
|
|
fn recovery(input: PathBuf) {
|
|
|
|
let stderr_path = input.parent().unwrap().join("output.swc-stderr");
|
|
|
|
|
|
|
|
let mut errored = false;
|
|
|
|
|
|
|
|
let stderr = testing::run_test2(false, |cm, handler| {
|
|
|
|
if false {
|
|
|
|
// For type inference
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
|
|
|
let ref_json_path = input.parent().unwrap().join("output.json");
|
|
|
|
|
2021-10-15 17:21:33 +03:00
|
|
|
let config = ParserConfig {
|
|
|
|
allow_wrong_line_comments: false,
|
|
|
|
};
|
2021-09-29 08:38:49 +03:00
|
|
|
let fm = cm.load_file(&input).unwrap();
|
2021-10-15 17:21:33 +03:00
|
|
|
let lexer = Lexer::new(SourceFileInput::from(&*fm), config);
|
|
|
|
let mut parser = Parser::new(lexer, config);
|
2021-09-29 08:38:49 +03:00
|
|
|
|
|
|
|
let stylesheet = parser.parse_all();
|
|
|
|
|
|
|
|
match stylesheet {
|
|
|
|
Ok(stylesheet) => {
|
|
|
|
let actual_json = serde_json::to_string_pretty(&stylesheet)
|
|
|
|
.map(NormalizedOutput::from)
|
|
|
|
.expect("failed to serialize stylesheet");
|
|
|
|
|
|
|
|
actual_json.clone().compare_to_file(&ref_json_path).unwrap();
|
|
|
|
|
|
|
|
{
|
2022-06-12 06:28:23 +03:00
|
|
|
let mut errors = vec![];
|
|
|
|
|
2021-10-15 17:21:33 +03:00
|
|
|
let mut lexer = Lexer::new(SourceFileInput::from(&*fm), Default::default());
|
2021-09-29 08:38:49 +03:00
|
|
|
let mut tokens = Tokens {
|
|
|
|
span: Span::new(fm.start_pos, fm.end_pos, Default::default()),
|
|
|
|
tokens: vec![],
|
|
|
|
};
|
|
|
|
|
2022-06-12 06:28:23 +03:00
|
|
|
while let Some(token_and_span) = lexer.next() {
|
|
|
|
tokens.tokens.push(token_and_span);
|
2021-09-29 08:38:49 +03:00
|
|
|
}
|
|
|
|
|
2022-06-12 06:28:23 +03:00
|
|
|
errors.extend(lexer.take_errors());
|
|
|
|
|
2021-10-15 17:21:33 +03:00
|
|
|
let ss_tok: Stylesheet = parse_tokens(
|
|
|
|
&tokens,
|
|
|
|
ParserConfig {
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
&mut errors,
|
|
|
|
)
|
|
|
|
.expect("failed to parse token");
|
2021-09-29 08:38:49 +03:00
|
|
|
|
|
|
|
for err in errors {
|
|
|
|
err.to_diagnostics(&handler).emit();
|
|
|
|
}
|
|
|
|
|
|
|
|
let json_from_tokens = serde_json::to_string_pretty(&ss_tok)
|
|
|
|
.map(NormalizedOutput::from)
|
|
|
|
.expect("failed to serialize stylesheet from tokens");
|
|
|
|
|
|
|
|
assert_eq!(actual_json, json_from_tokens);
|
|
|
|
}
|
|
|
|
|
|
|
|
Err(())
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
let mut d = err.to_diagnostics(&handler);
|
|
|
|
d.note(&format!("current token = {}", parser.dump_cur()));
|
|
|
|
|
|
|
|
d.emit();
|
|
|
|
|
|
|
|
errored = true;
|
|
|
|
|
|
|
|
Err(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_err();
|
|
|
|
|
|
|
|
if errored {
|
|
|
|
panic!("Parser should recover, but failed with {}", stderr);
|
|
|
|
}
|
|
|
|
|
|
|
|
stderr.compare_to_file(&stderr_path).unwrap();
|
|
|
|
}
|
|
|
|
|
2021-08-20 10:48:08 +03:00
|
|
|
struct SpanVisualizer<'a> {
|
|
|
|
handler: &'a Handler,
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! mtd {
|
|
|
|
($T:ty,$name:ident) => {
|
2021-12-07 08:34:16 +03:00
|
|
|
fn $name(&mut self, n: &$T) {
|
2021-08-20 10:48:08 +03:00
|
|
|
self.handler
|
|
|
|
.struct_span_err(n.span(), stringify!($T))
|
|
|
|
.emit();
|
|
|
|
|
|
|
|
n.visit_children_with(self);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Visit for SpanVisualizer<'_> {
|
2022-04-01 14:53:23 +03:00
|
|
|
mtd!(Stylesheet, visit_stylesheet);
|
|
|
|
|
2021-08-20 10:48:08 +03:00
|
|
|
mtd!(AtRule, visit_at_rule);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-04-01 14:53:23 +03:00
|
|
|
mtd!(AtRuleName, visit_at_rule_name);
|
|
|
|
|
|
|
|
mtd!(QualifiedRule, visit_qualified_rule);
|
|
|
|
|
|
|
|
mtd!(StyleBlock, visit_style_block);
|
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(SelectorList, visit_selector_list);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-25 05:05:12 +03:00
|
|
|
mtd!(CompoundSelectorList, visit_compound_selector_list);
|
|
|
|
|
|
|
|
mtd!(RelativeSelectorList, visit_relative_selector_list);
|
|
|
|
|
2021-08-20 10:48:08 +03:00
|
|
|
mtd!(ComplexSelector, visit_complex_selector);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2021-11-07 18:29:25 +03:00
|
|
|
mtd!(Combinator, visit_combinator);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-25 05:05:12 +03:00
|
|
|
mtd!(RelativeSelector, visit_relative_selector);
|
|
|
|
|
2021-08-20 10:48:08 +03:00
|
|
|
mtd!(CompoundSelector, visit_compound_selector);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(TypeSelector, visit_type_selector);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(TagNameSelector, visit_tag_name_selector);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(NsPrefix, visit_ns_prefix);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(WqName, visit_wq_name);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(UniversalSelector, visit_universal_selector);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(IdSelector, visit_id_selector);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(ClassSelector, visit_class_selector);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(AttributeSelector, visit_attribute_selector);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(AttributeSelectorMatcher, visit_attribute_selector_matcher);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(AttributeSelectorValue, visit_attribute_selector_value);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(AttributeSelectorModifier, visit_attribute_selector_modifier);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(SubclassSelector, visit_subclass_selector);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(NestingSelector, visit_nesting_selector);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(PseudoClassSelector, visit_pseudo_class_selector);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-25 05:05:12 +03:00
|
|
|
mtd!(
|
|
|
|
PseudoClassSelectorChildren,
|
|
|
|
visit_pseudo_class_selector_children
|
|
|
|
);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(AnPlusB, visit_an_plus_b);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-23 19:20:40 +03:00
|
|
|
mtd!(AnPlusBNotation, visit_an_plus_b_notation);
|
|
|
|
|
2022-02-25 05:05:12 +03:00
|
|
|
mtd!(PseudoElementSelector, visit_pseudo_element_selector);
|
|
|
|
|
|
|
|
mtd!(
|
|
|
|
PseudoElementSelectorChildren,
|
|
|
|
visit_pseudo_element_selector_children
|
|
|
|
);
|
|
|
|
|
2022-02-06 07:24:51 +03:00
|
|
|
mtd!(Delimiter, visit_delimiter);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-22 17:10:25 +03:00
|
|
|
mtd!(SimpleBlock, visit_simple_block);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-03-01 18:26:17 +03:00
|
|
|
mtd!(ComponentValue, visit_component_value);
|
|
|
|
|
2021-12-01 20:07:49 +03:00
|
|
|
mtd!(Function, visit_function);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-22 22:45:33 +03:00
|
|
|
mtd!(Color, visit_color);
|
|
|
|
|
2022-01-31 06:10:37 +03:00
|
|
|
mtd!(HexColor, visit_hex_color);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-03-04 00:24:22 +03:00
|
|
|
mtd!(AlphaValue, visit_alpha_value);
|
|
|
|
|
|
|
|
mtd!(Hue, visit_hue);
|
|
|
|
|
|
|
|
mtd!(CmykComponent, visit_cmyk_component);
|
|
|
|
|
2022-02-26 16:51:59 +03:00
|
|
|
mtd!(Integer, visit_integer);
|
|
|
|
|
2022-01-24 17:27:10 +03:00
|
|
|
mtd!(Number, visit_number);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-24 17:27:10 +03:00
|
|
|
mtd!(Ratio, visit_ratio);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-09 13:43:15 +03:00
|
|
|
mtd!(Percentage, visit_percentage);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2021-10-26 21:38:05 +03:00
|
|
|
mtd!(Declaration, visit_declaration);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-05 17:22:47 +03:00
|
|
|
mtd!(DeclarationName, visit_declaration_name);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-05 17:22:47 +03:00
|
|
|
mtd!(ImportantFlag, visit_important_flag);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2021-08-20 10:48:08 +03:00
|
|
|
mtd!(Rule, visit_rule);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2021-08-20 10:48:08 +03:00
|
|
|
mtd!(Str, visit_str);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2021-11-12 13:09:52 +03:00
|
|
|
mtd!(Ident, visit_ident);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-21 04:55:49 +03:00
|
|
|
mtd!(CustomIdent, visit_custom_ident);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-26 14:35:49 +03:00
|
|
|
mtd!(DashedIdent, visit_dashed_ident);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2021-08-20 10:48:08 +03:00
|
|
|
mtd!(Tokens, visit_tokens);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-30 15:15:05 +03:00
|
|
|
mtd!(Dimension, visit_dimension);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-08 14:57:57 +03:00
|
|
|
mtd!(Length, visit_length);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-08 14:57:57 +03:00
|
|
|
mtd!(Angle, visit_angle);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-08 14:57:57 +03:00
|
|
|
mtd!(Time, visit_time);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-08 14:57:57 +03:00
|
|
|
mtd!(Frequency, visit_frequency);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-08 14:57:57 +03:00
|
|
|
mtd!(Resolution, visit_resolution);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-08 14:57:57 +03:00
|
|
|
mtd!(Flex, visit_flex);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-08 14:57:57 +03:00
|
|
|
mtd!(UnknownDimension, visit_unknown_dimension);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-25 16:50:23 +03:00
|
|
|
mtd!(Url, visit_url);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2021-08-20 10:48:08 +03:00
|
|
|
mtd!(UrlValue, visit_url_value);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-25 16:50:23 +03:00
|
|
|
mtd!(UrlValueRaw, visit_url_value_raw);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-25 16:50:23 +03:00
|
|
|
mtd!(UrlModifier, visit_url_modifier);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-27 08:16:22 +03:00
|
|
|
mtd!(UnicodeRange, visit_unicode_range);
|
2022-02-09 15:23:14 +03:00
|
|
|
|
2022-02-14 09:19:02 +03:00
|
|
|
mtd!(CalcSum, visit_calc_sum);
|
|
|
|
|
|
|
|
mtd!(CalcProductOrOperator, visit_calc_product_or_operator);
|
|
|
|
|
|
|
|
mtd!(CalcProduct, visit_calc_product);
|
|
|
|
|
|
|
|
mtd!(CalcOperator, visit_calc_operator);
|
|
|
|
|
|
|
|
mtd!(CalcValueOrOperator, visit_calc_value_or_operator);
|
|
|
|
|
|
|
|
mtd!(CalcValue, visit_calc_value);
|
|
|
|
|
2022-01-14 14:21:41 +03:00
|
|
|
mtd!(LayerName, visit_layer_name);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-14 14:21:41 +03:00
|
|
|
mtd!(LayerNameList, visit_layer_name_list);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-14 14:21:41 +03:00
|
|
|
mtd!(LayerPrelude, visit_layer_prelude);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaQueryList, visit_media_query_list);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaQuery, visit_media_query);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaCondition, visit_media_condition);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaConditionWithoutOr, visit_media_condition_without_or);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaConditionAllType, visit_media_condition_all_type);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(
|
|
|
|
MediaConditionWithoutOrType,
|
|
|
|
visit_media_condition_without_or_type
|
|
|
|
);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaNot, visit_media_not);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaAnd, visit_media_and);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaOr, visit_media_or);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaInParens, visit_media_in_parens);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaFeatureName, visit_media_feature_name);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaFeatureValue, visit_media_feature_value);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaFeature, visit_media_feature);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaFeaturePlain, visit_media_feature_plain);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaFeatureBoolean, visit_media_feature_boolean);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(MediaFeatureRange, visit_media_feature_range);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-20 05:57:24 +03:00
|
|
|
mtd!(
|
|
|
|
MediaFeatureRangeInterval,
|
|
|
|
visit_media_feature_range_interval
|
|
|
|
);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-21 03:57:29 +03:00
|
|
|
mtd!(SupportsCondition, visit_supports_condition);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-21 03:57:29 +03:00
|
|
|
mtd!(SupportsConditionType, visit_supports_condition_type);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-21 03:57:29 +03:00
|
|
|
mtd!(SupportsNot, visit_supports_not);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-21 03:57:29 +03:00
|
|
|
mtd!(SupportsAnd, visit_supports_and);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-21 03:57:29 +03:00
|
|
|
mtd!(SupportsOr, visit_supports_or);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-21 03:57:29 +03:00
|
|
|
mtd!(SupportsInParens, visit_supports_in_parens);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-01-21 03:57:29 +03:00
|
|
|
mtd!(SupportsFeature, visit_supports_feature);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 23:22:30 +03:00
|
|
|
mtd!(PageSelectorList, visit_page_selector_list);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2021-08-20 10:48:08 +03:00
|
|
|
mtd!(PageSelector, visit_page_selector);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 23:22:30 +03:00
|
|
|
mtd!(PageSelectorType, visit_page_selector_type);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2022-02-06 23:22:30 +03:00
|
|
|
mtd!(PageSelectorPseudo, visit_page_selector_pseudo);
|
2022-02-09 09:33:32 +03:00
|
|
|
|
2021-12-07 08:34:16 +03:00
|
|
|
fn visit_token_and_span(&mut self, n: &TokenAndSpan) {
|
2021-08-20 10:48:08 +03:00
|
|
|
self.handler
|
|
|
|
.struct_span_err(n.span, &format!("{:?}", n.token))
|
|
|
|
.emit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[testing::fixture("tests/fixture/**/input.css")]
|
|
|
|
fn span(input: PathBuf) {
|
|
|
|
let dir = input.parent().unwrap().to_path_buf();
|
|
|
|
|
|
|
|
let output = testing::run_test2(false, |cm, handler| {
|
2021-10-15 17:21:33 +03:00
|
|
|
// Type annotation
|
2021-08-20 10:48:08 +03:00
|
|
|
if false {
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
|
2021-10-15 17:21:33 +03:00
|
|
|
let config = ParserConfig {
|
|
|
|
..Default::default()
|
|
|
|
};
|
|
|
|
|
2021-08-20 10:48:08 +03:00
|
|
|
let fm = cm.load_file(&input).unwrap();
|
2021-10-15 17:21:33 +03:00
|
|
|
let lexer = Lexer::new(SourceFileInput::from(&*fm), config);
|
|
|
|
let mut parser = Parser::new(lexer, config);
|
2021-08-20 10:48:08 +03:00
|
|
|
|
|
|
|
let stylesheet = parser.parse_all();
|
|
|
|
|
|
|
|
match stylesheet {
|
|
|
|
Ok(stylesheet) => {
|
2021-12-07 08:34:16 +03:00
|
|
|
stylesheet.visit_with(&mut SpanVisualizer { handler: &handler });
|
2021-08-20 10:48:08 +03:00
|
|
|
|
|
|
|
Err(())
|
|
|
|
}
|
|
|
|
Err(err) => {
|
|
|
|
let mut d = err.to_diagnostics(&handler);
|
|
|
|
d.note(&format!("current token = {}", parser.dump_cur()));
|
|
|
|
|
|
|
|
d.emit();
|
|
|
|
|
|
|
|
panic!();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_err();
|
|
|
|
|
|
|
|
output
|
|
|
|
.compare_to_file(&dir.join("span.rust-debug"))
|
|
|
|
.unwrap();
|
|
|
|
}
|