Skip to main content

turbopack_ecmascript/
annotations.rs

1use swc_core::{
2    common::DUMMY_SP,
3    ecma::ast::{Expr, KeyValueProp, ObjectLit, Prop, PropName, PropOrSpread},
4};
5
6/// Changes the chunking type for the annotated import
7pub const ANNOTATION_CHUNKING_TYPE: &str = "turbopack-chunking-type";
8
9/// Enables a specified transition for the annotated import
10pub const ANNOTATION_TRANSITION: &str = "turbopack-transition";
11
12/// Forwards the importing module's used exports to the referenced module
13pub const ANNOTATION_EXPORT_USAGE: &str = "turbopack-export-usage";
14
15pub fn with_clause<'a>(
16    entries: impl IntoIterator<Item = &'a (&'a str, &'a str)>,
17) -> Box<ObjectLit> {
18    Box::new(ObjectLit {
19        span: DUMMY_SP,
20        props: entries.into_iter().map(|(k, v)| with_prop(k, v)).collect(),
21    })
22}
23
24fn with_prop(key: &str, value: &str) -> PropOrSpread {
25    PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
26        key: PropName::Str(key.into()),
27        value: Box::new(Expr::Lit(value.into())),
28    })))
29}