Skip to content

Commit

Permalink
jsx: Remove unnecessary hasOwnProperty check (#28775)
Browse files Browse the repository at this point in the history
Follow up to #28768.

The modern JSX runtime (`jsx`) does not need to check if each prop is a
direct property with `hasOwnProperty` because the compiler always passes
a plain object.

I'll leave the check in the old JSX runtime (`createElement`) since that
one can be called manually with any kind of object, and if there were
old user code that relied on this for some reason, it would be using
that runtime.

DiffTrain build for commit 0b3b8a6.
  • Loading branch information
acdlite committed Apr 8, 2024
1 parent 86065f6 commit 38b5f5d
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<ec56b30d76b5a69544373d710da9f9aa>>
* @generated SignedSource<<89ab70059fbd85b63bf80748a754cb73>>
*/

"use strict";
Expand Down Expand Up @@ -1327,11 +1327,8 @@ if (__DEV__) {
props = {};

for (var propName in config) {
if (
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" &&
propName !== "ref"
) {
// Skip over reserved prop names
if (propName !== "key" && propName !== "ref") {
{
props[propName] = config[propName];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<f9829995214271eca2ce345a7f2da74a>>
* @generated SignedSource<<793e5defde71fd400afe9a6583a3e6cb>>
*/

"use strict";
Expand Down Expand Up @@ -1363,11 +1363,8 @@ if (__DEV__) {
props = {};

for (var propName in config) {
if (
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" &&
propName !== "ref"
) {
// Skip over reserved prop names
if (propName !== "key" && propName !== "ref") {
{
props[propName] = config[propName];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<d24a690e1d6994ec3438bae6ba3ca710>>
* @generated SignedSource<<8e9fc6c30cb3a1a336d8532aee527031>>
*/

"use strict";
Expand All @@ -32,7 +32,6 @@ function formatProdErrorMessage(code) {
}
var disableDefaultPropsExceptForClasses =
dynamicFlagsUntyped.disableDefaultPropsExceptForClasses,
hasOwnProperty = Object.prototype.hasOwnProperty,
ReactCurrentOwner =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner;
function jsxProd(type, config, maybeKey) {
Expand All @@ -54,8 +53,7 @@ function jsxProd(type, config, maybeKey) {
}
maybeKey = {};
for (var propName in config)
hasOwnProperty.call(config, propName) &&
"key" !== propName &&
"key" !== propName &&
"ref" !== propName &&
(maybeKey[propName] = config[propName]);
if (!disableDefaultPropsExceptForClasses && type && type.defaultProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<d24a690e1d6994ec3438bae6ba3ca710>>
* @generated SignedSource<<8e9fc6c30cb3a1a336d8532aee527031>>
*/

"use strict";
Expand All @@ -32,7 +32,6 @@ function formatProdErrorMessage(code) {
}
var disableDefaultPropsExceptForClasses =
dynamicFlagsUntyped.disableDefaultPropsExceptForClasses,
hasOwnProperty = Object.prototype.hasOwnProperty,
ReactCurrentOwner =
React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner;
function jsxProd(type, config, maybeKey) {
Expand All @@ -54,8 +53,7 @@ function jsxProd(type, config, maybeKey) {
}
maybeKey = {};
for (var propName in config)
hasOwnProperty.call(config, propName) &&
"key" !== propName &&
"key" !== propName &&
"ref" !== propName &&
(maybeKey[propName] = config[propName]);
if (!disableDefaultPropsExceptForClasses && type && type.defaultProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<c641be89261f73fa6d57361dd219a15d>>
* @generated SignedSource<<0301515ac101d5b3682c687183627ea7>>
*/

"use strict";
Expand All @@ -26,7 +26,7 @@ if (__DEV__) {
}
var dynamicFlagsUntyped = require("ReactNativeInternalFeatureFlags");

var ReactVersion = "19.0.0-canary-33300bbd";
var ReactVersion = "19.0.0-canary-91afb935";

// ATTENTION
// When adding new symbols to this file,
Expand Down Expand Up @@ -1749,11 +1749,8 @@ if (__DEV__) {
props = {};

for (var propName in config) {
if (
hasOwnProperty.call(config, propName) && // Skip over reserved prop names
propName !== "key" &&
propName !== "ref"
) {
// Skip over reserved prop names
if (propName !== "key" && propName !== "ref") {
{
props[propName] = config[propName];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<c127deb722db5c1322641d4b8f8d0b01>>
* @generated SignedSource<<68b673436655d580c5a9bcf2c90d6d00>>
*/

"use strict";
Expand Down Expand Up @@ -117,8 +117,7 @@ function jsxProd(type, config, maybeKey) {
(ref = coerceStringRef(ref, ReactCurrentOwner.current, type)));
maybeKey = {};
for (var propName in config)
hasOwnProperty.call(config, propName) &&
"key" !== propName &&
"key" !== propName &&
"ref" !== propName &&
(maybeKey[propName] = config[propName]);
if (!disableDefaultPropsExceptForClasses && type && type.defaultProps) {
Expand Down Expand Up @@ -685,4 +684,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "19.0.0-canary-78482d58";
exports.version = "19.0.0-canary-2d37c214";
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @noflow
* @nolint
* @preventMunge
* @generated SignedSource<<5a164104e95b6f496fecb7036c4b4780>>
* @generated SignedSource<<c327032e795f673af99163be781261f7>>
*/

"use strict";
Expand Down Expand Up @@ -121,8 +121,7 @@ function jsxProd(type, config, maybeKey) {
(ref = coerceStringRef(ref, ReactCurrentOwner.current, type)));
maybeKey = {};
for (var propName in config)
hasOwnProperty.call(config, propName) &&
"key" !== propName &&
"key" !== propName &&
"ref" !== propName &&
(maybeKey[propName] = config[propName]);
if (!disableDefaultPropsExceptForClasses && type && type.defaultProps) {
Expand Down Expand Up @@ -689,7 +688,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactCurrentDispatcher.current.useTransition();
};
exports.version = "19.0.0-canary-cedf8410";
exports.version = "19.0.0-canary-f3e1f261";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d1547defe34cee6326a61059148afc83228d8ecf
0b3b8a6a354b90fe76a9d82bb34487e5d2f71203

0 comments on commit 38b5f5d

Please sign in to comment.