@@ -87,21 +87,12 @@ impl Rule for PreferObjectHasOwn {
8787 ctx. diagnostic ( diagnostic) ;
8888 } else {
8989 ctx. diagnostic_with_fix ( diagnostic, |fixer| {
90- let before_token_of_replace_span = if replace_target_span. start > 1 {
91- Some ( ctx. source_range ( Span :: new (
92- replace_target_span. start - 1 ,
93- replace_target_span. start ,
94- ) ) )
95- } else {
96- None
97- } ;
98- let replacement = match before_token_of_replace_span {
99- Some ( token) => match token {
100- " " | "=" | "/" | "(" => "Object.hasOwn" ,
101- _ => " Object.hasOwn" ,
102- } ,
103- _ => "Object.hasOwn" ,
104- } ;
90+ let needs_space = replace_target_span. start > 1
91+ && !ctx
92+ . source_range ( Span :: new ( 0 , replace_target_span. start ) )
93+ . ends_with ( & [ ' ' , '=' , '/' , '(' ] ) ;
94+
95+ let replacement = if needs_space { " Object.hasOwn" } else { "Object.hasOwn" } ;
10596 fixer. replace ( replace_target_span, replacement)
10697 } ) ;
10798 }
@@ -238,6 +229,8 @@ fn test() {
238229 "Object[`hasOwnProperty`][`call`](object, property);" ,
239230 "({})['hasOwnProperty']['call'](object, property);" ,
240231 "({})[`hasOwnProperty`][`call`](object, property);" ,
232+ // Issue: <https://github.com/oxc-project/oxc/issues/7450>
233+ "
Object.prototype.hasOwnProperty.call(C,x);" ,
241234 ] ;
242235
243236 let fix = vec ! [
@@ -385,6 +378,8 @@ fn test() {
385378 "Object.hasOwn(object, property);" ,
386379 None ,
387380 ) ,
381+ // Issue: <https://github.com/oxc-project/oxc/issues/7450>
382+ ( "
Object.prototype.hasOwnProperty.call(C,x);" , "
Object.hasOwn(C,x);" , None ) ,
388383 ] ;
389384 Tester :: new ( PreferObjectHasOwn :: NAME , pass, fail) . expect_fix ( fix) . test_and_snapshot ( ) ;
390385}
0 commit comments