mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
### Every structure has 2 builder methods:
1. `xxx` e.g. `block_statement`
```rust
#[inline]
pub fn block_statement(self, span: Span, body: Vec<'a, Statement<'a>>) -> BlockStatement<'a> {
BlockStatement { span, body, scope_id: Default::default() }
}
```
2. `alloc_xxx` e.g. `alloc_block_statement`
```rust
#[inline]
pub fn alloc_block_statement(
self,
span: Span,
body: Vec<'a, Statement<'a>>,
) -> Box<'a, BlockStatement<'a>> {
self.block_statement(span, body).into_in(self.allocator)
}
```
### We generate 3 types of methods for enums:
1. `yyy_xxx` e.g. `statement_block`
```rust
#[inline]
pub fn statement_block(self, span: Span, body: Vec<'a, Statement<'a>>) -> Statement<'a> {
Statement::BlockStatement(self.alloc(self.block_statement(span, body)))
}
```
2. `yyy_from_xxx` e.g. `statement_from_block`
```rust
#[inline]
pub fn statement_from_block<T>(self, inner: T) -> Statement<'a>
where
T: IntoIn<'a, Box<'a, BlockStatement<'a>>>,
{
Statement::BlockStatement(inner.into_in(self.allocator))
}
```
3. `yyy_xxx` where `xxx` is inherited e.g. `statement_declaration`
```rust
#[inline]
pub fn statement_declaration(self, inner: Declaration<'a>) -> Statement<'a> {
Statement::from(inner)
}
```
------------
### Generic parameters:
We no longer accept `Box<'a, ADT>`, `Atom` or `&'a str`, Instead we use `IntoIn<'a, Box<'a, ADT>>`, `IntoIn<'a, Atom<'a>>` and `IntoIn<'a, &'a str>` respectively.
It allows us to rewrite things like this:
```rust
let ident = IdentifierReference::new(SPAN, Atom::from("require"));
let number_literal_expr = self.ast.expression_numeric_literal(
right_expr.span(),
num,
raw,
self.ast.new_str(num.to_string().as_str()),
NumberBase::Decimal,
);
```
As this:
```rust
let ident = IdentifierReference::new(SPAN, "require");
let number_literal_expr = self.ast.expression_numeric_literal(
right_expr.span(),
num,
raw,
num.to_string(),
NumberBase::Decimal,
);
```
|
||
|---|---|---|
| .. | ||
| oxc | ||
| oxc_allocator | ||
| oxc_ast | ||
| oxc_ast_macros | ||
| oxc_cfg | ||
| oxc_codegen | ||
| oxc_diagnostics | ||
| oxc_index | ||
| oxc_isolated_declarations | ||
| oxc_js_regex | ||
| oxc_language_server | ||
| oxc_linter | ||
| oxc_macros | ||
| oxc_minifier | ||
| oxc_module_lexer | ||
| oxc_parser | ||
| oxc_prettier | ||
| oxc_semantic | ||
| oxc_sourcemap | ||
| oxc_span | ||
| oxc_syntax | ||
| oxc_transformer | ||
| oxc_traverse | ||
| oxc_wasm | ||