From 2bee4e273545b5867c826ee7ca113f185f1607f1 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Wed, 23 Oct 2024 03:36:30 +0000 Subject: [PATCH] refactor(ast, transformer)!: remove `BlockStatement::new` methods (#6783) First of a series of PRs removing `new` and `new_with_scope_id` etc methods from AST types. Following #6760, all AST node creation can now go via the AST builder. This lays groundwork for Node IDs (#5689), as we'll need `NodeId`s to be generated in `AstBuilder`, so that all nodes receive an ID. --- crates/oxc_ast/src/ast_impl/js.rs | 17 +---------------- .../src/typescript/annotations.rs | 10 +++++----- 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/crates/oxc_ast/src/ast_impl/js.rs b/crates/oxc_ast/src/ast_impl/js.rs index ce685ee66..4e82cf665 100644 --- a/crates/oxc_ast/src/ast_impl/js.rs +++ b/crates/oxc_ast/src/ast_impl/js.rs @@ -5,10 +5,7 @@ use std::{borrow::Cow, cell::Cell, fmt}; use oxc_allocator::{Address, Box, FromIn, GetAddress, Vec}; use oxc_span::{Atom, GetSpan, Span}; use oxc_syntax::{ - operator::UnaryOperator, - reference::ReferenceId, - scope::{ScopeFlags, ScopeId}, - symbol::SymbolId, + operator::UnaryOperator, reference::ReferenceId, scope::ScopeFlags, symbol::SymbolId, }; use crate::ast::*; @@ -818,18 +815,6 @@ impl<'a> Directive<'a> { } } -impl<'a> BlockStatement<'a> { - #[allow(missing_docs)] - pub fn new(span: Span, body: Vec<'a, Statement<'a>>) -> Self { - Self { span, body, scope_id: Cell::default() } - } - - #[allow(missing_docs)] - pub fn new_with_scope_id(span: Span, body: Vec<'a, Statement<'a>>, scope_id: ScopeId) -> Self { - Self { span, body, scope_id: Cell::new(Some(scope_id)) } - } -} - impl<'a> Declaration<'a> { #[allow(missing_docs)] pub fn is_typescript_syntax(&self) -> bool { diff --git a/crates/oxc_transformer/src/typescript/annotations.rs b/crates/oxc_transformer/src/typescript/annotations.rs index aa5b529dc..d385b0b49 100644 --- a/crates/oxc_transformer/src/typescript/annotations.rs +++ b/crates/oxc_transformer/src/typescript/annotations.rs @@ -562,9 +562,8 @@ impl<'a, 'ctx> TypeScriptAnnotations<'a, 'ctx> { ctx: &mut TraverseCtx<'a>, ) -> Statement<'a> { let scope_id = ctx.insert_scope_below_statement(&stmt, ScopeFlags::empty()); - let block = BlockStatement::new_with_scope_id(span, ctx.ast.vec1(stmt), scope_id); - block.scope_id.set(Some(scope_id)); - Statement::BlockStatement(ctx.ast.alloc(block)) + let block = ctx.ast.alloc_block_statement_with_scope_id(span, ctx.ast.vec1(stmt), scope_id); + Statement::BlockStatement(block) } fn replace_for_statement_body_with_empty_block_if_ts( @@ -583,8 +582,9 @@ impl<'a, 'ctx> TypeScriptAnnotations<'a, 'ctx> { ) { if stmt.is_typescript_syntax() { let scope_id = ctx.create_child_scope(parent_scope_id, ScopeFlags::empty()); - let block = BlockStatement::new_with_scope_id(stmt.span(), ctx.ast.vec(), scope_id); - *stmt = Statement::BlockStatement(ctx.ast.alloc(block)); + let block = + ctx.ast.alloc_block_statement_with_scope_id(stmt.span(), ctx.ast.vec(), scope_id); + *stmt = Statement::BlockStatement(block); } }