Split into multiple invariants

That way the messages are extracted by the error code transform.
This commit is contained in:
Andrew Clark committed 2017-02-06 17:59:53 -08:00
1 parent 9fcf761e90
commit 0564b08cf2
2 files changed
+58 -32

No files matched your search

+29 -16
View File
@@ -378,23 +378,36 @@ var ReactDOM = {
// Top-level check occurs here instead of inside child reconciler because
// because requirements vary between renderers. E.g. React Art
// allows arrays.
invariant(
isValidElement(element),
'ReactDOM.render(): Invalid component element.%s',
(
typeof element === 'string' ?
' Instead of passing a string like \'div\', pass ' +
'React.createElement(\'div\') or <div />.' :
typeof element === 'function' ?
' Instead of passing a class like Foo, pass ' +
'React.createElement(Foo) or <Foo />.' :
if (!isValidElement(element)) {
if (typeof element === 'string') {
invariant(
false,
'ReactDOM.render(): Invalid component element. Instead of ' +
'passing a string like \'div\', pass ' +
'React.createElement(\'div\') or <div />.'
);
} else if (typeof element === 'function') {
invariant(
false,
'ReactDOM.render(): Invalid component element. Instead of ' +
'passing a class like Foo, pass React.createElement(Foo) ' +
'or <Foo />.'
);
} else if (element != null && typeof element.props !== 'undefined') {
// Check if it quacks like an element
element != null && element.props !== undefined ?
' This may be caused by unintentionally loading two independent ' +
'copies of React.' :
''
)
);
invariant(
false,
'ReactDOM.render(): Invalid component element. This may be ' +
'caused by unintentionally loading two independent copies ' +
'of React.'
);
} else {
invariant(
false,
'ReactDOM.render(): Invalid component element.'
);
}
}
}
if (__DEV__) {
+29 -16
View File
@@ -434,23 +434,36 @@ var ReactMount = {
_renderSubtreeIntoContainer: function(parentComponent, nextElement, container, callback) {
validateCallback(callback, 'ReactDOM.render');
invariant(
React.isValidElement(nextElement),
'ReactDOM.render(): Invalid component element.%s',
(
typeof nextElement === 'string' ?
' Instead of passing a string like \'div\', pass ' +
'React.createElement(\'div\') or <div />.' :
typeof nextElement === 'function' ?
' Instead of passing a class like Foo, pass ' +
'React.createElement(Foo) or <Foo />.' :
if (!React.isValidElement(nextElement)) {
if (typeof nextElement === 'string') {
invariant(
false,
'ReactDOM.render(): Invalid component element. Instead of ' +
'passing a string like \'div\', pass ' +
'React.createElement(\'div\') or <div />.'
);
} else if (typeof nextElement === 'function') {
invariant(
false,
'ReactDOM.render(): Invalid component element. Instead of ' +
'passing a class like Foo, pass React.createElement(Foo) ' +
'or <Foo />.'
);
} else if (nextElement != null && typeof nextElement.props !== 'undefined') {
// Check if it quacks like an element
nextElement != null && nextElement.props !== undefined ?
' This may be caused by unintentionally loading two independent ' +
'copies of React.' :
''
)
);
invariant(
false,
'ReactDOM.render(): Invalid component element. This may be ' +
'caused by unintentionally loading two independent copies ' +
'of React.'
);
} else {
invariant(
false,
'ReactDOM.render(): Invalid component element.'
);
}
}
warning(
!container || !container.tagName ||