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