Skip to content

Commit

Permalink
Apply sokra's suggestion, defer add_code_gen resolution until build
Browse files Browse the repository at this point in the history
  • Loading branch information
bgw committed Jan 10, 2025
1 parent 11eabbe commit e56d201
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 178 deletions.
17 changes: 17 additions & 0 deletions turbopack/crates/turbopack-ecmascript/src/code_gen.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Result;
use serde::{Deserialize, Serialize};
use swc_core::ecma::{
ast::Stmt,
Expand Down Expand Up @@ -106,6 +107,22 @@ pub trait CodeGenerateableWithAsyncModuleInfo {
) -> Vc<CodeGeneration>;
}

pub enum UnresolvedCodeGen {
CodeGenerateable(Vc<Box<dyn CodeGenerateable>>),
CodeGenerateableWithAsyncModuleInfo(Vc<Box<dyn CodeGenerateableWithAsyncModuleInfo>>),
}

impl UnresolvedCodeGen {
pub async fn to_resolved(&self) -> Result<CodeGen> {
Ok(match self {
Self::CodeGenerateable(vc) => CodeGen::CodeGenerateable(vc.to_resolved().await?),
Self::CodeGenerateableWithAsyncModuleInfo(vc) => {
CodeGen::CodeGenerateableWithAsyncModuleInfo(vc.to_resolved().await?)
}
})
}
}

#[derive(
Clone, Copy, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs, ValueDebugFormat, NonLocalValue,
)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
/// Makes code changes to remove export/import declarations and places the
/// expr/decl in a normal statement. Unnamed expr/decl will be named with the
/// magic identifier "export default"
#[turbo_tasks::value(shared)]
#[turbo_tasks::value]
#[derive(Hash, Debug)]
pub struct EsmModuleItem {
pub path: ResolvedVc<AstPath>,
Expand Down
Loading

0 comments on commit e56d201

Please sign in to comment.