mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(minifier): may add space before RegExpLiteral (#397)
This commit is contained in:
parent
c01df484db
commit
3792b70dbd
2 changed files with 20 additions and 3 deletions
|
|
@ -801,6 +801,14 @@ impl Gen for BigintLiteral {
|
|||
|
||||
impl Gen for RegExpLiteral {
|
||||
fn gen(&self, p: &mut Printer) {
|
||||
let last = p.peek_nth(0);
|
||||
// Avoid forming a single-line comment or "</script" sequence
|
||||
if Some('/') == last
|
||||
|| (Some('<') == last
|
||||
&& self.regex.pattern.as_str().to_lowercase().starts_with("script"))
|
||||
{
|
||||
p.print(b' ');
|
||||
}
|
||||
p.print(b'/');
|
||||
p.print_str(self.regex.pattern.as_bytes());
|
||||
p.print(b'/');
|
||||
|
|
|
|||
|
|
@ -570,7 +570,7 @@ fn whitespace() {
|
|||
// test("1 + -Infinity", "1+-1/0");
|
||||
// test("1 - -Infinity", "1- -1/0;");
|
||||
|
||||
// test("/x/ / /y/", "/x// /y/");
|
||||
test("/x/ / /y/", "/x// /y/");
|
||||
test("/x/ + Foo", "/x/+Foo");
|
||||
test("/x/ instanceof Foo", "/x/ instanceof Foo");
|
||||
test("[x] instanceof Foo", "[x]instanceof Foo");
|
||||
|
|
@ -693,8 +693,17 @@ fn jsx() {}
|
|||
fn jsx_single_line() {}
|
||||
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn avoid_slash_script() {}
|
||||
fn avoid_slash_script() {
|
||||
// Positive cases
|
||||
test("x = 1 < /script/.exec(y).length", "x=1< /script/.exec(y).length");
|
||||
test("x = 1 < /SCRIPT/.exec(y).length", "x=1< /SCRIPT/.exec(y).length");
|
||||
test("x = 1 < /ScRiPt/.exec(y).length", "x=1< /ScRiPt/.exec(y).length");
|
||||
test("x = 1 << /script/.exec(y).length", "x=1<< /script/.exec(y).length");
|
||||
|
||||
// Negative cases
|
||||
test("x = 1 < / script/.exec(y).length", "x=1</ script/.exec(y).length");
|
||||
test("x = 1 << / script/.exec(y).length", "x=1<</ script/.exec(y).length");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn binary_operator_visitor() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue