Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed an internal hasOwnProperty to hasOwn. This avoids problems in CommonJS environments when the consumer tries to prevent prototype pollution with Object.freeze(Object.prototype).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eh, this was meant to be a code suggestion and not a regular comment 😅

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