disallow - in unit when followed by [0-9\.]

This commit is contained in:
ConnorSkees 2020-04-20 04:05:02 -04:00
parent 4cdcf4f0d4
commit 4346756e9e
2 changed files with 17 additions and 3 deletions

View File

@ -359,10 +359,19 @@ fn ident_body<I: Iterator<Item = Token>>(
span = span.merge(tok.pos()); span = span.merge(tok.pos());
if unit && tok.kind == '-' { if unit && tok.kind == '-' {
// Disallow `-` followed by a dot or a digit digit in units. // Disallow `-` followed by a dot or a digit digit in units.
let second = match toks.peek_forward(1) {
Some(v) => v.clone(),
None => break,
};
toks.peek_backward(1).unwrap();
if second.kind == '.' || second.kind.is_ascii_digit() {
break;
}
toks.next(); toks.next();
// var second = scanner.peekChar(1); text.push('-');
// if (second != null && (second == $dot || isDigit(second))) break; text.push(toks.next().unwrap().kind);
// text.writeCharCode(scanner.readChar());
} else if is_name(tok.kind) { } else if is_name(tok.kind) {
text.push(toks.next().unwrap().kind); text.push(toks.next().unwrap().kind);
} else if tok.kind == '\\' { } else if tok.kind == '\\' {

View File

@ -69,6 +69,11 @@ test!(
"a {\n color: 10% + 10;\n}\n", "a {\n color: 10% + 10;\n}\n",
"a {\n color: 20%;\n}\n" "a {\n color: 20%;\n}\n"
); );
test!(
unit_no_hyphen,
"a {\n color: 1px-2px;\n}\n",
"a {\n color: -1px;\n}\n"
);
error!( error!(
display_single_mul, display_single_mul,
"a {\n color: 1rem * 1px;\n}\n", "Error: 1rem*px isn't a valid CSS value." "a {\n color: 1rem * 1px;\n}\n", "Error: 1rem*px isn't a valid CSS value."