properly error when attempting to display map
This commit is contained in:
parent
0a5c6b907c
commit
305581ad75
@ -47,30 +47,23 @@ impl Value {
|
|||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_css_string(&self, span: Span) -> SassResult<String> {
|
pub fn to_css_string(&self, span: Span) -> SassResult<String> {
|
||||||
Ok(match self {
|
Ok(match self {
|
||||||
Self::Important => format!("!important"),
|
Self::Important => format!("!important"),
|
||||||
Self::Dimension(num, unit) => match unit {
|
Self::Dimension(num, unit) => match unit {
|
||||||
Unit::Mul(..) => {
|
Unit::Mul(..) => {
|
||||||
return Err((
|
return Err((format!("{}{} isn't a valid CSS value.", num, unit), span).into());
|
||||||
format!("Error: {}{} isn't a valid CSS value.", num, unit),
|
|
||||||
span,
|
|
||||||
)
|
|
||||||
.into());
|
|
||||||
}
|
}
|
||||||
_ => format!("{}{}", num, unit),
|
_ => format!("{}{}", num, unit),
|
||||||
},
|
},
|
||||||
Self::Map(map) => format!(
|
Self::Map(..) => {
|
||||||
"({})",
|
return Err((
|
||||||
map.iter()
|
format!("{} isn't a valid CSS value.", dbg!(self.inspect(span)?)),
|
||||||
.map(|(k, v)| Ok(format!(
|
span,
|
||||||
"{}: {}",
|
)
|
||||||
k.to_css_string(span)?,
|
.into())
|
||||||
v.to_css_string(span)?
|
}
|
||||||
)))
|
|
||||||
.collect::<SassResult<Vec<String>>>()?
|
|
||||||
.join(", ")
|
|
||||||
),
|
|
||||||
Self::Function(func) => format!("get-function(\"{}\")", func.name()),
|
Self::Function(func) => format!("get-function(\"{}\")", func.name()),
|
||||||
Self::List(vals, sep, brackets) => match brackets {
|
Self::List(vals, sep, brackets) => match brackets {
|
||||||
Brackets::None => format!(
|
Brackets::None => format!(
|
||||||
@ -195,6 +188,17 @@ impl Value {
|
|||||||
},
|
},
|
||||||
Value::Function(f) => format!("get-function(\"{}\")", f.name()),
|
Value::Function(f) => format!("get-function(\"{}\")", f.name()),
|
||||||
Value::Null => "null".to_string(),
|
Value::Null => "null".to_string(),
|
||||||
|
Value::Map(map) => format!(
|
||||||
|
"({})",
|
||||||
|
map.iter()
|
||||||
|
.map(|(k, v)| Ok(format!(
|
||||||
|
"{}: {}",
|
||||||
|
k.to_css_string(span)?,
|
||||||
|
v.to_css_string(span)?
|
||||||
|
)))
|
||||||
|
.collect::<SassResult<Vec<String>>>()?
|
||||||
|
.join(", ")
|
||||||
|
),
|
||||||
v => v.to_css_string(span)?,
|
v => v.to_css_string(span)?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -133,3 +133,7 @@ error!(
|
|||||||
duplicate_key_in_declaration,
|
duplicate_key_in_declaration,
|
||||||
"a {\n $a: (foo: a, foo: b);;\n}\n", "Error: Duplicate key."
|
"a {\n $a: (foo: a, foo: b);;\n}\n", "Error: Duplicate key."
|
||||||
);
|
);
|
||||||
|
error!(
|
||||||
|
display_map,
|
||||||
|
"a {\n color: (a: b, c: d);\n}\n", "Error: (a: b, c: d) isn't a valid CSS value."
|
||||||
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user