support the @use ... as ...;
syntax
This commit is contained in:
parent
eeb0b0a924
commit
0916dcc5bd
@ -149,32 +149,67 @@ impl<'a> Parser<'a> {
|
|||||||
let Spanned { node: module, span } = self.parse_quoted_string(quote)?;
|
let Spanned { node: module, span } = self.parse_quoted_string(quote)?;
|
||||||
let module = module.unquote().to_css_string(span)?;
|
let module = module.unquote().to_css_string(span)?;
|
||||||
|
|
||||||
if let Some(Token { kind: ';', .. }) = self.toks.peek() {
|
self.whitespace_or_comment();
|
||||||
|
|
||||||
|
let mut module_name: Option<String> = None;
|
||||||
|
|
||||||
|
match self.toks.peek() {
|
||||||
|
Some(Token { kind: ';', .. }) => {
|
||||||
self.toks.next();
|
self.toks.next();
|
||||||
} else {
|
}
|
||||||
todo!()
|
Some(Token { kind: 'a', .. }) | Some(Token { kind: 'A', .. }) => {
|
||||||
|
let mut ident =
|
||||||
|
peek_ident_no_interpolation(self.toks, false, self.span_before)?;
|
||||||
|
ident.node.make_ascii_lowercase();
|
||||||
|
if ident.node != "as" {
|
||||||
|
return Err(("expected \";\".", ident.span).into());
|
||||||
|
}
|
||||||
|
|
||||||
|
self.whitespace_or_comment();
|
||||||
|
|
||||||
|
let name = self.parse_identifier_no_interpolation(false)?;
|
||||||
|
|
||||||
|
module_name = Some(name.node);
|
||||||
|
|
||||||
|
if !matches!(self.toks.next(), Some(Token { kind: ';', .. })) {
|
||||||
|
return Err(("expected \";\".", name.span).into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Some(Token { kind: 'w', .. }) | Some(Token { kind: 'W', .. }) => {
|
||||||
|
todo!("with")
|
||||||
|
}
|
||||||
|
Some(..) | None => return Err(("expected \";\".", span).into()),
|
||||||
}
|
}
|
||||||
|
|
||||||
match module.as_ref() {
|
match module.as_ref() {
|
||||||
"sass:color" => self
|
"sass:color" => self.modules.insert(
|
||||||
.modules
|
module_name.unwrap_or("color".to_owned()),
|
||||||
.insert("color".to_owned(), declare_module_color()),
|
declare_module_color(),
|
||||||
"sass:list" => self
|
),
|
||||||
.modules
|
"sass:list" => self.modules.insert(
|
||||||
.insert("list".to_owned(), declare_module_list()),
|
module_name.unwrap_or("list".to_owned()),
|
||||||
"sass:map" => self.modules.insert("map".to_owned(), declare_module_map()),
|
declare_module_list(),
|
||||||
"sass:math" => self
|
),
|
||||||
.modules
|
"sass:map" => self.modules.insert(
|
||||||
.insert("math".to_owned(), declare_module_math()),
|
module_name.unwrap_or("map".to_owned()),
|
||||||
"sass:meta" => self
|
declare_module_map(),
|
||||||
.modules
|
),
|
||||||
.insert("meta".to_owned(), declare_module_meta()),
|
"sass:math" => self.modules.insert(
|
||||||
"sass:selector" => self
|
module_name.unwrap_or("math".to_owned()),
|
||||||
.modules
|
declare_module_math(),
|
||||||
.insert("selector".to_owned(), declare_module_selector()),
|
),
|
||||||
"sass:string" => self
|
"sass:meta" => self.modules.insert(
|
||||||
.modules
|
module_name.unwrap_or("meta".to_owned()),
|
||||||
.insert("string".to_owned(), declare_module_string()),
|
declare_module_meta(),
|
||||||
|
),
|
||||||
|
"sass:selector" => self.modules.insert(
|
||||||
|
module_name.unwrap_or("selector".to_owned()),
|
||||||
|
declare_module_selector(),
|
||||||
|
),
|
||||||
|
"sass:string" => self.modules.insert(
|
||||||
|
module_name.unwrap_or("string".to_owned()),
|
||||||
|
declare_module_string(),
|
||||||
|
),
|
||||||
_ => todo!("@use not yet implemented"),
|
_ => todo!("@use not yet implemented"),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
31
tests/use.rs
31
tests/use.rs
@ -10,3 +10,34 @@ error!(
|
|||||||
",
|
",
|
||||||
"Error: @use rules must be written before any other rules."
|
"Error: @use rules must be written before any other rules."
|
||||||
);
|
);
|
||||||
|
error!(
|
||||||
|
interpolation_in_as_identifier,
|
||||||
|
"@use \"sass:math\" as m#{a}th;",
|
||||||
|
"Error: expected \";\"."
|
||||||
|
);
|
||||||
|
error!(
|
||||||
|
use_as_quoted_string,
|
||||||
|
"@use \"sass:math\" as \"math\";",
|
||||||
|
"Error: Expected identifier."
|
||||||
|
);
|
||||||
|
error!(
|
||||||
|
use_as_missing_s,
|
||||||
|
"@use \"sass:math\" a math;",
|
||||||
|
"Error: expected \";\"."
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
use_as,
|
||||||
|
"@use \"sass:math\" as foo;
|
||||||
|
a {
|
||||||
|
color: foo.clamp(0, 1, 2);
|
||||||
|
}",
|
||||||
|
"a {\n color: 1;\n}\n"
|
||||||
|
);
|
||||||
|
test!(
|
||||||
|
use_as_uppercase,
|
||||||
|
"@use \"sass:math\" AS foo;
|
||||||
|
a {
|
||||||
|
color: foo.clamp(0, 1, 2);
|
||||||
|
}",
|
||||||
|
"a {\n color: 1;\n}\n"
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user