@getchomp/mcp 0.0.0-stage → 0.2.42
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/README.md +15 -2
- package/dist/conventionsReference.d.ts +84 -0
- package/dist/conventionsReference.js +313 -0
- package/dist/designSystem/astScanner.d.ts +153 -0
- package/dist/designSystem/astScanner.js +2014 -0
- package/dist/designSystem/baseline.d.ts +65 -0
- package/dist/designSystem/baseline.js +136 -0
- package/dist/designSystem/color.d.ts +35 -0
- package/dist/designSystem/color.js +265 -0
- package/dist/designSystem/config.d.ts +183 -0
- package/dist/designSystem/config.js +469 -0
- package/dist/designSystem/contrast.d.ts +55 -0
- package/dist/designSystem/contrast.js +377 -0
- package/dist/designSystem/cssParser.d.ts +63 -0
- package/dist/designSystem/cssParser.js +469 -0
- package/dist/designSystem/merges.d.ts +57 -0
- package/dist/designSystem/merges.js +94 -0
- package/dist/designSystem/preprocessors.d.ts +46 -0
- package/dist/designSystem/preprocessors.js +1108 -0
- package/dist/designSystem/presentation.d.ts +45 -0
- package/dist/designSystem/presentation.js +796 -0
- package/dist/designSystem/styleVectors.d.ts +27 -0
- package/dist/designSystem/styleVectors.js +484 -0
- package/dist/designSystem/tokens.d.ts +39 -0
- package/dist/designSystem/tokens.js +409 -0
- package/dist/designSystem/topology.d.ts +64 -0
- package/dist/designSystem/topology.js +254 -0
- package/dist/designSystem/types.d.ts +857 -0
- package/dist/designSystem/types.js +113 -0
- package/dist/designSystem/typography.d.ts +25 -0
- package/dist/designSystem/typography.js +244 -0
- package/dist/designSystem/uiShapes.d.ts +74 -0
- package/dist/designSystem/uiShapes.js +285 -0
- package/dist/designSystem/valueClusters.d.ts +76 -0
- package/dist/designSystem/valueClusters.js +281 -0
- package/dist/designSystemPlugin.d.ts +321 -0
- package/dist/designSystemPlugin.js +4730 -0
- package/dist/enrichNodesPlugin.d.ts +160 -0
- package/dist/enrichNodesPlugin.js +957 -0
- package/dist/index.d.ts +65 -0
- package/dist/index.js +1298 -0
- package/dist/intelligence.d.ts +502 -0
- package/dist/intelligence.js +3058 -0
- package/dist/pluginRunner.d.ts +364 -0
- package/dist/pluginRunner.js +1096 -0
- package/dist/plugins/design-system/index.d.ts +14 -0
- package/dist/plugins/design-system/index.js +241 -0
- package/dist/plugins/enrich-nodes/index.d.ts +388 -0
- package/dist/plugins/enrich-nodes/index.js +697 -0
- package/dist/plugins/index.d.ts +15 -0
- package/dist/plugins/index.js +20 -0
- package/dist/plugins/local-shims/index.d.ts +121 -0
- package/dist/plugins/local-shims/index.js +237 -0
- package/dist/shimsPlugin.d.ts +134 -0
- package/dist/shimsPlugin.js +1392 -0
- package/package.json +38 -3
|
@@ -0,0 +1,2014 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* packages/mcp/src/designSystem/astScanner.ts
|
|
3
|
+
*
|
|
4
|
+
* Single-pass TypeScript/TSX AST scanner for component styling conventions, Tailwind v4 utilities,
|
|
5
|
+
* magic spacing steps, intra-function className variable dataflow, JSX skeletons, prop contracts,
|
|
6
|
+
* ancestor-propagated Tailwind color pairs, nested interactive checks, stateful UI shapes, and
|
|
7
|
+
* canvas slot-recorder provenance (including local variable binding attribution).
|
|
8
|
+
*/
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
import ts from "typescript";
|
|
11
|
+
import { looksLikeColorLiteral } from "./color.js";
|
|
12
|
+
import { DEFAULT_ATOM_CATALOG, DEFAULT_DESIGN_SYSTEM_CONFIG, } from "./config.js";
|
|
13
|
+
import { getLineSnippet, VAR_REF_RE } from "./cssParser.js";
|
|
14
|
+
import { isPreprocessedUiComponentFile } from "./preprocessors.js";
|
|
15
|
+
import { arbitraryTailwindValue, extractColorLiterals, extractLengthLiterals, } from "./valueClusters.js";
|
|
16
|
+
/** Core Tailwind utility prefixes (v3 + v4), matched after stripping variant/important prefixes. */
|
|
17
|
+
const TAILWIND_CORE_UTILITY_RE = /^-?(flex|inline-flex|inline-grid|grid|block|inline-block|inline|contents|table|hidden|sr-only|not-sr-only|visible|invisible|collapse|isolate|isolation-|items-|justify-|content-|self-|place-|order-|grow|shrink|basis-|gap-|space-[xy]-|divide-|p[xytblrse]?-|m[xytblrse]?-|w-|h-|size-|min-[wh]-|max-[wh]-|aspect-|text-|font-|leading-|tracking-|indent-|align-|whitespace-|break-|truncate|line-clamp-|uppercase|lowercase|capitalize|normal-case|italic|not-italic|underline|no-underline|line-through|overline|decoration-|tabular-nums|oldstyle-nums|lining-nums|proportional-nums|antialiased|subpixel-antialiased|list-|object-|bg-|from-|via-|to-|fill-|stroke-|border|rounded|outline|ring|inset-ring|shadow|opacity-|mix-blend-|z-|relative|absolute|fixed|sticky|static|inset-|top-|right-|bottom-|left-|start-|end-|overflow-|overscroll-|scroll-|snap-|touch-|cursor-|select-|pointer-events-|resize|appearance-|will-change-|transition|duration-|ease-|delay-|animate-|transform|scale-|rotate-|translate-|skew-|origin-|backdrop-|grid-cols-|grid-rows-|col-|row-|auto-cols-|auto-rows-|accent-|caret-|group$|peer$)/;
|
|
18
|
+
const TAILWIND_VARIANT_PREFIX_RE = /^(?:(?:[a-z0-9_@/-]+|\[[^\]]+\]):)+/i;
|
|
19
|
+
export function isTailwindUtilityToken(token) {
|
|
20
|
+
if (!token)
|
|
21
|
+
return false;
|
|
22
|
+
if (token.includes("[") && TAILWIND_ARBITRARY_TEST_RE.test(token))
|
|
23
|
+
return true;
|
|
24
|
+
let core = token.replace(TAILWIND_VARIANT_PREFIX_RE, "");
|
|
25
|
+
if (core.startsWith("!"))
|
|
26
|
+
core = core.slice(1);
|
|
27
|
+
if (core.endsWith("!"))
|
|
28
|
+
core = core.slice(0, -1);
|
|
29
|
+
// Support opacity modifier like `bg-hud/80`, `text-accent/50`
|
|
30
|
+
const slashIdx = core.indexOf("/");
|
|
31
|
+
if (slashIdx > 0 && !core.includes("[")) {
|
|
32
|
+
core = core.slice(0, slashIdx);
|
|
33
|
+
}
|
|
34
|
+
return TAILWIND_CORE_UTILITY_RE.test(core);
|
|
35
|
+
}
|
|
36
|
+
const TAILWIND_ARBITRARY_TEST_RE = /^[a-zA-Z0-9_:@/.-]+-\[[^\]]+\]!?$/;
|
|
37
|
+
export const ARBITRARY_TW_RE = /(?:^|\s)([a-zA-Z0-9_:@/.-]+-\[[^\]]+\]!?)/g;
|
|
38
|
+
const PALETTE_TW_RE = /(?:^|\s)(?:[a-z0-9-]+:)*(?:bg|text|border|ring|fill|stroke|from|via|to|outline|decoration|divide|accent|caret|shadow)-([a-z][a-z-]*?)-(\d{1,4})(?:\/\d+)?(?![\w-])/g;
|
|
39
|
+
export const TAILWIND_DEFAULT_PALETTES = new Set([
|
|
40
|
+
"slate", "gray", "zinc", "neutral", "stone", "red", "orange", "amber", "yellow", "lime",
|
|
41
|
+
"green", "emerald", "teal", "cyan", "sky", "blue", "indigo", "violet", "purple", "fuchsia",
|
|
42
|
+
"pink", "rose",
|
|
43
|
+
]);
|
|
44
|
+
const STANDARD_TAILWIND_PALETTE_STEPS = new Set([
|
|
45
|
+
"50", "100", "200", "300", "400", "500", "600", "700", "800", "900", "950",
|
|
46
|
+
]);
|
|
47
|
+
const STANDARD_TAILWIND_SPACING_STEPS = new Set([
|
|
48
|
+
"0", "0.5", "1", "1.5", "2", "2.5", "3", "3.5", "4", "5", "6", "7", "8", "9",
|
|
49
|
+
"10", "11", "12", "14", "16", "20", "24", "28", "32", "36", "40", "44", "48",
|
|
50
|
+
"52", "56", "60", "64", "72", "80", "96",
|
|
51
|
+
]);
|
|
52
|
+
const MAGIC_SPACING_UTIL_RE = /^(?:[a-z0-9-]+:)*-?(w|h|min-w|min-h|max-w|max-h|size|p|px|py|pt|pb|pl|pr|ps|pe|m|mx|my|mt|mb|ml|mr|ms|me|gap|gap-x|gap-y|space-x|space-y|top|right|bottom|left|inset|inset-x|inset-y)-(\d+(?:\.\d+)?)$/;
|
|
53
|
+
const CLASS_HELPER_CALLEES = new Set([
|
|
54
|
+
"cva", "tv", "clsx", "cn", "twMerge", "classNames", "classnames", "cx", "twJoin",
|
|
55
|
+
]);
|
|
56
|
+
const CSS_IN_JS_MODULES = [
|
|
57
|
+
"styled-components",
|
|
58
|
+
"@emotion/styled",
|
|
59
|
+
"@emotion/react",
|
|
60
|
+
"@emotion/css",
|
|
61
|
+
"@mui/material",
|
|
62
|
+
"@mui/system",
|
|
63
|
+
"@chakra-ui/react",
|
|
64
|
+
"@mantine/core",
|
|
65
|
+
"theme-ui",
|
|
66
|
+
"@stitches/react",
|
|
67
|
+
"@vanilla-extract/css",
|
|
68
|
+
"@linaria/core",
|
|
69
|
+
"goober",
|
|
70
|
+
];
|
|
71
|
+
function classifyArbitraryTailwindCategory(cls) {
|
|
72
|
+
const base = cls.split(":").pop() ?? cls;
|
|
73
|
+
if (/^(text|font|leading|tracking)-/.test(base))
|
|
74
|
+
return "typography";
|
|
75
|
+
if (/^(w|h|min-w|min-h|max-w|max-h|p|px|py|pt|pb|pl|pr|m|mx|my|mt|mb|ml|mr|gap|top|right|bottom|left|inset)-/.test(base)) {
|
|
76
|
+
return "spacing-sizing";
|
|
77
|
+
}
|
|
78
|
+
if (/^(rounded|border)-/.test(base))
|
|
79
|
+
return "radius-border";
|
|
80
|
+
if (/^stroke-\[([^\]]+)\]$/.test(base)) {
|
|
81
|
+
const inner = base.match(/^stroke-\[([^\]]+)\]$/)?.[1]?.trim() ?? "";
|
|
82
|
+
if (/^-?\d+(\.\d+)?(px|rem|em|%)?$/.test(inner)) {
|
|
83
|
+
return "radius-border";
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (/^(bg|from|via|to|ring|fill|stroke)-/.test(base))
|
|
87
|
+
return "color";
|
|
88
|
+
return "layout";
|
|
89
|
+
}
|
|
90
|
+
function atomMatcherHits(m, tagName, roleAttr, classAttr, getAttr) {
|
|
91
|
+
if (m.tag !== undefined) {
|
|
92
|
+
const tags = Array.isArray(m.tag) ? m.tag : [m.tag];
|
|
93
|
+
if (!tags.includes(tagName))
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (m.role !== undefined && m.role !== roleAttr)
|
|
97
|
+
return false;
|
|
98
|
+
if (m.classPattern !== undefined) {
|
|
99
|
+
try {
|
|
100
|
+
if (!new RegExp(m.classPattern, "i").test(classAttr))
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (m.attrs) {
|
|
108
|
+
for (const [k, v] of Object.entries(m.attrs)) {
|
|
109
|
+
if (getAttr(k) !== v)
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return (m.tag !== undefined ||
|
|
114
|
+
m.role !== undefined ||
|
|
115
|
+
m.classPattern !== undefined ||
|
|
116
|
+
m.attrs !== undefined);
|
|
117
|
+
}
|
|
118
|
+
function scoreAtomMatcher(m) {
|
|
119
|
+
return ((m.role !== undefined ? 4 : 0) +
|
|
120
|
+
(m.attrs ? Object.keys(m.attrs).length * 3 : 0) +
|
|
121
|
+
(m.classPattern !== undefined ? 2 : 0) +
|
|
122
|
+
(m.tag !== undefined ? 1 : 0));
|
|
123
|
+
}
|
|
124
|
+
const SVG_PRIMITIVE_TAGS = new Set([
|
|
125
|
+
"svg", "path", "circle", "rect", "line", "polyline", "polygon",
|
|
126
|
+
"g", "defs", "clipPath", "linearGradient", "radialGradient", "stop",
|
|
127
|
+
"mask", "pattern", "use", "symbol", "ellipse",
|
|
128
|
+
]);
|
|
129
|
+
const STATE_HOOK_NAMES = new Set([
|
|
130
|
+
"useState", "useReducer", "useContext", "useSyncExternalStore", "useStore", "useSignal",
|
|
131
|
+
"React.useState", "React.useReducer", "React.useContext",
|
|
132
|
+
]);
|
|
133
|
+
const INTERACTIVE_DOM_TAGS = new Set([
|
|
134
|
+
"button", "a", "input", "select", "textarea", "summary",
|
|
135
|
+
]);
|
|
136
|
+
const INTERACTIVE_ARIA_ROLES = new Set([
|
|
137
|
+
"button", "link", "tab", "radio", "checkbox", "switch", "menuitem", "option",
|
|
138
|
+
]);
|
|
139
|
+
const NON_TRIVIAL_INLINE_STYLE_PROPS = new Set([
|
|
140
|
+
"color", "background", "backgroundColor", "border", "borderColor", "borderRadius",
|
|
141
|
+
"padding", "paddingTop", "paddingBottom", "paddingLeft", "paddingRight",
|
|
142
|
+
"margin", "marginTop", "marginBottom", "marginLeft", "marginRight",
|
|
143
|
+
"fontSize", "fontFamily", "boxShadow", "gap",
|
|
144
|
+
]);
|
|
145
|
+
const STYLE_VECTOR_INLINE_PROPS = new Set([
|
|
146
|
+
"height", "minHeight", "padding", "paddingInline", "paddingBlock",
|
|
147
|
+
"paddingLeft", "paddingRight", "paddingTop", "paddingBottom",
|
|
148
|
+
"gap", "fontFamily", "fontSize", "fontWeight", "lineHeight",
|
|
149
|
+
"letterSpacing", "textTransform", "borderRadius", "border",
|
|
150
|
+
"borderWidth", "borderColor", "background", "backgroundColor", "color",
|
|
151
|
+
"margin", "marginTop", "marginRight", "marginBottom", "marginLeft", "width", "minWidth",
|
|
152
|
+
]);
|
|
153
|
+
const NON_COLOR_TEXT_SLUGS = new Set([
|
|
154
|
+
"xs", "sm", "base", "lg", "xl", "2xl", "3xl", "4xl", "5xl", "6xl", "7xl", "8xl", "9xl",
|
|
155
|
+
"left", "center", "right", "justify", "start", "end",
|
|
156
|
+
"wrap", "nowrap", "balance", "pretty",
|
|
157
|
+
"ellipsis", "clip",
|
|
158
|
+
"transparent", "current", "inherit",
|
|
159
|
+
]);
|
|
160
|
+
const NON_COLOR_BG_SLUGS = new Set([
|
|
161
|
+
"none", "auto", "cover", "contain",
|
|
162
|
+
"center", "top", "bottom", "left", "right",
|
|
163
|
+
"left-top", "left-bottom", "right-top", "right-bottom",
|
|
164
|
+
"repeat", "no-repeat", "repeat-x", "repeat-y", "repeat-round", "repeat-space",
|
|
165
|
+
"fixed", "local", "scroll",
|
|
166
|
+
"transparent", "current", "inherit",
|
|
167
|
+
]);
|
|
168
|
+
const NON_COLOR_BG_PREFIXES = [
|
|
169
|
+
"clip-", "origin-", "gradient-", "linear-", "radial-", "conic-", "size-", "position-",
|
|
170
|
+
];
|
|
171
|
+
function isDefaultTailwindPaletteSlug(slug, knownThemeColorSlugs) {
|
|
172
|
+
if (knownThemeColorSlugs?.has(slug))
|
|
173
|
+
return false;
|
|
174
|
+
if (slug === "white" || slug === "black")
|
|
175
|
+
return true;
|
|
176
|
+
const m = /^([a-z-]+)-(\d{1,4})$/.exec(slug);
|
|
177
|
+
if (!m || !TAILWIND_DEFAULT_PALETTES.has(m[1]))
|
|
178
|
+
return false;
|
|
179
|
+
if (!knownThemeColorSlugs)
|
|
180
|
+
return true;
|
|
181
|
+
return STANDARD_TAILWIND_PALETTE_STEPS.has(m[2]);
|
|
182
|
+
}
|
|
183
|
+
function extractColorUtilitySlugsFromTokens(tokens, knownThemeColorSlugs, nonColorThemeTextSlugs) {
|
|
184
|
+
const byVariant = new Map();
|
|
185
|
+
for (const tok of tokens) {
|
|
186
|
+
const colonIdx = tok.lastIndexOf(":");
|
|
187
|
+
const variant = colonIdx >= 0 ? tok.slice(0, colonIdx) : "";
|
|
188
|
+
const base = colonIdx >= 0 ? tok.slice(colonIdx + 1) : tok;
|
|
189
|
+
if (base.startsWith("bg-")) {
|
|
190
|
+
const slug = base.slice(3);
|
|
191
|
+
if (!slug ||
|
|
192
|
+
slug.includes("[") ||
|
|
193
|
+
slug.includes("/") ||
|
|
194
|
+
NON_COLOR_BG_SLUGS.has(slug) ||
|
|
195
|
+
NON_COLOR_BG_PREFIXES.some((p) => slug.startsWith(p)) ||
|
|
196
|
+
isDefaultTailwindPaletteSlug(slug, knownThemeColorSlugs)) {
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
let bucket = byVariant.get(variant);
|
|
200
|
+
if (!bucket) {
|
|
201
|
+
bucket = { bg: [], fg: [] };
|
|
202
|
+
byVariant.set(variant, bucket);
|
|
203
|
+
}
|
|
204
|
+
if (!bucket.bg.includes(slug))
|
|
205
|
+
bucket.bg.push(slug);
|
|
206
|
+
}
|
|
207
|
+
else if (base.startsWith("text-")) {
|
|
208
|
+
const slug = base.slice(5);
|
|
209
|
+
if (!slug ||
|
|
210
|
+
slug.includes("[") ||
|
|
211
|
+
slug.includes("/") ||
|
|
212
|
+
NON_COLOR_TEXT_SLUGS.has(slug) ||
|
|
213
|
+
nonColorThemeTextSlugs?.has(slug) ||
|
|
214
|
+
isDefaultTailwindPaletteSlug(slug, knownThemeColorSlugs)) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
let bucket = byVariant.get(variant);
|
|
218
|
+
if (!bucket) {
|
|
219
|
+
bucket = { bg: [], fg: [] };
|
|
220
|
+
byVariant.set(variant, bucket);
|
|
221
|
+
}
|
|
222
|
+
if (!bucket.fg.includes(slug))
|
|
223
|
+
bucket.fg.push(slug);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return byVariant;
|
|
227
|
+
}
|
|
228
|
+
function isTypographyTailwindClass(tok) {
|
|
229
|
+
const base = tok.replace(TAILWIND_VARIANT_PREFIX_RE, "");
|
|
230
|
+
return /^(?:text|font|leading|tracking|uppercase|lowercase|capitalize|normal-case|italic|not-italic|tabular-nums)/.test(base);
|
|
231
|
+
}
|
|
232
|
+
export function scanTsxOrTsFile(filePath, sourceText, scanOptions = {}) {
|
|
233
|
+
const knownCssClasses = scanOptions.knownCssClasses;
|
|
234
|
+
const cssClassPrefixes = scanOptions.cssClassPrefixes ?? [];
|
|
235
|
+
const atomDefinitions = scanOptions.atomDefinitions ?? DEFAULT_ATOM_CATALOG;
|
|
236
|
+
const knownThemeColorSlugs = scanOptions.knownThemeColorSlugs;
|
|
237
|
+
const nonColorThemeTextSlugs = scanOptions.nonColorThemeTextSlugs;
|
|
238
|
+
const knownThemeSpacingSteps = scanOptions.knownThemeSpacingSteps;
|
|
239
|
+
const colorPropRe = (() => {
|
|
240
|
+
try {
|
|
241
|
+
return new RegExp(scanOptions.colorPropPattern ?? DEFAULT_DESIGN_SYSTEM_CONFIG.invariants.colorPropPattern);
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
return new RegExp(DEFAULT_DESIGN_SYSTEM_CONFIG.invariants.colorPropPattern);
|
|
245
|
+
}
|
|
246
|
+
})();
|
|
247
|
+
const slotRecorderFactories = scanOptions.canvasSlotRecorderFactories ?? [];
|
|
248
|
+
const canvasCssValueHelpers = scanOptions.canvasCssValueHelpers ?? [];
|
|
249
|
+
const canvasTokenReaderHelpers = scanOptions.canvasTokenReaderHelpers ?? [];
|
|
250
|
+
const isKnownCssClass = (tok) => Boolean(knownCssClasses?.has(tok)) || cssClassPrefixes.some((p) => tok.startsWith(p));
|
|
251
|
+
const scriptKind = filePath.endsWith(".tsx") || isPreprocessedUiComponentFile(filePath)
|
|
252
|
+
? ts.ScriptKind.TSX
|
|
253
|
+
: /\.(jsx|js|mjs|cjs)$/i.test(filePath)
|
|
254
|
+
? ts.ScriptKind.JSX
|
|
255
|
+
: ts.ScriptKind.TS;
|
|
256
|
+
const sf = ts.createSourceFile(filePath, sourceText, ts.ScriptTarget.Latest, true, scriptKind);
|
|
257
|
+
const rawLines = sourceText.split(/\r?\n/);
|
|
258
|
+
const getLine = (pos) => sf.getLineAndCharacterOfPosition(pos).line + 1;
|
|
259
|
+
const definedFontVars = [];
|
|
260
|
+
const tokenReferences = [];
|
|
261
|
+
const cssImports = [];
|
|
262
|
+
const tailwindClassPairs = [];
|
|
263
|
+
const seenLocalTwPairs = new Set();
|
|
264
|
+
const recordTailwindClassBranches = (branches, lineNumber, inheritedBgByVariant) => {
|
|
265
|
+
for (const tokens of branches) {
|
|
266
|
+
if (tokens.length === 0)
|
|
267
|
+
continue;
|
|
268
|
+
const byVariant = extractColorUtilitySlugsFromTokens(tokens, knownThemeColorSlugs, nonColorThemeTextSlugs);
|
|
269
|
+
for (const [variant, { bg, fg }] of byVariant.entries()) {
|
|
270
|
+
const effBg = bg.length > 0
|
|
271
|
+
? bg
|
|
272
|
+
: inheritedBgByVariant?.get(variant) ??
|
|
273
|
+
(variant !== "" ? inheritedBgByVariant?.get("") : undefined) ??
|
|
274
|
+
[];
|
|
275
|
+
if (effBg.length === 0 || fg.length === 0)
|
|
276
|
+
continue;
|
|
277
|
+
for (const fgSlug of fg) {
|
|
278
|
+
for (const bgSlug of effBg) {
|
|
279
|
+
const key = `${fgSlug}::${bgSlug}`;
|
|
280
|
+
if (!seenLocalTwPairs.has(key)) {
|
|
281
|
+
seenLocalTwPairs.add(key);
|
|
282
|
+
tailwindClassPairs.push({ fgSlug, bgSlug, filePath, lineNumber });
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
};
|
|
289
|
+
const functionsAndClasses = new Map();
|
|
290
|
+
const typeMembersByName = new Map();
|
|
291
|
+
const typeExtendsByName = new Map();
|
|
292
|
+
const typeAliasNodeByName = new Map();
|
|
293
|
+
const importedModules = [];
|
|
294
|
+
const importedBindings = new Map();
|
|
295
|
+
const reExports = [];
|
|
296
|
+
const cssModuleBindings = new Set();
|
|
297
|
+
const variantAxes = {};
|
|
298
|
+
const consumedStringNodes = new Set();
|
|
299
|
+
let hasPixiImport = false;
|
|
300
|
+
let hasCssInJs = false;
|
|
301
|
+
for (const stmt of sf.statements) {
|
|
302
|
+
if (ts.isImportDeclaration(stmt) && ts.isStringLiteral(stmt.moduleSpecifier)) {
|
|
303
|
+
const spec = stmt.moduleSpecifier.text;
|
|
304
|
+
importedModules.push(spec);
|
|
305
|
+
const clause = stmt.importClause;
|
|
306
|
+
if (clause && !clause.isTypeOnly) {
|
|
307
|
+
if (clause.name) {
|
|
308
|
+
importedBindings.set(clause.name.text, { specifier: spec, importedName: "default" });
|
|
309
|
+
}
|
|
310
|
+
if (clause.namedBindings) {
|
|
311
|
+
if (ts.isNamedImports(clause.namedBindings)) {
|
|
312
|
+
for (const el of clause.namedBindings.elements) {
|
|
313
|
+
if (el.isTypeOnly)
|
|
314
|
+
continue;
|
|
315
|
+
importedBindings.set(el.name.text, {
|
|
316
|
+
specifier: spec,
|
|
317
|
+
importedName: (el.propertyName ?? el.name).text,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
else if (ts.isNamespaceImport(clause.namedBindings)) {
|
|
322
|
+
importedBindings.set(clause.namedBindings.name.text, {
|
|
323
|
+
specifier: spec,
|
|
324
|
+
importedName: "*",
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
if (spec === "pixi.js" || spec.startsWith("pixi.js/") || spec === "pixi-viewport") {
|
|
330
|
+
hasPixiImport = true;
|
|
331
|
+
}
|
|
332
|
+
if (CSS_IN_JS_MODULES.some((m) => spec === m || spec.startsWith(`${m}/`))) {
|
|
333
|
+
hasCssInJs = true;
|
|
334
|
+
}
|
|
335
|
+
if (/\.module\.(?:css|scss|sass|less)$/.test(spec)) {
|
|
336
|
+
if (clause?.name)
|
|
337
|
+
cssModuleBindings.add(clause.name.text);
|
|
338
|
+
if (clause?.namedBindings && ts.isNamespaceImport(clause.namedBindings)) {
|
|
339
|
+
cssModuleBindings.add(clause.namedBindings.name.text);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
else if (ts.isExportDeclaration(stmt) &&
|
|
344
|
+
!stmt.isTypeOnly &&
|
|
345
|
+
stmt.moduleSpecifier &&
|
|
346
|
+
ts.isStringLiteral(stmt.moduleSpecifier)) {
|
|
347
|
+
const spec = stmt.moduleSpecifier.text;
|
|
348
|
+
if (!stmt.exportClause) {
|
|
349
|
+
reExports.push({ exportedName: "*", sourceName: "*", specifier: spec });
|
|
350
|
+
}
|
|
351
|
+
else if (ts.isNamedExports(stmt.exportClause)) {
|
|
352
|
+
for (const el of stmt.exportClause.elements) {
|
|
353
|
+
if (el.isTypeOnly)
|
|
354
|
+
continue;
|
|
355
|
+
reExports.push({
|
|
356
|
+
exportedName: el.name.text,
|
|
357
|
+
sourceName: (el.propertyName ?? el.name).text,
|
|
358
|
+
specifier: spec,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
if (ts.isInterfaceDeclaration(stmt) && stmt.name) {
|
|
364
|
+
typeMembersByName.set(stmt.name.text, stmt.members);
|
|
365
|
+
const ext = [];
|
|
366
|
+
for (const h of stmt.heritageClauses ?? []) {
|
|
367
|
+
if (h.token !== ts.SyntaxKind.ExtendsKeyword)
|
|
368
|
+
continue;
|
|
369
|
+
for (const t of h.types)
|
|
370
|
+
ext.push(t.expression.getText(sf));
|
|
371
|
+
}
|
|
372
|
+
typeExtendsByName.set(stmt.name.text, ext);
|
|
373
|
+
}
|
|
374
|
+
else if (ts.isTypeAliasDeclaration(stmt) && stmt.name) {
|
|
375
|
+
typeAliasNodeByName.set(stmt.name.text, stmt.type);
|
|
376
|
+
if (ts.isTypeLiteralNode(stmt.type)) {
|
|
377
|
+
typeMembersByName.set(stmt.name.text, stmt.type.members);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
const literalUnionValues = (t) => {
|
|
382
|
+
if (!t)
|
|
383
|
+
return undefined;
|
|
384
|
+
const node = ts.isParenthesizedTypeNode(t) ? t.type : t;
|
|
385
|
+
if (ts.isLiteralTypeNode(node) && ts.isStringLiteral(node.literal)) {
|
|
386
|
+
return [node.literal.text];
|
|
387
|
+
}
|
|
388
|
+
if (ts.isUnionTypeNode(node)) {
|
|
389
|
+
const vals = [];
|
|
390
|
+
for (const part of node.types) {
|
|
391
|
+
if (ts.isLiteralTypeNode(part) && ts.isStringLiteral(part.literal)) {
|
|
392
|
+
vals.push(part.literal.text);
|
|
393
|
+
}
|
|
394
|
+
else if (ts.isLiteralTypeNode(part) && part.literal.kind === ts.SyntaxKind.NullKeyword) {
|
|
395
|
+
continue;
|
|
396
|
+
}
|
|
397
|
+
else if (part.kind === ts.SyntaxKind.UndefinedKeyword) {
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
else {
|
|
401
|
+
return vals.length > 0 ? vals : undefined;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
return vals.length > 0 ? vals : undefined;
|
|
405
|
+
}
|
|
406
|
+
return undefined;
|
|
407
|
+
};
|
|
408
|
+
const collectPropsFromTypeNode = (typeNode, into, visited) => {
|
|
409
|
+
const addMembers = (members) => {
|
|
410
|
+
for (const m of members) {
|
|
411
|
+
if (ts.isPropertySignature(m) && m.name) {
|
|
412
|
+
const propName = m.name.getText(sf);
|
|
413
|
+
const full = m.type ? m.type.getText(sf).replace(/\s+/g, " ").trim() : "unknown";
|
|
414
|
+
const variants = literalUnionValues(m.type);
|
|
415
|
+
into.set(propName, {
|
|
416
|
+
name: propName,
|
|
417
|
+
type: full.slice(0, 160),
|
|
418
|
+
required: !m.questionToken,
|
|
419
|
+
...(variants ? { variants } : {}),
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
const addByName = (name) => {
|
|
425
|
+
if (visited.has(name))
|
|
426
|
+
return;
|
|
427
|
+
visited.add(name);
|
|
428
|
+
if (/(?:Button|Input|Select|Textarea|Fieldset|Optgroup|Option)HTMLAttributes/i.test(name)) {
|
|
429
|
+
if (!into.has("disabled")) {
|
|
430
|
+
into.set("disabled", { name: "disabled", type: "boolean", required: false });
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
const members = typeMembersByName.get(name);
|
|
434
|
+
if (members)
|
|
435
|
+
addMembers(members);
|
|
436
|
+
for (const parent of typeExtendsByName.get(name) ?? [])
|
|
437
|
+
addByName(parent);
|
|
438
|
+
const alias = typeAliasNodeByName.get(name);
|
|
439
|
+
if (alias && !ts.isTypeLiteralNode(alias))
|
|
440
|
+
collectPropsFromTypeNode(alias, into, visited);
|
|
441
|
+
};
|
|
442
|
+
if (ts.isTypeLiteralNode(typeNode)) {
|
|
443
|
+
addMembers(typeNode.members);
|
|
444
|
+
}
|
|
445
|
+
else if (ts.isTypeReferenceNode(typeNode)) {
|
|
446
|
+
addByName(typeNode.typeName.getText(sf));
|
|
447
|
+
}
|
|
448
|
+
else if (ts.isIntersectionTypeNode(typeNode)) {
|
|
449
|
+
for (const part of typeNode.types)
|
|
450
|
+
collectPropsFromTypeNode(part, into, visited);
|
|
451
|
+
}
|
|
452
|
+
else if (ts.isParenthesizedTypeNode(typeNode)) {
|
|
453
|
+
collectPropsFromTypeNode(typeNode.type, into, visited);
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
const extractPropContractFromFunc = (fn, fallbackPropsType) => {
|
|
457
|
+
const propsMap = new Map();
|
|
458
|
+
const firstParam = fn.parameters[0];
|
|
459
|
+
const declared = firstParam?.type ?? fallbackPropsType;
|
|
460
|
+
if (declared)
|
|
461
|
+
collectPropsFromTypeNode(declared, propsMap, new Set());
|
|
462
|
+
if (firstParam && ts.isObjectBindingPattern(firstParam.name)) {
|
|
463
|
+
for (const el of firstParam.name.elements) {
|
|
464
|
+
if (ts.isIdentifier(el.name)) {
|
|
465
|
+
const propName = el.propertyName && ts.isIdentifier(el.propertyName) ? el.propertyName.text : el.name.text;
|
|
466
|
+
const existing = propsMap.get(propName);
|
|
467
|
+
if (existing) {
|
|
468
|
+
if (el.initializer)
|
|
469
|
+
existing.required = false;
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
propsMap.set(propName, {
|
|
473
|
+
name: propName,
|
|
474
|
+
type: "unknown",
|
|
475
|
+
required: !el.initializer,
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return [...propsMap.values()];
|
|
482
|
+
};
|
|
483
|
+
const ensureOwnerBucket = (name, lineNumber, endLineNumber, isExported) => {
|
|
484
|
+
let b = functionsAndClasses.get(name);
|
|
485
|
+
if (!b) {
|
|
486
|
+
b = {
|
|
487
|
+
name,
|
|
488
|
+
lineNumber,
|
|
489
|
+
endLineNumber,
|
|
490
|
+
isExported,
|
|
491
|
+
jsxDomElementCount: 0,
|
|
492
|
+
jsxCustomComponentCount: 0,
|
|
493
|
+
stateHookCount: 0,
|
|
494
|
+
propContract: [],
|
|
495
|
+
jsxCallSites: [],
|
|
496
|
+
jsxSkeletons: [],
|
|
497
|
+
stylingConventions: new Set(),
|
|
498
|
+
cssClassesUsed: new Set(),
|
|
499
|
+
cssClassOccurrences: [],
|
|
500
|
+
dynamicClassPrefixes: new Set(),
|
|
501
|
+
tokensConsumed: new Set(),
|
|
502
|
+
arbitraryTailwind: [],
|
|
503
|
+
magicSpacingUtilities: [],
|
|
504
|
+
primitiveScaleSkips: [],
|
|
505
|
+
inlineStyleLiterals: [],
|
|
506
|
+
usesSlotRecorder: false,
|
|
507
|
+
canvasCssCount: 0,
|
|
508
|
+
canvasTsConstCount: 0,
|
|
509
|
+
canvasLiteralCount: 0,
|
|
510
|
+
canvasLiterals: [],
|
|
511
|
+
rawDomPrimitives: [],
|
|
512
|
+
rawDomOffsets: [],
|
|
513
|
+
nestedInteractive: [],
|
|
514
|
+
uiShapeCandidates: [],
|
|
515
|
+
elementStyleSnapshots: [],
|
|
516
|
+
tailwindTypographyGroups: [],
|
|
517
|
+
renderedComponents: new Set(),
|
|
518
|
+
paletteClassCandidates: [],
|
|
519
|
+
tsTokenRefs: [],
|
|
520
|
+
literalValues: [],
|
|
521
|
+
domTags: new Set(),
|
|
522
|
+
invariantViolations: [],
|
|
523
|
+
tailwindUtilityCount: 0,
|
|
524
|
+
tailwindClassesUsed: [],
|
|
525
|
+
};
|
|
526
|
+
functionsAndClasses.set(name, b);
|
|
527
|
+
}
|
|
528
|
+
return b;
|
|
529
|
+
};
|
|
530
|
+
const moduleBucket = ensureOwnerBucket("__module__", 1, rawLines.length, true);
|
|
531
|
+
// Scope stacks for Upgrade 1A (className bindings), 1B (slot recorder bindings), 2/4 (JSX stacks)
|
|
532
|
+
const classEnvStack = [
|
|
533
|
+
new Map(),
|
|
534
|
+
];
|
|
535
|
+
const slotBindingStack = [new Map()];
|
|
536
|
+
const interactiveAncestorStack = [];
|
|
537
|
+
const bgAncestorStack = [];
|
|
538
|
+
const lookupClassBinding = (name) => {
|
|
539
|
+
for (let i = classEnvStack.length - 1; i >= 0; i--) {
|
|
540
|
+
const hit = classEnvStack[i].get(name);
|
|
541
|
+
if (hit)
|
|
542
|
+
return hit;
|
|
543
|
+
}
|
|
544
|
+
return undefined;
|
|
545
|
+
};
|
|
546
|
+
const lookupSlotBinding = (name) => {
|
|
547
|
+
for (let i = slotBindingStack.length - 1; i >= 0; i--) {
|
|
548
|
+
const hit = slotBindingStack[i].get(name);
|
|
549
|
+
if (hit)
|
|
550
|
+
return hit;
|
|
551
|
+
}
|
|
552
|
+
return undefined;
|
|
553
|
+
};
|
|
554
|
+
const recordSlotVarOrigin = (varName, entry) => {
|
|
555
|
+
const scope = slotBindingStack[slotBindingStack.length - 1];
|
|
556
|
+
let list = scope.get(varName);
|
|
557
|
+
if (!list) {
|
|
558
|
+
list = [];
|
|
559
|
+
scope.set(varName, list);
|
|
560
|
+
}
|
|
561
|
+
list.push(entry);
|
|
562
|
+
};
|
|
563
|
+
const MAX_CLASS_BRANCHES = 24;
|
|
564
|
+
const collectClassTokenBranchesWithEnv = (expr, depth = 0, dynamicPrefixesOut) => {
|
|
565
|
+
if (depth > 8)
|
|
566
|
+
return [[]];
|
|
567
|
+
if (ts.isStringLiteral(expr) || ts.isNoSubstitutionTemplateLiteral(expr)) {
|
|
568
|
+
return [expr.text.split(/\s+/).filter(Boolean)];
|
|
569
|
+
}
|
|
570
|
+
if (ts.isIdentifier(expr)) {
|
|
571
|
+
const bound = lookupClassBinding(expr.text);
|
|
572
|
+
if (bound && dynamicPrefixesOut) {
|
|
573
|
+
for (const p of bound.dynamicPrefixes)
|
|
574
|
+
dynamicPrefixesOut.add(p);
|
|
575
|
+
}
|
|
576
|
+
return bound ? bound.branches.map((b) => [...b]) : [[]];
|
|
577
|
+
}
|
|
578
|
+
if (ts.isParenthesizedExpression(expr) ||
|
|
579
|
+
ts.isAsExpression(expr) ||
|
|
580
|
+
ts.isTypeAssertionExpression(expr) ||
|
|
581
|
+
ts.isNonNullExpression(expr) ||
|
|
582
|
+
ts.isSatisfiesExpression(expr)) {
|
|
583
|
+
return collectClassTokenBranchesWithEnv(expr.expression, depth + 1, dynamicPrefixesOut);
|
|
584
|
+
}
|
|
585
|
+
if (ts.isTemplateExpression(expr)) {
|
|
586
|
+
const rawHead = expr.head.text;
|
|
587
|
+
let headPrefixStem = null;
|
|
588
|
+
if (/[a-zA-Z0-9_-]-$/.test(rawHead)) {
|
|
589
|
+
const lastSpace = rawHead.lastIndexOf(" ");
|
|
590
|
+
headPrefixStem = rawHead.slice(lastSpace + 1);
|
|
591
|
+
}
|
|
592
|
+
const base = rawHead
|
|
593
|
+
.split(/\s+/)
|
|
594
|
+
.filter((t) => Boolean(t) && t !== headPrefixStem);
|
|
595
|
+
let branches = [base];
|
|
596
|
+
let pendingStem = headPrefixStem;
|
|
597
|
+
for (const span of expr.templateSpans) {
|
|
598
|
+
const subBranches = collectClassTokenBranchesWithEnv(span.expression, depth + 1, dynamicPrefixesOut);
|
|
599
|
+
const nonEmptySub = subBranches.filter((b) => b.length > 0);
|
|
600
|
+
const spanText = span.literal.text;
|
|
601
|
+
let nextStem = null;
|
|
602
|
+
if (/[a-zA-Z0-9_-]-$/.test(spanText)) {
|
|
603
|
+
const lastSpace = spanText.lastIndexOf(" ");
|
|
604
|
+
nextStem = spanText.slice(lastSpace + 1);
|
|
605
|
+
}
|
|
606
|
+
const tailTokens = spanText
|
|
607
|
+
.split(/\s+/)
|
|
608
|
+
.filter((t) => Boolean(t) && t !== nextStem);
|
|
609
|
+
if (pendingStem && nonEmptySub.length === 0 && dynamicPrefixesOut) {
|
|
610
|
+
dynamicPrefixesOut.add(`${pendingStem}*`);
|
|
611
|
+
}
|
|
612
|
+
const next = [];
|
|
613
|
+
for (const prefix of branches) {
|
|
614
|
+
for (const sub of subBranches) {
|
|
615
|
+
if (pendingStem && sub.length > 0 && !/^\s/.test(span.literal.text)) {
|
|
616
|
+
const joinedFirst = `${pendingStem}${sub[0]}`;
|
|
617
|
+
next.push([...prefix, joinedFirst, ...sub.slice(1), ...tailTokens]);
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
next.push([...prefix, ...sub, ...tailTokens]);
|
|
621
|
+
}
|
|
622
|
+
if (next.length >= MAX_CLASS_BRANCHES)
|
|
623
|
+
break;
|
|
624
|
+
}
|
|
625
|
+
if (next.length >= MAX_CLASS_BRANCHES)
|
|
626
|
+
break;
|
|
627
|
+
}
|
|
628
|
+
branches = next;
|
|
629
|
+
pendingStem = nextStem;
|
|
630
|
+
}
|
|
631
|
+
if (pendingStem && dynamicPrefixesOut) {
|
|
632
|
+
dynamicPrefixesOut.add(`${pendingStem}*`);
|
|
633
|
+
}
|
|
634
|
+
return branches;
|
|
635
|
+
}
|
|
636
|
+
if (ts.isConditionalExpression(expr)) {
|
|
637
|
+
return [
|
|
638
|
+
...collectClassTokenBranchesWithEnv(expr.whenTrue, depth + 1, dynamicPrefixesOut),
|
|
639
|
+
...collectClassTokenBranchesWithEnv(expr.whenFalse, depth + 1, dynamicPrefixesOut),
|
|
640
|
+
].slice(0, MAX_CLASS_BRANCHES);
|
|
641
|
+
}
|
|
642
|
+
if (ts.isBinaryExpression(expr)) {
|
|
643
|
+
if (expr.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken) {
|
|
644
|
+
return [
|
|
645
|
+
[],
|
|
646
|
+
...collectClassTokenBranchesWithEnv(expr.right, depth + 1, dynamicPrefixesOut),
|
|
647
|
+
].slice(0, MAX_CLASS_BRANCHES);
|
|
648
|
+
}
|
|
649
|
+
if (expr.operatorToken.kind === ts.SyntaxKind.BarBarToken ||
|
|
650
|
+
expr.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken) {
|
|
651
|
+
return [
|
|
652
|
+
...collectClassTokenBranchesWithEnv(expr.left, depth + 1, dynamicPrefixesOut),
|
|
653
|
+
...collectClassTokenBranchesWithEnv(expr.right, depth + 1, dynamicPrefixesOut),
|
|
654
|
+
].slice(0, MAX_CLASS_BRANCHES);
|
|
655
|
+
}
|
|
656
|
+
if (expr.operatorToken.kind === ts.SyntaxKind.PlusToken) {
|
|
657
|
+
const left = collectClassTokenBranchesWithEnv(expr.left, depth + 1, dynamicPrefixesOut);
|
|
658
|
+
const right = collectClassTokenBranchesWithEnv(expr.right, depth + 1, dynamicPrefixesOut);
|
|
659
|
+
const combined = [];
|
|
660
|
+
for (const l of left) {
|
|
661
|
+
for (const r of right) {
|
|
662
|
+
combined.push([...l, ...r]);
|
|
663
|
+
if (combined.length >= MAX_CLASS_BRANCHES)
|
|
664
|
+
break;
|
|
665
|
+
}
|
|
666
|
+
if (combined.length >= MAX_CLASS_BRANCHES)
|
|
667
|
+
break;
|
|
668
|
+
}
|
|
669
|
+
return combined;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
if (ts.isArrayLiteralExpression(expr)) {
|
|
673
|
+
let combined = [[]];
|
|
674
|
+
for (const el of expr.elements) {
|
|
675
|
+
if (ts.isOmittedExpression(el))
|
|
676
|
+
continue;
|
|
677
|
+
const inner = ts.isSpreadElement(el) ? el.expression : el;
|
|
678
|
+
const argBranches = collectClassTokenBranchesWithEnv(inner, depth + 1, dynamicPrefixesOut);
|
|
679
|
+
if (argBranches.every((b) => b.length === 0))
|
|
680
|
+
continue;
|
|
681
|
+
const next = [];
|
|
682
|
+
for (const cur of combined) {
|
|
683
|
+
for (const ab of argBranches) {
|
|
684
|
+
next.push([...cur, ...ab]);
|
|
685
|
+
if (next.length >= MAX_CLASS_BRANCHES)
|
|
686
|
+
break;
|
|
687
|
+
}
|
|
688
|
+
if (next.length >= MAX_CLASS_BRANCHES)
|
|
689
|
+
break;
|
|
690
|
+
}
|
|
691
|
+
combined = next;
|
|
692
|
+
}
|
|
693
|
+
return combined;
|
|
694
|
+
}
|
|
695
|
+
if (ts.isCallExpression(expr)) {
|
|
696
|
+
if (ts.isPropertyAccessExpression(expr.expression)) {
|
|
697
|
+
const methodName = expr.expression.name.text;
|
|
698
|
+
const recv = expr.expression.expression;
|
|
699
|
+
if (methodName === "join" || methodName === "filter" || methodName === "concat" || methodName === "flat") {
|
|
700
|
+
return collectClassTokenBranchesWithEnv(recv, depth + 1, dynamicPrefixesOut);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
let combined = [[]];
|
|
704
|
+
for (const arg of expr.arguments) {
|
|
705
|
+
const argBranches = collectClassTokenBranchesWithEnv(arg, depth + 1, dynamicPrefixesOut);
|
|
706
|
+
if (argBranches.every((b) => b.length === 0))
|
|
707
|
+
continue;
|
|
708
|
+
const next = [];
|
|
709
|
+
for (const cur of combined) {
|
|
710
|
+
for (const ab of argBranches) {
|
|
711
|
+
next.push([...cur, ...ab]);
|
|
712
|
+
if (next.length >= MAX_CLASS_BRANCHES)
|
|
713
|
+
break;
|
|
714
|
+
}
|
|
715
|
+
if (next.length >= MAX_CLASS_BRANCHES)
|
|
716
|
+
break;
|
|
717
|
+
}
|
|
718
|
+
combined = next;
|
|
719
|
+
}
|
|
720
|
+
return combined;
|
|
721
|
+
}
|
|
722
|
+
return [[]];
|
|
723
|
+
};
|
|
724
|
+
const maybeBindClassVariable = (name, init) => {
|
|
725
|
+
const dynSet = new Set();
|
|
726
|
+
const branches = collectClassTokenBranchesWithEnv(init, 0, dynSet).filter((b) => b.length > 0);
|
|
727
|
+
if (branches.length === 0 && dynSet.size === 0)
|
|
728
|
+
return;
|
|
729
|
+
const flatTokens = branches.flat();
|
|
730
|
+
const plausible = flatTokens.every((t) => /^[!@-]?[a-zA-Z0-9_.:/\[\]-]+$/.test(t));
|
|
731
|
+
if (!plausible)
|
|
732
|
+
return;
|
|
733
|
+
classEnvStack[classEnvStack.length - 1].set(name, {
|
|
734
|
+
branches,
|
|
735
|
+
dynamicPrefixes: [...dynSet],
|
|
736
|
+
});
|
|
737
|
+
};
|
|
738
|
+
const hasExportModifier = (node) => {
|
|
739
|
+
if (!ts.canHaveModifiers(node))
|
|
740
|
+
return false;
|
|
741
|
+
const mods = ts.getModifiers(node);
|
|
742
|
+
return Boolean(mods?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword || m.kind === ts.SyntaxKind.DefaultKeyword));
|
|
743
|
+
};
|
|
744
|
+
const inspectClassTokens = (rawClassStr, lineNumber, snippet, bucket) => {
|
|
745
|
+
const tokens = rawClassStr
|
|
746
|
+
.split(/\s+/)
|
|
747
|
+
.map((t) => t.trim())
|
|
748
|
+
.filter(Boolean);
|
|
749
|
+
const typoTokensInGroup = [];
|
|
750
|
+
for (const tok of tokens) {
|
|
751
|
+
if (isKnownCssClass(tok)) {
|
|
752
|
+
bucket.stylingConventions.add("css-classes");
|
|
753
|
+
bucket.cssClassesUsed.add(tok);
|
|
754
|
+
bucket.cssClassOccurrences.push({ className: tok, lineNumber, snippet });
|
|
755
|
+
}
|
|
756
|
+
else if (isTailwindUtilityToken(tok) || tok.includes("[")) {
|
|
757
|
+
bucket.stylingConventions.add("tailwind");
|
|
758
|
+
if (!tok.includes("[")) {
|
|
759
|
+
bucket.tailwindUtilityCount++;
|
|
760
|
+
bucket.tailwindClassesUsed.push({ className: tok, lineNumber, snippet });
|
|
761
|
+
const magicMatch = MAGIC_SPACING_UTIL_RE.exec(tok);
|
|
762
|
+
if (magicMatch && magicMatch[1] && magicMatch[2]) {
|
|
763
|
+
const step = magicMatch[2];
|
|
764
|
+
if (Number(step) > 0 &&
|
|
765
|
+
!STANDARD_TAILWIND_SPACING_STEPS.has(step) &&
|
|
766
|
+
!knownThemeSpacingSteps?.has(step)) {
|
|
767
|
+
bucket.magicSpacingUtilities.push({
|
|
768
|
+
className: tok,
|
|
769
|
+
utilityPrefix: magicMatch[1],
|
|
770
|
+
value: step,
|
|
771
|
+
filePath,
|
|
772
|
+
lineNumber,
|
|
773
|
+
snippet,
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
if (isTypographyTailwindClass(tok)) {
|
|
779
|
+
typoTokensInGroup.push(tok);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
else if (/^[a-z][a-z0-9_-]+$/i.test(tok) && !tok.endsWith("-")) {
|
|
783
|
+
bucket.cssClassesUsed.add(tok);
|
|
784
|
+
bucket.cssClassOccurrences.push({ className: tok, lineNumber, snippet });
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
if (typoTokensInGroup.length >= 2) {
|
|
788
|
+
bucket.tailwindTypographyGroups.push({
|
|
789
|
+
classes: typoTokensInGroup,
|
|
790
|
+
filePath,
|
|
791
|
+
lineNumber,
|
|
792
|
+
snippet,
|
|
793
|
+
});
|
|
794
|
+
}
|
|
795
|
+
for (const m of rawClassStr.matchAll(ARBITRARY_TW_RE)) {
|
|
796
|
+
const cls = m[1];
|
|
797
|
+
if (!cls)
|
|
798
|
+
continue;
|
|
799
|
+
bucket.stylingConventions.add("tailwind");
|
|
800
|
+
bucket.arbitraryTailwind.push({
|
|
801
|
+
className: cls,
|
|
802
|
+
category: classifyArbitraryTailwindCategory(cls),
|
|
803
|
+
filePath,
|
|
804
|
+
lineNumber,
|
|
805
|
+
snippet,
|
|
806
|
+
});
|
|
807
|
+
}
|
|
808
|
+
for (const m of rawClassStr.matchAll(PALETTE_TW_RE)) {
|
|
809
|
+
const cls = m[0]?.trim();
|
|
810
|
+
if (!cls || !m[1] || !m[2])
|
|
811
|
+
continue;
|
|
812
|
+
bucket.paletteClassCandidates.push({
|
|
813
|
+
className: cls,
|
|
814
|
+
palette: m[1],
|
|
815
|
+
step: m[2],
|
|
816
|
+
filePath,
|
|
817
|
+
lineNumber,
|
|
818
|
+
snippet,
|
|
819
|
+
});
|
|
820
|
+
}
|
|
821
|
+
for (const m of rawClassStr.matchAll(ARBITRARY_TW_RE)) {
|
|
822
|
+
const cls = m[1];
|
|
823
|
+
const raw = cls ? arbitraryTailwindValue(cls) : null;
|
|
824
|
+
if (!cls || !raw)
|
|
825
|
+
continue;
|
|
826
|
+
const colors = extractColorLiterals(raw);
|
|
827
|
+
const lengths = colors.length === 0 ? extractLengthLiterals(raw) : [];
|
|
828
|
+
for (const c of colors) {
|
|
829
|
+
bucket.literalValues.push({
|
|
830
|
+
kind: "color",
|
|
831
|
+
value: c,
|
|
832
|
+
surface: "tailwind-arbitrary",
|
|
833
|
+
context: cls,
|
|
834
|
+
filePath,
|
|
835
|
+
lineNumber,
|
|
836
|
+
snippet,
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
for (const l of lengths) {
|
|
840
|
+
bucket.literalValues.push({
|
|
841
|
+
kind: "length",
|
|
842
|
+
value: l,
|
|
843
|
+
surface: "tailwind-arbitrary",
|
|
844
|
+
context: cls,
|
|
845
|
+
filePath,
|
|
846
|
+
lineNumber,
|
|
847
|
+
snippet,
|
|
848
|
+
});
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
const getJsxAttributeString = (attrs, attrName) => {
|
|
853
|
+
for (const prop of attrs.properties) {
|
|
854
|
+
if (ts.isJsxAttribute(prop) &&
|
|
855
|
+
ts.isIdentifier(prop.name) &&
|
|
856
|
+
prop.name.text === attrName &&
|
|
857
|
+
prop.initializer) {
|
|
858
|
+
if (ts.isStringLiteral(prop.initializer)) {
|
|
859
|
+
return prop.initializer.text;
|
|
860
|
+
}
|
|
861
|
+
if (ts.isJsxExpression(prop.initializer) && prop.initializer.expression) {
|
|
862
|
+
const branches = collectClassTokenBranchesWithEnv(prop.initializer.expression);
|
|
863
|
+
const merged = [...new Set(branches.flat())];
|
|
864
|
+
if (merged.length > 0)
|
|
865
|
+
return merged.join(" ");
|
|
866
|
+
if (ts.isStringLiteralLike(prop.initializer.expression)) {
|
|
867
|
+
return prop.initializer.expression.text;
|
|
868
|
+
}
|
|
869
|
+
if (ts.isTemplateExpression(prop.initializer.expression)) {
|
|
870
|
+
return (prop.initializer.expression.head.text +
|
|
871
|
+
prop.initializer.expression.templateSpans
|
|
872
|
+
.map((s) => s.literal.text)
|
|
873
|
+
.join(""));
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
return undefined;
|
|
879
|
+
};
|
|
880
|
+
const extractInlineStyleRecord = (attrs) => {
|
|
881
|
+
const out = {};
|
|
882
|
+
for (const attr of attrs.properties) {
|
|
883
|
+
if (ts.isJsxAttribute(attr) &&
|
|
884
|
+
ts.isIdentifier(attr.name) &&
|
|
885
|
+
attr.name.text === "style" &&
|
|
886
|
+
attr.initializer &&
|
|
887
|
+
ts.isJsxExpression(attr.initializer) &&
|
|
888
|
+
attr.initializer.expression &&
|
|
889
|
+
ts.isObjectLiteralExpression(attr.initializer.expression)) {
|
|
890
|
+
for (const sp of attr.initializer.expression.properties) {
|
|
891
|
+
if (!ts.isPropertyAssignment(sp))
|
|
892
|
+
continue;
|
|
893
|
+
const spName = sp.name.getText(sf);
|
|
894
|
+
if (!STYLE_VECTOR_INLINE_PROPS.has(spName))
|
|
895
|
+
continue;
|
|
896
|
+
if (ts.isStringLiteralLike(sp.initializer)) {
|
|
897
|
+
out[spName] = sp.initializer.text;
|
|
898
|
+
}
|
|
899
|
+
else if (ts.isNumericLiteral(sp.initializer)) {
|
|
900
|
+
out[spName] = `${sp.initializer.text}px`;
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
return out;
|
|
906
|
+
};
|
|
907
|
+
const computeJsxSkeletonNode = (jsxNode) => {
|
|
908
|
+
const opening = ts.isJsxElement(jsxNode) ? jsxNode.openingElement : jsxNode;
|
|
909
|
+
const tagName = opening.tagName.getText(sf);
|
|
910
|
+
if (SVG_PRIMITIVE_TAGS.has(tagName))
|
|
911
|
+
return null;
|
|
912
|
+
const isCustomTag = /^[A-Z]/.test(tagName) || tagName.includes(".");
|
|
913
|
+
const isRawDomTag = !isCustomTag && /^[a-z]/.test(tagName);
|
|
914
|
+
const roleAttr = getJsxAttributeString(opening.attributes, "role");
|
|
915
|
+
const classAttr = getJsxAttributeString(opening.attributes, "className") ?? "";
|
|
916
|
+
const firstSemanticClass = classAttr
|
|
917
|
+
.split(/\s+/)
|
|
918
|
+
.map((t) => t.trim())
|
|
919
|
+
.find((t) => t !== "" && isKnownCssClass(t));
|
|
920
|
+
const cleanBlockClass = firstSemanticClass
|
|
921
|
+
? firstSemanticClass.split("--")[0]
|
|
922
|
+
: undefined;
|
|
923
|
+
const hasOwnSemantic = Boolean(roleAttr || cleanBlockClass);
|
|
924
|
+
const tagDescriptor = roleAttr
|
|
925
|
+
? `${tagName}[role=${roleAttr}]`
|
|
926
|
+
: cleanBlockClass
|
|
927
|
+
? `${tagName}.${cleanBlockClass}`
|
|
928
|
+
: tagName;
|
|
929
|
+
if (ts.isJsxSelfClosingElement(jsxNode)) {
|
|
930
|
+
return {
|
|
931
|
+
canonicalSig: tagDescriptor,
|
|
932
|
+
shapeStr: tagDescriptor,
|
|
933
|
+
rootTag: tagDescriptor,
|
|
934
|
+
elementCount: 1,
|
|
935
|
+
rawDomCount: isRawDomTag ? 1 : 0,
|
|
936
|
+
customCount: isCustomTag ? 1 : 0,
|
|
937
|
+
hasSemanticClassOrRole: hasOwnSemantic,
|
|
938
|
+
depth: 1,
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
const childSkeletons = [];
|
|
942
|
+
const collectDirectJsxChildren = (childrenNodes) => {
|
|
943
|
+
for (const child of childrenNodes) {
|
|
944
|
+
if (ts.isJsxElement(child) || ts.isJsxSelfClosingElement(child)) {
|
|
945
|
+
const sk = computeJsxSkeletonNode(child);
|
|
946
|
+
if (sk)
|
|
947
|
+
childSkeletons.push(sk);
|
|
948
|
+
}
|
|
949
|
+
else if (ts.isJsxFragment(child)) {
|
|
950
|
+
collectDirectJsxChildren(child.children);
|
|
951
|
+
}
|
|
952
|
+
else if (ts.isJsxExpression(child) && child.expression) {
|
|
953
|
+
const walkExpr = (exprNode) => {
|
|
954
|
+
if (ts.isJsxElement(exprNode) || ts.isJsxSelfClosingElement(exprNode)) {
|
|
955
|
+
const sk = computeJsxSkeletonNode(exprNode);
|
|
956
|
+
if (sk)
|
|
957
|
+
childSkeletons.push(sk);
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
if (ts.isJsxFragment(exprNode)) {
|
|
961
|
+
collectDirectJsxChildren(exprNode.children);
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
ts.forEachChild(exprNode, walkExpr);
|
|
965
|
+
};
|
|
966
|
+
walkExpr(child.expression);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
};
|
|
970
|
+
collectDirectJsxChildren(jsxNode.children);
|
|
971
|
+
if (childSkeletons.length === 0) {
|
|
972
|
+
return {
|
|
973
|
+
canonicalSig: tagDescriptor,
|
|
974
|
+
shapeStr: tagDescriptor,
|
|
975
|
+
rootTag: tagDescriptor,
|
|
976
|
+
elementCount: 1,
|
|
977
|
+
rawDomCount: isRawDomTag ? 1 : 0,
|
|
978
|
+
customCount: isCustomTag ? 1 : 0,
|
|
979
|
+
hasSemanticClassOrRole: hasOwnSemantic,
|
|
980
|
+
depth: 1,
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
let totalElements = 1;
|
|
984
|
+
let totalCustom = isCustomTag ? 1 : 0;
|
|
985
|
+
let totalRawDom = isRawDomTag ? 1 : 0;
|
|
986
|
+
let anySemantic = hasOwnSemantic;
|
|
987
|
+
let maxChildDepth = 0;
|
|
988
|
+
const dedupedChildSigs = [];
|
|
989
|
+
const dedupedChildShapes = [];
|
|
990
|
+
for (const c of childSkeletons) {
|
|
991
|
+
totalElements += c.elementCount;
|
|
992
|
+
totalCustom += c.customCount;
|
|
993
|
+
totalRawDom += c.rawDomCount;
|
|
994
|
+
if (c.hasSemanticClassOrRole)
|
|
995
|
+
anySemantic = true;
|
|
996
|
+
if (c.depth > maxChildDepth)
|
|
997
|
+
maxChildDepth = c.depth;
|
|
998
|
+
const prevSig = dedupedChildSigs[dedupedChildSigs.length - 1];
|
|
999
|
+
if (prevSig === c.canonicalSig || prevSig === `${c.canonicalSig}+`) {
|
|
1000
|
+
dedupedChildSigs[dedupedChildSigs.length - 1] = `${c.canonicalSig}+`;
|
|
1001
|
+
dedupedChildShapes[dedupedChildShapes.length - 1] = `${c.shapeStr}+`;
|
|
1002
|
+
}
|
|
1003
|
+
else {
|
|
1004
|
+
dedupedChildSigs.push(c.canonicalSig);
|
|
1005
|
+
dedupedChildShapes.push(c.shapeStr);
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
const canonicalSig = `${tagDescriptor}>(${dedupedChildSigs.join(",")})`;
|
|
1009
|
+
const shapeStr = `${tagDescriptor} > [${dedupedChildShapes.slice(0, 4).join(", ")}${dedupedChildShapes.length > 4 ? ", ..." : ""}]`;
|
|
1010
|
+
return {
|
|
1011
|
+
canonicalSig,
|
|
1012
|
+
shapeStr,
|
|
1013
|
+
rootTag: tagDescriptor,
|
|
1014
|
+
elementCount: totalElements,
|
|
1015
|
+
rawDomCount: totalRawDom,
|
|
1016
|
+
customCount: totalCustom,
|
|
1017
|
+
hasSemanticClassOrRole: anySemantic,
|
|
1018
|
+
depth: 1 + maxChildDepth,
|
|
1019
|
+
};
|
|
1020
|
+
};
|
|
1021
|
+
/** Detects raw unextracted Tabs, SegmentedControl, and BadgePill shapes on JSX nodes. */
|
|
1022
|
+
const inspectUiShapeCandidate = (jsxNode, bucket) => {
|
|
1023
|
+
const opening = jsxNode.openingElement;
|
|
1024
|
+
const containerTag = opening.tagName.getText(sf);
|
|
1025
|
+
if (/^[A-Z]/.test(containerTag) || SVG_PRIMITIVE_TAGS.has(containerTag))
|
|
1026
|
+
return;
|
|
1027
|
+
const containerRole = getJsxAttributeString(opening.attributes, "role");
|
|
1028
|
+
const containerClassStr = getJsxAttributeString(opening.attributes, "className") ?? "";
|
|
1029
|
+
const containerClasses = containerClassStr.split(/\s+/).filter(Boolean);
|
|
1030
|
+
const lineNumber = getLine(opening.getStart(sf));
|
|
1031
|
+
const snippet = getLineSnippet(rawLines, lineNumber);
|
|
1032
|
+
// 1. Collect direct interactive tab/toggle triggers inside this container (explicit or mapped)
|
|
1033
|
+
const directTriggers = [];
|
|
1034
|
+
let hasMappedTrigger = false;
|
|
1035
|
+
const inspectChildJsxTrigger = (el, fromMap) => {
|
|
1036
|
+
const elOpen = ts.isJsxElement(el) ? el.openingElement : el;
|
|
1037
|
+
const elTag = elOpen.tagName.getText(sf);
|
|
1038
|
+
const elRole = getJsxAttributeString(elOpen.attributes, "role");
|
|
1039
|
+
const isTrigger = elTag === "button" || elRole === "tab" || elRole === "radio" || elRole === "menuitem";
|
|
1040
|
+
if (!isTrigger)
|
|
1041
|
+
return;
|
|
1042
|
+
const clsStr = getJsxAttributeString(elOpen.attributes, "className") ?? "";
|
|
1043
|
+
const hasAttr = (name) => elOpen.attributes.properties.some((p) => ts.isJsxAttribute(p) && ts.isIdentifier(p.name) && p.name.text === name);
|
|
1044
|
+
const clsAttrNode = elOpen.attributes.properties.find((p) => ts.isJsxAttribute(p) && ts.isIdentifier(p.name) && (p.name.text === "className" || p.name.text === "class"));
|
|
1045
|
+
let hasConditionalClassName = false;
|
|
1046
|
+
if (clsAttrNode?.initializer && ts.isJsxExpression(clsAttrNode.initializer) && clsAttrNode.initializer.expression) {
|
|
1047
|
+
const expr = clsAttrNode.initializer.expression;
|
|
1048
|
+
const branches = collectClassTokenBranchesWithEnv(expr);
|
|
1049
|
+
hasConditionalClassName =
|
|
1050
|
+
branches.length > 1 ||
|
|
1051
|
+
ts.isConditionalExpression(expr) ||
|
|
1052
|
+
ts.isTemplateExpression(expr) ||
|
|
1053
|
+
ts.isCallExpression(expr) ||
|
|
1054
|
+
ts.isBinaryExpression(expr);
|
|
1055
|
+
}
|
|
1056
|
+
directTriggers.push({
|
|
1057
|
+
startOffset: elOpen.getStart(sf),
|
|
1058
|
+
tag: elTag,
|
|
1059
|
+
role: elRole,
|
|
1060
|
+
classes: clsStr.split(/\s+/).filter(Boolean),
|
|
1061
|
+
hasAriaSelected: hasAttr("aria-selected"),
|
|
1062
|
+
hasAriaPressed: hasAttr("aria-pressed"),
|
|
1063
|
+
hasAriaChecked: hasAttr("aria-checked"),
|
|
1064
|
+
hasDataActiveAttr: hasAttr("data-state") || hasAttr("data-active") || hasAttr("data-selected"),
|
|
1065
|
+
hasConditionalClassName,
|
|
1066
|
+
hasOnClick: hasAttr("onClick"),
|
|
1067
|
+
});
|
|
1068
|
+
if (fromMap)
|
|
1069
|
+
hasMappedTrigger = true;
|
|
1070
|
+
};
|
|
1071
|
+
const scanContainerChildren = (children) => {
|
|
1072
|
+
for (const ch of children) {
|
|
1073
|
+
if (ts.isJsxElement(ch) || ts.isJsxSelfClosingElement(ch)) {
|
|
1074
|
+
inspectChildJsxTrigger(ch, false);
|
|
1075
|
+
}
|
|
1076
|
+
else if (ts.isJsxFragment(ch)) {
|
|
1077
|
+
scanContainerChildren(ch.children);
|
|
1078
|
+
}
|
|
1079
|
+
else if (ts.isJsxExpression(ch) && ch.expression) {
|
|
1080
|
+
const findMappedRoot = (n) => {
|
|
1081
|
+
if (ts.isJsxElement(n) || ts.isJsxSelfClosingElement(n)) {
|
|
1082
|
+
inspectChildJsxTrigger(n, true);
|
|
1083
|
+
return;
|
|
1084
|
+
}
|
|
1085
|
+
if (ts.isJsxFragment(n)) {
|
|
1086
|
+
scanContainerChildren(n.children);
|
|
1087
|
+
return;
|
|
1088
|
+
}
|
|
1089
|
+
ts.forEachChild(n, findMappedRoot);
|
|
1090
|
+
};
|
|
1091
|
+
findMappedRoot(ch.expression);
|
|
1092
|
+
}
|
|
1093
|
+
}
|
|
1094
|
+
};
|
|
1095
|
+
scanContainerChildren(jsxNode.children);
|
|
1096
|
+
const hasEnoughTriggers = directTriggers.length >= 2 || (hasMappedTrigger && directTriggers.length === 1);
|
|
1097
|
+
const hasExplicitAriaToggle = containerRole === "tablist" ||
|
|
1098
|
+
containerRole === "radiogroup" ||
|
|
1099
|
+
directTriggers.some((t) => t.role === "tab" ||
|
|
1100
|
+
t.role === "radio" ||
|
|
1101
|
+
t.hasAriaSelected ||
|
|
1102
|
+
t.hasAriaPressed ||
|
|
1103
|
+
t.hasAriaChecked ||
|
|
1104
|
+
t.hasDataActiveAttr);
|
|
1105
|
+
const hasConditionalGroupToggle = directTriggers.length <= 6 &&
|
|
1106
|
+
directTriggers.every((t) => t.hasOnClick) &&
|
|
1107
|
+
((hasMappedTrigger && directTriggers.some((t) => t.hasConditionalClassName)) ||
|
|
1108
|
+
directTriggers.every((t) => t.hasConditionalClassName));
|
|
1109
|
+
if (hasEnoughTriggers && (hasExplicitAriaToggle || hasConditionalGroupToggle)) {
|
|
1110
|
+
const itemClasses = [...new Set(directTriggers.flatMap((t) => t.classes))];
|
|
1111
|
+
const hasTabSemantics = containerRole === "tablist" ||
|
|
1112
|
+
directTriggers.some((t) => t.role === "tab" || t.hasAriaSelected) ||
|
|
1113
|
+
containerClasses.some((c) => /^border-b(?:-\d+)?$/.test(c) || c.endsWith("__tabs")) ||
|
|
1114
|
+
itemClasses.some((c) => c.includes("border-b") || /tab/i.test(c));
|
|
1115
|
+
const hasEnclosedTrack = containerRole === "group" ||
|
|
1116
|
+
(containerClasses.some((c) => c.startsWith("rounded")) &&
|
|
1117
|
+
containerClasses.some((c) => c === "border" || c.startsWith("bg-")));
|
|
1118
|
+
const shapeKind = containerRole === "radiogroup" ||
|
|
1119
|
+
directTriggers.some((t) => t.role === "radio" || t.hasAriaPressed || t.hasAriaChecked) ||
|
|
1120
|
+
(!hasTabSemantics && hasEnclosedTrack)
|
|
1121
|
+
? "SegmentedControl"
|
|
1122
|
+
: hasTabSemantics
|
|
1123
|
+
? "Tabs"
|
|
1124
|
+
: "SegmentedControl";
|
|
1125
|
+
bucket.uiShapeCandidates.push({
|
|
1126
|
+
shapeKind,
|
|
1127
|
+
filePath,
|
|
1128
|
+
lineNumber,
|
|
1129
|
+
snippet,
|
|
1130
|
+
absorbedButtonStarts: directTriggers.map((t) => t.startOffset),
|
|
1131
|
+
variantCount: hasMappedTrigger ? undefined : directTriggers.length,
|
|
1132
|
+
containerClasses,
|
|
1133
|
+
itemClasses,
|
|
1134
|
+
inlineStyle: extractInlineStyleRecord(opening.attributes),
|
|
1135
|
+
});
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
// 2. Compact inline non-interactive pill/chip BadgePill candidate (Tailwind pill OR CSS class verified by styleVector)
|
|
1139
|
+
if ((containerTag === "span" || containerTag === "code" || containerTag === "div") && !containerRole) {
|
|
1140
|
+
const childJsxCount = jsxNode.children.filter((c) => ts.isJsxElement(c) || ts.isJsxSelfClosingElement(c)).length;
|
|
1141
|
+
const hasRoundedPill = containerClasses.some((c) => c === "rounded-full" || c === "rounded-md" || c === "rounded");
|
|
1142
|
+
const hasBgOrBorder = containerClasses.some((c) => c.startsWith("bg-") || c === "border" || c.startsWith("border-"));
|
|
1143
|
+
const hasCompactType = containerClasses.some((c) => /^text-(?:2xs|xs|hud-2xs|hud-xs|\[\d+px\])$/.test(c));
|
|
1144
|
+
const hasInlineFlex = containerClasses.some((c) => c === "inline-flex" || c === "inline-block");
|
|
1145
|
+
const hasKnownCssBadgeClass = containerClasses.some(isKnownCssClass);
|
|
1146
|
+
if (childJsxCount <= 2 &&
|
|
1147
|
+
(((containerClasses.includes("rounded-full") || (hasInlineFlex && hasRoundedPill && hasCompactType)) && hasBgOrBorder) ||
|
|
1148
|
+
hasKnownCssBadgeClass)) {
|
|
1149
|
+
bucket.uiShapeCandidates.push({
|
|
1150
|
+
shapeKind: "BadgePill",
|
|
1151
|
+
filePath,
|
|
1152
|
+
lineNumber,
|
|
1153
|
+
snippet,
|
|
1154
|
+
absorbedButtonStarts: [],
|
|
1155
|
+
containerClasses,
|
|
1156
|
+
itemClasses: [],
|
|
1157
|
+
inlineStyle: extractInlineStyleRecord(opening.attributes),
|
|
1158
|
+
});
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
const emitSlotRecording = (bucket, slotName, propName, kind, rawVal, lineNumber, snippet) => {
|
|
1163
|
+
if (kind === "lit") {
|
|
1164
|
+
const isTrivialOpaqueAlpha = propName.endsWith("alpha") && rawVal.trim() === "1";
|
|
1165
|
+
if (!isTrivialOpaqueAlpha) {
|
|
1166
|
+
bucket.canvasLiteralCount++;
|
|
1167
|
+
bucket.canvasLiterals.push({
|
|
1168
|
+
slot: slotName,
|
|
1169
|
+
prop: propName,
|
|
1170
|
+
value: rawVal,
|
|
1171
|
+
filePath,
|
|
1172
|
+
lineNumber,
|
|
1173
|
+
snippet,
|
|
1174
|
+
});
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
else if (kind === "tsConst") {
|
|
1178
|
+
bucket.canvasTsConstCount++;
|
|
1179
|
+
}
|
|
1180
|
+
else {
|
|
1181
|
+
bucket.canvasCssCount++;
|
|
1182
|
+
}
|
|
1183
|
+
};
|
|
1184
|
+
const visit = (node, currentBucket) => {
|
|
1185
|
+
let activeBucket = currentBucket;
|
|
1186
|
+
let pushedFnScope = false;
|
|
1187
|
+
if (ts.isFunctionDeclaration(node) && node.name) {
|
|
1188
|
+
activeBucket = ensureOwnerBucket(node.name.text, getLine(node.getStart(sf)), getLine(node.getEnd()), hasExportModifier(node));
|
|
1189
|
+
if (activeBucket.propContract.length === 0) {
|
|
1190
|
+
activeBucket.propContract = extractPropContractFromFunc(node);
|
|
1191
|
+
}
|
|
1192
|
+
pushedFnScope = true;
|
|
1193
|
+
}
|
|
1194
|
+
else if (ts.isClassDeclaration(node) && node.name) {
|
|
1195
|
+
activeBucket = ensureOwnerBucket(node.name.text, getLine(node.getStart(sf)), getLine(node.getEnd()), hasExportModifier(node));
|
|
1196
|
+
}
|
|
1197
|
+
else if (ts.isVariableDeclaration(node) &&
|
|
1198
|
+
ts.isIdentifier(node.name) &&
|
|
1199
|
+
node.initializer &&
|
|
1200
|
+
(ts.isArrowFunction(node.initializer) ||
|
|
1201
|
+
ts.isFunctionExpression(node.initializer) ||
|
|
1202
|
+
ts.isCallExpression(node.initializer))) {
|
|
1203
|
+
const isFuncLike = ts.isArrowFunction(node.initializer) ||
|
|
1204
|
+
ts.isFunctionExpression(node.initializer) ||
|
|
1205
|
+
(ts.isCallExpression(node.initializer) &&
|
|
1206
|
+
/^(memo|forwardRef|React\.memo|React\.forwardRef)$/.test(node.initializer.expression.getText(sf)));
|
|
1207
|
+
if (isFuncLike) {
|
|
1208
|
+
const varStmt = node.parent?.parent;
|
|
1209
|
+
const exported = varStmt ? hasExportModifier(varStmt) : false;
|
|
1210
|
+
activeBucket = ensureOwnerBucket(node.name.text, getLine(node.getStart(sf)), getLine(node.getEnd()), exported);
|
|
1211
|
+
const annotationProps = node.type && ts.isTypeReferenceNode(node.type) && node.type.typeArguments?.length
|
|
1212
|
+
? node.type.typeArguments[0]
|
|
1213
|
+
: undefined;
|
|
1214
|
+
if (activeBucket.propContract.length === 0 &&
|
|
1215
|
+
(ts.isArrowFunction(node.initializer) || ts.isFunctionExpression(node.initializer))) {
|
|
1216
|
+
activeBucket.propContract = extractPropContractFromFunc(node.initializer, annotationProps);
|
|
1217
|
+
}
|
|
1218
|
+
else if (activeBucket.propContract.length === 0 &&
|
|
1219
|
+
ts.isCallExpression(node.initializer) &&
|
|
1220
|
+
node.initializer.arguments.length > 0 &&
|
|
1221
|
+
(ts.isArrowFunction(node.initializer.arguments[0]) ||
|
|
1222
|
+
ts.isFunctionExpression(node.initializer.arguments[0]))) {
|
|
1223
|
+
const genericProps = node.initializer.typeArguments && node.initializer.typeArguments.length >= 2
|
|
1224
|
+
? node.initializer.typeArguments[1]
|
|
1225
|
+
: node.initializer.typeArguments?.[0];
|
|
1226
|
+
activeBucket.propContract = extractPropContractFromFunc(node.initializer.arguments[0], annotationProps ?? genericProps);
|
|
1227
|
+
}
|
|
1228
|
+
pushedFnScope = true;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
if (pushedFnScope) {
|
|
1232
|
+
classEnvStack.push(new Map());
|
|
1233
|
+
slotBindingStack.push(new Map());
|
|
1234
|
+
}
|
|
1235
|
+
// Track intra-function & module variable bindings for className dataflow & canvas slot recorder locals
|
|
1236
|
+
let capturedSlotRecorderVarInit = false;
|
|
1237
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) {
|
|
1238
|
+
maybeBindClassVariable(node.name.text, node.initializer);
|
|
1239
|
+
if (slotRecorderFactories.length > 0 && ts.isCallExpression(node.initializer)) {
|
|
1240
|
+
const calleeText = node.initializer.expression.getText(sf);
|
|
1241
|
+
if (/^(?:[a-zA-Z_$][a-zA-Z0-9_$]*\.)?(lit|css|tsConst)$/.test(calleeText)) {
|
|
1242
|
+
if (calleeText.includes(".")) {
|
|
1243
|
+
activeBucket.usesSlotRecorder = true;
|
|
1244
|
+
activeBucket.stylingConventions.add("pixi-canvas");
|
|
1245
|
+
}
|
|
1246
|
+
const method = calleeText.split(".").pop();
|
|
1247
|
+
const valArg = method === "lit" && node.initializer.arguments.length >= 2
|
|
1248
|
+
? node.initializer.arguments[1]
|
|
1249
|
+
: node.initializer.arguments[0];
|
|
1250
|
+
const initLine = getLine(node.initializer.getStart(sf));
|
|
1251
|
+
recordSlotVarOrigin(node.name.text, {
|
|
1252
|
+
kind: method,
|
|
1253
|
+
rawVal: valArg?.getText(sf) ?? "?",
|
|
1254
|
+
lineNumber: initLine,
|
|
1255
|
+
snippet: getLineSnippet(rawLines, initLine),
|
|
1256
|
+
used: false,
|
|
1257
|
+
});
|
|
1258
|
+
capturedSlotRecorderVarInit = true;
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
else if (ts.isBinaryExpression(node) &&
|
|
1263
|
+
node.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
1264
|
+
ts.isIdentifier(node.left)) {
|
|
1265
|
+
maybeBindClassVariable(node.left.text, node.right);
|
|
1266
|
+
if (slotRecorderFactories.length > 0 && ts.isCallExpression(node.right)) {
|
|
1267
|
+
const calleeText = node.right.expression.getText(sf);
|
|
1268
|
+
if (/^(?:[a-zA-Z_$][a-zA-Z0-9_$]*\.)?(lit|css|tsConst)$/.test(calleeText)) {
|
|
1269
|
+
if (calleeText.includes(".")) {
|
|
1270
|
+
activeBucket.usesSlotRecorder = true;
|
|
1271
|
+
activeBucket.stylingConventions.add("pixi-canvas");
|
|
1272
|
+
}
|
|
1273
|
+
const method = calleeText.split(".").pop();
|
|
1274
|
+
const valArg = method === "lit" && node.right.arguments.length >= 2
|
|
1275
|
+
? node.right.arguments[1]
|
|
1276
|
+
: node.right.arguments[0];
|
|
1277
|
+
const assignLine = getLine(node.right.getStart(sf));
|
|
1278
|
+
recordSlotVarOrigin(node.left.text, {
|
|
1279
|
+
kind: method,
|
|
1280
|
+
rawVal: valArg?.getText(sf) ?? "?",
|
|
1281
|
+
lineNumber: assignLine,
|
|
1282
|
+
snippet: getLineSnippet(rawLines, assignLine),
|
|
1283
|
+
used: false,
|
|
1284
|
+
});
|
|
1285
|
+
capturedSlotRecorderVarInit = true;
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {
|
|
1290
|
+
const spec = node.moduleSpecifier.text;
|
|
1291
|
+
if (spec.endsWith(".css")) {
|
|
1292
|
+
cssImports.push(spec);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
if (ts.isPropertyAssignment(node)) {
|
|
1296
|
+
if (ts.isIdentifier(node.name) &&
|
|
1297
|
+
(node.name.text === "variable" || node.name.text === "cssVariable") &&
|
|
1298
|
+
ts.isStringLiteralLike(node.initializer) &&
|
|
1299
|
+
/^--[a-zA-Z0-9_-]+$/.test(node.initializer.text)) {
|
|
1300
|
+
let fontFamily;
|
|
1301
|
+
if (ts.isObjectLiteralExpression(node.parent)) {
|
|
1302
|
+
for (const prop of node.parent.properties) {
|
|
1303
|
+
if (ts.isPropertyAssignment(prop) &&
|
|
1304
|
+
ts.isIdentifier(prop.name) &&
|
|
1305
|
+
(prop.name.text === "name" || prop.name.text === "family") &&
|
|
1306
|
+
ts.isStringLiteralLike(prop.initializer)) {
|
|
1307
|
+
fontFamily = `"${prop.initializer.text}"`;
|
|
1308
|
+
break;
|
|
1309
|
+
}
|
|
1310
|
+
}
|
|
1311
|
+
if (!fontFamily && node.parent.parent && ts.isCallExpression(node.parent.parent)) {
|
|
1312
|
+
const calleeName = node.parent.parent.expression.getText(sf).split(".").pop() ?? "";
|
|
1313
|
+
if (calleeName && !/^(?:localFont|defineConfig|font)$/.test(calleeName)) {
|
|
1314
|
+
fontFamily = `"${calleeName.replace(/_/g, " ")}"`;
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
definedFontVars.push({
|
|
1319
|
+
name: node.initializer.text,
|
|
1320
|
+
lineNumber: getLine(node.getStart(sf)),
|
|
1321
|
+
scope: "global",
|
|
1322
|
+
...(fontFamily ? { fontFamily } : {}),
|
|
1323
|
+
});
|
|
1324
|
+
}
|
|
1325
|
+
else if (ts.isStringLiteralLike(node.name) && /^--[a-zA-Z0-9_-]+$/.test(node.name.text)) {
|
|
1326
|
+
definedFontVars.push({
|
|
1327
|
+
name: node.name.text,
|
|
1328
|
+
lineNumber: getLine(node.getStart(sf)),
|
|
1329
|
+
scope: "scoped",
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
}
|
|
1333
|
+
if (ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) {
|
|
1334
|
+
const text = node.text;
|
|
1335
|
+
const lineNumber = getLine(node.getStart(sf));
|
|
1336
|
+
const snippet = getLineSnippet(rawLines, lineNumber);
|
|
1337
|
+
for (const m of text.matchAll(VAR_REF_RE)) {
|
|
1338
|
+
const tokenName = m[1];
|
|
1339
|
+
if (!tokenName)
|
|
1340
|
+
continue;
|
|
1341
|
+
const ref = {
|
|
1342
|
+
name: tokenName,
|
|
1343
|
+
filePath,
|
|
1344
|
+
lineNumber,
|
|
1345
|
+
snippet,
|
|
1346
|
+
kind: "ts-var",
|
|
1347
|
+
...(m[2] ? { hasFallback: true } : {}),
|
|
1348
|
+
};
|
|
1349
|
+
tokenReferences.push(ref);
|
|
1350
|
+
activeBucket.tokensConsumed.add(tokenName);
|
|
1351
|
+
activeBucket.tsTokenRefs.push(ref);
|
|
1352
|
+
}
|
|
1353
|
+
const parent = node.parent;
|
|
1354
|
+
const isModuleSpecifier = parent !== undefined &&
|
|
1355
|
+
(ts.isImportDeclaration(parent) ||
|
|
1356
|
+
ts.isExportDeclaration(parent) ||
|
|
1357
|
+
ts.isLiteralTypeNode(parent) ||
|
|
1358
|
+
ts.isExternalModuleReference(parent));
|
|
1359
|
+
if (!isModuleSpecifier && text.includes("bg-") && text.includes("text-")) {
|
|
1360
|
+
recordTailwindClassBranches([text.split(/\s+/).filter(Boolean)], lineNumber);
|
|
1361
|
+
}
|
|
1362
|
+
const isCanvasLitArg = parent !== undefined &&
|
|
1363
|
+
ts.isCallExpression(parent) &&
|
|
1364
|
+
/(?:^|\.)lit$/.test(parent.expression.getText(sf));
|
|
1365
|
+
if (!isModuleSpecifier &&
|
|
1366
|
+
!isCanvasLitArg &&
|
|
1367
|
+
!consumedStringNodes.has(node) &&
|
|
1368
|
+
looksLikeColorLiteral(text)) {
|
|
1369
|
+
let context;
|
|
1370
|
+
let surface = "string-literal";
|
|
1371
|
+
const attr = parent && ts.isJsxAttribute(parent)
|
|
1372
|
+
? parent
|
|
1373
|
+
: parent && ts.isJsxExpression(parent) && parent.parent && ts.isJsxAttribute(parent.parent)
|
|
1374
|
+
? parent.parent
|
|
1375
|
+
: undefined;
|
|
1376
|
+
if (attr && ts.isIdentifier(attr.name)) {
|
|
1377
|
+
context = attr.name.text;
|
|
1378
|
+
surface = "jsx-prop";
|
|
1379
|
+
}
|
|
1380
|
+
else if (parent && ts.isPropertyAssignment(parent)) {
|
|
1381
|
+
context = parent.name.getText(sf);
|
|
1382
|
+
}
|
|
1383
|
+
if (!context || !/^(?:href|id|key|name|htmlFor|to|src|alt)$/.test(context)) {
|
|
1384
|
+
activeBucket.literalValues.push({
|
|
1385
|
+
kind: "color",
|
|
1386
|
+
value: text.trim(),
|
|
1387
|
+
surface,
|
|
1388
|
+
...(context ? { context } : {}),
|
|
1389
|
+
filePath,
|
|
1390
|
+
lineNumber,
|
|
1391
|
+
snippet,
|
|
1392
|
+
});
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
if (hasCssInJs && ts.isTaggedTemplateExpression(node)) {
|
|
1397
|
+
activeBucket.stylingConventions.add("css-in-js");
|
|
1398
|
+
const tpl = node.template;
|
|
1399
|
+
const tplText = ts.isNoSubstitutionTemplateLiteral(tpl)
|
|
1400
|
+
? tpl.text
|
|
1401
|
+
: tpl.head.text + tpl.templateSpans.map((sp) => sp.literal.text).join(" ");
|
|
1402
|
+
const tplLine = getLine(node.getStart(sf));
|
|
1403
|
+
const tplSnippet = getLineSnippet(rawLines, tplLine);
|
|
1404
|
+
for (const c of extractColorLiterals(tplText)) {
|
|
1405
|
+
activeBucket.literalValues.push({
|
|
1406
|
+
kind: "color",
|
|
1407
|
+
value: c,
|
|
1408
|
+
surface: "string-literal",
|
|
1409
|
+
context: "css-in-js",
|
|
1410
|
+
filePath,
|
|
1411
|
+
lineNumber: tplLine,
|
|
1412
|
+
snippet: tplSnippet,
|
|
1413
|
+
});
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
// JSX Attribute scanning (with intra-function variable expansion for className={ident})
|
|
1417
|
+
if (ts.isJsxAttribute(node) && ts.isIdentifier(node.name)) {
|
|
1418
|
+
const attrName = node.name.text;
|
|
1419
|
+
const lineNumber = getLine(node.getStart(sf));
|
|
1420
|
+
const snippet = getLineSnippet(rawLines, lineNumber);
|
|
1421
|
+
if ((attrName === "className" || attrName === "class") && node.initializer) {
|
|
1422
|
+
if (ts.isStringLiteral(node.initializer)) {
|
|
1423
|
+
consumedStringNodes.add(node.initializer);
|
|
1424
|
+
inspectClassTokens(node.initializer.text, lineNumber, snippet, activeBucket);
|
|
1425
|
+
}
|
|
1426
|
+
else if (ts.isJsxExpression(node.initializer) && node.initializer.expression) {
|
|
1427
|
+
const expr = node.initializer.expression;
|
|
1428
|
+
if (ts.isStringLiteralLike(expr)) {
|
|
1429
|
+
consumedStringNodes.add(expr);
|
|
1430
|
+
inspectClassTokens(expr.text, lineNumber, snippet, activeBucket);
|
|
1431
|
+
}
|
|
1432
|
+
else if (ts.isTemplateExpression(expr)) {
|
|
1433
|
+
inspectClassTokens(expr.head.text, lineNumber, snippet, activeBucket);
|
|
1434
|
+
const headTrimmed = expr.head.text;
|
|
1435
|
+
if (/[a-zA-Z0-9_-]-$/.test(headTrimmed)) {
|
|
1436
|
+
const lastSpace = headTrimmed.lastIndexOf(" ");
|
|
1437
|
+
const prefix = headTrimmed.slice(lastSpace + 1);
|
|
1438
|
+
if (prefix)
|
|
1439
|
+
activeBucket.dynamicClassPrefixes.add(`${prefix}*`);
|
|
1440
|
+
}
|
|
1441
|
+
for (const span of expr.templateSpans) {
|
|
1442
|
+
inspectClassTokens(span.literal.text, getLine(span.getStart(sf)), getLineSnippet(rawLines, getLine(span.getStart(sf))), activeBucket);
|
|
1443
|
+
if (/[a-zA-Z0-9_-]-$/.test(span.literal.text)) {
|
|
1444
|
+
const lastSpace = span.literal.text.lastIndexOf(" ");
|
|
1445
|
+
const prefix = span.literal.text.slice(lastSpace + 1);
|
|
1446
|
+
if (prefix)
|
|
1447
|
+
activeBucket.dynamicClassPrefixes.add(`${prefix}*`);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
const seenBoundIdents = new Set();
|
|
1452
|
+
const walkClassExpr = (sub) => {
|
|
1453
|
+
if (ts.isStringLiteral(sub) || ts.isNoSubstitutionTemplateLiteral(sub)) {
|
|
1454
|
+
if (!consumedStringNodes.has(sub)) {
|
|
1455
|
+
consumedStringNodes.add(sub);
|
|
1456
|
+
const subLine = getLine(sub.getStart(sf));
|
|
1457
|
+
inspectClassTokens(sub.text, subLine, getLineSnippet(rawLines, subLine), activeBucket);
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
else if (ts.isIdentifier(sub)) {
|
|
1461
|
+
// Expand intra-function/module className variable bindings at usage site
|
|
1462
|
+
const parent = sub.parent;
|
|
1463
|
+
const isMethodOrPropName = parent &&
|
|
1464
|
+
((ts.isPropertyAccessExpression(parent) && parent.name === sub) ||
|
|
1465
|
+
(ts.isPropertyAssignment(parent) && parent.name === sub));
|
|
1466
|
+
if (!isMethodOrPropName && !seenBoundIdents.has(sub.text)) {
|
|
1467
|
+
const bound = lookupClassBinding(sub.text);
|
|
1468
|
+
if (bound) {
|
|
1469
|
+
seenBoundIdents.add(sub.text);
|
|
1470
|
+
for (const dp of bound.dynamicPrefixes) {
|
|
1471
|
+
activeBucket.dynamicClassPrefixes.add(dp);
|
|
1472
|
+
}
|
|
1473
|
+
for (const branch of bound.branches) {
|
|
1474
|
+
if (branch.length > 0) {
|
|
1475
|
+
inspectClassTokens(branch.join(" "), lineNumber, snippet, activeBucket);
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
else if (ts.isPropertyAccessExpression(sub) &&
|
|
1482
|
+
ts.isIdentifier(sub.expression) &&
|
|
1483
|
+
cssModuleBindings.has(sub.expression.text)) {
|
|
1484
|
+
activeBucket.stylingConventions.add("css-modules");
|
|
1485
|
+
activeBucket.cssClassesUsed.add(sub.name.text);
|
|
1486
|
+
}
|
|
1487
|
+
else if (ts.isElementAccessExpression(sub) &&
|
|
1488
|
+
ts.isIdentifier(sub.expression) &&
|
|
1489
|
+
cssModuleBindings.has(sub.expression.text) &&
|
|
1490
|
+
ts.isStringLiteralLike(sub.argumentExpression)) {
|
|
1491
|
+
activeBucket.stylingConventions.add("css-modules");
|
|
1492
|
+
activeBucket.cssClassesUsed.add(sub.argumentExpression.text);
|
|
1493
|
+
}
|
|
1494
|
+
ts.forEachChild(sub, walkClassExpr);
|
|
1495
|
+
};
|
|
1496
|
+
if (ts.isTemplateExpression(expr)) {
|
|
1497
|
+
for (const span of expr.templateSpans)
|
|
1498
|
+
walkClassExpr(span.expression);
|
|
1499
|
+
}
|
|
1500
|
+
else if (!ts.isStringLiteralLike(expr)) {
|
|
1501
|
+
walkClassExpr(expr);
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
else if (attrName === "style" &&
|
|
1506
|
+
node.initializer &&
|
|
1507
|
+
ts.isJsxExpression(node.initializer) &&
|
|
1508
|
+
node.initializer.expression &&
|
|
1509
|
+
ts.isObjectLiteralExpression(node.initializer.expression)) {
|
|
1510
|
+
activeBucket.stylingConventions.add("inline-style");
|
|
1511
|
+
for (const prop of node.initializer.expression.properties) {
|
|
1512
|
+
if (!ts.isPropertyAssignment(prop))
|
|
1513
|
+
continue;
|
|
1514
|
+
const propName = prop.name.getText(sf);
|
|
1515
|
+
if (!NON_TRIVIAL_INLINE_STYLE_PROPS.has(propName))
|
|
1516
|
+
continue;
|
|
1517
|
+
const init = prop.initializer;
|
|
1518
|
+
if (ts.isStringLiteralLike(init)) {
|
|
1519
|
+
consumedStringNodes.add(init);
|
|
1520
|
+
const val = init.text.trim();
|
|
1521
|
+
if (!val.includes("var(") &&
|
|
1522
|
+
!/^(0|0px|none|auto|inherit|transparent|100%|50%)$/i.test(val)) {
|
|
1523
|
+
const propLine = getLine(prop.getStart(sf));
|
|
1524
|
+
activeBucket.inlineStyleLiterals.push({
|
|
1525
|
+
property: propName,
|
|
1526
|
+
value: val,
|
|
1527
|
+
filePath,
|
|
1528
|
+
lineNumber: propLine,
|
|
1529
|
+
snippet: getLineSnippet(rawLines, propLine),
|
|
1530
|
+
});
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
else if (ts.isNumericLiteral(init)) {
|
|
1534
|
+
const numVal = Number(init.text);
|
|
1535
|
+
if (numVal !== 0) {
|
|
1536
|
+
const propLine = getLine(prop.getStart(sf));
|
|
1537
|
+
activeBucket.inlineStyleLiterals.push({
|
|
1538
|
+
property: propName,
|
|
1539
|
+
value: `${init.text}px`,
|
|
1540
|
+
filePath,
|
|
1541
|
+
lineNumber: propLine,
|
|
1542
|
+
snippet: getLineSnippet(rawLines, propLine),
|
|
1543
|
+
});
|
|
1544
|
+
}
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
}
|
|
1548
|
+
else if (hasCssInJs && attrName === "sx") {
|
|
1549
|
+
activeBucket.stylingConventions.add("css-in-js");
|
|
1550
|
+
}
|
|
1551
|
+
}
|
|
1552
|
+
if (ts.isJsxElement(node)) {
|
|
1553
|
+
const sk = computeJsxSkeletonNode(node);
|
|
1554
|
+
if (sk &&
|
|
1555
|
+
sk.elementCount >= 3 &&
|
|
1556
|
+
sk.elementCount <= 35 &&
|
|
1557
|
+
sk.depth >= 2 &&
|
|
1558
|
+
((/^[a-z]/.test(sk.rootTag) &&
|
|
1559
|
+
sk.rawDomCount >= 2 &&
|
|
1560
|
+
(sk.hasSemanticClassOrRole || sk.rawDomCount >= 4)) ||
|
|
1561
|
+
sk.customCount >= 3)) {
|
|
1562
|
+
const lineNumber = getLine(node.openingElement.getStart(sf));
|
|
1563
|
+
const skeletonHash = createHash("sha256")
|
|
1564
|
+
.update(sk.canonicalSig)
|
|
1565
|
+
.digest("hex")
|
|
1566
|
+
.slice(0, 12);
|
|
1567
|
+
activeBucket.jsxSkeletons.push({
|
|
1568
|
+
skeletonHash,
|
|
1569
|
+
skeletonShape: sk.shapeStr,
|
|
1570
|
+
canonicalSignature: sk.canonicalSig,
|
|
1571
|
+
rootTag: sk.rootTag,
|
|
1572
|
+
elementCount: sk.elementCount,
|
|
1573
|
+
customCount: sk.customCount,
|
|
1574
|
+
depth: sk.depth,
|
|
1575
|
+
filePath,
|
|
1576
|
+
lineNumber,
|
|
1577
|
+
snippet: getLineSnippet(rawLines, lineNumber),
|
|
1578
|
+
});
|
|
1579
|
+
}
|
|
1580
|
+
inspectUiShapeCandidate(node, activeBucket);
|
|
1581
|
+
// Evaluate openingElement against enclosing ancestors before pushing this container's own context
|
|
1582
|
+
visit(node.openingElement, activeBucket);
|
|
1583
|
+
const openEl = node.openingElement;
|
|
1584
|
+
const openTag = openEl.tagName.getText(sf);
|
|
1585
|
+
const openIsCustom = /^[A-Z]/.test(openTag) || openTag.includes(".");
|
|
1586
|
+
const openRole = getJsxAttributeString(openEl.attributes, "role");
|
|
1587
|
+
const openLine = getLine(openEl.getStart(sf));
|
|
1588
|
+
let pushedElInteractive = false;
|
|
1589
|
+
if (!openIsCustom &&
|
|
1590
|
+
(INTERACTIVE_DOM_TAGS.has(openTag) ||
|
|
1591
|
+
(openRole !== undefined && INTERACTIVE_ARIA_ROLES.has(openRole)))) {
|
|
1592
|
+
const outerLabel = openRole ? `${openTag}[role="${openRole}"]` : openTag;
|
|
1593
|
+
interactiveAncestorStack.push({ label: outerLabel, lineNumber: openLine });
|
|
1594
|
+
pushedElInteractive = true;
|
|
1595
|
+
}
|
|
1596
|
+
let pushedElBg = false;
|
|
1597
|
+
const openClassBranches = [];
|
|
1598
|
+
for (const attr of openEl.attributes.properties) {
|
|
1599
|
+
if (ts.isJsxAttribute(attr) &&
|
|
1600
|
+
ts.isIdentifier(attr.name) &&
|
|
1601
|
+
(attr.name.text === "className" || attr.name.text === "class") &&
|
|
1602
|
+
attr.initializer) {
|
|
1603
|
+
if (ts.isStringLiteral(attr.initializer)) {
|
|
1604
|
+
openClassBranches.push(attr.initializer.text.split(/\s+/).filter(Boolean));
|
|
1605
|
+
}
|
|
1606
|
+
else if (ts.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
1607
|
+
openClassBranches.push(...collectClassTokenBranchesWithEnv(attr.initializer.expression));
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
const branchForBg = openClassBranches.find((b) => b.some((t) => /(?:^|:)bg-/.test(t))) ??
|
|
1612
|
+
openClassBranches[0] ??
|
|
1613
|
+
[];
|
|
1614
|
+
if (branchForBg.length > 0) {
|
|
1615
|
+
const ownColorSlugs = extractColorUtilitySlugsFromTokens(branchForBg, knownThemeColorSlugs, nonColorThemeTextSlugs);
|
|
1616
|
+
const prevBg = bgAncestorStack.length > 0 ? bgAncestorStack[bgAncestorStack.length - 1] : undefined;
|
|
1617
|
+
const bgEntries = new Map();
|
|
1618
|
+
if (prevBg) {
|
|
1619
|
+
for (const [v, bgs] of prevBg.entries())
|
|
1620
|
+
bgEntries.set(v, [...bgs]);
|
|
1621
|
+
}
|
|
1622
|
+
let addedOwnBg = false;
|
|
1623
|
+
for (const [v, { bg }] of ownColorSlugs.entries()) {
|
|
1624
|
+
if (bg.length > 0) {
|
|
1625
|
+
bgEntries.set(v, [...bg]);
|
|
1626
|
+
addedOwnBg = true;
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
if (addedOwnBg) {
|
|
1630
|
+
bgAncestorStack.push(bgEntries);
|
|
1631
|
+
pushedElBg = true;
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
try {
|
|
1635
|
+
for (const ch of node.children)
|
|
1636
|
+
visit(ch, activeBucket);
|
|
1637
|
+
visit(node.closingElement, activeBucket);
|
|
1638
|
+
}
|
|
1639
|
+
finally {
|
|
1640
|
+
if (pushedElInteractive)
|
|
1641
|
+
interactiveAncestorStack.pop();
|
|
1642
|
+
if (pushedElBg)
|
|
1643
|
+
bgAncestorStack.pop();
|
|
1644
|
+
}
|
|
1645
|
+
return;
|
|
1646
|
+
}
|
|
1647
|
+
if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
|
|
1648
|
+
const tagName = node.tagName.getText(sf);
|
|
1649
|
+
const lineNumber = getLine(node.getStart(sf));
|
|
1650
|
+
const snippet = getLineSnippet(rawLines, lineNumber);
|
|
1651
|
+
const isCustom = /^[A-Z]/.test(tagName) || tagName.includes(".");
|
|
1652
|
+
const roleAttr = getJsxAttributeString(node.attributes, "role");
|
|
1653
|
+
const classAttr = getJsxAttributeString(node.attributes, "className") ??
|
|
1654
|
+
getJsxAttributeString(node.attributes, "class") ?? "";
|
|
1655
|
+
const inlineStyle = extractInlineStyleRecord(node.attributes);
|
|
1656
|
+
// Nearest ancestor background lookup for cross-element contrast pairing
|
|
1657
|
+
const inheritedBgByVariant = bgAncestorStack.length > 0 ? bgAncestorStack[bgAncestorStack.length - 1] : undefined;
|
|
1658
|
+
const elementClassBranches = [];
|
|
1659
|
+
for (const attr of node.attributes.properties) {
|
|
1660
|
+
if (ts.isJsxAttribute(attr) &&
|
|
1661
|
+
ts.isIdentifier(attr.name) &&
|
|
1662
|
+
(attr.name.text === "className" || attr.name.text === "class") &&
|
|
1663
|
+
attr.initializer) {
|
|
1664
|
+
if (ts.isStringLiteral(attr.initializer)) {
|
|
1665
|
+
elementClassBranches.push(attr.initializer.text.split(/\s+/).filter(Boolean));
|
|
1666
|
+
}
|
|
1667
|
+
else if (ts.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
1668
|
+
elementClassBranches.push(...collectClassTokenBranchesWithEnv(attr.initializer.expression));
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
if (elementClassBranches.length > 0) {
|
|
1673
|
+
recordTailwindClassBranches(elementClassBranches, lineNumber, inheritedBgByVariant);
|
|
1674
|
+
}
|
|
1675
|
+
const isInteractiveElement = !isCustom &&
|
|
1676
|
+
(INTERACTIVE_DOM_TAGS.has(tagName) ||
|
|
1677
|
+
(roleAttr !== undefined && INTERACTIVE_ARIA_ROLES.has(roleAttr)));
|
|
1678
|
+
if (isInteractiveElement && interactiveAncestorStack.length > 0) {
|
|
1679
|
+
const outer = interactiveAncestorStack[interactiveAncestorStack.length - 1];
|
|
1680
|
+
const innerLabel = roleAttr ? `${tagName}[role="${roleAttr}"]` : tagName;
|
|
1681
|
+
activeBucket.nestedInteractive.push({
|
|
1682
|
+
componentName: activeBucket.name,
|
|
1683
|
+
outerTag: outer.label,
|
|
1684
|
+
innerTag: innerLabel,
|
|
1685
|
+
filePath,
|
|
1686
|
+
lineNumber,
|
|
1687
|
+
snippet,
|
|
1688
|
+
});
|
|
1689
|
+
}
|
|
1690
|
+
const isFirstElement = !activeBucket.rootElement && activeBucket.name !== "__module__";
|
|
1691
|
+
if (!isCustom || isFirstElement) {
|
|
1692
|
+
const classList = classAttr.split(/\s+/).filter(Boolean);
|
|
1693
|
+
if (isFirstElement || classList.length > 0 || Object.keys(inlineStyle).length > 0) {
|
|
1694
|
+
activeBucket.elementStyleSnapshots.push({
|
|
1695
|
+
tag: tagName,
|
|
1696
|
+
...(roleAttr ? { role: roleAttr } : {}),
|
|
1697
|
+
isRootElement: isFirstElement,
|
|
1698
|
+
classes: classList,
|
|
1699
|
+
inlineStyle,
|
|
1700
|
+
lineNumber,
|
|
1701
|
+
snippet,
|
|
1702
|
+
});
|
|
1703
|
+
}
|
|
1704
|
+
}
|
|
1705
|
+
if (isFirstElement) {
|
|
1706
|
+
const rootStyleProps = {};
|
|
1707
|
+
for (const [k, v] of Object.entries(inlineStyle)) {
|
|
1708
|
+
if (/^(?:margin|marginTop|marginRight|marginBottom|marginLeft|width|minWidth)$/.test(k)) {
|
|
1709
|
+
rootStyleProps[k] = v;
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
activeBucket.rootElement = {
|
|
1713
|
+
tag: tagName,
|
|
1714
|
+
classes: classAttr,
|
|
1715
|
+
styleProps: rootStyleProps,
|
|
1716
|
+
lineNumber,
|
|
1717
|
+
snippet,
|
|
1718
|
+
};
|
|
1719
|
+
}
|
|
1720
|
+
if (isCustom) {
|
|
1721
|
+
activeBucket.jsxCustomComponentCount++;
|
|
1722
|
+
activeBucket.renderedComponents.add(tagName);
|
|
1723
|
+
const passedProps = [];
|
|
1724
|
+
const inlineStyleProps = [];
|
|
1725
|
+
const arbitraryTailwindOverrides = [];
|
|
1726
|
+
const literalProps = [];
|
|
1727
|
+
let classNameOverride;
|
|
1728
|
+
for (const prop of node.attributes.properties) {
|
|
1729
|
+
if (ts.isJsxAttribute(prop) && ts.isIdentifier(prop.name)) {
|
|
1730
|
+
const pName = prop.name.text;
|
|
1731
|
+
passedProps.push(pName);
|
|
1732
|
+
if (colorPropRe.test(pName) && prop.initializer) {
|
|
1733
|
+
const lit = ts.isStringLiteral(prop.initializer)
|
|
1734
|
+
? prop.initializer
|
|
1735
|
+
: ts.isJsxExpression(prop.initializer) &&
|
|
1736
|
+
prop.initializer.expression &&
|
|
1737
|
+
ts.isStringLiteralLike(prop.initializer.expression)
|
|
1738
|
+
? prop.initializer.expression
|
|
1739
|
+
: undefined;
|
|
1740
|
+
if (lit && looksLikeColorLiteral(lit.text)) {
|
|
1741
|
+
literalProps.push({ prop: pName, value: lit.text.trim(), kind: "color" });
|
|
1742
|
+
activeBucket.invariantViolations.push({
|
|
1743
|
+
parentComponent: activeBucket.name,
|
|
1744
|
+
childComponent: tagName,
|
|
1745
|
+
prop: pName,
|
|
1746
|
+
value: lit.text.trim(),
|
|
1747
|
+
filePath,
|
|
1748
|
+
lineNumber,
|
|
1749
|
+
snippet,
|
|
1750
|
+
});
|
|
1751
|
+
}
|
|
1752
|
+
}
|
|
1753
|
+
if (pName === "style" &&
|
|
1754
|
+
prop.initializer &&
|
|
1755
|
+
ts.isJsxExpression(prop.initializer) &&
|
|
1756
|
+
prop.initializer.expression &&
|
|
1757
|
+
ts.isObjectLiteralExpression(prop.initializer.expression)) {
|
|
1758
|
+
for (const sp of prop.initializer.expression.properties) {
|
|
1759
|
+
if (ts.isPropertyAssignment(sp)) {
|
|
1760
|
+
const spName = sp.name.getText(sf);
|
|
1761
|
+
if (NON_TRIVIAL_INLINE_STYLE_PROPS.has(spName)) {
|
|
1762
|
+
inlineStyleProps.push(spName);
|
|
1763
|
+
}
|
|
1764
|
+
}
|
|
1765
|
+
}
|
|
1766
|
+
}
|
|
1767
|
+
else if (pName === "className") {
|
|
1768
|
+
const clsStr = getJsxAttributeString(node.attributes, "className");
|
|
1769
|
+
if (clsStr) {
|
|
1770
|
+
classNameOverride = clsStr;
|
|
1771
|
+
for (const m of clsStr.matchAll(ARBITRARY_TW_RE)) {
|
|
1772
|
+
if (m[1])
|
|
1773
|
+
arbitraryTailwindOverrides.push(m[1]);
|
|
1774
|
+
}
|
|
1775
|
+
}
|
|
1776
|
+
}
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
activeBucket.jsxCallSites.push({
|
|
1780
|
+
targetComponent: tagName,
|
|
1781
|
+
filePath,
|
|
1782
|
+
lineNumber,
|
|
1783
|
+
snippet,
|
|
1784
|
+
passedProps,
|
|
1785
|
+
hasInlineStyleOverride: inlineStyleProps.length > 0,
|
|
1786
|
+
inlineStyleProps,
|
|
1787
|
+
arbitraryTailwindOverrides,
|
|
1788
|
+
literalProps,
|
|
1789
|
+
...(classNameOverride ? { classNameOverride } : {}),
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
else {
|
|
1793
|
+
if (!SVG_PRIMITIVE_TAGS.has(tagName)) {
|
|
1794
|
+
activeBucket.jsxDomElementCount++;
|
|
1795
|
+
activeBucket.domTags.add(tagName);
|
|
1796
|
+
}
|
|
1797
|
+
const getAttr = (n) => getJsxAttributeString(node.attributes, n);
|
|
1798
|
+
let bestAtomDef;
|
|
1799
|
+
let bestAtomScore = 0;
|
|
1800
|
+
for (const def of atomDefinitions) {
|
|
1801
|
+
for (const m of def.matchers) {
|
|
1802
|
+
if (!atomMatcherHits(m, tagName, roleAttr, classAttr, getAttr))
|
|
1803
|
+
continue;
|
|
1804
|
+
const specificity = scoreAtomMatcher(m);
|
|
1805
|
+
if (specificity > bestAtomScore) {
|
|
1806
|
+
bestAtomScore = specificity;
|
|
1807
|
+
bestAtomDef = def;
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
if (bestAtomDef) {
|
|
1812
|
+
const firstClass = classAttr.split(/\s+/).find(Boolean);
|
|
1813
|
+
activeBucket.rawDomPrimitives.push({
|
|
1814
|
+
tagOrRole: `<${tagName}${roleAttr ? ` role="${roleAttr}"` : ""}${firstClass ? ` className="${firstClass}"` : ""}>`,
|
|
1815
|
+
atomicTarget: bestAtomDef.name,
|
|
1816
|
+
filePath,
|
|
1817
|
+
lineNumber,
|
|
1818
|
+
snippet,
|
|
1819
|
+
});
|
|
1820
|
+
activeBucket.rawDomOffsets.push(node.getStart(sf));
|
|
1821
|
+
}
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
if (hasPixiImport && ts.isNewExpression(node)) {
|
|
1825
|
+
const ctorText = node.expression.getText(sf);
|
|
1826
|
+
if (/^(?:PIXI\.)?(Application|Container|Graphics|Sprite|Text|BitmapText|Rectangle)$/.test(ctorText)) {
|
|
1827
|
+
activeBucket.stylingConventions.add("pixi-canvas");
|
|
1828
|
+
}
|
|
1829
|
+
}
|
|
1830
|
+
if (ts.isCallExpression(node)) {
|
|
1831
|
+
const calleeText = node.expression.getText(sf);
|
|
1832
|
+
const lineNumber = getLine(node.getStart(sf));
|
|
1833
|
+
const snippet = getLineSnippet(rawLines, lineNumber);
|
|
1834
|
+
const calleeLast = calleeText.split(".").pop() ?? calleeText;
|
|
1835
|
+
if (hasCssInJs && /^(?:styled|css|keyframes|createGlobalStyle)$/.test(calleeLast)) {
|
|
1836
|
+
activeBucket.stylingConventions.add("css-in-js");
|
|
1837
|
+
}
|
|
1838
|
+
if (CLASS_HELPER_CALLEES.has(calleeLast)) {
|
|
1839
|
+
const walkHelperArg = (sub) => {
|
|
1840
|
+
if (ts.isPropertyAssignment(sub) && sub.name.getText(sf) === "defaultVariants")
|
|
1841
|
+
return;
|
|
1842
|
+
if (ts.isStringLiteral(sub) || ts.isNoSubstitutionTemplateLiteral(sub)) {
|
|
1843
|
+
const subLine = getLine(sub.getStart(sf));
|
|
1844
|
+
recordTailwindClassBranches([sub.text.split(/\s+/).filter(Boolean)], subLine);
|
|
1845
|
+
if (!consumedStringNodes.has(sub)) {
|
|
1846
|
+
consumedStringNodes.add(sub);
|
|
1847
|
+
inspectClassTokens(sub.text, subLine, getLineSnippet(rawLines, subLine), activeBucket);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
else if (ts.isPropertyAccessExpression(sub) &&
|
|
1851
|
+
ts.isIdentifier(sub.expression) &&
|
|
1852
|
+
cssModuleBindings.has(sub.expression.text)) {
|
|
1853
|
+
activeBucket.stylingConventions.add("css-modules");
|
|
1854
|
+
activeBucket.cssClassesUsed.add(sub.name.text);
|
|
1855
|
+
}
|
|
1856
|
+
ts.forEachChild(sub, walkHelperArg);
|
|
1857
|
+
};
|
|
1858
|
+
for (const arg of node.arguments)
|
|
1859
|
+
walkHelperArg(arg);
|
|
1860
|
+
if (calleeLast === "cva" || calleeLast === "tv") {
|
|
1861
|
+
for (const arg of node.arguments) {
|
|
1862
|
+
if (!ts.isObjectLiteralExpression(arg))
|
|
1863
|
+
continue;
|
|
1864
|
+
for (const prop of arg.properties) {
|
|
1865
|
+
if (!ts.isPropertyAssignment(prop) ||
|
|
1866
|
+
prop.name.getText(sf) !== "variants" ||
|
|
1867
|
+
!ts.isObjectLiteralExpression(prop.initializer)) {
|
|
1868
|
+
continue;
|
|
1869
|
+
}
|
|
1870
|
+
for (const axis of prop.initializer.properties) {
|
|
1871
|
+
if (!ts.isPropertyAssignment(axis) || !ts.isObjectLiteralExpression(axis.initializer)) {
|
|
1872
|
+
continue;
|
|
1873
|
+
}
|
|
1874
|
+
const axisName = axis.name.getText(sf).replace(/^["']|["']$/g, "");
|
|
1875
|
+
const values = axis.initializer.properties
|
|
1876
|
+
.filter(ts.isPropertyAssignment)
|
|
1877
|
+
.map((v) => v.name.getText(sf).replace(/^["']|["']$/g, ""));
|
|
1878
|
+
const existing = new Set(variantAxes[axisName] ?? []);
|
|
1879
|
+
for (const v of values)
|
|
1880
|
+
existing.add(v);
|
|
1881
|
+
variantAxes[axisName] = [...existing].sort();
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
if (hasPixiImport &&
|
|
1888
|
+
(/^draw[A-Z][a-zA-Z0-9]*$/.test(calleeText) ||
|
|
1889
|
+
/\.(circle|rect|roundRect|fill|stroke|moveTo|lineTo|addChild|canvas)$/.test(calleeText))) {
|
|
1890
|
+
activeBucket.stylingConventions.add("pixi-canvas");
|
|
1891
|
+
}
|
|
1892
|
+
if (STATE_HOOK_NAMES.has(calleeText)) {
|
|
1893
|
+
activeBucket.stateHookCount++;
|
|
1894
|
+
}
|
|
1895
|
+
if (slotRecorderFactories.includes(calleeText)) {
|
|
1896
|
+
activeBucket.usesSlotRecorder = true;
|
|
1897
|
+
activeBucket.stylingConventions.add("pixi-canvas");
|
|
1898
|
+
}
|
|
1899
|
+
else if ((canvasTokenReaderHelpers.includes(calleeText) || calleeText.endsWith(".getPropertyValue")) &&
|
|
1900
|
+
node.arguments.length >= 1 &&
|
|
1901
|
+
ts.isStringLiteralLike(node.arguments[0]) &&
|
|
1902
|
+
node.arguments[0].text.trim().startsWith("--")) {
|
|
1903
|
+
const tokenName = node.arguments[0].text.trim();
|
|
1904
|
+
tokenReferences.push({
|
|
1905
|
+
name: tokenName,
|
|
1906
|
+
filePath,
|
|
1907
|
+
lineNumber,
|
|
1908
|
+
snippet,
|
|
1909
|
+
kind: "canvas-bridge",
|
|
1910
|
+
});
|
|
1911
|
+
activeBucket.tokensConsumed.add(tokenName);
|
|
1912
|
+
}
|
|
1913
|
+
else if (slotRecorderFactories.length > 0 &&
|
|
1914
|
+
calleeText === "t" &&
|
|
1915
|
+
node.arguments.length >= 3) {
|
|
1916
|
+
activeBucket.usesSlotRecorder = true;
|
|
1917
|
+
activeBucket.stylingConventions.add("pixi-canvas");
|
|
1918
|
+
const slotArg = node.arguments[0];
|
|
1919
|
+
const propArg = node.arguments[1];
|
|
1920
|
+
const valArg = node.arguments[2];
|
|
1921
|
+
const slotName = ts.isStringLiteralLike(slotArg) ? slotArg.text : slotArg.getText(sf);
|
|
1922
|
+
const propName = ts.isStringLiteralLike(propArg) ? propArg.text : propArg.getText(sf);
|
|
1923
|
+
if (ts.isCallExpression(valArg)) {
|
|
1924
|
+
const valCallee = valArg.expression.getText(sf);
|
|
1925
|
+
if (valCallee === "lit" || valCallee.endsWith(".lit")) {
|
|
1926
|
+
const rawVal = valArg.arguments[0]?.getText(sf) ?? "?";
|
|
1927
|
+
emitSlotRecording(activeBucket, slotName, propName, "lit", rawVal, getLine(valArg.getStart(sf)), getLineSnippet(rawLines, getLine(valArg.getStart(sf))));
|
|
1928
|
+
}
|
|
1929
|
+
else if (valCallee === "tsConst" || valCallee.endsWith(".tsConst")) {
|
|
1930
|
+
emitSlotRecording(activeBucket, slotName, propName, "tsConst", "", lineNumber, snippet);
|
|
1931
|
+
}
|
|
1932
|
+
else if (valCallee === "css" ||
|
|
1933
|
+
valCallee.endsWith(".css") ||
|
|
1934
|
+
canvasCssValueHelpers.includes(valCallee) ||
|
|
1935
|
+
canvasTokenReaderHelpers.includes(valCallee)) {
|
|
1936
|
+
emitSlotRecording(activeBucket, slotName, propName, "css", "", lineNumber, snippet);
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
else if (ts.isIdentifier(valArg)) {
|
|
1940
|
+
// Local variable bound to `lit(...)` / `css(...)` / `tsConst(...)`
|
|
1941
|
+
const origins = lookupSlotBinding(valArg.text);
|
|
1942
|
+
if (origins) {
|
|
1943
|
+
for (const o of origins) {
|
|
1944
|
+
o.used = true;
|
|
1945
|
+
emitSlotRecording(activeBucket, slotName, propName, o.kind, o.rawVal, o.lineNumber, o.snippet);
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
else if (!capturedSlotRecorderVarInit &&
|
|
1951
|
+
!(ts.isVariableDeclaration(node.parent) &&
|
|
1952
|
+
ts.isIdentifier(node.parent.name)) &&
|
|
1953
|
+
!(ts.isBinaryExpression(node.parent) &&
|
|
1954
|
+
node.parent.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
|
|
1955
|
+
ts.isIdentifier(node.parent.left)) &&
|
|
1956
|
+
slotRecorderFactories.length > 0 &&
|
|
1957
|
+
/^(?:[a-zA-Z_$][a-zA-Z0-9_$]*\.)?(css|tsConst|lit)$/.test(calleeText) &&
|
|
1958
|
+
!(ts.isCallExpression(node.parent) && node.parent.expression.getText(sf) === "t")) {
|
|
1959
|
+
const method = calleeText.split(".").pop();
|
|
1960
|
+
const hasDotReceiver = calleeText.includes(".");
|
|
1961
|
+
if (hasDotReceiver || activeBucket.usesSlotRecorder) {
|
|
1962
|
+
activeBucket.usesSlotRecorder = true;
|
|
1963
|
+
activeBucket.stylingConventions.add("pixi-canvas");
|
|
1964
|
+
if (method === "css") {
|
|
1965
|
+
activeBucket.canvasCssCount++;
|
|
1966
|
+
}
|
|
1967
|
+
else if (method === "tsConst") {
|
|
1968
|
+
activeBucket.canvasTsConstCount++;
|
|
1969
|
+
}
|
|
1970
|
+
else {
|
|
1971
|
+
const slotOrValArg = node.arguments[0];
|
|
1972
|
+
const valArg = node.arguments.length >= 2 ? node.arguments[1] : node.arguments[0];
|
|
1973
|
+
const rawVal = valArg?.getText(sf) ?? "?";
|
|
1974
|
+
const slotName = node.arguments.length >= 2 && slotOrValArg && ts.isStringLiteralLike(slotOrValArg)
|
|
1975
|
+
? slotOrValArg.text
|
|
1976
|
+
: "canvas";
|
|
1977
|
+
emitSlotRecording(activeBucket, slotName, "value", "lit", rawVal, lineNumber, snippet);
|
|
1978
|
+
}
|
|
1979
|
+
}
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
try {
|
|
1983
|
+
ts.forEachChild(node, (child) => visit(child, activeBucket));
|
|
1984
|
+
}
|
|
1985
|
+
finally {
|
|
1986
|
+
if (pushedFnScope) {
|
|
1987
|
+
classEnvStack.pop();
|
|
1988
|
+
const poppedSlots = slotBindingStack.pop();
|
|
1989
|
+
if (poppedSlots && activeBucket.usesSlotRecorder) {
|
|
1990
|
+
for (const origins of poppedSlots.values()) {
|
|
1991
|
+
for (const o of origins) {
|
|
1992
|
+
if (!o.used) {
|
|
1993
|
+
emitSlotRecording(activeBucket, "canvas", "value", o.kind, o.rawVal, o.lineNumber, o.snippet);
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
}
|
|
1998
|
+
}
|
|
1999
|
+
}
|
|
2000
|
+
};
|
|
2001
|
+
visit(sf, moduleBucket);
|
|
2002
|
+
return {
|
|
2003
|
+
filePath,
|
|
2004
|
+
definedFontVars,
|
|
2005
|
+
tokenReferences,
|
|
2006
|
+
cssImports,
|
|
2007
|
+
tailwindClassPairs,
|
|
2008
|
+
importedModules,
|
|
2009
|
+
importedBindings,
|
|
2010
|
+
reExports,
|
|
2011
|
+
variantAxes,
|
|
2012
|
+
functionsAndClasses,
|
|
2013
|
+
};
|
|
2014
|
+
}
|