Unverified Commit 825753a2 authored by Tobias Koppers's avatar Tobias Koppers Committed by GitHub

Turbopack: name the module factory function (#73553)

### What?

In development give the module factory a useful name, so it's clear in stack traces that this is the module evaluation part of the execution.

This also fixes some bugs with the stack trace parser, which seems to struggle if function names contain brackets. The automatically inferred function name would be the module id, which contains brackets.
parent b98796b1
......@@ -139,7 +139,6 @@ export const CODE_FRAME_STYLES = `
}
.code-frame-link [data-text] {
display: inline-flex;
text-align: left;
margin: auto 6px;
}
......
......@@ -93,12 +93,12 @@ describe('ReactRefreshLogBox app', () => {
"description": "no",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:7) @ [project]/index.js [app-client] (ecmascript)
"source": "index.js (3:7) @ {module evaluation}
> 3 | throw new Error('no')
| ^",
"stack": [
"[project]/index.js [app-client] (ecmascript) index.js (3:7)",
"[project]/app/page.js [app-client] (ecmascript) app/page.js (2:1)",
"{module evaluation} index.js (3:7)",
"{module evaluation} app/page.js (2:1)",
],
}
`)
......@@ -938,8 +938,7 @@ describe('ReactRefreshLogBox app', () => {
"description": "test",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:11) @
{default export}
"source": "index.js (3:11) @ {default export}
> 3 | throw new Error('test')
| ^",
"stack": [
......@@ -1570,12 +1569,12 @@ export default function Home() {
"description": "utils error",
"environmentLabel": null,
"label": "Runtime Error",
"source": "app/utils.ts (1:7) @ [project]/app/utils.ts [app-client] (ecmascript)
"source": "app/utils.ts (1:7) @ {module evaluation}
> 1 | throw new Error('utils error')
| ^",
"stack": [
"[project]/app/utils.ts [app-client] (ecmascript) app/utils.ts (1:7)",
"[project]/app/page.js [app-client] (ecmascript) app/page.js (2:1)",
"{module evaluation} app/utils.ts (1:7)",
"{module evaluation} app/page.js (2:1)",
],
}
`)
......
......@@ -121,13 +121,13 @@ describe('ReactRefreshLogBox', () => {
"description": "no",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:7) @ [project]/index.js [ssr] (ecmascript)
"source": "index.js (3:7) @ {module evaluation}
> 3 | throw new Error('no')
| ^",
"stack": [
"[project]/index.js [ssr] (ecmascript) index.js (3:7)",
"[project]/pages/index.js [ssr] (ecmascript) <module evaluation> pages/index.js (1:1)",
"[project]/pages/index.js [ssr] (ecmascript) pages/index.js (1:1)",
"{module evaluation} index.js (3:7)",
"{module evaluation} pages/index.js (1:1)",
"{module evaluation} pages/index.js (1:1)",
"<FIXME-next-dist-dir>",
],
}
......@@ -162,13 +162,13 @@ describe('ReactRefreshLogBox', () => {
"description": "no",
"environmentLabel": null,
"label": "Runtime Error",
"source": "index.js (3:7) @ [project]/index.js [ssr] (ecmascript)
"source": "index.js (3:7) @ {module evaluation}
> 3 | throw new Error('no')
| ^",
"stack": [
"[project]/index.js [ssr] (ecmascript) index.js (3:7)",
"[project]/pages/index.js [ssr] (ecmascript) <module evaluation> pages/index.js (1:1)",
"[project]/pages/index.js [ssr] (ecmascript) pages/index.js (1:1)",
"{module evaluation} index.js (3:7)",
"{module evaluation} pages/index.js (1:1)",
"{module evaluation} pages/index.js (1:1)",
"<FIXME-next-dist-dir>",
],
}
......
......@@ -287,8 +287,7 @@ describe('ReactRefreshRegression', () => {
"description": "boom",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/index.js (1:36) @
{default export}
"source": "pages/index.js (1:36) @ {default export}
> 1 | export default function () { throw new Error('boom'); }
| ^",
"stack": [
......
......@@ -358,7 +358,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": "app/exports/app-code/react-dom-server-node-explicit/page.js (1:1) @ [project]/app/exports/app-code/react-dom-server-node-explicit/page.js [app-rsc] (ecmascript)
"source": "app/exports/app-code/react-dom-server-node-explicit/page.js (1:1) @ {module evaluation}
> 1 | import * as ReactDOMServerNode from 'react-dom/server.node'
| ^
......@@ -371,7 +371,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "react-dom/server is not supported in React Server Components.",
"source": "app/exports/app-code/react-dom-server-node-explicit/page.js (1:1) @ [project]/app/exports/app-code/react-dom-server-node-explicit/page.js [app-rsc] (ecmascript)
"source": "app/exports/app-code/react-dom-server-node-explicit/page.js (1:1) @ {module evaluation}
> 1 | import * as ReactDOMServerNode from 'react-dom/server.node'
| ^
......@@ -498,7 +498,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": "internal-pkg/server.node.js (1:1) @ [project]/internal-pkg/server.node.js [app-rsc] (ecmascript)
"source": "internal-pkg/server.node.js (1:1) @ {module evaluation}
> 1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
| ^
......@@ -511,7 +511,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "react-dom/server is not supported in React Server Components.",
"source": "internal-pkg/server.node.js (1:1) @ [project]/internal-pkg/server.node.js [app-rsc] (ecmascript)
"source": "internal-pkg/server.node.js (1:1) @ {module evaluation}
> 1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
| ^
......@@ -796,7 +796,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": "internal-pkg/server.node.js (1:1) @ [project]/internal-pkg/server.node.js [app-rsc] (ecmascript)
"source": "internal-pkg/server.node.js (1:1) @ {module evaluation}
> 1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
| ^
......@@ -809,7 +809,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "react-dom/server is not supported in React Server Components.",
"source": "internal-pkg/server.node.js (1:1) @ [project]/internal-pkg/server.node.js [app-rsc] (ecmascript)
"source": "internal-pkg/server.node.js (1:1) @ {module evaluation}
> 1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
| ^
......@@ -854,7 +854,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "Cannot read properties of undefined (reading 'ReactCurrentDispatcher')",
"source": "internal-pkg/server.node.js (1:1) @ [project]/internal-pkg/server.node.js [app-rsc] (ecmascript)
"source": "internal-pkg/server.node.js (1:1) @ {module evaluation}
> 1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
| ^
......@@ -867,7 +867,7 @@ describe('react-dom/server in React Server environment', () => {
expect(redbox).toMatchInlineSnapshot(`
{
"description": "react-dom/server is not supported in React Server Components.",
"source": "internal-pkg/server.node.js (1:1) @ [project]/internal-pkg/server.node.js [app-rsc] (ecmascript)
"source": "internal-pkg/server.node.js (1:1) @ {module evaluation}
> 1 | import * as ReactDOMServerEdge from 'react-dom/server.node'
| ^
......
......@@ -57,8 +57,7 @@ describe('middleware - development errors', () => {
"description": "boom",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.js (3:15) @
{default export}
"source": "middleware.js (3:15) @ {default export}
> 3 | throw new Error('boom')
| ^",
"stack": [
......@@ -268,7 +267,7 @@ describe('middleware - development errors', () => {
isTurbopack
? '\n ⨯ Error: booooom!' +
// TODO(veil): Should be sourcemapped
'\n at [project]/middleware.js [middleware-edge] (ecmascript)'
'\n at __TURBOPACK__module__evaluation__ (middleware.js:3:13)'
: '\n ⨯ Error: booooom!' +
// TODO: Should be anonymous method without a method name
'\n at <unknown> (middleware.js:3)' +
......@@ -288,11 +287,11 @@ describe('middleware - development errors', () => {
"description": "booooom!",
"environmentLabel": null,
"label": "Runtime Error",
"source": "middleware.js (3:13) @ [project]/middleware.js [middleware-edge] (ecmascript)
"source": "middleware.js (3:13) @ {module evaluation}
> 3 | throw new Error('booooom!')
| ^",
"stack": [
"[project]/middleware.js [middleware-edge] (ecmascript) middleware.js (3:13)",
"{module evaluation} middleware.js (3:13)",
],
}
`)
......
......@@ -353,11 +353,11 @@ describe('Client Navigation', () => {
"description": "An Expected error occurred",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/error-in-the-browser-global-scope.js (2:9) @ [project]/pages/error-in-the-browser-global-scope.js [client] (ecmascript)
"source": "pages/error-in-the-browser-global-scope.js (2:9) @ {module evaluation}
> 2 | throw new Error('An Expected error occurred')
| ^",
"stack": [
"[project]/pages/error-in-the-browser-global-scope.js [client] (ecmascript) pages/error-in-the-browser-global-scope.js (2:9)",
"{module evaluation} pages/error-in-the-browser-global-scope.js (2:9)",
],
}
`)
......
......@@ -236,8 +236,7 @@ describe('Client Navigation rendering', () => {
"description": "This is an expected error",
"environmentLabel": null,
"label": "Runtime Error",
"source": "pages/error-inside-page.js (2:9) @
{default export}
"source": "pages/error-inside-page.js (2:9) @ {default export}
> 2 | throw new Error('This is an expected error')
| ^",
"stack": [
......@@ -274,11 +273,11 @@ describe('Client Navigation rendering', () => {
"description": "aa is not defined",
"environmentLabel": null,
"label": "Runtime ReferenceError",
"source": "pages/error-in-the-global-scope.js (1:1) @ [project]/pages/error-in-the-global-scope.js [ssr] (ecmascript)
"source": "pages/error-in-the-global-scope.js (1:1) @ {module evaluation}
> 1 | aa = 10 //eslint-disable-line
| ^",
"stack": [
"[project]/pages/error-in-the-global-scope.js [ssr] (ecmascript) pages/error-in-the-global-scope.js (1:1)",
"{module evaluation} pages/error-in-the-global-scope.js (1:1)",
"<FIXME-next-dist-dir>",
],
}
......
......@@ -2425,11 +2425,11 @@ describe('Cache Components Errors', () => {
"description": ""use cache: private" must not be used within \`unstable_cache()\`.",
"environmentLabel": null,
"label": "Runtime Error",
"source": "app/use-cache-private-in-unstable-cache/page.tsx (21:38) @ [project]/app/use-cache-private-in-unstable-cache/page.tsx [app-rsc] (ecmascript)
"source": "app/use-cache-private-in-unstable-cache/page.tsx (21:38) @ {module evaluation}
> 21 | const getCachedData = unstable_cache(async () => {
| ^",
"stack": [
"[project]/app/use-cache-private-in-unstable-cache/page.tsx [app-rsc] (ecmascript) app/use-cache-private-in-unstable-cache/page.tsx (21:38)",
"{module evaluation} app/use-cache-private-in-unstable-cache/page.tsx (21:38)",
"<FIXME-file-protocol>",
"<FIXME-file-protocol>",
"<FIXME-next-dist-dir>",
......@@ -2486,7 +2486,7 @@ describe('Cache Components Errors', () => {
if (isDebugPrerender) {
expect(output).toMatchInlineSnapshot(`
"Error: "use cache: private" must not be used within \`unstable_cache()\`.
at 0 (bundler:///app/use-cache-private-in-unstable-cache/page.tsx:21:38)
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-unstable-cache/page.tsx:21:38)
at a (<next-dist-dir>)
at b (<next-dist-dir>)
19 | }
......@@ -2505,7 +2505,7 @@ describe('Cache Components Errors', () => {
} else {
expect(output).toMatchInlineSnapshot(`
"Error: "use cache: private" must not be used within \`unstable_cache()\`.
at 0 (bundler:///app/use-cache-private-in-unstable-cache/page.tsx:21:38)
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-unstable-cache/page.tsx:21:38)
at a (<next-dist-dir>)
19 | }
20 |
......@@ -2569,11 +2569,11 @@ describe('Cache Components Errors', () => {
"description": ""use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".",
"environmentLabel": null,
"label": "Runtime Error",
"source": "app/use-cache-private-in-use-cache/page.tsx (15:1) @ [project]/app/use-cache-private-in-use-cache/page.tsx [app-rsc] (ecmascript)
"source": "app/use-cache-private-in-use-cache/page.tsx (15:1) @ {module evaluation}
> 15 | async function Private() {
| ^",
"stack": [
"[project]/app/use-cache-private-in-use-cache/page.tsx [app-rsc] (ecmascript) app/use-cache-private-in-use-cache/page.tsx (15:1)",
"{module evaluation} app/use-cache-private-in-use-cache/page.tsx (15:1)",
"<FIXME-file-protocol>",
"<FIXME-file-protocol>",
"<FIXME-next-dist-dir>",
......@@ -2631,7 +2631,7 @@ describe('Cache Components Errors', () => {
if (isDebugPrerender) {
expect(output).toMatchInlineSnapshot(`
"Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
at 0 (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at a (<next-dist-dir>)
at b (<next-dist-dir>)
13 | }
......@@ -2642,7 +2642,7 @@ describe('Cache Components Errors', () => {
17 |
18 | return <p>Private</p>
Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
at 1 (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at c (<next-dist-dir>)
at d (<next-dist-dir>)
13 | }
......@@ -2661,8 +2661,8 @@ describe('Cache Components Errors', () => {
} else {
expect(output).toMatchInlineSnapshot(`
"Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
at 0 (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at 1 (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:16)
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:16)
at a (<next-dist-dir>)
13 | }
14 |
......@@ -2672,8 +2672,8 @@ describe('Cache Components Errors', () => {
17 |
18 | return <p>Private</p>
Error: "use cache: private" must not be used within "use cache". It can only be nested inside of another "use cache: private".
at 2 (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at 3 (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:16)
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:1)
at __TURBOPACK__module__evaluation__ (bundler:///app/use-cache-private-in-use-cache/page.tsx:15:16)
at b (<next-dist-dir>)
13 | }
14 |
......
......@@ -89,7 +89,7 @@ describe('non-root-project-monorepo', () => {
if (isTurbopack) {
// TODO the function name should be hidden
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"app/separate-file.ts (1:7) @ [project]/apps/web/app/separate-file.ts [app-rsc] (ecmascript)
"app/separate-file.ts (1:7) @ {module evaluation}
> 1 | throw new Error('Expected error')
| ^
......@@ -97,7 +97,7 @@ describe('non-root-project-monorepo', () => {
`)
expect(await getRedboxCallStack(browser)).toMatchInlineSnapshot(`
[
"[project]/apps/web/app/separate-file.ts [app-rsc] (ecmascript) app/separate-file.ts (1:7)",
"{module evaluation} app/separate-file.ts (1:7)",
"innerArrowFunction app/source-maps-rsc/page.tsx (13:28)",
"innerFunction app/source-maps-rsc/page.tsx (10:3)",
"Page app/source-maps-rsc/page.tsx (4:5)",
......@@ -134,7 +134,7 @@ describe('non-root-project-monorepo', () => {
if (isTurbopack) {
// TODO the function name should be hidden
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"app/separate-file.ts (1:7) @ [project]/apps/web/app/separate-file.ts [app-client] (ecmascript)
"app/separate-file.ts (1:7) @ {module evaluation}
> 1 | throw new Error('Expected error')
| ^
......@@ -142,7 +142,7 @@ describe('non-root-project-monorepo', () => {
`)
expect(await getRedboxCallStack(browser)).toMatchInlineSnapshot(`
[
"[project]/apps/web/app/separate-file.ts [app-client] (ecmascript) app/separate-file.ts (1:7)",
"{module evaluation} app/separate-file.ts (1:7)",
"innerArrowFunction app/source-maps-ssr/page.tsx (15:28)",
"innerFunction app/source-maps-ssr/page.tsx (12:3)",
"Page app/source-maps-ssr/page.tsx (6:5)",
......@@ -178,7 +178,7 @@ describe('non-root-project-monorepo', () => {
if (isTurbopack) {
// TODO the function name should be hidden
expect(await getRedboxSource(browser)).toMatchInlineSnapshot(`
"app/separate-file.ts (1:7) @ [project]/apps/web/app/separate-file.ts [app-client] (ecmascript)
"app/separate-file.ts (1:7) @ {module evaluation}
> 1 | throw new Error('Expected error')
| ^
......@@ -186,7 +186,7 @@ describe('non-root-project-monorepo', () => {
`)
expect(await getRedboxCallStack(browser)).toMatchInlineSnapshot(`
[
"[project]/apps/web/app/separate-file.ts [app-client] (ecmascript) app/separate-file.ts (1:7)",
"{module evaluation} app/separate-file.ts (1:7)",
"innerArrowFunction app/source-maps-client/page.tsx (16:28)",
"innerFunction app/source-maps-client/page.tsx (13:3)",
"effectCallback app/source-maps-client/page.tsx (7:5)",
......
......@@ -448,10 +448,10 @@ describe('app-dir - server source maps', () => {
'' +
'\nError: module-evaluation' +
// TODO(veil): Should map to no name like you'd get with native stacks without a bundler.
'\n at [project]/app/module-evaluation/module.js [app-rsc] (ecmascript) (app/module-evaluation/module.js:1:22)' +
'\n at __TURBOPACK__module__evaluation__ (app/module-evaluation/module.js:1:22)' +
// TODO(veil): Added frames from bundler should be sourcemapped (https://linear.app/vercel/issue/NDX-509/)
'\n at [project]/app/module-evaluation/page.js [app-rsc] (ecmascript) (app/module-evaluation/page.js:1:1)' +
'\n at [project]/app/module-evaluation/page.js [app-rsc] (ecmascript, Next.js Server Component) (.next'
'\n at __TURBOPACK__module__evaluation__ (app/module-evaluation/page.js:1:1)' +
'\n at __TURBOPACK__module__evaluation__ (.next'
)
} else {
expect(cliOutput).toContain(
......@@ -477,13 +477,13 @@ describe('app-dir - server source maps', () => {
"description": "module-evaluation",
"environmentLabel": "Prerender",
"label": "Console Error",
"source": "app/module-evaluation/module.js (1:22) @ [project]/app/module-evaluation/module.js [app-rsc] (ecmascript)
"source": "app/module-evaluation/module.js (1:22) @ {module evaluation}
> 1 | export const error = new Error('module-evaluation')
| ^",
"stack": [
"[project]/app/module-evaluation/module.js [app-rsc] (ecmascript) app/module-evaluation/module.js (1:22)",
"[project]/app/module-evaluation/page.js [app-rsc] (ecmascript) app/module-evaluation/page.js (1:1)",
"[project]/app/module-evaluation/page.js [app-rsc] (ecmascript, Next.js Server Component) app/module-evaluation/page.js (6:1)",
"{module evaluation} app/module-evaluation/module.js (1:22)",
"{module evaluation} app/module-evaluation/page.js (1:1)",
"{module evaluation} app/module-evaluation/page.js (6:1)",
"<FIXME-next-dist-dir>",
"Page <anonymous>",
],
......@@ -512,15 +512,10 @@ describe('app-dir - server source maps', () => {
}
} else {
if (isTurbopack) {
expect(
normalizeCliOutput(next.cliOutput).replaceAll(
/at \d+ /g,
'at <TurbopackModuleID> '
)
).toContain(
expect(normalizeCliOutput(next.cliOutput)).toContain(
'' +
'\nError: module-evaluation' +
'\n at <TurbopackModuleID> (bundler:///app/module-evaluation/module.js:1:22)' +
'\n at __TURBOPACK__module__evaluation__ (bundler:///app/module-evaluation/module.js:1:22)' +
// TODO(veil): Turbopack internals. Feel free to update. Tracked in https://linear.app/vercel/issue/NEXT-4362
'\n at Object.<anonymous>'
)
......
......@@ -99,8 +99,7 @@ describe('use-cache-close-over-function', () => {
'\n [function fn]' +
'\n ^^^^^^^^^^^' +
'\n at createCachedFn (app/server/page.tsx:6:3)' +
// TODO(veil): Should be source-mapped.
'\n at [project]'
'\n at __TURBOPACK__module__evaluation__ (app/server/page.tsx:12:24)'
: '' +
'Error: Functions cannot be passed directly to Client Components unless you explicitly expose it by marking it with "use server". Or maybe you meant to call this function rather than return it.' +
'\n [function fn]' +
......
......@@ -48,7 +48,7 @@ describe('use-cache-hanging-inputs', () => {
if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(`
"app/search-params/page.tsx (3:16) @ [project]/app/search-params/page.tsx [app-rsc] (ecmascript)
"app/search-params/page.tsx (3:16) @ {module evaluation}
1 | 'use cache'
2 |
......@@ -60,7 +60,7 @@ describe('use-cache-hanging-inputs', () => {
`)
expect(cliOutput).toContain(`Error: ${expectedTimeoutErrorMessage}
at [project]/app/search-params/page.tsx [app-rsc] (ecmascript)`)
at __TURBOPACK__module__evaluation__`)
} else {
expect(errorSource).toMatchInlineSnapshot(`
"app/search-params/page.tsx (3:16) @ eval
......@@ -102,7 +102,7 @@ describe('use-cache-hanging-inputs', () => {
if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(`
"app/search-params-caught/page.tsx (1:1) @ [project]/app/search-params-caught/page.tsx [app-rsc] (ecmascript)
"app/search-params-caught/page.tsx (1:1) @ {module evaluation}
> 1 | async function getSearchParam({
| ^
......@@ -112,7 +112,7 @@ describe('use-cache-hanging-inputs', () => {
`)
expect(cliOutput).toContain(`Error: ${expectedTimeoutErrorMessage}
at [project]/app/search-params-caught/page.tsx [app-rsc] (ecmascript)`)
at __TURBOPACK__module__evaluation__`)
} else {
expect(errorSource).toMatchInlineSnapshot(`
"app/search-params-caught/page.tsx (1:1) @ eval
......@@ -165,7 +165,7 @@ describe('use-cache-hanging-inputs', () => {
if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(`
"app/uncached-promise/page.tsx (10:13) @ [project]/app/uncached-promise/page.tsx [app-rsc] (ecmascript)
"app/uncached-promise/page.tsx (10:13) @ {module evaluation}
8 | }
9 |
......@@ -177,7 +177,7 @@ describe('use-cache-hanging-inputs', () => {
`)
expect(cliOutput).toContain(`Error: ${expectedTimeoutErrorMessage}
at [project]/app/uncached-promise/page.tsx [app-rsc] (ecmascript)`)
at __TURBOPACK__module__evaluation__`)
} else {
expect(errorSource).toMatchInlineSnapshot(`
"app/uncached-promise/page.tsx (10:13) @ eval
......@@ -219,7 +219,7 @@ describe('use-cache-hanging-inputs', () => {
if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(`
"app/uncached-promise-nested/page.tsx (16:1) @ [project]/app/uncached-promise-nested/page.tsx [app-rsc] (ecmascript)
"app/uncached-promise-nested/page.tsx (16:1) @ {module evaluation}
14 | }
15 |
......@@ -231,7 +231,7 @@ describe('use-cache-hanging-inputs', () => {
`)
expect(cliOutput).toContain(`Error: ${expectedTimeoutErrorMessage}
at [project]/app/uncached-promise-nested/page.tsx [app-rsc] (ecmascript)`)
at __TURBOPACK__module__evaluation__`)
} else {
expect(errorSource).toMatchInlineSnapshot(`
"app/uncached-promise-nested/page.tsx (16:1) @ eval
......@@ -274,7 +274,7 @@ describe('use-cache-hanging-inputs', () => {
if (isTurbopack) {
expect(errorSource).toMatchInlineSnapshot(`
"app/bound-args/page.tsx (13:15) @ [project]/app/bound-args/page.tsx [app-rsc] (ecmascript)
"app/bound-args/page.tsx (13:15) @ {module evaluation}
11 | const uncachedDataPromise = fetchUncachedData()
12 |
......@@ -286,7 +286,7 @@ describe('use-cache-hanging-inputs', () => {
`)
expect(cliOutput).toContain(`Error: ${expectedTimeoutErrorMessage}
at [project]/app/bound-args/page.tsx [app-rsc] (ecmascript)`)
at __TURBOPACK__module__evaluation__`)
} else {
expect(errorSource).toMatchInlineSnapshot(`
"app/bound-args/page.tsx (13:15) @ eval
......
......@@ -1493,7 +1493,7 @@ export async function getRedboxCallStack(
// `innerText` will be "${methodName}\n${location}".
// Ideally `innerText` would be "${methodName} ${location}"
// so that c&p automatically does the right thing.
const frame = frameElement.innerText.replace('\n', ' ')
const frame = frameElement.innerText.replace(/\n+/g, ' ')
// TODO: Special marker if source-mapping fails.
......
......@@ -554,6 +554,7 @@ function applyPhase(
) {
// Update module factories.
for (const [moduleId, factory] of newModuleFactories.entries()) {
applyModuleFactoryName(factory)
moduleFactories[moduleId] = factory
}
......@@ -1127,6 +1128,11 @@ function registerChunk([
]: ChunkRegistration) {
const chunkPath = getPathFromScript(chunkScript)
for (const [moduleId, moduleFactory] of Object.entries(chunkModules)) {
// Give the module factory a nice name to improve stack traces.
applyModuleFactoryName(
Array.isArray(moduleFactory) ? moduleFactory[0] : moduleFactory
)
registerCompressedModuleFactory(moduleId, moduleFactory)
addModuleToChunk(moduleId, chunkPath)
}
......
......@@ -117,17 +117,7 @@ function loadRuntimeChunkPath(
const chunkModules: CompressedModuleFactories = require(resolved)
for (const [moduleId, moduleFactory] of Object.entries(chunkModules)) {
if (!moduleFactories[moduleId]) {
if (Array.isArray(moduleFactory)) {
const [moduleFactoryFn, otherIds] = moduleFactory
moduleFactories[moduleId] = moduleFactoryFn
for (const otherModuleId of otherIds) {
moduleFactories[otherModuleId] = moduleFactoryFn
}
} else {
moduleFactories[moduleId] = moduleFactory
}
}
registerCompressedModuleFactory(moduleId, moduleFactory)
}
loadedChunks.add(chunkPath)
} catch (e) {
......@@ -151,18 +141,27 @@ function loadChunkUncached(chunkPath: ChunkPath) {
// However this is incompatible with hot reloading (since `import` doesn't use the require cache)
const chunkModules: CompressedModuleFactories = require(resolved)
for (const [moduleId, moduleFactory] of Object.entries(chunkModules)) {
registerCompressedModuleFactory(moduleId, moduleFactory)
}
}
function registerCompressedModuleFactory(
moduleId: ModuleId,
moduleFactory: Function | [Function, ModuleId[]]
) {
if (!moduleFactories[moduleId]) {
if (Array.isArray(moduleFactory)) {
const [moduleFactoryFn, otherIds] = moduleFactory
let [moduleFactoryFn, otherIds] = moduleFactory
applyModuleFactoryName(moduleFactoryFn)
moduleFactories[moduleId] = moduleFactoryFn
for (const otherModuleId of otherIds) {
moduleFactories[otherModuleId] = moduleFactoryFn
}
} else {
applyModuleFactoryName(moduleFactory)
moduleFactories[moduleId] = moduleFactory
}
}
}
}
function loadChunkAsync(
......
......@@ -625,3 +625,10 @@ contextPrototype.z = requireStub
type ContextConstructor<M> = {
new (module: Module): TurbopackBaseContext<M>
}
function applyModuleFactoryName(factory: Function) {
// Give the module factory a nice name to improve stack traces.
Object.defineProperty(factory, 'name', {
value: '__TURBOPACK__module__evaluation__',
})
}
......@@ -9,7 +9,7 @@ use turbopack_core::{
context::AssetContext,
environment::{ChunkLoading, Environment},
};
use turbopack_ecmascript::utils::StringifyJs;
use turbopack_ecmascript::{magic_identifier, utils::StringifyJs};
use crate::{RuntimeType, asset_context::get_runtime_asset_context, embed_js::embed_static_code};
......@@ -35,6 +35,12 @@ pub async fn get_browser_runtime_code(
match runtime_type {
RuntimeType::Production => runtime_base_code.push("browser/runtime/base/build-base.ts"),
RuntimeType::Development => {
debug_assert!(
// The dev runtime makes this assumption. If that's no longer true, we need to
// update the runtime code.
magic_identifier::mangle("module evaluation").as_str()
== "__TURBOPACK__module__evaluation__"
);
runtime_base_code.push("browser/runtime/base/dev-base.ts");
}
#[cfg(feature = "test")]
......
......@@ -155,6 +155,10 @@ mod tests {
#[test]
fn test_encode() {
assert_eq!(
mangle("module evaluation"),
"__TURBOPACK__module__evaluation__"
);
assert_eq!(mangle("Hello World"), "__TURBOPACK__Hello__World__");
assert_eq!(mangle("Hello_World"), "__TURBOPACK__Hello_World__");
assert_eq!(mangle("Hello__World"), "__TURBOPACK__Hello_$5f$World__");
......@@ -176,6 +180,10 @@ mod tests {
#[test]
fn test_decode() {
assert_eq!(
unmangle("__TURBOPACK__module__evaluation__"),
"module evaluation"
);
assert_eq!(unmangle("__TURBOPACK__Hello__World__"), "Hello World");
assert_eq!(unmangle("__TURBOPACK__Hello_World__"), "Hello_World");
assert_eq!(unmangle("__TURBOPACK__Hello_$5f$World__"), "Hello__World");
......
......@@ -414,6 +414,12 @@ contextPrototype.U = relativeURL;
throw new Error('dynamic usage of require is not supported');
}
contextPrototype.z = requireStub;
function applyModuleFactoryName(factory) {
// Give the module factory a nice name to improve stack traces.
Object.defineProperty(factory, 'name', {
value: '__TURBOPACK__module__evaluation__'
});
}
/* eslint-disable @typescript-eslint/no-unused-vars */ /// <reference path="../shared/runtime-utils.ts" />
/// A 'base' utilities to support runtime can have externals.
/// Currently this is for node.js / edge runtime both.
......@@ -571,17 +577,7 @@ function loadRuntimeChunkPath(sourcePath, chunkPath) {
const resolved = path.resolve(RUNTIME_ROOT, chunkPath);
const chunkModules = require(resolved);
for (const [moduleId, moduleFactory] of Object.entries(chunkModules)){
if (!moduleFactories[moduleId]) {
if (Array.isArray(moduleFactory)) {
const [moduleFactoryFn, otherIds] = moduleFactory;
moduleFactories[moduleId] = moduleFactoryFn;
for (const otherModuleId of otherIds){
moduleFactories[otherModuleId] = moduleFactoryFn;
}
} else {
moduleFactories[moduleId] = moduleFactory;
}
}
registerCompressedModuleFactory(moduleId, moduleFactory);
}
loadedChunks.add(chunkPath);
} catch (e) {
......@@ -601,18 +597,23 @@ function loadChunkUncached(chunkPath) {
// However this is incompatible with hot reloading (since `import` doesn't use the require cache)
const chunkModules = require(resolved);
for (const [moduleId, moduleFactory] of Object.entries(chunkModules)){
registerCompressedModuleFactory(moduleId, moduleFactory);
}
}
function registerCompressedModuleFactory(moduleId, moduleFactory) {
if (!moduleFactories[moduleId]) {
if (Array.isArray(moduleFactory)) {
const [moduleFactoryFn, otherIds] = moduleFactory;
let [moduleFactoryFn, otherIds] = moduleFactory;
applyModuleFactoryName(moduleFactoryFn);
moduleFactories[moduleId] = moduleFactoryFn;
for (const otherModuleId of otherIds){
moduleFactories[otherModuleId] = moduleFactoryFn;
}
} else {
applyModuleFactoryName(moduleFactory);
moduleFactories[moduleId] = moduleFactory;
}
}
}
}
function loadChunkAsync(chunkData) {
const chunkPath = typeof chunkData === 'string' ? chunkData : chunkData.path;
......
......@@ -425,6 +425,12 @@ contextPrototype.U = relativeURL;
throw new Error('dynamic usage of require is not supported');
}
contextPrototype.z = requireStub;
function applyModuleFactoryName(factory) {
// Give the module factory a nice name to improve stack traces.
Object.defineProperty(factory, 'name', {
value: '__TURBOPACK__module__evaluation__'
});
}
/**
* This file contains runtime types and functions that are shared between all
* Turbopack *development* ECMAScript runtimes.
......@@ -1038,6 +1044,7 @@ function disposePhase(outdatedModules, disposedModules) {
function applyPhase(outdatedSelfAcceptedModules, newModuleFactories, outdatedModuleParents, reportError) {
// Update module factories.
for (const [moduleId, factory] of newModuleFactories.entries()){
applyModuleFactoryName(factory);
moduleFactories[moduleId] = factory;
}
// TODO(alexkirsz) Run new runtime entries here.
......@@ -1475,6 +1482,8 @@ function createModuleHot(moduleId, hotData) {
function registerChunk([chunkScript, chunkModules, runtimeParams]) {
const chunkPath = getPathFromScript(chunkScript);
for (const [moduleId, moduleFactory] of Object.entries(chunkModules)){
// Give the module factory a nice name to improve stack traces.
applyModuleFactoryName(Array.isArray(moduleFactory) ? moduleFactory[0] : moduleFactory);
registerCompressedModuleFactory(moduleId, moduleFactory);
addModuleToChunk(moduleId, chunkPath);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment