From 2810dc6460bf2e61c10b321077861d5535e954db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Thu, 30 Dec 2021 23:58:16 +0100 Subject: [PATCH] Fix derived classes in Chrome <= 36 (#14072) --- packages/babel-helpers/src/helpers.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/babel-helpers/src/helpers.ts b/packages/babel-helpers/src/helpers.ts index 891aad0d2815..80ee32905a72 100644 --- a/packages/babel-helpers/src/helpers.ts +++ b/packages/babel-helpers/src/helpers.ts @@ -335,16 +335,17 @@ helpers.inherits = helper("7.0.0-beta.0")` if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } - Object.defineProperty(subClass, "prototype", { - value: Object.create(superClass && superClass.prototype, { - constructor: { - value: subClass, - writable: true, - configurable: true - } - }), - writable: false, + // We can't use defineProperty to set the prototype in a single step because it + // doesn't work in Chrome <= 36. https://github.com/babel/babel/issues/14056 + // V8 bug: https://bugs.chromium.org/p/v8/issues/detail?id=3334 + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } }); + Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) setPrototypeOf(subClass, superClass); } `;