path-parser icon indicating copy to clipboard operation
path-parser copied to clipboard

test for function with `typeof` not `instanceof`

Open RamIdeas opened this issue 5 years ago • 1 comments

Allows environments (e.g. jest) to override the global Function constructor

Checking via instanceof resolved to false, which caused the Path#source property to be set incorrectly where partialTest would return {} rather than null when it wasn't meant to match

EDIT: actually, not sure if it is jest which is wrapping Function or the environment I am running my code in (Cloudflare Workers) which doesn't allow eval/new Function

RamIdeas avatar Nov 06 '20 18:11 RamIdeas

This change would be great, currently preventing this package from use in next.js middleware since it disallows references to Function. This is probably also true for all edge functions

kcirtaptrick avatar Mar 14 '22 19:03 kcirtaptrick