In the catch block, if the error is an instance of error, a new error is thrown otherwise, the error is simply thrown. There must be a reason behind this way of handling the error, which i do not know yet.
export function jsoncParse(data: string) { try { return new Function(`return ${strip(data).trim()}`)() } catch { // Silently ignore any error // That's what tsc/jsonc-parser did after all return {} }}
This jsoncParse function returns a new function that returns the following function
return new Function(`return ${strip(data).trim()}`)()
// Create a global property with `var`var x = 10;function createFunction1() { const x = 20; return new Function("return x;"); // this `x` refers to global `x`}function createFunction2() { const x = 20; function f() { return x; // this `x` refers to the local `x` above } return f;}const f1 = createFunction1();console.log(f1()); // 10const f2 = createFunction2();console.log(f2()); // 20
Here, we can see that jsoncParse returns the code below:
return new Function(`return ${strip(data).trim()}`)()