bef709bc74
## 🐛 What's in there? `foo instanceof Function` is wrongly considered as Dynamic code evaluation by our static analyzer. This PR fixes it. - [ ] Related issues linked using `fixes #number` - [x] Integration tests added - [x] Errors have a helpful link attached, see `contributing.md` ## 🧪 How to reproduce? 1. Create a simple repro in `examples` folder: ```js // examples/instance-of-function/pages/index.js export default function Home() { return <h1>home</h1> } // examples/instance-of-function/middleware.js import { NextResponse } from 'next/server' export default async function handler() { console.log('is arrow a function?', (() => {}) instanceof Function) return NextResponse.next() } ``` 1. build with next `pnpm next build examples/instance-of-function` > the build fails 1. rebuild next to include PR's fix `pnpm build` 1. build with new next `pnpm next build examples/instance-of-function` > the build works ## 📔 Notes to reviewers `hooks.expression.for(`${prefix}Function`).tap(NAME, handleExpression)` is actually legacy code from the original implementation. It's used when finding `Function` regardless of how it is used. We only want to find `new Function()` or `Function()`, which `hooks.calls` and `hooks.new` are covering. `eval instanceof Function` is perfectly legit code on the edge, despite its uselessness :lol-think: Because we got multiple people asking "how do I relax this error when my code contains unreachable dynamic code evaluation", I've copy-pasted details about `config.unstable_allowDynamic` into the error page. Because users do not always click links :blob_shrug: |
||
---|---|---|
.. | ||
config | ||
loaders | ||
plugins | ||
require-hook.ts | ||
stringify-request.ts |