1import type { generateFunctionMap as generateFunctionMapType } from 'metro-source-map';
2
3import { env } from '../env';
4
5type GenerateFunctionMapParams = Parameters<typeof generateFunctionMapType>;
6
7export function generateFunctionMap(
8  ...props: GenerateFunctionMapParams
9): ReturnType<typeof generateFunctionMapType> | null {
10  //  `x_facebook_sources` is a source map feature that we disable by default since it isn't documented
11  // and doesn't appear to add much value to the DX, it also increases bundle time, and source map size.
12  // The feature supposedly provides improved function names for anonymous functions, but we will opt towards
13  // linting to prevent users from adding anonymous functions for important features like React components.
14  //
15  // Here is an example stack trace for a component that throws an error
16  // in the root component (which is an anonymous function):
17  //
18  // Before:
19  // - <anonymous> App.js:5:9
20  // - renderApplication renderApplication.js:54:5
21  // - runnables.appKey.run AppRegistry.js:117:26
22  //
23  // After:
24  // - _default App.js:5:9
25  // - renderApplication renderApplication.js:54:5
26  // - run AppRegistry.js:117:26
27  //
28  if (env.EXPO_USE_FB_SOURCES) {
29    return (require('metro-source-map') as typeof import('metro-source-map')).generateFunctionMap(
30      ...props
31    );
32  }
33  return null;
34}
35