UNPKG

react-imported-component

Version:
30 lines (29 loc) 1.23 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getFunctionSignature = exports.importMatch = void 0; var trimImport = function (str) { return str.replace(/['"]/g, ''); }; var importMatch = function (functionString) { var markMatches = functionString.match(/`imported_(.*?)_component`/g) || []; return markMatches.map(function (match) { return match && trimImport((match.match(/`imported_(.*?)_component`/i) || [])[1]); }); }; exports.importMatch = importMatch; /** * the intention of this function is to "clear some (minification) noise from the function * basically from file to file different "short" names could be used * @param fn */ var getFunctionSignature = function (fn) { return String(fn) // quotes .replace(/(["'])/g, '`') // comments .replace(/\/\*([^\*]*)\*\//gi, '') // webpack specific .replace(/Promise.resolve\([^)]*\)/, '-we()') .replace(/\w+.e\([^)]*\)/, '-we()') .replace(/\w+.\w.bind\(/, '-wbind(') .replace(/\w+.bind\(/, '-wbind(') // prefix imported .replace(/([A-z0-9_]+)\(`imported_/g, '$(`imported_'); }; exports.getFunctionSignature = getFunctionSignature;