Skip to content

Commit

Permalink
[5/n] no-context: migrate remaining crates (#5663)
Browse files Browse the repository at this point in the history
This migrates remaining to the no-context rule.
  • Loading branch information
wbinnssmith committed Aug 4, 2023
1 parent 604a702 commit cdfb31e
Show file tree
Hide file tree
Showing 41 changed files with 351 additions and 291 deletions.
2 changes: 1 addition & 1 deletion .config/ast-grep/rules/no-context.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
id: no-context
message: Don't name variables `context`.
note: Use a more specific name, such as chunking_context, asset_context, etc.
severity: warning
severity: error
language: Rust
rule:
regex: \bcontext\b
Expand Down
34 changes: 20 additions & 14 deletions crates/turbopack-css/src/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn modifier() -> Vc<String> {
#[derive(Clone)]
pub struct CssModuleAsset {
source: Vc<Box<dyn Source>>,
context: Vc<Box<dyn AssetContext>>,
asset_context: Vc<Box<dyn AssetContext>>,
transforms: Vc<CssInputTransforms>,
ty: CssModuleAssetType,
}
Expand All @@ -54,13 +54,13 @@ impl CssModuleAsset {
#[turbo_tasks::function]
pub fn new(
source: Vc<Box<dyn Source>>,
context: Vc<Box<dyn AssetContext>>,
asset_context: Vc<Box<dyn AssetContext>>,
transforms: Vc<CssInputTransforms>,
ty: CssModuleAssetType,
) -> Vc<Self> {
Self::cell(CssModuleAsset {
source,
context,
asset_context,
transforms,
ty,
})
Expand Down Expand Up @@ -114,10 +114,14 @@ impl ChunkableModule for CssModuleAsset {
#[turbo_tasks::function]
fn as_chunk(
self: Vc<Self>,
context: Vc<Box<dyn ChunkingContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
availability_info: Value<AvailabilityInfo>,
) -> Vc<Box<dyn Chunk>> {
Vc::upcast(CssChunk::new(context, Vc::upcast(self), availability_info))
Vc::upcast(CssChunk::new(
chunking_context,
Vc::upcast(self),
availability_info,
))
}
}

Expand All @@ -126,11 +130,11 @@ impl CssChunkPlaceable for CssModuleAsset {
#[turbo_tasks::function]
fn as_chunk_item(
self: Vc<Self>,
context: Vc<Box<dyn ChunkingContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
) -> Vc<Box<dyn CssChunkItem>> {
Vc::upcast(CssModuleChunkItem::cell(CssModuleChunkItem {
module: self,
context,
chunking_context,
}))
}
}
Expand All @@ -144,14 +148,14 @@ impl ResolveOrigin for CssModuleAsset {

#[turbo_tasks::function]
fn asset_context(&self) -> Vc<Box<dyn AssetContext>> {
self.context
self.asset_context
}
}

#[turbo_tasks::value]
struct CssModuleChunkItem {
module: Vc<CssModuleAsset>,
context: Vc<Box<dyn ChunkingContext>>,
chunking_context: Vc<Box<dyn ChunkingContext>>,
}

#[turbo_tasks::value_impl]
Expand All @@ -173,7 +177,7 @@ impl CssChunkItem for CssModuleChunkItem {
async fn content(&self) -> Result<Vc<CssChunkItemContent>> {
let references = &*self.module.references().await?;
let mut imports = vec![];
let context = self.context;
let chunking_context = self.chunking_context;

for reference in references.iter() {
if let Some(import_ref) =
Expand All @@ -190,7 +194,7 @@ impl CssChunkItem for CssModuleChunkItem {
{
imports.push(CssImport::Internal(
import_ref,
placeable.as_chunk_item(context),
placeable.as_chunk_item(chunking_context),
));
}
}
Expand All @@ -206,7 +210,9 @@ impl CssChunkItem for CssModuleChunkItem {
if let Some(placeable) =
Vc::try_resolve_downcast::<Box<dyn CssChunkPlaceable>>(module).await?
{
imports.push(CssImport::Composes(placeable.as_chunk_item(context)));
imports.push(CssImport::Composes(
placeable.as_chunk_item(chunking_context),
));
}
}
}
Expand All @@ -217,7 +223,7 @@ impl CssChunkItem for CssModuleChunkItem {
if let Some(code_gen) =
Vc::try_resolve_sidecast::<Box<dyn CodeGenerateable>>(*r).await?
{
code_gens.push(code_gen.code_generation(context));
code_gens.push(code_gen.code_generation(chunking_context));
}
}
// need to keep that around to allow references into that
Expand Down Expand Up @@ -308,6 +314,6 @@ impl CssChunkItem for CssModuleChunkItem {

#[turbo_tasks::function]
fn chunking_context(&self) -> Vc<Box<dyn ChunkingContext>> {
self.context
self.chunking_context
}
}
Loading

0 comments on commit cdfb31e

Please sign in to comment.