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
12pub fn with_clause<'a>(
13    entries: impl IntoIterator<Item = &'a (&'a str, &'a str)>,
14) -> Box<ObjectLit> {
15    Box::new(ObjectLit {
16        span: DUMMY_SP,
17        props: entries.into_iter().map(|(k, v)| with_prop(k, v)).collect(),
18    })
19}
20
21fn with_prop(key: &str, value: &str) -> PropOrSpread {
22    PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp {
23        key: PropName::Str(key.into()),
24        value: Box::new(Expr::Lit(value.into())),
25    })))
26}