Skip to content

Commit

Permalink
Delete use of source in JSX runtime
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 47beb96 commit f343031
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 37 deletions.
Original file line number Diff line number Diff line change
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: 2 additions & 30 deletions packages/react/src/jsx/ReactJSXElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,7 @@ 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();
}
info += getDeclarationErrorAddendum();

let typeString;
if (type === null) {
Expand Down Expand Up @@ -622,12 +617,7 @@ 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();
}
info += getDeclarationErrorAddendum();

let typeString;
if (type === null) {
Expand Down Expand Up @@ -939,24 +929,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 f343031

Please sign in to comment.