remove redundant number accessor
This commit is contained in:
parent
00845ad518
commit
795a160e01
@ -1,7 +1,5 @@
|
|||||||
use codemap::Spanned;
|
use codemap::Spanned;
|
||||||
|
|
||||||
use crate::token::Token;
|
|
||||||
|
|
||||||
use super::AstExpr;
|
use super::AstExpr;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -36,7 +34,6 @@ impl Interpolation {
|
|||||||
self.contents.push(InterpolationPart::Expr(expr));
|
self.contents.push(InterpolationPart::Expr(expr));
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: cow?
|
|
||||||
pub fn add_string(&mut self, s: String) {
|
pub fn add_string(&mut self, s: String) {
|
||||||
match self.contents.last_mut() {
|
match self.contents.last_mut() {
|
||||||
Some(InterpolationPart::String(existing)) => *existing += &s,
|
Some(InterpolationPart::String(existing)) => *existing += &s,
|
||||||
|
@ -60,9 +60,9 @@ fn hsl_3_args(
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(Value::Color(Box::new(Color::from_hsla_fn(
|
Ok(Value::Color(Box::new(Color::from_hsla_fn(
|
||||||
Number(hue.num().rem_euclid(360.0)),
|
Number(hue.num.rem_euclid(360.0)),
|
||||||
saturation.num() / Number(100.0),
|
saturation.num / Number(100.0),
|
||||||
lightness.num() / Number(100.0),
|
lightness.num / Number(100.0),
|
||||||
Number(alpha),
|
Number(alpha),
|
||||||
))))
|
))))
|
||||||
}
|
}
|
||||||
@ -179,7 +179,7 @@ pub(crate) fn adjust_hue(mut args: ArgumentResult, visitor: &mut Visitor) -> Sas
|
|||||||
let degrees = args
|
let degrees = args
|
||||||
.get_err(1, "degrees")?
|
.get_err(1, "degrees")?
|
||||||
.assert_number_with_name("degrees", args.span())?
|
.assert_number_with_name("degrees", args.span())?
|
||||||
.num();
|
.num;
|
||||||
|
|
||||||
Ok(Value::Color(Box::new(color.adjust_hue(degrees))))
|
Ok(Value::Color(Box::new(color.adjust_hue(degrees))))
|
||||||
}
|
}
|
||||||
@ -200,7 +200,7 @@ fn lighten(mut args: ArgumentResult, visitor: &mut Visitor) -> SassResult<Value>
|
|||||||
let amount = args
|
let amount = args
|
||||||
.get_err(1, "amount")?
|
.get_err(1, "amount")?
|
||||||
.assert_number_with_name("amount", args.span())?;
|
.assert_number_with_name("amount", args.span())?;
|
||||||
let amount = bound!(args, "amount", amount.num(), amount.unit, 0, 100) / Number(100.0);
|
let amount = bound!(args, "amount", amount.num, amount.unit, 0, 100) / Number(100.0);
|
||||||
|
|
||||||
Ok(Value::Color(Box::new(color.lighten(amount))))
|
Ok(Value::Color(Box::new(color.lighten(amount))))
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ fn opacify(mut args: ArgumentResult, visitor: &mut Visitor) -> SassResult<Value>
|
|||||||
.get_err(1, "amount")?
|
.get_err(1, "amount")?
|
||||||
.assert_number_with_name("amount", args.span())?;
|
.assert_number_with_name("amount", args.span())?;
|
||||||
|
|
||||||
let amount = bound!(args, "amount", amount.num(), amount.unit(), 0, 1);
|
let amount = bound!(args, "amount", amount.num, amount.unit(), 0, 1);
|
||||||
|
|
||||||
Ok(Value::Color(Box::new(color.fade_in(amount))))
|
Ok(Value::Color(Box::new(color.fade_in(amount))))
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ pub(crate) fn random(mut args: ArgumentResult, visitor: &mut Visitor) -> SassRes
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
let limit = limit.assert_number_with_name("limit", args.span())?.num();
|
let limit = limit.assert_number_with_name("limit", args.span())?.num;
|
||||||
let limit_int = limit.assert_int_with_name("limit", args.span())?;
|
let limit_int = limit.assert_int_with_name("limit", args.span())?;
|
||||||
|
|
||||||
if limit.is_one() {
|
if limit.is_one() {
|
||||||
|
@ -93,7 +93,7 @@ pub(crate) fn str_slice(mut args: ArgumentResult, visitor: &mut Visitor) -> Sass
|
|||||||
.assert_number_with_name("start-at", span)?;
|
.assert_number_with_name("start-at", span)?;
|
||||||
start.assert_no_units("start-at", span)?;
|
start.assert_no_units("start-at", span)?;
|
||||||
|
|
||||||
let start = start.num().assert_int(span)?;
|
let start = start.num.assert_int(span)?;
|
||||||
|
|
||||||
let start = if start == 0 {
|
let start = if start == 0 {
|
||||||
1
|
1
|
||||||
@ -117,7 +117,7 @@ pub(crate) fn str_slice(mut args: ArgumentResult, visitor: &mut Visitor) -> Sass
|
|||||||
|
|
||||||
end.assert_no_units("end-at", span)?;
|
end.assert_no_units("end-at", span)?;
|
||||||
|
|
||||||
let mut end = end.num().assert_int(span)?;
|
let mut end = end.num.assert_int(span)?;
|
||||||
|
|
||||||
if end < 0 {
|
if end < 0 {
|
||||||
end += str_len as i64 + 1;
|
end += str_len as i64 + 1;
|
||||||
@ -203,7 +203,7 @@ pub(crate) fn str_insert(mut args: ArgumentResult, visitor: &mut Visitor) -> Sas
|
|||||||
.get_err(2, "index")?
|
.get_err(2, "index")?
|
||||||
.assert_number_with_name("index", span)?;
|
.assert_number_with_name("index", span)?;
|
||||||
index.assert_no_units("index", span)?;
|
index.assert_no_units("index", span)?;
|
||||||
let index_int = index.num().assert_int_with_name("index", span)?;
|
let index_int = index.num.assert_int_with_name("index", span)?;
|
||||||
|
|
||||||
if s1.is_empty() {
|
if s1.is_empty() {
|
||||||
return Ok(Value::String(substr, quotes));
|
return Ok(Value::String(substr, quotes));
|
||||||
|
@ -1703,9 +1703,9 @@ impl<'a> Visitor<'a> {
|
|||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
let from = from_number.num().assert_int(from_span)?;
|
let from = from_number.num.assert_int(from_span)?;
|
||||||
let mut to = to_number
|
let mut to = to_number
|
||||||
.num()
|
.num
|
||||||
.convert(to_number.unit(), from_number.unit())
|
.convert(to_number.unit(), from_number.unit())
|
||||||
.assert_int(to_span)?;
|
.assert_int(to_span)?;
|
||||||
|
|
||||||
|
@ -101,8 +101,8 @@ impl SassCalculation {
|
|||||||
}
|
}
|
||||||
CalculationArg::Number(n)
|
CalculationArg::Number(n)
|
||||||
if minimum.is_none()
|
if minimum.is_none()
|
||||||
|| minimum.as_ref().unwrap().num()
|
|| minimum.as_ref().unwrap().num
|
||||||
> n.num().convert(&n.unit, &minimum.as_ref().unwrap().unit) =>
|
> n.num.convert(&n.unit, &minimum.as_ref().unwrap().unit) =>
|
||||||
{
|
{
|
||||||
minimum = Some(n.clone());
|
minimum = Some(n.clone());
|
||||||
}
|
}
|
||||||
@ -145,8 +145,8 @@ impl SassCalculation {
|
|||||||
}
|
}
|
||||||
CalculationArg::Number(n)
|
CalculationArg::Number(n)
|
||||||
if maximum.is_none()
|
if maximum.is_none()
|
||||||
|| maximum.as_ref().unwrap().num()
|
|| maximum.as_ref().unwrap().num
|
||||||
< n.num().convert(&n.unit, &maximum.as_ref().unwrap().unit) =>
|
< n.num.convert(&n.unit, &maximum.as_ref().unwrap().unit) =>
|
||||||
{
|
{
|
||||||
maximum = Some(n.clone());
|
maximum = Some(n.clone());
|
||||||
}
|
}
|
||||||
@ -193,11 +193,11 @@ impl SassCalculation {
|
|||||||
Some(CalculationArg::Number(max)),
|
Some(CalculationArg::Number(max)),
|
||||||
) => {
|
) => {
|
||||||
if min.is_comparable_to(&value) && min.is_comparable_to(&max) {
|
if min.is_comparable_to(&value) && min.is_comparable_to(&max) {
|
||||||
if value.num <= min.num().convert(min.unit(), value.unit()) {
|
if value.num <= min.num.convert(min.unit(), value.unit()) {
|
||||||
return Ok(Value::Dimension(min));
|
return Ok(Value::Dimension(min));
|
||||||
}
|
}
|
||||||
|
|
||||||
if value.num >= max.num().convert(max.unit(), value.unit()) {
|
if value.num >= max.num.convert(max.unit(), value.unit()) {
|
||||||
return Ok(Value::Dimension(max));
|
return Ok(Value::Dimension(max));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,11 +178,6 @@ impl SassNumber {
|
|||||||
|| known_compatibilities_by_unit(&other.unit).is_none()
|
|| known_compatibilities_by_unit(&other.unit).is_none()
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: remove
|
|
||||||
pub fn num(&self) -> Number {
|
|
||||||
self.num
|
|
||||||
}
|
|
||||||
|
|
||||||
// todo: remove
|
// todo: remove
|
||||||
pub fn unit(&self) -> &Unit {
|
pub fn unit(&self) -> &Unit {
|
||||||
&self.unit
|
&self.unit
|
||||||
|
Loading…
x
Reference in New Issue
Block a user