@weerachai06/tw-scanner 1.0.1 → 1.0.3
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/dist/validator.js +18 -3
- package/package.json +1 -1
package/dist/validator.js
CHANGED
|
@@ -29,9 +29,17 @@ function cssSelector(cls) {
|
|
|
29
29
|
.replace(/\]/g, '\\]')
|
|
30
30
|
.replace(/\(/g, '\\(')
|
|
31
31
|
.replace(/\)/g, '\\)')
|
|
32
|
+
.replace(/=/g, '\\=')
|
|
33
|
+
.replace(/>/g, '\\>')
|
|
34
|
+
.replace(/&/g, '\\&')
|
|
35
|
+
.replace(/~/g, '\\~')
|
|
36
|
+
.replace(/\+/g, '\\+')
|
|
32
37
|
.replace(/#/g, '\\#')
|
|
33
38
|
.replace(/%/g, '\\%')
|
|
34
|
-
.replace(/!/g, '\\!')
|
|
39
|
+
.replace(/!/g, '\\!')
|
|
40
|
+
.replace(/,/g, '\\,')
|
|
41
|
+
.replace(/'/g, "\\'")
|
|
42
|
+
.replace(/"/g, '\\"');
|
|
35
43
|
}
|
|
36
44
|
function selectorInOutput(selector, output) {
|
|
37
45
|
const idx = output.indexOf(selector);
|
|
@@ -40,9 +48,13 @@ function selectorInOutput(selector, output) {
|
|
|
40
48
|
const next = output[idx + selector.length];
|
|
41
49
|
return next === '{' || next === ' ' || next === ':' || next === '[' || next === ',';
|
|
42
50
|
}
|
|
51
|
+
// Marker classes that are valid but generate no CSS of their own
|
|
52
|
+
const MARKER_CLASS_RE = /^(group|peer)(\/\S+)?$/;
|
|
43
53
|
// ─── Validation cache: per-context ───────────────────────────────────────────
|
|
44
54
|
const validityCache = new Map();
|
|
45
55
|
export function isValidClass(cls, context) {
|
|
56
|
+
if (MARKER_CLASS_RE.test(cls))
|
|
57
|
+
return true;
|
|
46
58
|
if (!validityCache.has(context))
|
|
47
59
|
validityCache.set(context, new Map());
|
|
48
60
|
const cache = validityCache.get(context);
|
|
@@ -61,9 +73,12 @@ export function validateBatch(classes, context) {
|
|
|
61
73
|
const cache = validityCache.get(context) ?? new Map();
|
|
62
74
|
if (!validityCache.has(context))
|
|
63
75
|
validityCache.set(context, cache);
|
|
64
|
-
// Use cache first
|
|
76
|
+
// Use cache first; skip marker classes
|
|
65
77
|
for (const cls of classes) {
|
|
66
|
-
if (
|
|
78
|
+
if (MARKER_CLASS_RE.test(cls)) {
|
|
79
|
+
result.set(cls, true);
|
|
80
|
+
}
|
|
81
|
+
else if (cache.has(cls)) {
|
|
67
82
|
result.set(cls, cache.get(cls));
|
|
68
83
|
}
|
|
69
84
|
else {
|