next.js
c4c3aee9 - Fix `--no-mangling` for `"use cache"` functions (#78993)

Commit
230 days ago
Fix `--no-mangling` for `"use cache"` functions (#78993) When mangling is disabled with `next build --no-mangling`, the function names of `"use cache"` functions are currently still mangled. The reason is that those functions are transformed to inline function expressions whose names are removed by the SWC minifier even if `mangle` is `false`. Original: ```js 'use cache' export async function getCachedData() { return functionThatMightThrow() } ``` Transformed by the Next.js compiler during `next dev`: ```js export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "<id>", 0, async function getCachedData() { return functionThatMightThrow() }); ``` Transformed by the Next.js compiler during `next build`: ```js export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "<id>", 0, async function () { return functionThatMightThrow() }); ``` By setting `keep_fnames` to `true` in SWC's `compress` options, we can ensure that those function expression names are preserved when building with `--no-mangling`, which is helpful when looking at error stacks or traces.
Author
Parents
Loading