Value::inspect returns cow

This commit is contained in:
ConnorSkees 2020-05-06 11:50:35 -04:00
parent 5ba28e27f3
commit 6729f24b17
3 changed files with 20 additions and 18 deletions

View File

@ -71,7 +71,7 @@ impl AtRule {
super_selector,
)?;
return Err((message.inspect(span)?, span.merge(kind_span)).into());
return Err((message.inspect(span)?.to_string(), span.merge(kind_span)).into());
}
AtRuleKind::Warn => {
let Spanned {
@ -111,7 +111,7 @@ impl AtRule {
devour_whitespace(toks);
Spanned {
node: AtRule::Debug(Spanned {
node: message.inspect(span)?,
node: message.inspect(span)?.into(),
span,
}),
span,

View File

@ -96,7 +96,9 @@ fn unitless(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sas
fn inspect(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(1)?;
Ok(Value::Ident(
arg!(args, scope, super_selector, 0, "value").inspect(args.span())?,
arg!(args, scope, super_selector, 0, "value")
.inspect(args.span())?
.into(),
QuoteKind::None,
))
}

View File

@ -265,39 +265,39 @@ impl Value {
// TODO:
// https://github.com/sass/dart-sass/blob/d4adea7569832f10e3a26d0e420ae51640740cfb/lib/src/ast/sass/expression/list.dart#L39
pub fn inspect(&self, span: Span) -> SassResult<String> {
pub fn inspect(&self, span: Span) -> SassResult<Cow<'static, str>> {
Ok(match self {
Value::List(v, _, brackets) if v.is_empty() => match brackets {
Brackets::None => "()".to_string(),
Brackets::Bracketed => "[]".to_string(),
Brackets::None => Cow::Borrowed("()"),
Brackets::Bracketed => Cow::Borrowed("[]"),
},
Value::List(v, sep, brackets) if v.len() == 1 => match brackets {
Brackets::None => match sep {
ListSeparator::Space => v[0].inspect(span)?,
ListSeparator::Comma => format!("({},)", v[0].inspect(span)?),
ListSeparator::Comma => Cow::Owned(format!("({},)", v[0].inspect(span)?)),
},
Brackets::Bracketed => match sep {
ListSeparator::Space => format!("[{}]", v[0].inspect(span)?),
ListSeparator::Comma => format!("[{},]", v[0].inspect(span)?),
ListSeparator::Space => Cow::Owned(format!("[{}]", v[0].inspect(span)?)),
ListSeparator::Comma => Cow::Owned(format!("[{},]", v[0].inspect(span)?)),
},
},
Self::List(vals, sep, brackets) => match brackets {
Self::List(vals, sep, brackets) => Cow::Owned(match brackets {
Brackets::None => vals
.iter()
.map(|x| x.inspect(span))
.collect::<SassResult<Vec<String>>>()?
.collect::<SassResult<Vec<Cow<'static, str>>>>()?
.join(sep.as_str()),
Brackets::Bracketed => format!(
"[{}]",
vals.iter()
.map(|x| x.inspect(span))
.collect::<SassResult<Vec<String>>>()?
.collect::<SassResult<Vec<Cow<'static, str>>>>()?
.join(sep.as_str()),
),
},
Value::Function(f) => format!("get-function(\"{}\")", f.name()),
Value::Null => "null".to_string(),
Value::Map(map) => format!(
}),
Value::Function(f) => Cow::Owned(format!("get-function(\"{}\")", f.name())),
Value::Null => Cow::Borrowed("null"),
Value::Map(map) => Cow::Owned(format!(
"({})",
map.iter()
.map(|(k, v)| Ok(format!(
@ -307,9 +307,9 @@ impl Value {
)))
.collect::<SassResult<Vec<String>>>()?
.join(", ")
),
)),
Value::Paren(v) => v.inspect(span)?,
v => v.to_css_string(span)?.into(),
v => v.to_css_string(span)?,
})
}