Unverified Commit d170370a authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: move get_inner_asset into ecmascript module (#93191)

`resolve_origin.get_inner_asset` showed up in Luke's statistics at a
very high place.
But in reality, there are only 1-3 modules per page that have any inner
assets (the templates, and the edge wrapper modules).
`resolve_origin.get_inner_asset` is in the hottest hot path (resolving
references), so let's simply move this logic into the
EcmascriptModuleAsset itself.

Behavioral differences to before:
- only works with static ESM `import`s, dynamic `import()`, `require`,
`require.resolve`. But these are the only places that currently use it
anyway.

```
0d9738112f mischnic/remove-get-inner-asset
pnpm next build --experimental-build-mode=compile  353.40s user 52.96s system 748% cpu 54.265 total
pnpm next build --experimental-build-mode=compile  349.42s user 53.84s system 744% cpu 54.198 total
pnpm next build --experimental-build-mode=compile  352.42s user 54.46s system 741% cpu 54.874 total

3cb77c84 canary
pnpm next build --experimental-build-mode=compile  367.91s user 58.06s system 726% cpu 58.672 total
pnpm next build --experimental-build-mode=compile  362.97s user 57.68s system 746% cpu 56.379 total
pnpm next build --experimental-build-mode=compile  364.59s user 57.01s system 724% cpu 58.167 total
```
parent fb06f5f3
...@@ -616,8 +616,11 @@ export interface TraceQueryOptions { ...@@ -616,8 +616,11 @@ export interface TraceQueryOptions {
parent?: string parent?: string
/** When `true` (default), aggregate child spans with the same name. */ /** When `true` (default), aggregate child spans with the same name. */
aggregated?: boolean aggregated?: boolean
/** Sort mode: `"value"` for duration descending, `"name"` for alphabetical. Omit for execution order. */ /**
sort?: 'value' | 'name' * Sort mode: `"value"` for duration descending, `"name"` for alphabetical.
* Omit for execution order (no sorting).
*/
sort?: string
/** Optional substring search query applied to span name/category. */ /** Optional substring search query applied to span name/category. */
search?: string search?: string
/** 1-based page number. Default `1`. */ /** 1-based page number. Default `1`. */
......
...@@ -6,7 +6,7 @@ use turbo_tasks::{ResolvedVc, Upcast, Vc}; ...@@ -6,7 +6,7 @@ use turbo_tasks::{ResolvedVc, Upcast, Vc};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use super::{ModuleResolveResult, options::ResolveOptions, parse::Request}; use super::{ModuleResolveResult, options::ResolveOptions, parse::Request};
use crate::{context::AssetContext, module::OptionModule, reference_type::ReferenceType}; use crate::{context::AssetContext, reference_type::ReferenceType};
/// A location where resolving can occur from. It carries some meta information /// A location where resolving can occur from. It carries some meta information
/// that are needed for resolving from here. /// that are needed for resolving from here.
...@@ -24,14 +24,6 @@ pub trait ResolveOrigin { ...@@ -24,14 +24,6 @@ pub trait ResolveOrigin {
#[turbo_tasks::function] #[turbo_tasks::function]
fn asset_context(self: Vc<Self>) -> Vc<Box<dyn AssetContext>>; fn asset_context(self: Vc<Self>) -> Vc<Box<dyn AssetContext>>;
/// Get an inner asset form this origin that doesn't require resolving but
/// is directly attached
#[turbo_tasks::function]
fn get_inner_asset(self: Vc<Self>, request: Vc<Request>) -> Vc<OptionModule> {
let _ = request;
Vc::cell(None)
}
/// Get the resolve options that apply for this origin. /// Get the resolve options that apply for this origin.
#[turbo_tasks::function] #[turbo_tasks::function]
async fn resolve_options(self: Vc<Self>) -> Result<Vc<ResolveOptions>> { async fn resolve_options(self: Vc<Self>) -> Result<Vc<ResolveOptions>> {
...@@ -62,18 +54,18 @@ impl<T> ResolveOriginExt for T ...@@ -62,18 +54,18 @@ impl<T> ResolveOriginExt for T
where where
T: ResolveOrigin + Upcast<Box<dyn ResolveOrigin>>, T: ResolveOrigin + Upcast<Box<dyn ResolveOrigin>>,
{ {
fn resolve_asset( async fn resolve_asset(
self: Vc<Self>, self: Vc<Self>,
request: Vc<Request>, request: Vc<Request>,
options: Vc<ResolveOptions>, options: Vc<ResolveOptions>,
reference_type: ReferenceType, reference_type: ReferenceType,
) -> impl Future<Output = Result<Vc<ModuleResolveResult>>> + Send { ) -> Result<Vc<ModuleResolveResult>> {
resolve_asset( Ok(self.asset_context().to_resolved().await?.resolve_asset(
Vc::upcast_non_strict(self), self.origin_path().owned().await?,
request, *request.to_resolved().await?,
options, *options.to_resolved().await?,
reference_type, reference_type,
) ))
} }
fn with_transition(self: ResolvedVc<Self>, transition: RcStr) -> Vc<Box<dyn ResolveOrigin>> { fn with_transition(self: ResolvedVc<Self>, transition: RcStr) -> Vc<Box<dyn ResolveOrigin>> {
...@@ -87,27 +79,6 @@ where ...@@ -87,27 +79,6 @@ where
} }
} }
async fn resolve_asset(
resolve_origin: Vc<Box<dyn ResolveOrigin>>,
request: Vc<Request>,
options: Vc<ResolveOptions>,
reference_type: ReferenceType,
) -> Result<Vc<ModuleResolveResult>> {
if let Some(asset) = *resolve_origin.get_inner_asset(request).await? {
return Ok(*ModuleResolveResult::module(asset));
}
Ok(resolve_origin
.asset_context()
.to_resolved()
.await?
.resolve_asset(
resolve_origin.origin_path().owned().await?,
*request.to_resolved().await?,
*options.to_resolved().await?,
reference_type,
))
}
/// A resolve origin for some path and context without additional modifications. /// A resolve origin for some path and context without additional modifications.
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct PlainResolveOrigin { pub struct PlainResolveOrigin {
...@@ -163,9 +134,4 @@ impl ResolveOrigin for ResolveOriginWithTransition { ...@@ -163,9 +134,4 @@ impl ResolveOrigin for ResolveOriginWithTransition {
.asset_context() .asset_context()
.with_transition(self.transition.clone()) .with_transition(self.transition.clone())
} }
#[turbo_tasks::function]
fn get_inner_asset(&self, request: Vc<Request>) -> Vc<OptionModule> {
self.previous.get_inner_asset(request)
}
} }
...@@ -91,14 +91,11 @@ use turbopack_core::{ ...@@ -91,14 +91,11 @@ use turbopack_core::{
compile_time_info::CompileTimeInfo, compile_time_info::CompileTimeInfo,
context::AssetContext, context::AssetContext,
ident::AssetIdent, ident::AssetIdent,
module::{Module, ModuleSideEffects, OptionModule}, module::{Module, ModuleSideEffects},
module_graph::ModuleGraph, module_graph::ModuleGraph,
reference::ModuleReferences, reference::ModuleReferences,
reference_type::InnerAssets, reference_type::InnerAssets,
resolve::{ resolve::{FindContextFileResult, find_context_file, origin::ResolveOrigin, package_json},
FindContextFileResult, find_context_file, origin::ResolveOrigin, package_json,
parse::Request,
},
source::Source, source::Source,
source_map::GenerateSourceMap, source_map::GenerateSourceMap,
}; };
...@@ -977,19 +974,6 @@ impl ResolveOrigin for EcmascriptModuleAsset { ...@@ -977,19 +974,6 @@ impl ResolveOrigin for EcmascriptModuleAsset {
fn asset_context(&self) -> Vc<Box<dyn AssetContext>> { fn asset_context(&self) -> Vc<Box<dyn AssetContext>> {
*self.asset_context *self.asset_context
} }
#[turbo_tasks::function]
async fn get_inner_asset(&self, request: Vc<Request>) -> Result<Vc<OptionModule>> {
Ok(Vc::cell(if let Some(inner_assets) = &self.inner_assets {
if let Some(request) = request.await?.request() {
inner_assets.await?.get(&request).copied()
} else {
None
}
} else {
None
}))
}
} }
/// The transformed contents of an Ecmascript module. /// The transformed contents of an Ecmascript module.
......
...@@ -11,6 +11,7 @@ use turbo_tasks::{ ...@@ -11,6 +11,7 @@ use turbo_tasks::{
use turbopack_core::{ use turbopack_core::{
chunk::{ChunkingContext, ChunkingType}, chunk::{ChunkingContext, ChunkingType},
issue::IssueSource, issue::IssueSource,
module::Module,
reference::ModuleReference, reference::ModuleReference,
reference_type::CommonJsReferenceSubType, reference_type::CommonJsReferenceSubType,
resolve::{ModuleResolveResult, ResolveErrorMode, origin::ResolveOrigin, parse::Request}, resolve::{ModuleResolveResult, ResolveErrorMode, origin::ResolveOrigin, parse::Request},
...@@ -28,6 +29,7 @@ use crate::{ ...@@ -28,6 +29,7 @@ use crate::{
runtime_functions::TURBOPACK_CACHE, runtime_functions::TURBOPACK_CACHE,
}; };
/// Generic CommonJS reference that doesn't perform any codegen. Used for tracing
#[turbo_tasks::value] #[turbo_tasks::value]
#[derive(Hash, Debug, ValueToString)] #[derive(Hash, Debug, ValueToString)]
#[value_to_string("generic commonjs {request}")] #[value_to_string("generic commonjs {request}")]
...@@ -86,6 +88,7 @@ pub struct CjsRequireAssetReference { ...@@ -86,6 +88,7 @@ pub struct CjsRequireAssetReference {
issue_source: IssueSource, issue_source: IssueSource,
error_mode: ResolveErrorMode, error_mode: ResolveErrorMode,
chunking_type_attribute: Option<SpecifiedChunkingType>, chunking_type_attribute: Option<SpecifiedChunkingType>,
resolve_override: Option<ResolvedVc<Box<dyn Module>>>,
} }
impl CjsRequireAssetReference { impl CjsRequireAssetReference {
...@@ -95,6 +98,7 @@ impl CjsRequireAssetReference { ...@@ -95,6 +98,7 @@ impl CjsRequireAssetReference {
issue_source: IssueSource, issue_source: IssueSource,
error_mode: ResolveErrorMode, error_mode: ResolveErrorMode,
chunking_type_attribute: Option<SpecifiedChunkingType>, chunking_type_attribute: Option<SpecifiedChunkingType>,
resolve_override: Option<ResolvedVc<Box<dyn Module>>>,
) -> Self { ) -> Self {
CjsRequireAssetReference { CjsRequireAssetReference {
origin, origin,
...@@ -102,6 +106,7 @@ impl CjsRequireAssetReference { ...@@ -102,6 +106,7 @@ impl CjsRequireAssetReference {
issue_source, issue_source,
error_mode, error_mode,
chunking_type_attribute, chunking_type_attribute,
resolve_override,
} }
} }
} }
...@@ -110,6 +115,10 @@ impl CjsRequireAssetReference { ...@@ -110,6 +115,10 @@ impl CjsRequireAssetReference {
impl ModuleReference for CjsRequireAssetReference { impl ModuleReference for CjsRequireAssetReference {
#[turbo_tasks::function] #[turbo_tasks::function]
fn resolve_reference(&self) -> Vc<ModuleResolveResult> { fn resolve_reference(&self) -> Vc<ModuleResolveResult> {
if let Some(resolved) = &self.resolve_override {
return *ModuleResolveResult::module(*resolved);
}
cjs_resolve( cjs_resolve(
*self.origin, *self.origin,
*self.request, *self.request,
...@@ -216,6 +225,7 @@ pub struct CjsRequireResolveAssetReference { ...@@ -216,6 +225,7 @@ pub struct CjsRequireResolveAssetReference {
issue_source: IssueSource, issue_source: IssueSource,
error_mode: ResolveErrorMode, error_mode: ResolveErrorMode,
chunking_type_attribute: Option<SpecifiedChunkingType>, chunking_type_attribute: Option<SpecifiedChunkingType>,
resolve_override: Option<ResolvedVc<Box<dyn Module>>>,
} }
impl CjsRequireResolveAssetReference { impl CjsRequireResolveAssetReference {
...@@ -225,6 +235,7 @@ impl CjsRequireResolveAssetReference { ...@@ -225,6 +235,7 @@ impl CjsRequireResolveAssetReference {
issue_source: IssueSource, issue_source: IssueSource,
error_mode: ResolveErrorMode, error_mode: ResolveErrorMode,
chunking_type_attribute: Option<SpecifiedChunkingType>, chunking_type_attribute: Option<SpecifiedChunkingType>,
resolve_override: Option<ResolvedVc<Box<dyn Module>>>,
) -> Self { ) -> Self {
CjsRequireResolveAssetReference { CjsRequireResolveAssetReference {
origin, origin,
...@@ -232,6 +243,7 @@ impl CjsRequireResolveAssetReference { ...@@ -232,6 +243,7 @@ impl CjsRequireResolveAssetReference {
issue_source, issue_source,
error_mode, error_mode,
chunking_type_attribute, chunking_type_attribute,
resolve_override,
} }
} }
} }
...@@ -240,6 +252,10 @@ impl CjsRequireResolveAssetReference { ...@@ -240,6 +252,10 @@ impl CjsRequireResolveAssetReference {
impl ModuleReference for CjsRequireResolveAssetReference { impl ModuleReference for CjsRequireResolveAssetReference {
#[turbo_tasks::function] #[turbo_tasks::function]
fn resolve_reference(&self) -> Vc<ModuleResolveResult> { fn resolve_reference(&self) -> Vc<ModuleResolveResult> {
if let Some(resolved) = &self.resolve_override {
return *ModuleResolveResult::module(*resolved);
}
cjs_resolve( cjs_resolve(
*self.origin, *self.origin,
*self.request, *self.request,
......
...@@ -333,6 +333,7 @@ pub struct EsmAssetReference { ...@@ -333,6 +333,7 @@ pub struct EsmAssetReference {
pub import_externals: bool, pub import_externals: bool,
pub tree_shaking_mode: Option<TreeShakingMode>, pub tree_shaking_mode: Option<TreeShakingMode>,
pub is_pure_import: bool, pub is_pure_import: bool,
pub resolve_override: Option<ResolvedVc<Box<dyn Module>>>,
} }
impl EsmAssetReference { impl EsmAssetReference {
...@@ -356,6 +357,7 @@ impl EsmAssetReference { ...@@ -356,6 +357,7 @@ impl EsmAssetReference {
import_usage: ImportUsage, import_usage: ImportUsage,
import_externals: bool, import_externals: bool,
tree_shaking_mode: Option<TreeShakingMode>, tree_shaking_mode: Option<TreeShakingMode>,
resolve_override: Option<ResolvedVc<Box<dyn Module>>>,
) -> Self { ) -> Self {
EsmAssetReference { EsmAssetReference {
module, module,
...@@ -368,6 +370,7 @@ impl EsmAssetReference { ...@@ -368,6 +370,7 @@ impl EsmAssetReference {
import_externals, import_externals,
tree_shaking_mode, tree_shaking_mode,
is_pure_import: false, is_pure_import: false,
resolve_override,
} }
} }
...@@ -381,6 +384,7 @@ impl EsmAssetReference { ...@@ -381,6 +384,7 @@ impl EsmAssetReference {
import_usage: ImportUsage, import_usage: ImportUsage,
import_externals: bool, import_externals: bool,
tree_shaking_mode: Option<TreeShakingMode>, tree_shaking_mode: Option<TreeShakingMode>,
resolve_override: Option<ResolvedVc<Box<dyn Module>>>,
) -> Self { ) -> Self {
EsmAssetReference { EsmAssetReference {
module, module,
...@@ -393,6 +397,7 @@ impl EsmAssetReference { ...@@ -393,6 +397,7 @@ impl EsmAssetReference {
import_externals, import_externals,
tree_shaking_mode, tree_shaking_mode,
is_pure_import: true, is_pure_import: true,
resolve_override,
} }
} }
pub(crate) fn get_referenced_asset(self: Vc<Self>) -> Vc<ReferencedAsset> { pub(crate) fn get_referenced_asset(self: Vc<Self>) -> Vc<ReferencedAsset> {
...@@ -404,6 +409,9 @@ impl EsmAssetReference { ...@@ -404,6 +409,9 @@ impl EsmAssetReference {
impl ModuleReference for EsmAssetReference { impl ModuleReference for EsmAssetReference {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> { async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
if let Some(resolved) = &self.resolve_override {
return Ok(*ModuleResolveResult::module(*resolved));
}
let ty = if let Some(loader) = self.annotations.as_ref().and_then(|a| a.turbopack_loader()) let ty = if let Some(loader) = self.annotations.as_ref().and_then(|a| a.turbopack_loader())
{ {
// Resolve the loader path relative to the importing file // Resolve the loader path relative to the importing file
......
...@@ -12,6 +12,7 @@ use turbopack_core::{ ...@@ -12,6 +12,7 @@ use turbopack_core::{
chunk::{ChunkingContext, ChunkingType}, chunk::{ChunkingContext, ChunkingType},
environment::ChunkLoading, environment::ChunkLoading,
issue::IssueSource, issue::IssueSource,
module::Module,
reference::ModuleReference, reference::ModuleReference,
reference_type::EcmaScriptModulesReferenceSubType, reference_type::EcmaScriptModulesReferenceSubType,
resolve::{ resolve::{
...@@ -46,6 +47,7 @@ pub struct EsmAsyncAssetReference { ...@@ -46,6 +47,7 @@ pub struct EsmAsyncAssetReference {
/// Detected from destructured await, member access on await, .then() /// Detected from destructured await, member access on await, .then()
/// callback destructuring, or webpackExports/turbopackExports comments. /// callback destructuring, or webpackExports/turbopackExports comments.
pub export_usage: ExportUsage, pub export_usage: ExportUsage,
pub resolve_override: Option<ResolvedVc<Box<dyn Module>>>,
} }
impl EsmAsyncAssetReference { impl EsmAsyncAssetReference {
...@@ -67,6 +69,7 @@ impl EsmAsyncAssetReference { ...@@ -67,6 +69,7 @@ impl EsmAsyncAssetReference {
error_mode: ResolveErrorMode, error_mode: ResolveErrorMode,
import_externals: bool, import_externals: bool,
export_usage: ExportUsage, export_usage: ExportUsage,
resolve_override: Option<ResolvedVc<Box<dyn Module>>>,
) -> Self { ) -> Self {
EsmAsyncAssetReference { EsmAsyncAssetReference {
origin, origin,
...@@ -76,6 +79,7 @@ impl EsmAsyncAssetReference { ...@@ -76,6 +79,7 @@ impl EsmAsyncAssetReference {
error_mode, error_mode,
import_externals, import_externals,
export_usage, export_usage,
resolve_override,
} }
} }
} }
...@@ -84,6 +88,10 @@ impl EsmAsyncAssetReference { ...@@ -84,6 +88,10 @@ impl EsmAsyncAssetReference {
impl ModuleReference for EsmAsyncAssetReference { impl ModuleReference for EsmAsyncAssetReference {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> { async fn resolve_reference(&self) -> Result<Vc<ModuleResolveResult>> {
if let Some(resolved) = &self.resolve_override {
return Ok(*ModuleResolveResult::module(*resolved));
}
esm_resolve( esm_resolve(
*self.get_origin().to_resolved().await?, *self.get_origin().to_resolved().await?,
*self.request, *self.request,
......
...@@ -77,7 +77,7 @@ use turbopack_core::{ ...@@ -77,7 +77,7 @@ use turbopack_core::{
issue::{IssueExt, IssueSeverity, IssueSource, StyledString, analyze::AnalyzeIssue}, issue::{IssueExt, IssueSeverity, IssueSource, StyledString, analyze::AnalyzeIssue},
module::{Module, ModuleSideEffects}, module::{Module, ModuleSideEffects},
reference::{ModuleReference, ModuleReferences}, reference::{ModuleReference, ModuleReferences},
reference_type::CommonJsReferenceSubType, reference_type::{CommonJsReferenceSubType, InnerAssets},
resolve::{ resolve::{
ExportUsage, FindContextFileResult, ImportUsage, ModulePart, ResolveErrorMode, ExportUsage, FindContextFileResult, ImportUsage, ModulePart, ResolveErrorMode,
find_context_file, find_context_file,
...@@ -479,6 +479,8 @@ struct AnalysisState<'a> { ...@@ -479,6 +479,8 @@ struct AnalysisState<'a> {
import_references: &'a [ResolvedVc<EsmAssetReference>], import_references: &'a [ResolvedVc<EsmAssetReference>],
// The import map from the eval context, used to match dep strings to import references. // The import map from the eval context, used to match dep strings to import references.
imports: &'a ImportMap, imports: &'a ImportMap,
// Resolve overrides for imports
inner_assets: Option<ReadRef<InnerAssets>>,
} }
impl AnalysisState<'_> { impl AnalysisState<'_> {
...@@ -557,6 +559,12 @@ async fn analyze_ecmascript_module_internal( ...@@ -557,6 +559,12 @@ async fn analyze_ecmascript_module_internal(
analysis.ident = source.ident().to_string().owned().await?; analysis.ident = source.ident().to_string().owned().await?;
} }
let inner_assets = if let Some(assets) = raw_module.inner_assets {
Some(assets.await?)
} else {
None
};
// Is this a typescript file that requires analyzing type references? // Is this a typescript file that requires analyzing type references?
let analyze_types = match &ty { let analyze_types = match &ty {
EcmascriptModuleAssetType::Typescript { analyze_types, .. } => *analyze_types, EcmascriptModuleAssetType::Typescript { analyze_types, .. } => *analyze_types,
...@@ -756,6 +764,16 @@ async fn analyze_ecmascript_module_internal( ...@@ -756,6 +764,16 @@ async fn analyze_ecmascript_module_internal(
let mut import_references = Vec::with_capacity(eval_context.imports.references().len()); let mut import_references = Vec::with_capacity(eval_context.imports.references().len());
for (i, r) in eval_context.imports.references().enumerate() { for (i, r) in eval_context.imports.references().enumerate() {
let mut should_add_evaluation = false; let mut should_add_evaluation = false;
let resolve_override = if let Some(inner_assets) = &inner_assets
&& let Some(req) = r.module_path.as_str()
&& let Some(a) = inner_assets.get(req)
{
Some(*a)
} else {
None
};
let reference = EsmAssetReference::new( let reference = EsmAssetReference::new(
module, module,
ResolvedVc::upcast(module), ResolvedVc::upcast(module),
...@@ -799,6 +817,7 @@ async fn analyze_ecmascript_module_internal( ...@@ -799,6 +817,7 @@ async fn analyze_ecmascript_module_internal(
.unwrap_or_default(), .unwrap_or_default(),
import_externals, import_externals,
options.tree_shaking_mode, options.tree_shaking_mode,
resolve_override,
) )
.resolved_cell(); .resolved_cell();
...@@ -972,6 +991,7 @@ async fn analyze_ecmascript_module_internal( ...@@ -972,6 +991,7 @@ async fn analyze_ecmascript_module_internal(
is_esm, is_esm,
import_references: &import_references, import_references: &import_references,
imports: &eval_context.imports, imports: &eval_context.imports,
inner_assets,
}; };
enum Action { enum Action {
...@@ -1411,6 +1431,7 @@ async fn analyze_ecmascript_module_internal( ...@@ -1411,6 +1431,7 @@ async fn analyze_ecmascript_module_internal(
original_reference.import_usage.clone(), original_reference.import_usage.clone(),
original_reference.import_externals, original_reference.import_externals,
original_reference.tree_shaking_mode, original_reference.tree_shaking_mode,
original_reference.resolve_override,
) )
.resolved_cell() .resolved_cell()
}, },
...@@ -1778,6 +1799,7 @@ async fn handle_dynamic_import<G: Fn(Vec<Effect>) + Send + Sync>( ...@@ -1778,6 +1799,7 @@ async fn handle_dynamic_import<G: Fn(Vec<Effect>) + Send + Sync>(
handler, handler,
origin, origin,
source, source,
&state.inner_assets,
ignore_dynamic_requests, ignore_dynamic_requests,
analysis, analysis,
error_mode, error_mode,
...@@ -1794,6 +1816,7 @@ async fn handle_dynamic_import_with_linked_args( ...@@ -1794,6 +1816,7 @@ async fn handle_dynamic_import_with_linked_args(
handler: &Handler, handler: &Handler,
origin: ResolvedVc<Box<dyn ResolveOrigin>>, origin: ResolvedVc<Box<dyn ResolveOrigin>>,
source: ResolvedVc<Box<dyn Source>>, source: ResolvedVc<Box<dyn Source>>,
inner_assets: &Option<ReadRef<InnerAssets>>,
ignore_dynamic_requests: bool, ignore_dynamic_requests: bool,
analysis: &mut AnalyzeEcmascriptModuleResultBuilder, analysis: &mut AnalyzeEcmascriptModuleResultBuilder,
error_mode: ResolveErrorMode, error_mode: ResolveErrorMode,
...@@ -1837,6 +1860,16 @@ async fn handle_dynamic_import_with_linked_args( ...@@ -1837,6 +1860,16 @@ async fn handle_dynamic_import_with_linked_args(
return Ok(()); return Ok(());
} }
} }
let resolve_override = if let Some(inner_assets) = &inner_assets
&& let Some(req) = pat.as_constant_string()
&& let Some(a) = inner_assets.get(req)
{
Some(*a)
} else {
None
};
analysis.add_reference_code_gen( analysis.add_reference_code_gen(
EsmAsyncAssetReference::new( EsmAsyncAssetReference::new(
origin, origin,
...@@ -1846,6 +1879,7 @@ async fn handle_dynamic_import_with_linked_args( ...@@ -1846,6 +1879,7 @@ async fn handle_dynamic_import_with_linked_args(
error_mode, error_mode,
import_externals, import_externals,
export_usage, export_usage,
resolve_override,
), ),
ast_path.to_vec().into(), ast_path.to_vec().into(),
); );
...@@ -2137,6 +2171,7 @@ where ...@@ -2137,6 +2171,7 @@ where
handler, handler,
origin, origin,
source, source,
&state.inner_assets,
ignore_dynamic_requests, ignore_dynamic_requests,
analysis, analysis,
error_mode, error_mode,
...@@ -2163,6 +2198,16 @@ where ...@@ -2163,6 +2198,16 @@ where
return Ok(()); return Ok(());
} }
} }
let resolve_override = if let Some(inner_assets) = &state.inner_assets
&& let Some(req) = pat.as_constant_string()
&& let Some(a) = inner_assets.get(req)
{
Some(*a)
} else {
None
};
analysis.add_reference_code_gen( analysis.add_reference_code_gen(
CjsRequireAssetReference::new( CjsRequireAssetReference::new(
origin, origin,
...@@ -2170,6 +2215,7 @@ where ...@@ -2170,6 +2215,7 @@ where
issue_source(source, span), issue_source(source, span),
error_mode, error_mode,
attributes.chunking_type, attributes.chunking_type,
resolve_override,
), ),
ast_path.to_vec().into(), ast_path.to_vec().into(),
); );
...@@ -2221,6 +2267,7 @@ where ...@@ -2221,6 +2267,7 @@ where
issue_source(source, span), issue_source(source, span),
error_mode, error_mode,
attributes.chunking_type, attributes.chunking_type,
None,
), ),
ast_path.to_vec().into(), ast_path.to_vec().into(),
); );
...@@ -2268,6 +2315,16 @@ where ...@@ -2268,6 +2315,16 @@ where
return Ok(()); return Ok(());
} }
} }
let resolve_override = if let Some(inner_assets) = &state.inner_assets
&& let Some(req) = pat.as_constant_string()
&& let Some(a) = inner_assets.get(req)
{
Some(*a)
} else {
None
};
analysis.add_reference_code_gen( analysis.add_reference_code_gen(
CjsRequireResolveAssetReference::new( CjsRequireResolveAssetReference::new(
origin, origin,
...@@ -2275,6 +2332,7 @@ where ...@@ -2275,6 +2332,7 @@ where
issue_source(source, span), issue_source(source, span),
error_mode, error_mode,
attributes.chunking_type, attributes.chunking_type,
resolve_override,
), ),
ast_path.to_vec().into(), ast_path.to_vec().into(),
); );
...@@ -3219,6 +3277,7 @@ async fn handle_free_var_reference( ...@@ -3219,6 +3277,7 @@ async fn handle_free_var_reference(
ImportUsage::TopLevel, ImportUsage::TopLevel,
state.import_externals, state.import_externals,
state.tree_shaking_mode, state.tree_shaking_mode,
None,
) )
.resolved_cell()) .resolved_cell())
}) })
......
...@@ -8,12 +8,12 @@ use turbopack_core::{ ...@@ -8,12 +8,12 @@ use turbopack_core::{
}, },
context::AssetContext, context::AssetContext,
ident::AssetIdent, ident::AssetIdent,
module::{Module, ModuleSideEffects, OptionModule}, module::{Module, ModuleSideEffects},
module_graph::ModuleGraph, module_graph::ModuleGraph,
output::OutputAssetsWithReferenced, output::OutputAssetsWithReferenced,
reference::{ModuleReferences, SingleChunkableModuleReference}, reference::{ModuleReferences, SingleChunkableModuleReference},
reference_type::ReferenceType, reference_type::ReferenceType,
resolve::{ExportUsage, origin::ResolveOrigin, parse::Request}, resolve::{ExportUsage, origin::ResolveOrigin},
source::{OptionSource, Source}, source::{OptionSource, Source},
}; };
use turbopack_ecmascript::{ use turbopack_ecmascript::{
...@@ -215,9 +215,4 @@ impl ResolveOrigin for WebAssemblyModuleAsset { ...@@ -215,9 +215,4 @@ impl ResolveOrigin for WebAssemblyModuleAsset {
fn asset_context(&self) -> Vc<Box<dyn AssetContext>> { fn asset_context(&self) -> Vc<Box<dyn AssetContext>> {
*self.asset_context *self.asset_context
} }
#[turbo_tasks::function]
fn get_inner_asset(self: Vc<Self>, request: Vc<Request>) -> Vc<OptionModule> {
self.loader_as_resolve_origin().get_inner_asset(request)
}
} }
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