change where parent selectors are resolved
This commit is contained in:
parent
991be977ac
commit
e94dd80a53
@ -80,23 +80,11 @@ impl Css {
|
|||||||
|
|
||||||
fn parse_stmt(&mut self, stmt: Stmt, extender: &mut Extender) -> SassResult<Vec<Toplevel>> {
|
fn parse_stmt(&mut self, stmt: Stmt, extender: &mut Extender) -> SassResult<Vec<Toplevel>> {
|
||||||
Ok(match stmt {
|
Ok(match stmt {
|
||||||
Stmt::RuleSet {
|
Stmt::RuleSet { selector, body } => {
|
||||||
selector,
|
|
||||||
super_selector,
|
|
||||||
body,
|
|
||||||
} => {
|
|
||||||
if body.is_empty() {
|
if body.is_empty() {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
}
|
}
|
||||||
let selector = if extender.is_empty() {
|
let selector = selector.remove_placeholders();
|
||||||
selector.resolve_parent_selectors(&super_selector, true)?
|
|
||||||
} else {
|
|
||||||
Selector(extender.add_selector(
|
|
||||||
selector.resolve_parent_selectors(&super_selector, true)?.0,
|
|
||||||
None,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
.remove_placeholders();
|
|
||||||
if selector.is_empty() {
|
if selector.is_empty() {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,6 @@ pub(crate) enum Comment {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub(crate) enum Stmt {
|
pub(crate) enum Stmt {
|
||||||
RuleSet {
|
RuleSet {
|
||||||
super_selector: Selector,
|
|
||||||
selector: Selector,
|
selector: Selector,
|
||||||
body: Vec<Self>,
|
body: Vec<Self>,
|
||||||
},
|
},
|
||||||
@ -272,11 +271,7 @@ impl<'a> Parser<'a> {
|
|||||||
self.scopes.pop();
|
self.scopes.pop();
|
||||||
self.super_selectors.pop();
|
self.super_selectors.pop();
|
||||||
self.at_root = self.super_selectors.is_empty();
|
self.at_root = self.super_selectors.is_empty();
|
||||||
stmts.push(Stmt::RuleSet {
|
stmts.push(Stmt::RuleSet { selector, body });
|
||||||
selector,
|
|
||||||
body,
|
|
||||||
super_selector,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@ -378,7 +373,10 @@ impl<'a> Parser<'a> {
|
|||||||
|
|
||||||
// todo: we should be registering the selector here, but that would require being given
|
// todo: we should be registering the selector here, but that would require being given
|
||||||
// an `Rc<RefCell<Selector>>`, which we haven't implemented yet.
|
// an `Rc<RefCell<Selector>>`, which we haven't implemented yet.
|
||||||
Ok(Selector(selector))
|
Ok(Selector(selector).resolve_parent_selectors(
|
||||||
|
self.super_selectors.last(),
|
||||||
|
!self.at_root || self.at_root_has_selector,
|
||||||
|
)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Eat and return the contents of a comment.
|
/// Eat and return the contents of a comment.
|
||||||
@ -1029,7 +1027,6 @@ impl<'a> Parser<'a> {
|
|||||||
body = vec![Stmt::RuleSet {
|
body = vec![Stmt::RuleSet {
|
||||||
selector: self.super_selectors.last().clone(),
|
selector: self.super_selectors.last().clone(),
|
||||||
body,
|
body,
|
||||||
super_selector: Selector::new(self.span_before),
|
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1082,7 +1079,6 @@ impl<'a> Parser<'a> {
|
|||||||
body = vec![Stmt::RuleSet {
|
body = vec![Stmt::RuleSet {
|
||||||
selector: self.super_selectors.last().clone(),
|
selector: self.super_selectors.last().clone(),
|
||||||
body,
|
body,
|
||||||
super_selector: Selector::new(self.span_before),
|
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1144,11 +1140,11 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
Stmt::RuleSet { selector, body, .. } if !at_root_has_selector => {
|
Stmt::RuleSet { selector, body, .. } if !at_root_has_selector => {
|
||||||
Some(Ok(Stmt::RuleSet {
|
Some(Ok(Stmt::RuleSet {
|
||||||
super_selector: Selector::new(self.span_before),
|
selector,
|
||||||
selector: match selector.resolve_parent_selectors(&at_rule_selector, false) {
|
// selector: match selector.resolve_parent_selectors(&at_rule_selector, false) {
|
||||||
Ok(v) => v,
|
// Ok(v) => v,
|
||||||
Err(e) => return Some(Err(e)),
|
// Err(e) => return Some(Err(e)),
|
||||||
},
|
// },
|
||||||
body,
|
body,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
@ -1158,7 +1154,6 @@ impl<'a> Parser<'a> {
|
|||||||
let mut stmts = vec![Stmt::RuleSet {
|
let mut stmts = vec![Stmt::RuleSet {
|
||||||
selector: at_rule_selector,
|
selector: at_rule_selector,
|
||||||
body: styles,
|
body: styles,
|
||||||
super_selector: Selector::new(self.span_before),
|
|
||||||
}];
|
}];
|
||||||
stmts.extend(raw_stmts);
|
stmts.extend(raw_stmts);
|
||||||
Ok(stmts)
|
Ok(stmts)
|
||||||
@ -1279,7 +1274,6 @@ impl<'a> Parser<'a> {
|
|||||||
body = vec![Stmt::RuleSet {
|
body = vec![Stmt::RuleSet {
|
||||||
selector: self.super_selectors.last().clone(),
|
selector: self.super_selectors.last().clone(),
|
||||||
body,
|
body,
|
||||||
super_selector: Selector::new(self.span_before),
|
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user