1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:27:35 +00:00

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.
This commit is contained in:
davidot 2021-12-19 02:27:25 +01:00 committed by Linus Groh
parent 45578f58dc
commit a1308bfc60
2 changed files with 13 additions and 0 deletions

View file

@ -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;
}

View file

@ -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();