Skip to content

Commit

Permalink
Avoid optional chaining in instanceOf to achieve 100% coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Jan 26, 2021
1 parent db4b2b8 commit 823d311
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/jsutils/instanceOf.js
Expand Up @@ -23,7 +23,8 @@ export default process.env.NODE_ENV === 'production'
return true;
}
if (value) {
const classTag = constructor?.prototype?.[SYMBOL_TO_STRING_TAG];
const proto = constructor && constructor.prototype;
const classTag = proto && proto[SYMBOL_TO_STRING_TAG];
const className = classTag || constructor.name;
// When the constructor class defines a Symbol.toStringTag
// property, as most classes exported by graphql-js do, use it
Expand All @@ -38,7 +39,7 @@ export default process.env.NODE_ENV === 'production'
// value is legitimately _not_ instanceof constructor.
const valueName = classTag
? value[SYMBOL_TO_STRING_TAG]
: value.constructor?.name;
: value.constructor && value.constructor.name;
if (typeof className === 'string' && valueName === className) {
throw new Error(
`Cannot use ${className} "${value}" from another module or realm.
Expand Down

0 comments on commit 823d311

Please sign in to comment.