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

process(original_source, source)

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