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;
|
pub(crate) use crate::token::Token;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
devour_whitespace, eat_comment, eat_ident, eat_ident_no_interpolation, eat_variable_value,
|
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,
|
parse_quoted_string, read_until_closing_curly_brace, read_until_closing_paren,
|
||||||
read_until_closing_paren
|
read_until_newline, VariableDecl,
|
||||||
};
|
};
|
||||||
use crate::value::Value;
|
use crate::value::Value;
|
||||||
|
|
||||||
@ -358,12 +358,11 @@ impl<'a> StyleSheetParser<'a> {
|
|||||||
AtRuleKind::Import => {
|
AtRuleKind::Import => {
|
||||||
devour_whitespace(&mut self.lexer);
|
devour_whitespace(&mut self.lexer);
|
||||||
let mut file_name = String::new();
|
let mut file_name = String::new();
|
||||||
match self
|
let next = match self.lexer.next() {
|
||||||
.lexer
|
Some(v) => v,
|
||||||
.next()
|
None => todo!("expected input after @import")
|
||||||
.unwrap()
|
};
|
||||||
.kind
|
match next.kind {
|
||||||
{
|
|
||||||
q @ '"' | q @ '\'' => {
|
q @ '"' | q @ '\'' => {
|
||||||
file_name.push_str(
|
file_name.push_str(
|
||||||
&parse_quoted_string(
|
&parse_quoted_string(
|
||||||
@ -373,11 +372,15 @@ impl<'a> StyleSheetParser<'a> {
|
|||||||
&Selector::new())?
|
&Selector::new())?
|
||||||
.node.unquote().to_css_string(span)?);
|
.node.unquote().to_css_string(span)?);
|
||||||
}
|
}
|
||||||
_ => todo!("expected ' or \" after @import"),
|
_ => return Err(("Expected string.", next.pos()).into()),
|
||||||
}
|
}
|
||||||
if self.lexer.next().unwrap().kind != ';' {
|
if let Some(t) = self.lexer.peek() {
|
||||||
todo!("no semicolon after @import");
|
if t.kind == ';' {
|
||||||
|
self.lexer.next();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
devour_whitespace(&mut self.lexer);
|
||||||
|
|
||||||
let (new_rules, new_scope) = import(file_name)?;
|
let (new_rules, new_scope) = import(file_name)?;
|
||||||
rules.extend(new_rules);
|
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]
|
#[test]
|
||||||
fn single_quotes_import() {
|
fn single_quotes_import() {
|
||||||
let input = "@import 'single_quotes_import';\na {\n color: $a;\n}";
|
let input = "@import 'single_quotes_import';\na {\n color: $a;\n}";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user