Skip to content

Commit

Permalink
Allow HMTL close comments after single line delimited comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jedel1043 committed Apr 18, 2023
1 parent 1b3aac5 commit 539da3e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 38 deletions.
51 changes: 21 additions & 30 deletions boa_engine/src/builtins/regexp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,36 +293,27 @@ impl RegExp {
};

// 10. If u is true, then
let regexp = if flags.contains(RegExpFlags::UNICODE) {
// a. Let patternText be StringToCodePoints(P).
Regex::from_unicode(
p.code_points().map(CodePoint::as_u32),
Flags::new(f.code_points().map(CodePoint::as_u32)),
)
} else {
// 11. Else,
// a. Let patternText be the result of interpreting each of P's 16-bit elements as a Unicode BMP code point. UTF-16 decoding is not applied to the elements.
Regex::from_unicode(
p.iter().map(|surr| u32::from(*surr)),
Flags::new(f.code_points().map(CodePoint::as_u32)),
)
};

// 9. Let parseResult be ParsePattern(patternText, u).
// 10. If parseResult is a non-empty List of SyntaxError objects, throw a SyntaxError exception.
// 11. Assert: parseResult is a Pattern Parse Node.
// 12. Set obj.[[OriginalSource]] to P.
// 13. Set obj.[[OriginalFlags]] to F.
// 14. NOTE: The definitions of DotAll, IgnoreCase, Multiline, and Unicode in 22.2.2.1 refer to this value of obj.[[OriginalFlags]].
// 15. Set obj.[[RegExpMatcher]] to CompilePattern of parseResult.
let matcher = match regexp {
Err(error) => {
return Err(JsNativeError::syntax()
.with_message(format!("failed to create matcher: {}", error.text))
.into());
}
Ok(val) => val,
};
// a. Let patternText be StringToCodePoints(P).
// 11. Else,
// a. Let patternText be the result of interpreting each of P's 16-bit elements as a Unicode BMP code point. UTF-16 decoding is not applied to the elements.
// 12. Let parseResult be ParsePattern(patternText, u).
// 13. If parseResult is a non-empty List of SyntaxError objects, throw a SyntaxError exception.
// 14. Assert: parseResult is a Pattern Parse Node.
// 15. Set obj.[[OriginalSource]] to P.
// 16. Set obj.[[OriginalFlags]] to F.
// 17. Let capturingGroupsCount be CountLeftCapturingParensWithin(parseResult).
// 18. Let rer be the RegExp Record { [[IgnoreCase]]: i, [[Multiline]]: m, [[DotAll]]: s, [[Unicode]]: u, [[CapturingGroupsCount]]: capturingGroupsCount }.
// 19. Set obj.[[RegExpRecord]] to rer.
// 20. Set obj.[[RegExpMatcher]] to CompilePattern of parseResult with argument rer.
let matcher =
match Regex::from_unicode(p.code_points().map(CodePoint::as_u32), Flags::from(flags)) {
Err(error) => {
return Err(JsNativeError::syntax()
.with_message(format!("failed to create matcher: {}", error.text))
.into());
}
Ok(val) => val,
};

let regexp = Self {
matcher,
Expand Down
7 changes: 1 addition & 6 deletions boa_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,7 @@ impl<R> Lexer<R> {
}
}?;

if token.kind() == &TokenKind::Comment {
// Skip comment
self.next(interner)
} else {
Ok(Some(token))
}
Ok(Some(token))
} else {
Err(Error::syntax(
format!(
Expand Down
14 changes: 13 additions & 1 deletion boa_parser/src/lexer/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bitflags::bitflags;
use boa_ast::Position;
use boa_interner::{Interner, Sym};
use boa_profiler::Profiler;
use regress::Regex;
use regress::{Flags, Regex};
use std::{
io::{self, ErrorKind, Read},
str::{self, FromStr},
Expand Down Expand Up @@ -237,3 +237,15 @@ impl ToString for RegExpFlags {
s
}
}

impl From<RegExpFlags> for Flags {
fn from(value: RegExpFlags) -> Self {
Self {
icase: value.contains(RegExpFlags::IGNORE_CASE),
multiline: value.contains(RegExpFlags::MULTILINE),
dot_all: value.contains(RegExpFlags::DOT_ALL),
unicode: value.contains(RegExpFlags::UNICODE),
..Self::default()
}
}
}
2 changes: 1 addition & 1 deletion boa_parser/src/parser/cursor/buffered_lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ where
} else {
self.peeked[self.write_index] = self.lexer.next(interner)?;
}
self.write_index = (self.write_index + 1) % PEEK_BUF_SIZE;

self.write_index = (self.write_index + 1) % PEEK_BUF_SIZE;
debug_assert_ne!(
self.read_index, self.write_index,
"we reached the read index with the write index"
Expand Down
1 change: 1 addition & 0 deletions test_ignore.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ features = [
"decorators",
"array-grouping",
"IsHTMLDDA",
"legacy-regexp",

# Non-implemented Intl features
"intl-normative-optional",
Expand Down

0 comments on commit 539da3e

Please sign in to comment.