mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
feat(printer) Print RegExpLiteral (#1269)
This commit is contained in:
parent
1cc003f194
commit
1fb12d0088
1 changed files with 38 additions and 1 deletions
|
|
@ -481,7 +481,12 @@ impl<'a> Format<'a> for BigintLiteral {
|
|||
|
||||
impl<'a> Format<'a> for RegExpLiteral {
|
||||
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
||||
Doc::Line
|
||||
let mut parts = p.vec();
|
||||
parts.push(p.str("/"));
|
||||
parts.push(p.str(self.regex.pattern.as_str()));
|
||||
parts.push(p.str("/"));
|
||||
parts.push(format!(p, self.regex.flags));
|
||||
Doc::Array(parts)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1011,3 +1016,35 @@ impl<'a> Format<'a> for AssignmentPattern<'a> {
|
|||
array![p, format!(p, self.left), string!(p, " = "), format!(p, self.right)]
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Format<'a> for RegExpFlags {
|
||||
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
||||
let mut str = vec![];
|
||||
|
||||
if self.contains(Self::D) {
|
||||
str.push('d');
|
||||
}
|
||||
if self.contains(Self::G) {
|
||||
str.push('g');
|
||||
}
|
||||
if self.contains(Self::I) {
|
||||
str.push('i');
|
||||
}
|
||||
if self.contains(Self::M) {
|
||||
str.push('m');
|
||||
}
|
||||
if self.contains(Self::S) {
|
||||
str.push('s');
|
||||
}
|
||||
if self.contains(Self::V) {
|
||||
str.push('v');
|
||||
}
|
||||
if self.contains(Self::U) {
|
||||
str.push('u');
|
||||
}
|
||||
if self.contains(Self::Y) {
|
||||
str.push('y');
|
||||
}
|
||||
p.str(str.iter().collect::<String>().as_str())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue