Skip to content

Commit

Permalink
Merge 7281047 into 0c068cb
Browse files Browse the repository at this point in the history
  • Loading branch information
tofpie authored Dec 13, 2020
2 parents 0c068cb + 7281047 commit c5d3219
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 c5d3219

Please sign in to comment.