-
Notifications
You must be signed in to change notification settings - Fork 47k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Flight] Encode the name of a function as an object property #30325
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
// We generate code where the call is at the line and column of the server executed code. | ||
// This allows us to use the original source map as the source map of this fake file to | ||
// point to the original source. | ||
let code; | ||
if (line <= 1) { | ||
code = '_=>' + ' '.repeat(col < 4 ? 0 : col - 4) + '_()\n' + comment; | ||
const minSize = encodedName.length + 8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot model a call on the first row with a column less than this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clever
@@ -1931,7 +1945,7 @@ function createFakeFunction<T>( | |||
let fn: FakeFunction<T>; | |||
try { | |||
// eslint-disable-next-line no-eval | |||
fn = (0, eval)(code); | |||
fn = (0, eval)(code)[name]; | |||
} catch (x) { | |||
// If eval fails, such as if in an environment that doesn't support it, | |||
// we fallback to creating a function here. It'll still have the right |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no longer true?
…k#30325) Unfortunately, Firefox doesn't include the name of a function in stack traces if you set it as either `.name` or `.displayName` at runtime. Only if you include it declarative. We also can't include it into a named function expression because not all possible names are expressible declaratively. E.g. spaces or punctuations. However, we can express any name if it's an object property and since object properties now give their name declarative to the function defined inside of them, we can declaratively express any name this way.
…k#30325) Unfortunately, Firefox doesn't include the name of a function in stack traces if you set it as either `.name` or `.displayName` at runtime. Only if you include it declarative. We also can't include it into a named function expression because not all possible names are expressible declaratively. E.g. spaces or punctuations. However, we can express any name if it's an object property and since object properties now give their name declarative to the function defined inside of them, we can declaratively express any name this way.
Unfortunately, Firefox doesn't include the name of a function in stack traces if you set it as either
.name
or.displayName
at runtime. Only if you include it declarative.We also can't include it into a named function expression because not all possible names are expressible declaratively. E.g. spaces or punctuations.
However, we can express any name if it's an object property and since object properties now give their name declarative to the function defined inside of them, we can declaratively express any name this way.