Skip to content

Commit

Permalink
fix(ast): do not include scope_id fields in JSON AST (#4858)
Browse files Browse the repository at this point in the history
Exclude `scope_id` fields from JSON AST (as produced by `oxc-parser` NPM
package). I neglected to flag them `#[serde(skip)]` when I added these
fields.
  • Loading branch information
overlookmotel committed Aug 13, 2024
1 parent c4354da commit c0b26f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct Program<'a> {
pub hashbang: Option<Hashbang<'a>>,
pub directives: Vec<'a, Directive<'a>>,
pub body: Vec<'a, Statement<'a>>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -1187,6 +1188,7 @@ pub struct BlockStatement<'a> {
#[serde(flatten)]
pub span: Span,
pub body: Vec<'a, Statement<'a>>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -1362,6 +1364,7 @@ pub struct ForStatement<'a> {
pub test: Option<Expression<'a>>,
pub update: Option<Expression<'a>>,
pub body: Statement<'a>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -1398,6 +1401,7 @@ pub struct ForInStatement<'a> {
pub left: ForStatementLeft<'a>,
pub right: Expression<'a>,
pub body: Statement<'a>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -1434,6 +1438,7 @@ pub struct ForOfStatement<'a> {
pub left: ForStatementLeft<'a>,
pub right: Expression<'a>,
pub body: Statement<'a>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -1500,6 +1505,7 @@ pub struct SwitchStatement<'a> {
pub discriminant: Expression<'a>,
#[scope(enter_before)]
pub cases: Vec<'a, SwitchCase<'a>>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -1567,6 +1573,7 @@ pub struct CatchClause<'a> {
pub span: Span,
pub param: Option<CatchParameter<'a>>,
pub body: Box<'a, BlockStatement<'a>>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -1735,6 +1742,7 @@ pub struct Function<'a> {
pub params: Box<'a, FormalParameters<'a>>,
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
pub body: Option<Box<'a, FunctionBody<'a>>>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -1832,6 +1840,7 @@ pub struct ArrowFunctionExpression<'a> {
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
/// See `expression` for whether this arrow expression returns an expression.
pub body: Box<'a, FunctionBody<'a>>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -1919,6 +1928,7 @@ pub struct Class<'a> {
pub declare: bool,
/// Id of the scope created by the [`Class`], including type parameters and
/// statements within the [`ClassBody`].
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -2176,6 +2186,7 @@ pub struct StaticBlock<'a> {
#[serde(flatten)]
pub span: Span,
pub body: Vec<'a, Statement<'a>>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down
8 changes: 8 additions & 0 deletions crates/oxc_ast/src/ast/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct TSEnumDeclaration<'a> {
pub members: Vec<'a, TSEnumMember<'a>>,
pub r#const: bool,
pub declare: bool,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -314,6 +315,7 @@ pub struct TSConditionalType<'a> {
pub extends_type: TSType<'a>,
pub true_type: TSType<'a>,
pub false_type: TSType<'a>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -759,6 +761,7 @@ pub struct TSTypeAliasDeclaration<'a> {
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
pub type_annotation: TSType<'a>,
pub declare: bool,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -805,6 +808,7 @@ pub struct TSInterfaceDeclaration<'a> {
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
pub body: Box<'a, TSInterfaceBody<'a>>,
pub declare: bool,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -914,6 +918,7 @@ pub struct TSMethodSignature<'a> {
pub params: Box<'a, FormalParameters<'a>>,
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand All @@ -930,6 +935,7 @@ pub struct TSConstructSignatureDeclaration<'a> {
pub params: Box<'a, FormalParameters<'a>>,
pub return_type: Option<Box<'a, TSTypeAnnotation<'a>>>,
pub type_parameters: Option<Box<'a, TSTypeParameterDeclaration<'a>>>,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -1007,6 +1013,7 @@ pub struct TSModuleDeclaration<'a> {
/// ```
pub kind: TSModuleDeclarationKind,
pub declare: bool,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down Expand Up @@ -1205,6 +1212,7 @@ pub struct TSMappedType<'a> {
pub type_annotation: Option<TSType<'a>>,
pub optional: TSMappedTypeModifierOperator,
pub readonly: TSMappedTypeModifierOperator,
#[serde(skip)]
#[clone_in(default)]
pub scope_id: Cell<Option<ScopeId>>,
}
Expand Down

0 comments on commit c0b26f4

Please sign in to comment.