Socket
Socket
Sign inDemoInstall

@wordpress/element

Package Overview
Dependencies
Maintainers
14
Versions
168
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/element - npm Package Compare versions

Comparing version 2.10.0 to 2.11.0

6

build-module/platform.android.js

@@ -1,3 +0,7 @@

import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**

@@ -4,0 +8,0 @@ * External dependencies

@@ -1,3 +0,7 @@

import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**

@@ -4,0 +8,0 @@ * External dependencies

@@ -1,4 +0,8 @@

import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**

@@ -5,0 +9,0 @@ * Internal dependencies

@@ -1,4 +0,8 @@

import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**

@@ -5,0 +9,0 @@ * External dependencies

@@ -1,5 +0,9 @@

import _objectSpread from "@babel/runtime/helpers/esm/objectSpread";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import _typeof from "@babel/runtime/helpers/esm/typeof";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**

@@ -6,0 +10,0 @@ * Parts of this source were derived and modified from fast-react-render,

12

build/platform.android.js

@@ -10,10 +10,11 @@ "use strict";

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _reactNative = require("react-native");
/**
* External dependencies
*/
var Platform = (0, _objectSpread2.default)({}, _reactNative.Platform, {
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var Platform = _objectSpread({}, _reactNative.Platform, {
OS: 'native',

@@ -30,4 +31,5 @@ select: function select(spec) {

});
var _default = Platform;
exports.default = _default;
//# sourceMappingURL=platform.android.js.map

@@ -10,10 +10,11 @@ "use strict";

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _reactNative = require("react-native");
/**
* External dependencies
*/
var Platform = (0, _objectSpread2.default)({}, _reactNative.Platform, {
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
var Platform = _objectSpread({}, _reactNative.Platform, {
OS: 'native',

@@ -30,4 +31,5 @@ select: function select(spec) {

});
var _default = Platform;
exports.default = _default;
//# sourceMappingURL=platform.ios.js.map

@@ -10,3 +10,3 @@ "use strict";

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

@@ -17,6 +17,6 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

/**
* Internal dependencies
*/
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**

@@ -39,3 +39,3 @@ * Component used as equivalent of Fragment with unescaped HTML, in cases where

// non-children props present.
return (0, _react.createElement)('div', (0, _objectSpread2.default)({
return (0, _react.createElement)('div', _objectSpread({
dangerouslySetInnerHTML: {

@@ -42,0 +42,0 @@ __html: children

@@ -149,3 +149,3 @@ "use strict";

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

@@ -158,151 +158,7 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

/**
* External dependencies
*/
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
/**
* Object containing a React element.
*
* @typedef {import('react').ReactElement} WPElement
*/
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**
* Object containing a React component.
*
* @typedef {import('react').Component} WPComponent
*/
/**
* Object containing a React synthetic event.
*
* @typedef {import('react').SyntheticEvent} WPSyntheticEvent
*/
/**
* Object that provides utilities for dealing with React children.
*/
/**
* Creates a copy of an element with extended props.
*
* @param {WPElement} element Element
* @param {?Object} props Props to apply to cloned element
*
* @return {WPElement} Cloned element.
*/
/**
* A base class to create WordPress Components (Refs, state and lifecycle hooks)
*/
/**
* Creates a context object containing two components: a provider and consumer.
*
* @param {Object} defaultValue A default data stored in the context.
*
* @return {Object} Context object.
*/
/**
* Returns a new element of given type. Type can be either a string tag name or
* another function which itself returns an element.
*
* @param {?(string|Function)} type Tag name or element creator
* @param {Object} props Element properties, either attribute
* set to apply to DOM node or values to
* pass through to element creator
* @param {...WPElement} children Descendant elements
*
* @return {WPElement} Element.
*/
/**
* Returns an object tracking a reference to a rendered element via its
* `current` property as either a DOMElement or Element, dependent upon the
* type of element rendered with the ref attribute.
*
* @return {Object} Ref object.
*/
/**
* Component enhancer used to enable passing a ref to its wrapped component.
* Pass a function argument which receives `props` and `ref` as its arguments,
* returning an element using the forwarded ref. The return value is a new
* component which forwards its ref.
*
* @param {Function} forwarder Function passed `props` and `ref`, expected to
* return an element.
*
* @return {WPComponent} Enhanced component.
*/
/**
* A component which renders its children without any wrapping element.
*/
/**
* Checks if an object is a valid WPElement.
*
* @param {Object} objectToCheck The object to be checked.
*
* @return {boolean} true if objectToTest is a valid WPElement and false otherwise.
*/
/**
* @see https://reactjs.org/docs/react-api.html#reactmemo
*/
/**
* Component that activates additional checks and warnings for its descendants.
*/
/**
* @see https://reactjs.org/docs/hooks-reference.html#usecallback
*/
/**
* @see https://reactjs.org/docs/hooks-reference.html#usecontext
*/
/**
* @see https://reactjs.org/docs/hooks-reference.html#usedebugvalue
*/
/**
* @see https://reactjs.org/docs/hooks-reference.html#useeffect
*/
/**
* @see https://reactjs.org/docs/hooks-reference.html#useimperativehandle
*/
/**
* @see https://reactjs.org/docs/hooks-reference.html#uselayouteffect
*/
/**
* @see https://reactjs.org/docs/hooks-reference.html#usememo
*/
/**
* @see https://reactjs.org/docs/hooks-reference.html#usereducer
*/
/**
* @see https://reactjs.org/docs/hooks-reference.html#useref
*/
/**
* @see https://reactjs.org/docs/hooks-reference.html#usestate
*/
/**
* @see https://reactjs.org/docs/react-api.html#reactlazy
*/
/**
* @see https://reactjs.org/docs/react-api.html#reactsuspense
*/
/**
* Concatenate two or more React children objects.

@@ -354,3 +210,3 @@ *

props = (0, _objectWithoutProperties2.default)(_elt$props, ["children"]);
return (0, _react.createElement)(nodeName, (0, _objectSpread2.default)({
return (0, _react.createElement)(nodeName, _objectSpread({
key: index

@@ -357,0 +213,0 @@ }, props), childrenProp);

@@ -16,3 +16,3 @@ "use strict";

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

@@ -31,40 +31,6 @@ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

/**
* Parts of this source were derived and modified from fast-react-render,
* released under the MIT license.
*
* https://github.com/alt-j/fast-react-render
*
* Copyright (c) 2016 Andrey Morozov
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
/**
* External dependencies
*/
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**
* WordPress dependencies
*/
/**
* Internal dependencies
*/
var _createContext = (0, _react.createContext)(),

@@ -299,3 +265,3 @@ Provider = _createContext.Provider,

wrapperProps = (0, _objectWithoutProperties2.default)(props, ["children"]);
return renderNativeComponent((0, _lodash.isEmpty)(wrapperProps) ? null : 'div', (0, _objectSpread2.default)({}, wrapperProps, {
return renderNativeComponent((0, _lodash.isEmpty)(wrapperProps) ? null : 'div', _objectSpread({}, wrapperProps, {
dangerouslySetInnerHTML: {

@@ -302,0 +268,0 @@ __html: children

### WordPress - Web publishing software
Copyright 2011-2019 by the contributors
Copyright 2011-2020 by the contributors

@@ -5,0 +5,0 @@ This program is free software; you can redistribute it and/or modify

{
"name": "@wordpress/element",
"version": "2.10.0",
"version": "2.11.0",
"description": "Element React module for WordPress.",

@@ -26,4 +26,4 @@ "author": "The WordPress Contributors",

"dependencies": {
"@babel/runtime": "^7.4.4",
"@wordpress/escape-html": "^1.6.0",
"@babel/runtime": "^7.8.3",
"@wordpress/escape-html": "^1.7.0",
"lodash": "^4.17.15",

@@ -36,3 +36,3 @@ "react": "^16.9.0",

},
"gitHead": "cc8b3fde75738a15c6152d18458eb5078a620cbe"
"gitHead": "41fc84af285da696c65c235331ee245dfe23971d"
}

@@ -6,6 +6,3 @@ /**

let indoc,
offset,
output,
stack;
let indoc, offset, output, stack;

@@ -55,3 +52,3 @@ /**

prevOffset,
leadingTextStart,
leadingTextStart
) {

@@ -129,5 +126,7 @@ return {

const values = isObject && Object.values( conversionMap );
return isObject &&
return (
isObject &&
values.length &&
values.every( ( element ) => isValidElement( element ) );
values.every( ( element ) => isValidElement( element ) )
);
};

@@ -156,3 +155,6 @@

if ( stackDepth !== 0 ) {
const { leadingTextStart: stackLeadingText, tokenStart } = stack.pop();
const {
leadingTextStart: stackLeadingText,
tokenStart,
} = stack.pop();
output.push( indoc.substr( stackLeadingText, tokenStart ) );

@@ -167,3 +169,6 @@ }

output.push(
indoc.substr( leadingTextStart, startOffset - leadingTextStart )
indoc.substr(
leadingTextStart,
startOffset - leadingTextStart
)
);

@@ -217,3 +222,3 @@ }

stackTop.tokenLength,
startOffset + tokenLength,
startOffset + tokenLength
);

@@ -283,3 +288,6 @@ frame.children = stackTop.children;

const parent = stack[ stack.length - 1 ];
const text = indoc.substr( parent.prevOffset, tokenStart - parent.prevOffset );
const text = indoc.substr(
parent.prevOffset,
tokenStart - parent.prevOffset
);

@@ -290,5 +298,3 @@ if ( text ) {

parent.children.push(
cloneElement( element, null, ...children )
);
parent.children.push( cloneElement( element, null, ...children ) );
parent.prevOffset = prevOffset ? prevOffset : tokenStart + tokenLength;

@@ -310,7 +316,13 @@ }

function closeOuterElement( endOffset ) {
const { element, leadingTextStart, prevOffset, tokenStart, children } = stack.pop();
const {
element,
leadingTextStart,
prevOffset,
tokenStart,
children,
} = stack.pop();
const text = endOffset ?
indoc.substr( prevOffset, endOffset - prevOffset ) :
indoc.substr( prevOffset );
const text = endOffset
? indoc.substr( prevOffset, endOffset - prevOffset )
: indoc.substr( prevOffset );

@@ -322,14 +334,10 @@ if ( text ) {

if ( null !== leadingTextStart ) {
output.push( indoc.substr( leadingTextStart, tokenStart - leadingTextStart ) );
output.push(
indoc.substr( leadingTextStart, tokenStart - leadingTextStart )
);
}
output.push(
cloneElement(
element,
null,
...children
)
);
output.push( cloneElement( element, null, ...children ) );
}
export default createInterpolateElement;

@@ -230,9 +230,16 @@ /**

export function switchChildrenNodeName( children, nodeName ) {
return children && Children.map( children, ( elt, index ) => {
if ( isString( elt ) ) {
return createElement( nodeName, { key: index }, elt );
}
const { children: childrenProp, ...props } = elt.props;
return createElement( nodeName, { key: index, ...props }, childrenProp );
} );
return (
children &&
Children.map( children, ( elt, index ) => {
if ( isString( elt ) ) {
return createElement( nodeName, { key: index }, elt );
}
const { children: childrenProp, ...props } = elt.props;
return createElement(
nodeName,
{ key: index, ...props },
childrenProp
);
} )
);
}

@@ -43,3 +43,7 @@ /**

*/
import { escapeHTML, escapeAttribute, isValidAttributeName } from '@wordpress/escape-html';
import {
escapeHTML,
escapeAttribute,
isValidAttributeName,
} from '@wordpress/escape-html';

@@ -49,8 +53,3 @@ /**

*/
import {
createContext,
Fragment,
StrictMode,
forwardRef,
} from './react';
import { createContext, Fragment, StrictMode, forwardRef } from './react';
import RawHTML from './raw-html';

@@ -68,7 +67,3 @@

*/
const ATTRIBUTES_TYPES = new Set( [
'string',
'boolean',
'number',
] );
const ATTRIBUTES_TYPES = new Set( [ 'string', 'boolean', 'number' ] );

@@ -343,4 +338,7 @@ /**

function getNormalStylePropertyValue( property, value ) {
if ( typeof value === 'number' && 0 !== value &&
! CSS_PROPERTIES_SUPPORTS_UNITLESS.has( property ) ) {
if (
typeof value === 'number' &&
0 !== value &&
! CSS_PROPERTIES_SUPPORTS_UNITLESS.has( property )
) {
return value + 'px';

@@ -404,7 +402,14 @@ }

case 'function':
if ( type.prototype && typeof type.prototype.render === 'function' ) {
if (
type.prototype &&
typeof type.prototype.render === 'function'
) {
return renderComponent( type, props, context, legacyContext );
}
return renderElement( type( props, legacyContext ), context, legacyContext );
return renderElement(
type( props, legacyContext ),
context,
legacyContext
);
}

@@ -417,6 +422,14 @@

case Consumer.$$typeof:
return renderElement( props.children( context || type._currentValue ), context, legacyContext );
return renderElement(
props.children( context || type._currentValue ),
context,
legacyContext
);
case ForwardRef.$$typeof:
return renderElement( type.render( props ), context, legacyContext );
return renderElement(
type.render( props ),
context,
legacyContext
);
}

@@ -438,3 +451,8 @@

*/
export function renderNativeComponent( type, props, context, legacyContext = {} ) {
export function renderNativeComponent(
type,
props,
context,
legacyContext = {}
) {
let content = '';

@@ -447,4 +465,6 @@ if ( type === 'textarea' && props.hasOwnProperty( 'value' ) ) {

props = omit( props, 'value' );
} else if ( props.dangerouslySetInnerHTML &&
typeof props.dangerouslySetInnerHTML.__html === 'string' ) {
} else if (
props.dangerouslySetInnerHTML &&
typeof props.dangerouslySetInnerHTML.__html === 'string'
) {
// Dangerous content is left unescaped.

@@ -479,3 +499,8 @@ content = props.dangerouslySetInnerHTML.__html;

*/
export function renderComponent( Component, props, context, legacyContext = {} ) {
export function renderComponent(
Component,
props,
context,
legacyContext = {}
) {
const instance = new Component( props, legacyContext );

@@ -550,7 +575,6 @@

const isMeaningfulAttribute = (
const isMeaningfulAttribute =
isBooleanAttribute ||
hasPrefix( key, [ 'data-', 'aria-' ] ) ||
ENUMERATED_ATTRIBUTES.has( attribute )
);
ENUMERATED_ATTRIBUTES.has( attribute );

@@ -557,0 +581,0 @@ // Only write boolean value as attribute if meaningful.

@@ -15,5 +15,5 @@ /**

const testString = 'This is a string';
expect(
() => createInterpolateElement( testString, {} )
).toThrow( TypeError );
expect( () => createInterpolateElement( testString, {} ) ).toThrow(
TypeError
);
} );

@@ -24,6 +24,3 @@ it( 'returns same string when there are no tokens in the string', () => {

expect(
createInterpolateElement(
testString,
{ someValue: <em /> }
)
createInterpolateElement( testString, { someValue: <em /> } )
).toEqual( expectedElement );

@@ -33,33 +30,35 @@ } );

const testString = 'This is a <someValue/> string';
expect(
() => createInterpolateElement(
testString,
[ 'someValue', { value: 10 } ],
)
expect( () =>
createInterpolateElement( testString, [
'someValue',
{ value: 10 },
] )
).toThrow( TypeError );
} );
it( 'throws an error when there is an invalid entry in the conversion ' +
'map', () => {
const testString = 'This is a <item /> string and <somethingElse/>';
expect(
() => createInterpolateElement(
testString,
{
it(
'throws an error when there is an invalid entry in the conversion ' +
'map',
() => {
const testString = 'This is a <item /> string and <somethingElse/>';
expect( () =>
createInterpolateElement( testString, {
someValue: <em />,
somethingElse: 10,
}
)
).toThrow( TypeError );
} );
it( 'returns same string when there is an non matching token in the ' +
'string', () => {
const testString = 'This is a <non_parsed/> string';
const expectedElement = <>{ testString }</>;
expect(
createInterpolateElement(
testString,
{ someValue: <strong /> }
)
).toEqual( expectedElement );
} );
} )
).toThrow( TypeError );
}
);
it(
'returns same string when there is an non matching token in the ' +
'string',
() => {
const testString = 'This is a <non_parsed/> string';
const expectedElement = <>{ testString }</>;
expect(
createInterpolateElement( testString, {
someValue: <strong />,
} )
).toEqual( expectedElement );
}
);
it( 'returns same string when there is spaces in the token', () => {

@@ -69,6 +68,3 @@ const testString = 'This is a <spaced token/>string';

expect(
createInterpolateElement(
testString,
{ 'spaced token': <em /> }
)
createInterpolateElement( testString, { 'spaced token': <em /> } )
).toEqual( expectedElement );

@@ -89,12 +85,7 @@ } );

);
const component = createInterpolateElement(
testString,
{
// eslint-disable-next-line jsx-a11y/anchor-has-content
a: <a href={ 'https://github.com' } className={ 'some_class' } />,
}
);
expect(
JSON.stringify( component )
).toEqual(
const component = createInterpolateElement( testString, {
// eslint-disable-next-line jsx-a11y/anchor-has-content
a: <a href={ 'https://github.com' } className={ 'some_class' } />,
} );
expect( JSON.stringify( component ) ).toEqual(
JSON.stringify( expectedElement )

@@ -113,41 +104,39 @@ );

'string that is ',
createElement(
'em',
null,
'linked'
),
createElement( 'em', null, 'linked' )
),
'.'
);
expect( JSON.stringify( createInterpolateElement(
testString,
{
a: createElement( 'a' ),
em: <em />,
}
) ) ).toEqual( JSON.stringify( expectedElement ) );
expect(
JSON.stringify(
createInterpolateElement( testString, {
a: createElement( 'a' ),
em: <em />,
} )
)
).toEqual( JSON.stringify( expectedElement ) );
} );
it( 'returns expected output for a custom component with children ' +
'replacement', () => {
const TestComponent = ( props ) => {
return <div { ...props } >{ props.children }</div>;
};
const testString = 'This is a string with a <TestComponent>Custom Component</TestComponent>';
const expectedElement = createElement(
Fragment,
null,
'This is a string with a ',
createElement(
TestComponent,
it(
'returns expected output for a custom component with children ' +
'replacement',
() => {
const TestComponent = ( props ) => {
return <div { ...props }>{ props.children }</div>;
};
const testString =
'This is a string with a <TestComponent>Custom Component</TestComponent>';
const expectedElement = createElement(
Fragment,
null,
'Custom Component'
),
);
expect( JSON.stringify( createInterpolateElement(
testString,
{
TestComponent: <TestComponent />,
}
) ) ).toEqual( JSON.stringify( expectedElement ) );
} );
'This is a string with a ',
createElement( TestComponent, null, 'Custom Component' )
);
expect(
JSON.stringify(
createInterpolateElement( testString, {
TestComponent: <TestComponent />,
} )
)
).toEqual( JSON.stringify( expectedElement ) );
}
);
it( 'returns expected output for self closing custom component', () => {

@@ -157,3 +146,4 @@ const TestComponent = ( props ) => {

};
const testString = 'This is a string with a self closing custom component: <TestComponent/>';
const testString =
'This is a string with a self closing custom component: <TestComponent/>';
const expectedElement = createElement(

@@ -163,15 +153,17 @@ Fragment,

'This is a string with a self closing custom component: ',
createElement( TestComponent ),
createElement( TestComponent )
);
expect( JSON.stringify( createInterpolateElement(
testString,
{
TestComponent: <TestComponent />,
}
) ) ).toEqual( JSON.stringify( expectedElement ) );
expect(
JSON.stringify(
createInterpolateElement( testString, {
TestComponent: <TestComponent />,
} )
)
).toEqual( JSON.stringify( expectedElement ) );
} );
it( 'throws an error with an invalid element in the conversion map', () => {
const test = () => (
createInterpolateElement( 'This is a <invalid /> string', { invalid: 10 } )
);
const test = () =>
createInterpolateElement( 'This is a <invalid /> string', {
invalid: 10,
} );
expect( test ).toThrow( TypeError );

@@ -185,3 +177,4 @@ } );

}
const testString = 'This is a complex string with ' +
const testString =
'This is a complex string with ' +
'a <a1>nested <em1>emphasized string</em1> link</a1> and value: <TestComponent/>';

@@ -196,31 +189,37 @@ const expectedElement = createElement(

'nested ',
createElement(
'em',
null,
'emphasized string'
),
' link',
createElement( 'em', null, 'emphasized string' ),
' link'
),
' and value: ',
createElement( TestComponent ),
createElement( TestComponent )
);
expect( JSON.stringify( createInterpolateElement(
testString,
{
TestComponent: <TestComponent />,
em1: <em />,
a1: createElement( 'a' ),
}
) ) ).toEqual( JSON.stringify( expectedElement ) );
expect(
JSON.stringify(
createInterpolateElement( testString, {
TestComponent: <TestComponent />,
em1: <em />,
a1: createElement( 'a' ),
} )
)
).toEqual( JSON.stringify( expectedElement ) );
} );
it( 'renders expected components across renders for keys in use', () => {
const TestComponent = ( { switchKey } ) => {
const elementConfig = switchKey ? { item: <em /> } : { item: <strong /> };
return <div>
{ createInterpolateElement( 'This is a <item>string!</item>', elementConfig ) }
</div>;
const elementConfig = switchKey
? { item: <em /> }
: { item: <strong /> };
return (
<div>
{ createInterpolateElement(
'This is a <item>string!</item>',
elementConfig
) }
</div>
);
};
let renderer;
act( () => {
renderer = TestRenderer.create( <TestComponent switchKey={ true } /> );
renderer = TestRenderer.create(
<TestComponent switchKey={ true } />
);
} );

@@ -241,16 +240,13 @@ expect( () => renderer.root.findByType( 'em' ) ).not.toThrow();

'👳‍♀️',
createElement(
'strong',
null,
'🚨🤷‍♂️⛈️fully',
),
' here',
createElement( 'strong', null, '🚨🤷‍♂️⛈️fully' ),
' here'
);
expect( JSON.stringify( createInterpolateElement(
testString,
{
icon: <strong />,
}
) ) ).toEqual( JSON.stringify( expectedElement ) );
expect(
JSON.stringify(
createInterpolateElement( testString, {
icon: <strong />,
} )
)
).toEqual( JSON.stringify( expectedElement ) );
} );
} );

@@ -34,27 +34,35 @@ /**

it( 'should return a string from an array', () => {
expect( renderToString( [
'Zucchini ',
createElement( 'em', null, 'is a' ),
' summer squash',
] ) ).toBe( 'Zucchini <em>is a</em> summer squash' );
expect(
renderToString( [
'Zucchini ',
createElement( 'em', null, 'is a' ),
' summer squash',
] )
).toBe( 'Zucchini <em>is a</em> summer squash' );
} );
it( 'should return a string from an element', () => {
expect( renderToString(
createElement( 'strong', null, 'Courgette' )
) ).toBe( '<strong>Courgette</strong>' );
expect(
renderToString( createElement( 'strong', null, 'Courgette' ) )
).toBe( '<strong>Courgette</strong>' );
} );
it( 'should escape attributes and html', () => {
const result = renderToString( createElement( 'a', {
href: '/index.php?foo=bar&qux=<"scary">',
style: {
backgroundColor: 'red',
},
}, '<"WordPress" & Friends>' ) );
const result = renderToString(
createElement(
'a',
{
href: '/index.php?foo=bar&qux=<"scary">',
style: {
backgroundColor: 'red',
},
},
'<"WordPress" & Friends>'
)
);
expect( result ).toBe(
'<a href="/index.php?foo=bar&amp;qux=<&quot;scary&quot;&gt;" style="background-color:red">' +
'&lt;"WordPress" &amp; Friends>' +
'</a>'
'&lt;"WordPress" &amp; Friends>' +
'</a>'
);

@@ -66,5 +74,5 @@ } );

expect( renderToString(
<RawHTML>{ html }</RawHTML>,
) ).toBe( html );
expect( renderToString( <RawHTML>{ html }</RawHTML> ) ).toBe(
html
);
} );

@@ -108,6 +116,9 @@ } );

it( 'should switch elements', () => {
const children = switchChildrenNodeName( [
createElement( 'strong', { align: 'left' }, 'Courgette' ),
createElement( 'strong', {}, 'Concombre' ),
], 'em' );
const children = switchChildrenNodeName(
[
createElement( 'strong', { align: 'left' }, 'Courgette' ),
createElement( 'strong', {}, 'Concombre' ),
],
'em'
);
expect( children ).toHaveLength( 2 );

@@ -114,0 +125,0 @@ expect( children[ 0 ].type ).toBe( 'em' );

@@ -14,7 +14,3 @@ /**

const html = '<p>So scary!</p>';
const element = shallow(
<RawHTML>
{ html }
</RawHTML>
);
const element = shallow( <RawHTML>{ html }</RawHTML> );

@@ -28,7 +24,3 @@ expect( element.type() ).toBe( 'div' );

const html = '<p>So scary!</p>';
const element = shallow(
<RawHTML className="foo">
{ html }
</RawHTML>
);
const element = shallow( <RawHTML className="foo">{ html }</RawHTML> );

@@ -35,0 +27,0 @@ expect( element.type() ).toBe( 'div' );

@@ -29,11 +29,8 @@ /**

it( 'should allow only valid attribute names', () => {
const element = createElement(
'div',
{
'notok\u007F': 'bad',
'notok"': 'bad',
ok: 'good',
'notok\uFDD0': 'bad',
},
);
const element = createElement( 'div', {
'notok\u007F': 'bad',
'notok"': 'bad',
ok: 'good',
'notok\uFDD0': 'bad',
} );

@@ -84,4 +81,3 @@ const result = serialize( element );

expect( result ).toBe(
'FunctionComponent: Hello!' +
'ClassComponent: Hello!'
'FunctionComponent: Hello!' + 'ClassComponent: Hello!'
);

@@ -95,9 +91,5 @@ } );

const result = serialize(
<ForwardedComponent />
);
const result = serialize( <ForwardedComponent /> );
expect( result ).toBe(
'<div>test</div>'
);
expect( result ).toBe( '<div>test</div>' );
} );

@@ -134,3 +126,5 @@

[ false, null, undefined ].forEach( ( controls ) => {
const result = serialize( <video src="/" controls={ controls } /> );
const result = serialize(
<video src="/" controls={ controls } />
);

@@ -143,3 +137,5 @@ expect( result ).toBe( '<video src="/"></video>' );

[ true, 'true', 'false', '' ].forEach( ( controls ) => {
const result = serialize( <video src="/" controls={ controls } /> );
const result = serialize(
<video src="/" controls={ controls } />
);

@@ -269,5 +265,3 @@ expect( result ).toBe( '<video src="/" controls></video>' );

const result = renderElement(
<Consumer>
{ ( context ) => context.value }
</Consumer>
<Consumer>{ ( context ) => context.value }</Consumer>
);

@@ -285,5 +279,3 @@

<Provider value={ { value: 'provided' } }>
<Consumer>
{ ( context ) => context.value }
</Consumer>
<Consumer>{ ( context ) => context.value }</Consumer>
</Provider>

@@ -303,16 +295,10 @@ );

<Provider value={ { value: '1st provided' } }>
<Consumer>
{ ( context ) => context.value }
</Consumer>
<Consumer>{ ( context ) => context.value }</Consumer>
</Provider>
{ '|' }
<Provider value={ { value: '2nd provided' } }>
<Consumer>
{ ( context ) => context.value }
</Consumer>
<Consumer>{ ( context ) => context.value }</Consumer>
</Provider>
{ '|' }
<Consumer>
{ ( context ) => context.value }
</Consumer>
<Consumer>{ ( context ) => context.value }</Consumer>
</Fragment>

@@ -332,10 +318,6 @@ );

<Provider value={ { value: 'inner provided' } }>
<Consumer>
{ ( context ) => context.value }
</Consumer>
<Consumer>{ ( context ) => context.value }</Consumer>
</Provider>
{ '|' }
<Consumer>
{ ( context ) => context.value }
</Consumer>
<Consumer>{ ( context ) => context.value }</Consumer>
</Provider>

@@ -354,3 +336,5 @@ );

it( 'renders RawHTML with wrapper if props passed', () => {
const result = renderElement( <RawHTML className="foo">{ '<img/>' }</RawHTML> );
const result = renderElement(
<RawHTML className="foo">{ '<img/>' }</RawHTML>
);

@@ -376,3 +360,6 @@ expect( result ).toBe( '<div class="foo"><img/></div>' );

it( 'should render textarea value as its content', () => {
const result = renderNativeComponent( 'textarea', { value: 'Hello', children: [] } );
const result = renderNativeComponent( 'textarea', {
value: 'Hello',
children: [],
} );

@@ -383,3 +370,5 @@ expect( result ).toBe( '<textarea>Hello</textarea>' );

it( 'should render textarea children as its content', () => {
const result = renderNativeComponent( 'textarea', { children: [ 'Hello' ] } );
const result = renderNativeComponent( 'textarea', {
children: [ 'Hello' ],
} );

@@ -392,3 +381,5 @@ expect( result ).toBe( '<textarea>Hello</textarea>' );

it( 'should escape children', () => {
const result = renderNativeComponent( 'div', { children: [ '<img/>' ] } );
const result = renderNativeComponent( 'div', {
children: [ '<img/>' ],
} );

@@ -399,3 +390,5 @@ expect( result ).toBe( '<div>&lt;img/></div>' );

it( 'should not render invalid dangerouslySetInnerHTML', () => {
const result = renderNativeComponent( 'div', { dangerouslySetInnerHTML: { __html: undefined } } );
const result = renderNativeComponent( 'div', {
dangerouslySetInnerHTML: { __html: undefined },
} );

@@ -406,3 +399,5 @@ expect( result ).toBe( '<div></div>' );

it( 'should not escape children with dangerouslySetInnerHTML', () => {
const result = renderNativeComponent( 'div', { dangerouslySetInnerHTML: { __html: '<img/>' } } );
const result = renderNativeComponent( 'div', {
dangerouslySetInnerHTML: { __html: '<img/>' },
} );

@@ -421,3 +416,6 @@ expect( result ).toBe( '<div><img/></div>' );

it( 'should ignore self-closing elements children', () => {
const result = renderNativeComponent( 'img', { src: 'foo.png', children: [ 'Surprise!' ] } );
const result = renderNativeComponent( 'img', {
src: 'foo.png',
children: [ 'Surprise!' ],
} );

@@ -430,3 +428,5 @@ expect( result ).toBe( '<img src="foo.png"/>' );

it( 'should render single literal child', () => {
const result = renderNativeComponent( 'div', { children: 'Hello' } );
const result = renderNativeComponent( 'div', {
children: 'Hello',
} );

@@ -437,6 +437,5 @@ expect( result ).toBe( '<div>Hello</div>' );

it( 'should render array of children', () => {
const result = renderNativeComponent( 'div', { children: [
'Hello ',
<Fragment key="toWhom">World</Fragment>,
] } );
const result = renderNativeComponent( 'div', {
children: [ 'Hello ', <Fragment key="toWhom">World</Fragment> ],
} );

@@ -551,3 +550,5 @@ expect( result ).toBe( '<div>Hello World</div>' );

expect( result ).toBe( ' for="foo" class="bar" contenteditable="true"' );
expect( result ).toBe(
' for="foo" class="bar" contenteditable="true"'
);
} );

@@ -565,3 +566,5 @@ } );

expect( result ).toBe( ' style="background:url(&quot;foo.png&quot;)" href="/index.php?foo=bar&amp;qux=<&quot;scary&quot;&gt;"' );
expect( result ).toBe(
' style="background:url(&quot;foo.png&quot;)" href="/index.php?foo=bar&amp;qux=<&quot;scary&quot;&gt;"'
);
} );

@@ -673,3 +676,5 @@

expect( result ).toBe( '-ms-transform:none;-o-transform:none;-moz-transform:none;-webkit-transform:none' );
expect( result ).toBe(
'-ms-transform:none;-o-transform:none;-moz-transform:none;-webkit-transform:none'
);
} );

@@ -676,0 +681,0 @@

/**
* External dependencies
*/
import {
isArray,
isNumber,
isString,
} from 'lodash';
import { isArray, isNumber, isString } from 'lodash';

@@ -10,0 +6,0 @@ /**

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc