recognize plain css @import
s beginning with //
This commit is contained in:
parent
36bdea138d
commit
56030f1292
@ -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)
|
||||
|
@ -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?)
|
||||
|
Loading…
x
Reference in New Issue
Block a user