-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(turbopack-ecmascript): use import attributes for annotations
- Loading branch information
1 parent
04248f4
commit e0a5a0a
Showing
6 changed files
with
145 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
use swc_core::{ | ||
common::DUMMY_SP, | ||
ecma::ast::{Expr, KeyValueProp, ObjectLit, Prop, PropName, PropOrSpread}, | ||
}; | ||
|
||
/// Changes the chunking type for the annotated import | ||
pub const ANNOTATION_CHUNKING_TYPE: &str = "turbopack-chunking-type"; | ||
|
||
/// Enables a specified transition for the annotated import | ||
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>( | ||
entries: impl IntoIterator<Item = &'a (&'a str, &'a str)>, | ||
) -> Box<ObjectLit> { | ||
Box::new(ObjectLit { | ||
span: DUMMY_SP, | ||
props: entries.into_iter().map(|(k, v)| with_prop(k, v)).collect(), | ||
}) | ||
} | ||
|
||
fn with_prop(key: &str, value: &str) -> PropOrSpread { | ||
PropOrSpread::Prop(Box::new(Prop::KeyValue(KeyValueProp { | ||
key: PropName::Str(key.into()), | ||
value: Box::new(Expr::Lit(value.into())), | ||
}))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.