give better error messages for undefined modules and functions

This commit is contained in:
Connor Skees 2020-07-26 13:44:30 -04:00
parent 0916dcc5bd
commit ee57cda9c5
2 changed files with 18 additions and 3 deletions

View File

@ -224,7 +224,7 @@ impl<'a> Parser<'a> {
let value = self
.modules
.get(module)
.ok_or(("todo: module dne", module_span))?
.ok_or((format!("There is no module with the namespace \"{}\".", module), module_span))?
.get_var(var)?;
HigherIntermediateValue::Literal(value.clone())
} else {
@ -235,9 +235,9 @@ impl<'a> Parser<'a> {
let function = self
.modules
.get(module)
.ok_or(("todo: module dne", module_span))?
.ok_or((format!("There is no module with the namespace \"{}\".", module), module_span))?
.get_fn(fn_name.node)
.ok_or(("todo: fn dne", fn_name.span))?;
.ok_or(("Undefined function.", fn_name.span))?;
if !matches!(self.toks.next(), Some(Token { kind: '(', .. })) {
todo!()

View File

@ -25,6 +25,21 @@ error!(
"@use \"sass:math\" a math;",
"Error: expected \";\"."
);
error!(
unknown_module_get_variable,
"a { color: foo.$bar; }",
"Error: There is no module with the namespace \"foo\"."
);
error!(
unknown_module_get_function,
"a { color: foo.bar(); }",
"Error: There is no module with the namespace \"foo\"."
);
error!(
unknown_function,
"@use \"sass:math\";\na { color: math.bar(); }",
"Error: Undefined function."
);
test!(
use_as,
"@use \"sass:math\" as foo;