Skip to content

Commit

Permalink
turbopack-ecmascript: ResolvedVc<T>
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Nov 29, 2024
1 parent 3729ef6 commit 7554a5f
Show file tree
Hide file tree
Showing 14 changed files with 135 additions and 109 deletions.
4 changes: 2 additions & 2 deletions turbopack/crates/turbopack-ecmascript/src/chunk/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
#[derive(Default, Clone)]
pub struct EcmascriptChunkItemContent {
pub inner_code: Rope,
pub source_map: Option<Vc<Box<dyn GenerateSourceMap>>>,
pub source_map: Option<ResolvedVc<Box<dyn GenerateSourceMap>>>,
pub options: EcmascriptChunkItemOptions,
pub rewrite_source_path: Option<ResolvedVc<FileSystemPath>>,
pub placeholder_for_future_extensions: (),
Expand Down Expand Up @@ -159,7 +159,7 @@ impl EcmascriptChunkItemContent {
None => None,
}
} else {
self.source_map
self.source_map.map(|v| *v)
};

code.push_source(&self.inner_code, source_map);
Expand Down
6 changes: 3 additions & 3 deletions turbopack/crates/turbopack-ecmascript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl EcmascriptAnalyzable for EcmascriptModuleAsset {
*analyze.references,
*analyze.code_generation,
*analyze.async_module,
analyze.source_map,
*analyze.source_map,
*analyze.exports,
async_module_info,
))
Expand Down Expand Up @@ -704,7 +704,7 @@ impl EcmascriptChunkItem for ModuleChunkItem {
#[turbo_tasks::value]
pub struct EcmascriptModuleContent {
pub inner_code: Rope,
pub source_map: Option<Vc<Box<dyn GenerateSourceMap>>>,
pub source_map: Option<ResolvedVc<Box<dyn GenerateSourceMap>>>,
pub is_esm: bool,
// pub refresh: bool,
}
Expand Down Expand Up @@ -834,7 +834,7 @@ async fn gen_content_with_code_gens(

Ok(EcmascriptModuleContent {
inner_code: bytes.into(),
source_map: Some(Vc::upcast(srcmap)),
source_map: Some(ResolvedVc::upcast(srcmap.to_resolved().await?)),
is_esm: eval_context.is_esm(specified_module_type),
}
.cell())
Expand Down
2 changes: 1 addition & 1 deletion turbopack/crates/turbopack-ecmascript/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub struct ParseResultSourceMap {

/// An input's original source map, if one exists. This will be used to
/// trace locations back to the input's pre-transformed sources.
original_source_map: Vc<OptionSourceMap>,
original_source_map: ResolvedVc<OptionSourceMap>,
}

impl PartialEq for ParseResultSourceMap {
Expand Down
14 changes: 7 additions & 7 deletions turbopack/crates/turbopack-ecmascript/src/references/amd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,20 @@ pub enum AmdDefineFactoryType {
#[derive(Debug)]
pub struct AmdDefineWithDependenciesCodeGen {
dependencies_requests: Vec<AmdDefineDependencyElement>,
origin: Vc<Box<dyn ResolveOrigin>>,
origin: ResolvedVc<Box<dyn ResolveOrigin>>,
path: ResolvedVc<AstPath>,
factory_type: AmdDefineFactoryType,
issue_source: Vc<IssueSource>,
issue_source: ResolvedVc<IssueSource>,
in_try: bool,
}

impl AmdDefineWithDependenciesCodeGen {
pub fn new(
dependencies_requests: Vec<AmdDefineDependencyElement>,
origin: Vc<Box<dyn ResolveOrigin>>,
origin: ResolvedVc<Box<dyn ResolveOrigin>>,
path: ResolvedVc<AstPath>,
factory_type: AmdDefineFactoryType,
issue_source: Vc<IssueSource>,
issue_source: ResolvedVc<IssueSource>,
in_try: bool,
) -> Vc<Self> {
Self::cell(AmdDefineWithDependenciesCodeGen {
Expand Down Expand Up @@ -154,12 +154,12 @@ impl CodeGenerateable for AmdDefineWithDependenciesCodeGen {
} => ResolvedElement::PatternMapping {
pattern_mapping: PatternMapping::resolve_request(
*request,
self.origin,
*self.origin,
Vc::upcast(chunking_context),
cjs_resolve(
self.origin,
*self.origin,
*request,
Some(self.issue_source),
Some(*self.issue_source),
self.in_try,
),
Value::new(ChunkItem),
Expand Down
35 changes: 20 additions & 15 deletions turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ pub enum EsmExport {
/// An imported binding that is exported (export { a as b } from "...")
///
/// The last bool is true if the binding is a mutable binding
ImportedBinding(Vc<Box<dyn ModuleReference>>, RcStr, bool),
ImportedBinding(ResolvedVc<Box<dyn ModuleReference>>, RcStr, bool),
/// An imported namespace that is exported (export * from "...")
ImportedNamespace(Vc<Box<dyn ModuleReference>>),
ImportedNamespace(ResolvedVc<Box<dyn ModuleReference>>),
/// An error occurred while resolving the export
Error,
}
Expand Down Expand Up @@ -118,14 +118,14 @@ pub enum FoundExportType {

#[turbo_tasks::value]
pub struct FollowExportsResult {
pub module: Vc<Box<dyn EcmascriptChunkPlaceable>>,
pub module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
pub export_name: Option<RcStr>,
pub ty: FoundExportType,
}

#[turbo_tasks::function]
pub async fn follow_reexports(
module: Vc<Box<dyn EcmascriptChunkPlaceable>>,
module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
export_name: RcStr,
side_effect_free_packages: Vc<Glob>,
ignore_side_effect_of_entry: bool,
Expand Down Expand Up @@ -172,7 +172,7 @@ pub async fn follow_reexports(

// Try to find the export in the star exports
if !exports_ref.star_exports.is_empty() && &*export_name != "default" {
let result = get_all_export_names(module).await?;
let result = get_all_export_names(*module).await?;
if let Some(m) = result.esm_exports.get(&export_name) {
module = *m;
continue;
Expand Down Expand Up @@ -208,11 +208,12 @@ pub async fn follow_reexports(
}

async fn handle_declared_export(
module: Vc<Box<dyn EcmascriptChunkPlaceable>>,
module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
export_name: RcStr,
export: &EsmExport,
side_effect_free_packages: Vc<Glob>,
) -> Result<ControlFlow<FollowExportsResult, (Vc<Box<dyn EcmascriptChunkPlaceable>>, RcStr)>> {
) -> Result<ControlFlow<FollowExportsResult, (ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>, RcStr)>>
{
match export {
EsmExport::ImportedBinding(reference, name, _) => {
if let ReferencedAsset::Some(module) =
Expand All @@ -223,20 +224,20 @@ async fn handle_declared_export(
.await?
{
return Ok(ControlFlow::Break(FollowExportsResult {
module: *module,
module,
export_name: Some(name.clone()),
ty: FoundExportType::SideEffects,
}));
}
return Ok(ControlFlow::Continue((*module, name.clone())));
return Ok(ControlFlow::Continue((module, name.clone())));
}
}
EsmExport::ImportedNamespace(reference) => {
if let ReferencedAsset::Some(m) =
*ReferencedAsset::from_resolve_result(reference.resolve_reference()).await?
{
return Ok(ControlFlow::Break(FollowExportsResult {
module: *m,
module: m,
export_name: None,
ty: FoundExportType::Found,
}));
Expand Down Expand Up @@ -266,13 +267,13 @@ async fn handle_declared_export(

#[turbo_tasks::value]
struct AllExportNamesResult {
esm_exports: FxIndexMap<RcStr, Vc<Box<dyn EcmascriptChunkPlaceable>>>,
dynamic_exporting_modules: Vec<Vc<Box<dyn EcmascriptChunkPlaceable>>>,
esm_exports: FxIndexMap<RcStr, ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>>,
dynamic_exporting_modules: Vec<ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>>,
}

#[turbo_tasks::function]
async fn get_all_export_names(
module: Vc<Box<dyn EcmascriptChunkPlaceable>>,
module: ResolvedVc<Box<dyn EcmascriptChunkPlaceable>>,
) -> Result<Vc<AllExportNamesResult>> {
let exports = module.get_exports().await?;
let EcmascriptExports::EsmExports(exports) = &*exports else {
Expand Down Expand Up @@ -417,7 +418,7 @@ fn emit_star_exports_issue(source_ident: Vc<AssetIdent>, message: RcStr) {
#[derive(Hash, Debug)]
pub struct EsmExports {
pub exports: BTreeMap<RcStr, EsmExport>,
pub star_exports: Vec<Vc<Box<dyn ModuleReference>>>,
pub star_exports: Vec<ResolvedVc<Box<dyn ModuleReference>>>,
}

/// The expanded version of [EsmExports], the `exports` field here includes all
Expand Down Expand Up @@ -455,7 +456,11 @@ impl EsmExports {
if !exports.contains_key(export) {
exports.insert(
export.clone(),
EsmExport::ImportedBinding(Vc::upcast(esm_ref), export.clone(), false),
EsmExport::ImportedBinding(
ResolvedVc::upcast(esm_ref),
export.clone(),
false,
),
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions turbopack/crates/turbopack-ecmascript/src/references/ident.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;
use swc_core::{ecma::ast::Expr, quote};
use turbo_rcstr::RcStr;
use turbo_tasks::Vc;
use turbo_tasks::{ResolvedVc, Vc};
use turbopack_core::chunk::ChunkingContext;

use super::AstPath;
Expand All @@ -13,13 +13,13 @@ use crate::{
#[turbo_tasks::value]
pub struct IdentReplacement {
value: RcStr,
path: Vc<AstPath>,
path: ResolvedVc<AstPath>,
}

#[turbo_tasks::value_impl]
impl IdentReplacement {
#[turbo_tasks::function]
pub fn new(value: RcStr, path: Vc<AstPath>) -> Vc<Self> {
pub fn new(value: RcStr, path: ResolvedVc<AstPath>) -> Vc<Self> {
Self::cell(IdentReplacement { value, path })
}
}
Expand Down
Loading

0 comments on commit 7554a5f

Please sign in to comment.