feat(lib/modules/metro/utils): improve perf on bad module exports check

This commit is contained in:
PalmDevs 2025-07-03 20:45:48 +07:00
parent 2f21be2c52
commit 6a6a67e78f
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA

View file

@ -78,17 +78,17 @@ export function isModuleExportBad(
*/
export function isModuleExportsBad(exports: Metro.ModuleExports): boolean {
return (
// Can't run isProxy() on this because this isn't your typical proxy:
// https://github.com/facebook/react-native/blob/master/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp
exports === nativeModuleProxy ||
// Nullish?
exports == null ||
// Isn't an object or function?
// - Number exports are not useful, usually just an asset ID
// - String, Boolean, Symbol, BigInt exports are not useful (who would do `module.exports = ...`?)
!(typeof exports === 'object' || typeof exports === 'function') ||
// Checking if the object is empty
(exports.__proto__ === Object.prototype &&
!Reflect.ownKeys(exports).length) ||
// Can't run isProxy() on this because this isn't your typical proxy:
// https://github.com/facebook/react-native/blob/master/packages/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleBinding.cpp
exports === nativeModuleProxy
!(
exports.__proto__ === Function.prototype ||
(typeof exports === 'object' && Reflect.ownKeys(exports).length)
)
)
}