@llui/vite-plugin 0.0.20 → 0.0.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/collect-deps.d.ts +21 -0
- package/dist/collect-deps.d.ts.map +1 -1
- package/dist/collect-deps.js +59 -13
- package/dist/collect-deps.js.map +1 -1
- package/dist/diagnostics.d.ts +7 -0
- package/dist/diagnostics.d.ts.map +1 -1
- package/dist/diagnostics.js +302 -60
- package/dist/diagnostics.js.map +1 -1
- package/dist/index.d.ts +40 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +136 -9
- package/dist/index.js.map +1 -1
- package/dist/transform.d.ts +1 -1
- package/dist/transform.d.ts.map +1 -1
- package/dist/transform.js +20 -9
- package/dist/transform.js.map +1 -1
- package/package.json +1 -1
package/dist/collect-deps.d.ts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
/**
|
|
3
|
+
* Walk the AST and collect every unique state access path referenced by
|
|
4
|
+
* a reactive accessor. A reactive accessor is an arrow/function whose
|
|
5
|
+
* placement passes `isReactiveAccessor` — text()/memo() first args,
|
|
6
|
+
* element-helper prop values, and allowlisted framework-API prop values.
|
|
7
|
+
* Paths are rooted at the accessor's single parameter name.
|
|
8
|
+
*
|
|
9
|
+
* Shared by the bit-assignment path (`collectDeps`, below) and the
|
|
10
|
+
* `diagnostics.ts` bitmask-overflow warning. Extracted so both consumers
|
|
11
|
+
* see the same truth — previously the diagnostics side had its own naïve
|
|
12
|
+
* walker that produced false positives for `each({ key })`, `item(...)`,
|
|
13
|
+
* array-method callbacks, and user-land helpers.
|
|
14
|
+
*/
|
|
15
|
+
export declare function collectStatePathsFromSource(sourceFile: ts.SourceFile): Set<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Per-accessor path sets — one entry per reactive arrow/function. Used
|
|
18
|
+
* by the bitmask-overflow diagnostic to find clusters of paths that
|
|
19
|
+
* always fire together (co-occurrence analysis).
|
|
20
|
+
*/
|
|
21
|
+
export declare function collectAccessorPathSets(sourceFile: ts.SourceFile): Set<string>[];
|
|
1
22
|
/**
|
|
2
23
|
* Pre-scan a source file to collect all unique state access paths
|
|
3
24
|
* referenced by reactive accessors (arrow functions in props and text() calls).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collect-deps.d.ts","sourceRoot":"","sources":["../src/collect-deps.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"collect-deps.d.ts","sourceRoot":"","sources":["../src/collect-deps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B;;;;;;;;;;;;GAYG;AACH,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,CAyBlF;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,CAoBhF;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CA4B/D"}
|
package/dist/collect-deps.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import ts from 'typescript';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Walk the AST and collect every unique state access path referenced by
|
|
4
|
+
* a reactive accessor. A reactive accessor is an arrow/function whose
|
|
5
|
+
* placement passes `isReactiveAccessor` — text()/memo() first args,
|
|
6
|
+
* element-helper prop values, and allowlisted framework-API prop values.
|
|
7
|
+
* Paths are rooted at the accessor's single parameter name.
|
|
8
|
+
*
|
|
9
|
+
* Shared by the bit-assignment path (`collectDeps`, below) and the
|
|
10
|
+
* `diagnostics.ts` bitmask-overflow warning. Extracted so both consumers
|
|
11
|
+
* see the same truth — previously the diagnostics side had its own naïve
|
|
12
|
+
* walker that produced false positives for `each({ key })`, `item(...)`,
|
|
13
|
+
* array-method callbacks, and user-land helpers.
|
|
6
14
|
*/
|
|
7
|
-
export function
|
|
8
|
-
const sourceFile = ts.createSourceFile('input.ts', source, ts.ScriptTarget.Latest, true);
|
|
9
|
-
// Check if file imports from @llui/dom
|
|
10
|
-
if (!hasLluiImport(sourceFile)) {
|
|
11
|
-
return new Map();
|
|
12
|
-
}
|
|
15
|
+
export function collectStatePathsFromSource(sourceFile) {
|
|
13
16
|
const paths = new Set();
|
|
14
|
-
// Walk the AST to find reactive accessors
|
|
15
17
|
function visit(node) {
|
|
16
18
|
// Look for arrow functions that are reactive accessors:
|
|
17
19
|
// - First arg to text(): text(s => s.count)
|
|
@@ -31,6 +33,45 @@ export function collectDeps(source) {
|
|
|
31
33
|
ts.forEachChild(node, visit);
|
|
32
34
|
}
|
|
33
35
|
visit(sourceFile);
|
|
36
|
+
return paths;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Per-accessor path sets — one entry per reactive arrow/function. Used
|
|
40
|
+
* by the bitmask-overflow diagnostic to find clusters of paths that
|
|
41
|
+
* always fire together (co-occurrence analysis).
|
|
42
|
+
*/
|
|
43
|
+
export function collectAccessorPathSets(sourceFile) {
|
|
44
|
+
const sets = [];
|
|
45
|
+
function visit(node) {
|
|
46
|
+
if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
|
|
47
|
+
const params = node.parameters;
|
|
48
|
+
if (params.length === 1) {
|
|
49
|
+
const paramName = params[0].name;
|
|
50
|
+
if (ts.isIdentifier(paramName) && isReactiveAccessor(node)) {
|
|
51
|
+
const set = new Set();
|
|
52
|
+
extractPaths(node.body, paramName.text, '', set);
|
|
53
|
+
if (set.size > 0)
|
|
54
|
+
sets.push(set);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
ts.forEachChild(node, visit);
|
|
59
|
+
}
|
|
60
|
+
visit(sourceFile);
|
|
61
|
+
return sets;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Pre-scan a source file to collect all unique state access paths
|
|
65
|
+
* referenced by reactive accessors (arrow functions in props and text() calls).
|
|
66
|
+
* Returns a Map<path, bitPosition> where each path gets a unique power-of-two bit.
|
|
67
|
+
*/
|
|
68
|
+
export function collectDeps(source) {
|
|
69
|
+
const sourceFile = ts.createSourceFile('input.ts', source, ts.ScriptTarget.Latest, true);
|
|
70
|
+
// Check if file imports from @llui/dom
|
|
71
|
+
if (!hasLluiImport(sourceFile)) {
|
|
72
|
+
return new Map();
|
|
73
|
+
}
|
|
74
|
+
const paths = collectStatePathsFromSource(sourceFile);
|
|
34
75
|
// Assign bit positions. The bitmask holds 31 unique paths (positions
|
|
35
76
|
// 0..30). When the count exceeds 31, overflow paths use FULL_MASK (-1)
|
|
36
77
|
// — they always trigger re-evaluation, degrading gracefully. The
|
|
@@ -68,9 +109,13 @@ function isReactiveAccessor(node) {
|
|
|
68
109
|
const parent = node.parent;
|
|
69
110
|
// text(s => s.count) — first arg to a call
|
|
70
111
|
if (ts.isCallExpression(parent) && parent.arguments[0] === node) {
|
|
71
|
-
// Skip item(t => t.id) — per-item selectors inside each() render
|
|
72
|
-
|
|
73
|
-
|
|
112
|
+
// Skip item(t => t.id) — per-item selectors inside each() render.
|
|
113
|
+
// Skip sample(s => s.x) — imperative one-shot read, no binding created
|
|
114
|
+
// (both the top-level import and the destructured-from-h form).
|
|
115
|
+
if (ts.isIdentifier(parent.expression)) {
|
|
116
|
+
if (parent.expression.text === 'item' || parent.expression.text === 'sample') {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
74
119
|
}
|
|
75
120
|
// Skip array method callbacks: .filter(t => ...), .map(t => ...), .some(t => ...), etc.
|
|
76
121
|
// Allow view-helper primitive calls: h.text(s => ...), h.memo(s => ...)
|
|
@@ -186,6 +231,7 @@ const REACTIVE_API_NAMES = new Set([
|
|
|
186
231
|
// Structural primitives
|
|
187
232
|
'each',
|
|
188
233
|
'branch',
|
|
234
|
+
'scope',
|
|
189
235
|
'show',
|
|
190
236
|
'memo',
|
|
191
237
|
'portal',
|
package/dist/collect-deps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"collect-deps.js","sourceRoot":"","sources":["../src/collect-deps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B;;;;GAIG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,MAAM,UAAU,GAAG,EAAE,CAAC,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;IAExF,uCAAuC;IACvC,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,CAAC;QAC/B,OAAO,IAAI,GAAG,EAAE,CAAA;IAClB,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IAE/B,0CAA0C;IAC1C,SAAS,KAAK,CAAC,IAAa;QAC1B,wDAAwD;QACxD,4CAA4C;QAC5C,sEAAsE;QACtE,IAAI,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAA;YAC9B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACxB,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAE,CAAC,IAAI,CAAA;gBACjC,IAAI,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;oBAC/B,sEAAsE;oBACtE,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;wBAC7B,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,CAAA;oBACpD,CAAC;gBACH,CAAC;YACH,CAAC;QACH,C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CAAC,CAAA;AAClF,CAAC;AAED;;;;GAIG;AACH,SAAS,oBAAoB,CAAC,IAAiC,EAAE,SAAiB;IAChF,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,IAAI,OAAO,GAAkB,IAAI,CAAA;IAEjC,OAAO,EAAE,CAAC,0BAA0B,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9C,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAChC,OAAO,GAAG,OAAO,CAAC,UAAU,CAAA;IAC9B,CAAC;IAED,uCAAuC;IACvC,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5D,OAAO,IAAI,CAAA;IACb,CAAC;IAED,mBAAmB;IACnB,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;IACpC,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACxB,CAAC;AAED;;GAEG;AACH,SAAS,oBAAoB,CAAC,IAAgC,EAAE,SAAiB;IAC/E,IAAI,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC5E,OAAO,IAAI,CAAA;IACb,CAAC;IAED,IAAI,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAChD,OAAO,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAA;IACrC,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import ts from 'typescript'\n\n/**\n * Pre-scan a source file to collect all unique state access paths\n * referenced by reactive accessors (arrow functions in props and text() calls).\n * Returns a Map<path, bitPosition> where each path gets a unique power-of-two bit.\n */\nexport function collectDeps(source: string): Map<string, number> {\n const sourceFile = ts.createSourceFile('input.ts', source, ts.ScriptTarget.Latest, true)\n\n // Check if file imports from @llui/dom\n if (!hasLluiImport(sourceFile)) {\n return new Map()\n }\n\n const paths = new Set<string>()\n\n // Walk the AST to find reactive accessors\n function visit(node: ts.Node): void {\n // Look for arrow functions that are reactive accessors:\n // - First arg to text(): text(s => s.count)\n // - Prop values in element helper calls: div({ title: s => s.title })\n if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {\n const params = node.parameters\n if (params.length === 1) {\n const paramName = params[0]!.name\n if (ts.isIdentifier(paramName)) {\n // Check if this looks like a reactive accessor (not an event handler)\n if (isReactiveAccessor(node)) {\n extractPaths(node.body, paramName.text, '', paths)\n }\n }\n }\n }\n\n ts.forEachChild(node, visit)\n }\n\n visit(sourceFile)\n\n // Assign bit positions. The bitmask holds 31 unique paths (positions\n // 0..30). When the count exceeds 31, overflow paths use FULL_MASK (-1)\n // — they always trigger re-evaluation, degrading gracefully. The\n // diagnostic warns the user to decompose.\n const fieldBits = new Map<string, number>()\n let bit = 1\n let index = 0\n for (const path of paths) {\n if (index >= 31) {\n fieldBits.set(path, -1)\n } else {\n fieldBits.set(path, bit)\n bit <<= 1\n }\n index++\n }\n\n return fieldBits\n}\n\nfunction hasLluiImport(sourceFile: ts.SourceFile): boolean {\n for (const stmt of sourceFile.statements) {\n if (\n ts.isImportDeclaration(stmt) &&\n ts.isStringLiteral(stmt.moduleSpecifier) &&\n stmt.moduleSpecifier.text === '@llui/dom'\n ) {\n return true\n }\n }\n return false\n}\n\n/**\n * Determines if an arrow/function expression is a reactive accessor\n * (not an event handler, not a callback like onClick).\n */\nfunction isReactiveAccessor(node: ts.ArrowFunction | ts.FunctionExpression): boolean {\n const parent = node.parent\n\n // text(s => s.count) — first arg to a call\n if (ts.isCallExpression(parent) && parent.arguments[0] === node) {\n // Skip item(t => t.id) — per-item selectors inside each() render\n if (ts.isIdentifier(parent.expression) && parent.expression.text === 'item') {\n return false\n }\n // Skip array method callbacks: .filter(t => ...), .map(t => ...), .some(t => ...), etc.\n // Allow view-helper primitive calls: h.text(s => ...), h.memo(s => ...)\n if (ts.isPropertyAccessExpression(parent.expression)) {\n const methodName = parent.expression.name.text\n if (methodName === 'text' || methodName === 'memo') {\n return true\n }\n return false\n }\n return true\n }\n\n // div({ title: s => s.title }) — value in a property assignment inside an object literal.\n // Only treat as reactive if the containing call is a known framework API whose\n // properties are reactive accessors. Otherwise user-land helpers like\n // sliceHandler({ narrow: (m) => m.type === ... }) would pollute the path set.\n if (ts.isPropertyAssignment(parent)) {\n const key = parent.name\n if (ts.isIdentifier(key)) {\n // Skip event handlers (onClick, onInput, etc.)\n if (/^on[A-Z]/.test(key.text)) return false\n // Skip each() key function and other non-reactive props\n if (key.text === 'key' || key.text === 'name') return false\n // Walk up to find the enclosing call expression\n let ancestor: ts.Node | undefined = parent.parent // ObjectLiteralExpression\n while (ancestor && !ts.isCallExpression(ancestor)) {\n ancestor = ancestor.parent\n }\n if (!ancestor) return false\n const callExpr = ancestor as ts.CallExpression\n if (!ts.isIdentifier(callExpr.expression)) return false\n return REACTIVE_API_NAMES.has(callExpr.expression.text)\n }\n }\n\n return false\n}\n\n// Framework APIs whose object-literal arguments contain reactive accessors.\n// Arrow functions in property values of these calls are state-tracked.\nconst REACTIVE_API_NAMES = new Set([\n // Element helpers (see ELEMENT_HELPERS in transform.ts — we keep a superset here)\n ...[\n 'a',\n 'abbr',\n 'article',\n 'aside',\n 'b',\n 'blockquote',\n 'br',\n 'button',\n 'canvas',\n 'code',\n 'dd',\n 'details',\n 'dialog',\n 'div',\n 'dl',\n 'dt',\n 'em',\n 'fieldset',\n 'figcaption',\n 'figure',\n 'footer',\n 'form',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'header',\n 'hr',\n 'i',\n 'iframe',\n 'img',\n 'input',\n 'label',\n 'legend',\n 'li',\n 'main',\n 'mark',\n 'nav',\n 'ol',\n 'optgroup',\n 'option',\n 'output',\n 'p',\n 'pre',\n 'progress',\n 'section',\n 'select',\n 'small',\n 'span',\n 'strong',\n 'sub',\n 'summary',\n 'sup',\n 'table',\n 'tbody',\n 'td',\n 'textarea',\n 'tfoot',\n 'th',\n 'thead',\n 'time',\n 'tr',\n 'ul',\n 'video',\n ],\n // Structural primitives\n 'each',\n 'branch',\n 'show',\n 'memo',\n 'portal',\n 'foreign',\n 'child',\n 'errorBoundary',\n])\n\n/**\n * Extract state access paths from an expression body.\n * Handles:\n * - Direct property access: param.field, param.field.subfield\n * - Bracket notation with string literal: param['field']\n */\nfunction extractPaths(node: ts.Node, paramName: string, _prefix: string, paths: Set<string>): void {\n if (ts.isPropertyAccessExpression(node)) {\n // Skip if this is an intermediate in a deeper chain\n if (ts.isPropertyAccessExpression(node.parent)) {\n // handled when the leaf is visited\n }\n // Skip if this is the callee of a method call: s.todos.filter(...)\n else if (ts.isCallExpression(node.parent) && node.parent.expression === node) {\n // It's a method call — record the object, not the method\n // e.g. s.todos.filter(...) → record 'todos', not 'todos.filter'\n if (ts.isPropertyAccessExpression(node.expression)) {\n const chain = resolvePropertyChain(node.expression, paramName)\n if (chain) paths.add(chain)\n }\n } else {\n const chain = resolvePropertyChain(node, paramName)\n if (chain) {\n paths.add(chain)\n }\n }\n }\n\n if (ts.isElementAccessExpression(node)) {\n const chain = resolveElementAccess(node, paramName)\n if (chain) {\n paths.add(chain)\n }\n }\n\n ts.forEachChild(node, (child) => extractPaths(child, paramName, _prefix, paths))\n}\n\n/**\n * Resolve a property access chain like s.user.name to \"user.name\".\n * Returns null if the chain doesn't start with the state parameter.\n * Stops at depth 2.\n */\nfunction resolvePropertyChain(node: ts.PropertyAccessExpression, paramName: string): string | null {\n const parts: string[] = []\n let current: ts.Expression = node\n\n while (ts.isPropertyAccessExpression(current)) {\n parts.unshift(current.name.text)\n current = current.expression\n }\n\n // The root must be the state parameter\n if (!ts.isIdentifier(current) || current.text !== paramName) {\n return null\n }\n\n // Limit to depth 2\n if (parts.length > 2) {\n return parts.slice(0, 2).join('.')\n }\n\n return parts.join('.')\n}\n\n/**\n * Resolve bracket access with string literal: s['count'] → \"count\"\n */\nfunction resolveElementAccess(node: ts.ElementAccessExpression, paramName: string): string | null {\n if (!ts.isIdentifier(node.expression) || node.expression.text !== paramName) {\n return null\n }\n\n if (ts.isStringLiteral(node.argumentExpression)) {\n return node.argumentExpression.text\n }\n\n return null\n}\n"]}
|
|
1
|
+
{"version":3,"file":"collect-deps.js","sourceRoot":"","sources":["../src/collect-deps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAA;AAE3B;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,2BAA2B,CAAC,UAAyB;IACnE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IAE/B,SAAS,KAAK,CAAC,IAAa;QAC1B,wDAAwD;QACxD,4CAA4C;QAC5C,sEAAsE;QACtE,IAAI,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAA;YAC9B,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACxB,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAE,CAAC,IAAI,CAAA;gBACjC,IAAI,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC;oBAC/B,sEAAsE;oBACtE,IAAI,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;wBAC7B,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,CAAA;oBACpD,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;IAC9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I,CAAA;AACb,CAAC","sourcesContent":["import ts from 'typescript'\n\n/**\n * Walk the AST and collect every unique state access path referenced by\n * a reactive accessor. A reactive accessor is an arrow/function whose\n * placement passes `isReactiveAccessor` — text()/memo() first args,\n * element-helper prop values, and allowlisted framework-API prop values.\n * Paths are rooted at the accessor's single parameter name.\n *\n * Shared by the bit-assignment path (`collectDeps`, below) and the\n * `diagnostics.ts` bitmask-overflow warning. Extracted so both consumers\n * see the same truth — previously the diagnostics side had its own naïve\n * walker that produced false positives for `each({ key })`, `item(...)`,\n * array-method callbacks, and user-land helpers.\n */\nexport function collectStatePathsFromSource(sourceFile: ts.SourceFile): Set<string> {\n const paths = new Set<string>()\n\n function visit(node: ts.Node): void {\n // Look for arrow functions that are reactive accessors:\n // - First arg to text(): text(s => s.count)\n // - Prop values in element helper calls: div({ title: s => s.title })\n if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {\n const params = node.parameters\n if (params.length === 1) {\n const paramName = params[0]!.name\n if (ts.isIdentifier(paramName)) {\n // Check if this looks like a reactive accessor (not an event handler)\n if (isReactiveAccessor(node)) {\n extractPaths(node.body, paramName.text, '', paths)\n }\n }\n }\n }\n\n ts.forEachChild(node, visit)\n }\n\n visit(sourceFile)\n return paths\n}\n\n/**\n * Per-accessor path sets — one entry per reactive arrow/function. Used\n * by the bitmask-overflow diagnostic to find clusters of paths that\n * always fire together (co-occurrence analysis).\n */\nexport function collectAccessorPathSets(sourceFile: ts.SourceFile): Set<string>[] {\n const sets: Set<string>[] = []\n\n function visit(node: ts.Node): void {\n if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {\n const params = node.parameters\n if (params.length === 1) {\n const paramName = params[0]!.name\n if (ts.isIdentifier(paramName) && isReactiveAccessor(node)) {\n const set = new Set<string>()\n extractPaths(node.body, paramName.text, '', set)\n if (set.size > 0) sets.push(set)\n }\n }\n }\n ts.forEachChild(node, visit)\n }\n\n visit(sourceFile)\n return sets\n}\n\n/**\n * Pre-scan a source file to collect all unique state access paths\n * referenced by reactive accessors (arrow functions in props and text() calls).\n * Returns a Map<path, bitPosition> where each path gets a unique power-of-two bit.\n */\nexport function collectDeps(source: string): Map<string, number> {\n const sourceFile = ts.createSourceFile('input.ts', source, ts.ScriptTarget.Latest, true)\n\n // Check if file imports from @llui/dom\n if (!hasLluiImport(sourceFile)) {\n return new Map()\n }\n\n const paths = collectStatePathsFromSource(sourceFile)\n\n // Assign bit positions. The bitmask holds 31 unique paths (positions\n // 0..30). When the count exceeds 31, overflow paths use FULL_MASK (-1)\n // — they always trigger re-evaluation, degrading gracefully. The\n // diagnostic warns the user to decompose.\n const fieldBits = new Map<string, number>()\n let bit = 1\n let index = 0\n for (const path of paths) {\n if (index >= 31) {\n fieldBits.set(path, -1)\n } else {\n fieldBits.set(path, bit)\n bit <<= 1\n }\n index++\n }\n\n return fieldBits\n}\n\nfunction hasLluiImport(sourceFile: ts.SourceFile): boolean {\n for (const stmt of sourceFile.statements) {\n if (\n ts.isImportDeclaration(stmt) &&\n ts.isStringLiteral(stmt.moduleSpecifier) &&\n stmt.moduleSpecifier.text === '@llui/dom'\n ) {\n return true\n }\n }\n return false\n}\n\n/**\n * Determines if an arrow/function expression is a reactive accessor\n * (not an event handler, not a callback like onClick).\n */\nfunction isReactiveAccessor(node: ts.ArrowFunction | ts.FunctionExpression): boolean {\n const parent = node.parent\n\n // text(s => s.count) — first arg to a call\n if (ts.isCallExpression(parent) && parent.arguments[0] === node) {\n // Skip item(t => t.id) — per-item selectors inside each() render.\n // Skip sample(s => s.x) — imperative one-shot read, no binding created\n // (both the top-level import and the destructured-from-h form).\n if (ts.isIdentifier(parent.expression)) {\n if (parent.expression.text === 'item' || parent.expression.text === 'sample') {\n return false\n }\n }\n // Skip array method callbacks: .filter(t => ...), .map(t => ...), .some(t => ...), etc.\n // Allow view-helper primitive calls: h.text(s => ...), h.memo(s => ...)\n if (ts.isPropertyAccessExpression(parent.expression)) {\n const methodName = parent.expression.name.text\n if (methodName === 'text' || methodName === 'memo') {\n return true\n }\n return false\n }\n return true\n }\n\n // div({ title: s => s.title }) — value in a property assignment inside an object literal.\n // Only treat as reactive if the containing call is a known framework API whose\n // properties are reactive accessors. Otherwise user-land helpers like\n // sliceHandler({ narrow: (m) => m.type === ... }) would pollute the path set.\n if (ts.isPropertyAssignment(parent)) {\n const key = parent.name\n if (ts.isIdentifier(key)) {\n // Skip event handlers (onClick, onInput, etc.)\n if (/^on[A-Z]/.test(key.text)) return false\n // Skip each() key function and other non-reactive props\n if (key.text === 'key' || key.text === 'name') return false\n // Walk up to find the enclosing call expression\n let ancestor: ts.Node | undefined = parent.parent // ObjectLiteralExpression\n while (ancestor && !ts.isCallExpression(ancestor)) {\n ancestor = ancestor.parent\n }\n if (!ancestor) return false\n const callExpr = ancestor as ts.CallExpression\n if (!ts.isIdentifier(callExpr.expression)) return false\n return REACTIVE_API_NAMES.has(callExpr.expression.text)\n }\n }\n\n return false\n}\n\n// Framework APIs whose object-literal arguments contain reactive accessors.\n// Arrow functions in property values of these calls are state-tracked.\nconst REACTIVE_API_NAMES = new Set([\n // Element helpers (see ELEMENT_HELPERS in transform.ts — we keep a superset here)\n ...[\n 'a',\n 'abbr',\n 'article',\n 'aside',\n 'b',\n 'blockquote',\n 'br',\n 'button',\n 'canvas',\n 'code',\n 'dd',\n 'details',\n 'dialog',\n 'div',\n 'dl',\n 'dt',\n 'em',\n 'fieldset',\n 'figcaption',\n 'figure',\n 'footer',\n 'form',\n 'h1',\n 'h2',\n 'h3',\n 'h4',\n 'h5',\n 'h6',\n 'header',\n 'hr',\n 'i',\n 'iframe',\n 'img',\n 'input',\n 'label',\n 'legend',\n 'li',\n 'main',\n 'mark',\n 'nav',\n 'ol',\n 'optgroup',\n 'option',\n 'output',\n 'p',\n 'pre',\n 'progress',\n 'section',\n 'select',\n 'small',\n 'span',\n 'strong',\n 'sub',\n 'summary',\n 'sup',\n 'table',\n 'tbody',\n 'td',\n 'textarea',\n 'tfoot',\n 'th',\n 'thead',\n 'time',\n 'tr',\n 'ul',\n 'video',\n ],\n // Structural primitives\n 'each',\n 'branch',\n 'scope',\n 'show',\n 'memo',\n 'portal',\n 'foreign',\n 'child',\n 'errorBoundary',\n])\n\n/**\n * Extract state access paths from an expression body.\n * Handles:\n * - Direct property access: param.field, param.field.subfield\n * - Bracket notation with string literal: param['field']\n */\nfunction extractPaths(node: ts.Node, paramName: string, _prefix: string, paths: Set<string>): void {\n if (ts.isPropertyAccessExpression(node)) {\n // Skip if this is an intermediate in a deeper chain\n if (ts.isPropertyAccessExpression(node.parent)) {\n // handled when the leaf is visited\n }\n // Skip if this is the callee of a method call: s.todos.filter(...)\n else if (ts.isCallExpression(node.parent) && node.parent.expression === node) {\n // It's a method call — record the object, not the method\n // e.g. s.todos.filter(...) → record 'todos', not 'todos.filter'\n if (ts.isPropertyAccessExpression(node.expression)) {\n const chain = resolvePropertyChain(node.expression, paramName)\n if (chain) paths.add(chain)\n }\n } else {\n const chain = resolvePropertyChain(node, paramName)\n if (chain) {\n paths.add(chain)\n }\n }\n }\n\n if (ts.isElementAccessExpression(node)) {\n const chain = resolveElementAccess(node, paramName)\n if (chain) {\n paths.add(chain)\n }\n }\n\n ts.forEachChild(node, (child) => extractPaths(child, paramName, _prefix, paths))\n}\n\n/**\n * Resolve a property access chain like s.user.name to \"user.name\".\n * Returns null if the chain doesn't start with the state parameter.\n * Stops at depth 2.\n */\nfunction resolvePropertyChain(node: ts.PropertyAccessExpression, paramName: string): string | null {\n const parts: string[] = []\n let current: ts.Expression = node\n\n while (ts.isPropertyAccessExpression(current)) {\n parts.unshift(current.name.text)\n current = current.expression\n }\n\n // The root must be the state parameter\n if (!ts.isIdentifier(current) || current.text !== paramName) {\n return null\n }\n\n // Limit to depth 2\n if (parts.length > 2) {\n return parts.slice(0, 2).join('.')\n }\n\n return parts.join('.')\n}\n\n/**\n * Resolve bracket access with string literal: s['count'] → \"count\"\n */\nfunction resolveElementAccess(node: ts.ElementAccessExpression, paramName: string): string | null {\n if (!ts.isIdentifier(node.expression) || node.expression.text !== paramName) {\n return null\n }\n\n if (ts.isStringLiteral(node.argumentExpression)) {\n return node.argumentExpression.text\n }\n\n return null\n}\n"]}
|
package/dist/diagnostics.d.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
export interface Diagnostic {
|
|
2
|
+
/** Short identifier — passed to `disabledWarnings` in LluiPluginOptions to silence. */
|
|
3
|
+
rule: DiagnosticRule;
|
|
2
4
|
message: string;
|
|
3
5
|
line: number;
|
|
4
6
|
column: number;
|
|
5
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Every diagnostic the plugin can emit. Exported so consumers can pass
|
|
10
|
+
* `disabledWarnings: [...]` with compile-time type safety.
|
|
11
|
+
*/
|
|
12
|
+
export type DiagnosticRule = 'map-on-state' | 'exhaustive-update' | 'accessibility' | 'controlled-input' | 'child-static-props' | 'bitmask-overflow' | 'namespace-import' | 'spread-in-children' | 'empty-props' | 'static-on';
|
|
6
13
|
export declare function diagnose(source: string): Diagnostic[];
|
|
7
14
|
//# sourceMappingURL=diagnostics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"diagnostics.d.ts","sourceRoot":"","sources":["../src/diagnostics.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,UAAU;IACzB,uFAAuF;IACvF,IAAI,EAAE,cAAc,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;CACf;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GACtB,cAAc,GACd,mBAAmB,GACnB,eAAe,GACf,kBAAkB,GAClB,oBAAoB,GACpB,kBAAkB,GAClB,kBAAkB,GAClB,oBAAoB,GACpB,aAAa,GACb,WAAW,CAAA;AAiFf,wBAAgB,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE,CA2BrD"}
|