( fn: Node, module: SourceModule )
| 1753 | |
| 1754 | // e.g. `Component.prototype.forceUpdate = function () { ... }` in compiled dependencies |
| 1755 | const es5ProtoMethodOf = ( |
| 1756 | fn: Node, |
| 1757 | module: SourceModule |
| 1758 | ): Es5ProtoMethod | undefined => { |
| 1759 | if (fn.type !== "FunctionExpression") return |
| 1760 | const [rhs, assign] = operatorOf(fn) |
| 1761 | if ( |
| 1762 | assign?.type !== "AssignmentExpression" || |
| 1763 | assign.operator !== "=" || |
| 1764 | assign.right !== rhs || |
| 1765 | !isDiscardedAssignment(assign) |
| 1766 | ) |
| 1767 | return |
| 1768 | const left = unwrapExpression(assign.left) |
| 1769 | if (left.type !== "MemberExpression") return |
| 1770 | const methodKey = staticMemberKeyOf(left, module) |
| 1771 | if (methodKey === undefined) return |
| 1772 | const proto = unwrapExpression(left.object) |
| 1773 | if (proto.type !== "MemberExpression" || memberNameOf(proto) !== "prototype") |
| 1774 | return |
| 1775 | const ctorNode = unwrapExpression(proto.object) |
| 1776 | if (ctorNode.type !== "Identifier") return |
| 1777 | const ctorBinding = module.scopes.byId.get(ctorNode)?.binding |
| 1778 | if (!ctorBinding || ctorBinding.writes.length > 0) return |
| 1779 | const isCtorFn = |
| 1780 | ctorBinding.kind === "function" || |
| 1781 | (ctorBinding.declaration.type === "VariableDeclarator" && |
| 1782 | ctorBinding.declaration.id === ctorBinding.id && |
| 1783 | !!ctorBinding.declaration.init && |
| 1784 | unwrapExpression(ctorBinding.declaration.init).type === |
| 1785 | "FunctionExpression") |
| 1786 | return isCtorFn ? { ctorBinding, methodKey } : undefined |
| 1787 | } |
| 1788 | |
| 1789 | // whether `fn`'s `this` reads cannot reach any object literal and are skipped by |
| 1790 | // `thisReadsOf`: class constructors, non-detached class/ES5-prototype methods, |
no test coverage detected