Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1557,7 +1557,11 @@ pub struct BindingRestElement<'a> {
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
// https://github.com/estree/estree/blob/master/es5.md#patterns
// https://github.com/DefinitelyTyped/DefinitelyTyped/blob/cd61c555bfc93e985b313263a42ed78074570d08/types/estree/index.d.ts#L411
#[estree(add_ts_def = "type ParamPattern = FormalParameter | FormalParameterRest")]
#[estree(
add_ts_def = "type ParamPattern = FormalParameter | FormalParameterRest",
add_fields(expression = false),
add_ts = "expression: false"
)]
pub struct Function<'a> {
pub span: Span,
pub r#type: FunctionType,
Expand Down Expand Up @@ -1695,9 +1699,11 @@ pub enum FormalParameterKind {
#[ast(visit)]
#[derive(Debug)]
#[generate_derive(CloneIn, GetSpan, GetSpanMut, ContentEq, ESTree)]
#[estree(rename = "BlockStatement")]
pub struct FunctionBody<'a> {
pub span: Span,
pub directives: Vec<'a, Directive<'a>>,
#[estree(rename = "body")]
pub statements: Vec<'a, Statement<'a>>,
Comment on lines 1705 to 1707
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

both directives and statements should be in body, but append_to macro seems to break for non optional field. I'll look into updating macro for this case separately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, extending #[estree(append_to = ...)] to cover appending Vecs too would be ideal. We could alternatively add #[estree(prepend_to = ...)], which would make more sense here. But I think for now we already have enough attributes - probably better to use append_to at least for now.

Let me know if you have trouble working out how to adapt the codegen. I think it mostly makes sense, but I wrote it, so of course it makes sense to me!

}

Expand Down
5 changes: 3 additions & 2 deletions crates/oxc_ast/src/generated/derive_estree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,7 @@ impl Serialize for Function<'_> {
map.serialize_entry("params", &self.params)?;
map.serialize_entry("returnType", &self.return_type)?;
map.serialize_entry("body", &self.body)?;
map.serialize_entry("expression", &false)?;
map.end()
}
}
Expand Down Expand Up @@ -1399,11 +1400,11 @@ impl Serialize for FormalParameterKind {
impl Serialize for FunctionBody<'_> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
let mut map = serializer.serialize_map(None)?;
map.serialize_entry("type", "FunctionBody")?;
map.serialize_entry("type", "BlockStatement")?;
map.serialize_entry("start", &self.span.start)?;
map.serialize_entry("end", &self.span.end)?;
map.serialize_entry("directives", &self.directives)?;
map.serialize_entry("statements", &self.statements)?;
map.serialize_entry("body", &self.statements)?;
map.end()
}
}
Expand Down
5 changes: 3 additions & 2 deletions npm/oxc-types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ export interface Function extends Span {
params: ParamPattern[];
returnType: TSTypeAnnotation | null;
body: FunctionBody | null;
expression: false;
}

export type ParamPattern = FormalParameter | FormalParameterRest;
Expand Down Expand Up @@ -576,9 +577,9 @@ export type FormalParameter =
export type FormalParameterKind = 'FormalParameter' | 'UniqueFormalParameters' | 'ArrowFormalParameters' | 'Signature';

export interface FunctionBody extends Span {
type: 'FunctionBody';
type: 'BlockStatement';
directives: Array<Directive>;
statements: Array<Statement>;
body: Array<Statement>;
}

export interface ArrowFunctionExpression extends Span {
Expand Down
Loading
Loading