-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract as_chunk into shared ChunkType trait (#6123)
### Description Step 3 in our chunking refactors extracts `ChunkItem::as_chunk` into a new `ChunkType` trait. This new trait isn't useful yet, but will eventually allow us to collect `ChunkItems` of a similar type into a lists, and perform chunking over all similar items at once. Re: #6120 ### Testing Instructions Closes WEB-1722
- Loading branch information
1 parent
624521f
commit 8439948
Showing
19 changed files
with
284 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use anyhow::{Context, Result}; | ||
use turbo_tasks::{Value, ValueDefault, Vc}; | ||
use turbopack_core::chunk::{availability_info::AvailabilityInfo, Chunk, ChunkItem, ChunkType}; | ||
|
||
use super::{EcmascriptChunk, EcmascriptChunkPlaceable}; | ||
|
||
#[derive(Default)] | ||
#[turbo_tasks::value] | ||
pub struct EcmascriptChunkType {} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl ChunkType for EcmascriptChunkType { | ||
#[turbo_tasks::function] | ||
async fn as_chunk( | ||
&self, | ||
chunk_item: Vc<Box<dyn ChunkItem>>, | ||
availability_info: Value<AvailabilityInfo>, | ||
) -> Result<Vc<Box<dyn Chunk>>> { | ||
let placeable = | ||
Vc::try_resolve_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(chunk_item.module()) | ||
.await? | ||
.context( | ||
"Module must implmement EcmascriptChunkPlaceable to be used as a EcmaScript \ | ||
Chunk", | ||
)?; | ||
Ok(Vc::upcast(EcmascriptChunk::new( | ||
chunk_item.chunking_context(), | ||
placeable, | ||
availability_info, | ||
))) | ||
} | ||
} | ||
|
||
#[turbo_tasks::value_impl] | ||
impl ValueDefault for EcmascriptChunkType { | ||
#[turbo_tasks::function] | ||
fn value_default() -> Vc<Self> { | ||
Self::default().cell() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.