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.

2cd2a367ee/crates/rolldown_ecmascript/src/allocator_helpers/into_in.rs (L24)
This commit is contained in:
rzvxa 2024-07-09 12:16:40 +00:00
parent b936162093
commit 485c871e8d

View file

@ -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.