Skip to content

Commit

Permalink
Support numbers with multiple leading zeroes (#1979)
Browse files Browse the repository at this point in the history
This Pull Request makes the non-octal-decimal-integer test pass. The test would previously fail for values with multiple leading zeroes.

It changes the following:

- Number lexer
  • Loading branch information
lupd authored and Razican committed Jun 8, 2022
1 parent c511707 commit 2537ac6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions boa_engine/src/syntax/lexer/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl<R> Tokenizer<R> for NumberLiteral {
legacy_octal = true;
let ch = char::from(byte);
if ch.is_digit(8) {
// LegacyOctalIntegerLiteral
// LegacyOctalIntegerLiteral, or a number with leading 0s.
if cursor.strict_mode() {
// LegacyOctalIntegerLiteral is forbidden with strict mode true.
return Err(Error::syntax(
Expand All @@ -275,7 +275,12 @@ impl<R> Tokenizer<R> for NumberLiteral {

buf.push(cursor.next_byte()?.expect("'0' character vanished"));

kind = NumericKind::Integer(8);
take_integer(&mut buf, cursor, NumericKind::Integer(8), false)?;

if !cursor.next_is_ascii_pred(&|c| c.is_digit(10) || c == '_')? {
// LegacyOctalIntegerLiteral
kind = NumericKind::Integer(8);
}
} else if ch.is_digit(10) {
// Indicates a numerical digit comes after then 0 but it isn't an octal digit
// so therefore this must be a number with an unneeded leading 0. This is
Expand Down

0 comments on commit 2537ac6

Please sign in to comment.