mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
feat(prettier): sort regex flags (#1372)
This commit is contained in:
parent
5a6c83b0cc
commit
6d8fa7ff36
2 changed files with 11 additions and 13 deletions
|
|
@ -170,8 +170,6 @@ impl TryFrom<char> for RegExpFlags {
|
|||
}
|
||||
}
|
||||
|
||||
// TODO: should we implement TryFrom<&str> too?
|
||||
|
||||
impl fmt::Display for RegExpFlags {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if self.contains(Self::G) {
|
||||
|
|
|
|||
|
|
@ -1363,33 +1363,33 @@ impl<'a> Format<'a> for AssignmentPattern<'a> {
|
|||
|
||||
impl<'a> Format<'a> for RegExpFlags {
|
||||
fn format(&self, p: &mut Prettier<'a>) -> Doc<'a> {
|
||||
let mut str = vec![];
|
||||
|
||||
let mut string = std::vec::Vec::with_capacity(self.iter().count());
|
||||
if self.contains(Self::D) {
|
||||
str.push('d');
|
||||
string.push('d');
|
||||
}
|
||||
if self.contains(Self::G) {
|
||||
str.push('g');
|
||||
string.push('g');
|
||||
}
|
||||
if self.contains(Self::I) {
|
||||
str.push('i');
|
||||
string.push('i');
|
||||
}
|
||||
if self.contains(Self::M) {
|
||||
str.push('m');
|
||||
string.push('m');
|
||||
}
|
||||
if self.contains(Self::S) {
|
||||
str.push('s');
|
||||
string.push('s');
|
||||
}
|
||||
if self.contains(Self::V) {
|
||||
str.push('v');
|
||||
string.push('v');
|
||||
}
|
||||
if self.contains(Self::U) {
|
||||
str.push('u');
|
||||
string.push('u');
|
||||
}
|
||||
if self.contains(Self::Y) {
|
||||
str.push('y');
|
||||
string.push('y');
|
||||
}
|
||||
p.str(str.iter().collect::<String>().as_str())
|
||||
string.sort_unstable();
|
||||
p.str(&string.iter().collect::<String>())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue