Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix internal JS/TS references not being processed #5457

Merged
merged 1 commit into from
Jul 4, 2023
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
4 changes: 2 additions & 2 deletions crates/turbopack/src/module_options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ impl ModuleOptionsVc {
ModuleRuleCondition::ResourcePathEndsWith(".json".to_string()),
vec![ModuleRuleEffect::ModuleType(ModuleType::Json)],
),
ModuleRule::new(
ModuleRule::new_all(
ModuleRuleCondition::any(vec![
ModuleRuleCondition::ResourcePathEndsWith(".js".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".jsx".to_string()),
Expand Down Expand Up @@ -255,7 +255,7 @@ impl ModuleOptionsVc {
},
})],
),
ModuleRule::new(
ModuleRule::new_all(
ModuleRuleCondition::any(vec![
ModuleRuleCondition::ResourcePathEndsWith(".ts".to_string()),
ModuleRuleCondition::ResourcePathEndsWith(".tsx".to_string()),
Expand Down
20 changes: 15 additions & 5 deletions crates/turbopack/src/module_options/module_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@ pub struct ModuleRule {
match_mode: MatchMode,
}

#[derive(Default, Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize, TraceRawVcs)]
enum MatchMode {
// Match all but internal references.
#[default]
Default,
NonInternal,
// Only match internal references.
Internal,
// Match both internal and non-internal references.
All,
}

impl MatchMode {
fn matches(&self, reference_type: &ReferenceType) -> bool {
matches!(
(self, reference_type.is_internal()),
(MatchMode::Default, false) | (MatchMode::Internal, true)
(MatchMode::All, _) | (MatchMode::NonInternal, false) | (MatchMode::Internal, true)
)
}
}
Expand All @@ -42,7 +43,7 @@ impl ModuleRule {
ModuleRule {
condition,
effects,
match_mode: Default::default(),
match_mode: MatchMode::NonInternal,
}
}

Expand All @@ -55,6 +56,15 @@ impl ModuleRule {
}
}

/// Creates a new module rule. Will only matches internal references.
pub fn new_all(condition: ModuleRuleCondition, effects: Vec<ModuleRuleEffect>) -> Self {
ModuleRule {
condition,
effects,
match_mode: MatchMode::All,
}
}

pub fn effects(&self) -> impl Iterator<Item = &ModuleRuleEffect> {
self.effects.iter()
}
Expand Down