Skip to content

Commit

Permalink
feat(ast): allow conversion between ExpressionStatement and `Statem…
Browse files Browse the repository at this point in the history
…ent` with `FromIn` trait.

Our down stream rolldown is using this, If we want then to adopt our traits we should provide this implementation for them
  • Loading branch information
rzvxa committed Jul 8, 2024
1 parent 451cf2e commit 05f1f4d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 05f1f4d

Please sign in to comment.