@jsonjoy.com/codegen
Version:
No-dependencies, low-level, high-performance JIT code generation package for JavaScript
20 lines • 632 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSwitch = void 0;
const dynamicFunction_1 = require("./dynamicFunction");
/**
* Switcher for code generation. It first executes "evaluation" function
* 3 times, and then generates optimized code.
*/
const createSwitch = (fn, codegen) => {
let counter = 0;
const [proxy, set] = (0, dynamicFunction_1.dynamicFunction)((...args) => {
if (counter > 2)
set(codegen());
counter++;
return fn(...args);
});
return proxy;
};
exports.createSwitch = createSwitch;
//# sourceMappingURL=switch.js.map