diff --git a/src/parse/import.rs b/src/parse/import.rs index 573a026..debad53 100644 --- a/src/parse/import.rs +++ b/src/parse/import.rs @@ -64,7 +64,7 @@ fn find_import(file_path: &PathBuf, name: &OsStr, load_paths: &[&Path]) -> Optio } impl<'a> Parser<'a> { - pub fn _parse_single_import(&mut self, file_name: &str, span: Span) -> SassResult> { + fn parse_single_import(&mut self, file_name: &str, span: Span) -> SassResult> { let path: &Path = file_name.as_ref(); let path_buf = if path.is_absolute() { @@ -76,6 +76,7 @@ impl<'a> Parser<'a> { .unwrap_or_else(|| Path::new("")) .join(path) }; + let name = path_buf.file_name().unwrap_or_else(|| OsStr::new("..")); if let Some(name) = find_import(&path_buf, name, &self.options.load_paths) { @@ -108,8 +109,10 @@ impl<'a> Parser<'a> { Err(("Can't find stylesheet to import.", span).into()) } + pub(super) fn import(&mut self) -> SassResult> { self.whitespace(); + match self.toks.peek() { Some(Token { kind: '\'', .. }) | Some(Token { kind: '"', .. }) @@ -127,14 +130,14 @@ impl<'a> Parser<'a> { if s.ends_with(".css") || s.starts_with("http://") || s.starts_with("https://") { Ok(vec![Stmt::Import(format!("\"{}\"", s))]) } else { - self._parse_single_import(&s, span) + self.parse_single_import(&s, span) } } Value::String(s, QuoteKind::None) => { if s.starts_with("url(") { Ok(vec![Stmt::Import(s)]) } else { - self._parse_single_import(&s, span) + self.parse_single_import(&s, span) } } Value::List(v, Comma, _) => { @@ -148,14 +151,14 @@ impl<'a> Parser<'a> { { list_of_imports.push(Stmt::Import(format!("\"{}\"", s))); } else { - list_of_imports.append(&mut self._parse_single_import(&s, span)?); + list_of_imports.append(&mut self.parse_single_import(&s, span)?); } } Value::String(s, QuoteKind::None) => { if s.starts_with("url(") { list_of_imports.push(Stmt::Import(s)); } else { - list_of_imports.append(&mut self._parse_single_import(&s, span)?); + list_of_imports.append(&mut self.parse_single_import(&s, span)?); } } _ => return Err(("Expected string.", span).into()), diff --git a/tests/imports.rs b/tests/imports.rs index 01513e4..6ab0b0e 100644 --- a/tests/imports.rs +++ b/tests/imports.rs @@ -83,10 +83,10 @@ fn single_quotes_import() { } #[test] -fn comma_seperated_import() { - let input = "@import 'firsta', 'seconda';\na {\n color: $a;\n}"; - tempfile!("firsta", "$a: red;"); - tempfile!("seconda", "p { color: blue; }"); +fn comma_separated_import() { + let input = "@import 'comma_separated_import_first', 'comma_separated_import_second';\na {\n color: $a;\n}"; + tempfile!("comma_separated_import_first", "$a: red;"); + tempfile!("comma_separated_import_second", "p { color: blue; }"); assert_eq!( "p {\n color: blue;\n}\n\na {\n color: red;\n}\n", &grass::from_string(input.to_string(), &grass::Options::default()).expect(input) @@ -94,10 +94,11 @@ fn comma_seperated_import() { } #[test] -fn comma_seperated_import_order() { - let input = "@import 'firstb', 'secondb', url(third);"; - tempfile!("firstb", "p { color: red; }"); - tempfile!("secondb", "p { color: blue; }"); +fn comma_separated_import_order() { + let input = + "@import 'comma_separated_import_order1', 'comma_separated_import_order2', url(third);"; + tempfile!("comma_separated_import_order1", "p { color: red; }"); + tempfile!("comma_separated_import_order2", "p { color: blue; }"); assert_eq!( "p {\n color: red;\n}\n\np {\n color: blue;\n}\n@import url(third);\n", &grass::from_string(input.to_string(), &grass::Options::default()).expect(input)