Skip to main content

turbopack_core/
raw_module.rs

1use turbo_rcstr::RcStr;
2use turbo_tasks::{ResolvedVc, Vc};
3
4use crate::{
5    ident::AssetIdent,
6    module::{Module, ModuleSideEffects},
7    source::{OptionSource, Source},
8};
9
10/// A module where source code doesn't need to be parsed but can be used as is.
11/// This module has no references to other modules.
12#[turbo_tasks::value]
13pub struct RawModule {
14    source: ResolvedVc<Box<dyn Source>>,
15    modifier: Option<RcStr>,
16}
17
18#[turbo_tasks::value_impl]
19impl Module for RawModule {
20    #[turbo_tasks::function]
21    fn ident(&self) -> Vc<AssetIdent> {
22        match &self.modifier {
23            Some(modifier) => self.source.ident().with_modifier(modifier.clone()),
24            None => self.source.ident(),
25        }
26    }
27
28    #[turbo_tasks::function]
29    fn source(&self) -> Vc<OptionSource> {
30        Vc::cell(Some(self.source))
31    }
32    #[turbo_tasks::function]
33    fn side_effects(self: Vc<Self>) -> Vc<ModuleSideEffects> {
34        ModuleSideEffects::SideEffectful.cell()
35    }
36}
37
38impl RawModule {
39    pub fn new(source: Vc<Box<dyn Source>>) -> Vc<RawModule> {
40        Self::new_inner(source, None)
41    }
42
43    pub fn new_with_modifier(source: Vc<Box<dyn Source>>, modifier: RcStr) -> Vc<RawModule> {
44        Self::new_inner(source, Some(modifier))
45    }
46}
47
48#[turbo_tasks::value_impl]
49impl RawModule {
50    #[turbo_tasks::function]
51    fn new_inner(source: ResolvedVc<Box<dyn Source>>, modifier: Option<RcStr>) -> Vc<RawModule> {
52        RawModule { source, modifier }.cell()
53    }
54}