turbopack_core/
module.rs

1use serde::{Deserialize, Serialize};
2use turbo_tasks::{NonLocalValue, ResolvedVc, Vc, trace::TraceRawVcs};
3
4use crate::{asset::Asset, ident::AssetIdent, reference::ModuleReferences};
5
6#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, TraceRawVcs, NonLocalValue)]
7pub enum StyleType {
8    IsolatedStyle,
9    GlobalStyle,
10}
11
12#[turbo_tasks::value(transparent)]
13pub struct OptionStyleType(Option<StyleType>);
14
15/// A module. This usually represents parsed source code, which has references
16/// to other modules.
17#[turbo_tasks::value_trait]
18pub trait Module: Asset {
19    /// The identifier of the [Module]. It's expected to be unique and capture
20    /// all properties of the [Module].
21    fn ident(&self) -> Vc<AssetIdent>;
22
23    /// Other [Module]s or [OutputAsset]s referenced from this [Module].
24    // TODO refactor to avoid returning [OutputAsset]s here
25    fn references(self: Vc<Self>) -> Vc<ModuleReferences> {
26        ModuleReferences::empty()
27    }
28
29    /// Signifies the module itself is async, e.g. it uses top-level await, is a wasm module, etc.
30    fn is_self_async(self: Vc<Self>) -> Vc<bool> {
31        Vc::cell(false)
32    }
33
34    /// The style type of the module.
35    fn style_type(self: Vc<Self>) -> Vc<OptionStyleType> {
36        Vc::cell(None)
37    }
38}
39
40#[turbo_tasks::value(transparent)]
41pub struct OptionModule(Option<ResolvedVc<Box<dyn Module>>>);
42
43#[turbo_tasks::value(transparent)]
44pub struct Modules(Vec<ResolvedVc<Box<dyn Module>>>);
45
46#[turbo_tasks::value_impl]
47impl Modules {
48    #[turbo_tasks::function]
49    pub fn empty() -> Vc<Self> {
50        Vc::cell(Vec::new())
51    }
52}