Skip to content

Commit

Permalink
Review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexkirsz committed Jul 3, 2023
1 parent 282704e commit 41230e8
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions crates/turbopack-css/src/module_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,23 @@ fn modifier() -> StringVc {
#[turbo_tasks::value]
#[derive(Clone)]
pub struct ModuleCssAsset {
pub inner: AssetVc,
pub source: AssetVc,
pub context: AssetContextVc,
}

#[turbo_tasks::value_impl]
impl ModuleCssAssetVc {
#[turbo_tasks::function]
pub async fn new(source: AssetVc, context: AssetContextVc) -> Result<Self> {
let inner = context.process(
source,
Value::new(ReferenceType::Css(CssReferenceSubType::Internal)),
);

Ok(Self::cell(ModuleCssAsset { inner, context }))
Ok(Self::cell(ModuleCssAsset { source, context }))
}
}

#[turbo_tasks::value_impl]
impl Asset for ModuleCssAsset {
#[turbo_tasks::function]
fn ident(&self) -> AssetIdentVc {
self.inner.ident().with_modifier(modifier())
self.source.ident().with_modifier(modifier())
}

#[turbo_tasks::function]
Expand All @@ -79,14 +74,12 @@ impl Asset for ModuleCssAsset {

#[turbo_tasks::function]
async fn references(self_vc: ModuleCssAssetVc) -> Result<AssetReferencesVc> {
let this = self_vc.await?;

// The inner reference must come first so it is processed before other potential
// references inside of the CSS, like `@import` and `composes:`.
// This affects the order in which the resulting CSS chunks will be loaded:
// later references are processed first in the post-order traversal of the
// reference tree, and as such they will be loaded first in the resulting HTML.
let references = once(InternalCssAssetReferenceVc::new(this.inner).into())
let references = once(InternalCssAssetReferenceVc::new(self_vc.inner()).into())
.chain(self_vc.module_references().await?.iter().copied())
.collect();

Expand Down Expand Up @@ -140,9 +133,18 @@ struct ModuleCssClasses(IndexMap<String, Vec<ModuleCssClass>>);

#[turbo_tasks::value_impl]
impl ModuleCssAssetVc {
#[turbo_tasks::function]
async fn inner(self) -> Result<AssetVc> {
let this = self.await?;
Ok(this.context.process(
this.source,
Value::new(ReferenceType::Css(CssReferenceSubType::Internal)),
))
}

#[turbo_tasks::function]
async fn classes(self) -> Result<ModuleCssClassesVc> {
let inner = self.await?.inner;
let inner = self.inner();

let Some(inner) = ParseCssVc::resolve_from(inner).await? else {
bail!("inner asset should be CSS parseable");
Expand Down Expand Up @@ -237,7 +239,7 @@ impl EcmascriptChunkPlaceable for ModuleCssAsset {
impl ResolveOrigin for ModuleCssAsset {
#[turbo_tasks::function]
fn origin_path(&self) -> FileSystemPathVc {
self.inner.ident().path()
self.source.ident().path()
}

#[turbo_tasks::function]
Expand Down

0 comments on commit 41230e8

Please sign in to comment.