Delete use of `source` in JSX runtime (#28433)
Only remaining place it was being used was in a warning message.
Andrew Clark committed
Feb 23, 2024 at 16:52 UTC
16d3f7833d25b1ea026add83dd109601b60f138e
3 files changed
+8
-43
packages/react/src/__tests__/ReactElementValidator-test.internal.js
+5
-5
@@ -310,12 +310,12 @@ describe('ReactElementValidator', () => {
310
}).toErrorDev([
311
'Warning: React.createElement: type is invalid -- expected a string ' +
312
'(for built-in components) or a class/function (for composite ' +
313
- 'components) but got: null.' +
314
- '\n\nCheck the render method of `ParentComp`.\n in ParentComp',
313
+ 'components) but got: null.\n' +
314
+ ' in ParentComp (at **)',
315
'Warning: React.createElement: type is invalid -- expected a string ' +
316
'(for built-in components) or a class/function (for composite ' +
317
- 'components) but got: null.' +
318
- '\n\nCheck the render method of `ParentComp`.\n in ParentComp',
317
+ 'components) but got: null.\n' +
318
+ ' in ParentComp (at **)',
319
]);
320
});
321
@@ -427,7 +427,7 @@ describe('ReactElementValidator', () => {
427
'(for built-in components) or a class/function (for composite ' +
428
'components) but got: undefined. You likely forgot to export your ' +
429
"component from the file it's defined in, or you might have mixed up " +
430
- 'default and named imports.\n\nCheck your code at **.',
430
+ 'default and named imports.',
431
{withoutStack: true},
432
);
433
});
packages/react/src/__tests__/ReactJSXElementValidator-test.js
+3
-6
@@ -170,22 +170,19 @@ describe('ReactJSXElementValidator', () => {
170
'(for built-in components) or a class/function (for composite ' +
171
'components) but got: undefined. You likely forgot to export your ' +
172
"component from the file it's defined in, or you might have mixed up " +
173
- 'default and named imports.' +
174
- '\n\nCheck your code at **.',
173
+ 'default and named imports.',
174
{withoutStack: true},
175
);
176
expect(() => void (<Null />)).toErrorDev(
177
'Warning: React.jsx: type is invalid -- expected a string ' +
178
'(for built-in components) or a class/function (for composite ' +
180
- 'components) but got: null.' +
181
- '\n\nCheck your code at **.',
179
+ 'components) but got: null.',
180
{withoutStack: true},
181
);
182
expect(() => void (<True />)).toErrorDev(
183
'Warning: React.jsx: type is invalid -- expected a string ' +
184
'(for built-in components) or a class/function (for composite ' +
187
- 'components) but got: boolean.' +
188
- '\n\nCheck your code at **.',
185
+ 'components) but got: boolean.',
186
{withoutStack: true},
187
);
188
// No error expected
packages/react/src/jsx/ReactJSXElement.js
-32
@@ -425,13 +425,6 @@ export function jsxDEV(type, config, maybeKey, isStaticChildren, source, self) {
425
"it's defined in, or you might have mixed up default and named imports.";
426
}
427
428
- const sourceInfo = getSourceInfoErrorAddendum(source);
429
- if (sourceInfo) {
430
- info += sourceInfo;
431
- } else {
432
- info += getDeclarationErrorAddendum();
433
- }
434
-
428
let typeString;
429
if (type === null) {
430
typeString = 'null';
@@ -622,13 +615,6 @@ export function createElement(type, config, children) {
615
"it's defined in, or you might have mixed up default and named imports.";
616
}
617
625
- const sourceInfo = getSourceInfoErrorAddendumForProps(config);
626
- if (sourceInfo) {
627
- info += sourceInfo;
628
- } else {
629
- info += getDeclarationErrorAddendum();
630
- }
631
-
618
let typeString;
619
if (type === null) {
620
typeString = 'null';
@@ -939,24 +925,6 @@ function getDeclarationErrorAddendum() {
925
}
926
}
927
942
-function getSourceInfoErrorAddendumForProps(elementProps) {
943
- if (elementProps !== null && elementProps !== undefined) {
944
- return getSourceInfoErrorAddendum(elementProps.__source);
945
- }
946
- return '';
947
-}
948
-
949
-function getSourceInfoErrorAddendum(source) {
950
- if (__DEV__) {
951
- if (source !== undefined) {
952
- const fileName = source.fileName.replace(/^.*[\\\/]/, '');
953
- const lineNumber = source.lineNumber;
954
- return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.';
955
- }
956
- return '';
957
- }
958
-}
959
-
928
/**
929
* Ensure that every element either is passed in a static location, in an
930
* array with an explicit keys property defined, or in an object literal