@@ -7,12 +7,15 @@ use crate::printer::Printer;
77use crate :: traits:: { Parse , ToCss } ;
88use std:: fmt:: Write ;
99use crate :: selector:: { Selectors , SelectorParser } ;
10- use crate :: rules:: keyframes:: { KeyframeListParser , KeyframesRule } ;
11- use crate :: rules:: font_face:: { FontFaceRule , FontFaceDeclarationParser } ;
12- use crate :: rules:: page:: { PageSelector , PageRule } ;
13- use crate :: rules:: supports:: { SupportsCondition , SupportsRule } ;
14- use crate :: rules:: counter_style:: CounterStyleRule ;
15- use crate :: rules:: namespace:: NamespaceRule ;
10+ use crate :: rules:: {
11+ keyframes:: { KeyframeListParser , KeyframesRule } ,
12+ font_face:: { FontFaceRule , FontFaceDeclarationParser } ,
13+ page:: { PageSelector , PageRule } ,
14+ supports:: { SupportsCondition , SupportsRule } ,
15+ counter_style:: CounterStyleRule ,
16+ namespace:: NamespaceRule ,
17+ import:: ImportRule
18+ } ;
1619use crate :: values:: ident:: CustomIdent ;
1720use crate :: declaration:: { Declaration , DeclarationHandler } ;
1821use crate :: properties:: VendorPrefix ;
@@ -99,7 +102,7 @@ pub enum AtRulePrelude {
99102 /// A @document rule, with its conditional.
100103 Document , //(DocumentCondition),
101104 /// A @import rule prelude.
102- Import ( String , MediaList ) , //(CssUrl, Arc<Locked<MediaList> >),
105+ Import ( String , MediaList , Option < SupportsCondition > ) ,
103106 /// A @namespace rule prelude.
104107 Namespace ( Option < String > , String ) ,
105108}
@@ -118,28 +121,30 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser {
118121 match_ignore_ascii_case ! { & * name,
119122 "import" => {
120123 let url_string = input. expect_url_or_string( ) ?. as_ref( ) . to_owned( ) ;
124+ let supports = if input. try_parse( |input| input. expect_function_matching( "supports" ) ) . is_ok( ) {
125+ Some ( input. parse_nested_block( |input| {
126+ input. try_parse( SupportsCondition :: parse) . or_else( |_| SupportsCondition :: parse_declaration( input) )
127+ } ) ?)
128+ } else {
129+ None
130+ } ;
121131 let media = MediaList :: parse( input) ;
122- return Ok ( AtRuleType :: WithoutBlock ( AtRulePrelude :: Import ( url_string, media) ) ) ;
132+ return Ok ( AtRuleType :: WithoutBlock ( AtRulePrelude :: Import ( url_string, media, supports ) ) ) ;
123133 } ,
124134 "namespace" => {
125135 let prefix = input. try_parse( |input| input. expect_ident_cloned( ) ) . map( |v| v. as_ref( ) . to_owned( ) ) . ok( ) ;
126136 let namespace = input. expect_url_or_string( ) ?. as_ref( ) . to_owned( ) ;
127137 let prelude = AtRulePrelude :: Namespace ( prefix, namespace) ;
128138 return Ok ( AtRuleType :: WithoutBlock ( prelude) ) ;
129139 } ,
130- // // @charset is removed by rust-cssparser if it’s the first rule in the stylesheet
131- // // anything left is invalid.
132- // "charset" => {
133- // self.dom_error = Some(RulesMutateError::HierarchyRequest);
134- // return Err(input.new_custom_error(StyleParseErrorKind::UnexpectedCharsetRule))
135- // },
140+ // @charset is removed by rust-cssparser if it’s the first rule in the stylesheet
141+ // anything left is invalid.
142+ "charset" => {
143+ return Err ( input. new_error( BasicParseErrorKind :: AtRuleInvalid ( name) ) )
144+ } ,
136145 _ => { }
137146 }
138147
139- // if !self.check_state(State::Body) {
140- // return Err(input.new_custom_error(StyleParseErrorKind::UnspecifiedError));
141- // }
142-
143148 AtRuleParser :: parse_prelude ( & mut self . nested ( ) , name, input)
144149 }
145150
@@ -161,9 +166,10 @@ impl<'a, 'i> AtRuleParser<'i> for TopLevelRuleParser {
161166 start : & ParserState ,
162167 ) -> Self :: AtRule {
163168 let rule = match prelude {
164- AtRulePrelude :: Import ( url, media) => {
169+ AtRulePrelude :: Import ( url, media, supports ) => {
165170 CssRule :: Import ( ImportRule {
166171 url,
172+ supports,
167173 media
168174 } )
169175 } ,
@@ -232,21 +238,6 @@ impl ToCss for MediaRule {
232238 }
233239}
234240
235- #[ derive( Debug , PartialEq ) ]
236- pub struct ImportRule {
237- pub url : String ,
238- pub media : MediaList
239- }
240-
241- impl ToCss for ImportRule {
242- fn to_css < W > ( & self , dest : & mut Printer < W > ) -> fmt:: Result where W : fmt:: Write {
243- dest. write_str ( "@import " ) ?;
244- serialize_string ( & self . url , dest) ?;
245- // dest.write_str(&self.media)?;
246- dest. write_str ( ";" )
247- }
248- }
249-
250241#[ derive( Debug , PartialEq ) ]
251242pub struct StyleRule {
252243 pub selectors : SelectorList < Selectors > ,
0 commit comments