mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
LibJS: Emit TokenType::Invalid for unterminated multi-line comments
This commit is contained in:
parent
03c1d43f6e
commit
19edcbd79c
2 changed files with 19 additions and 1 deletions
|
@ -362,6 +362,7 @@ Token Lexer::next()
|
|||
{
|
||||
size_t trivia_start = m_position;
|
||||
auto in_template = !m_template_states.is_empty();
|
||||
bool unterminated_comment = false;
|
||||
|
||||
if (!in_template || m_template_states.last().in_expr) {
|
||||
// consume whitespace and comments
|
||||
|
@ -380,7 +381,11 @@ Token Lexer::next()
|
|||
do {
|
||||
consume();
|
||||
} while (!is_eof() && !is_block_comment_end());
|
||||
if (is_eof())
|
||||
unterminated_comment = true;
|
||||
consume(); // consume *
|
||||
if (is_eof())
|
||||
unterminated_comment = true;
|
||||
consume(); // consume /
|
||||
} else {
|
||||
break;
|
||||
|
@ -542,7 +547,12 @@ Token Lexer::next()
|
|||
consume();
|
||||
}
|
||||
} else if (m_current_char == EOF) {
|
||||
if (unterminated_comment) {
|
||||
token_type = TokenType::Invalid;
|
||||
token_message = "Unterminated multi-line comment";
|
||||
} else {
|
||||
token_type = TokenType::Eof;
|
||||
}
|
||||
} else {
|
||||
// There is only one four-char operator: >>>=
|
||||
bool found_four_char_token = false;
|
||||
|
|
|
@ -21,3 +21,11 @@ return i;`;
|
|||
|
||||
expect(source).toEvalTo(1);
|
||||
});
|
||||
|
||||
test("unterminated multi-line comment", () => {
|
||||
expect("/*").not.toEval();
|
||||
expect("/**").not.toEval();
|
||||
expect("/*/").not.toEval();
|
||||
expect("/* foo").not.toEval();
|
||||
expect("foo /*").not.toEval();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue