Commit 7af2a39e authored by Tobias Koppers's avatar Tobias Koppers

move evaluation to EcmascriptExports

parent 8c732389
......@@ -21,6 +21,7 @@ use turbopack_ecmascript::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkItemOptions,
EcmascriptChunkPlaceable, EcmascriptChunkType, EcmascriptExports, EcmascriptExportsType,
},
references::esm::EsmEvaluation,
runtime_functions::TURBOPACK_REQUIRE,
utils::StringifyJs,
};
......@@ -104,6 +105,7 @@ impl EcmascriptChunkPlaceable for HmrEntryModule {
fn get_exports(self: Vc<Self>) -> Vc<EcmascriptExports> {
EcmascriptExports {
ty: EcmascriptExportsType::None,
evaluation: EsmEvaluation::SideEffects,
}
.cell()
}
......
......@@ -118,10 +118,10 @@ impl EcmascriptChunkPlaceable for NextDynamicEntryModule {
EsmExports {
exports,
star_exports: vec![module_reference],
evaluation: EsmEvaluation::DelegatedSideEffects(module_reference),
}
.resolved_cell(),
),
evaluation: EsmEvaluation::DelegatedSideEffects(module_reference),
}
.cell())
}
......
......@@ -111,10 +111,10 @@ impl EcmascriptChunkPlaceable for NextServerComponentModule {
EsmExports {
exports,
star_exports: vec![module_reference],
evaluation: EsmEvaluation::DelegatedSideEffects(module_reference),
}
.resolved_cell(),
),
evaluation: EsmEvaluation::DelegatedSideEffects(module_reference),
}
.cell())
}
......
......@@ -111,10 +111,10 @@ impl EcmascriptChunkPlaceable for NextServerUtilityModule {
EsmExports {
exports,
star_exports: vec![module_reference],
evaluation: EsmEvaluation::DelegatedSideEffects(module_reference),
}
.resolved_cell(),
),
evaluation: EsmEvaluation::DelegatedSideEffects(module_reference),
}
.cell())
}
......
......@@ -29,6 +29,7 @@ use turbopack_ecmascript::{
EcmascriptChunkType, EcmascriptExports, EcmascriptExportsType,
},
parse::generate_js_source_map,
references::esm::EsmEvaluation,
runtime_functions::{TURBOPACK_EXPORT_VALUE, TURBOPACK_IMPORT},
utils::StringifyJs,
};
......@@ -265,6 +266,7 @@ impl EcmascriptChunkPlaceable for ModuleCssAsset {
fn get_exports(&self) -> Vc<EcmascriptExports> {
EcmascriptExports {
ty: EcmascriptExportsType::Value,
evaluation: EsmEvaluation::SideEffects,
}
.cell()
}
......
......@@ -21,7 +21,7 @@ use turbopack_core::{
use crate::references::{
async_module::OptionAsyncModule,
esm::{EsmExport, EsmExports},
esm::{EsmEvaluation, EsmExport, EsmExports},
};
#[turbo_tasks::value_trait]
......@@ -222,6 +222,7 @@ pub async fn is_marked_as_side_effect_free(
#[turbo_tasks::value(shared)]
pub struct EcmascriptExports {
pub ty: EcmascriptExportsType,
pub evaluation: EsmEvaluation,
}
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize, TraceRawVcs, NonLocalValue)]
......
......@@ -16,7 +16,10 @@ use turbopack_core::{
};
use super::chunk_item::ManifestChunkItem;
use crate::chunk::{EcmascriptChunkPlaceable, EcmascriptExports, EcmascriptExportsType};
use crate::{
chunk::{EcmascriptChunkPlaceable, EcmascriptExports, EcmascriptExportsType},
references::esm::EsmEvaluation,
};
/// The manifest module is deferred until requested by the manifest loader
/// item when the dynamic `import()` expression is reached.
......@@ -174,6 +177,7 @@ impl EcmascriptChunkPlaceable for ManifestAsyncModule {
fn get_exports(&self) -> Vc<EcmascriptExports> {
EcmascriptExports {
ty: EcmascriptExportsType::Value,
evaluation: EsmEvaluation::SideEffects,
}
.cell()
}
......
......@@ -561,7 +561,6 @@ pub enum EsmEvaluation {
pub struct EsmExports {
pub exports: BTreeMap<RcStr, EsmExport>,
pub star_exports: Vec<ResolvedVc<Box<dyn ModuleReference>>>,
pub evaluation: EsmEvaluation,
}
/// The expanded version of [`EsmExports`], the `exports` field here includes all exports that could
......
......@@ -26,7 +26,10 @@ use crate::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable,
EcmascriptChunkType, EcmascriptExports, EcmascriptExportsType,
},
references::async_module::{AsyncModule, OptionAsyncModule},
references::{
async_module::{AsyncModule, OptionAsyncModule},
esm::EsmEvaluation,
},
runtime_functions::{
TURBOPACK_EXPORT_NAMESPACE, TURBOPACK_EXPORT_VALUE, TURBOPACK_EXTERNAL_IMPORT,
TURBOPACK_EXTERNAL_REQUIRE, TURBOPACK_LOAD_BY_URL,
......@@ -321,11 +324,13 @@ impl EcmascriptChunkPlaceable for CachedExternalModule {
if self.external_type == CachedExternalType::CommonJs {
EcmascriptExports {
ty: EcmascriptExportsType::CommonJs,
evaluation: EsmEvaluation::SideEffects,
}
.cell()
} else {
EcmascriptExports {
ty: EcmascriptExportsType::DynamicNamespace,
evaluation: EsmEvaluation::SideEffects,
}
.cell()
}
......
......@@ -227,6 +227,7 @@ pub struct AnalyzeEcmascriptModuleResultBuilder {
code_gens: Vec<CodeGen>,
exports: EcmascriptExportsType,
evaluation: EsmEvaluation,
async_module: ResolvedVc<OptionAsyncModule>,
successful: bool,
source_map: Option<ResolvedVc<Box<dyn GenerateSourceMap>>>,
......@@ -245,6 +246,7 @@ impl AnalyzeEcmascriptModuleResultBuilder {
esm_references_free_var: Default::default(),
code_gens: Default::default(),
exports: EcmascriptExportsType::Unknown,
evaluation: EsmEvaluation::SideEffects,
async_module: ResolvedVc::cell(None),
successful: false,
source_map: None,
......@@ -305,6 +307,11 @@ impl AnalyzeEcmascriptModuleResultBuilder {
self.exports = exports;
}
/// Sets the analysis result evaluation.
pub fn set_evaluation(&mut self, evaluation: EsmEvaluation) {
self.evaluation = evaluation;
}
/// Sets the analysis result ES export.
pub fn set_async_module(&mut self, async_module: ResolvedVc<AsyncModule>) {
self.async_module = ResolvedVc::cell(Some(async_module));
......@@ -411,7 +418,11 @@ impl AnalyzeEcmascriptModuleResultBuilder {
esm_reexport_references.unwrap_or_default(),
),
code_generation: ResolvedVc::cell(self.code_gens),
exports: EcmascriptExports { ty: self.exports }.resolved_cell(),
exports: EcmascriptExports {
ty: self.exports,
evaluation: self.evaluation,
}
.resolved_cell(),
async_module: self.async_module,
has_side_effect_free_directive: self.has_side_effect_free_directive,
successful: self.successful,
......@@ -580,6 +591,18 @@ pub async fn analyse_ecmascript_module_internal(
..
} = &*parsed
else {
// Even a file that failed parsing can be side effect free.
// That's important as
let marked_as_side_effect_free =
*is_marked_as_side_effect_free(path, options.side_effect_free_packages.map(|l| *l))
.await?;
let evaluation = if marked_as_side_effect_free {
EsmEvaluation::SideEffectFree
} else {
EsmEvaluation::SideEffects
};
analysis.set_evaluation(evaluation);
return analysis.build(Default::default(), false).await;
};
......@@ -806,6 +829,8 @@ pub async fn analyse_ecmascript_module_internal(
} else {
EsmEvaluation::SideEffects
};
analysis.set_evaluation(evaluation);
let exports = if !esm_exports.is_empty() || !esm_star_exports.is_empty() {
if specified_type == SpecifiedModuleType::CommonJs {
SpecifiedModuleTypeIssue {
......@@ -820,7 +845,6 @@ pub async fn analyse_ecmascript_module_internal(
let esm_exports = EsmExports {
exports: esm_exports,
star_exports: esm_star_exports,
evaluation,
}
.cell();
......@@ -841,7 +865,6 @@ pub async fn analyse_ecmascript_module_internal(
EsmExports {
exports: Default::default(),
star_exports: Default::default(),
evaluation,
}
.resolved_cell(),
)
......@@ -853,7 +876,6 @@ pub async fn analyse_ecmascript_module_internal(
EsmExports {
exports: Default::default(),
star_exports: Default::default(),
evaluation,
}
.resolved_cell(),
),
......@@ -868,7 +890,6 @@ pub async fn analyse_ecmascript_module_internal(
EsmExports {
exports: Default::default(),
star_exports: Default::default(),
evaluation,
}
.resolved_cell(),
)
......
......@@ -47,6 +47,7 @@ use crate::{
create_visitor,
references::{
AstPath,
esm::EsmEvaluation,
pattern_mapping::{PatternMapping, ResolveType},
},
runtime_functions::{TURBOPACK_EXPORT_VALUE, TURBOPACK_MODULE_CONTEXT, TURBOPACK_REQUIRE},
......@@ -458,6 +459,7 @@ impl EcmascriptChunkPlaceable for RequireContextAsset {
fn get_exports(&self) -> Vc<EcmascriptExports> {
EcmascriptExports {
ty: EcmascriptExportsType::Value,
evaluation: EsmEvaluation::SideEffects,
}
.cell()
}
......
......@@ -343,11 +343,11 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleFacadeModule {
let exports = EsmExports {
exports,
star_exports,
evaluation,
}
.resolved_cell();
Ok(EcmascriptExports {
ty: EcmascriptExportsType::EsmExports(exports),
evaluation,
}
.cell())
}
......
......@@ -133,7 +133,8 @@ impl EcmascriptAnalyzable for EcmascriptModuleLocalsModule {
impl EcmascriptChunkPlaceable for EcmascriptModuleLocalsModule {
#[turbo_tasks::function]
async fn get_exports(&self) -> Result<Vc<EcmascriptExports>> {
let EcmascriptExportsType::EsmExports(exports) = self.module.get_exports().await?.ty else {
let module_exports = self.module.get_exports().await?;
let EcmascriptExportsType::EsmExports(exports) = &module_exports.ty else {
bail!("EcmascriptModuleLocalsModule must only be used on modules with EsmExports");
};
let esm_exports = exports.await?;
......@@ -159,11 +160,11 @@ impl EcmascriptChunkPlaceable for EcmascriptModuleLocalsModule {
let exports = EsmExports {
exports,
star_exports: vec![],
evaluation: esm_exports.evaluation,
}
.resolved_cell();
Ok(EcmascriptExports {
ty: EcmascriptExportsType::EsmExports(exports),
evaluation: module_exports.evaluation,
}
.cell())
}
......
......@@ -28,6 +28,7 @@ use turbopack_ecmascript::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable,
EcmascriptChunkType, EcmascriptExports, EcmascriptExportsType,
},
references::esm::EsmEvaluation,
runtime_functions::TURBOPACK_EXPORT_VALUE,
};
......@@ -81,6 +82,7 @@ impl EcmascriptChunkPlaceable for JsonModuleAsset {
fn get_exports(&self) -> Vc<EcmascriptExports> {
EcmascriptExports {
ty: EcmascriptExportsType::Value,
evaluation: EsmEvaluation::SideEffects,
}
.cell()
}
......
......@@ -15,6 +15,7 @@ use turbopack_ecmascript::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable,
EcmascriptChunkType, EcmascriptExports, EcmascriptExportsType,
},
references::esm::EsmEvaluation,
runtime_functions::TURBOPACK_EXPORT_VALUE,
utils::StringifyJs,
};
......@@ -88,6 +89,7 @@ impl EcmascriptChunkPlaceable for StaticUrlJsModule {
fn get_exports(&self) -> Vc<EcmascriptExports> {
EcmascriptExports {
ty: EcmascriptExportsType::Value,
evaluation: EsmEvaluation::SideEffects,
}
.cell()
}
......
......@@ -16,6 +16,7 @@ use turbopack_ecmascript::{
EcmascriptChunkItem, EcmascriptChunkItemContent, EcmascriptChunkPlaceable,
EcmascriptChunkType, EcmascriptExports, EcmascriptExportsType,
},
references::esm::EsmEvaluation,
runtime_functions::TURBOPACK_EXPORT_VALUE,
utils::StringifyJs,
};
......@@ -94,6 +95,7 @@ impl EcmascriptChunkPlaceable for RawWebAssemblyModuleAsset {
fn get_exports(self: Vc<Self>) -> Vc<EcmascriptExports> {
EcmascriptExports {
ty: EcmascriptExportsType::Value,
evaluation: EsmEvaluation::SideEffects,
}
.cell()
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment