From a1308bfc6090ec66c6d02f66def9acaaa7bd3ed4 Mon Sep 17 00:00:00 2001 From: davidot Date: Sun, 19 Dec 2021 02:27:25 +0100 Subject: [PATCH] LibJS: Make new lines in block comments reset line has token Before this a closing html comment would not be treated as a comment if directly following a block comment which was not the first token of its first line. --- Userland/Libraries/LibJS/Lexer.cpp | 4 ++++ Userland/Libraries/LibJS/Tests/comments-basic.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/Userland/Libraries/LibJS/Lexer.cpp b/Userland/Libraries/LibJS/Lexer.cpp index dc70354ed1..a439d0c684 100644 --- a/Userland/Libraries/LibJS/Lexer.cpp +++ b/Userland/Libraries/LibJS/Lexer.cpp @@ -530,6 +530,7 @@ Token Lexer::next() consume(); } while (!is_eof() && !is_line_terminator()); } else if (is_block_comment_start()) { + size_t start_line_number = m_line_number; consume(); do { consume(); @@ -540,6 +541,9 @@ Token Lexer::next() if (is_eof()) unterminated_comment = true; consume(); // consume / + + if (start_line_number != m_line_number) + line_has_token_yet = false; } else { break; } diff --git a/Userland/Libraries/LibJS/Tests/comments-basic.js b/Userland/Libraries/LibJS/Tests/comments-basic.js index 7ad452bf29..86d9d68a32 100644 --- a/Userland/Libraries/LibJS/Tests/comments-basic.js +++ b/Userland/Libraries/LibJS/Tests/comments-basic.js @@ -26,6 +26,15 @@ i;`; expect(source).toEvalTo(2); }); +test("html comments directly after block comment", () => { + expect("0 /* */-->i").not.toEval(); + expect(`0 /* + */-->i`).toEval(); + expect(`0 /* + */-->i + 'a'`).toEvalTo("a"); +}); + test("unterminated multi-line comment", () => { expect("/*").not.toEval(); expect("/**").not.toEval();