Skip to content

Commit

Permalink
Fix single line comment lexing with CRLF line ending (#964)
Browse files Browse the repository at this point in the history
Co-authored-by: tofpie <tofpie@users.noreply.github.com>
  • Loading branch information
tofpie and tofpie authored Dec 14, 2020
1 parent ff13904 commit 8f590d7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions boa/src/syntax/lexer/comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ impl<R> Tokenizer<R> for SingleLineComment {

// Skip either to the end of the line or to the end of the input
while let Some(ch) = cursor.peek()? {
if ch == b'\n' {
if ch == b'\n' || ch == b'\r' {
break;
} else {
// Consume char.
cursor.next_byte()?.expect("Comment character vansihed");
cursor.next_byte()?.expect("Comment character vanished");
}
}
Ok(Token::new(
Expand Down
15 changes: 15 additions & 0 deletions boa/src/syntax/lexer/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ fn check_single_line_comment() {
expect_tokens(&mut lexer, &expected);
}

#[test]
fn check_single_line_comment_with_crlf_ending() {
let s1 = "var \r\n//This is a comment\r\ntrue";
let mut lexer = Lexer::new(s1.as_bytes());

let expected = [
TokenKind::Keyword(Keyword::Var),
TokenKind::LineTerminator,
TokenKind::LineTerminator,
TokenKind::BooleanLiteral(true),
];

expect_tokens(&mut lexer, &expected);
}

#[test]
fn check_multi_line_comment() {
let s = "var /* await \n break \n*/ x";
Expand Down

0 comments on commit 8f590d7

Please sign in to comment.