use lazy_static::lazy_static;
use onig::*;
lazy_static! {
pub static ref JS_ARGUMENTS: Regex = Regex::new(
r##"(?x)
\/\*[^*]*\*+(?>[^\/*][^*]*\*+)*\/
| \/\/[^\n\r]*
| (?<function>
\.insertAdjacentHTML
| \.querySelectorAll
| \.querySelector
| \.closest
| \.matches
| \.getElementById
| \.getElementsByClassName
| \.classList\s*+\.(?> add | remove | contains | replace | toggle )
| \.setAttribute
| history\s*+\.(?> pushState | replaceState )
| window\s*+\.(?> location\s*+\.assign | location\s*+\.replace | open )
)
(?<join>
\(\s*+
)
(?<arguments>
(?:
\s*
(?:
(?:
(?<quote>[`"'])
(?:
(?:
(?<=`)
(?:[^`\\] | \\.)*
`
)
| (?:
(?<=")
(?:[^"\\] | \\.)*
"
)
| (?:
(?<=')
(?:[^'\\] | \\.)*
'
)
)
)
| (?:
!*
(?:
\.?[$\w]+
)+
)
| (?:
\(
(?: [^()] | \k<arguments>)*
\)
)
| (?:
\{
(?: [^{}] | \k<arguments> )*
\}
)
| (?:
\[
(?: [^\[\]] | \k<arguments> )*
\]
)
)
(?:
\s*
(?:
,
| &&
| \|\|
| \?{1,2}
| :
| ={1,3}
| !={1,2}
| >={0,2}
| <={0,2}
)
)?
)++
)
"##
).unwrap();
pub static ref JS_PROPERTIES : Regex = Regex::new(
r##"(?x)
\/\*[^*]*\*+(?>[^\/*][^*]*\*+)*\/
| \/\/[^\n\r]*
| (?<function>
window.location.hash
| window.location.href
| window.location
| \.id
| \.className
| \.classList
(?>
\[[0-9]++\]
| \.value
| \.item
(?<arguments>
\(
[^)(]*+(?:(\g<arguments>)[^)(]*)*+
\)
)
)?
| \.innerHTML
| \.outerHTML
)
(?<join>
\s*+[=+\-!<>]{1,3}\s*+
)
(?<value>
(?:
`(?:[^`\\] | \\.)*
[^)]`
)
| (?:
"(?:[^"\\] | \\.)*
[^)]"
)
| (?:
'(?:[^'\\] | \\.)*
[^)]'
)
)
"##
).unwrap();
pub static ref HTML_SCRIPT_ELEMENT: Regex = Regex::new(
r##"(?x)
(?<tag_open>
<script[^>]*>
)
(?<script>
(?:.|\n|\r)*?
)
(?<tag_close>
<\/script>
)
"##
).unwrap();
pub static ref ESCAPED_JS_CHARS: Regex = Regex::new(
r##"(?x)
(?<url_encoded_char>
%[0-9A-Fa-f]{2}
)
| (?<hexdecimal>
\\x[0-9A-Fa-f]{2}
)
| (?<unicode>
\\u[0-9A-Fa-f]{4}
)
| (?<unicode_codepoint>
\\u{[0-9A-Fa-f]{1,}}
)
"##
).unwrap();
}