(path)
| 798 | |
| 799 | // [{a, ...b}] = c; |
| 800 | ArrayPattern(path) { |
| 801 | type LhsAndRhs = { left: t.ObjectPattern; right: t.Identifier }; |
| 802 | const objectPatterns: LhsAndRhs[] = []; |
| 803 | const { scope } = path; |
| 804 | const uidIdentifiers: t.Identifier[] = []; |
| 805 | |
| 806 | visitObjectRestElements(path, path => { |
| 807 | const objectPattern = path.parentPath as NodePath<t.ObjectPattern>; |
| 808 | |
| 809 | const uid = scope.generateUidIdentifier("ref"); |
| 810 | objectPatterns.push({ left: objectPattern.node, right: uid }); |
| 811 | uidIdentifiers.push(uid); |
| 812 | |
| 813 | objectPattern.replaceWith(t.cloneNode(uid)); |
| 814 | path.skip(); |
| 815 | }); |
| 816 | |
| 817 | if (objectPatterns.length > 0) { |
| 818 | const patternParentPath = path.findParent( |
| 819 | path => !(path.isPattern() || path.isObjectProperty()), |
| 820 | )!; |
| 821 | const patternParent = patternParentPath.node; |
| 822 | switch (patternParent.type) { |
| 823 | case "VariableDeclarator": |
| 824 | patternParentPath.insertAfter( |
| 825 | objectPatterns.map(({ left, right }) => |
| 826 | t.variableDeclarator(left, right), |
| 827 | ), |
| 828 | ); |
| 829 | break; |
| 830 | case "AssignmentExpression": |
| 831 | { |
| 832 | for (const uidIdentifier of uidIdentifiers) { |
| 833 | scope.push({ id: t.cloneNode(uidIdentifier) }); |
| 834 | } |
| 835 | patternParentPath.insertAfter( |
| 836 | objectPatterns.map(({ left, right }) => |
| 837 | t.assignmentExpression("=", left, right), |
| 838 | ), |
| 839 | ); |
| 840 | } |
| 841 | break; |
| 842 | default: |
| 843 | throw new Error( |
| 844 | `Unexpected pattern parent type: ${patternParent.type}`, |
| 845 | ); |
| 846 | } |
| 847 | } |
| 848 | }, |
| 849 | |
| 850 | // var a = { ...b, ...c } |
| 851 | ObjectExpression(path, file) { |
nothing calls this directly
no test coverage detected