| 103 | }, |
| 104 | }, |
| 105 | create(context) { |
| 106 | const globalScope = context.sourceCode.scopeManager.globalScope; |
| 107 | |
| 108 | const nameMap = new Map(); |
| 109 | const renameMap = new Map(); |
| 110 | const polyfilledSet = new Set(); |
| 111 | |
| 112 | for (const option of context.options) { |
| 113 | const names = option.ignore || []; |
| 114 | nameMap.set( |
| 115 | option.name, |
| 116 | new Map(names.map((name) => [name, { ignored: true }])), |
| 117 | ); |
| 118 | if (option.into) { |
| 119 | renameMap.set(option.name, option.into); |
| 120 | } |
| 121 | if (option.polyfilled) { |
| 122 | for (const propertyName of option.polyfilled) { |
| 123 | polyfilledSet.add(`${option.name}${propertyName[0].toUpperCase()}${propertyName.slice(1)}`); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | let reported; |
| 129 | |
| 130 | return { |
| 131 | Program() { |
| 132 | reported = new Set(); |
| 133 | }, |
| 134 | [identifierSelector](node) { |
| 135 | if (node.parent.type === 'Property' && node.parent.key === node) { |
| 136 | // If the identifier is the key for this property declaration, it |
| 137 | // can't be referring to a primordials member. |
| 138 | return; |
| 139 | } |
| 140 | if (reported.has(node.range[0])) { |
| 141 | return; |
| 142 | } |
| 143 | const name = node.name; |
| 144 | const parent = getDestructuringAssignmentParent( |
| 145 | context.sourceCode.getScope(node), |
| 146 | node, |
| 147 | ); |
| 148 | const parentName = parent?.name; |
| 149 | if (!isTarget(nameMap, name) && (!isTarget(nameMap, parentName) || isIgnored(nameMap, parentName, name))) { |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | const defs = globalScope.set.get(name)?.defs; |
| 154 | if (parentName && isTarget(nameMap, parentName)) { |
| 155 | if (defs?.[0].name.name !== 'primordials' && |
| 156 | !reported.has(parent.range[0]) && |
| 157 | parent.parent?.id?.type !== 'Identifier') { |
| 158 | reported.add(node.range[0]); |
| 159 | const into = renameMap.get(name); |
| 160 | context.report({ |
| 161 | node, |
| 162 | messageId: 'error', |