@@ -3,7 +3,6 @@ use oxc_ast::{
33 ast:: { Argument , Expression , FormalParameter } ,
44} ;
55use oxc_span:: Atom ;
6- use phf:: { phf_set, set:: Set } ;
76
87/// Check if the given node is registering an endpoint handler or middleware to
98/// a route or Express application object. If it is, it
@@ -24,7 +23,7 @@ pub fn as_endpoint_registration<'a, 'n>(
2423 let call = node. as_call_expression ( ) ?;
2524 let callee = call. callee . as_member_expression ( ) ?;
2625 let method_name = callee. static_property_name ( ) ?;
27- if ! ROUTER_HANDLER_METHOD_NAMES . contains ( method_name) {
26+ if ROUTER_HANDLER_METHOD_NAMES . binary_search ( & method_name) . is_err ( ) {
2827 return None ;
2928 }
3029 if call. arguments . is_empty ( ) {
@@ -74,53 +73,31 @@ pub fn is_endpoint_handler(maybe_handler: &Expression<'_>) -> bool {
7473 }
7574}
7675
77- const ROUTER_HANDLER_METHOD_NAMES : Set < & ' static str > = phf_set ! {
78- "get" ,
79- "post" ,
80- "put" ,
81- "delete" ,
82- "patch" ,
83- "options" ,
84- "head" ,
85- "use" ,
86- "all" ,
87- } ;
76+ const ROUTER_HANDLER_METHOD_NAMES : [ & str ; 9 ] =
77+ [ "all" , "delete" , "get" , "head" , "options" , "patch" , "post" , "put" , "use" ] ;
8878
89- const COMMON_REQUEST_NAMES : Set < & ' static str > = phf_set ! {
90- "r" ,
91- "req" ,
92- "request" ,
93- } ;
79+ const COMMON_REQUEST_NAMES : [ & str ; 3 ] = [ "r" , "req" , "request" ] ;
9480fn is_req_param ( param : & FormalParameter ) -> bool {
95- param. pattern . get_identifier_name ( ) . is_some_and ( |id| COMMON_REQUEST_NAMES . contains ( id. as_str ( ) ) )
81+ param
82+ . pattern
83+ . get_identifier_name ( )
84+ . is_some_and ( |id| COMMON_REQUEST_NAMES . contains ( & id. as_str ( ) ) )
9685}
9786
98- const COMMON_RESPONSE_NAMES : Set < & ' static str > = phf_set ! {
99- "s" ,
100- "res" ,
101- "response" ,
102- } ;
87+ const COMMON_RESPONSE_NAMES : [ & str ; 3 ] = [ "s" , "res" , "response" ] ;
10388fn is_res_param ( param : & FormalParameter ) -> bool {
10489 param
10590 . pattern
10691 . get_identifier_name ( )
107- . is_some_and ( |id| COMMON_RESPONSE_NAMES . contains ( id. as_str ( ) ) )
92+ . is_some_and ( |id| COMMON_RESPONSE_NAMES . contains ( & id. as_str ( ) ) )
10893}
10994
110- const COMMON_NEXT_NAMES : Set < & ' static str > = phf_set ! {
111- "n" ,
112- "next" ,
113- } ;
95+ const COMMON_NEXT_NAMES : [ & str ; 2 ] = [ "n" , "next" ] ;
11496fn is_next_param ( param : & FormalParameter ) -> bool {
115- param. pattern . get_identifier_name ( ) . is_some_and ( |id| COMMON_NEXT_NAMES . contains ( id. as_str ( ) ) )
97+ param. pattern . get_identifier_name ( ) . is_some_and ( |id| COMMON_NEXT_NAMES . contains ( & id. as_str ( ) ) )
11698}
11799
118- const COMMON_ERROR_NAMES : Set < & ' static str > = phf_set ! {
119- "e" ,
120- "err" ,
121- "error" ,
122- "exception" ,
123- } ;
100+ const COMMON_ERROR_NAMES : [ & str ; 4 ] = [ "e" , "err" , "error" , "exception" ] ;
124101fn is_error_param ( param : & FormalParameter ) -> bool {
125- param. pattern . get_identifier_name ( ) . is_some_and ( |id| COMMON_ERROR_NAMES . contains ( id. as_str ( ) ) )
102+ param. pattern . get_identifier_name ( ) . is_some_and ( |id| COMMON_ERROR_NAMES . contains ( & id. as_str ( ) ) )
126103}
0 commit comments