diff --git a/src/parse/mixin.rs b/src/parse/mixin.rs index 610099c..52f12b6 100644 --- a/src/parse/mixin.rs +++ b/src/parse/mixin.rs @@ -18,6 +18,19 @@ impl<'a> Parser<'a> { pub(super) fn parse_mixin(&mut self) -> SassResult<()> { self.whitespace(); let Spanned { node: name, span } = self.parse_identifier()?; + + if self.flags.in_mixin() { + return Err(("Mixins may not contain mixin declarations.", span).into()); + } + + if self.flags.in_function() { + return Err(("This at-rule is not allowed here.", span).into()); + } + + if self.flags.in_control_flow() { + return Err(("Mixins may not be declared in control directives.", span).into()); + } + self.whitespace(); let args = match self.toks.next() { Some(Token { kind: '(', .. }) => self.parse_func_args()?, diff --git a/tests/mixins.rs b/tests/mixins.rs index 35dc6ec..266a820 100644 --- a/tests/mixins.rs +++ b/tests/mixins.rs @@ -449,3 +449,32 @@ test!( }", "a {\n color: foo;\n color: foo;\n}\n" ); +error!( + mixin_in_function, + "@function foo() { + @mixin bar {} + } + a { + color: foo(); + } + ", + "Error: This at-rule is not allowed here." +); +error!( + mixin_in_mixin, + "@mixin foo { + @mixin bar {} + } + a { + @include foo; + } + ", + "Error: Mixins may not contain mixin declarations." +); +error!( + mixin_in_control_directives, + "@if true { + @mixin bar {} + }", + "Error: Mixins may not be declared in control directives." +);