@markuplint/selector 4.0.0-alpha.5 → 4.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2023 Yusuke Hirao
3
+ Copyright (c) 2017-2024 Yusuke Hirao
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -186,42 +186,34 @@ el, selector) {
186
186
  tagSelector = el.localName;
187
187
  specificity[2] = 1;
188
188
  }
189
- if (selector.attrName) {
190
- const selectorAttrName = selector.attrName;
191
- const matchedAttrNameList = [...el.attributes].map(attr => {
192
- const attrName = attr.name;
193
- const matchedAttrName = regexSelectorMatches(selectorAttrName, attrName, isPureHTMLElement(el));
189
+ const isPure = isPureHTMLElement(el);
190
+ if (selector.attrName || selector.attrValue) {
191
+ const matchedAttrList = [...el.attributes]
192
+ .map(attr => {
193
+ const matchedAttrName = regexSelectorMatches(selector.attrName, attr.name, isPure);
194
+ if (selector.attrName && !matchedAttrName) {
195
+ return null;
196
+ }
197
+ const matchedAttrValue = regexSelectorMatches(selector.attrValue, attr.value, isPure);
198
+ if (selector.attrValue && !matchedAttrValue) {
199
+ return null;
200
+ }
194
201
  if (matchedAttrName) {
195
202
  delete matchedAttrName.$0;
196
- data = {
197
- ...data,
198
- ...matchedAttrName,
199
- };
200
- specifiedAttr.set(attrName, '');
201
203
  }
202
- return matchedAttrName;
203
- });
204
- if (!matchedAttrNameList.some(_ => !!_)) {
205
- matched = false;
206
- }
207
- }
208
- if (selector.attrValue) {
209
- const selectorAttrValue = selector.attrValue;
210
- const matchedAttrValueList = [...el.attributes].map(attr => {
211
- const attrName = attr.name;
212
- const attrValue = attr.value;
213
- const matchedAttrValue = regexSelectorMatches(selectorAttrValue, attrValue, isPureHTMLElement(el));
214
204
  if (matchedAttrValue) {
215
205
  delete matchedAttrValue.$0;
216
- data = {
217
- ...data,
218
- ...matchedAttrValue,
219
- };
220
- specifiedAttr.set(attrName, attrValue);
221
206
  }
222
- return matchedAttrValue;
223
- });
224
- if (!matchedAttrValueList.some(_ => !!_)) {
207
+ data = {
208
+ ...data,
209
+ ...matchedAttrName,
210
+ ...matchedAttrValue,
211
+ };
212
+ specifiedAttr.set(attr.name, matchedAttrValue ? attr.value : '');
213
+ return matchedAttrValue ?? matchedAttrName ?? null;
214
+ })
215
+ .filter((a) => !!a);
216
+ if (matchedAttrList.length === 0) {
225
217
  matched = false;
226
218
  }
227
219
  }
@@ -1,3 +1,3 @@
1
- export declare function regexSelectorMatches(reg: string, raw: string, ignoreCase: boolean): {
1
+ export declare function regexSelectorMatches(reg: string | undefined, raw: string, ignoreCase: boolean): {
2
2
  [x: string]: string;
3
3
  } | null;
@@ -1,4 +1,7 @@
1
1
  export function regexSelectorMatches(reg, raw, ignoreCase) {
2
+ if (!reg) {
3
+ return null;
4
+ }
2
5
  const res = {};
3
6
  const pattern = toRegexp(reg);
4
7
  const regex = new RegExp(pattern instanceof RegExp ? pattern : `^${pattern.trim()}$`, ignoreCase ? 'i' : undefined);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/selector",
3
- "version": "4.0.0-alpha.5",
3
+ "version": "4.0.0-alpha.7",
4
4
  "description": "Extended W3C Selectors matcher",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -25,15 +25,15 @@
25
25
  "clean": "tsc --build --clean"
26
26
  },
27
27
  "dependencies": {
28
- "@markuplint/ml-spec": "4.0.0-alpha.5",
29
- "@types/debug": "^4.1.10",
28
+ "@markuplint/ml-spec": "4.0.0-alpha.7",
29
+ "@types/debug": "^4.1.12",
30
30
  "debug": "^4.3.4",
31
- "postcss-selector-parser": "^6.0.13",
32
- "type-fest": "^4.5.0"
31
+ "postcss-selector-parser": "^6.0.15",
32
+ "type-fest": "^4.9.0"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/jsdom": "21.1.4",
36
- "jsdom": "22.1.0"
35
+ "@types/jsdom": "21.1.6",
36
+ "jsdom": "23.0.1"
37
37
  },
38
- "gitHead": "0c3e4690662edf1765bcc4b6411ec5507c1e2ea3"
38
+ "gitHead": "571129bf6498541125e1e7c3907d5ed9af53459a"
39
39
  }