allow units beginning with a single -

This commit is contained in:
Connor Skees 2020-08-17 03:58:29 -04:00
parent cb046f7be7
commit 9b9946c0ee
2 changed files with 41 additions and 0 deletions

View File

@ -476,6 +476,22 @@ impl<'a> Parser<'a> {
span = span.merge(u.span);
Unit::from(u.node)
}
'-' => {
if let Some(Token { kind, .. }) = self.toks.peek_next().cloned() {
self.toks.reset_cursor();
if matches!(kind, 'a'..='z' | 'A'..='Z' | '_' | '\\' | '\u{7f}'..=std::char::MAX)
{
let u = self.parse_identifier_no_interpolation(true)?;
span = span.merge(u.span);
Unit::from(u.node)
} else {
Unit::None
}
} else {
self.toks.reset_cursor();
Unit::None
}
}
'%' => {
span = span.merge(self.toks.next().unwrap().pos());
Unit::Percent

View File

@ -127,6 +127,31 @@ test!(
"a {\n color: unit((1 / 1in) * 1in);\n}\n",
"a {\n color: \"\";\n}\n"
);
test!(
unit_begins_with_single_hyphen,
"a {\n color: unit(1-em);\n}\n",
"a {\n color: \"-em\";\n}\n"
);
test!(
unit_begins_with_two_hyphens,
"a {\n color: 1--em;\n}\n",
"a {\n color: 1 --em;\n}\n"
);
test!(
unit_begins_with_escape_sequence,
"a {\n color: unit(1\\65);\n}\n",
"a {\n color: \"e\";\n}\n"
);
test!(
unit_begins_with_escape_sequence_followed_by_space_and_hyphen,
"a {\n color: unit(1\\65 -);\n}\n",
"a {\n color: \"e-\";\n}\n"
);
test!(
unit_begins_with_single_hyphen_followed_by_escape_sequence,
"a {\n color: unit(1-\\65);\n}\n",
"a {\n color: \"-e\";\n}\n"
);
error!(
display_single_div_with_none_numerator,
"a {\n color: (1 / 1em);\n}\n", "Error: 1em^-1 isn't a valid CSS value."