emit proper error for missing quotes on @ import
This commit is contained in:
parent
ecf36cd6d3
commit
2fb64934d7
25
src/lib.rs
25
src/lib.rs
@ -105,8 +105,8 @@ use crate::style::Style;
|
||||
pub(crate) use crate::token::Token;
|
||||
use crate::utils::{
|
||||
devour_whitespace, eat_comment, eat_ident, eat_ident_no_interpolation, eat_variable_value,
|
||||
parse_quoted_string, read_until_closing_curly_brace, read_until_newline, VariableDecl,
|
||||
read_until_closing_paren
|
||||
parse_quoted_string, read_until_closing_curly_brace, read_until_closing_paren,
|
||||
read_until_newline, VariableDecl,
|
||||
};
|
||||
use crate::value::Value;
|
||||
|
||||
@ -358,12 +358,11 @@ impl<'a> StyleSheetParser<'a> {
|
||||
AtRuleKind::Import => {
|
||||
devour_whitespace(&mut self.lexer);
|
||||
let mut file_name = String::new();
|
||||
match self
|
||||
.lexer
|
||||
.next()
|
||||
.unwrap()
|
||||
.kind
|
||||
{
|
||||
let next = match self.lexer.next() {
|
||||
Some(v) => v,
|
||||
None => todo!("expected input after @import")
|
||||
};
|
||||
match next.kind {
|
||||
q @ '"' | q @ '\'' => {
|
||||
file_name.push_str(
|
||||
&parse_quoted_string(
|
||||
@ -373,11 +372,15 @@ impl<'a> StyleSheetParser<'a> {
|
||||
&Selector::new())?
|
||||
.node.unquote().to_css_string(span)?);
|
||||
}
|
||||
_ => todo!("expected ' or \" after @import"),
|
||||
_ => return Err(("Expected string.", next.pos()).into()),
|
||||
}
|
||||
if self.lexer.next().unwrap().kind != ';' {
|
||||
todo!("no semicolon after @import");
|
||||
if let Some(t) = self.lexer.peek() {
|
||||
if t.kind == ';' {
|
||||
self.lexer.next();
|
||||
}
|
||||
}
|
||||
|
||||
devour_whitespace(&mut self.lexer);
|
||||
|
||||
let (new_rules, new_scope) = import(file_name)?;
|
||||
rules.extend(new_rules);
|
||||
|
@ -41,6 +41,23 @@ fn import_no_semicolon() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_no_quotes() {
|
||||
let input = "@import import_no_quotes";
|
||||
tempfile!("import_no_quotes", "$a: red;");
|
||||
match grass::StyleSheet::new(input.to_string()) {
|
||||
Ok(..) => panic!("did not fail"),
|
||||
Err(e) => assert_eq!(
|
||||
"Error: Expected string.",
|
||||
e.to_string()
|
||||
.chars()
|
||||
.take_while(|c| *c != '\n')
|
||||
.collect::<String>()
|
||||
.as_str()
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_quotes_import() {
|
||||
let input = "@import 'single_quotes_import';\na {\n color: $a;\n}";
|
||||
|
Loading…
x
Reference in New Issue
Block a user