@pikku/inspector 0.12.107 → 0.12.108
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.
|
@@ -42,6 +42,34 @@ const NON_TEXT_ATTRIBUTES = new Set([
|
|
|
42
42
|
'value',
|
|
43
43
|
'key',
|
|
44
44
|
]);
|
|
45
|
+
/**
|
|
46
|
+
* Calls whose string arguments are class lists. A literal anywhere inside one —
|
|
47
|
+
* `cva('…', { variants: { size: { heading: 'font-heading text-xl' } } })` — is
|
|
48
|
+
* styling, even under a key like `heading` that would otherwise read as text.
|
|
49
|
+
*/
|
|
50
|
+
const CLASS_BUILDERS = new Set([
|
|
51
|
+
'cn',
|
|
52
|
+
'cva',
|
|
53
|
+
'clsx',
|
|
54
|
+
'cx',
|
|
55
|
+
'classNames',
|
|
56
|
+
'classnames',
|
|
57
|
+
'tv',
|
|
58
|
+
'twMerge',
|
|
59
|
+
'twJoin',
|
|
60
|
+
]);
|
|
61
|
+
const isInsideClassBuilder = (node) => {
|
|
62
|
+
for (let at = node.parent; at; at = at.parent) {
|
|
63
|
+
if (ts.isJsxElement(at) || ts.isJsxSelfClosingElement(at))
|
|
64
|
+
return false;
|
|
65
|
+
if (ts.isCallExpression(at) &&
|
|
66
|
+
ts.isIdentifier(at.expression) &&
|
|
67
|
+
CLASS_BUILDERS.has(at.expression.text)) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
};
|
|
45
73
|
const isProse = (text) => /^\p{Lu}[^\s]*(\s+[^\s]+)+/u.test(text.trim()) &&
|
|
46
74
|
!/[:/[\]=_#]/.test(text.split(/\s+/)[0] ?? '');
|
|
47
75
|
const isSentence = (text) => /\p{L}+\s+\p{L}+/u.test(text);
|
|
@@ -72,7 +100,9 @@ export const readJsxLiteralText = (fileName, content) => {
|
|
|
72
100
|
const found = [];
|
|
73
101
|
const seen = new Set();
|
|
74
102
|
const add = (node, text) => {
|
|
75
|
-
if (!hasLetter(text) ||
|
|
103
|
+
if (!hasLetter(text) ||
|
|
104
|
+
seen.has(node.getStart(source)) ||
|
|
105
|
+
isInsideClassBuilder(node))
|
|
76
106
|
return;
|
|
77
107
|
seen.add(node.getStart(source));
|
|
78
108
|
const { line } = source.getLineAndCharacterOfPosition(node.getStart(source));
|