From d25f265a2b032b9d8737abf8918088d1e73b987f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hu=C3=A1ng=20J=C3=B9nli=C3=A0ng?= Date: Mon, 9 Oct 2023 23:03:39 -0400 Subject: [PATCH] Fix: fallback to typeof when toString is applied to incompatible object (#16017) --- packages/babel-helpers/src/helpers.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/babel-helpers/src/helpers.ts b/packages/babel-helpers/src/helpers.ts index 6f101048e7c0..957e61e634c5 100644 --- a/packages/babel-helpers/src/helpers.ts +++ b/packages/babel-helpers/src/helpers.ts @@ -314,7 +314,12 @@ helpers.construct = helper("7.0.0-beta.0")` helpers.isNativeFunction = helper("7.0.0-beta.0")` export default function _isNativeFunction(fn) { // Note: This function returns "true" for core-js functions. - return Function.toString.call(fn).indexOf("[native code]") !== -1; + try { + return Function.toString.call(fn).indexOf("[native code]") !== -1; + } catch (e) { + // Firefox 31 throws when "toString" is applied to an HTMLElement + return typeof fn === "function"; + } } `;