-
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
- Loading branch information
1 parent
e3ea47f
commit f0d34dd
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.