From eb6dd8e6e9268878f2eafa5a3ae0ec0e5f3d0461 Mon Sep 17 00:00:00 2001 From: Marin Atanasov <8436925+tyxla@users.noreply.github.com> Date: Fri, 24 Jun 2022 10:21:52 +0300 Subject: [PATCH] Lodash: Remove most of it from element package (#41903) --- packages/element/src/serialize.js | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/element/src/serialize.js b/packages/element/src/serialize.js index b3636f2a9eb078..ba23e5f364255a 100644 --- a/packages/element/src/serialize.js +++ b/packages/element/src/serialize.js @@ -28,14 +28,7 @@ /** * External dependencies */ -import { - isEmpty, - castArray, - omit, - startsWith, - kebabCase, - isPlainObject, -} from 'lodash'; +import { kebabCase, isPlainObject } from 'lodash'; /** * WordPress dependencies @@ -508,7 +501,7 @@ function getNormalAttributeName( attribute ) { * @return {string} Normalized property name. */ function getNormalStylePropertyName( property ) { - if ( startsWith( property, '--' ) ) { + if ( property.startsWith( '--' ) ) { return property; } @@ -579,7 +572,7 @@ export function renderElement( element, context, legacyContext = {} ) { const { children, ...wrapperProps } = props; return renderNativeComponent( - isEmpty( wrapperProps ) ? null : 'div', + ! Object.keys( wrapperProps ).length ? null : 'div', { ...wrapperProps, dangerouslySetInnerHTML: { __html: children }, @@ -653,7 +646,9 @@ export function renderNativeComponent( // place of children. Ensure to omit so it is not assigned as attribute // as well. content = renderChildren( props.value, context, legacyContext ); - props = omit( props, 'value' ); + // eslint-disable-next-line no-unused-vars + const { value, ...restProps } = props; + props = restProps; } else if ( props.dangerouslySetInnerHTML && typeof props.dangerouslySetInnerHTML.__html === 'string' @@ -731,7 +726,7 @@ export function renderComponent( function renderChildren( children, context, legacyContext = {} ) { let result = ''; - children = castArray( children ); + children = Array.isArray( children ) ? children : [ children ]; for ( let i = 0; i < children.length; i++ ) { const child = children[ i ];