这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions crates/turbopack-ecmascript/src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,7 @@ pub enum EcmascriptInputTransform {
ClientDirective(StringVc),
CommonJs,
Custom(CustomTransformVc),
Emotion {
#[serde(default)]
sourcemap: bool,
label_format: OptionStringVc,
auto_label: Option<bool>,
},
Emotion,
PresetEnv(EnvironmentVc),
React {
#[serde(default)]
Expand Down Expand Up @@ -179,24 +174,10 @@ impl EcmascriptInputTransform {
Some(comments.clone()),
));
}
EcmascriptInputTransform::Emotion {
sourcemap,
label_format,
auto_label,
} => {
let options = swc_emotion::EmotionOptions {
// this should be always enabled if match arrives here:
// since moduleoptions expect to push emotion transform only if
// there are valid, enabled config values.
enabled: Some(true),
sourcemap: Some(*sourcemap),
label_format: label_format.await?.clone_value(),
auto_label: *auto_label,
..Default::default()
};
EcmascriptInputTransform::Emotion => {
let p = std::mem::replace(program, Program::Module(Module::dummy()));
*program = p.fold_with(&mut swc_emotion::emotion(
options,
Default::default(),
Path::new(file_name_str),
source_map.clone(),
comments.clone(),
Expand Down
11 changes: 2 additions & 9 deletions crates/turbopack-tests/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ use turbo_tasks_memory::MemoryBackend;
use turbopack::{
condition::ContextCondition,
ecmascript::EcmascriptModuleAssetVc,
module_options::{
EmotionTransformOptions, EmotionTransformOptionsVc, JsxTransformOptions,
JsxTransformOptionsVc, ModuleOptionsContext,
},
module_options::{JsxTransformOptions, JsxTransformOptionsVc, ModuleOptionsContext},
resolve_options_context::ResolveOptionsContext,
transition::TransitionsByNameVc,
ModuleAssetContextVc,
Expand Down Expand Up @@ -196,11 +193,7 @@ async fn run_test(resource: &str) -> Result<FileSystemPathVc> {
enable_jsx: Some(JsxTransformOptionsVc::cell(JsxTransformOptions {
..Default::default()
})),
enable_emotion: Some(EmotionTransformOptionsVc::cell(EmotionTransformOptions {
enabled: true,
sourcemap: Some(false),
..Default::default()
})),
enable_emotion: true,
enable_styled_components: true,
preset_env_versions: Some(env),
rules: vec![(
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 3 additions & 19 deletions crates/turbopack/src/module_options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl ModuleOptionsVc {
) -> Result<ModuleOptionsVc> {
let ModuleOptionsContext {
enable_jsx,
ref enable_emotion,
enable_emotion,
enable_react_refresh,
enable_styled_jsx,
enable_styled_components,
Expand Down Expand Up @@ -96,24 +96,8 @@ impl ModuleOptionsVc {
if enable_styled_jsx {
transforms.push(EcmascriptInputTransform::StyledJsx);
}
if let Some(enable_emotion) = enable_emotion {
let emotion_transform = enable_emotion.await?;
if emotion_transform.enabled {
transforms.push(EcmascriptInputTransform::Emotion {
sourcemap: emotion_transform.sourcemap.unwrap_or(false),
label_format: OptionStringVc::cell(emotion_transform.label_format.clone()),
auto_label: if let Some(auto_label) = emotion_transform.auto_label.as_ref() {
match auto_label {
EmotionLabelKind::Always => Some(true),
EmotionLabelKind::Never => Some(false),
// [TODO]: this is not correct coerece, need to be fixed
EmotionLabelKind::DevOnly => None,
}
} else {
None
},
});
}
if enable_emotion {
transforms.push(EcmascriptInputTransform::Emotion);
}
if enable_styled_components {
transforms.push(EcmascriptInputTransform::StyledComponents);
Expand Down
34 changes: 1 addition & 33 deletions crates/turbopack/src/module_options/module_options_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,38 +89,6 @@ impl Default for TypescriptTransformOptionsVc {
}
}

#[derive(Clone, PartialEq, Eq, Debug, TraceRawVcs, Serialize, Deserialize)]
pub enum EmotionLabelKind {
DevOnly,
Always,
Never,
}

//[TODO]: need to support importmap, there are type mismatch between
//[TODO]: next.config.js to swc's emotion options
#[turbo_tasks::value(shared)]
#[derive(Default, Clone, Debug)]
pub struct EmotionTransformOptions {
pub enabled: bool,
pub sourcemap: Option<bool>,
pub label_format: Option<String>,
pub auto_label: Option<EmotionLabelKind>,
}

#[turbo_tasks::value_impl]
impl EmotionTransformOptionsVc {
#[turbo_tasks::function]
pub fn default() -> Self {
Self::cell(Default::default())
}
}

impl Default for EmotionTransformOptionsVc {
fn default() -> Self {
Self::default()
}
}

impl WebpackLoadersOptions {
pub fn is_empty(&self) -> bool {
self.extension_to_loaders.is_empty()
Expand Down Expand Up @@ -149,7 +117,7 @@ pub struct ModuleOptionsContext {
#[serde(default)]
pub enable_jsx: Option<JsxTransformOptionsVc>,
#[serde(default)]
pub enable_emotion: Option<EmotionTransformOptionsVc>,
pub enable_emotion: bool,
#[serde(default)]
pub enable_react_refresh: bool,
#[serde(default)]
Expand Down