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AAC,CAAC;AACzE,CAAC","sourcesContent":["const REACT_LIFECYCLE_EXCLUSIONS = [\n 'setState',\n 'render',\n 'componentWillMount',\n 'UNSAFE_componentWillMount',\n 'componentDidMount',\n 'componentWillReceiveProps',\n 'UNSAFE_componentWillReceiveProps',\n 'shouldComponentUpdate',\n 'componentWillUpdate',\n 'getSnapshotBeforeUpdate',\n 'UNSAFE_componentWillUpdate',\n 'componentDidUpdate',\n 'componentWillUnmount',\n];\n\n/**\n * Allows you to hoist methods, except those in an exclusion set from a source object into a destination object.\n *\n * @public\n * @param destination - The instance of the object to hoist the methods onto.\n * @param source - The instance of the object where the methods are hoisted from.\n * @param exclusions - (Optional) What methods to exclude from being hoisted.\n * @returns An array of names of methods that were hoisted.\n */\nexport function hoistMethods(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n destination: any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n source: any,\n exclusions: string[] = REACT_LIFECYCLE_EXCLUSIONS,\n): string[] {\n let hoisted: string[] = [];\n for (let methodName in source) {\n if (\n typeof source[methodName] === 'function' &&\n destination[methodName] === undefined &&\n (!exclusions || exclusions.indexOf(methodName) === -1)\n ) {\n hoisted.push(methodName);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n destination[methodName] = function(...args: any[]): void {\n source[methodName](...args);\n };\n }\n }\n\n return hoisted;\n}\n\n/**\n * Provides a method for convenience to unhoist hoisted methods.\n *\n * @public\n * @param source - The source object upon which methods were hoisted.\n * @param methodNames - An array of method names to unhoist.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function unhoistMethods(source: any, methodNames: string[]): void {\n methodNames.forEach((methodName: string) => delete source[methodName]);\n}\n"]}
\No newline at end of file