Check that a function doesn’t use closure in JavaScript

In JavaScript, functions can’t be serialized because they close over their parent environment. Is there any way to check/enforce that a function doesn’t use variables from its parent environment?

E.g. something like:


function sum(a, b) {
   return a + b;
}

const greeting = "hello";
function greet() {
   console.log(greeting);
}

usesClosure(sum); // false
usesClosure(greet); // true