11use std:: { io:: Write , iter:: once} ;
22
3- use anyhow:: { Context , Result , bail} ;
3+ use anyhow:: { Result , bail} ;
44use indoc:: writedoc;
55use turbo_rcstr:: { RcStr , rcstr} ;
66use turbo_tasks:: { IntoTraitRef , ResolvedVc , ValueToString , Vc } ;
77use turbo_tasks_fs:: { File , FileContent } ;
88use turbopack_core:: {
99 asset:: AssetContent ,
1010 chunk:: {
11- AsyncModuleInfo , ChunkGroupType , ChunkItem , ChunkType , ChunkableModule , ChunkingContext ,
12- ChunkingType , ChunkingTypeOption ,
11+ AsyncModuleInfo , ChunkGroupType , ChunkItem , ChunkableModule , ChunkingContext , ChunkingType ,
12+ ChunkingTypeOption ,
1313 } ,
1414 code_builder:: CodeBuilder ,
1515 context:: AssetContext ,
1616 ident:: AssetIdent ,
1717 module:: { Module , ModuleSideEffects } ,
1818 module_graph:: { ModuleGraph , binding_usage_info:: ModuleExportUsageInfo } ,
19- output:: OutputAssetsReference ,
2019 reference:: { ModuleReference , ModuleReferences } ,
2120 reference_type:: ReferenceType ,
2221 resolve:: ModuleResolveResult ,
@@ -25,8 +24,8 @@ use turbopack_core::{
2524} ;
2625use turbopack_ecmascript:: {
2726 chunk:: {
28- EcmascriptChunkItem , EcmascriptChunkItemContent , EcmascriptChunkPlaceable ,
29- EcmascriptChunkType , EcmascriptExports ,
27+ EcmascriptChunkItemContent , EcmascriptChunkPlaceable , EcmascriptExports ,
28+ ecmascript_chunk_item ,
3029 } ,
3130 runtime_functions:: TURBOPACK_EXPORT_NAMESPACE ,
3231 utils:: StringifyJs ,
@@ -257,20 +256,10 @@ impl ChunkableModule for EcmascriptClientReferenceModule {
257256 module_graph : Vc < ModuleGraph > ,
258257 chunking_context : ResolvedVc < Box < dyn ChunkingContext > > ,
259258 ) -> Result < Vc < Box < dyn ChunkItem > > > {
260- let item = self
261- . proxy_module ( )
262- . as_chunk_item ( module_graph, * chunking_context) ;
263- let ecmascript_item =
264- ResolvedVc :: try_downcast :: < Box < dyn EcmascriptChunkItem > > ( item. to_resolved ( ) . await ?)
265- . context ( "EcmascriptModuleAsset must implement EcmascriptChunkItem" ) ?;
266-
267- Ok ( Vc :: upcast (
268- EcmascriptClientReferenceProxyChunkItem {
269- inner_module : self ,
270- inner_chunk_item : ecmascript_item,
271- chunking_context,
272- }
273- . cell ( ) ,
259+ Ok ( ecmascript_chunk_item (
260+ ResolvedVc :: upcast ( self ) ,
261+ module_graph. to_resolved ( ) . await ?,
262+ chunking_context,
274263 ) )
275264 }
276265}
@@ -285,67 +274,13 @@ impl EcmascriptChunkPlaceable for EcmascriptClientReferenceModule {
285274 #[ turbo_tasks:: function]
286275 fn chunk_item_content (
287276 self : Vc < Self > ,
288- _chunking_context : Vc < Box < dyn ChunkingContext > > ,
289- _module_graph : Vc < ModuleGraph > ,
290- _async_module_info : Option < Vc < AsyncModuleInfo > > ,
291- _estimated : bool ,
292- ) -> Result < Vc < EcmascriptChunkItemContent > > {
293- bail ! ( "Attempted to get chunk_item_content for EcmascriptClientReferenceModule" )
294- }
295- }
296-
297- /// This wrapper only exists to overwrite the `asset_ident` method of the
298- /// wrapped [`Vc<Box<dyn EcmascriptChunkItem>>`]. Otherwise, the asset ident of
299- /// the chunk item would not be the same as the asset ident of the
300- /// [`Vc<EcmascriptClientReferenceModule>`].
301- #[ turbo_tasks:: value]
302- struct EcmascriptClientReferenceProxyChunkItem {
303- inner_module : ResolvedVc < EcmascriptClientReferenceModule > ,
304- inner_chunk_item : ResolvedVc < Box < dyn EcmascriptChunkItem > > ,
305- chunking_context : ResolvedVc < Box < dyn ChunkingContext > > ,
306- }
307-
308- #[ turbo_tasks:: value_impl]
309- impl OutputAssetsReference for EcmascriptClientReferenceProxyChunkItem { }
310-
311- #[ turbo_tasks:: value_impl]
312- impl ChunkItem for EcmascriptClientReferenceProxyChunkItem {
313- #[ turbo_tasks:: function]
314- fn asset_ident ( & self ) -> Vc < AssetIdent > {
315- self . inner_module . ident ( )
316- }
317-
318- #[ turbo_tasks:: function]
319- fn chunking_context ( & self ) -> Vc < Box < dyn ChunkingContext > > {
320- * self . chunking_context
321- }
322-
323- #[ turbo_tasks:: function]
324- fn ty ( & self ) -> Vc < Box < dyn ChunkType > > {
325- Vc :: upcast ( Vc :: < EcmascriptChunkType > :: default ( ) )
326- }
327-
328- #[ turbo_tasks:: function]
329- fn module ( & self ) -> Vc < Box < dyn Module > > {
330- Vc :: upcast ( * self . inner_module )
331- }
332- }
333-
334- #[ turbo_tasks:: value_impl]
335- impl EcmascriptChunkItem for EcmascriptClientReferenceProxyChunkItem {
336- #[ turbo_tasks:: function]
337- fn content ( & self ) -> Vc < EcmascriptChunkItemContent > {
338- self . inner_chunk_item . content ( )
339- }
340-
341- #[ turbo_tasks:: function]
342- fn content_with_async_module_info (
343- & self ,
277+ chunking_context : Vc < Box < dyn ChunkingContext > > ,
278+ module_graph : Vc < ModuleGraph > ,
344279 async_module_info : Option < Vc < AsyncModuleInfo > > ,
345280 estimated : bool ,
346281 ) -> Vc < EcmascriptChunkItemContent > {
347- self . inner_chunk_item
348- . content_with_async_module_info ( async_module_info, estimated)
282+ self . proxy_module ( )
283+ . chunk_item_content ( chunking_context , module_graph , async_module_info, estimated)
349284 }
350285}
351286
0 commit comments