mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:28:12 +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;
|
size_t trivia_start = m_position;
|
||||||
auto in_template = !m_template_states.is_empty();
|
auto in_template = !m_template_states.is_empty();
|
||||||
|
bool unterminated_comment = false;
|
||||||
|
|
||||||
if (!in_template || m_template_states.last().in_expr) {
|
if (!in_template || m_template_states.last().in_expr) {
|
||||||
// consume whitespace and comments
|
// consume whitespace and comments
|
||||||
|
@ -380,7 +381,11 @@ Token Lexer::next()
|
||||||
do {
|
do {
|
||||||
consume();
|
consume();
|
||||||
} while (!is_eof() && !is_block_comment_end());
|
} while (!is_eof() && !is_block_comment_end());
|
||||||
|
if (is_eof())
|
||||||
|
unterminated_comment = true;
|
||||||
consume(); // consume *
|
consume(); // consume *
|
||||||
|
if (is_eof())
|
||||||
|
unterminated_comment = true;
|
||||||
consume(); // consume /
|
consume(); // consume /
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
@ -542,7 +547,12 @@ Token Lexer::next()
|
||||||
consume();
|
consume();
|
||||||
}
|
}
|
||||||
} else if (m_current_char == EOF) {
|
} else if (m_current_char == EOF) {
|
||||||
token_type = TokenType::Eof;
|
if (unterminated_comment) {
|
||||||
|
token_type = TokenType::Invalid;
|
||||||
|
token_message = "Unterminated multi-line comment";
|
||||||
|
} else {
|
||||||
|
token_type = TokenType::Eof;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// There is only one four-char operator: >>>=
|
// There is only one four-char operator: >>>=
|
||||||
bool found_four_char_token = false;
|
bool found_four_char_token = false;
|
||||||
|
|
|
@ -21,3 +21,11 @@ return i;`;
|
||||||
|
|
||||||
expect(source).toEvalTo(1);
|
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