Allow @for to include only styles
This commit is contained in:
parent
7923d096a7
commit
82813fee6f
@ -164,19 +164,21 @@ impl AtRule {
|
||||
};
|
||||
let mut body = Vec::new();
|
||||
let mut n = 1;
|
||||
for tok in toks {
|
||||
while let Some(tok) = toks.next() {
|
||||
match tok.kind {
|
||||
TokenKind::Symbol(Symbol::OpenCurlyBrace) => n += 1,
|
||||
TokenKind::Symbol(Symbol::CloseCurlyBrace) => n -= 1,
|
||||
TokenKind::Interpolation => n += 1,
|
||||
_ => {}
|
||||
}
|
||||
body.push(tok);
|
||||
if n == 0 {
|
||||
break;
|
||||
}
|
||||
body.push(tok);
|
||||
}
|
||||
|
||||
devour_whitespace_or_comment(toks);
|
||||
|
||||
let mut scope = scope.clone();
|
||||
if from < to {
|
||||
for i in from..(to + through) {
|
||||
|
@ -145,8 +145,7 @@ impl Css {
|
||||
writeln!(buf, "{}@{} {} {{", padding, u.name, u.params)?;
|
||||
}
|
||||
Css::from_stylesheet(StyleSheet::from_stmts(u.body.clone()))
|
||||
.pretty_print(buf, nesting + 1)
|
||||
.unwrap();
|
||||
.pretty_print(buf, nesting + 1)?;
|
||||
writeln!(buf, "{}}}", padding)?;
|
||||
}
|
||||
_ => todo!(),
|
||||
|
@ -498,7 +498,10 @@ impl<'a> StyleSheetParser<'a> {
|
||||
while let Some(expr) = eat_expr(&mut self.lexer, scope, super_selector)? {
|
||||
match expr {
|
||||
Expr::Style(s) => stmts.push(Stmt::Style(*s)),
|
||||
Expr::AtRule(s) => stmts.push(Stmt::AtRule(s)),
|
||||
Expr::AtRule(a) => match a {
|
||||
AtRule::For(s) => stmts.extend(s),
|
||||
r => stmts.push(Stmt::AtRule(r)),
|
||||
},
|
||||
Expr::Styles(s) => stmts.extend(s.into_iter().map(Stmt::Style)),
|
||||
Expr::MixinDecl(name, mixin) => {
|
||||
scope.insert_mixin(&name, *mixin);
|
||||
|
@ -160,7 +160,7 @@ impl Value {
|
||||
let kind = if let Some(tok) = toks.next() {
|
||||
tok.kind
|
||||
} else {
|
||||
return Err("Unexpected EOF".into());
|
||||
panic!("Unexpected EOF");
|
||||
};
|
||||
match kind {
|
||||
TokenKind::Number(val) => {
|
||||
|
@ -33,3 +33,8 @@ test!(
|
||||
"@for $x from 1 to 3 {\n $limit: $x;\n\n a {\n color: $limit;\n }\n}\n",
|
||||
"a {\n color: 1;\n}\n\na {\n color: 2;\n}\n"
|
||||
);
|
||||
test!(
|
||||
for_styles,
|
||||
"a {\n @for $i from 1 to 3 {\n color: $i;\n }\n}\n",
|
||||
"a {\n color: 1;\n color: 2;\n}\n"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user