consistently use Value over Self in certain methods

This commit is contained in:
Connor Skees 2020-07-03 13:00:31 -04:00
parent b473717861
commit e801e4d424

View File

@ -110,8 +110,8 @@ impl Value {
match self { match self {
Value::Null => true, Value::Null => true,
Value::String(i, QuoteKind::None) if i.is_empty() => true, Value::String(i, QuoteKind::None) if i.is_empty() => true,
Self::List(v, _, Brackets::Bracketed) if v.is_empty() => false, Value::List(v, _, Brackets::Bracketed) if v.is_empty() => false,
Self::List(v, ..) => v Value::List(v, ..) => v
.iter() .iter()
.map(Value::is_null) .map(Value::is_null)
.collect::<Vec<bool>>() .collect::<Vec<bool>>()
@ -123,21 +123,21 @@ impl Value {
pub fn to_css_string(&self, span: Span) -> SassResult<Cow<'static, str>> { pub fn to_css_string(&self, span: Span) -> SassResult<Cow<'static, str>> {
Ok(match self { Ok(match self {
Self::Important => Cow::const_str("!important"), Value::Important => Cow::const_str("!important"),
Self::Dimension(num, unit) => match unit { Value::Dimension(num, unit) => match unit {
Unit::Mul(..) => { Unit::Mul(..) => {
return Err((format!("{}{} isn't a valid CSS value.", num, unit), span).into()); return Err((format!("{}{} isn't a valid CSS value.", num, unit), span).into());
} }
_ => Cow::owned(format!("{}{}", num, unit)), _ => Cow::owned(format!("{}{}", num, unit)),
}, },
Self::Map(..) | Self::FunctionRef(..) => { Value::Map(..) | Value::FunctionRef(..) => {
return Err(( return Err((
format!("{} isn't a valid CSS value.", self.inspect(span)?), format!("{} isn't a valid CSS value.", self.inspect(span)?),
span, span,
) )
.into()) .into())
} }
Self::List(vals, sep, brackets) => match brackets { Value::List(vals, sep, brackets) => match brackets {
Brackets::None => Cow::owned( Brackets::None => Cow::owned(
vals.iter() vals.iter()
.filter(|x| !x.is_null()) .filter(|x| !x.is_null())
@ -154,8 +154,8 @@ impl Value {
.join(sep.as_str()), .join(sep.as_str()),
)), )),
}, },
Self::Color(c) => Cow::owned(c.to_string()), Value::Color(c) => Cow::owned(c.to_string()),
Self::String(string, QuoteKind::None) => { Value::String(string, QuoteKind::None) => {
let mut after_newline = false; let mut after_newline = false;
let mut buf = String::with_capacity(string.len()); let mut buf = String::with_capacity(string.len());
for c in string.chars() { for c in string.chars() {
@ -177,15 +177,15 @@ impl Value {
} }
Cow::owned(buf) Cow::owned(buf)
} }
Self::String(string, QuoteKind::Quoted) => { Value::String(string, QuoteKind::Quoted) => {
let mut buf = String::with_capacity(string.len()); let mut buf = String::with_capacity(string.len());
visit_quoted_string(&mut buf, false, string); visit_quoted_string(&mut buf, false, string);
Cow::owned(buf) Cow::owned(buf)
} }
Self::True => Cow::const_str("true"), Value::True => Cow::const_str("true"),
Self::False => Cow::const_str("false"), Value::False => Cow::const_str("false"),
Self::Null => Cow::const_str(""), Value::Null => Cow::const_str(""),
Self::ArgList(args) => Cow::owned( Value::ArgList(args) => Cow::owned(
args.iter() args.iter()
.filter(|x| !x.is_null()) .filter(|x| !x.is_null())
.map(|a| Ok(a.node.to_css_string(span)?)) .map(|a| Ok(a.node.to_css_string(span)?))
@ -204,9 +204,9 @@ impl Value {
pub fn unquote(self) -> Self { pub fn unquote(self) -> Self {
match self { match self {
Self::String(s1, _) => Self::String(s1, QuoteKind::None), Value::String(s1, _) => Value::String(s1, QuoteKind::None),
Self::List(v, sep, bracket) => { Value::List(v, sep, bracket) => {
Self::List(v.into_iter().map(Value::unquote).collect(), sep, bracket) Value::List(v.into_iter().map(Value::unquote).collect(), sep, bracket)
} }
v => v, v => v,
} }
@ -218,21 +218,21 @@ impl Value {
pub fn kind(&self) -> &'static str { pub fn kind(&self) -> &'static str {
match self { match self {
Self::Color(..) => "color", Value::Color(..) => "color",
Self::String(..) | Self::Important => "string", Value::String(..) | Value::Important => "string",
Self::Dimension(..) => "number", Value::Dimension(..) => "number",
Self::List(..) => "list", Value::List(..) => "list",
Self::FunctionRef(..) => "function", Value::FunctionRef(..) => "function",
Self::ArgList(..) => "arglist", Value::ArgList(..) => "arglist",
Self::True | Self::False => "bool", Value::True | Value::False => "bool",
Self::Null => "null", Value::Null => "null",
Self::Map(..) => "map", Value::Map(..) => "map",
} }
} }
pub fn is_special_function(&self) -> bool { pub fn is_special_function(&self) -> bool {
match self { match self {
Self::String(s, QuoteKind::None) => is_special_function(s), Value::String(s, QuoteKind::None) => is_special_function(s),
_ => false, _ => false,
} }
} }
@ -263,7 +263,7 @@ impl Value {
ListSeparator::Comma => Cow::owned(format!("[{},]", v[0].inspect(span)?)), ListSeparator::Comma => Cow::owned(format!("[{},]", v[0].inspect(span)?)),
}, },
}, },
Self::List(vals, sep, brackets) => Cow::owned(match brackets { Value::List(vals, sep, brackets) => Cow::owned(match brackets {
Brackets::None => vals Brackets::None => vals
.iter() .iter()
.map(|x| x.inspect(span)) .map(|x| x.inspect(span))
@ -347,8 +347,8 @@ impl Value {
fn selector_string(self, span: Span) -> SassResult<Option<String>> { fn selector_string(self, span: Span) -> SassResult<Option<String>> {
Ok(Some(match self { Ok(Some(match self {
Self::String(text, ..) => text, Value::String(text, ..) => text,
Self::List(list, sep, ..) if !list.is_empty() => { Value::List(list, sep, ..) if !list.is_empty() => {
let mut result = Vec::new(); let mut result = Vec::new();
match sep { match sep {
ListSeparator::Comma => { ListSeparator::Comma => {