Browse Source

fix `NaN` is lexed as identifier, not as a number (#397)

close #393
pull/407/head
Yiyu Lin 5 years ago committed by GitHub
parent
commit
d4d27296fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      boa/src/syntax/lexer/mod.rs
  2. 13
      boa/src/syntax/lexer/tests.rs

1
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)

13
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(

Loading…
Cancel
Save