diff --git a/src/utils.rs b/src/utils.rs index 6a19525..5cab9ef 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -359,10 +359,19 @@ fn ident_body>( span = span.merge(tok.pos()); if unit && tok.kind == '-' { // 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(); - // var second = scanner.peekChar(1); - // if (second != null && (second == $dot || isDigit(second))) break; - // text.writeCharCode(scanner.readChar()); + text.push('-'); + text.push(toks.next().unwrap().kind); } else if is_name(tok.kind) { text.push(toks.next().unwrap().kind); } else if tok.kind == '\\' { diff --git a/tests/units.rs b/tests/units.rs index 4546781..3b7f339 100644 --- a/tests/units.rs +++ b/tests/units.rs @@ -69,6 +69,11 @@ test!( "a {\n color: 10% + 10;\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!( display_single_mul, "a {\n color: 1rem * 1px;\n}\n", "Error: 1rem*px isn't a valid CSS value."