Skip to content

Commit 2c9fef3

Browse files
authored
Remove redundant initial of hasOwnProperty (#21134)
* remove redundant initial of hasOwnProperty * remove redundant initial of hasOwnProperty part 2 * remove redundant initial of hasOwnProperty part 3
1 parent 1cf9978 commit 2c9fef3

15 files changed

+29
-25
lines changed

packages/react-dom/src/client/ReactDOMComponent.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '../events/EventRegistry';
1414

1515
import {canUseDOM} from 'shared/ExecutionEnvironment';
16+
import hasOwnProperty from 'shared/hasOwnProperty';
1617

1718
import {
1819
getValueForAttribute,
@@ -443,7 +444,7 @@ export function createElement(
443444
!isCustomComponentTag &&
444445
Object.prototype.toString.call(domElement) ===
445446
'[object HTMLUnknownElement]' &&
446-
!Object.prototype.hasOwnProperty.call(warnedUnknownTags, type)
447+
!hasOwnProperty.call(warnedUnknownTags, type)
447448
) {
448449
warnedUnknownTags[type] = true;
449450
console.error(

packages/react-dom/src/server/ReactDOMServerFormatConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ import warnValidStyle from '../shared/warnValidStyle';
4444
import escapeTextForBrowser from './escapeTextForBrowser';
4545
import hyphenateStyleName from '../shared/hyphenateStyleName';
4646
import invariant from 'shared/invariant';
47+
import hasOwnProperty from 'shared/hasOwnProperty';
4748
import sanitizeURL from '../shared/sanitizeURL';
4849

49-
const hasOwnProperty = Object.prototype.hasOwnProperty;
5050
const isArray = Array.isArray;
5151

5252
// Per response, global state that is not contextual to the rendering subtree.

packages/react-dom/src/server/ReactPartialRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import warnValidStyle from '../shared/warnValidStyle';
7777
import {validateProperties as validateARIAProperties} from '../shared/ReactDOMInvalidARIAHook';
7878
import {validateProperties as validateInputProperties} from '../shared/ReactDOMNullInputValuePropHook';
7979
import {validateProperties as validateUnknownProperties} from '../shared/ReactDOMUnknownPropertyHook';
80+
import hasOwnProperty from 'shared/hasOwnProperty';
8081

8182
export type ServerOptions = {
8283
identifierPrefix?: string,
@@ -340,7 +341,6 @@ function flattenOptionChildren(children: mixed): ?string {
340341
return content;
341342
}
342343

343-
const hasOwnProperty = Object.prototype.hasOwnProperty;
344344
const STYLE = 'style';
345345
const RESERVED_PROPS = {
346346
children: null,

packages/react-dom/src/shared/DOMProperty.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
import {enableFilterEmptyStringAttributesDOM} from 'shared/ReactFeatureFlags';
11+
import hasOwnProperty from 'shared/hasOwnProperty';
1112

1213
type PropertyType = 0 | 1 | 2 | 3 | 4 | 5 | 6;
1314

@@ -67,7 +68,6 @@ export const VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
6768
'^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$',
6869
);
6970

70-
const hasOwnProperty = Object.prototype.hasOwnProperty;
7171
const illegalAttributeNameCache = {};
7272
const validatedAttributeNameCache = {};
7373

packages/react-dom/src/shared/ReactDOMInvalidARIAHook.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
import {ATTRIBUTE_NAME_CHAR} from './DOMProperty';
99
import isCustomComponent from './isCustomComponent';
1010
import validAriaProperties from './validAriaProperties';
11+
import hasOwnProperty from 'shared/hasOwnProperty';
1112

1213
const warnedProperties = {};
1314
const rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
1415
const rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
1516

16-
const hasOwnProperty = Object.prototype.hasOwnProperty;
17-
1817
function validateProperty(tagName, name) {
1918
if (__DEV__) {
2019
if (hasOwnProperty.call(warnedProperties, name) && warnedProperties[name]) {

packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ import {
1414
} from './DOMProperty';
1515
import isCustomComponent from './isCustomComponent';
1616
import possibleStandardNames from './possibleStandardNames';
17+
import hasOwnProperty from 'shared/hasOwnProperty';
1718

1819
let validateProperty = () => {};
1920

2021
if (__DEV__) {
2122
const warnedProperties = {};
22-
const hasOwnProperty = Object.prototype.hasOwnProperty;
2323
const EVENT_NAME_REGEX = /^on./;
2424
const INVALID_EVENT_NAME_REGEX = /^on[^A-Z]/;
2525
const rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');

packages/react-server-dom-relay/src/ReactFlightDOMRelayServerHostConfig.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import type {Request, ReactModel} from 'react-server/src/ReactFlightServer';
1313

1414
import JSResourceReference from 'JSResourceReference';
1515

16+
import hasOwnProperty from 'shared/hasOwnProperty';
17+
1618
export type ModuleReference<T> = JSResourceReference<T>;
1719

1820
import type {
@@ -72,8 +74,6 @@ export function processErrorChunk(
7274
];
7375
}
7476

75-
const hasOwnProperty = Object.prototype.hasOwnProperty;
76-
7777
function convertModelToJSON(
7878
request: Request,
7979
parent: {+[key: string]: ReactModel} | $ReadOnlyArray<ReactModel>,

packages/react-server-native-relay/src/ReactFlightNativeRelayServerHostConfig.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import type {RowEncoding, JSONValue} from './ReactFlightNativeRelayProtocol';
1111

1212
import type {Request, ReactModel} from 'react-server/src/ReactFlightServer';
13-
13+
import hasOwnProperty from 'shared/hasOwnProperty';
1414
import JSResourceReferenceImpl from 'JSResourceReferenceImpl';
1515

1616
export type ModuleReference<T> = JSResourceReferenceImpl<T>;
@@ -72,8 +72,6 @@ export function processErrorChunk(
7272
];
7373
}
7474

75-
const hasOwnProperty = Object.prototype.hasOwnProperty;
76-
7775
function convertModelToJSON(
7876
request: Request,
7977
parent: {+[key: string]: ReactModel} | $ReadOnlyArray<ReactModel>,

packages/react/src/ReactElement.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@
88
import getComponentNameFromType from 'shared/getComponentNameFromType';
99
import invariant from 'shared/invariant';
1010
import {REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
11+
import hasOwnProperty from 'shared/hasOwnProperty';
1112

1213
import ReactCurrentOwner from './ReactCurrentOwner';
1314

14-
const hasOwnProperty = Object.prototype.hasOwnProperty;
15-
1615
const RESERVED_PROPS = {
1716
key: true,
1817
ref: true,

packages/react/src/ReactElementValidator.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
} from './ReactElement';
3434
import {setExtraStackFrame} from './ReactDebugCurrentFrame';
3535
import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
36+
import hasOwnProperty from 'shared/hasOwnProperty';
3637

3738
function setCurrentlyValidatingElement(element) {
3839
if (__DEV__) {
@@ -56,8 +57,6 @@ if (__DEV__) {
5657
propTypesMisspellWarningShown = false;
5758
}
5859

59-
const hasOwnProperty = Object.prototype.hasOwnProperty;
60-
6160
function getDeclarationErrorAddendum() {
6261
if (ReactCurrentOwner.current) {
6362
const name = getComponentNameFromType(ReactCurrentOwner.current.type);

packages/react/src/jsx/ReactJSXElement.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77

88
import getComponentNameFromType from 'shared/getComponentNameFromType';
99
import ReactSharedInternals from 'shared/ReactSharedInternals';
10-
10+
import hasOwnProperty from 'shared/hasOwnProperty';
1111
import {REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
1212

1313
const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
1414

15-
const hasOwnProperty = Object.prototype.hasOwnProperty;
16-
1715
const RESERVED_PROPS = {
1816
key: true,
1917
ref: true,

packages/react/src/jsx/ReactJSXElementValidator.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
REACT_ELEMENT_TYPE,
2323
} from 'shared/ReactSymbols';
2424
import {warnAboutSpreadingKeyToJSX} from 'shared/ReactFeatureFlags';
25-
25+
import hasOwnProperty from 'shared/hasOwnProperty';
2626
import {jsxDEV} from './ReactJSXElement';
2727

2828
import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
@@ -54,8 +54,6 @@ if (__DEV__) {
5454
propTypesMisspellWarningShown = false;
5555
}
5656

57-
const hasOwnProperty = Object.prototype.hasOwnProperty;
58-
5957
/**
6058
* Verifies the object is a ReactElement.
6159
* See https://reactjs.org/docs/react-api.html#isvalidelement

packages/shared/checkPropTypes.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const loggedTypeFailures = {};
1212
import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
1313

1414
import ReactSharedInternals from 'shared/ReactSharedInternals';
15+
import hasOwnProperty from 'shared/hasOwnProperty';
1516

1617
const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
1718

@@ -40,7 +41,7 @@ export default function checkPropTypes(
4041
): void {
4142
if (__DEV__) {
4243
// $FlowFixMe This is okay but Flow doesn't know it.
43-
const has = Function.call.bind(Object.prototype.hasOwnProperty);
44+
const has = Function.call.bind(hasOwnProperty);
4445
for (const typeSpecName in typeSpecs) {
4546
if (has(typeSpecs, typeSpecName)) {
4647
let error;

packages/shared/hasOwnProperty.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow
8+
*/
9+
10+
const hasOwnProperty = Object.prototype.hasOwnProperty;
11+
12+
export default hasOwnProperty;

packages/shared/shallowEqual.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
*/
99

1010
import is from './objectIs';
11-
12-
const hasOwnProperty = Object.prototype.hasOwnProperty;
11+
import hasOwnProperty from './hasOwnProperty';
1312

1413
/**
1514
* Performs equality by iterating through keys on an object and returning false

0 commit comments

Comments
 (0)