@@ -269,7 +269,6 @@ pub enum WorkerReferenceSubType {
269269 ServiceWorker ,
270270 NodeWorker ,
271271 Custom ( u8 ) ,
272- Undefined ,
273272}
274273
275274// TODO(sokra) this was next.js specific values. We want to solve this in a
@@ -351,53 +350,6 @@ impl Display for ReferenceType {
351350}
352351
353352impl ReferenceType {
354- pub fn includes ( & self , other : & Self ) -> bool {
355- if self == other {
356- return true ;
357- }
358- match self {
359- ReferenceType :: CommonJs ( sub_type) => {
360- matches ! ( other, ReferenceType :: CommonJs ( _) )
361- && matches ! ( sub_type, CommonJsReferenceSubType :: Undefined )
362- }
363- ReferenceType :: EcmaScriptModules ( sub_type) => {
364- matches ! ( other, ReferenceType :: EcmaScriptModules ( _) )
365- && matches ! ( sub_type, EcmaScriptModulesReferenceSubType :: Undefined )
366- }
367- ReferenceType :: Css ( CssReferenceSubType :: AtImport ( _) ) => {
368- // For condition matching, treat any AtImport pair as identical.
369- matches ! ( other, ReferenceType :: Css ( CssReferenceSubType :: AtImport ( _) ) )
370- }
371- ReferenceType :: Css ( sub_type) => {
372- matches ! ( other, ReferenceType :: Css ( _) )
373- && matches ! ( sub_type, CssReferenceSubType :: Undefined )
374- }
375- ReferenceType :: Url ( sub_type) => {
376- matches ! ( other, ReferenceType :: Url ( _) )
377- && matches ! ( sub_type, UrlReferenceSubType :: Undefined )
378- }
379- ReferenceType :: TypeScript ( sub_type) => {
380- matches ! ( other, ReferenceType :: TypeScript ( _) )
381- && matches ! ( sub_type, TypeScriptReferenceSubType :: Undefined )
382- }
383- ReferenceType :: Worker ( sub_type) => {
384- matches ! ( other, ReferenceType :: Worker ( _) )
385- && matches ! ( sub_type, WorkerReferenceSubType :: Undefined )
386- }
387- ReferenceType :: Entry ( sub_type) => {
388- matches ! ( other, ReferenceType :: Entry ( _) )
389- && matches ! ( sub_type, EntryReferenceSubType :: Undefined )
390- }
391- ReferenceType :: Runtime => matches ! ( other, ReferenceType :: Runtime ) ,
392- ReferenceType :: Internal ( _) => matches ! ( other, ReferenceType :: Internal ( _) ) ,
393- ReferenceType :: Loader => matches ! ( other, ReferenceType :: Loader ) ,
394- ReferenceType :: Custom ( _) => {
395- todo ! ( )
396- }
397- ReferenceType :: Undefined => true ,
398- }
399- }
400-
401353 /// Returns true if this reference type is internal. This will be used in
402354 /// combination with [`ModuleRuleCondition::Internal`] to determine if a
403355 /// rule should be applied to an internal asset/reference.
@@ -408,3 +360,74 @@ impl ReferenceType {
408360 )
409361 }
410362}
363+
364+ #[ derive(
365+ PartialEq , Eq , TraceRawVcs , NonLocalValue , Debug , Clone , Hash , TaskInput , Encode , Decode ,
366+ ) ]
367+ pub enum ReferenceTypeCondition {
368+ CommonJs ( Option < CommonJsReferenceSubType > ) ,
369+ EcmaScriptModules ( Option < EcmaScriptModulesReferenceSubType > ) ,
370+ Css ( Option < CssReferenceSubType > ) ,
371+ Url ( Option < UrlReferenceSubType > ) ,
372+ TypeScript ( Option < TypeScriptReferenceSubType > ) ,
373+ Worker ( Option < WorkerReferenceSubType > ) ,
374+ Entry ( Option < EntryReferenceSubType > ) ,
375+ Runtime ,
376+ Internal ,
377+ Loader ,
378+ Custom ( u8 ) ,
379+ }
380+
381+ macro_rules! match_condition_includes {
382+ (
383+ $self: expr, $other: expr,
384+ optional: [ $( $opt: ident) ,* $( , ) ?] ,
385+ unit: [ $( $unit: ident) ,* $( , ) ?] ,
386+ value: [ $( $val: ident) ,* $( , ) ?]
387+ $( , ) ?
388+ ) => {
389+ match $self {
390+ $(
391+ ReferenceTypeCondition :: $opt( sub_type) => {
392+ if let ReferenceType :: $opt( other_sub_type) = $other {
393+ return sub_type. as_ref( ) . is_none_or( |s| s == other_sub_type) ;
394+ }
395+ }
396+ ) *
397+ $(
398+ ReferenceTypeCondition :: $unit => {
399+ return matches!( $other, ReferenceType :: $unit { .. } ) ;
400+ }
401+ ) *
402+ $(
403+ ReferenceTypeCondition :: $val( v) => {
404+ if let ReferenceType :: $val( ov) = $other {
405+ return v == ov;
406+ }
407+ }
408+ ) *
409+ }
410+ } ;
411+ }
412+
413+ impl ReferenceTypeCondition {
414+ pub fn includes ( & self , other : & ReferenceType ) -> bool {
415+ if matches ! (
416+ self ,
417+ ReferenceTypeCondition :: Css ( Some ( CssReferenceSubType :: AtImport ( _) ) )
418+ ) && matches ! ( other, ReferenceType :: Css ( CssReferenceSubType :: AtImport ( _) ) )
419+ {
420+ // For condition matching, treat any AtImport pair as identical.
421+ return true ;
422+ }
423+
424+ match_condition_includes ! (
425+ self , other,
426+ optional: [ CommonJs , EcmaScriptModules , Css , Url , TypeScript , Worker , Entry ] ,
427+ unit: [ Runtime , Loader , Internal ] ,
428+ value: [ Custom ] ,
429+ ) ;
430+
431+ false
432+ }
433+ }
0 commit comments