| 176 | } |
| 177 | |
| 178 | const processMap = (opts: ProcessMapOpts) => { |
| 179 | const { map, current, componentReportItem, filepath, localMaps, skipRange } = opts |
| 180 | const { reportItemType: type, kind, componentName: name } = componentReportItem |
| 181 | |
| 182 | map.value.forEach((attrNode, attrName) => { |
| 183 | if (box.isLiteral(attrNode) || box.isEmptyInitializer(attrNode)) { |
| 184 | const value = box.isLiteral(attrNode) ? (attrNode.value as string) : true |
| 185 | |
| 186 | const propReportItem = { |
| 187 | index: String(id++), |
| 188 | componentIndex: String(componentReportItem.componentIndex), |
| 189 | componentName: name, |
| 190 | tokenType: undefined, |
| 191 | propName: attrName, |
| 192 | reportItemKind: 'utility', |
| 193 | reportItemType: type, |
| 194 | kind, |
| 195 | filepath, |
| 196 | path: current.concat(attrName), |
| 197 | value, |
| 198 | isKnownValue: false, |
| 199 | range: skipRange ? null : map.getRange(), |
| 200 | } as PropertyReportItem |
| 201 | |
| 202 | componentReportItem.contains.push(propReportItem.index) |
| 203 | |
| 204 | if (conditions.has(attrName)) { |
| 205 | addTo(globalMaps.byConditionName, attrName, propReportItem.index) |
| 206 | addTo(localMaps.byConditionName, attrName, propReportItem.index) |
| 207 | propReportItem.propName = current[0] ?? attrName |
| 208 | propReportItem.isKnownValue = isKnownUtility(propReportItem, componentReportItem) |
| 209 | propReportItem.conditionName = attrName |
| 210 | } else { |
| 211 | if (current.length && conditions.has(current[0])) { |
| 212 | propReportItem.conditionName = current[0] |
| 213 | |
| 214 | // TODO: when using nested conditions |
| 215 | // should we add the reportItem.id for each of them or just the first one? |
| 216 | // (currently just the first one) |
| 217 | addTo(globalMaps.byConditionName, current[0], propReportItem.index) |
| 218 | addTo(localMaps.byConditionName, current[0], propReportItem.index) |
| 219 | } |
| 220 | |
| 221 | // TODO: Split this to new function |
| 222 | const propName = ctx.utility.resolveShorthand(attrName) |
| 223 | const tokenType = ctx.utility.getTokenType(propName) |
| 224 | if (tokenType) { |
| 225 | propReportItem.reportItemKind = 'token' |
| 226 | propReportItem.tokenType = tokenType |
| 227 | } |
| 228 | |
| 229 | propReportItem.propName = propName |
| 230 | propReportItem.isKnownValue = isKnownUtility(propReportItem, componentReportItem) |
| 231 | |
| 232 | addTo(globalMaps.byPropertyName, propName, propReportItem.index) |
| 233 | addTo(localMaps.byPropertyName, propName, propReportItem.index) |
| 234 | |
| 235 | if (tokenType) { |