From 56030f12927dd94fa4ff4dbd7489eee07190f8f6 Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Fri, 7 Aug 2020 17:44:51 -0400 Subject: [PATCH] recognize plain css `@import`s beginning with `//` --- src/parse/import.rs | 13 ++++++++++++- tests/imports.rs | 7 +++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/parse/import.rs b/src/parse/import.rs index 81db734..c00ca46 100644 --- a/src/parse/import.rs +++ b/src/parse/import.rs @@ -13,6 +13,17 @@ use crate::{ use super::{Parser, Stmt}; +fn is_plain_css_import(url: &str) -> bool { + if url.len() < 5 { + return false; + } + + url.ends_with(".css") + || url.starts_with("http://") + || url.starts_with("https://") + || url.starts_with("//") +} + impl<'a> Parser<'a> { /// Searches the current directory of the file then searches in `load_paths` directories /// if the import has not yet been found. @@ -137,7 +148,7 @@ impl<'a> Parser<'a> { match file_name_as_value { Value::String(s, QuoteKind::Quoted) => { - if s.ends_with(".css") || s.starts_with("http://") || s.starts_with("https://") { + if is_plain_css_import(&s) { Ok(vec![Stmt::Import(format!("\"{}\"", s))]) } else { self.parse_single_import(&s, span) diff --git a/tests/imports.rs b/tests/imports.rs index ed52eae..1d3528a 100644 --- a/tests/imports.rs +++ b/tests/imports.rs @@ -20,6 +20,8 @@ fn imports_variable() { fn import_no_semicolon() { let input = "@import \"import_no_semicolon\"\na {\n color: $a;\n}"; tempfile!("import_no_semicolon", "$a: red;"); + + drop(input); } #[test] @@ -193,6 +195,11 @@ test!( " /**/ @import /**/ url(foo) /**/ ;", "/**/\n@import url(foo);\n" ); +test!( + plain_css_begins_with_two_slashes, + "@import \"//fonts.googleapis.com/css?family=Droid+Sans\";", + "@import \"//fonts.googleapis.com/css?family=Droid+Sans\";\n" +); // todo: test for calling paths, e.g. `grass b\index.scss` // todo: test for absolute paths (how?)