mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Convert usage of String and Boolean constructors
This commit is contained in:
@@ -196,8 +196,9 @@ var DOMRenderer = ReactFiberReconciler({
|
||||
typeof props.children === 'string' ||
|
||||
typeof props.children === 'number'
|
||||
) {
|
||||
const string = '' + props.children;
|
||||
const ownAncestorInfo = updatedAncestorInfo(hostContextDev.ancestorInfo, type, null);
|
||||
validateDOMNesting(null, String(props.children), null, ownAncestorInfo);
|
||||
validateDOMNesting(null, string, null, ownAncestorInfo);
|
||||
}
|
||||
parentNamespace = hostContextDev.namespace;
|
||||
} else {
|
||||
@@ -237,8 +238,9 @@ var DOMRenderer = ReactFiberReconciler({
|
||||
typeof newProps.children === 'string' ||
|
||||
typeof newProps.children === 'number'
|
||||
)) {
|
||||
const string = '' + newProps.children;
|
||||
const ownAncestorInfo = updatedAncestorInfo(hostContextDev.ancestorInfo, type, null);
|
||||
validateDOMNesting(null, String(newProps.children), null, ownAncestorInfo);
|
||||
validateDOMNesting(null, string, null, ownAncestorInfo);
|
||||
}
|
||||
}
|
||||
return diffProperties(domElement, type, oldProps, newProps, rootContainerInstance);
|
||||
@@ -411,9 +413,9 @@ var ReactDOM = {
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
const isRootRenderedBySomeReact = Boolean(container._reactRootContainer);
|
||||
const isRootRenderedBySomeReact = !!container._reactRootContainer;
|
||||
const rootEl = getReactRootElementInContainer(container);
|
||||
const hasNonRootReactChild = Boolean(rootEl && ReactDOMComponentTree.getInstanceFromNode(rootEl));
|
||||
const hasNonRootReactChild = !!(rootEl && ReactDOMComponentTree.getInstanceFromNode(rootEl));
|
||||
|
||||
warning(
|
||||
!hasNonRootReactChild ||
|
||||
|
||||
@@ -134,7 +134,7 @@ var ReactDOMSelect = {
|
||||
var value = props.value;
|
||||
node._wrapperState = {
|
||||
initialValue: value != null ? value : props.defaultValue,
|
||||
wasMultiple: Boolean(props.multiple),
|
||||
wasMultiple: !!props.multiple,
|
||||
};
|
||||
|
||||
if (
|
||||
@@ -153,11 +153,11 @@ var ReactDOMSelect = {
|
||||
didWarnValueDefaultValue = true;
|
||||
}
|
||||
|
||||
node.multiple = Boolean(props.multiple);
|
||||
node.multiple = !!props.multiple;
|
||||
if (value != null) {
|
||||
updateOptions(node, Boolean(props.multiple), value);
|
||||
updateOptions(node, !!props.multiple, value);
|
||||
} else if (props.defaultValue != null) {
|
||||
updateOptions(node, Boolean(props.multiple), props.defaultValue);
|
||||
updateOptions(node, !!props.multiple, props.defaultValue);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -168,18 +168,18 @@ var ReactDOMSelect = {
|
||||
node._wrapperState.initialValue = undefined;
|
||||
|
||||
var wasMultiple = node._wrapperState.wasMultiple;
|
||||
node._wrapperState.wasMultiple = Boolean(props.multiple);
|
||||
node._wrapperState.wasMultiple = !!props.multiple;
|
||||
|
||||
var value = props.value;
|
||||
if (value != null) {
|
||||
updateOptions(node, Boolean(props.multiple), value);
|
||||
} else if (wasMultiple !== Boolean(props.multiple)) {
|
||||
updateOptions(node, !!props.multiple, value);
|
||||
} else if (wasMultiple !== !!props.multiple) {
|
||||
// For simplicity, reapply `defaultValue` if `multiple` is toggled.
|
||||
if (props.defaultValue != null) {
|
||||
updateOptions(node, Boolean(props.multiple), props.defaultValue);
|
||||
updateOptions(node, !!props.multiple, props.defaultValue);
|
||||
} else {
|
||||
// Revert the select back to its default unselected state.
|
||||
updateOptions(node, Boolean(props.multiple), props.multiple ? [] : '');
|
||||
updateOptions(node, !!props.multiple, props.multiple ? [] : '');
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -189,7 +189,7 @@ var ReactDOMSelect = {
|
||||
var value = props.value;
|
||||
|
||||
if (value != null) {
|
||||
updateOptions(node, Boolean(props.multiple), value);
|
||||
updateOptions(node, !!props.multiple, value);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -154,7 +154,7 @@ var topEventMapping = {
|
||||
/**
|
||||
* To ensure no conflicts with other potential React instances on the page
|
||||
*/
|
||||
var topListenersIDKey = '_reactListenersID' + String(Math.random()).slice(2);
|
||||
var topListenersIDKey = '_reactListenersID' + ('' + Math.random()).slice(2);
|
||||
|
||||
function getListeningForDocument(mountAt) {
|
||||
// In IE8, `mountAt` is a host object and doesn't have `hasOwnProperty`
|
||||
|
||||
@@ -31,7 +31,7 @@ var internalEventHandlersKey = '__reactEventHandlers$' + randomKey;
|
||||
*/
|
||||
function shouldPrecacheNode(node, nodeID) {
|
||||
return (node.nodeType === 1 &&
|
||||
node.getAttribute(ATTR_NAME) === String(nodeID)) ||
|
||||
node.getAttribute(ATTR_NAME) === ('' + nodeID)) ||
|
||||
(node.nodeType === 8 &&
|
||||
node.nodeValue === ' react-text: ' + nodeID + ' ') ||
|
||||
(node.nodeType === 8 &&
|
||||
|
||||
@@ -400,7 +400,7 @@ if (__DEV__) {
|
||||
childTag,
|
||||
ancestorInstance,
|
||||
ancestorTag,
|
||||
Boolean(invalidParent)
|
||||
!!invalidParent
|
||||
) + '.';
|
||||
} else {
|
||||
addendum = getCurrentFiberStackAddendum();
|
||||
|
||||
@@ -185,7 +185,7 @@ if (__DEV__) {
|
||||
return;
|
||||
}
|
||||
|
||||
validateDOMNesting(null, String(content), this, this._ancestorInfo);
|
||||
validateDOMNesting(null, '' + content, this, this._ancestorInfo);
|
||||
this._contentDebugID = contentDebugID;
|
||||
if (hasExistingContent) {
|
||||
ReactInstrumentation.debugTool.onBeforeUpdateComponent(contentDebugID, content);
|
||||
|
||||
@@ -440,7 +440,7 @@ var ReactMount = {
|
||||
callback === null || typeof callback === 'function',
|
||||
'render(...): Expected the last optional `callback` argument to be a ' +
|
||||
'function. Instead received: %s.',
|
||||
String(callback)
|
||||
'' + callback
|
||||
);
|
||||
}
|
||||
if (!React.isValidElement(nextElement)) {
|
||||
|
||||
@@ -135,7 +135,7 @@ var ReactDOMSelect = {
|
||||
inst._wrapperState = {
|
||||
initialValue: value != null ? value : props.defaultValue,
|
||||
listeners: null,
|
||||
wasMultiple: Boolean(props.multiple),
|
||||
wasMultiple: !!props.multiple,
|
||||
};
|
||||
|
||||
if (
|
||||
@@ -169,18 +169,18 @@ var ReactDOMSelect = {
|
||||
inst._wrapperState.initialValue = undefined;
|
||||
|
||||
var wasMultiple = inst._wrapperState.wasMultiple;
|
||||
inst._wrapperState.wasMultiple = Boolean(props.multiple);
|
||||
inst._wrapperState.wasMultiple = !!props.multiple;
|
||||
|
||||
var value = props.value;
|
||||
if (value != null) {
|
||||
updateOptions(inst, Boolean(props.multiple), value);
|
||||
} else if (wasMultiple !== Boolean(props.multiple)) {
|
||||
updateOptions(inst, !!props.multiple, value);
|
||||
} else if (wasMultiple !== !!props.multiple) {
|
||||
// For simplicity, reapply `defaultValue` if `multiple` is toggled.
|
||||
if (props.defaultValue != null) {
|
||||
updateOptions(inst, Boolean(props.multiple), props.defaultValue);
|
||||
updateOptions(inst, !!props.multiple, props.defaultValue);
|
||||
} else {
|
||||
// Revert the select back to its default unselected state.
|
||||
updateOptions(inst, Boolean(props.multiple), props.multiple ? [] : '');
|
||||
updateOptions(inst, !!props.multiple, props.multiple ? [] : '');
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -191,7 +191,7 @@ var ReactDOMSelect = {
|
||||
var value = props.value;
|
||||
|
||||
if (value != null) {
|
||||
updateOptions(inst, Boolean(props.multiple), value);
|
||||
updateOptions(inst, !!props.multiple, value);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -95,7 +95,7 @@ function coerceRef(current: Fiber | null, element: ReactElement) {
|
||||
'bug in React. Please file an issue.',
|
||||
mixedRef
|
||||
);
|
||||
const stringRef = String(mixedRef);
|
||||
const stringRef = '' + mixedRef;
|
||||
// Check if previous string ref matches new string ref
|
||||
if (current !== null && current.ref !== null && current.ref._stringRef === stringRef) {
|
||||
return current.ref;
|
||||
@@ -117,7 +117,8 @@ function coerceRef(current: Fiber | null, element: ReactElement) {
|
||||
|
||||
function throwOnInvalidObjectType(returnFiber : Fiber, newChild : Object) {
|
||||
if (returnFiber.type !== 'textarea') {
|
||||
const childrenString = String(newChild);
|
||||
// $FlowFixMe - Intentional cast to string
|
||||
const childrenString = '' + newChild;
|
||||
let addendum = '';
|
||||
if (__DEV__) {
|
||||
addendum =
|
||||
|
||||
@@ -47,7 +47,8 @@ if (__DEV__) {
|
||||
'%s(...): Expected the last optional `callback` argument to be a ' +
|
||||
'function. Instead received: %s.',
|
||||
callerName,
|
||||
String(callback)
|
||||
// $FlowFixMe - Intentional cast to string
|
||||
'' + callback
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -167,7 +167,8 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(
|
||||
callback === null || typeof callback === 'function',
|
||||
'render(...): Expected the last optional `callback` argument to be a ' +
|
||||
'function. Instead received: %s.',
|
||||
String(callback)
|
||||
// $FlowFixMe - Intentional cast to string
|
||||
'' + callback
|
||||
);
|
||||
}
|
||||
addTopLevelUpdate(current, nextState, callback, priorityLevel);
|
||||
|
||||
@@ -776,7 +776,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
|
||||
'by a bug in React. Please file an issue.'
|
||||
);
|
||||
isPerformingWork = true;
|
||||
const isPerformingDeferredWork = Boolean(deadline);
|
||||
const isPerformingDeferredWork = !!deadline;
|
||||
|
||||
// This outer loop exists so that we can restart the work loop after
|
||||
// catching an error. It also lets us flush Task work at the end of a
|
||||
@@ -1034,7 +1034,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
|
||||
function hasCapturedError(fiber : Fiber) : boolean {
|
||||
// TODO: capturedErrors should store the boundary instance, to avoid needing
|
||||
// to check the alternate.
|
||||
return Boolean(
|
||||
return (
|
||||
capturedErrors !== null &&
|
||||
(capturedErrors.has(fiber) || (fiber.alternate !== null && capturedErrors.has(fiber.alternate)))
|
||||
);
|
||||
@@ -1043,7 +1043,7 @@ module.exports = function<T, P, I, TI, PI, C, CX, PL>(config : HostConfig<T, P,
|
||||
function isFailedBoundary(fiber : Fiber) : boolean {
|
||||
// TODO: failedBoundaries should store the boundary instance, to avoid
|
||||
// needing to check the alternate.
|
||||
return Boolean(
|
||||
return (
|
||||
failedBoundaries !== null &&
|
||||
(failedBoundaries.has(fiber) || (fiber.alternate !== null && failedBoundaries.has(fiber.alternate)))
|
||||
);
|
||||
|
||||
@@ -341,7 +341,7 @@ function addTopLevelUpdate(
|
||||
callback : Callback | null,
|
||||
priorityLevel : PriorityLevel
|
||||
) : void {
|
||||
const isTopLevelUnmount = Boolean(
|
||||
const isTopLevelUnmount = !!(
|
||||
partialState &&
|
||||
partialState.element === null
|
||||
);
|
||||
@@ -470,7 +470,8 @@ function commitCallbacks(finishedWork : Fiber, queue : UpdateQueue, context : mi
|
||||
typeof callback === 'function',
|
||||
'Invalid argument passed as callback. Expected a function. Instead ' +
|
||||
'received: %s',
|
||||
String(callback)
|
||||
// $FlowFixMe - Intentional cast to string
|
||||
'' + callback
|
||||
);
|
||||
callback.call(context);
|
||||
}
|
||||
|
||||
@@ -1002,7 +1002,7 @@ var ReactCompositeComponent = {
|
||||
) {
|
||||
var inst = this._instance;
|
||||
|
||||
var hasComponentDidUpdate = Boolean(inst.componentDidUpdate);
|
||||
var hasComponentDidUpdate = !!inst.componentDidUpdate;
|
||||
var prevProps;
|
||||
var prevState;
|
||||
var prevContext;
|
||||
|
||||
@@ -24,7 +24,7 @@ if (__DEV__) {
|
||||
'%s(...): Expected the last optional `callback` argument to be a ' +
|
||||
'function. Instead received: %s.',
|
||||
callerName,
|
||||
String(callback)
|
||||
'' + callback
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -19,7 +19,8 @@ function validateCallback(callback: ?Function) {
|
||||
!callback || typeof callback === 'function',
|
||||
'Invalid argument passed as callback. Expected a function. Instead ' +
|
||||
'received: %s',
|
||||
String(callback)
|
||||
// $FlowFixMe - Intentional cast to string
|
||||
'' + callback
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -157,7 +157,7 @@ function traverseAllChildrenImpl(
|
||||
}
|
||||
}
|
||||
}
|
||||
var childrenString = String(children);
|
||||
var childrenString = '' + children;
|
||||
invariant(
|
||||
false,
|
||||
'Objects are not valid as a React child (found: %s).%s',
|
||||
|
||||
@@ -212,7 +212,7 @@ Object.assign(reactComponentExpectInternal.prototype, {
|
||||
expect(this._instance.tag === HostText).toBe(true);
|
||||
var actualVal = this._instance.memoizedProps;
|
||||
expect(typeof actualVal === 'string' || typeof actualVal === 'number').toBe(true);
|
||||
expect(String(actualVal)).toBe(val);
|
||||
expect('' + actualVal).toBe(val);
|
||||
} else {
|
||||
// Fiber reconciler
|
||||
var elementType = typeof this._instance._currentElement;
|
||||
|
||||
Reference in New Issue
Block a user