Skip to content

Commit

Permalink
Support numbers with multiple leading zeroes
Browse files Browse the repository at this point in the history
  • Loading branch information
lupd committed Mar 27, 2022
1 parent 3f3f0aa commit d528d16
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 d528d16

Please sign in to comment.