Skip to main content

turbopack_core/
generated_code_source.rs

1use turbo_rcstr::RcStr;
2use turbo_tasks::{ResolvedVc, Vc};
3
4use crate::{
5    asset::{Asset, AssetContent},
6    ident::AssetIdent,
7    source::Source,
8};
9
10/// A source wrapping another source but stripping source map support.
11/// Used to display generated code in error messages without triggering
12/// source map remapping (since this type does NOT implement
13/// `GenerateSourceMap`).
14#[turbo_tasks::value]
15pub struct GeneratedCodeSource {
16    source: ResolvedVc<Box<dyn Source>>,
17}
18
19#[turbo_tasks::value_impl]
20impl GeneratedCodeSource {
21    #[turbo_tasks::function]
22    pub fn new(source: ResolvedVc<Box<dyn Source>>) -> Vc<Self> {
23        Self { source }.cell()
24    }
25}
26
27#[turbo_tasks::value_impl]
28impl Source for GeneratedCodeSource {
29    #[turbo_tasks::function]
30    fn ident(&self) -> Vc<AssetIdent> {
31        self.source.ident()
32    }
33
34    #[turbo_tasks::function]
35    fn description(&self) -> Vc<RcStr> {
36        self.source.description()
37    }
38}
39
40#[turbo_tasks::value_impl]
41impl Asset for GeneratedCodeSource {
42    #[turbo_tasks::function]
43    fn content(&self) -> Vc<AssetContent> {
44        self.source.content()
45    }
46}