Skip to content

Commit

Permalink
Remove redundant initial of hasOwnProperty (facebook#21134)
Browse files Browse the repository at this point in the history
* remove redundant initial of hasOwnProperty

* remove redundant initial of hasOwnProperty part 2

* remove redundant initial of hasOwnProperty part 3
  • Loading branch information
behnammodi authored and koto committed Jun 15, 2021
1 parent 1d2c8ec commit e25e50b
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 25 deletions.
3 changes: 2 additions & 1 deletion packages/react-dom/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from '../events/EventRegistry';

import {canUseDOM} from 'shared/ExecutionEnvironment';
import hasOwnProperty from 'shared/hasOwnProperty';

import {
getValueForAttribute,
Expand Down Expand Up @@ -443,7 +444,7 @@ export function createElement(
!isCustomComponentTag &&
Object.prototype.toString.call(domElement) ===
'[object HTMLUnknownElement]' &&
!Object.prototype.hasOwnProperty.call(warnedUnknownTags, type)
!hasOwnProperty.call(warnedUnknownTags, type)
) {
warnedUnknownTags[type] = true;
console.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ import warnValidStyle from '../shared/warnValidStyle';
import escapeTextForBrowser from './escapeTextForBrowser';
import hyphenateStyleName from '../shared/hyphenateStyleName';
import invariant from 'shared/invariant';
import hasOwnProperty from 'shared/hasOwnProperty';
import sanitizeURL from '../shared/sanitizeURL';

const hasOwnProperty = Object.prototype.hasOwnProperty;
const isArray = Array.isArray;

// Per response, global state that is not contextual to the rendering subtree.
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import warnValidStyle from '../shared/warnValidStyle';
import {validateProperties as validateARIAProperties} from '../shared/ReactDOMInvalidARIAHook';
import {validateProperties as validateInputProperties} from '../shared/ReactDOMNullInputValuePropHook';
import {validateProperties as validateUnknownProperties} from '../shared/ReactDOMUnknownPropertyHook';
import hasOwnProperty from 'shared/hasOwnProperty';

export type ServerOptions = {
identifierPrefix?: string,
Expand Down Expand Up @@ -340,7 +341,6 @@ function flattenOptionChildren(children: mixed): ?string {
return content;
}

const hasOwnProperty = Object.prototype.hasOwnProperty;
const STYLE = 'style';
const RESERVED_PROPS = {
children: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/shared/DOMProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/

import {enableFilterEmptyStringAttributesDOM} from 'shared/ReactFeatureFlags';
import hasOwnProperty from 'shared/hasOwnProperty';

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

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

const hasOwnProperty = Object.prototype.hasOwnProperty;
const illegalAttributeNameCache = {};
const validatedAttributeNameCache = {};

Expand Down
3 changes: 1 addition & 2 deletions packages/react-dom/src/shared/ReactDOMInvalidARIAHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
import {ATTRIBUTE_NAME_CHAR} from './DOMProperty';
import isCustomComponent from './isCustomComponent';
import validAriaProperties from './validAriaProperties';
import hasOwnProperty from 'shared/hasOwnProperty';

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

const hasOwnProperty = Object.prototype.hasOwnProperty;

function validateProperty(tagName, name) {
if (__DEV__) {
if (hasOwnProperty.call(warnedProperties, name) && warnedProperties[name]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import {
} from './DOMProperty';
import isCustomComponent from './isCustomComponent';
import possibleStandardNames from './possibleStandardNames';
import hasOwnProperty from 'shared/hasOwnProperty';

let validateProperty = () => {};

if (__DEV__) {
const warnedProperties = {};
const hasOwnProperty = Object.prototype.hasOwnProperty;
const EVENT_NAME_REGEX = /^on./;
const INVALID_EVENT_NAME_REGEX = /^on[^A-Z]/;
const rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import type {Request, ReactModel} from 'react-server/src/ReactFlightServer';

import JSResourceReference from 'JSResourceReference';

import hasOwnProperty from 'shared/hasOwnProperty';

export type ModuleReference<T> = JSResourceReference<T>;

import type {
Expand Down Expand Up @@ -72,8 +74,6 @@ export function processErrorChunk(
];
}

const hasOwnProperty = Object.prototype.hasOwnProperty;

function convertModelToJSON(
request: Request,
parent: {+[key: string]: ReactModel} | $ReadOnlyArray<ReactModel>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import type {RowEncoding, JSONValue} from './ReactFlightNativeRelayProtocol';

import type {Request, ReactModel} from 'react-server/src/ReactFlightServer';

import hasOwnProperty from 'shared/hasOwnProperty';
import JSResourceReferenceImpl from 'JSResourceReferenceImpl';

export type ModuleReference<T> = JSResourceReferenceImpl<T>;
Expand Down Expand Up @@ -72,8 +72,6 @@ export function processErrorChunk(
];
}

const hasOwnProperty = Object.prototype.hasOwnProperty;

function convertModelToJSON(
request: Request,
parent: {+[key: string]: ReactModel} | $ReadOnlyArray<ReactModel>,
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/ReactElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import getComponentNameFromType from 'shared/getComponentNameFromType';
import invariant from 'shared/invariant';
import {REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';
import hasOwnProperty from 'shared/hasOwnProperty';

import ReactCurrentOwner from './ReactCurrentOwner';

const hasOwnProperty = Object.prototype.hasOwnProperty;

const RESERVED_PROPS = {
key: true,
ref: true,
Expand Down
3 changes: 1 addition & 2 deletions packages/react/src/ReactElementValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from './ReactElement';
import {setExtraStackFrame} from './ReactDebugCurrentFrame';
import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
import hasOwnProperty from 'shared/hasOwnProperty';

function setCurrentlyValidatingElement(element) {
if (__DEV__) {
Expand All @@ -56,8 +57,6 @@ if (__DEV__) {
propTypesMisspellWarningShown = false;
}

const hasOwnProperty = Object.prototype.hasOwnProperty;

function getDeclarationErrorAddendum() {
if (ReactCurrentOwner.current) {
const name = getComponentNameFromType(ReactCurrentOwner.current.type);
Expand Down
4 changes: 1 addition & 3 deletions packages/react/src/jsx/ReactJSXElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

import getComponentNameFromType from 'shared/getComponentNameFromType';
import ReactSharedInternals from 'shared/ReactSharedInternals';

import hasOwnProperty from 'shared/hasOwnProperty';
import {REACT_ELEMENT_TYPE} from 'shared/ReactSymbols';

const ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;

const hasOwnProperty = Object.prototype.hasOwnProperty;

const RESERVED_PROPS = {
key: true,
ref: true,
Expand Down
4 changes: 1 addition & 3 deletions packages/react/src/jsx/ReactJSXElementValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
REACT_ELEMENT_TYPE,
} from 'shared/ReactSymbols';
import {warnAboutSpreadingKeyToJSX} from 'shared/ReactFeatureFlags';

import hasOwnProperty from 'shared/hasOwnProperty';
import {jsxDEV} from './ReactJSXElement';

import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';
Expand Down Expand Up @@ -54,8 +54,6 @@ if (__DEV__) {
propTypesMisspellWarningShown = false;
}

const hasOwnProperty = Object.prototype.hasOwnProperty;

/**
* Verifies the object is a ReactElement.
* See https://reactjs.org/docs/react-api.html#isvalidelement
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/checkPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const loggedTypeFailures = {};
import {describeUnknownElementTypeFrameInDEV} from 'shared/ReactComponentStackFrame';

import ReactSharedInternals from 'shared/ReactSharedInternals';
import hasOwnProperty from 'shared/hasOwnProperty';

const ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;

Expand Down Expand Up @@ -40,7 +41,7 @@ export default function checkPropTypes(
): void {
if (__DEV__) {
// $FlowFixMe This is okay but Flow doesn't know it.
const has = Function.call.bind(Object.prototype.hasOwnProperty);
const has = Function.call.bind(hasOwnProperty);
for (const typeSpecName in typeSpecs) {
if (has(typeSpecs, typeSpecName)) {
let error;
Expand Down
12 changes: 12 additions & 0 deletions packages/shared/hasOwnProperty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/

const hasOwnProperty = Object.prototype.hasOwnProperty;

export default hasOwnProperty;
3 changes: 1 addition & 2 deletions packages/shared/shallowEqual.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
*/

import is from './objectIs';

const hasOwnProperty = Object.prototype.hasOwnProperty;
import hasOwnProperty from './hasOwnProperty';

/**
* Performs equality by iterating through keys on an object and returning false
Expand Down

0 comments on commit e25e50b

Please sign in to comment.