Commit 8818b373 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig

process(original_source, source)

parent f907f242
...@@ -49,7 +49,7 @@ use turbopack::{ ...@@ -49,7 +49,7 @@ use turbopack::{
ModuleAssetContext, ModuleAssetContext,
module_options::{ModuleOptionsContext, RuleCondition, transition_rule::TransitionRule}, module_options::{ModuleOptionsContext, RuleCondition, transition_rule::TransitionRule},
resolve_options_context::ResolveOptionsContext, resolve_options_context::ResolveOptionsContext,
transition::{FullContextTransition, Transition, TransitionOptions}, transition::{Transition, TransitionOptions},
}; };
use turbopack_core::{ use turbopack_core::{
asset::AssetContent, asset::AssetContent,
...@@ -116,6 +116,39 @@ impl AppProject { ...@@ -116,6 +116,39 @@ impl AppProject {
} }
} }
#[turbo_tasks::value(shared)]
pub struct ContextOriginalTransition {
module_context: ResolvedVc<ModuleAssetContext>,
}
#[turbo_tasks::value_impl]
impl ContextOriginalTransition {
#[turbo_tasks::function]
pub fn new(module_context: ResolvedVc<ModuleAssetContext>) -> Vc<ContextOriginalTransition> {
ContextOriginalTransition { module_context }.cell()
}
}
#[turbo_tasks::value_impl]
impl Transition for ContextOriginalTransition {
#[turbo_tasks::function]
fn process_source(
self: Vc<Self>,
original_source: Vc<Box<dyn Source>>,
_source: Vc<Box<dyn Source>>,
) -> Vc<Box<dyn Source>> {
original_source
}
#[turbo_tasks::function]
fn process_context(
&self,
_module_asset_context: Vc<ModuleAssetContext>,
) -> Vc<ModuleAssetContext> {
*self.module_context
}
}
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl AppProject { impl AppProject {
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -212,9 +245,9 @@ impl AppProject { ...@@ -212,9 +245,9 @@ impl AppProject {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn client_transition(self: Vc<Self>) -> Vc<FullContextTransition> { fn client_transition(self: Vc<Self>) -> Vc<Box<dyn Transition>> {
let module_context = self.client_module_context(); let module_context = self.client_module_context();
FullContextTransition::new(module_context) Vc::upcast(ContextOriginalTransition::new(module_context))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -664,9 +697,9 @@ impl AppProject { ...@@ -664,9 +697,9 @@ impl AppProject {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn ssr_transition(self: Vc<Self>) -> Vc<FullContextTransition> { fn ssr_transition(self: Vc<Self>) -> Vc<ContextOriginalTransition> {
let module_context = self.ssr_module_context(); let module_context = self.ssr_module_context();
FullContextTransition::new(module_context) ContextOriginalTransition::new(module_context)
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -685,7 +718,7 @@ impl AppProject { ...@@ -685,7 +718,7 @@ impl AppProject {
#[turbo_tasks::function] #[turbo_tasks::function]
fn shared_transition(self: Vc<Self>) -> Vc<Box<dyn Transition>> { fn shared_transition(self: Vc<Self>) -> Vc<Box<dyn Transition>> {
Vc::upcast(FullContextTransition::new(self.shared_module_context())) Vc::upcast(ContextOriginalTransition::new(self.shared_module_context()))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -727,9 +760,9 @@ impl AppProject { ...@@ -727,9 +760,9 @@ impl AppProject {
} }
#[turbo_tasks::function] #[turbo_tasks::function]
fn edge_ssr_transition(self: Vc<Self>) -> Vc<FullContextTransition> { fn edge_ssr_transition(self: Vc<Self>) -> Vc<ContextOriginalTransition> {
let module_context = self.edge_ssr_module_context(); let module_context = self.edge_ssr_module_context();
FullContextTransition::new(module_context) ContextOriginalTransition::new(module_context)
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -748,7 +781,7 @@ impl AppProject { ...@@ -748,7 +781,7 @@ impl AppProject {
#[turbo_tasks::function] #[turbo_tasks::function]
fn edge_shared_transition(self: Vc<Self>) -> Vc<Box<dyn Transition>> { fn edge_shared_transition(self: Vc<Self>) -> Vc<Box<dyn Transition>> {
Vc::upcast(FullContextTransition::new( Vc::upcast(ContextOriginalTransition::new(
self.edge_shared_module_context(), self.edge_shared_module_context(),
)) ))
} }
......
...@@ -39,7 +39,7 @@ use turbopack::{ ...@@ -39,7 +39,7 @@ use turbopack::{
ModuleAssetContext, ModuleAssetContext,
module_options::ModuleOptionsContext, module_options::ModuleOptionsContext,
resolve_options_context::ResolveOptionsContext, resolve_options_context::ResolveOptionsContext,
transition::{FullContextTransition, Transition, TransitionOptions}, transition::{Transition, TransitionOptions},
}; };
use turbopack_core::{ use turbopack_core::{
asset::AssetContent, asset::AssetContent,
...@@ -65,6 +65,7 @@ use turbopack_ecmascript::resolve::esm_resolve; ...@@ -65,6 +65,7 @@ use turbopack_ecmascript::resolve::esm_resolve;
use turbopack_nodejs::NodeJsChunkingContext; use turbopack_nodejs::NodeJsChunkingContext;
use crate::{ use crate::{
app::ContextOriginalTransition,
dynamic_imports::{ dynamic_imports::{
DynamicImportedChunks, NextDynamicChunkAvailability, collect_next_dynamic_chunks, DynamicImportedChunks, NextDynamicChunkAvailability, collect_next_dynamic_chunks,
}, },
...@@ -327,7 +328,7 @@ impl PagesProject { ...@@ -327,7 +328,7 @@ impl PagesProject {
#[turbo_tasks::function] #[turbo_tasks::function]
fn client_transition(self: Vc<Self>) -> Vc<Box<dyn Transition>> { fn client_transition(self: Vc<Self>) -> Vc<Box<dyn Transition>> {
Vc::upcast(FullContextTransition::new(self.client_module_context())) Vc::upcast(ContextOriginalTransition::new(self.client_module_context()))
} }
#[turbo_tasks::function] #[turbo_tasks::function]
......
...@@ -78,7 +78,7 @@ impl BaseLoaderTreeBuilder { ...@@ -78,7 +78,7 @@ impl BaseLoaderTreeBuilder {
ReferenceType::EcmaScriptModules(EcmaScriptModulesReferenceSubType::Undefined); ReferenceType::EcmaScriptModules(EcmaScriptModulesReferenceSubType::Undefined);
self.server_component_transition self.server_component_transition
.process(source, *self.module_asset_context, reference_type) .process(source, source, *self.module_asset_context, reference_type)
.module() .module()
} }
......
...@@ -23,14 +23,17 @@ impl Transition for NextCssClientReferenceTransition { ...@@ -23,14 +23,17 @@ impl Transition for NextCssClientReferenceTransition {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn process( async fn process(
self: Vc<Self>, self: Vc<Self>,
original_source: Vc<Box<dyn Source>>,
source: Vc<Box<dyn Source>>, source: Vc<Box<dyn Source>>,
rsc_module_asset_context: Vc<ModuleAssetContext>, rsc_module_asset_context: Vc<ModuleAssetContext>,
reference_type: ReferenceType, reference_type: ReferenceType,
) -> Result<Vc<ProcessResult>> { ) -> Result<Vc<ProcessResult>> {
let module = let module = self.await?.client_transition.process(
self.await? original_source,
.client_transition source,
.process(source, rsc_module_asset_context, reference_type); rsc_module_asset_context,
reference_type,
);
let ProcessResult::Module(module) = *module.await? else { let ProcessResult::Module(module) = *module.await? else {
return Ok(ProcessResult::Ignore.cell()); return Ok(ProcessResult::Ignore.cell());
......
...@@ -37,7 +37,8 @@ impl Transition for NextEcmascriptClientReferenceTransition { ...@@ -37,7 +37,8 @@ impl Transition for NextEcmascriptClientReferenceTransition {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn process( async fn process(
self: Vc<Self>, self: Vc<Self>,
source: Vc<Box<dyn Source>>, original_source: Vc<Box<dyn Source>>,
_source: Vc<Box<dyn Source>>,
module_asset_context: Vc<ModuleAssetContext>, module_asset_context: Vc<ModuleAssetContext>,
reference_type: ReferenceType, reference_type: ReferenceType,
) -> Result<Vc<ProcessResult>> { ) -> Result<Vc<ProcessResult>> {
...@@ -53,8 +54,8 @@ impl Transition for NextEcmascriptClientReferenceTransition { ...@@ -53,8 +54,8 @@ impl Transition for NextEcmascriptClientReferenceTransition {
let this = self.await?; let this = self.await?;
let ident = match part { let ident = match part {
Some(part) => source.ident().with_part(part.clone()), Some(part) => original_source.ident().with_part(part.clone()),
None => source.ident(), None => original_source.ident(),
}; };
let ident_ref = ident.await?; let ident_ref = ident.await?;
let ident_path = ident_ref.path.clone(); let ident_path = ident_ref.path.clone();
...@@ -70,9 +71,10 @@ impl Transition for NextEcmascriptClientReferenceTransition { ...@@ -70,9 +71,10 @@ impl Transition for NextEcmascriptClientReferenceTransition {
ident_ref.fragment.clone(), ident_ref.fragment.clone(),
)) ))
} else { } else {
source original_source
}; };
let client_module = this.client_transition.process( let client_module = this.client_transition.process(
client_source,
client_source, client_source,
module_asset_context, module_asset_context,
ReferenceType::Entry(EntryReferenceSubType::AppClientComponent), ReferenceType::Entry(EntryReferenceSubType::AppClientComponent),
...@@ -82,7 +84,8 @@ impl Transition for NextEcmascriptClientReferenceTransition { ...@@ -82,7 +84,8 @@ impl Transition for NextEcmascriptClientReferenceTransition {
}; };
let ssr_module = this.ssr_transition.process( let ssr_module = this.ssr_transition.process(
source, original_source,
original_source,
module_asset_context, module_asset_context,
ReferenceType::Entry(EntryReferenceSubType::AppClientComponent), ReferenceType::Entry(EntryReferenceSubType::AppClientComponent),
); );
......
...@@ -47,15 +47,19 @@ impl Transition for NextDynamicTransition { ...@@ -47,15 +47,19 @@ impl Transition for NextDynamicTransition {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn process( async fn process(
self: Vc<Self>, self: Vc<Self>,
original_source: Vc<Box<dyn Source>>,
source: Vc<Box<dyn Source>>, source: Vc<Box<dyn Source>>,
module_asset_context: Vc<ModuleAssetContext>, module_asset_context: Vc<ModuleAssetContext>,
_reference_type: ReferenceType, _reference_type: ReferenceType,
) -> Result<Vc<ProcessResult>> { ) -> Result<Vc<ProcessResult>> {
let module_asset_context = self.process_context(module_asset_context); let module_asset_context = self.process_context(module_asset_context);
let module = match self.await?.client_transition { let module = match self.await?.client_transition {
Some(client_transition) => { Some(client_transition) => client_transition.process(
client_transition.process(source, module_asset_context, ReferenceType::Undefined) original_source,
} source,
module_asset_context,
ReferenceType::Undefined,
),
None => module_asset_context.process(source, ReferenceType::Undefined), None => module_asset_context.process(source, ReferenceType::Undefined),
}; };
......
...@@ -425,6 +425,7 @@ impl ModuleAssetContext { ...@@ -425,6 +425,7 @@ impl ModuleAssetContext {
impl ModuleAssetContext { impl ModuleAssetContext {
async fn process_with_transition_rules( async fn process_with_transition_rules(
self: Vc<Self>, self: Vc<Self>,
original_source: ResolvedVc<Box<dyn Source>>,
source: ResolvedVc<Box<dyn Source>>, source: ResolvedVc<Box<dyn Source>>,
reference_type: ReferenceType, reference_type: ReferenceType,
) -> Result<Vc<ProcessResult>> { ) -> Result<Vc<ProcessResult>> {
...@@ -436,24 +437,27 @@ impl ModuleAssetContext { ...@@ -436,24 +437,27 @@ impl ModuleAssetContext {
.get_by_rules(source, &reference_type) .get_by_rules(source, &reference_type)
.await? .await?
{ {
transition.process(*source, self, reference_type) transition.process(*original_source, *source, self, reference_type)
} else { } else {
self.process_default(source, reference_type).await? self.process_default(original_source, source, reference_type)
.await?
}, },
) )
} }
async fn process_default( async fn process_default(
self: Vc<Self>, self: Vc<Self>,
original_source: ResolvedVc<Box<dyn Source>>,
source: ResolvedVc<Box<dyn Source>>, source: ResolvedVc<Box<dyn Source>>,
reference_type: ReferenceType, reference_type: ReferenceType,
) -> Result<Vc<ProcessResult>> { ) -> Result<Vc<ProcessResult>> {
process_default(self, source, reference_type, Vec::new()).await process_default(self, original_source, source, reference_type, Vec::new()).await
} }
} }
async fn process_default( async fn process_default(
module_asset_context: Vc<ModuleAssetContext>, module_asset_context: Vc<ModuleAssetContext>,
original_source: ResolvedVc<Box<dyn Source>>,
source: ResolvedVc<Box<dyn Source>>, source: ResolvedVc<Box<dyn Source>>,
reference_type: ReferenceType, reference_type: ReferenceType,
processed_rules: Vec<usize>, processed_rules: Vec<usize>,
...@@ -471,6 +475,7 @@ async fn process_default( ...@@ -471,6 +475,7 @@ async fn process_default(
} }
process_default_internal( process_default_internal(
module_asset_context, module_asset_context,
original_source,
source, source,
reference_type, reference_type,
processed_rules, processed_rules,
...@@ -481,6 +486,7 @@ async fn process_default( ...@@ -481,6 +486,7 @@ async fn process_default(
async fn process_default_internal( async fn process_default_internal(
module_asset_context: Vc<ModuleAssetContext>, module_asset_context: Vc<ModuleAssetContext>,
original_source: ResolvedVc<Box<dyn Source>>,
source: ResolvedVc<Box<dyn Source>>, source: ResolvedVc<Box<dyn Source>>,
reference_type: ReferenceType, reference_type: ReferenceType,
processed_rules: Vec<usize>, processed_rules: Vec<usize>,
...@@ -544,6 +550,7 @@ async fn process_default_internal( ...@@ -544,6 +550,7 @@ async fn process_default_internal(
.await? .await?
{ {
return Ok(transition.process( return Ok(transition.process(
*original_source,
*current_source, *current_source,
module_asset_context, module_asset_context,
reference_type, reference_type,
...@@ -553,6 +560,7 @@ async fn process_default_internal( ...@@ -553,6 +560,7 @@ async fn process_default_internal(
processed_rules.push(i); processed_rules.push(i);
return Box::pin(process_default( return Box::pin(process_default(
module_asset_context, module_asset_context,
original_source,
current_source, current_source,
reference_type, reference_type,
processed_rules, processed_rules,
...@@ -853,15 +861,15 @@ impl AssetContext for ModuleAssetContext { ...@@ -853,15 +861,15 @@ impl AssetContext for ModuleAssetContext {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn process( async fn process(
self: Vc<Self>, self: Vc<Self>,
asset: ResolvedVc<Box<dyn Source>>, source: ResolvedVc<Box<dyn Source>>,
reference_type: ReferenceType, reference_type: ReferenceType,
) -> Result<Vc<ProcessResult>> { ) -> Result<Vc<ProcessResult>> {
let this = self.await?; let this = self.await?;
if let Some(transition) = this.transition { if let Some(transition) = this.transition {
Ok(transition.process(*asset, self, reference_type)) Ok(transition.process(*source, *source, self, reference_type))
} else { } else {
Ok(self Ok(self
.process_with_transition_rules(asset, reference_type) .process_with_transition_rules(source, source, reference_type)
.await?) .await?)
} }
} }
......
...@@ -4,20 +4,20 @@ use crate::{ModuleAssetContext, transition::Transition}; ...@@ -4,20 +4,20 @@ use crate::{ModuleAssetContext, transition::Transition};
/// A transition that only affects the asset context. /// A transition that only affects the asset context.
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
pub struct FullContextTransition { pub struct ContextOriginalTransition {
module_context: ResolvedVc<ModuleAssetContext>, module_context: ResolvedVc<ModuleAssetContext>,
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl FullContextTransition { impl ContextOriginalTransition {
#[turbo_tasks::function] #[turbo_tasks::function]
pub fn new(module_context: ResolvedVc<ModuleAssetContext>) -> Vc<FullContextTransition> { pub fn new(module_context: ResolvedVc<ModuleAssetContext>) -> Vc<ContextOriginalTransition> {
FullContextTransition { module_context }.cell() ContextOriginalTransition { module_context }.cell()
} }
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl Transition for FullContextTransition { impl Transition for ContextOriginalTransition {
#[turbo_tasks::function] #[turbo_tasks::function]
fn process_context( fn process_context(
&self, &self,
......
pub(crate) mod full_context_transition; pub(crate) mod full_context_transition;
use anyhow::Result; use anyhow::Result;
pub use full_context_transition::FullContextTransition;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::{ResolvedVc, ValueDefault, Vc}; use turbo_tasks::{ResolvedVc, ValueDefault, Vc};
...@@ -23,8 +22,12 @@ use crate::{ ...@@ -23,8 +22,12 @@ use crate::{
pub trait Transition { pub trait Transition {
/// Apply modifications/wrapping to the source asset /// Apply modifications/wrapping to the source asset
#[turbo_tasks::function] #[turbo_tasks::function]
fn process_source(self: Vc<Self>, asset: Vc<Box<dyn Source>>) -> Vc<Box<dyn Source>> { fn process_source(
asset self: Vc<Self>,
_original_source: Vc<Box<dyn Source>>,
source: Vc<Box<dyn Source>>,
) -> Vc<Box<dyn Source>> {
source
} }
/// Apply modifications to the compile-time information /// Apply modifications to the compile-time information
...@@ -102,16 +105,17 @@ pub trait Transition { ...@@ -102,16 +105,17 @@ pub trait Transition {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn process( async fn process(
self: Vc<Self>, self: Vc<Self>,
asset: Vc<Box<dyn Source>>, original_source: Vc<Box<dyn Source>>,
source: Vc<Box<dyn Source>>,
module_asset_context: Vc<ModuleAssetContext>, module_asset_context: Vc<ModuleAssetContext>,
reference_type: ReferenceType, reference_type: ReferenceType,
) -> Result<Vc<ProcessResult>> { ) -> Result<Vc<ProcessResult>> {
let asset = self.process_source(asset); let source = self.process_source(original_source, source);
let module_asset_context = self.process_context(module_asset_context); let module_asset_context = self.process_context(module_asset_context);
let asset = asset.to_resolved().await?; let source = source.to_resolved().await?;
Ok(match &*module_asset_context Ok(match &*module_asset_context
.process_default(asset, reference_type) .process_default(original_source.to_resolved().await?, source, reference_type)
.await? .await?
.await? .await?
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment