@@ -1891,19 +1891,33 @@ function createFakeFunction<T>(
1891
1891
const comment =
1892
1892
'/* This module was rendered by a Server Component. Turn on Source Maps to see the server source. */' ;
1893
1893
1894
+ if ( ! name ) {
1895
+ // An eval:ed function with no name gets the name "eval". We give it something more descriptive.
1896
+ name = '(anonymous)' ;
1897
+ }
1898
+ const encodedName = JSON . stringify ( name ) ;
1894
1899
// We generate code where the call is at the line and column of the server executed code.
1895
1900
// This allows us to use the original source map as the source map of this fake file to
1896
1901
// point to the original source.
1897
1902
let code ;
1898
1903
if ( line <= 1 ) {
1899
- code = '_=>' + ' ' . repeat ( col < 4 ? 0 : col - 4 ) + '_()\n' + comment ;
1904
+ const minSize = encodedName . length + 8 ;
1905
+ code =
1906
+ '({' +
1907
+ encodedName +
1908
+ '}:_=>' +
1909
+ ' ' . repeat ( col < minSize ? 0 : col - minSize ) +
1910
+ '_()})\n' +
1911
+ comment ;
1900
1912
} else {
1901
1913
code =
1902
1914
comment +
1903
1915
'\n' . repeat ( line - 2 ) +
1904
- '_=>\n' +
1916
+ '({' +
1917
+ encodedName +
1918
+ '}:_=>\n' +
1905
1919
' ' . repeat ( col < 1 ? 0 : col - 1 ) +
1906
- '_()' ;
1920
+ '_()}) ' ;
1907
1921
}
1908
1922
1909
1923
if (filename.startsWith('/')) {
@@ -1931,7 +1945,7 @@ function createFakeFunction<T>(
1931
1945
let fn: FakeFunction< T > ;
1932
1946
try {
1933
1947
// eslint-disable-next-line no-eval
1934
- fn = ( 0 , eval ) ( code ) ;
1948
+ fn = ( 0 , eval ) ( code ) [ name ] ;
1935
1949
} catch (x) {
1936
1950
// If eval fails, such as if in an environment that doesn't support it,
1937
1951
// we fallback to creating a function here. It'll still have the right
@@ -1940,10 +1954,6 @@ function createFakeFunction<T>(
1940
1954
return _ ( ) ;
1941
1955
} ;
1942
1956
}
1943
- // $FlowFixMe[cannot-write]
1944
- Object.defineProperty(fn, 'name', { value : name || '(anonymous)' } );
1945
- // $FlowFixMe[prop-missing]
1946
- fn.displayName = name;
1947
1957
return fn;
1948
1958
}
1949
1959
0 commit comments