Unverified Commit 29e6b0e3 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: refactor tuple variant into struct (#86374)

The list was getting long...
parent d6735683
...@@ -2721,7 +2721,7 @@ async fn resolve_import_map_result( ...@@ -2721,7 +2721,7 @@ async fn resolve_import_map_result(
)) ))
} }
} }
ImportMapResult::External(name, ty, traced) => { ImportMapResult::External { name, ty, traced } => {
Some(*ResolveResult::primary(ResolveResultItem::External { Some(*ResolveResult::primary(ResolveResultItem::External {
name: name.clone(), name: name.clone(),
ty: *ty, ty: *ty,
......
...@@ -134,7 +134,11 @@ pub enum ImportMapping { ...@@ -134,7 +134,11 @@ pub enum ImportMapping {
#[turbo_tasks::value(shared)] #[turbo_tasks::value(shared)]
#[derive(Clone)] #[derive(Clone)]
pub enum ReplacedImportMapping { pub enum ReplacedImportMapping {
External(Option<RcStr>, ExternalType, ExternalTraced), External {
name_override: Option<RcStr>,
ty: ExternalType,
traced: ExternalTraced,
},
PrimaryAlternativeExternal { PrimaryAlternativeExternal {
name: Option<RcStr>, name: Option<RcStr>,
ty: ExternalType, ty: ExternalType,
...@@ -190,9 +194,11 @@ impl AliasTemplate for Vc<ImportMapping> { ...@@ -190,9 +194,11 @@ impl AliasTemplate for Vc<ImportMapping> {
Box::pin(async move { Box::pin(async move {
let this = &*self.await?; let this = &*self.await?;
Ok(match this { Ok(match this {
ImportMapping::External(name, ty, traced) => { ImportMapping::External(name, ty, traced) => ReplacedImportMapping::External {
ReplacedImportMapping::External(name.clone(), *ty, *traced) name_override: name.clone(),
} ty: *ty,
traced: *traced,
},
ImportMapping::PrimaryAlternativeExternal { ImportMapping::PrimaryAlternativeExternal {
name, name,
ty, ty,
...@@ -233,13 +239,20 @@ impl AliasTemplate for Vc<ImportMapping> { ...@@ -233,13 +239,20 @@ impl AliasTemplate for Vc<ImportMapping> {
Ok(match this { Ok(match this {
ImportMapping::External(name, ty, traced) => { ImportMapping::External(name, ty, traced) => {
if let Some(name) = name { if let Some(name) = name {
ReplacedImportMapping::External( ReplacedImportMapping::External {
capture.spread_into_star(name).as_constant_string().cloned(), name_override: capture
*ty, .spread_into_star(name)
*traced, .as_constant_string()
) .cloned(),
ty: *ty,
traced: *traced,
}
} else { } else {
ReplacedImportMapping::External(None, *ty, *traced) ReplacedImportMapping::External {
name_override: None,
ty: *ty,
traced: *traced,
}
} }
} }
ImportMapping::PrimaryAlternativeExternal { ImportMapping::PrimaryAlternativeExternal {
...@@ -393,7 +406,11 @@ pub struct ResolvedMap { ...@@ -393,7 +406,11 @@ pub struct ResolvedMap {
#[derive(Clone)] #[derive(Clone)]
pub enum ImportMapResult { pub enum ImportMapResult {
Result(ResolvedVc<ResolveResult>), Result(ResolvedVc<ResolveResult>),
External(RcStr, ExternalType, ExternalTraced), External {
name: RcStr,
ty: ExternalType,
traced: ExternalTraced,
},
AliasExternal { AliasExternal {
name: RcStr, name: RcStr,
ty: ExternalType, ty: ExternalType,
...@@ -412,8 +429,12 @@ async fn import_mapping_to_result( ...@@ -412,8 +429,12 @@ async fn import_mapping_to_result(
) -> Result<ImportMapResult> { ) -> Result<ImportMapResult> {
Ok(match &*mapping.await? { Ok(match &*mapping.await? {
ReplacedImportMapping::Direct(result) => ImportMapResult::Result(*result), ReplacedImportMapping::Direct(result) => ImportMapResult::Result(*result),
ReplacedImportMapping::External(name, ty, traced) => ImportMapResult::External( ReplacedImportMapping::External {
if let Some(name) = name { name_override,
ty,
traced,
} => ImportMapResult::External {
name: if let Some(name) = name_override {
name.clone() name.clone()
} else if let Some(request) = request.await?.request() { } else if let Some(request) = request.await?.request() {
request request
...@@ -423,9 +444,9 @@ async fn import_mapping_to_result( ...@@ -423,9 +444,9 @@ async fn import_mapping_to_result(
request.request_pattern().await?.describe_as_string() request.request_pattern().await?.describe_as_string()
) )
}, },
*ty, ty: *ty,
*traced, traced: *traced,
), },
ReplacedImportMapping::PrimaryAlternativeExternal { ReplacedImportMapping::PrimaryAlternativeExternal {
name, name,
ty, ty,
...@@ -480,7 +501,7 @@ impl ValueToString for ImportMapResult { ...@@ -480,7 +501,7 @@ impl ValueToString for ImportMapResult {
async fn to_string(&self) -> Result<Vc<RcStr>> { async fn to_string(&self) -> Result<Vc<RcStr>> {
match self { match self {
ImportMapResult::Result(_) => Ok(Vc::cell(rcstr!("Resolved by import map"))), ImportMapResult::Result(_) => Ok(Vc::cell(rcstr!("Resolved by import map"))),
ImportMapResult::External(_, _, _) => Ok(Vc::cell(rcstr!("TODO external"))), ImportMapResult::External { .. } => Ok(Vc::cell(rcstr!("TODO external"))),
ImportMapResult::AliasExternal { .. } => Ok(Vc::cell(rcstr!("TODO external"))), ImportMapResult::AliasExternal { .. } => Ok(Vc::cell(rcstr!("TODO external"))),
ImportMapResult::Alias(request, context) => { ImportMapResult::Alias(request, context) => {
let s = if let Some(path) = context { let s = if let Some(path) = context {
......
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