Skip to content

Commit

Permalink
Renamed an internal hasOwnProperty to hasOwn (#3159)
Browse files Browse the repository at this point in the history
* Remove hasOwnProperty from utils

Exported hasOwnProperty conflicts with exports.prototype.hasOwnProperty.
Because it tries to override itself.

* Add changeset

* Add test

* Replace hasOwnProperty with hasOwn

* Update Test

* Remove test

* Add hasOwn into utils as safe replacement for hasOwnProperty

* Remove test

* Remove test

* Map hasOwn to Object.prototype.hasOwnProperty.call

To support old targets

* Prefer simpler notation

* Ok
  • Loading branch information
iegik authored Feb 27, 2024
1 parent 0bfa978 commit 5b82631
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-brooms-sort.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@emotion/react': patch
---

Remove hasOwnProperty from utils
6 changes: 3 additions & 3 deletions packages/react/src/emotion-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
insertStyles,
registerStyles
} from '@emotion/utils'
import { hasOwnProperty, isBrowser } from './utils'
import { hasOwn, isBrowser } from './utils'
import { serializeStyles } from '@emotion/serialize'
import { getLabelFromStackTrace } from './get-label-from-stack-trace'
import { useInsertionEffectAlwaysWithSyncFallback } from '@emotion/use-insertion-effect-with-fallbacks'
Expand All @@ -31,7 +31,7 @@ export const createEmotionProps = (type: React.ElementType, props: Object) => {
let newProps: any = {}

for (let key in props) {
if (hasOwnProperty.call(props, key)) {
if (hasOwn.call(props, key)) {
newProps[key] = props[key]
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ let Emotion = /* #__PURE__ */ withEmotionCache<any, any>(
const newProps = {}
for (let key in props) {
if (
hasOwnProperty.call(props, key) &&
hasOwn.call(props, key) &&
key !== 'css' &&
key !== typePropName &&
(process.env.NODE_ENV === 'production' || key !== labelPropName)
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/jsx-dev-runtime.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import * as ReactJSXRuntimeDev from 'react/jsx-dev-runtime'
import Emotion, { createEmotionProps } from './emotion-element'
import { hasOwnProperty } from './utils'
import { hasOwn } from './utils'

export const Fragment = ReactJSXRuntimeDev.Fragment

Expand All @@ -13,7 +13,7 @@ export function jsxDEV(
source: any,
self: any
) {
if (!hasOwnProperty.call(props, 'css')) {
if (!hasOwn.call(props, 'css')) {
return ReactJSXRuntimeDev.jsxDEV(
type,
props,
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/jsx-runtime.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
// @flow
import * as ReactJSXRuntime from 'react/jsx-runtime'
import Emotion, { createEmotionProps } from './emotion-element'
import { hasOwnProperty } from './utils'
import { hasOwn } from './utils'

export const Fragment = ReactJSXRuntime.Fragment

export function jsx(type: any, props: any, key: any) {
if (!hasOwnProperty.call(props, 'css')) {
if (!hasOwn.call(props, 'css')) {
return ReactJSXRuntime.jsx(type, props, key)
}

return ReactJSXRuntime.jsx(Emotion, createEmotionProps(type, props), key)
}

export function jsxs(type: any, props: any, key: any) {
if (!hasOwnProperty.call(props, 'css')) {
if (!hasOwn.call(props, 'css')) {
return ReactJSXRuntime.jsxs(type, props, key)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/jsx.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import * as React from 'react'
import Emotion, { createEmotionProps } from './emotion-element'
import { hasOwnProperty } from './utils'
import { hasOwn } from './utils'

// $FlowFixMe
export const jsx: typeof React.createElement = function (
Expand All @@ -10,7 +10,7 @@ export const jsx: typeof React.createElement = function (
) {
let args = arguments

if (props == null || !hasOwnProperty.call(props, 'css')) {
if (props == null || !hasOwn.call(props, 'css')) {
// $FlowFixMe
return React.createElement.apply(undefined, args)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @flow
export let isBrowser = typeof document !== 'undefined'

export const hasOwnProperty = {}.hasOwnProperty
export const hasOwn = {}.hasOwnProperty

0 comments on commit 5b82631

Please sign in to comment.