Skip to content

Commit

Permalink
fix NaN is lexed as identifier, not as a number (#397)
Browse files Browse the repository at this point in the history
close #393
  • Loading branch information
attila-lin authored May 13, 2020
1 parent fefb5a3 commit d4d2729
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions boa/src/syntax/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ impl<'a> Lexer<'a> {
"true" => TokenKind::BooleanLiteral(true),
"false" => TokenKind::BooleanLiteral(false),
"null" => TokenKind::NullLiteral,
"NaN" => TokenKind::NumericLiteral(NumericLiteral::Rational(f64::NAN)),
slice => {
if let Ok(keyword) = FromStr::from_str(slice) {
TokenKind::Keyword(keyword)
Expand Down
13 changes: 13 additions & 0 deletions boa/src/syntax/lexer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,19 @@ fn check_decrement_advances_lexer_2_places() {
);
}

#[test]
fn check_nan() {
let mut lexer = Lexer::new("let a = NaN;");
lexer.lex().expect("failed to lex");

match lexer.tokens[3].kind {
TokenKind::NumericLiteral(NumericLiteral::Rational(a)) => {
assert_eq!(a.is_nan(), true);
}
_ => assert!(false),
}
}

#[test]
fn numbers() {
let mut lexer = Lexer::new(
Expand Down

0 comments on commit d4d2729

Please sign in to comment.