From 622d44ac635fba6e8439e228e45786145a426d03 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Mon, 3 Aug 2020 01:18:00 -0400 Subject: [PATCH] disallow selectors and styles in functions --- src/parse/mod.rs | 7 +++++++ tests/functions.rs | 13 +++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 0fd3eb5..c8793bb 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -245,6 +245,13 @@ impl<'a> Parser<'a> { // dart-sass seems to special-case the error message here? '!' | '{' => return Err(("expected \"}\".", *pos).into()), _ => { + if self.flags.in_function() { + return Err(( + "Functions can only contain variable declarations and control directives.", + self.span_before + ) + .into()); + } if self.flags.in_keyframes() { match self.is_selector_or_style()? { SelectorOrStyle::Style(property, value) => { diff --git a/tests/functions.rs b/tests/functions.rs index 007dc25..973dbe0 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -305,3 +305,16 @@ error!( }", "Error: This at-rule is not allowed here." ); +error!( + disallows_selectors, + "@function foo($a) { + functiona { + @return $a; + } + } + + a { + color: foo(nul); + }", + "Error: Functions can only contain variable declarations and control directives." +);