-
-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use bitflags
for oxc_regular_expression::ast::Flags
#5562
Comments
In regards to the #[ast]
#[derive(Debug, Clone)]
#[generate_derive(CloneIn, ContentEq, ContentHash)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
pub struct Flags {
pub span: Span,
pub flags: RegularExpressionFlags
} However, I think this span is redundant since we can easily obtain it at the |
I agree with this.
From the perspective of But from the perspective of the independent |
In what context do we need this information? Are we looking also to produce an How I look at it is that a flag always contains valid values and depending on the number of flags that are true we can calculate its span from a starting point, So in the impl<'a> RegularExpression<'a> {
pub fn flags_span(&self) -> Span {
Span::new(self.pattern.span.end + 1 /* skip `/` in the middle */, self.span.end)
}
} And we can also have this method on the impl RegularExpressionFlags {
pub fn active_flags(&self) -> u8 {
return number_of_active_flags
}
} Where do users care for flags without also having access to their regex literal? |
Yes, I was thinking in case of that. |
Closing, |
Currently our
oxc_ast::ast::literal::RegExpFlags
is defined using thebitflags
macro.oxc/crates/oxc_ast/src/ast/literal.rs
Lines 156 to 197 in af69393
While the
oxc_regular_expression::ast::Flags
is defined as such:oxc/crates/oxc_regular_expression/src/ast.rs
Lines 26 to 40 in af69393
I suggest we refactor
Flags
to usebitflags
and maybe rename it toRegularExpressionFlags
. Ideally, we should remove theRegExpFlags
and share this flag and its parser(probably throughRegularExpressionFlags::try_from("giv")
) throughout the project.We can still keep a
FlagsOption
that implementsInto<RegularExpressionFlags>
if we want to allow users to use a struct to pass in flags to the pattern parser.cc @leaysgur @overlookmotel
The text was updated successfully, but these errors were encountered: