rename Value::Ident to Value::String

This commit is contained in:
ConnorSkees 2020-05-22 14:35:41 -04:00
parent 969726eb30
commit 283a2097ff
14 changed files with 135 additions and 143 deletions

View File

@ -107,7 +107,7 @@ fn inner_hsl(
);
}
string.push(')');
return Ok(Value::Ident(string, QuoteKind::None));
return Ok(Value::String(string, QuoteKind::None));
}
v => {
return Err((
@ -136,7 +136,7 @@ fn inner_hsl(
);
}
string.push(')');
return Ok(Value::Ident(string, QuoteKind::None));
return Ok(Value::String(string, QuoteKind::None));
}
v => {
return Err((
@ -167,7 +167,7 @@ fn inner_hsl(
);
}
string.push(')');
return Ok(Value::Ident(string, QuoteKind::None));
return Ok(Value::String(string, QuoteKind::None));
}
v => {
return Err((
@ -200,7 +200,7 @@ fn inner_hsl(
.into())
}
v if v.is_special_function() => {
return Ok(Value::Ident(
return Ok(Value::String(
format!(
"{}({}, {}, {}, {})",
name,
@ -357,7 +357,7 @@ fn darken(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassR
fn saturate(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(2)?;
if args.len() == 1 {
return Ok(Value::Ident(
return Ok(Value::String(
format!(
"saturate({})",
arg!(args, scope, super_selector, 0, "amount").to_css_string(args.span())?
@ -382,7 +382,7 @@ fn saturate(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sas
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
Value::Dimension(n, u) => {
return Ok(Value::Ident(
return Ok(Value::String(
format!("saturate({}{})", n, u),
QuoteKind::None,
))
@ -431,7 +431,7 @@ fn grayscale(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sa
let color = match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => c,
Value::Dimension(n, u) => {
return Ok(Value::Ident(
return Ok(Value::String(
format!("grayscale({}{})", n, u),
QuoteKind::None,
))
@ -486,7 +486,7 @@ fn invert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassR
match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Color(Box::new(c.invert(weight)))),
Value::Dimension(n, Unit::Percent) => {
Ok(Value::Ident(format!("invert({}%)", n), QuoteKind::None))
Ok(Value::String(format!("invert({}%)", n), QuoteKind::None))
}
Value::Dimension(..) => Err((
"Only one argument may be passed to the plain-CSS invert() function.",

View File

@ -25,7 +25,7 @@ fn opacity(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sass
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "color") {
Value::Color(c) => Ok(Value::Dimension(c.alpha(), Unit::None)),
Value::Dimension(num, unit) => Ok(Value::Ident(
Value::Dimension(num, unit) => Ok(Value::String(
format!("opacity({}{})", num, unit),
QuoteKind::None,
)),

View File

@ -345,7 +345,7 @@ fn ie_hex_str(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S
.into())
}
};
Ok(Value::Ident(color.to_ie_hex_str(), QuoteKind::None))
Ok(Value::String(color.to_ie_hex_str(), QuoteKind::None))
}
pub(crate) fn declare(f: &mut GlobalFunctionMap) {

View File

@ -45,7 +45,7 @@ fn inner_rgb(
Some(v) if v.is_special_function() => {
let green = channels.pop().unwrap();
let red = channels.pop().unwrap();
return Ok(Value::Ident(
return Ok(Value::String(
format!(
"{}({}, {}, {})",
name,
@ -80,7 +80,7 @@ fn inner_rgb(
),
None => format!("{}({} {})", name, v.to_css_string(args.span())?, blue),
};
return Ok(Value::Ident(string, QuoteKind::None));
return Ok(Value::String(string, QuoteKind::None));
}
Some(v) => {
return Err((
@ -96,7 +96,7 @@ fn inner_rgb(
Some(Value::Dimension(n, Unit::None)) => n,
Some(Value::Dimension(n, Unit::Percent)) => (n / Number::from(100)) * Number::from(255),
Some(v) if v.is_special_function() => {
return Ok(Value::Ident(
return Ok(Value::String(
format!(
"{}({}, {}, {})",
name,
@ -125,7 +125,7 @@ fn inner_rgb(
Value::Color(c) => c,
v if v.is_special_function() => {
let alpha = arg!(args, scope, super_selector, 1, "alpha");
return Ok(Value::Ident(
return Ok(Value::String(
format!(
"{}({}, {})",
name,
@ -157,7 +157,7 @@ fn inner_rgb(
.into())
}
v if v.is_special_function() => {
return Ok(Value::Ident(
return Ok(Value::String(
format!(
"{}({}, {}, {}, {})",
name,
@ -210,7 +210,7 @@ fn inner_rgb(
);
}
string.push(')');
return Ok(Value::Ident(string, QuoteKind::None));
return Ok(Value::String(string, QuoteKind::None));
}
v => {
return Err((
@ -250,7 +250,7 @@ fn inner_rgb(
);
}
string.push(')');
return Ok(Value::Ident(string, QuoteKind::None));
return Ok(Value::String(string, QuoteKind::None));
}
v => {
return Err((
@ -289,7 +289,7 @@ fn inner_rgb(
);
}
string.push(')');
return Ok(Value::Ident(string, QuoteKind::None));
return Ok(Value::String(string, QuoteKind::None));
}
v => {
return Err((
@ -327,7 +327,7 @@ fn inner_rgb(
blue,
v.to_css_string(args.span())?
);
return Ok(Value::Ident(string, QuoteKind::None));
return Ok(Value::String(string, QuoteKind::None));
}
v => {
return Err((

View File

@ -71,7 +71,7 @@ fn list_separator(
super_selector: &Selector,
) -> SassResult<Value> {
args.max_args(1)?;
Ok(Value::Ident(
Ok(Value::String(
match arg!(args, scope, super_selector, 0, "list") {
Value::List(_, sep, ..) => sep.name(),
_ => ListSeparator::Space.name(),
@ -140,9 +140,9 @@ fn append(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassR
scope,
super_selector,
2,
"separator" = Value::Ident("auto".to_owned(), QuoteKind::None)
"separator" = Value::String("auto".to_owned(), QuoteKind::None)
) {
Value::Ident(s, ..) => match s.as_str() {
Value::String(s, ..) => match s.as_str() {
"auto" => sep,
"comma" => ListSeparator::Comma,
"space" => ListSeparator::Space,
@ -188,9 +188,9 @@ fn join(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassRes
scope,
super_selector,
2,
"separator" = Value::Ident("auto".to_owned(), QuoteKind::None)
"separator" = Value::String("auto".to_owned(), QuoteKind::None)
) {
Value::Ident(s, ..) => match s.as_str() {
Value::String(s, ..) => match s.as_str() {
"auto" => {
if list1.is_empty() || (list1.len() == 1 && sep1 == ListSeparator::Space) {
sep2
@ -225,9 +225,9 @@ fn join(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassRes
scope,
super_selector,
3,
"bracketed" = Value::Ident("auto".to_owned(), QuoteKind::None)
"bracketed" = Value::String("auto".to_owned(), QuoteKind::None)
) {
Value::Ident(s, ..) => match s.as_str() {
Value::String(s, ..) => match s.as_str() {
"auto" => brackets,
_ => Brackets::Bracketed,
},

View File

@ -27,7 +27,7 @@ fn feature_exists(
) -> SassResult<Value> {
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "feature") {
Value::Ident(s, _) => Ok(match s.as_str() {
Value::String(s, _) => Ok(match s.as_str() {
// A local variable will shadow a global variable unless
// `!global` is used.
"global-variable-shadowing" => Value::True,
@ -71,13 +71,13 @@ fn unit(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassRes
.into())
}
};
Ok(Value::Ident(unit, QuoteKind::Quoted))
Ok(Value::String(unit, QuoteKind::Quoted))
}
fn type_of(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(1)?;
let value = arg!(args, scope, super_selector, 0, "value");
Ok(Value::Ident(
Ok(Value::String(
value.kind(args.span())?.to_owned(),
QuoteKind::None,
))
@ -94,7 +94,7 @@ 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(
Ok(Value::String(
arg!(args, scope, super_selector, 0, "value")
.inspect(args.span())?
.into(),
@ -109,7 +109,7 @@ fn variable_exists(
) -> SassResult<Value> {
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "name") {
Value::Ident(s, _) => Ok(Value::bool(scope.var_exists(&s))),
Value::String(s, _) => Ok(Value::bool(scope.var_exists(&s))),
v => Err((
format!("$name: {} is not a string.", v.to_css_string(args.span())?),
args.span(),
@ -125,7 +125,7 @@ fn global_variable_exists(
) -> SassResult<Value> {
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "name") {
Value::Ident(s, _) => Ok(Value::bool(global_var_exists(&s))),
Value::String(s, _) => Ok(Value::bool(global_var_exists(&s))),
v => Err((
format!("$name: {} is not a string.", v.to_css_string(args.span())?),
args.span(),
@ -137,7 +137,7 @@ fn global_variable_exists(
fn mixin_exists(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(2)?;
match arg!(args, scope, super_selector, 0, "name") {
Value::Ident(s, _) => Ok(Value::bool(scope.mixin_exists(&s))),
Value::String(s, _) => Ok(Value::bool(scope.mixin_exists(&s))),
v => Err((
format!("$name: {} is not a string.", v.to_css_string(args.span())?),
args.span(),
@ -153,7 +153,7 @@ fn function_exists(
) -> SassResult<Value> {
args.max_args(2)?;
match arg!(args, scope, super_selector, 0, "name") {
Value::Ident(s, _) => Ok(Value::bool(
Value::String(s, _) => Ok(Value::bool(
scope.fn_exists(&s) || GLOBAL_FUNCTIONS.contains_key(s.as_str()),
)),
v => Err((
@ -167,7 +167,7 @@ fn function_exists(
fn get_function(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(3)?;
let name = match arg!(args, scope, super_selector, 0, "name") {
Value::Ident(s, _) => s,
Value::String(s, _) => s,
v => {
return Err((
format!("$name: {} is not a string.", v.to_css_string(args.span())?),
@ -178,7 +178,7 @@ fn get_function(mut args: CallArgs, scope: &Scope, super_selector: &Selector) ->
};
let css = arg!(args, scope, super_selector, 1, "css" = Value::False).is_true(args.span())?;
let module = match arg!(args, scope, super_selector, 2, "module" = Value::Null) {
Value::Ident(s, ..) => Some(s),
Value::String(s, ..) => Some(s),
Value::Null => None,
v => {
return Err((

View File

@ -21,9 +21,9 @@ fn to_upper_case(
) -> SassResult<Value> {
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(mut i, q) => {
Value::String(mut i, q) => {
i.make_ascii_uppercase();
Ok(Value::Ident(i, q))
Ok(Value::String(i, q))
}
v => Err((
format!(
@ -43,9 +43,9 @@ fn to_lower_case(
) -> SassResult<Value> {
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(mut i, q) => {
Value::String(mut i, q) => {
i.make_ascii_lowercase();
Ok(Value::Ident(i, q))
Ok(Value::String(i, q))
}
v => Err((
format!(
@ -61,7 +61,7 @@ fn to_lower_case(
fn str_length(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(i, _) => Ok(Value::Dimension(
Value::String(i, _) => Ok(Value::Dimension(
Number::from(i.chars().count()),
Unit::None,
)),
@ -79,7 +79,7 @@ fn str_length(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S
fn quote(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(i, _) => Ok(Value::Ident(i, QuoteKind::Quoted)),
Value::String(i, _) => Ok(Value::String(i, QuoteKind::Quoted)),
v => Err((
format!(
"$string: {} is not a string.",
@ -94,7 +94,7 @@ fn quote(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassRe
fn unquote(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(1)?;
match arg!(args, scope, super_selector, 0, "string") {
i @ Value::Ident(..) => Ok(i.unquote()),
i @ Value::String(..) => Ok(i.unquote()),
v => Err((
format!(
"$string: {} is not a string.",
@ -109,7 +109,7 @@ fn unquote(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sass
fn str_slice(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(3)?;
let (string, quotes) = match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(s, q) => (s, q),
Value::String(s, q) => (s, q),
v => {
return Err((
format!(
@ -195,9 +195,9 @@ fn str_slice(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sa
}
if start > end || start > str_len {
Ok(Value::Ident(String::new(), quotes))
Ok(Value::String(String::new(), quotes))
} else {
Ok(Value::Ident(
Ok(Value::String(
string
.chars()
.skip(start - 1)
@ -211,7 +211,7 @@ fn str_slice(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sa
fn str_index(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(2)?;
let s1 = match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(i, _) => i,
Value::String(i, _) => i,
v => {
return Err((
format!(
@ -225,7 +225,7 @@ fn str_index(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sa
};
let substr = match arg!(args, scope, super_selector, 1, "substring") {
Value::Ident(i, _) => i,
Value::String(i, _) => i,
v => {
return Err((
format!(
@ -247,7 +247,7 @@ fn str_index(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> Sa
fn str_insert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> SassResult<Value> {
args.max_args(3)?;
let (s1, quotes) = match arg!(args, scope, super_selector, 0, "string") {
Value::Ident(i, q) => (i, q),
Value::String(i, q) => (i, q),
v => {
return Err((
format!(
@ -261,7 +261,7 @@ fn str_insert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S
};
let substr = match arg!(args, scope, super_selector, 1, "insert") {
Value::Ident(i, _) => i,
Value::String(i, _) => i,
v => {
return Err((
format!(
@ -299,7 +299,7 @@ fn str_insert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S
};
if s1.is_empty() {
return Ok(Value::Ident(substr, quotes));
return Ok(Value::String(substr, quotes));
}
let len = s1.chars().count();
@ -342,7 +342,7 @@ fn str_insert(mut args: CallArgs, scope: &Scope, super_selector: &Selector) -> S
}
};
Ok(Value::Ident(string, quotes))
Ok(Value::String(string, quotes))
}
#[cfg(feature = "random")]
@ -353,7 +353,7 @@ fn unique_id(args: CallArgs, _: &Scope, _: &Selector) -> SassResult<Value> {
.map(|()| rng.sample(Alphanumeric))
.take(7)
.collect();
Ok(Value::Ident(string, QuoteKind::None))
Ok(Value::String(string, QuoteKind::None))
}
pub(crate) fn declare(f: &mut GlobalFunctionMap) {

View File

@ -124,7 +124,7 @@ impl Attribute {
q @ '\'' | q @ '"' => {
toks.next();
match parse_quoted_string(toks, scope, q, super_selector)?.node {
Value::Ident(s, ..) => s,
Value::String(s, ..) => s,
_ => unreachable!(),
}
}
@ -180,7 +180,7 @@ impl Display for Attribute {
// or having special emitter for quoted strings?
// (also avoids the clone because we can consume/modify self)
f.write_str(
&Value::Ident(self.value.clone(), QuoteKind::Quoted)
&Value::String(self.value.clone(), QuoteKind::Quoted)
.to_css_string(self.span)
.unwrap(),
)?;

View File

@ -57,7 +57,7 @@ impl SelectorPart {
Value::List(
kinds
.iter()
.map(|s| Value::Ident(s.to_string(), QuoteKind::None))
.map(|s| Value::String(s.to_string(), QuoteKind::None))
.collect(),
ListSeparator::Space,
Brackets::None,

View File

@ -213,7 +213,7 @@ pub(crate) fn eat_ident<I: Iterator<Item = Token>>(
toks.next();
text.push_str(
&match parse_interpolation(toks, scope, super_selector)?.node {
Value::Ident(s, ..) => s,
Value::String(s, ..) => s,
v => v.to_css_string(span)?.into(),
},
);
@ -291,7 +291,7 @@ pub(crate) fn parse_quoted_string<I: Iterator<Item = Token>>(
toks.next();
let interpolation = parse_interpolation(toks, scope, super_selector)?;
s.push_str(&match interpolation.node {
Value::Ident(s, ..) => s,
Value::String(s, ..) => s,
v => v.to_css_string(interpolation.span)?.into(),
});
continue;
@ -345,7 +345,7 @@ pub(crate) fn parse_quoted_string<I: Iterator<Item = Token>>(
}
}
Ok(Spanned {
node: Value::Ident(s, QuoteKind::Quoted),
node: Value::String(s, QuoteKind::Quoted),
span,
})
}

View File

@ -113,7 +113,7 @@ pub(crate) fn try_eat_url<I: Iterator<Item = Token>>(
let (interpolation, count) = peek_interpolation(toks, scope, super_selector)?;
peek_counter += count;
buf.push_str(&match interpolation.node {
Value::Ident(s, ..) => s,
Value::String(s, ..) => s,
v => v.to_css_string(interpolation.span)?.into(),
});
} else {

View File

@ -33,7 +33,7 @@ pub(crate) enum Value {
UnaryOp(Op, Box<Value>),
BinaryOp(Box<Value>, Op, Box<Value>),
Paren(Box<Value>),
Ident(String, QuoteKind),
String(String, QuoteKind),
Map(SassMap),
ArgList(Vec<Spanned<Value>>),
/// Returned by `get-function()`
@ -111,7 +111,7 @@ impl Value {
pub fn is_null(&self, span: Span) -> SassResult<bool> {
Ok(match self {
&Value::Null => true,
Value::Ident(i, QuoteKind::None) if i.is_empty() => true,
Value::String(i, QuoteKind::None) if i.is_empty() => true,
Self::BinaryOp(..) | Self::Paren(..) | Self::UnaryOp(..) => {
self.clone().eval(span)?.is_null(span)?
}
@ -166,7 +166,7 @@ impl Value {
self.clone().eval(span)?.to_css_string(span)?
}
Self::Paren(val) => val.to_css_string(span)?,
Self::Ident(string, QuoteKind::None) => {
Self::String(string, QuoteKind::None) => {
let mut after_newline = false;
let mut buf = String::with_capacity(string.len());
for c in string.chars() {
@ -188,7 +188,7 @@ impl Value {
}
Cow::Owned(buf)
}
Self::Ident(string, QuoteKind::Quoted) => {
Self::String(string, QuoteKind::Quoted) => {
let mut buf = String::with_capacity(string.len());
visit_quoted_string(&mut buf, false, string)?;
Cow::Owned(buf)
@ -218,7 +218,7 @@ impl Value {
pub fn unquote(self) -> Self {
match self {
Self::Ident(s1, _) => Self::Ident(s1, QuoteKind::None),
Self::String(s1, _) => Self::String(s1, QuoteKind::None),
Self::List(v, sep, bracket) => {
Self::List(v.into_iter().map(Value::unquote).collect(), sep, bracket)
}
@ -233,7 +233,7 @@ impl Value {
pub fn kind(&self, span: Span) -> SassResult<&'static str> {
match self {
Self::Color(..) => Ok("color"),
Self::Ident(..) | Self::Important => Ok("string"),
Self::String(..) | Self::Important => Ok("string"),
Self::Dimension(..) => Ok("number"),
Self::List(..) => Ok("list"),
Self::Function(..) => Ok("function"),
@ -249,7 +249,7 @@ impl Value {
pub fn is_special_function(&self) -> bool {
match self {
Self::Ident(s, QuoteKind::None) => is_special_function(s),
Self::String(s, QuoteKind::None) => is_special_function(s),
_ => false,
}
}

View File

@ -16,8 +16,8 @@ impl Value {
let precedence = Op::Equal.precedence();
Ok(Value::bool(match self {
Self::Ident(s1, ..) => match other {
Self::Ident(s2, ..) => s1 == s2,
Self::String(s1, ..) => match other {
Self::String(s2, ..) => s1 == s2,
_ => false,
},
Self::Dimension(n, unit) => match other {
@ -66,8 +66,8 @@ impl Value {
let precedence = Op::Equal.precedence();
Ok(Value::bool(match self {
Self::Ident(s1, ..) => match other {
Self::Ident(s2, ..) => s1 != s2,
Self::String(s1, ..) => match other {
Self::String(s2, ..) => s1 != s2,
_ => true,
},
Self::Dimension(n, unit) => match other {
@ -111,7 +111,7 @@ impl Value {
pub fn unary_op_plus(self, span: Span) -> SassResult<Self> {
Ok(match self.eval(span)?.node {
v @ Value::Dimension(..) => v,
v => Value::Ident(format!("+{}", v.to_css_string(span)?), QuoteKind::None),
v => Value::String(format!("+{}", v.to_css_string(span)?), QuoteKind::None),
})
}
@ -258,12 +258,12 @@ impl Value {
Ok(match self {
Self::Function(..) | Self::ArgList(..) | Self::Map(..) => todo!(),
Self::Important | Self::True | Self::False => match other {
Self::Ident(s, QuoteKind::Quoted) => Value::Ident(
Self::String(s, QuoteKind::Quoted) => Value::String(
format!("{}{}", self.to_css_string(span)?, s),
QuoteKind::Quoted,
),
Self::Null => Value::Ident(self.to_css_string(span)?.into(), QuoteKind::None),
_ => Value::Ident(
Self::Null => Value::String(self.to_css_string(span)?.into(), QuoteKind::None),
_ => Value::String(
format!(
"{}{}",
self.to_css_string(span)?,
@ -274,7 +274,7 @@ impl Value {
},
Self::Null => match other {
Self::Null => Self::Null,
_ => Value::Ident(other.to_css_string(span)?.into(), QuoteKind::None),
_ => Value::String(other.to_css_string(span)?.into(), QuoteKind::None),
},
Self::Dimension(num, unit) => match other {
Self::Dimension(num2, unit2) => {
@ -299,13 +299,13 @@ impl Value {
)
}
}
Self::Ident(s, q) => Value::Ident(format!("{}{}{}", num, unit, s), q),
Self::Null => Value::Ident(format!("{}{}", num, unit), QuoteKind::None),
Self::List(..) => Value::Ident(
Self::String(s, q) => Value::String(format!("{}{}{}", num, unit, s), q),
Self::Null => Value::String(format!("{}{}", num, unit), QuoteKind::None),
Self::List(..) => Value::String(
format!("{}{}{}", num, unit, other.to_css_string(span)?),
QuoteKind::None,
),
Self::True | Self::False => Self::Ident(
Self::True | Self::False => Self::String(
format!("{}{}{}", num, unit, other.to_css_string(span)?),
QuoteKind::None,
),
@ -323,9 +323,9 @@ impl Value {
}
},
Self::Color(c) => match other {
Self::Ident(s, q) => Value::Ident(format!("{}{}", c, s), q),
Self::Null => Value::Ident(c.to_string(), QuoteKind::None),
Self::List(..) => Value::Ident(
Self::String(s, q) => Value::String(format!("{}{}", c, s), q),
Self::Null => Value::String(c.to_string(), QuoteKind::None),
Self::List(..) => Value::String(
format!("{}{}", c, other.to_css_string(span)?),
QuoteKind::None,
),
@ -362,14 +362,16 @@ impl Value {
}
}
Self::UnaryOp(..) | Self::Paren(..) => self.eval(span)?.node.add(other, span)?,
Self::Ident(text, quotes) => match other {
Self::Ident(text2, ..) => Self::Ident(text + &text2, quotes),
_ => Value::Ident(text + &other.to_css_string(span)?, quotes),
Self::String(text, quotes) => match other {
Self::String(text2, ..) => Self::String(text + &text2, quotes),
_ => Value::String(text + &other.to_css_string(span)?, quotes),
},
Self::List(..) => match other {
Self::Ident(s, q) => Value::Ident(format!("{}{}", self.to_css_string(span)?, s), q),
Self::String(s, q) => {
Value::String(format!("{}{}", self.to_css_string(span)?, s), q)
}
Self::Paren(..) => (self.add(other.eval(span)?.node, span))?,
_ => Value::Ident(
_ => Value::String(
format!(
"{}{}",
self.to_css_string(span)?,
@ -411,21 +413,21 @@ impl Value {
)
}
}
Self::List(..) => Value::Ident(
Self::List(..) => Value::String(
format!("{}{}-{}", num, unit, other.to_css_string(span)?),
QuoteKind::None,
),
Self::Ident(..) => Value::Ident(
Self::String(..) => Value::String(
format!("{}{}-{}", num, unit, other.to_css_string(span)?),
QuoteKind::None,
),
_ => todo!(),
},
Self::Color(c) => match other {
Self::Ident(s, q) => {
Value::Ident(format!("{}-{}{}{}", c, q, s, q), QuoteKind::None)
Self::String(s, q) => {
Value::String(format!("{}-{}{}{}", c, q, s, q), QuoteKind::None)
}
Self::Null => Value::Ident(format!("{}-", c), QuoteKind::None),
Self::Null => Value::String(format!("{}-", c), QuoteKind::None),
Self::Dimension(..) | Self::Color(..) => {
return Err((
format!(
@ -437,7 +439,7 @@ impl Value {
)
.into())
}
_ => Value::Ident(
_ => Value::String(
format!("{}-{}", c, other.to_css_string(span)?),
QuoteKind::None,
),
@ -463,7 +465,7 @@ impl Value {
}
}
Self::Paren(..) => self.eval(span)?.node.sub(other, span)?,
Self::Ident(..) => Self::Ident(
Self::String(..) => Self::String(
format!(
"{}-{}",
self.to_css_string(span)?,
@ -472,11 +474,11 @@ impl Value {
QuoteKind::None,
),
Self::List(..) => match other {
Self::Ident(s, q) => Value::Ident(
Self::String(s, q) => Value::String(
format!("{}-{}{}{}", self.to_css_string(span)?, q, s, q),
QuoteKind::None,
),
_ => Value::Ident(
_ => Value::String(
format!(
"{}-{}",
self.to_css_string(span)?,
@ -486,14 +488,14 @@ impl Value {
),
},
_ => match other {
Self::Ident(s, q) => Value::Ident(
Self::String(s, q) => Value::String(
format!("{}-{}{}{}", self.to_css_string(span)?, q, s, q),
QuoteKind::None,
),
Self::Null => {
Value::Ident(format!("{}-", self.to_css_string(span)?), QuoteKind::None)
Value::String(format!("{}-", self.to_css_string(span)?), QuoteKind::None)
}
_ => Value::Ident(
_ => Value::String(
format!(
"{}-{}",
self.to_css_string(span)?,
@ -604,8 +606,8 @@ impl Value {
)
}
}
Self::Ident(s, q) => {
Value::Ident(format!("{}{}/{}{}{}", num, unit, q, s, q), QuoteKind::None)
Self::String(s, q) => {
Value::String(format!("{}{}/{}{}{}", num, unit, q, s, q), QuoteKind::None)
}
Self::BinaryOp(..) | Self::Paren(..) => {
Self::Dimension(num, unit).div(other.eval(span)?.node, span)?
@ -613,10 +615,10 @@ impl Value {
_ => todo!(),
},
Self::Color(c) => match other {
Self::Ident(s, q) => {
Value::Ident(format!("{}/{}{}{}", c, q, s, q), QuoteKind::None)
Self::String(s, q) => {
Value::String(format!("{}/{}{}{}", c, q, s, q), QuoteKind::None)
}
Self::Null => Value::Ident(format!("{}/", c), QuoteKind::None),
Self::Null => Value::String(format!("{}/", c), QuoteKind::None),
Self::Dimension(..) | Self::Color(..) => {
return Err((
format!(
@ -628,7 +630,7 @@ impl Value {
)
.into())
}
_ => Value::Ident(
_ => Value::String(
format!("{}/{}", c, other.to_css_string(span)?),
QuoteKind::None,
),
@ -654,8 +656,8 @@ impl Value {
}
}
Self::Paren(..) => self.eval(span)?.node.div(other, span)?,
Self::Ident(s1, q1) => match other {
Self::Ident(s2, q2) => Value::Ident(
Self::String(s1, q1) => match other {
Self::String(s2, q2) => Value::String(
format!("{}{}{}/{}{}{}", q1, s1, q1, q2, s2, q2),
QuoteKind::None,
),
@ -663,22 +665,22 @@ impl Value {
| Self::True
| Self::False
| Self::Dimension(..)
| Self::Color(..) => Value::Ident(
| Self::Color(..) => Value::String(
format!("{}{}{}/{}", q1, s1, q1, other.to_css_string(span)?),
QuoteKind::None,
),
Self::Null => Value::Ident(format!("{}{}{}/", q1, s1, q1), QuoteKind::None),
Self::Null => Value::String(format!("{}{}{}/", q1, s1, q1), QuoteKind::None),
_ => todo!(),
},
_ => match other {
Self::Ident(s, q) => Value::Ident(
Self::String(s, q) => Value::String(
format!("{}/{}{}{}", self.to_css_string(span)?, q, s, q),
QuoteKind::None,
),
Self::Null => {
Value::Ident(format!("{}/", self.to_css_string(span)?), QuoteKind::None)
Value::String(format!("{}/", self.to_css_string(span)?), QuoteKind::None)
}
_ => Value::Ident(
_ => Value::String(
format!(
"{}/{}",
self.to_css_string(span)?,
@ -736,7 +738,7 @@ impl Value {
pub fn neg(self, span: Span) -> SassResult<Self> {
Ok(match self.eval(span)?.node {
Value::Dimension(n, u) => Value::Dimension(-n, u),
v => Value::Ident(format!("-{}", v.to_css_string(span)?), QuoteKind::None),
v => Value::String(format!("-{}", v.to_css_string(span)?), QuoteKind::None),
})
}
}

View File

@ -58,7 +58,7 @@ fn parse_hex<I: Iterator<Item = Token>>(
span = span.merge(i.span);
} else {
return Ok(Spanned {
node: Value::Ident(format!("#{}", i.node), QuoteKind::None),
node: Value::String(format!("#{}", i.node), QuoteKind::None),
span: i.span,
});
}
@ -67,7 +67,7 @@ fn parse_hex<I: Iterator<Item = Token>>(
3 => {
let v = match u16::from_str_radix(&s, 16) {
Ok(a) => a,
Err(_) => return Ok(Value::Ident(format!("#{}", s), QuoteKind::None).span(span)),
Err(_) => return Ok(Value::String(format!("#{}", s), QuoteKind::None).span(span)),
};
let red = (((v & 0xf00) >> 8) * 0x11) as u8;
let green = (((v & 0x0f0) >> 4) * 0x11) as u8;
@ -80,7 +80,7 @@ fn parse_hex<I: Iterator<Item = Token>>(
4 => {
let v = match u16::from_str_radix(&s, 16) {
Ok(a) => a,
Err(_) => return Ok(Value::Ident(format!("#{}", s), QuoteKind::None).span(span)),
Err(_) => return Ok(Value::String(format!("#{}", s), QuoteKind::None).span(span)),
};
let red = (((v & 0xf000) >> 12) * 0x11) as u8;
let green = (((v & 0x0f00) >> 8) * 0x11) as u8;
@ -98,7 +98,7 @@ fn parse_hex<I: Iterator<Item = Token>>(
6 => {
let v = match u32::from_str_radix(&s, 16) {
Ok(a) => a,
Err(_) => return Ok(Value::Ident(format!("#{}", s), QuoteKind::None).span(span)),
Err(_) => return Ok(Value::String(format!("#{}", s), QuoteKind::None).span(span)),
};
let red = ((v & 0x00ff_0000) >> 16) as u8;
let green = ((v & 0x0000_ff00) >> 8) as u8;
@ -111,7 +111,7 @@ fn parse_hex<I: Iterator<Item = Token>>(
8 => {
let v = match u32::from_str_radix(&s, 16) {
Ok(a) => a,
Err(_) => return Ok(Value::Ident(format!("#{}", s), QuoteKind::None).span(span)),
Err(_) => return Ok(Value::String(format!("#{}", s), QuoteKind::None).span(span)),
};
let red = ((v & 0xff00_0000) >> 24) as u8;
let green = ((v & 0x00ff_0000) >> 16) as u8;
@ -264,7 +264,7 @@ fn eat_op<I: Iterator<Item = Token>>(
} else {
devour_whitespace(iter);
space_separated.push(Spanned {
node: Value::Ident(
node: Value::String(
format!("/{}", right.node.to_css_string(right.span)?),
QuoteKind::None,
),
@ -309,7 +309,7 @@ fn eat_op<I: Iterator<Item = Token>>(
devour_whitespace(iter);
// special case when the value is literally "and" or "or"
if iter.peek().is_none() {
space_separated.push(Value::Ident(op.to_string(), QuoteKind::None).span(op.span));
space_separated.push(Value::String(op.to_string(), QuoteKind::None).span(op.span));
} else if let Some(left) = space_separated.pop() {
devour_whitespace(iter);
let right = single_value(iter, scope, super_selector, left.span)?;
@ -371,31 +371,21 @@ fn single_value<I: Iterator<Item = Token>>(
devour_whitespace(iter);
let val = single_value(iter, scope, super_selector, span)?;
Spanned {
node: Value::Ident(
node: Value::String(
format!("/{}", val.node.to_css_string(val.span)?),
QuoteKind::None,
),
span: next.span.merge(val.span),
}
}
Op::And => {
Spanned {
node: Value::Ident(
"and".into(),
QuoteKind::None,
),
span: next.span,
}
}
Op::Or => {
Spanned {
node: Value::Ident(
"or".into(),
QuoteKind::None,
),
span: next.span,
}
}
Op::And => Spanned {
node: Value::String("and".into(), QuoteKind::None),
span: next.span,
},
Op::Or => Spanned {
node: Value::String("or".into(), QuoteKind::None),
span: next.span,
},
_ => {
return Err(("Expected expression.", next.span).into());
}
@ -577,7 +567,7 @@ impl Value {
s.push(':');
s.push_str(&eat_progid(toks, scope, super_selector)?);
return Ok(Spanned {
node: IntermediateValue::Value(Value::Ident(s, QuoteKind::None)),
node: IntermediateValue::Value(Value::String(s, QuoteKind::None)),
span,
});
}
@ -617,7 +607,7 @@ impl Value {
),
}
return Ok(
IntermediateValue::Value(Value::Ident(s, QuoteKind::None)).span(span)
IntermediateValue::Value(Value::String(s, QuoteKind::None)).span(span)
);
}
},
@ -644,7 +634,7 @@ impl Value {
"not" => IntermediateValue::Op(Op::Not),
"and" => IntermediateValue::Op(Op::And),
"or" => IntermediateValue::Op(Op::Or),
_ => IntermediateValue::Value(Value::Ident(s, QuoteKind::None)),
_ => IntermediateValue::Value(Value::String(s, QuoteKind::None)),
}
.span(span))
}