Skip to content

Commit

Permalink
Simplify $jscomp.inherits when ASSUME_ES6 is set.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 708433968
  • Loading branch information
concavelenz authored and copybara-github committed Dec 20, 2024
1 parent d89c439 commit 6481877
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/com/google/javascript/jscomp/js/es6/util/inherits.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @suppress {uselessCode}
*/
'require base';
'require util/defines';
'require util/objectcreate';
'require es6/util/setprototypeof';

Expand Down Expand Up @@ -57,10 +58,11 @@
$jscomp.inherits = function(childCtor, parentCtor) {
childCtor.prototype = $jscomp.objectCreate(parentCtor.prototype);
/** @override */ childCtor.prototype.constructor = childCtor;
if ($jscomp.setPrototypeOf) {
if ($jscomp.ASSUME_ES6 || $jscomp.setPrototypeOf) {
// avoid null dereference warning
/** @const {!Function} */
var setPrototypeOf = $jscomp.setPrototypeOf;
// NOTE: `$jscomp.setPrototypeOf` will be set to `Object.setPrototypeOf`
// when `$jscomp.ASSUME_ES6` is `true`.
var setPrototypeOf = /** @type {!Function} */ ($jscomp.setPrototypeOf);
setPrototypeOf(childCtor, parentCtor);
} else {
// setPrototypeOf is not available so we need to copy the static
Expand Down

0 comments on commit 6481877

Please sign in to comment.