diff --git a/crates/turbopack-core/src/resolve/alias_map.rs b/crates/turbopack-core/src/resolve/alias_map.rs index cfef8d66744805..924608d3a798ee 100644 --- a/crates/turbopack-core/src/resolve/alias_map.rs +++ b/crates/turbopack-core/src/resolve/alias_map.rs @@ -694,10 +694,10 @@ pub trait AliasTemplate { Self: 'a; /// Turn `self` into a `Self::Output` - fn convert<'a>(&'a self) -> Self::Output<'a>; + fn convert(&self) -> Self::Output<'_>; /// Replaces `capture` within `self`. - fn replace<'a>(&'a self, capture: &'a Pattern) -> Self::Output<'a>; + fn replace<'a>(&'a self, capture: &Pattern) -> Self::Output<'a>; } #[cfg(test)] diff --git a/crates/turbopack-core/src/resolve/options.rs b/crates/turbopack-core/src/resolve/options.rs index 2ce24b4a89c691..065000d198b4b8 100644 --- a/crates/turbopack-core/src/resolve/options.rs +++ b/crates/turbopack-core/src/resolve/options.rs @@ -140,7 +140,35 @@ impl ImportMapping { impl AliasTemplate for Vc { type Output<'a> = Pin>> + Send + 'a>>; - fn replace<'a>(&'a self, capture: &'a Pattern) -> Self::Output<'a> { + fn convert(&self) -> Self::Output<'_> { + Box::pin(async move { + let this = &*self.await?; + Ok(match this { + // _ => ImportMapping::Ignore + ImportMapping::External(name, ty) => { + ReplacedImportMapping::External(name.clone(), *ty) + } + ImportMapping::PrimaryAlternative(name, context) => { + ReplacedImportMapping::PrimaryAlternative((*name).clone().into(), *context) + } + ImportMapping::Direct(v) => ReplacedImportMapping::Direct(*v), + ImportMapping::Ignore => ReplacedImportMapping::Ignore, + ImportMapping::Empty => ReplacedImportMapping::Empty, + ImportMapping::Alternatives(alternatives) => ReplacedImportMapping::Alternatives( + alternatives + .iter() + .map(|mapping| mapping.convert()) + .try_join() + .await?, + ), + ImportMapping::Dynamic(replacement) => ReplacedImportMapping::Dynamic(*replacement), + } + .cell()) + }) + } + + fn replace<'a>(&'a self, capture: &Pattern) -> Self::Output<'a> { + let capture = capture.clone(); Box::pin(async move { let this = &*self.await?; Ok(match this { @@ -161,13 +189,13 @@ impl AliasTemplate for Vc { *context, ) } - ImportMapping::Direct(v) => ReplacedImportMapping::Direct(v.clone()), + ImportMapping::Direct(v) => ReplacedImportMapping::Direct(*v), ImportMapping::Ignore => ReplacedImportMapping::Ignore, ImportMapping::Empty => ReplacedImportMapping::Empty, ImportMapping::Alternatives(alternatives) => ReplacedImportMapping::Alternatives( alternatives .iter() - .map(|mapping| mapping.replace(capture)) + .map(|mapping| mapping.replace(&capture)) .try_join() .await?, ), @@ -178,10 +206,6 @@ impl AliasTemplate for Vc { .cell()) }) } - - fn convert<'a>(&'a self) -> Self::Output<'a> { - todo!() - } } #[turbo_tasks::value(shared)] diff --git a/crates/turbopack-core/src/resolve/remap.rs b/crates/turbopack-core/src/resolve/remap.rs index 9440cf9b79fc60..aa65b31af8a78e 100644 --- a/crates/turbopack-core/src/resolve/remap.rs +++ b/crates/turbopack-core/src/resolve/remap.rs @@ -378,33 +378,33 @@ impl<'a> Iterator for ResultsIterMut<'a> { } } -struct ResultsPatternIterMut<'a> { - stack: Vec<&'a mut SubpathValueResult>, -} - -impl<'a> Iterator for ResultsPatternIterMut<'a> { - type Item = &'a mut Pattern; - - fn next(&mut self) -> Option { - while let Some(value) = self.stack.pop() { - match value { - SubpathValueResult::Alternatives(list) => { - for value in list { - self.stack.push(value); - } - } - SubpathValueResult::Conditional(list) => { - for (_, value) in list { - self.stack.push(value); - } - } - SubpathValueResult::Result(r) => return Some(r), - SubpathValueResult::Excluded => {} - } - } - None - } -} +// struct ResultsPatternIterMut<'a> { +// stack: Vec<&'a mut SubpathValueResult>, +// } + +// impl<'a> Iterator for ResultsPatternIterMut<'a> { +// type Item = &'a mut Pattern; + +// fn next(&mut self) -> Option { +// while let Some(value) = self.stack.pop() { +// match value { +// SubpathValueResult::Alternatives(list) => { +// for value in list { +// self.stack.push(value); +// } +// } +// SubpathValueResult::Conditional(list) => { +// for (_, value) in list { +// self.stack.push(value); +// } +// } +// SubpathValueResult::Result(r) => return Some(r), +// SubpathValueResult::Excluded => {} +// } +// } +// None +// } +// } /// Content of an "exports" field in a package.json #[derive(PartialEq, Eq, Serialize, Deserialize)]