Skip to content

Commit

Permalink
feat(ast, parser): add optional oxc_regular_expression types to the…
Browse files Browse the repository at this point in the history
… parser and AST.
  • Loading branch information
rzvxa committed Aug 29, 2024
1 parent 062474d commit 1d12388
Show file tree
Hide file tree
Showing 14 changed files with 868 additions and 93 deletions.
2 changes: 2 additions & 0 deletions .github/.generated_ast_watch_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ src:
- 'crates/oxc_syntax/src/operator.rs'
- 'crates/oxc_span/src/span/types.rs'
- 'crates/oxc_span/src/source_type/types.rs'
- 'crates/oxc_regular_expression/src/ast.rs'
- 'crates/oxc_ast/src/generated/assert_layouts.rs'
- 'crates/oxc_ast/src/generated/ast_kind.rs'
- 'crates/oxc_ast/src/generated/ast_builder.rs'
- 'crates/oxc_ast/src/generated/visit.rs'
- 'crates/oxc_ast/src/generated/visit_mut.rs'
- 'crates/oxc_ast/src/generated/derive_clone_in.rs'
- 'crates/oxc_regular_expression/src/generated/derive_clone_in.rs'
- 'crates/oxc_syntax/src/generated/derive_clone_in.rs'
- 'crates/oxc_ast/src/generated/derive_get_span.rs'
- 'crates/oxc_ast/src/generated/derive_get_span_mut.rs'
Expand Down
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions crates/oxc_ast/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ workspace = true
doctest = false

[dependencies]
oxc_allocator = { workspace = true }
oxc_ast_macros = { workspace = true }
oxc_span = { workspace = true }
oxc_syntax = { workspace = true }
oxc_allocator = { workspace = true }
oxc_ast_macros = { workspace = true }
oxc_span = { workspace = true }
oxc_syntax = { workspace = true }
oxc_regular_expression = { workspace = true }

bitflags = { workspace = true }
num-bigint = { workspace = true }
Expand All @@ -44,4 +45,5 @@ serialize = [
"oxc_span/serialize",
"oxc_syntax/serialize",
"oxc_syntax/to_js_string",
"oxc_regular_expression/serialize"
]
7 changes: 4 additions & 3 deletions crates/oxc_ast/src/ast/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::hash::Hash;
use bitflags::bitflags;
use oxc_allocator::CloneIn;
use oxc_ast_macros::ast;
use oxc_regular_expression::ast::Pattern;
use oxc_span::{Atom, GetSpan, GetSpanMut, Span};
use oxc_syntax::number::{BigintBase, NumberBase};
#[cfg(feature = "serialize")]
Expand Down Expand Up @@ -86,7 +87,7 @@ pub struct BigIntLiteral<'a> {
///
/// <https://tc39.es/ecma262/#sec-literals-regular-expression-literals>
#[ast(visit)]
#[derive(Debug, Clone, Hash)]
#[derive(Debug, Hash)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
#[serde(tag = "type")]
Expand All @@ -103,12 +104,12 @@ pub struct RegExpLiteral<'a> {
///
/// <https://tc39.es/ecma262/multipage/text-processing.html#sec-regexp-regular-expression-objects>
#[ast]
#[derive(Debug, Clone, Hash)]
#[derive(Debug, Hash)]
#[generate_derive(CloneIn)]
#[cfg_attr(feature = "serialize", derive(Serialize, Tsify))]
pub struct RegExp<'a> {
/// The regex pattern between the slashes
pub pattern: Atom<'a>,
pub pattern: Pattern<'a>,
/// Regex flags after the closing slash
pub flags: RegExpFlags,
}
Expand Down
3 changes: 2 additions & 1 deletion crates/oxc_ast/src/ast_impl/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ impl<'a> fmt::Display for BigIntLiteral<'a> {

impl<'a> fmt::Display for RegExp<'a> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "/{}/{}", self.pattern, self.flags)
// TODO: fix me
write!(f, "/{}/{}", "TODO", self.flags)
}
}

Expand Down
Loading

0 comments on commit 1d12388

Please sign in to comment.