From d4d27296fc6af92b2a637f3851ddfa0933796a63 Mon Sep 17 00:00:00 2001 From: Yiyu Lin Date: Thu, 14 May 2020 02:17:54 +0800 Subject: [PATCH] fix `NaN` is lexed as identifier, not as a number (#397) close #393 --- boa/src/syntax/lexer/mod.rs | 1 + boa/src/syntax/lexer/tests.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/boa/src/syntax/lexer/mod.rs b/boa/src/syntax/lexer/mod.rs index cda968f4e15..c0696df90d9 100644 --- a/boa/src/syntax/lexer/mod.rs +++ b/boa/src/syntax/lexer/mod.rs @@ -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) diff --git a/boa/src/syntax/lexer/tests.rs b/boa/src/syntax/lexer/tests.rs index a50bc3b5b63..dcf2131aec9 100644 --- a/boa/src/syntax/lexer/tests.rs +++ b/boa/src/syntax/lexer/tests.rs @@ -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(