Skip to content

Commit

Permalink
Delete use of source in JSX runtime (facebook#28433)
Browse files Browse the repository at this point in the history
Only remaining place it was being used was in a warning message.
  • Loading branch information
acdlite committed Feb 23, 2024
1 parent d579e77 commit 16d3f78
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 **)',
]);
});

Expand Down Expand Up @@ -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},
);
});
Expand Down
9 changes: 3 additions & 6 deletions packages/react/src/__tests__/ReactJSXElementValidator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<Null />)).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 (<True />)).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
Expand Down
32 changes: 0 additions & 32 deletions packages/react/src/jsx/ReactJSXElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 16d3f78

Please sign in to comment.