diff --git a/src/parse/function.rs b/src/parse/function.rs index 44aeac4..7add40d 100644 --- a/src/parse/function.rs +++ b/src/parse/function.rs @@ -7,9 +7,8 @@ use crate::{ error::SassResult, lexer::Lexer, scope::Scopes, - utils::{read_until_closing_curly_brace, read_until_semicolon_or_closing_curly_brace}, + utils::{read_until_closing_curly_brace}, value::{SassFunction, Value}, - Token, }; use super::{common::ContextFlags, Parser, Stmt}; @@ -72,11 +71,10 @@ impl<'a> Parser<'a> { } pub(super) fn parse_return(&mut self) -> SassResult> { - let toks = read_until_semicolon_or_closing_curly_brace(self.toks)?; - let v = self.parse_value_from_vec(toks, true)?; - if let Some(Token { kind: ';', .. }) = self.toks.peek() { - self.toks.next(); - } + let v = self.parse_value(true, &|_| false)?; + + self.consume_char_if_exists(';'); + Ok(Box::new(v.node)) } diff --git a/src/parse/mixin.rs b/src/parse/mixin.rs index 7fa248b..91673bd 100644 --- a/src/parse/mixin.rs +++ b/src/parse/mixin.rs @@ -131,11 +131,8 @@ impl<'a> Parser<'a> { None }; - // todo: self.consume_if_exists - if let Some(Token { kind: ';', .. }) = self.toks.peek() { - self.toks.next(); - } - + self.consume_char_if_exists(';'); + let UserDefinedMixin { body, args: fn_args, diff --git a/src/parse/mod.rs b/src/parse/mod.rs index 475c4b4..446f8e1 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -245,10 +245,14 @@ impl<'a> Parser<'a> { .into()); } - read_until_semicolon_or_closing_curly_brace(self.toks)?; - if let Some(Token { kind: ';', .. }) = self.toks.peek() { - self.toks.next(); + let val = self.parse_value(false, &|_| false)?; + + self.consume_char_if_exists(';'); + + if !val.node.is_quoted_string() { + return Err(("Expected string.", val.span).into()); } + continue; } AtRuleKind::Media => stmts.push(self.parse_media()?), diff --git a/src/value/mod.rs b/src/value/mod.rs index ef9d68d..d30e0aa 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -572,4 +572,8 @@ impl Value { _ => return Ok(None), })) } + + pub fn is_quoted_string(&self) -> bool { + matches!(self, Value::String(_, QuoteKind::Quoted)) + } } diff --git a/tests/charset.rs b/tests/charset.rs index a08e4a1..321a7c1 100644 --- a/tests/charset.rs +++ b/tests/charset.rs @@ -2,17 +2,27 @@ mod macros; test!( - utf8_input, + charset_exists_when_output_not_ascii, "a {\n color: 🦆;\n}\n", "@charset \"UTF-8\";\na {\n color: 🦆;\n}\n" ); test!( - ascii_charset_utf8, + charset_utf8_is_removed_when_ascii, "@charset \"UTF-8\";\na {\n color: red;\n}\n", "a {\n color: red;\n}\n" ); test!( - unknown_charset, + unknown_charset_is_removed, "@charset \"foo\";\na {\n color: red;\n}\n", "a {\n color: red;\n}\n" ); +error!( + invalid_charset_value, + "@charset 1;", + "Error: Expected string." +); +error!( + invalid_charset_value_unquoted_string, + "@charset a;", + "Error: Expected string." +);