From 485c871e8d9e3ef6928709f11f1569bf5967f4b4 Mon Sep 17 00:00:00 2001 From: rzvxa <3788964+rzvxa@users.noreply.github.com> Date: Tue, 9 Jul 2024 12:16:40 +0000 Subject: [PATCH] feat(ast): allow conversion from `Expression` into `Statement` with `FromIn` trait. (#4124) Our downstream rolldown is using this, If we want them to adopt our traits we should provide this implementation for them. https://github.com/rolldown/rolldown/blob/2cd2a367ee25c3d1f711fda9b1d3ead5982cfcff/crates/rolldown_ecmascript/src/allocator_helpers/into_in.rs#L24 --- crates/oxc_ast/src/ast_impl/js.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/oxc_ast/src/ast_impl/js.rs b/crates/oxc_ast/src/ast_impl/js.rs index 538235e10a5e3..4fdab1343fc05 100644 --- a/crates/oxc_ast/src/ast_impl/js.rs +++ b/crates/oxc_ast/src/ast_impl/js.rs @@ -5,8 +5,8 @@ use crate::ast::*; use std::{cell::Cell, fmt, hash::Hash}; -use oxc_allocator::{Box, Vec}; -use oxc_span::{Atom, CompactStr, SourceType, Span}; +use oxc_allocator::{Box, FromIn, Vec}; +use oxc_span::{Atom, CompactStr, GetSpan, SourceType, Span}; use oxc_syntax::{ operator::UnaryOperator, reference::{ReferenceFlag, ReferenceId}, @@ -665,6 +665,15 @@ impl<'a> Statement<'a> { } } +impl<'a> FromIn<'a, Expression<'a>> for Statement<'a> { + fn from_in(expression: Expression<'a>, alloc: &'a oxc_allocator::Allocator) -> Self { + Statement::ExpressionStatement(Box::from_in( + ExpressionStatement { span: expression.span(), expression }, + alloc, + )) + } +} + impl<'a> Directive<'a> { /// A Use Strict Directive is an ExpressionStatement in a Directive Prologue whose StringLiteral is either of the exact code point sequences "use strict" or 'use strict'. /// A Use Strict Directive may not contain an EscapeSequence or LineContinuation.