UNPKG

@beenotung/tslib

Version:
42 lines 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.safeWrapFunction = exports.wrapFunction = void 0; const array_1 = require("./array"); let f_name; /* tslint:disable:ban-types */ /** * @description may not work after being minify due to scoped name collision * */ function wrapFunction(_host_function_, n = _host_function_.length, name = _host_function_.name) { /* tslint:enable:ban-types */ const args = array_1.mapArray(new Array(n), (x, i) => 'a' + i).join(','); /* tslint:disable */ let newF = undefined; eval(`newF=function ${name}(${args}){return ${f_name}.apply(null,arguments);}`); return newF; /* tslint:enable */ } exports.wrapFunction = wrapFunction; f_name = wrapFunction .toString() .split('(')[1] .split(',')[0]; /* tslint:disable:ban-types */ /** * @description safe under minify, but occur more call stack size * */ function safeWrapFunction(_host_function_, n = _host_function_.length, name = _host_function_.name) { /* tslint:enable:ban-types */ const args = array_1.mapArray(new Array(n), (x, i) => 'a' + i).join(','); /* tslint:disable */ return eval(`(function() { return function(f) { return function ${name}(${args}) { return f.apply(null, arguments); }; }; })()`)(_host_function_); /* tslint:enable */ } exports.safeWrapFunction = safeWrapFunction; //# sourceMappingURL=reflection.js.map