Skip to content

Refactor: Use centralized hasOwnProperty utility functions#583

Open
everettbu wants to merge 1 commit into
mainfrom
refactor/use-hasOwnProperty-utility
Open

Refactor: Use centralized hasOwnProperty utility functions#583
everettbu wants to merge 1 commit into
mainfrom
refactor/use-hasOwnProperty-utility

Conversation

@everettbu

Copy link
Copy Markdown

Mirror of facebook/react#35864
Original author: behnammodi


Summary

Overview

This PR refactors property checking throughout the codebase to use centralized hasOwnProperty utility functions instead of directly accessing Object.prototype.hasOwnProperty.

Changes

  • compiler/packages/babel-plugin-react-compiler/src/Utils/ComponentDeclaration.ts: Import hasOwnProperty from ./utils
  • compiler/packages/babel-plugin-react-compiler/src/Utils/HookDeclaration.ts: Import hasOwnProperty from ./utils
  • packages/react-devtools-shared/src/devtools/views/utils.js: Import hasOwnProperty from shared/hasOwnProperty instead of defining locally

How did you test this change?

yarn test --prod

@everettbu
everettbu marked this pull request as ready for review February 22, 2026 18:17
@greptile-apps

greptile-apps Bot commented Feb 22, 2026

Copy link
Copy Markdown

Greptile Summary

This PR replaces direct Object.prototype.hasOwnProperty usage with centralized utility imports across three files.

  • Compiler files (ComponentDeclaration.ts, HookDeclaration.ts): Replace Object.prototype.hasOwnProperty.call(node, key) with the typed hasOwnProperty(node, key) wrapper already defined in ./utils.ts, which provides TypeScript type narrowing (key is keyof T) while calling the same underlying method.
  • DevTools file (utils.js): Replaces a locally-defined const hasOwnProperty = Object.prototype.hasOwnProperty with an import from shared/hasOwnProperty, which exports the identical value. The existing .call() usage pattern is preserved.

All changes are functionally equivalent with no behavioral impact. This aligns the codebase with its existing centralized utility patterns and reduces code duplication.

Confidence Score: 5/5

  • This PR is safe to merge — all changes are purely mechanical refactors with no behavioral impact.
  • All three changes replace inline Object.prototype.hasOwnProperty usage with imports of functionally identical centralized utilities. The compiler wrapper calls the same underlying method, and the devtools import exports the same value that was previously defined locally. No logic, control flow, or behavior is altered.
  • No files require special attention.

Important Files Changed

Filename Overview
compiler/packages/babel-plugin-react-compiler/src/Utils/ComponentDeclaration.ts Replaces direct Object.prototype.hasOwnProperty.call() with the typed hasOwnProperty wrapper from ./utils, which internally does the same thing but adds TypeScript type narrowing. Functionally equivalent, no issues.
compiler/packages/babel-plugin-react-compiler/src/Utils/HookDeclaration.ts Same refactoring as ComponentDeclaration.ts — replaces direct Object.prototype.hasOwnProperty.call() with the typed hasOwnProperty wrapper from ./utils. Functionally equivalent, no issues.
packages/react-devtools-shared/src/devtools/views/utils.js Replaces locally-defined const hasOwnProperty = Object.prototype.hasOwnProperty with an import from shared/hasOwnProperty, which exports the exact same value. The single usage at line 98 correctly continues to use .call(). No behavioral change.

Last reviewed commit: 2434b99

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants