Skip to content

Commit

Permalink
rustfmt fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkirsz committed Jul 7, 2023
1 parent 230dc1b commit 4ef09e4
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ impl PagesBuildClientContextVc {
let client_asset_page =
create_page_loader_entry_asset(this.client_asset_context, client_asset_page, pathname);

let Some(client_module_asset) = EcmascriptModuleAssetVc::resolve_from(client_asset_page).await? else {
let Some(client_module_asset) =
EcmascriptModuleAssetVc::resolve_from(client_asset_page).await?
else {
bail!("Expected an EcmaScript module asset");
};

Expand Down
17 changes: 13 additions & 4 deletions packages/next-swc/crates/next-build/src/next_pages/node_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,16 @@ impl PagesBuildNodeContextVc {
.node_asset_context
.resolve_asset(
origin,
RequestVc::module(package.clone(), Value::new(path.clone().into()), QueryMapVc::none()),
this.node_asset_context.resolve_options(origin, Value::new(ReferenceType::Entry(EntryReferenceSubType::Page))),
Value::new(ReferenceType::Entry(EntryReferenceSubType::Page))
RequestVc::module(
package.clone(),
Value::new(path.clone().into()),
QueryMapVc::none(),
),
this.node_asset_context.resolve_options(
origin,
Value::new(ReferenceType::Entry(EntryReferenceSubType::Page)),
),
Value::new(ReferenceType::Entry(EntryReferenceSubType::Page)),
)
.primary_assets()
.await?
Expand Down Expand Up @@ -94,7 +101,9 @@ impl PagesBuildNodeContextVc {
.node_asset_context
.process(source_asset, reference_type);

let Some(node_module_asset) = EcmascriptChunkPlaceableVc::resolve_from(node_asset_page).await? else {
let Some(node_module_asset) =
EcmascriptChunkPlaceableVc::resolve_from(node_asset_page).await?
else {
bail!("Expected an EcmaScript module asset");
};

Expand Down
14 changes: 6 additions & 8 deletions packages/next-swc/crates/next-core/src/app_segment_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ pub async fn parse_segment_config_from_source(
program: Program::Module(module),
eval_context,
..
} = &*ecmascript_asset.parse().await? else {
} = &*ecmascript_asset.parse().await?
else {
return Ok(NextSegmentConfigVc::default());
};

Expand All @@ -231,16 +232,13 @@ pub async fn parse_segment_config_from_source(
let Some(decl) = item
.as_module_decl()
.and_then(|mod_decl| mod_decl.as_export_decl())
.and_then(|export_decl| export_decl.decl.as_var()) else {
.and_then(|export_decl| export_decl.decl.as_var())
else {
continue;
};

for decl in &decl.decls {
let Some(ident) = decl
.name
.as_ident()
.map(|ident| ident.deref())
else {
let Some(ident) = decl.name.as_ident().map(|ident| ident.deref()) else {
continue;
};

Expand Down Expand Up @@ -297,7 +295,7 @@ fn parse_config_value(
let value = eval_context.eval(init);
let Some(val) = value.as_bool() else {
invalid_config("`dynamicParams` needs to be a static boolean", &value);
return
return;
};

config.dynamic_params = Some(val);
Expand Down
5 changes: 4 additions & 1 deletion packages/next-swc/crates/next-core/src/app_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,10 @@ async fn add_app_page(
app_dir,
message: StringVc::cell(format!("Conflicting route at {}", e.key())),
severity: IssueSeverity::Error.cell(),
}.cell().as_issue().emit();
}
.cell()
.as_issue()
.emit();
return Ok(());
};
*value = merge_loader_trees(app_dir, *value, loader_tree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ impl EcmascriptChunkPlaceable for InChunkingContextAsset {
&self,
_context: EcmascriptChunkingContextVc,
) -> Result<EcmascriptChunkItemVc> {
let Some(chunking_context) = EcmascriptChunkingContextVc::resolve_from(&self.chunking_context).await? else {
let Some(chunking_context) =
EcmascriptChunkingContextVc::resolve_from(&self.chunking_context).await?
else {
bail!("chunking context is not an EcmascriptChunkingContext")
};
Ok(self.asset.as_chunk_item(chunking_context))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ impl WithChunksChunkItemVc {
async fn chunks_data(self) -> Result<ChunksDataVc> {
let this = self.await?;
let inner = this.inner.await?;
let Some(inner_chunking_context) = EcmascriptChunkingContextVc::resolve_from(inner.chunking_context).await? else {
let Some(inner_chunking_context) =
EcmascriptChunkingContextVc::resolve_from(inner.chunking_context).await?
else {
bail!("the chunking context is not an EcmascriptChunkingContextVc");
};
Ok(ChunkDataVc::from_assets(
Expand All @@ -153,7 +155,9 @@ impl EcmascriptChunkItem for WithChunksChunkItem {
async fn content(self_vc: WithChunksChunkItemVc) -> Result<EcmascriptChunkItemContentVc> {
let this = self_vc.await?;
let inner = this.inner.await?;
let Some(inner_chunking_context) = EcmascriptChunkingContextVc::resolve_from(inner.chunking_context).await? else {
let Some(inner_chunking_context) =
EcmascriptChunkingContextVc::resolve_from(inner.chunking_context).await?
else {
bail!("the chunking context is not an EcmascriptChunkingContextVc");
};

Expand Down
20 changes: 17 additions & 3 deletions packages/next-swc/crates/next-core/src/next_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,12 @@ impl NextConfigVc {
#[turbo_tasks::function]
pub async fn webpack_rules(self) -> Result<OptionWebpackRulesVc> {
let this = self.await?;
let Some(turbo_rules) = this.experimental.turbo.as_ref().and_then(|t| t.rules.as_ref()) else {
let Some(turbo_rules) = this
.experimental
.turbo
.as_ref()
.and_then(|t| t.rules.as_ref())
else {
return Ok(OptionWebpackRulesVc::cell(None));
};
if turbo_rules.is_empty() {
Expand Down Expand Up @@ -603,7 +608,12 @@ impl NextConfigVc {
#[turbo_tasks::function]
pub async fn resolve_alias_options(self) -> Result<ResolveAliasMapVc> {
let this = self.await?;
let Some(resolve_alias) = this.experimental.turbo.as_ref().and_then(|t| t.resolve_alias.as_ref()) else {
let Some(resolve_alias) = this
.experimental
.turbo
.as_ref()
.and_then(|t| t.resolve_alias.as_ref())
else {
return Ok(ResolveAliasMapVc::cell(ResolveAliasMap::default()));
};
let alias_map: ResolveAliasMap = resolve_alias.try_into()?;
Expand Down Expand Up @@ -694,7 +704,11 @@ pub async fn load_next_config_internal(
)
.await?;

let turbopack_binding::turbo::tasks_bytes::stream::SingleValue::Single(val) = config_value.try_into_single().await.context("Evaluation of Next.js config failed")? else {
let turbopack_binding::turbo::tasks_bytes::stream::SingleValue::Single(val) = config_value
.try_into_single()
.await
.context("Evaluation of Next.js config failed")?
else {
return Ok(NextConfig::default().cell());
};
let next_config: NextConfig = parse_json_with_source_context(val.to_str()?)?;
Expand Down
12 changes: 7 additions & 5 deletions packages/next-swc/crates/next-core/src/next_font/google/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ impl ImportMappingReplacement for NextFontGoogleReplacer {
let Request::Module {
module: _,
path: _,
query: query_vc
} = request else {
query: query_vc,
} = request
else {
return Ok(ImportMapResult::NoEntry.into());
};

Expand Down Expand Up @@ -205,7 +206,8 @@ impl ImportMappingReplacement for NextFontGoogleCssModuleReplacer {
module: _,
path: _,
query: query_vc,
} = request else {
} = request
else {
return Ok(ImportMapResult::NoEntry.into());
};

Expand Down Expand Up @@ -378,8 +380,8 @@ async fn font_options_from_query_map(
}

let Some((json, _)) = query_map.iter().next() else {
bail!("Expected one entry");
};
bail!("Expected one entry");
};

options_from_request(&parse_json_with_source_context(json)?, &*font_data.await?)
.map(|o| NextFontGoogleOptionsVc::new(Value::new(o)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ fn pick_font_for_fallback_generation(
/// If it's not a variable font we can just return the distance.
/// If it's a variable font we need to compare its weight range to 400.
fn get_distance_from_normal_weight(weight: &Option<FontWeight>) -> Result<f64> {
let Some(weight) = weight else {
return Ok(0.0)
};
let Some(weight) = weight else { return Ok(0.0) };

Ok(match weight {
FontWeight::Fixed(val) => parse_weight_string(val)? - NORMAL_WEIGHT,
Expand Down
12 changes: 7 additions & 5 deletions packages/next-swc/crates/next-core/src/next_font/local/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ impl ImportMappingReplacement for NextFontLocalReplacer {
let Request::Module {
module: _,
path: _,
query: query_vc
} = &*request.await? else {
query: query_vc,
} = &*request.await?
else {
return Ok(ImportMapResult::NoEntry.into());
};

Expand Down Expand Up @@ -165,7 +166,8 @@ impl ImportMappingReplacement for NextFontLocalCssModuleReplacer {
module: _,
path: _,
query: query_vc,
} = request else {
} = request
else {
return Ok(ImportMapResult::NoEntry.into());
};

Expand Down Expand Up @@ -240,8 +242,8 @@ async fn font_options_from_query_map(query: QueryMapVc) -> Result<NextFontLocalO
}

let Some((json, _)) = query_map.iter().next() else {
bail!("Expected one entry");
};
bail!("Expected one entry");
};

options_from_request(&parse_json_with_source_context(json)?)
.map(|o| NextFontLocalOptionsVc::new(Value::new(o)))
Expand Down
3 changes: 2 additions & 1 deletion packages/next-swc/crates/next-core/src/router_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ impl GetContentSourceContent for NextRouterContentSource {
raw_query: Some(raw_query),
body: Some(body),
..
} = &*data else {
} = &*data
else {
bail!("missing data for router");
};

Expand Down
3 changes: 1 addition & 2 deletions packages/next-swc/crates/next-core/src/web_entry_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ use crate::{
mode::NextMode,
next_client::{
context::{
get_client_asset_context,
get_client_resolve_options_context, ClientContextType,
get_client_asset_context, get_client_resolve_options_context, ClientContextType,
},
RuntimeEntriesVc, RuntimeEntry,
},
Expand Down
4 changes: 3 additions & 1 deletion packages/next-swc/crates/next-transform-dynamic/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ impl Fold for NextDynamicPatcher {
expr.args[0].expr = expr.args[0].expr.clone().fold_with(self);
self.is_next_dynamic_first_arg = false;

let Some((dynamically_imported_specifier, dynamically_imported_specifier_span)) = self.dynamically_imported_specifier.take() else {
let Some((dynamically_imported_specifier, dynamically_imported_specifier_span)) =
self.dynamically_imported_specifier.take()
else {
return expr;
};

Expand Down

0 comments on commit 4ef09e4

Please sign in to comment.