( id: Identifier, parent: Node | null, parentStack: Node[], )
| 124 | } |
| 125 | |
| 126 | export function isReferencedIdentifier( |
| 127 | id: Identifier, |
| 128 | parent: Node | null, |
| 129 | parentStack: Node[], |
| 130 | ): boolean { |
| 131 | if (__BROWSER__) { |
| 132 | return false |
| 133 | } |
| 134 | |
| 135 | if (!parent) { |
| 136 | return true |
| 137 | } |
| 138 | |
| 139 | // is a special keyword but parsed as identifier |
| 140 | if (id.name === 'arguments') { |
| 141 | return false |
| 142 | } |
| 143 | |
| 144 | if (isReferenced(id, parent, parentStack[parentStack.length - 2])) { |
| 145 | return true |
| 146 | } |
| 147 | |
| 148 | // babel's isReferenced check returns false for ids being assigned to, so we |
| 149 | // need to cover those cases here |
| 150 | switch (parent.type) { |
| 151 | case 'AssignmentExpression': |
| 152 | case 'AssignmentPattern': |
| 153 | return true |
| 154 | case 'ObjectProperty': |
| 155 | return parent.key !== id && isInDestructureAssignment(parent, parentStack) |
| 156 | case 'ArrayPattern': |
| 157 | return isInDestructureAssignment(parent, parentStack) |
| 158 | } |
| 159 | |
| 160 | return false |
| 161 | } |
| 162 | |
| 163 | export function isInDestructureAssignment( |
| 164 | parent: Node, |
no test coverage detected