diff --git a/crates/next-core/src/app_segment_config.rs b/crates/next-core/src/app_segment_config.rs index ba64f16317fa1..9ba28dfd3ea0e 100644 --- a/crates/next-core/src/app_segment_config.rs +++ b/crates/next-core/src/app_segment_config.rs @@ -166,9 +166,26 @@ impl NextSegmentConfig { /// An issue that occurred while parsing the app segment config. #[turbo_tasks::value(shared)] pub struct NextSegmentConfigParsingIssue { - ident: Vc, + ident: ResolvedVc, detail: ResolvedVc, - source: Vc, + source: ResolvedVc, +} + +#[turbo_tasks::value_impl] +impl NextSegmentConfigParsingIssue { + #[turbo_tasks::function] + pub fn new( + ident: ResolvedVc, + detail: ResolvedVc, + source: ResolvedVc, + ) -> Vc { + Self { + ident, + detail, + source, + } + .cell() + } } #[turbo_tasks::value_impl] @@ -333,13 +350,8 @@ fn parse_config_value( let detail = StyledString::Text(format!("{detail} Got {explainer}.{hints}").into()).resolved_cell(); - NextSegmentConfigParsingIssue { - ident: source.ident(), - detail, - source: issue_source(source, span), - } - .cell() - .emit(); + NextSegmentConfigParsingIssue::new(source.ident(), *detail, issue_source(source, span)) + .emit(); }; match &*ident.sym { diff --git a/crates/next-core/src/util.rs b/crates/next-core/src/util.rs index 86d7e2dd5592b..f2ea8baa64c7c 100644 --- a/crates/next-core/src/util.rs +++ b/crates/next-core/src/util.rs @@ -196,10 +196,18 @@ impl ValueDefault for NextSourceConfig { /// An issue that occurred while parsing the page config. #[turbo_tasks::value(shared)] pub struct NextSourceConfigParsingIssue { - ident: Vc, + ident: ResolvedVc, detail: ResolvedVc, } +#[turbo_tasks::value_impl] +impl NextSourceConfigParsingIssue { + #[turbo_tasks::function] + pub fn new(ident: ResolvedVc, detail: ResolvedVc) -> Vc { + Self { ident, detail }.cell() + } +} + #[turbo_tasks::value_impl] impl Issue for NextSourceConfigParsingIssue { #[turbo_tasks::function] @@ -242,13 +250,11 @@ impl Issue for NextSourceConfigParsingIssue { fn emit_invalid_config_warning(ident: Vc, detail: &str, value: &JsValue) { let (explainer, hints) = value.explain(2, 0); - NextSourceConfigParsingIssue { + NextSourceConfigParsingIssue::new( ident, - detail: StyledString::Text(format!("{detail} Got {explainer}.{hints}").into()) - .resolved_cell(), - } - .resolved_cell() - .emit() + StyledString::Text(format!("{detail} Got {explainer}.{hints}").into()).cell(), + ) + .emit(); } fn parse_route_matcher_from_js_value( @@ -409,17 +415,16 @@ pub async fn parse_config_from_source( Ok(parse_config_from_js_value(*module, &value).cell()) }); } else { - NextSourceConfigParsingIssue { - ident: module.ident(), - detail: StyledString::Text( + NextSourceConfigParsingIssue::new( + module.ident(), + StyledString::Text( "The exported config object must contain an variable \ initializer." .into(), ) - .resolved_cell(), - } - .resolved_cell() - .emit() + .cell(), + ) + .emit(); } } // Or, check if there is segment runtime option @@ -428,15 +433,14 @@ pub async fn parse_config_from_source( .map(|ident| &*ident.sym == "runtime") .unwrap_or_default() { - let runtime_value_issue = NextSourceConfigParsingIssue { - ident: module.ident(), - detail: StyledString::Text( + let runtime_value_issue = NextSourceConfigParsingIssue::new( + module.ident(), + StyledString::Text( "The runtime property must be either \"nodejs\" or \"edge\"." .into(), ) - .resolved_cell(), - } - .resolved_cell(); + .cell(), + ); if let Some(init) = decl.init.as_ref() { // skipping eval and directly read the expr's value, as we know it // should be a const string @@ -461,17 +465,16 @@ pub async fn parse_config_from_source( runtime_value_issue.emit(); } } else { - NextSourceConfigParsingIssue { - ident: module.ident(), - detail: StyledString::Text( + NextSourceConfigParsingIssue::new( + module.ident(), + StyledString::Text( "The exported segment runtime option must contain an \ variable initializer." .into(), ) - .resolved_cell(), - } - .resolved_cell() - .emit() + .cell(), + ) + .emit(); } } } diff --git a/turbopack/crates/turbopack-core/src/issue/analyze.rs b/turbopack/crates/turbopack-core/src/issue/analyze.rs index 236e5401ce4e2..eb521f7abd4ab 100644 --- a/turbopack/crates/turbopack-core/src/issue/analyze.rs +++ b/turbopack/crates/turbopack-core/src/issue/analyze.rs @@ -12,11 +12,34 @@ use crate::ident::AssetIdent; #[turbo_tasks::value(shared)] pub struct AnalyzeIssue { pub severity: ResolvedVc, - pub source_ident: Vc, + pub source_ident: ResolvedVc, pub title: ResolvedVc, pub message: ResolvedVc, pub code: Option, - pub source: Option>, + pub source: Option>, +} + +#[turbo_tasks::value_impl] +impl AnalyzeIssue { + #[turbo_tasks::function] + pub fn new( + severity: ResolvedVc, + source_ident: ResolvedVc, + title: ResolvedVc, + message: ResolvedVc, + code: Option, + source: Option>, + ) -> Vc { + Self { + severity, + source_ident, + title, + message, + code, + source, + } + .cell() + } } #[turbo_tasks::value_impl] diff --git a/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs b/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs index 596c6d826ed12..956057ec83a07 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/esm/export.rs @@ -401,15 +401,14 @@ pub async fn expand_star_exports( } fn emit_star_exports_issue(source_ident: Vc, message: RcStr) { - AnalyzeIssue { - code: None, - message: StyledString::Text(message).resolved_cell(), + AnalyzeIssue::new( + IssueSeverity::Warning.cell(), source_ident, - severity: IssueSeverity::Warning.resolved_cell(), - source: None, - title: ResolvedVc::cell("unexpected export *".into()), - } - .cell() + Vc::cell("unexpected export *".into()), + StyledString::Text(message).cell(), + None, + None, + ) .emit(); } diff --git a/turbopack/crates/turbopack-ecmascript/src/references/mod.rs b/turbopack/crates/turbopack-ecmascript/src/references/mod.rs index d0c6e7d590908..0e546668f4748 100644 --- a/turbopack/crates/turbopack-ecmascript/src/references/mod.rs +++ b/turbopack/crates/turbopack-ecmascript/src/references/mod.rs @@ -848,16 +848,14 @@ pub(crate) async fn analyse_ecmascript_module_internal( .resolved_cell(); analysis.set_async_module(async_module); } else if let Some(span) = top_level_await_span { - AnalyzeIssue { - code: None, - message: StyledString::Text("top level await is only supported in ESM modules.".into()) - .resolved_cell(), - source_ident: source.ident(), - severity: IssueSeverity::Error.resolved_cell(), - source: Some(issue_source(*source, span)), - title: ResolvedVc::cell("unexpected top level await".into()), - } - .cell() + AnalyzeIssue::new( + IssueSeverity::Error.cell(), + source.ident(), + Vc::cell("unexpected top level await".into()), + StyledString::Text("top level await is only supported in ESM modules.".into()).cell(), + None, + Some(issue_source(*source, span)), + ) .emit(); } diff --git a/turbopack/crates/turbopack-swc-utils/src/emitter.rs b/turbopack/crates/turbopack-swc-utils/src/emitter.rs index ed43a11a108f2..1ae371a487912 100644 --- a/turbopack/crates/turbopack-swc-utils/src/emitter.rs +++ b/turbopack/crates/turbopack-swc-utils/src/emitter.rs @@ -6,7 +6,7 @@ use swc_core::common::{ SourceMap, }; use turbo_rcstr::RcStr; -use turbo_tasks::ResolvedVc; +use turbo_tasks::{ResolvedVc, Vc}; use turbopack_core::{ issue::{analyze::AnalyzeIssue, IssueExt, IssueSeverity, IssueSource, StyledString}, source::Source, @@ -17,7 +17,7 @@ pub struct IssueEmitter { pub source: ResolvedVc>, pub source_map: Arc, pub title: Option, - pub emitted_issues: Vec>, + pub emitted_issues: Vec>, } impl IssueEmitter { @@ -83,15 +83,14 @@ impl Emitter for IssueEmitter { }); // TODO add other primary and secondary spans with labels as sub_issues - let issue = AnalyzeIssue { - severity, - source_ident: self.source.ident(), - title: ResolvedVc::cell(title), - message: StyledString::Text(message.into()).resolved_cell(), + let issue = AnalyzeIssue::new( + *severity, + self.source.ident(), + Vc::cell(title), + StyledString::Text(message.into()).cell(), code, source, - } - .resolved_cell(); + ); self.emitted_issues.push(issue); diff --git a/turbopack/crates/turbopack-tests/tests/execution/turbopack/async-modules/export-all/issues/unexpected export __star__-9b505f.txt b/turbopack/crates/turbopack-tests/tests/execution/turbopack/async-modules/export-all/issues/unexpected export __star__-1b6874.txt similarity index 100% rename from turbopack/crates/turbopack-tests/tests/execution/turbopack/async-modules/export-all/issues/unexpected export __star__-9b505f.txt rename to turbopack/crates/turbopack-tests/tests/execution/turbopack/async-modules/export-all/issues/unexpected export __star__-1b6874.txt diff --git a/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1001__ import(FreeVar(Math)[__quo__ra-5994a8.txt b/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1001__ import(FreeVar(Math)[__quo__ra-d3b7e2.txt similarity index 100% rename from turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1001__ import(FreeVar(Math)[__quo__ra-5994a8.txt rename to turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1001__ import(FreeVar(Math)[__quo__ra-d3b7e2.txt diff --git a/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1002__ require(FreeVar(Math)[__quo__r-ae8b1d.txt b/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1002__ require(FreeVar(Math)[__quo__r-6e3023.txt similarity index 100% rename from turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1002__ require(FreeVar(Math)[__quo__r-ae8b1d.txt rename to turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1002__ require(FreeVar(Math)[__quo__r-6e3023.txt diff --git a/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1004__ fs.readFileSync(FreeVar(Math)[-ad123b.txt b/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1004__ fs.readFileSync(FreeVar(Math)[-6979f9.txt similarity index 100% rename from turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1004__ fs.readFileSync(FreeVar(Math)[-ad123b.txt rename to turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1004__ fs.readFileSync(FreeVar(Math)[-6979f9.txt diff --git a/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1004__ fs.readFileSync(FreeVar(Math)[-9b8ecf.txt b/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1004__ fs.readFileSync(FreeVar(Math)[-d1bdaa.txt similarity index 100% rename from turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1004__ fs.readFileSync(FreeVar(Math)[-9b8ecf.txt rename to turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1004__ fs.readFileSync(FreeVar(Math)[-d1bdaa.txt diff --git a/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1005__ child_process.spawnSync(FreeVa-5687e7.txt b/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1005__ child_process.spawnSync(FreeVa-affa1e.txt similarity index 100% rename from turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1005__ child_process.spawnSync(FreeVa-5687e7.txt rename to turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1005__ child_process.spawnSync(FreeVa-affa1e.txt diff --git a/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1005__ child_process.spawnSync(__-e5d6ef.txt b/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1005__ child_process.spawnSync(__-10f2d3.txt similarity index 100% rename from turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1005__ child_process.spawnSync(__-e5d6ef.txt rename to turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1005__ child_process.spawnSync(__-10f2d3.txt diff --git a/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1005__ child_process.spawnSync(__quo_-6d6a3b.txt b/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1005__ child_process.spawnSync(__quo_-148671.txt similarity index 100% rename from turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1005__ child_process.spawnSync(__quo_-6d6a3b.txt rename to turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1005__ child_process.spawnSync(__quo_-148671.txt diff --git a/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1201__ new URL(FreeVar(Math)[__quo__r-9d8616.txt b/turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1201__ new URL(FreeVar(Math)[__quo__r-6f3f56.txt similarity index 100% rename from turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1201__ new URL(FreeVar(Math)[__quo__r-9d8616.txt rename to turbopack/crates/turbopack-tests/tests/snapshot/dynamic-request/very-dynamic/issues/__l___lint TP1201__ new URL(FreeVar(Math)[__quo__r-6f3f56.txt diff --git a/turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/issues/unexpected export __star__-f9a205.txt b/turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/issues/unexpected export __star__-fec6f9.txt similarity index 100% rename from turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/issues/unexpected export __star__-f9a205.txt rename to turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-2/issues/unexpected export __star__-fec6f9.txt diff --git a/turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/issues/unexpected export __star__-13c450.txt b/turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/issues/unexpected export __star__-951920.txt similarity index 100% rename from turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/issues/unexpected export __star__-13c450.txt rename to turbopack/crates/turbopack-tests/tests/snapshot/export-alls/cjs-script/issues/unexpected export __star__-951920.txt diff --git a/turbopack/crates/turbopack-tests/tests/snapshot/imports/duplicate-binding/issues/Ecmascript file had an error-f62e84.txt b/turbopack/crates/turbopack-tests/tests/snapshot/imports/duplicate-binding/issues/Ecmascript file had an error-a1afab.txt similarity index 100% rename from turbopack/crates/turbopack-tests/tests/snapshot/imports/duplicate-binding/issues/Ecmascript file had an error-f62e84.txt rename to turbopack/crates/turbopack-tests/tests/snapshot/imports/duplicate-binding/issues/Ecmascript file had an error-a1afab.txt