refactor lowercasing of idents

avoid creating more strings than necessary
This commit is contained in:
ConnorSkees 2020-04-30 19:37:14 -04:00
parent 0aed492123
commit 1d518efeaf
2 changed files with 11 additions and 4 deletions

View File

@ -503,7 +503,9 @@ impl Value {
) -> SassResult<IntermediateValue> { ) -> SassResult<IntermediateValue> {
let Spanned { node: mut s, span } = eat_ident(toks, scope, super_selector)?; let Spanned { node: mut s, span } = eat_ident(toks, scope, super_selector)?;
if s == "progid" && toks.peek().is_some() && toks.peek().unwrap().kind == ':' { let lower = s.to_ascii_lowercase();
if lower == "progid" && toks.peek().is_some() && toks.peek().unwrap().kind == ':' {
toks.next(); toks.next();
s.push(':'); s.push(':');
s.push_str(&eat_progid(toks, scope, super_selector)?); s.push_str(&eat_progid(toks, scope, super_selector)?);
@ -528,7 +530,7 @@ impl Value {
})) }))
} }
None => { None => {
match s.to_ascii_lowercase().as_str() { match lower.as_str() {
"calc" | "element" | "expression" => { "calc" | "element" | "expression" => {
s.push_str(&eat_calc_args(toks, scope, super_selector)?) s.push_str(&eat_calc_args(toks, scope, super_selector)?)
} }
@ -557,14 +559,14 @@ impl Value {
)); ));
} }
if let Some(c) = NAMED_COLORS.get_by_left(&s.as_str()) { if let Some(c) = NAMED_COLORS.get_by_left(&lower.as_str()) {
return Ok(IntermediateValue::Value(Spanned { return Ok(IntermediateValue::Value(Spanned {
node: Value::Color(Box::new(Color::new(c[0], c[1], c[2], c[3], s))), node: Value::Color(Box::new(Color::new(c[0], c[1], c[2], c[3], s))),
span, span,
})); }));
} }
Ok(match s.to_ascii_lowercase().as_str() { Ok(match lower.as_str() {
"true" => IntermediateValue::Value(Value::True.span(span)), "true" => IntermediateValue::Value(Value::True.span(span)),
"false" => IntermediateValue::Value(Value::False.span(span)), "false" => IntermediateValue::Value(Value::False.span(span)),
"null" => IntermediateValue::Value(Value::Null.span(span)), "null" => IntermediateValue::Value(Value::Null.span(span)),

View File

@ -4,6 +4,11 @@
mod macros; mod macros;
test!(preserves_named_color_case, "a {\n color: OrAnGe;\n}\n"); test!(preserves_named_color_case, "a {\n color: OrAnGe;\n}\n");
test!(
named_color_casing_is_color,
"a {\n color: hue(RED);\n}\n",
"a {\n color: 0deg;\n}\n"
);
test!(preserves_hex_color_case, "a {\n color: #FfFfFf;\n}\n"); test!(preserves_hex_color_case, "a {\n color: #FfFfFf;\n}\n");
test!( test!(
preserves_hex_8_val_10000000, preserves_hex_8_val_10000000,