Unverified Commit 855f0a3f authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: `require(/* turbopackChunkingType: parallel */` (#91278)

1. Add the CJS version of `import ... with {"turbopack-chunking-type: "parallel"`
2. Allow `shared` as a chunking type
3. Improve error message for invalid values:

<img width="718" height="455" alt="Bildschirmfoto 2026-03-13 um 15 07 06" src="https://github.com/user-attachments/assets/bc1efb43-4cc1-4885-b253-49c1e58b3add" />
parent baad064f
...@@ -5,12 +5,7 @@ use rustc_hash::{FxHashMap, FxHashSet}; ...@@ -5,12 +5,7 @@ use rustc_hash::{FxHashMap, FxHashSet};
use smallvec::SmallVec; use smallvec::SmallVec;
use swc_core::{ use swc_core::{
atoms::Wtf8Atom, atoms::Wtf8Atom,
common::{ common::{BytePos, Span, Spanned, SyntaxContext, comments::Comments, source_map::SmallPos},
BytePos, Span, Spanned, SyntaxContext,
comments::Comments,
errors::{DiagnosticId, HANDLER},
source_map::SmallPos,
},
ecma::{ ecma::{
ast::*, ast::*,
atoms::{Atom, atom}, atoms::{Atom, atom},
...@@ -20,15 +15,14 @@ use swc_core::{ ...@@ -20,15 +15,14 @@ use swc_core::{
}; };
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{FxIndexMap, FxIndexSet, ResolvedVc}; use turbo_tasks::{FxIndexMap, FxIndexSet, ResolvedVc};
use turbopack_core::{ use turbopack_core::{issue::IssueSource, loader::WebpackLoaderItem, source::Source};
chunk::ChunkingType, issue::IssueSource, loader::WebpackLoaderItem, source::Source,
};
use super::{JsValue, ModuleValue, top_level_await::has_top_level_await}; use super::{JsValue, ModuleValue, top_level_await::has_top_level_await};
use crate::{ use crate::{
SpecifiedModuleType, SpecifiedModuleType,
analyzer::{ConstantValue, ObjectPart}, analyzer::{ConstantValue, ObjectPart},
magic_identifier, magic_identifier,
references::util::{SpecifiedChunkingType, parse_chunking_type_annotation},
tree_shake::{PartId, find_turbopack_part_id_in_asserts}, tree_shake::{PartId, find_turbopack_part_id_in_asserts},
}; };
...@@ -46,16 +40,13 @@ pub struct ImportAnnotations { ...@@ -46,16 +40,13 @@ pub struct ImportAnnotations {
turbopack_loader: Option<WebpackLoaderItem>, turbopack_loader: Option<WebpackLoaderItem>,
turbopack_rename_as: Option<RcStr>, turbopack_rename_as: Option<RcStr>,
turbopack_module_type: Option<RcStr>, turbopack_module_type: Option<RcStr>,
chunking_type: Option<SpecifiedChunkingType>,
} }
/// Enables a specified transition for the annotated import /// Enables a specified transition for the annotated import
static ANNOTATION_TRANSITION: Lazy<Wtf8Atom> = static ANNOTATION_TRANSITION: Lazy<Wtf8Atom> =
Lazy::new(|| crate::annotations::ANNOTATION_TRANSITION.into()); Lazy::new(|| crate::annotations::ANNOTATION_TRANSITION.into());
/// Changes the chunking type for the annotated import
static ANNOTATION_CHUNKING_TYPE: Lazy<Wtf8Atom> =
Lazy::new(|| crate::annotations::ANNOTATION_CHUNKING_TYPE.into());
/// Changes the type of the resolved module (only "json" is supported currently) /// Changes the type of the resolved module (only "json" is supported currently)
static ATTRIBUTE_MODULE_TYPE: Lazy<Wtf8Atom> = Lazy::new(|| atom!("type").into()); static ATTRIBUTE_MODULE_TYPE: Lazy<Wtf8Atom> = Lazy::new(|| atom!("type").into());
...@@ -69,6 +60,7 @@ impl ImportAnnotations { ...@@ -69,6 +60,7 @@ impl ImportAnnotations {
serde_json::Map::new(); serde_json::Map::new();
let mut turbopack_rename_as: Option<RcStr> = None; let mut turbopack_rename_as: Option<RcStr> = None;
let mut turbopack_module_type: Option<RcStr> = None; let mut turbopack_module_type: Option<RcStr> = None;
let mut chunking_type: Option<SpecifiedChunkingType> = None;
for prop in &with.props { for prop in &with.props {
let Some(kv) = prop.as_prop().and_then(|p| p.as_key_value()) else { let Some(kv) = prop.as_prop().and_then(|p| p.as_key_value()) else {
...@@ -76,13 +68,13 @@ impl ImportAnnotations { ...@@ -76,13 +68,13 @@ impl ImportAnnotations {
}; };
let key_str = match &kv.key { let key_str = match &kv.key {
PropName::Ident(ident) => ident.sym.to_string(), PropName::Ident(ident) => Cow::Borrowed(ident.sym.as_str()),
PropName::Str(str) => str.value.to_string_lossy().into_owned(), PropName::Str(str) => str.value.to_string_lossy(),
_ => continue, _ => continue,
}; };
// All turbopack* keys are extracted as string values (per TC39 import attributes spec) // All turbopack* keys are extracted as string values (per TC39 import attributes spec)
match key_str.as_str() { match &*key_str {
"turbopackLoader" => { "turbopackLoader" => {
if let Some(Lit::Str(s)) = kv.value.as_lit() { if let Some(Lit::Str(s)) = kv.value.as_lit() {
turbopack_loader_name = turbopack_loader_name =
...@@ -110,6 +102,14 @@ impl ImportAnnotations { ...@@ -110,6 +102,14 @@ impl ImportAnnotations {
Some(RcStr::from(s.value.to_string_lossy().into_owned())); Some(RcStr::from(s.value.to_string_lossy().into_owned()));
} }
} }
"turbopack-chunking-type" => {
if let Some(Lit::Str(s)) = kv.value.as_lit() {
chunking_type = parse_chunking_type_annotation(
kv.value.span(),
&s.value.to_string_lossy(),
);
}
}
_ => { _ => {
// For all other keys, only accept string values (per spec) // For all other keys, only accept string values (per spec)
if let Some(Lit::Str(str)) = kv.value.as_lit() { if let Some(Lit::Str(str)) = kv.value.as_lit() {
...@@ -118,23 +118,6 @@ impl ImportAnnotations { ...@@ -118,23 +118,6 @@ impl ImportAnnotations {
PropName::Str(s) => s.value.clone(), PropName::Str(s) => s.value.clone(),
_ => continue, _ => continue,
}; };
// Validate known annotation values
if key == *ANNOTATION_CHUNKING_TYPE {
let value = str.value.to_string_lossy();
if value != "parallel" && value != "none" {
HANDLER.with(|handler| {
handler.span_warn_with_code(
kv.value.span(),
&format!(
"unknown turbopack-chunking-type: \"{value}\", \
expected \"parallel\" or \"none\""
),
DiagnosticId::Error("turbopack-chunking-type".into()),
);
});
continue;
}
}
map.insert(key, str.value.clone()); map.insert(key, str.value.clone());
} }
} }
...@@ -150,12 +133,14 @@ impl ImportAnnotations { ...@@ -150,12 +133,14 @@ impl ImportAnnotations {
|| turbopack_loader.is_some() || turbopack_loader.is_some()
|| turbopack_rename_as.is_some() || turbopack_rename_as.is_some()
|| turbopack_module_type.is_some() || turbopack_module_type.is_some()
|| chunking_type.is_some()
{ {
Some(ImportAnnotations { Some(ImportAnnotations {
map, map,
turbopack_loader, turbopack_loader,
turbopack_rename_as, turbopack_rename_as,
turbopack_module_type, turbopack_module_type,
chunking_type,
}) })
} else { } else {
None None
...@@ -193,6 +178,7 @@ impl ImportAnnotations { ...@@ -193,6 +178,7 @@ impl ImportAnnotations {
turbopack_loader: None, turbopack_loader: None,
turbopack_rename_as: None, turbopack_rename_as: None,
turbopack_module_type: None, turbopack_module_type: None,
chunking_type: None,
}) })
} else { } else {
None None
...@@ -205,23 +191,9 @@ impl ImportAnnotations { ...@@ -205,23 +191,9 @@ impl ImportAnnotations {
.map(|v| v.to_string_lossy()) .map(|v| v.to_string_lossy())
} }
/// Returns the chunking type override from the `turbopack-chunking-type` annotation. /// Returns the content on the chunking-type annotation
/// pub fn chunking_type(&self) -> Option<SpecifiedChunkingType> {
/// - `None` — no annotation present self.chunking_type
/// - `Some(None)` — annotation is `"none"` (opt out of chunking)
/// - `Some(Some(..))` — explicit chunking type (e.g. `"parallel"`)
///
/// Unknown values are rejected during [`ImportAnnotations::parse`] and omitted.
pub fn chunking_type(&self) -> Option<Option<ChunkingType>> {
let chunking_type = self.get(&ANNOTATION_CHUNKING_TYPE)?;
if chunking_type == "none" {
Some(None)
} else {
Some(Some(ChunkingType::Parallel {
inherit_async: true,
hoisted: true,
}))
}
} }
/// Returns the content on the type attribute /// Returns the content on the type attribute
...@@ -362,6 +334,15 @@ pub struct ImportAttributes { ...@@ -362,6 +334,15 @@ pub struct ImportAttributes {
/// const { b } = await import(/* turbopackExports: "b" */ "module"); /// const { b } = await import(/* turbopackExports: "b" */ "module");
/// ``` /// ```
pub export_names: Option<SmallVec<[RcStr; 1]>>, pub export_names: Option<SmallVec<[RcStr; 1]>>,
/// Whether to use a specific chunking type for this import.
//
/// This is set by using a or `turbopackChunkingType` comment.
///
/// Example:
/// ```js
/// const a = require(/* turbopackChunkingType: parallel */ "a");
/// ```
pub chunking_type: Option<SpecifiedChunkingType>,
} }
impl ImportAttributes { impl ImportAttributes {
...@@ -370,6 +351,7 @@ impl ImportAttributes { ...@@ -370,6 +351,7 @@ impl ImportAttributes {
ignore: false, ignore: false,
optional: false, optional: false,
export_names: None, export_names: None,
chunking_type: None,
} }
} }
...@@ -942,12 +924,13 @@ fn parse_directives( ...@@ -942,12 +924,13 @@ fn parse_directives(
comments: &dyn Comments, comments: &dyn Comments,
value: Option<&ExprOrSpread>, value: Option<&ExprOrSpread>,
) -> Option<ImportAttributes> { ) -> Option<ImportAttributes> {
let comment_pos = value.map(|arg| arg.span_lo())?; let value = value?;
let leading_comments = comments.get_leading(comment_pos)?; let leading_comments = comments.get_leading(value.span_lo())?;
let mut ignore = None; let mut ignore = None;
let mut optional = None; let mut optional = None;
let mut export_names = None; let mut export_names = None;
let mut chunking_type = None;
// Process all comments, last one wins for each directive type // Process all comments, last one wins for each directive type
for comment in leading_comments.iter() { for comment in leading_comments.iter() {
...@@ -967,17 +950,21 @@ fn parse_directives( ...@@ -967,17 +950,21 @@ fn parse_directives(
"webpackExports" | "turbopackExports" => { "webpackExports" | "turbopackExports" => {
export_names = Some(parse_export_names(val)); export_names = Some(parse_export_names(val));
} }
"turbopackChunkingType" => {
chunking_type = parse_chunking_type_annotation(value.span(), val);
}
_ => {} // ignore anything else _ => {} // ignore anything else
} }
} }
} }
// Return Some only if at least one directive was found // Return Some only if at least one directive was found
if ignore.is_some() || optional.is_some() || export_names.is_some() { if ignore.is_some() || optional.is_some() || export_names.is_some() || chunking_type.is_some() {
Some(ImportAttributes { Some(ImportAttributes {
ignore: ignore.unwrap_or(false), ignore: ignore.unwrap_or(false),
optional: optional.unwrap_or(false), optional: optional.unwrap_or(false),
export_names, export_names,
chunking_type,
}) })
} else { } else {
None None
......
...@@ -9,14 +9,6 @@ pub const ANNOTATION_CHUNKING_TYPE: &str = "turbopack-chunking-type"; ...@@ -9,14 +9,6 @@ pub const ANNOTATION_CHUNKING_TYPE: &str = "turbopack-chunking-type";
/// Enables a specified transition for the annotated import /// Enables a specified transition for the annotated import
pub const ANNOTATION_TRANSITION: &str = "turbopack-transition"; pub const ANNOTATION_TRANSITION: &str = "turbopack-transition";
pub fn with_chunking_type(chunking_type: &str) -> Box<ObjectLit> {
with_clause(&[(ANNOTATION_CHUNKING_TYPE, chunking_type)])
}
pub fn with_transition(transition_name: &str) -> Box<ObjectLit> {
with_clause(&[(ANNOTATION_TRANSITION, transition_name)])
}
pub fn with_clause<'a>( pub fn with_clause<'a>(
entries: impl IntoIterator<Item = &'a (&'a str, &'a str)>, entries: impl IntoIterator<Item = &'a (&'a str, &'a str)>,
) -> Box<ObjectLit> { ) -> Box<ObjectLit> {
......
...@@ -19,5 +19,6 @@ pub mod failed_to_analyze { ...@@ -19,5 +19,6 @@ pub mod failed_to_analyze {
pub const NEW_WORKER: &str = "TP1203"; pub const NEW_WORKER: &str = "TP1203";
pub const MODULE_HOT_ACCEPT: &str = "TP1204"; pub const MODULE_HOT_ACCEPT: &str = "TP1204";
pub const MODULE_HOT_DECLINE: &str = "TP1205"; pub const MODULE_HOT_DECLINE: &str = "TP1205";
pub const CHUNKING_TYPE: &str = "TP1206";
} }
} }
...@@ -23,6 +23,7 @@ use crate::{ ...@@ -23,6 +23,7 @@ use crate::{
references::{ references::{
AstPath, AstPath,
pattern_mapping::{PatternMapping, ResolveType}, pattern_mapping::{PatternMapping, ResolveType},
util::SpecifiedChunkingType,
}, },
runtime_functions::TURBOPACK_CACHE, runtime_functions::TURBOPACK_CACHE,
}; };
...@@ -80,10 +81,11 @@ impl ModuleReference for CjsAssetReference { ...@@ -80,10 +81,11 @@ impl ModuleReference for CjsAssetReference {
#[derive(Hash, Debug, ValueToString)] #[derive(Hash, Debug, ValueToString)]
#[value_to_string("require {request}")] #[value_to_string("require {request}")]
pub struct CjsRequireAssetReference { pub struct CjsRequireAssetReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>, origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>, request: ResolvedVc<Request>,
pub issue_source: IssueSource, issue_source: IssueSource,
pub error_mode: ResolveErrorMode, error_mode: ResolveErrorMode,
chunking_type_attribute: Option<SpecifiedChunkingType>,
} }
impl CjsRequireAssetReference { impl CjsRequireAssetReference {
...@@ -92,12 +94,14 @@ impl CjsRequireAssetReference { ...@@ -92,12 +94,14 @@ impl CjsRequireAssetReference {
request: ResolvedVc<Request>, request: ResolvedVc<Request>,
issue_source: IssueSource, issue_source: IssueSource,
error_mode: ResolveErrorMode, error_mode: ResolveErrorMode,
chunking_type_attribute: Option<SpecifiedChunkingType>,
) -> Self { ) -> Self {
CjsRequireAssetReference { CjsRequireAssetReference {
origin, origin,
request, request,
issue_source, issue_source,
error_mode, error_mode,
chunking_type_attribute,
} }
} }
} }
...@@ -116,10 +120,15 @@ impl ModuleReference for CjsRequireAssetReference { ...@@ -116,10 +120,15 @@ impl ModuleReference for CjsRequireAssetReference {
} }
fn chunking_type(&self) -> Option<ChunkingType> { fn chunking_type(&self) -> Option<ChunkingType> {
Some(ChunkingType::Parallel { self.chunking_type_attribute.map_or_else(
inherit_async: false, || {
hoisted: false, Some(ChunkingType::Parallel {
}) inherit_async: false,
hoisted: false,
})
},
|c| c.as_chunking_type(false, false),
)
} }
} }
...@@ -202,10 +211,11 @@ impl CjsRequireAssetReferenceCodeGen { ...@@ -202,10 +211,11 @@ impl CjsRequireAssetReferenceCodeGen {
#[derive(Hash, Debug, ValueToString)] #[derive(Hash, Debug, ValueToString)]
#[value_to_string("require.resolve {request}")] #[value_to_string("require.resolve {request}")]
pub struct CjsRequireResolveAssetReference { pub struct CjsRequireResolveAssetReference {
pub origin: ResolvedVc<Box<dyn ResolveOrigin>>, origin: ResolvedVc<Box<dyn ResolveOrigin>>,
pub request: ResolvedVc<Request>, request: ResolvedVc<Request>,
pub issue_source: IssueSource, issue_source: IssueSource,
pub error_mode: ResolveErrorMode, error_mode: ResolveErrorMode,
chunking_type_attribute: Option<SpecifiedChunkingType>,
} }
impl CjsRequireResolveAssetReference { impl CjsRequireResolveAssetReference {
...@@ -214,12 +224,14 @@ impl CjsRequireResolveAssetReference { ...@@ -214,12 +224,14 @@ impl CjsRequireResolveAssetReference {
request: ResolvedVc<Request>, request: ResolvedVc<Request>,
issue_source: IssueSource, issue_source: IssueSource,
error_mode: ResolveErrorMode, error_mode: ResolveErrorMode,
chunking_type_attribute: Option<SpecifiedChunkingType>,
) -> Self { ) -> Self {
CjsRequireResolveAssetReference { CjsRequireResolveAssetReference {
origin, origin,
request, request,
issue_source, issue_source,
error_mode, error_mode,
chunking_type_attribute,
} }
} }
} }
...@@ -238,10 +250,15 @@ impl ModuleReference for CjsRequireResolveAssetReference { ...@@ -238,10 +250,15 @@ impl ModuleReference for CjsRequireResolveAssetReference {
} }
fn chunking_type(&self) -> Option<ChunkingType> { fn chunking_type(&self) -> Option<ChunkingType> {
Some(ChunkingType::Parallel { self.chunking_type_attribute.map_or_else(
inherit_async: false, || {
hoisted: false, Some(ChunkingType::Parallel {
}) inherit_async: false,
hoisted: false,
})
},
|c| c.as_chunking_type(false, false),
)
} }
} }
......
...@@ -46,7 +46,7 @@ use crate::{ ...@@ -46,7 +46,7 @@ use crate::{
EsmExport, EsmExport,
export::{all_known_export_names, is_export_missing}, export::{all_known_export_names, is_export_missing},
}, },
util::throw_module_not_found_expr, util::{SpecifiedChunkingType, throw_module_not_found_expr},
}, },
runtime_functions::{TURBOPACK_EXTERNAL_IMPORT, TURBOPACK_EXTERNAL_REQUIRE, TURBOPACK_IMPORT}, runtime_functions::{TURBOPACK_EXTERNAL_IMPORT, TURBOPACK_EXTERNAL_REQUIRE, TURBOPACK_IMPORT},
tree_shake::{TURBOPACK_PART_IMPORT_SOURCE, part::module::EcmascriptModulePartAsset}, tree_shake::{TURBOPACK_PART_IMPORT_SOURCE, part::module::EcmascriptModulePartAsset},
...@@ -509,10 +509,15 @@ impl ModuleReference for EsmAssetReference { ...@@ -509,10 +509,15 @@ impl ModuleReference for EsmAssetReference {
self.annotations self.annotations
.as_ref() .as_ref()
.and_then(|a| a.chunking_type()) .and_then(|a| a.chunking_type())
.unwrap_or(Some(ChunkingType::Parallel { .map_or_else(
inherit_async: true, || {
hoisted: true, Some(ChunkingType::Parallel {
})) inherit_async: true,
hoisted: true,
})
},
|c| c.as_chunking_type(true, true),
)
} }
fn binding_usage(&self) -> BindingUsage { fn binding_usage(&self) -> BindingUsage {
...@@ -544,10 +549,12 @@ impl EsmAssetReference { ...@@ -544,10 +549,12 @@ impl EsmAssetReference {
} }
// only chunked references can be imported // only chunked references can be imported
if !matches!( if this
this.annotations.as_ref().and_then(|a| a.chunking_type()), .annotations
Some(None) .as_ref()
) { .and_then(|a| a.chunking_type())
.is_none_or(|v| v != SpecifiedChunkingType::None)
{
let import_externals = this.import_externals; let import_externals = this.import_externals;
let referenced_asset = self.get_referenced_asset().await?; let referenced_asset = self.get_referenced_asset().await?;
......
...@@ -1515,10 +1515,15 @@ async fn analyze_ecmascript_module_internal( ...@@ -1515,10 +1515,15 @@ async fn analyze_ecmascript_module_internal(
.annotations .annotations
.as_ref() .as_ref()
.and_then(|a| a.chunking_type()) .and_then(|a| a.chunking_type())
.unwrap_or(Some(ChunkingType::Parallel { .map_or_else(
inherit_async: true, || {
hoisted: true, Some(ChunkingType::Parallel {
})); inherit_async: true,
hoisted: true,
})
},
|c| c.as_chunking_type(true, true),
);
analysis.add_reference_code_gen( analysis.add_reference_code_gen(
EsmModuleIdAssetReference::new(*r, chunking_type), EsmModuleIdAssetReference::new(*r, chunking_type),
ast_path.into(), ast_path.into(),
...@@ -2262,6 +2267,7 @@ where ...@@ -2262,6 +2267,7 @@ where
Request::parse(pat).to_resolved().await?, Request::parse(pat).to_resolved().await?,
issue_source(source, span), issue_source(source, span),
error_mode, error_mode,
attributes.chunking_type,
), ),
ast_path.to_vec().into(), ast_path.to_vec().into(),
); );
...@@ -2315,6 +2321,7 @@ where ...@@ -2315,6 +2321,7 @@ where
Request::parse(pat).to_resolved().await?, Request::parse(pat).to_resolved().await?,
issue_source(source, span), issue_source(source, span),
error_mode, error_mode,
attributes.chunking_type,
), ),
ast_path.to_vec().into(), ast_path.to_vec().into(),
); );
......
use anyhow::Result; use anyhow::Result;
use swc_core::{ecma::ast::Expr, quote}; use bincode::{Decode, Encode};
use swc_core::{
common::{
Span,
errors::{DiagnosticId, HANDLER},
},
ecma::ast::Expr,
quote,
};
use turbo_rcstr::{RcStr, rcstr}; use turbo_rcstr::{RcStr, rcstr};
use turbo_tasks::{ResolvedVc, Vc, turbofmt}; use turbo_tasks::{NonLocalValue, ResolvedVc, Vc, trace::TraceRawVcs, turbofmt};
use turbo_tasks_fs::FileSystemPath; use turbo_tasks_fs::FileSystemPath;
use turbopack_core::{ use turbopack_core::{
self, self,
chunk::ChunkingType,
issue::{ issue::{
Issue, IssueExt, IssueSeverity, IssueSource, IssueStage, OptionIssueSource, Issue, IssueExt, IssueSeverity, IssueSource, IssueStage, OptionIssueSource,
OptionStyledString, StyledString, OptionStyledString, StyledString,
...@@ -12,6 +21,8 @@ use turbopack_core::{ ...@@ -12,6 +21,8 @@ use turbopack_core::{
resolve::{ModuleResolveResult, parse::Request, pattern::Pattern}, resolve::{ModuleResolveResult, parse::Request, pattern::Pattern},
}; };
use crate::errors;
/// Creates a IIFE expression that throws a "Cannot find module" error for the /// Creates a IIFE expression that throws a "Cannot find module" error for the
/// given request string /// given request string
pub fn throw_module_not_found_expr(request: &str) -> Expr { pub fn throw_module_not_found_expr(request: &str) -> Expr {
...@@ -132,3 +143,52 @@ impl Issue for TooManyMatchesWarning { ...@@ -132,3 +143,52 @@ impl Issue for TooManyMatchesWarning {
Vc::cell(Some(self.source)) Vc::cell(Some(self.source))
} }
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Encode, Decode, TraceRawVcs, NonLocalValue)]
pub enum SpecifiedChunkingType {
Parallel,
Shared,
None,
}
impl SpecifiedChunkingType {
pub fn as_chunking_type(&self, inherit_async: bool, hoisted: bool) -> Option<ChunkingType> {
match self {
SpecifiedChunkingType::Parallel => Some(ChunkingType::Parallel {
inherit_async,
hoisted,
}),
SpecifiedChunkingType::Shared => Some(ChunkingType::Shared {
inherit_async,
merge_tag: None,
}),
SpecifiedChunkingType::None => None,
}
}
}
pub fn parse_chunking_type_annotation(
span: Span,
chunking_type_annotation: &str,
) -> Option<SpecifiedChunkingType> {
match chunking_type_annotation {
"parallel" => Some(SpecifiedChunkingType::Parallel),
"shared" => Some(SpecifiedChunkingType::Shared),
"none" => Some(SpecifiedChunkingType::None),
_ => {
HANDLER.with(|handler| {
handler.span_err_with_code(
span,
&format!(
"Unknown specified chunking-type: \"{chunking_type_annotation}\", \
expected \"parallel\", \"shared\" or \"none\""
),
DiagnosticId::Error(
errors::failed_to_analyze::ecmascript::CHUNKING_TYPE.into(),
),
);
});
None
}
}
}
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