Skip to content

Commit

Permalink
🚴 perf(extendError): Reduce bundle size by exploiting return value.
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed Mar 18, 2021
1 parent e6e82fd commit 0773fee
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/extendError.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ export default function extendError(Error, name) {
const CustomError = function (...parameters) {
const instance = new Error(...parameters);
instance.name = name;
Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
if (Error.captureStackTrace) {
Error.captureStackTrace(instance, CustomError);
}

return instance;
return Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
};

CustomError.prototype = Object.create(Error.prototype, {
Expand All @@ -21,7 +20,5 @@ export default function extendError(Error, name) {
},
});

Object.setPrototypeOf(CustomError, Error);

return CustomError;
return Object.setPrototypeOf(CustomError, Error);
}

0 comments on commit 0773fee

Please sign in to comment.