@samitouri / QOS-React-2 / commits / 2c9fef32db

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

Behnam Mohammadi committed Apr 1, 2021 at 20:35 UTC 2c9fef32db5c9a342a1a60c34217ffc9ae087fbb
15 files changed +29 -25
packages/react-dom/src/client/ReactDOMComponent.js
+2 -1
@@ -13,6 +13,7 @@ import {
13 } from '../events/EventRegistry';
14
15 import {canUseDOM} from 'shared/ExecutionEnvironment';
16 +import hasOwnProperty from 'shared/hasOwnProperty';
17
18 import {
19 getValueForAttribute,
@@ -443,7 +444,7 @@ export function createElement(
444 !isCustomComponentTag &&
445 Object.prototype.toString.call(domElement) ===
446 '[object HTMLUnknownElement]' &&
446 - !Object.prototype.hasOwnProperty.call(warnedUnknownTags, type)
447 + !hasOwnProperty.call(warnedUnknownTags, type)
448 ) {
449 warnedUnknownTags[type] = true;
450 console.error(
packages/react-dom/src/server/ReactDOMServerFormatConfig.js
+1 -1
@@ -44,9 +44,9 @@ import warnValidStyle from '../shared/warnValidStyle';
44 import escapeTextForBrowser from './escapeTextForBrowser';
45 import hyphenateStyleName from '../shared/hyphenateStyleName';
46 import invariant from 'shared/invariant';
47 +import hasOwnProperty from 'shared/hasOwnProperty';
48 import sanitizeURL from '../shared/sanitizeURL';
49
49 -const hasOwnProperty = Object.prototype.hasOwnProperty;
50 const isArray = Array.isArray;
51
52 // Per response, global state that is not contextual to the rendering subtree.
packages/react-dom/src/server/ReactPartialRenderer.js
+1 -1
@@ -77,6 +77,7 @@ import warnValidStyle from '../shared/warnValidStyle';
77 import {validateProperties as validateARIAProperties} from '../shared/ReactDOMInvalidARIAHook';
78 import {validateProperties as validateInputProperties} from '../shared/ReactDOMNullInputValuePropHook';
79 import {validateProperties as validateUnknownProperties} from '../shared/ReactDOMUnknownPropertyHook';
80 +import hasOwnProperty from 'shared/hasOwnProperty';
81
82 export type ServerOptions = {
83 identifierPrefix?: string,
@@ -340,7 +341,6 @@ function flattenOptionChildren(children: mixed): ?string {
341 return content;
342 }
343
343 -const hasOwnProperty = Object.prototype.hasOwnProperty;
344 const STYLE = 'style';
345 const RESERVED_PROPS = {
346 children: null,
packages/react-dom/src/shared/DOMProperty.js
+1 -1
@@ -8,6 +8,7 @@
8 */
9
10 import {enableFilterEmptyStringAttributesDOM} from 'shared/ReactFeatureFlags';
11 +import hasOwnProperty from 'shared/hasOwnProperty';
12
13 type PropertyType = 0 | 1 | 2 | 3 | 4 | 5 | 6;
14
@@ -67,7 +68,6 @@ export const VALID_ATTRIBUTE_NAME_REGEX = new RegExp(
68 '^[' + ATTRIBUTE_NAME_START_CHAR + '][' + ATTRIBUTE_NAME_CHAR + ']*$',
69 );
70
70 -const hasOwnProperty = Object.prototype.hasOwnProperty;
71 const illegalAttributeNameCache = {};
72 const validatedAttributeNameCache = {};
73
packages/react-dom/src/shared/ReactDOMInvalidARIAHook.js
+1 -2
@@ -8,13 +8,12 @@
8 import {ATTRIBUTE_NAME_CHAR} from './DOMProperty';
9 import isCustomComponent from './isCustomComponent';
10 import validAriaProperties from './validAriaProperties';
11 +import hasOwnProperty from 'shared/hasOwnProperty';
12
13 const warnedProperties = {};
14 const rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
15 const rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
16
16 -const hasOwnProperty = Object.prototype.hasOwnProperty;
17 -
17 function validateProperty(tagName, name) {
18 if (__DEV__) {
19 if (hasOwnProperty.call(warnedProperties, name) && warnedProperties[name]) {
packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js
+1 -1
@@ -14,12 +14,12 @@ import {
14 } from './DOMProperty';
15 import isCustomComponent from './isCustomComponent';
16 import possibleStandardNames from './possibleStandardNames';
17 +import hasOwnProperty from 'shared/hasOwnProperty';
18
19 let validateProperty = () => {};
20
21 if (__DEV__) {
22 const warnedProperties = {};
22 - const hasOwnProperty = Object.prototype.hasOwnProperty;
23 const EVENT_NAME_REGEX = /^on./;
24 const INVALID_EVENT_NAME_REGEX = /^on[^A-Z]/;
25 const rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
packages/react-server-dom-relay/src/ReactFlightDOMRelayServerHostConfig.js
+2 -2
@@ -13,6 +13,8 @@ import type {Request, ReactModel} from 'react-server/src/ReactFlightServer';
13
14 import JSResourceReference from 'JSResourceReference';
15
16 +import hasOwnProperty from 'shared/hasOwnProperty';
17 +
18 export type ModuleReference<T> = JSResourceReference<T>;
19
20 import type {
@@ -72,8 +74,6 @@ export function processErrorChunk(
74 ];
75 }
76
75 -const hasOwnProperty = Object.prototype.hasOwnProperty;
76 -
77 function convertModelToJSON(
78 request: Request,
79 parent: {+[key: string]: ReactModel} | $ReadOnlyArray<ReactModel>,
packages/react-server-native-relay/src/ReactFlightNativeRelayServerHostConfig.js
+1 -3
@@ -10,7 +10,7 @@
10 import type {RowEncoding, JSONValue} from './ReactFlightNativeRelayProtocol';
11
12 import type {Request, ReactModel} from 'react-server/src/ReactFlightServer';
13 -
13 +import hasOwnProperty from 'shared/hasOwnProperty';
14 import JSResourceReferenceImpl from 'JSResourceReferenceImpl';
15
16 export type ModuleReference<T> = JSResourceReferenceImpl<T>;
@@ -72,8 +72,6 @@ export function processErrorChunk(
72 ];
73 }
74
75 -const hasOwnProperty = Object.prototype.hasOwnProperty;
76 -
75 function convertModelToJSON(
76 request: Request,
77 parent: {+[key: string]: ReactModel} | $ReadOnlyArray<ReactModel>,
packages/react/src/ReactElement.js
+1 -2
@@ -8,11 +8,10 @@
8 import getComponentNameFromType from 'shared/getComponentNameFromType';
9 import invariant from 'shared/invariant';
10 import {REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
11 +import hasOwnProperty from 'shared/hasOwnProperty';
12
13 import ReactCurrentOwner from './ReactCurrentOwner';
14
14 -const hasOwnProperty = Object.prototype.hasOwnProperty;
15 -
15 const RESERVED_PROPS = {
16 key: true,
17 ref: true,
packages/react/src/ReactElementValidator.js
+1 -2
@@ -33,6 +33,7 @@ import {
33 } from './ReactElement';
34 import {setExtraStackFrame} from './ReactDebugCurrentFrame';
35 import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
36 +import hasOwnProperty from 'shared/hasOwnProperty';
37
38 function setCurrentlyValidatingElement(element) {
39 if (__DEV__) {
@@ -56,8 +57,6 @@ if (__DEV__) {
57 propTypesMisspellWarningShown = false;
58 }
59
59 -const hasOwnProperty = Object.prototype.hasOwnProperty;
60 -
60 function getDeclarationErrorAddendum() {
61 if (ReactCurrentOwner.current) {
62 const name = getComponentNameFromType(ReactCurrentOwner.current.type);
packages/react/src/jsx/ReactJSXElement.js
+1 -3
@@ -7,13 +7,11 @@
7
8 import getComponentNameFromType from 'shared/getComponentNameFromType';
9 import ReactSharedInternals from 'shared/ReactSharedInternals';
10 -
10 +import hasOwnProperty from 'shared/hasOwnProperty';
11 import {REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
12
13 const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
14
15 -const hasOwnProperty = Object.prototype.hasOwnProperty;
16 -
15 const RESERVED_PROPS = {
16 key: true,
17 ref: true,
packages/react/src/jsx/ReactJSXElementValidator.js
+1 -3
@@ -22,7 +22,7 @@ import {
22 REACT_ELEMENT_TYPE,
23 } from 'shared/ReactSymbols';
24 import {warnAboutSpreadingKeyToJSX} from 'shared/ReactFeatureFlags';
25 -
25 +import hasOwnProperty from 'shared/hasOwnProperty';
26 import {jsxDEV} from './ReactJSXElement';
27
28 import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
@@ -54,8 +54,6 @@ if (__DEV__) {
54 propTypesMisspellWarningShown = false;
55 }
56
57 -const hasOwnProperty = Object.prototype.hasOwnProperty;
58 -
57 /**
58 * Verifies the object is a ReactElement.
59 * See https://reactjs.org/docs/react-api.html#isvalidelement
packages/shared/checkPropTypes.js
+2 -1
@@ -12,6 +12,7 @@ const loggedTypeFailures = {};
12 import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
13
14 import ReactSharedInternals from 'shared/ReactSharedInternals';
15 +import hasOwnProperty from 'shared/hasOwnProperty';
16
17 const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
18
@@ -40,7 +41,7 @@ export default function checkPropTypes(
41 ): void {
42 if (__DEV__) {
43 // $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);
45 for (const typeSpecName in typeSpecs) {
46 if (has(typeSpecs, typeSpecName)) {
47 let error;
packages/shared/hasOwnProperty.js new
+12
@@ -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
+1 -2
@@ -8,8 +8,7 @@
8 */
9
10 import is from './objectIs';
11 -
12 -const hasOwnProperty = Object.prototype.hasOwnProperty;
11 +import hasOwnProperty from './hasOwnProperty';
12
13 /**
14 * Performs equality by iterating through keys on an object and returning false