Browse Source

Add unicode terminator to line comment (#2301)

This PR sloves the unicode terminator to single line comment
+ [{u+2028}](https://unicode-table.com/en/2028/)
+ [{u+2029}](https://unicode-table.com/en/2029/)
+ [related test](9215420dee/test/language/line-terminators/comment-single-ps.js)
+ [related test set](9215420dee/test/language/line-terminators)


Co-authored-by: creampnx_x <2270436024@qq.com>
pull/2305/head
creampnx_x 2 years ago
parent
commit
573ac14458
  1. 13
      boa_engine/src/syntax/lexer/comment.rs

13
boa_engine/src/syntax/lexer/comment.rs

@ -34,12 +34,13 @@ impl<R> Tokenizer<R> for SingleLineComment {
let _timer = Profiler::global().start_event("SingleLineComment", "Lexing"); let _timer = Profiler::global().start_event("SingleLineComment", "Lexing");
// Skip either to the end of the line or to the end of the input // Skip either to the end of the line or to the end of the input
while let Some(ch) = cursor.peek()? { while let Some(ch) = cursor.peek_char()? {
if ch == b'\n' || ch == b'\r' { let tried_ch = char::try_from(ch);
break; match tried_ch {
} Ok(c) if c == '\r' || c == '\n' || c == '\u{2028}' || c == '\u{2029}' => break,
// Consume char. _ => {}
cursor.next_byte()?.expect("Comment character vanished"); };
cursor.next_char().expect("Comment character vanished");
} }
Ok(Token::new( Ok(Token::new(
TokenKind::Comment, TokenKind::Comment,

Loading…
Cancel
Save