From 823d311f8f8297ff9c909a9cd51cd88d053e95c2 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 26 Jan 2021 16:38:28 -0500 Subject: [PATCH] Avoid optional chaining in instanceOf to achieve 100% coverage. --- src/jsutils/instanceOf.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/jsutils/instanceOf.js b/src/jsutils/instanceOf.js index 2d0bf48208..db322a60ca 100644 --- a/src/jsutils/instanceOf.js +++ b/src/jsutils/instanceOf.js @@ -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 @@ -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.