(attributeSelector: string | string[])
| 290 | } |
| 291 | |
| 292 | setAttributeSelector(attributeSelector: string | string[]): void { |
| 293 | if (!attributeSelector) { |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | if (Array.isArray(attributeSelector)) { |
| 298 | attributeSelector.forEach((value) => this.setAttributeSelector(value)); |
| 299 | |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | const re = new RegExp(this.getAttributeSelectorRegex()); |
| 304 | const exec = re.exec(attributeSelector); |
| 305 | |
| 306 | if (!exec) { |
| 307 | return; |
| 308 | } |
| 309 | |
| 310 | const term = exec[3]; |
| 311 | |
| 312 | let attributeSelectorType = exec[2]; |
| 313 | let selector = term; |
| 314 | |
| 315 | // it is empty if the attribute selector is following: [class=test] |
| 316 | if (attributeSelectorType === '') { |
| 317 | attributeSelectorType = '='; |
| 318 | } |
| 319 | |
| 320 | if (term.charAt(0).match(/"|'/)) { |
| 321 | selector = term.slice(1, exec[3].length - 1); |
| 322 | } |
| 323 | |
| 324 | const attributeSelectorKey = attributeSelectorType + selector; |
| 325 | |
| 326 | this.attributeSelectors[attributeSelectorKey] = { |
| 327 | type: exec[1], |
| 328 | originalString: attributeSelector, |
| 329 | regexType: attributeSelectorType, |
| 330 | nameGeneratorCounter: new NameGenerator('attribute'), |
| 331 | }; |
| 332 | |
| 333 | // then, we need to replace any original selector that would be matching this rule with a |
| 334 | // rename that still match the replacement |
| 335 | Object.keys(this.values).forEach((key) => { |
| 336 | const r = AttributeLibrary.replaceAnAttributeSelector( |
| 337 | false, |
| 338 | attributeSelectorKey, |
| 339 | this.attributeSelectors[attributeSelectorKey], |
| 340 | key, |
| 341 | ); |
| 342 | |
| 343 | if (r !== false) { |
| 344 | const prev = this.values[key]; |
| 345 | |
| 346 | this.values[key] = r; |
| 347 | delete this.compressedValues[prev]; |
| 348 | this.compressedValues[r] = key; |
| 349 | } |
no test coverage detected