Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const render = (reactEl, config, ShallowRender) => {
if (!reactEl || typeof reactEl !== 'object') {
return reactEl;
}
const isAlreadyMocked = Boolean(reactEl._mock);
if (isAlreadyMocked) {
reactEl._mock._render();
}
if (!isAlreadyMocked && ReactIs.isForwardRef(reactEl)) {
const shallowRender = new ShallowRender(reactEl, config);
return {
...shallowRender._rendered,
_mock: shallowRender
};
}
// When rendering modify the context value
if (ReactIs.isContextProvider(reactEl) && reactEl.props.value) {
reactEl.type._context._currentValue = reactEl.props.value;
}
if (!isAlreadyMocked && shouldBeRender(reactEl, config)) {
const mock = config.mocks && config.mocks[reactEl.type.displayName || reactEl.type.name];
const el = mock === true ? reactEl.type : mock || reactEl.type;
typeof element === 'function'
? ' Instead of passing a component class, make sure to instantiate ' +
'it by passing it to React.createElement.'
: '',
);
element = ((element: any): ReactElement);
// Show a special message for host elements since it's a common case.
invariant(
typeof element.type !== 'string',
'ReactShallowRenderer render(): Shallow rendering works only with custom ' +
'components, not primitives (%s). Instead of calling `.render(el)` and ' +
'inspecting the rendered output, look at `el.props` directly instead.',
element.type,
);
invariant(
isForwardRef(element) ||
(typeof element.type === 'function' || isMemo(element)),
'ReactShallowRenderer render(): Shallow rendering works only with custom ' +
'components, but the provided element type was `%s`.',
Array.isArray(element.type)
? 'array'
: element.type === null
? 'null'
: typeof element.type,
);
if (this._rendering) {
return;
}
if (this._element != null && this._element.type !== element.type) {
this._reset();
}
typeof element === 'function'
? ' Instead of passing a component class, make sure to instantiate ' +
'it by passing it to React.createElement.'
: '',
);
element = ((element: any): ReactElement);
// Show a special message for host elements since it's a common case.
invariant(
typeof element.type !== 'string',
'ReactShallowRenderer render(): Shallow rendering works only with custom ' +
'components, not primitives (%s). Instead of calling `.render(el)` and ' +
'inspecting the rendered output, look at `el.props` directly instead.',
element.type,
);
invariant(
isForwardRef(element) ||
(typeof element.type === 'function' || isMemo(element)),
'ReactShallowRenderer render(): Shallow rendering works only with custom ' +
'components, but the provided element type was `%s`.',
Array.isArray(element.type)
? 'array'
: element.type === null
? 'null'
: typeof element.type,
);
if (this._rendering) {
return;
}
if (this._element != null && this._element.type !== element.type) {
this._reset();
}
render() {
const { children } = this.props;
if (!children) {
// We need an element that we can locate in the DOM to determine where it is
// rendered relative to the top of its context.
return <span style="{{">;
}
if (isDOMElement(children) || isForwardRef(children)) {
const ref = (node) => {
this.refElement(node);
if (children.ref) {
if (typeof children.ref === 'function') {
children.ref(node);
} else {
children.ref.current = node;
}
}
};
return React.cloneElement(children, { ref });
}
return React.cloneElement(children, { innerRef: this.refElement });
}</span>
function mergeOptions(Widget) {
// cache return value as property of widget for proper react reconciliation
if (!Widget.MergedWidget) {
const defaultOptions =
(Widget.defaultProps && Widget.defaultProps.options) || {};
Widget.MergedWidget = ({ options = {}, ...props }) => (
);
}
return Widget.MergedWidget;
}
if (
typeof widget === "function" ||
ReactIs.isForwardRef(React.createElement(widget)) ||
ReactIs.isMemo(widget)
) {
return mergeOptions(widget);
}
if (typeof widget !== "string") {
throw new Error(`Unsupported widget definition: ${typeof widget}`);
}
if (registeredWidgets.hasOwnProperty(widget)) {
const registeredWidget = registeredWidgets[widget];
return getWidget(schema, registeredWidget, registeredWidgets);
}
if (!widgetMap.hasOwnProperty(type)) {
throw new Error(`No widget for type "${type}"`);
this._instance.props = enhancedProps;
if (
!forceUpdate &&
!firstRender &&
typeof this._instance.shouldComponentUpdate === 'function' &&
!this._instance.shouldComponentUpdate(
this._instance.props,
this._instance.state
)
) {
return;
}
reactEl = this._instance.render();
} else if (ReactIs.isForwardRef(this._component)) {
reactEl = this._component.type.render.call(
undefined,
enhancedProps,
this._component.ref
);
} else {
reactEl = this._component.type.call(undefined, enhancedProps);
}
try {
this._rendered = render(reactEl, this._config, ShallowRender);
this.props = {
...enhancedProps,
...(this._rendered ? this._rendered.props : {}),
children: null
};
const Ref: React.FunctionComponent = props => {
const { children, innerRef, ...rest } = props
const child = React.Children.only(children)
const ElementType = ReactIs.isForwardRef(child) ? RefForward : RefFindNode
const childWithProps =
child && rest && Object.keys(rest).length > 0 ? React.cloneElement(child, rest) : child
return {childWithProps}
}
renderIcon: function(props, propName, componentName) {
if (props[propName] == undefined) {
return;
}
const RefForwardingComponent = props[propName];
if (!isForwardRef())
return new Error(`Invalid value of prop '${propName}' supplied to '${componentName}',
it should be created/wrapped with React.forwardRef() to have a ref and access the proper
DOM node of the element to calculate its position in the viewport.`);
},
isCustomComponent(type) {
const fakeElement = makeFakeElement(type);
return !!type && (
typeof type === 'function'
|| isForwardRef(fakeElement)
|| isContextProvider(fakeElement)
|| isContextConsumer(fakeElement)
);
}