From 3018f45504e51d65a27b410a5a954dda8cd0ab5b Mon Sep 17 00:00:00 2001 From: Andrew Clark Date: Fri, 23 Feb 2024 14:56:28 -0500 Subject: [PATCH] Delete use of `source` in JSX runtime Only remaining place it was being used was in a warning message. --- .../ReactElementValidator-test.internal.js | 10 +++--- .../ReactJSXElementValidator-test.js | 9 ++---- packages/react/src/jsx/ReactJSXElement.js | 32 ------------------- 3 files changed, 8 insertions(+), 43 deletions(-) diff --git a/packages/react/src/__tests__/ReactElementValidator-test.internal.js b/packages/react/src/__tests__/ReactElementValidator-test.internal.js index 3bfded6d6d824..4ffd5db6a2a66 100644 --- a/packages/react/src/__tests__/ReactElementValidator-test.internal.js +++ b/packages/react/src/__tests__/ReactElementValidator-test.internal.js @@ -310,12 +310,12 @@ describe('ReactElementValidator', () => { }).toErrorDev([ 'Warning: React.createElement: type is invalid -- expected a string ' + '(for built-in components) or a class/function (for composite ' + - 'components) but got: null.' + - '\n\nCheck the render method of `ParentComp`.\n in ParentComp', + 'components) but got: null.\n' + + ' in ParentComp (at **)', 'Warning: React.createElement: type is invalid -- expected a string ' + '(for built-in components) or a class/function (for composite ' + - 'components) but got: null.' + - '\n\nCheck the render method of `ParentComp`.\n in ParentComp', + 'components) but got: null.\n' + + ' in ParentComp (at **)', ]); }); @@ -427,7 +427,7 @@ describe('ReactElementValidator', () => { '(for built-in components) or a class/function (for composite ' + 'components) but got: undefined. You likely forgot to export your ' + "component from the file it's defined in, or you might have mixed up " + - 'default and named imports.\n\nCheck your code at **.', + 'default and named imports.', {withoutStack: true}, ); }); diff --git a/packages/react/src/__tests__/ReactJSXElementValidator-test.js b/packages/react/src/__tests__/ReactJSXElementValidator-test.js index 93293b54ff544..b34de9e67a4cb 100644 --- a/packages/react/src/__tests__/ReactJSXElementValidator-test.js +++ b/packages/react/src/__tests__/ReactJSXElementValidator-test.js @@ -170,22 +170,19 @@ describe('ReactJSXElementValidator', () => { '(for built-in components) or a class/function (for composite ' + 'components) but got: undefined. You likely forgot to export your ' + "component from the file it's defined in, or you might have mixed up " + - 'default and named imports.' + - '\n\nCheck your code at **.', + 'default and named imports.', {withoutStack: true}, ); expect(() => void ()).toErrorDev( 'Warning: React.jsx: type is invalid -- expected a string ' + '(for built-in components) or a class/function (for composite ' + - 'components) but got: null.' + - '\n\nCheck your code at **.', + 'components) but got: null.', {withoutStack: true}, ); expect(() => void ()).toErrorDev( 'Warning: React.jsx: type is invalid -- expected a string ' + '(for built-in components) or a class/function (for composite ' + - 'components) but got: boolean.' + - '\n\nCheck your code at **.', + 'components) but got: boolean.', {withoutStack: true}, ); // No error expected diff --git a/packages/react/src/jsx/ReactJSXElement.js b/packages/react/src/jsx/ReactJSXElement.js index 59e7b6e5e3114..a31cd45c2b0dc 100644 --- a/packages/react/src/jsx/ReactJSXElement.js +++ b/packages/react/src/jsx/ReactJSXElement.js @@ -425,13 +425,6 @@ export function jsxDEV(type, config, maybeKey, isStaticChildren, source, self) { "it's defined in, or you might have mixed up default and named imports."; } - const sourceInfo = getSourceInfoErrorAddendum(source); - if (sourceInfo) { - info += sourceInfo; - } else { - info += getDeclarationErrorAddendum(); - } - let typeString; if (type === null) { typeString = 'null'; @@ -622,13 +615,6 @@ export function createElement(type, config, children) { "it's defined in, or you might have mixed up default and named imports."; } - const sourceInfo = getSourceInfoErrorAddendumForProps(config); - if (sourceInfo) { - info += sourceInfo; - } else { - info += getDeclarationErrorAddendum(); - } - let typeString; if (type === null) { typeString = 'null'; @@ -939,24 +925,6 @@ function getDeclarationErrorAddendum() { } } -function getSourceInfoErrorAddendumForProps(elementProps) { - if (elementProps !== null && elementProps !== undefined) { - return getSourceInfoErrorAddendum(elementProps.__source); - } - return ''; -} - -function getSourceInfoErrorAddendum(source) { - if (__DEV__) { - if (source !== undefined) { - const fileName = source.fileName.replace(/^.*[\\\/]/, ''); - const lineNumber = source.lineNumber; - return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.'; - } - return ''; - } -} - /** * Ensure that every element either is passed in a static location, in an * array with an explicit keys property defined, or in an object literal