Skip to content

Commit

Permalink
fix(turbopack): Fix EcmascriptModuleFacadeModule::ident() (vercel#7…
Browse files Browse the repository at this point in the history
…1338)

### What?

Fix `ident` implementation of `EcmascriptModuleFacadeModule`. Previous code replaces original module part, while the new implementation adds part information as a modifier.

### Why?

Currently, `ident` implementations are not correctly aligned. This makes some modules returned from `references()` disappear from the final bundle.

### How?
  • Loading branch information
kdy1 authored and stipsan committed Nov 6, 2024
1 parent 0fcad3a commit d674ed5
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
26 changes: 14 additions & 12 deletions turbopack/crates/turbopack-core/src/ident.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct AssetIdent {
pub assets: Vec<(ResolvedVc<RcStr>, ResolvedVc<AssetIdent>)>,
/// The modifiers of this asset (e.g. `client chunks`)
pub modifiers: Vec<Vc<RcStr>>,
/// The part of the asset that is a (ECMAScript) module
pub part: Option<ResolvedVc<ModulePart>>,
/// The parts of the asset that are (ECMAScript) modules
pub parts: Vec<ResolvedVc<ModulePart>>,
/// The asset layer the asset was created from.
pub layer: Option<ResolvedVc<RcStr>>,
}
Expand Down Expand Up @@ -95,12 +95,14 @@ impl ValueToString for AssetIdent {
s.push(')');
}

if let Some(part) = self.part {
let part = part.to_string().await?;
// facade is not included in ident as switching between facade and non-facade shouldn't
// change the ident
if part.as_str() != "facade" {
write!(s, " <{}>", part)?;
if !self.parts.is_empty() {
for part in self.parts.iter() {
let part = part.to_string().await?;
// facade is not included in ident as switching between facade and non-facade
// shouldn't change the ident
if part.as_str() != "facade" {
write!(s, " <{}>", part)?;
}
}
}

Expand All @@ -124,7 +126,7 @@ impl AssetIdent {
fragment: None,
assets: Vec::new(),
modifiers: Vec::new(),
part: None,
parts: Vec::new(),
layer: None,
}))
}
Expand All @@ -146,7 +148,7 @@ impl AssetIdent {
#[turbo_tasks::function]
pub fn with_part(&self, part: ResolvedVc<ModulePart>) -> Vc<Self> {
let mut this = self.clone();
this.part = Some(part);
this.parts.push(part);
Self::new(Value::new(this))
}

Expand Down Expand Up @@ -224,7 +226,7 @@ impl AssetIdent {
fragment,
assets,
modifiers,
part,
parts,
layer,
} = self;
let query = query.await?;
Expand Down Expand Up @@ -255,7 +257,7 @@ impl AssetIdent {
modifier.deterministic_hash(&mut hasher);
has_hash = true;
}
if let Some(part) = part {
for part in parts.iter() {
4_u8.deterministic_hash(&mut hasher);
match &*part.await? {
ModulePart::Evaluation => {
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-css/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl OutputAsset for CssChunk {
fragment: None,
assets,
modifiers: Vec::new(),
part: None,
parts: Vec::new(),
layer: None,
};

Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-ecmascript/src/chunk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl Chunk for EcmascriptChunk {
fragment: None,
assets,
modifiers: Vec::new(),
part: None,
parts: Vec::new(),
layer: None,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ impl EcmascriptModuleFacadeModule {
#[turbo_tasks::value_impl]
impl Module for EcmascriptModuleFacadeModule {
#[turbo_tasks::function]
fn ident(&self) -> Vc<AssetIdent> {
async fn ident(&self) -> Result<Vc<AssetIdent>> {
let inner = self.module.ident();

inner.with_part(self.ty)
Ok(inner.with_part(self.ty))
}

#[turbo_tasks::function]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ pub(super) async fn split(
parsed: Vc<ParseResult>,
) -> Result<Vc<SplitResult>> {
// Do not split already split module
if ident.await?.part.is_some() {
if !ident.await?.parts.is_empty() {
return Ok(SplitResult::Failed {
parse_result: parsed,
}
Expand Down

0 comments on commit d674ed5

Please sign in to comment.