@component-compass/reference-graph 0.1.17 → 0.1.19
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/builder.d.ts +7 -1
- package/dist/builder.js +9 -3
- package/dist/builder.js.map +1 -1
- package/dist/engine/argument-map.d.ts +4 -0
- package/dist/engine/argument-map.js +7 -4
- package/dist/engine/argument-map.js.map +1 -1
- package/dist/engine/assert-never.d.ts +7 -0
- package/dist/engine/assert-never.js +10 -0
- package/dist/engine/assert-never.js.map +1 -0
- package/dist/engine/component-shape.d.ts +38 -0
- package/dist/engine/component-shape.js +177 -0
- package/dist/engine/component-shape.js.map +1 -0
- package/dist/engine/helper-callers.d.ts +43 -28
- package/dist/engine/helper-callers.js +94 -96
- package/dist/engine/helper-callers.js.map +1 -1
- package/dist/engine/host-element.d.ts +37 -0
- package/dist/engine/host-element.js +55 -0
- package/dist/engine/host-element.js.map +1 -0
- package/dist/engine/index.d.ts +4 -0
- package/dist/engine/index.js +312 -99
- package/dist/engine/index.js.map +1 -1
- package/dist/engine/library-stubs.d.ts +2 -0
- package/dist/engine/library-stubs.js +42 -0
- package/dist/engine/library-stubs.js.map +1 -0
- package/dist/engine/member-identity.d.ts +24 -4
- package/dist/engine/member-identity.js +28 -4
- package/dist/engine/member-identity.js.map +1 -1
- package/dist/engine/registry.d.ts +100 -0
- package/dist/engine/registry.js +242 -0
- package/dist/engine/registry.js.map +1 -0
- package/dist/engine/resolve-reference.js +7 -0
- package/dist/engine/resolve-reference.js.map +1 -1
- package/dist/engine/resolve-type.js +54 -1
- package/dist/engine/resolve-type.js.map +1 -1
- package/dist/engine/wrapper-folding.d.ts +21 -3
- package/dist/engine/wrapper-folding.js +386 -91
- package/dist/engine/wrapper-folding.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/types/file-graph.d.ts +21 -10
- package/package.json +2 -2
package/dist/builder.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { OccurrenceVia, PropUsage, ResolveImport } from "@component-compass/plugin-core";
|
|
2
|
-
import type { BindingDecl, ExportRecord, Graph, ImportRecord, Reference, ScopeId } from "./index.js";
|
|
2
|
+
import type { BindingDecl, ExportRecord, Graph, ImportRecord, InferredType, Reference, ScopeId } from "./index.js";
|
|
3
3
|
import type { Dialect, GraphHostHooks } from "./types/file-graph.js";
|
|
4
4
|
export interface FileBuilder {
|
|
5
5
|
/** Repo-relative POSIX path of the file this builder is emitting into. */
|
|
@@ -92,6 +92,12 @@ export interface FileBuilder {
|
|
|
92
92
|
callee: Omit<Reference, "scope"> & {
|
|
93
93
|
scope?: ScopeId;
|
|
94
94
|
};
|
|
95
|
+
args?: InferredType[];
|
|
96
|
+
}): void;
|
|
97
|
+
/** Record an identifier read in value position. See `FileGraph.heldRefs`.
|
|
98
|
+
* Scope defaults to the current scope, as for a JSX usage. */
|
|
99
|
+
addHeldRef(ref: Omit<Reference, "scope"> & {
|
|
100
|
+
scope?: ScopeId;
|
|
95
101
|
}): void;
|
|
96
102
|
/** Mark the most-recently-emitted usage as the lexical parent for any
|
|
97
103
|
* subsequent usages emitted before the matching `popUsageScope`. Parsers
|
package/dist/builder.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// - parser-vue: paper sketch (Task 0.2, see plan doc)
|
|
4
4
|
// Members not justified by either should not be added speculatively.
|
|
5
5
|
import { isAbsolute, relative, resolve } from "node:path";
|
|
6
|
+
import { posixPath } from "@component-compass/plugin-core";
|
|
6
7
|
import { MODULE_SCOPE } from "./index.js";
|
|
7
8
|
export function createGraphBuilder(opts) {
|
|
8
9
|
const files = new Map();
|
|
@@ -17,6 +18,7 @@ export function createGraphBuilder(opts) {
|
|
|
17
18
|
const tagUsages = [];
|
|
18
19
|
const ownership = [];
|
|
19
20
|
const bodyCalls = [];
|
|
21
|
+
const heldRefs = [];
|
|
20
22
|
const scopeStack = [MODULE_SCOPE];
|
|
21
23
|
let nextScopeId = 1;
|
|
22
24
|
// Deterministic scope ids per AST node key (`fn@<span-start>`): value
|
|
@@ -30,7 +32,7 @@ export function createGraphBuilder(opts) {
|
|
|
30
32
|
// `pushUsageScope` was called. See FileGraph.ownership.parentUsageIdx /
|
|
31
33
|
// depth.
|
|
32
34
|
const parentStack = [];
|
|
33
|
-
const fg = { filePath, dialect, scopes, declarations, imports, importsByLocal, exports, jsxUsages, tagUsages, ownership, bodyCalls };
|
|
35
|
+
const fg = { filePath, dialect, scopes, declarations, imports, importsByLocal, exports, jsxUsages, tagUsages, ownership, bodyCalls, heldRefs };
|
|
34
36
|
files.set(filePath, fg);
|
|
35
37
|
return {
|
|
36
38
|
filePath,
|
|
@@ -158,7 +160,11 @@ export function createGraphBuilder(opts) {
|
|
|
158
160
|
},
|
|
159
161
|
addBodyCall(record) {
|
|
160
162
|
const scope = record.callee.scope ?? scopeStack[scopeStack.length - 1] ?? MODULE_SCOPE;
|
|
161
|
-
bodyCalls.push({ ownerSymbol: record.ownerSymbol, callee: { ...record.callee, scope } });
|
|
163
|
+
bodyCalls.push({ ownerSymbol: record.ownerSymbol, callee: { ...record.callee, scope }, args: record.args ?? [] });
|
|
164
|
+
},
|
|
165
|
+
addHeldRef(ref) {
|
|
166
|
+
const scope = ref.scope ?? scopeStack[scopeStack.length - 1] ?? MODULE_SCOPE;
|
|
167
|
+
heldRefs.push({ ...ref, scope });
|
|
162
168
|
},
|
|
163
169
|
pushUsageScope() {
|
|
164
170
|
// Push the most-recently-emitted usage as the parent frame. No-op
|
|
@@ -193,7 +199,7 @@ export function createGraphBuilder(opts) {
|
|
|
193
199
|
const resolveToGraphKey = (absPath) => {
|
|
194
200
|
if (!isAbsolute(absPath))
|
|
195
201
|
return null;
|
|
196
|
-
const rel = relative(repoRoot, absPath)
|
|
202
|
+
const rel = posixPath(relative(repoRoot, absPath));
|
|
197
203
|
// Reject paths that escape the repo root (e.g. node_modules sibling
|
|
198
204
|
// checkouts). Callers fall back to the absolute path; `files.get`
|
|
199
205
|
// returns undefined for both cases. Repo-internal paths return the
|
package/dist/builder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,kDAAkD;AAClD,wDAAwD;AACxD,qEAAqE;AAErE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,kDAAkD;AAClD,wDAAwD;AACxD,qEAAqE;AAErE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE1D,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAC;AAY3D,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAuG1C,MAAM,UAAU,kBAAkB,CAAC,IAA+B;IAChE,MAAM,KAAK,GAAG,IAAI,GAAG,EAAqB,CAAC;IAE3C,OAAO;QACL,SAAS,CAAC,QAAgB,EAAE,UAAmB,OAAO;YACpD,MAAM,MAAM,GAAG,IAAI,GAAG,CAAsC,CAAC,CAAC,YAAY,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YAChG,MAAM,YAAY,GAAG,IAAI,GAAG,EAAuB,CAAC;YACpD,MAAM,OAAO,GAAmB,EAAE,CAAC;YACnC,MAAM,cAAc,GAAG,IAAI,GAAG,EAAwB,CAAC;YACvD,MAAM,OAAO,GAAmB,EAAE,CAAC;YACnC,MAAM,SAAS,GAAe,EAAE,CAAC;YACjC,MAAM,SAAS,GAAe,EAAE,CAAC;YACjC,MAAM,SAAS,GAA2B,EAAE,CAAC;YAC7C,MAAM,SAAS,GAA4E,EAAE,CAAC;YAC9F,MAAM,QAAQ,GAAgB,EAAE,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IAAI,CAAC;oBACtC,MAAM,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;oBACnD,oEAAoE;oBACpE,kEAAkE;oBAClE,mEAAmE;oBACnE,mEAAmE;oBACnE,kEAAkE;oBAClE,6BAA6B;oBAC7B,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC;wBAAE,OAAO,IAAI,CAAC;oBACtC,OAAO,GAAG,CAAC;gBACb,CAAC,CAAC;gBACF,kEAAkE;gBAClE,gEAAgE;gBAChE,oEAAoE;gBACpE,+DAA+D;gBAC/D,mEAAmE;gBACnE,MAAM,cAAc,GAAkB,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CACnD,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC;gBAC/E,OAAO;oBACL,KAAK;oBACL,cAAc;oBACd,iBAAiB;oBACjB,sBAAsB,EAAE,IAAI,CAAC,sBAAsB,IAAI,KAAK;oBAC5D,GAAG,SAAS;iBACb,CAAC;YACJ,CAAC;YACD,OAAO;gBACL,KAAK;gBACL,cAAc,EAAE,IAAI,CAAC,cAAc;gBACnC,sBAAsB,EAAE,IAAI,CAAC,sBAAsB,IAAI,KAAK;gBAC5D,GAAG,SAAS;aACb,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -11,4 +11,8 @@ export interface ArgumentMap {
|
|
|
11
11
|
unbind(fn: Reference): void;
|
|
12
12
|
lookup(fn: Reference, index: number): InferredType | undefined;
|
|
13
13
|
}
|
|
14
|
+
/** Key an ArgumentMap frame by. Exported so wrapper-folding's structural
|
|
15
|
+
* pass-through check compares `ParameterOf.fn` against a callee's
|
|
16
|
+
* `bindingRef` exactly the way `lookup` would. */
|
|
17
|
+
export declare function argumentRefKey(ref: Reference): string;
|
|
14
18
|
export declare function createArgumentMap(): ArgumentMap;
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
/** Key an ArgumentMap frame by. Exported so wrapper-folding's structural
|
|
2
|
+
* pass-through check compares `ParameterOf.fn` against a callee's
|
|
3
|
+
* `bindingRef` exactly the way `lookup` would. */
|
|
4
|
+
export function argumentRefKey(ref) {
|
|
2
5
|
return `${ref.symbol}::${ref.scope}`;
|
|
3
6
|
}
|
|
4
7
|
export function createArgumentMap() {
|
|
5
8
|
const stack = [];
|
|
6
9
|
return {
|
|
7
10
|
bind(fn, args) {
|
|
8
|
-
stack.push({ key:
|
|
11
|
+
stack.push({ key: argumentRefKey(fn), args });
|
|
9
12
|
},
|
|
10
13
|
unbind(fn) {
|
|
11
|
-
const key =
|
|
14
|
+
const key = argumentRefKey(fn);
|
|
12
15
|
for (let i = stack.length - 1; i >= 0; i--) {
|
|
13
16
|
if (stack[i]?.key === key) {
|
|
14
17
|
stack.splice(i, 1);
|
|
@@ -17,7 +20,7 @@ export function createArgumentMap() {
|
|
|
17
20
|
}
|
|
18
21
|
},
|
|
19
22
|
lookup(fn, index) {
|
|
20
|
-
const key =
|
|
23
|
+
const key = argumentRefKey(fn);
|
|
21
24
|
for (let i = stack.length - 1; i >= 0; i--) {
|
|
22
25
|
const frame = stack[i];
|
|
23
26
|
if (frame?.key === key)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"argument-map.js","sourceRoot":"","sources":["../../src/engine/argument-map.ts"],"names":[],"mappings":"AAeA,
|
|
1
|
+
{"version":3,"file":"argument-map.js","sourceRoot":"","sources":["../../src/engine/argument-map.ts"],"names":[],"mappings":"AAeA;;mDAEmD;AACnD,MAAM,UAAU,cAAc,CAAC,GAAc;IAC3C,OAAO,GAAG,GAAG,CAAC,MAAM,KAAK,GAAG,CAAC,KAAK,EAAE,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,iBAAiB;IAC/B,MAAM,KAAK,GAAiD,EAAE,CAAC;IAC/D,OAAO;QACL,IAAI,CAAC,EAAE,EAAE,IAAI;YACX,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,cAAc,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;QAChD,CAAC;QACD,MAAM,CAAC,EAAE;YACP,MAAM,GAAG,GAAG,cAAc,CAAC,EAAE,CAAC,CAAC;YAC/B,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC3C,IAAI,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,GAAG,EAAE,CAAC;oBAC1B,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;oBACnB,OAAO;gBACT,CAAC;YACH,CAAC;QACH,CAAC;QACD,MAAM,CAAC,EAAE,EAAE,KAAK;YACd,MAAM,GAAG,GAAG,cAAc,CAAC,EAAE,CAAC,CAAC;YAC/B,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;gBAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;gBACvB,IAAI,KAAK,EAAE,GAAG,KAAK,GAAG;oBAAE,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACnD,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exhaustiveness guard for every `switch (type.kind)` over `InferredType`
|
|
3
|
+
* (spec D7). Reaching it is a type error at compile time — adding a kind to
|
|
4
|
+
* the IR must fail to build in every interpreter — and a loud error at
|
|
5
|
+
* runtime for the one way TypeScript can be bypassed (a cast).
|
|
6
|
+
*/
|
|
7
|
+
export declare function assertNever(x: never): never;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exhaustiveness guard for every `switch (type.kind)` over `InferredType`
|
|
3
|
+
* (spec D7). Reaching it is a type error at compile time — adding a kind to
|
|
4
|
+
* the IR must fail to build in every interpreter — and a loud error at
|
|
5
|
+
* runtime for the one way TypeScript can be bypassed (a cast).
|
|
6
|
+
*/
|
|
7
|
+
export function assertNever(x) {
|
|
8
|
+
throw new Error(`Unhandled InferredType kind: ${JSON.stringify(x)}`);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=assert-never.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert-never.js","sourceRoot":"","sources":["../../src/engine/assert-never.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,CAAQ;IAClC,MAAM,IAAI,KAAK,CAAC,gCAAgC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AACvE,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { FileGraph, Graph, InferredType } from "../index.js";
|
|
2
|
+
import { type ArgumentMap } from "./argument-map.js";
|
|
3
|
+
import { type CycleGuard } from "./cycle-detection.js";
|
|
4
|
+
/**
|
|
5
|
+
* THE component-shape predicate (spec D2, D7, D9). Reduces an InferredType
|
|
6
|
+
* to what its VALUE is:
|
|
7
|
+
*
|
|
8
|
+
* "jsx" — a JSX value (`const br = <br/>`, or what calling a
|
|
9
|
+
* component yields). Not a component.
|
|
10
|
+
* "component" — a function whose returns are DIRECTLY JSX, or a call that
|
|
11
|
+
* evaluates to one.
|
|
12
|
+
* "unresolved" — bottoms out at an import the graph cannot see with nothing
|
|
13
|
+
* component-shaped in hand (D7).
|
|
14
|
+
* "other" — anything else: factories, data, hooks, strings.
|
|
15
|
+
*
|
|
16
|
+
* The non-recursion into nested Function returns is load-bearing: a Function
|
|
17
|
+
* whose return is itself a Function evaluates that return to "component",
|
|
18
|
+
* not "jsx", so the outer function is "other" — a factory. That single rule
|
|
19
|
+
* separates `createField` from its products and is why `hasJsx`'s recursive
|
|
20
|
+
* arm was deleted (D11). Do not add a second implementation anywhere; every
|
|
21
|
+
* caller — registry membership, owner classification, occurrence admission —
|
|
22
|
+
* calls this one. Named in docs/CONTEXT.md ("Component-shape seam").
|
|
23
|
+
*/
|
|
24
|
+
export type ValueKind = "jsx" | "component" | "unresolved" | "other";
|
|
25
|
+
export declare function evalKind(type: InferredType, graph: Graph, fileGraph: FileGraph, argMap?: ArgumentMap, guard?: CycleGuard): ValueKind;
|
|
26
|
+
export declare function isComponentShaped(type: InferredType, graph: Graph, fileGraph: FileGraph): boolean;
|
|
27
|
+
/** A TypeOf (possibly under a ReturnTypeOf chain, or a MemberOf access on
|
|
28
|
+
* one — `Sentry.withProfiler`) that names an import the graph cannot
|
|
29
|
+
* resolve — the shape the opaque-HOC fold synthesises identity from (#274).
|
|
30
|
+
* Unwrapping MemberOf.obj is what lets Ruling 16(ii)'s render-callback
|
|
31
|
+
* narrowing correctly except FOR an import-backed namespace member call.
|
|
32
|
+
*
|
|
33
|
+
* Exported (ruling 19): `wrapper-folding.ts`'s opaque-callee identity-fold
|
|
34
|
+
* step shares this EXACT predicate for its parallel "is this a data-method
|
|
35
|
+
* render call, not a wrapper" decision — never re-derive it there. Takes
|
|
36
|
+
* plain params (not this module's private `Ctx`) so a caller outside this
|
|
37
|
+
* file doesn't need to construct one. */
|
|
38
|
+
export declare function isImportBackedLeaf(t: InferredType, graph: Graph, fileGraph: FileGraph, guard: CycleGuard): boolean;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { createArgumentMap } from "./argument-map.js";
|
|
2
|
+
import { createCycleGuard } from "./cycle-detection.js";
|
|
3
|
+
import { fileGraphForRef, resolveReference } from "./resolve-reference.js";
|
|
4
|
+
import { resolveToFunctions, resolveType, DYNAMIC_MEMBER_KEY } from "./resolve-type.js";
|
|
5
|
+
import { assertNever } from "./assert-never.js";
|
|
6
|
+
export function evalKind(type, graph, fileGraph, argMap = createArgumentMap(), guard = createCycleGuard()) {
|
|
7
|
+
return evalInner(type, { graph, fileGraph, argMap, guard });
|
|
8
|
+
}
|
|
9
|
+
export function isComponentShaped(type, graph, fileGraph) {
|
|
10
|
+
return evalKind(type, graph, fileGraph) === "component";
|
|
11
|
+
}
|
|
12
|
+
/** Priority merge for fan-out shapes: jsx > component > unresolved > other. */
|
|
13
|
+
function merge(kinds) {
|
|
14
|
+
if (kinds.includes("jsx"))
|
|
15
|
+
return "jsx";
|
|
16
|
+
if (kinds.includes("component"))
|
|
17
|
+
return "component";
|
|
18
|
+
if (kinds.includes("unresolved"))
|
|
19
|
+
return "unresolved";
|
|
20
|
+
return "other";
|
|
21
|
+
}
|
|
22
|
+
function evalInner(t, ctx) {
|
|
23
|
+
if (ctx.guard.pushNode(t) === "cycle")
|
|
24
|
+
return "other";
|
|
25
|
+
try {
|
|
26
|
+
switch (t.kind) {
|
|
27
|
+
case "JSX":
|
|
28
|
+
return "jsx";
|
|
29
|
+
case "Function":
|
|
30
|
+
return t.returns.some((r) => evalInner(r, ctx) === "jsx") ? "component" : "other";
|
|
31
|
+
case "Union":
|
|
32
|
+
return merge(t.types.map((u) => evalInner(u, ctx)));
|
|
33
|
+
case "ParameterOf": {
|
|
34
|
+
const bound = ctx.argMap.lookup(t.fn, t.index);
|
|
35
|
+
return bound ? evalInner(bound, ctx) : "other";
|
|
36
|
+
}
|
|
37
|
+
case "TypeOf": {
|
|
38
|
+
const resolved = resolveReference(ctx.graph, ctx.fileGraph, t.ref, ctx.guard);
|
|
39
|
+
if (resolved.kind === "Unknown")
|
|
40
|
+
return isImportBacked(t, ctx.graph, ctx.fileGraph) ? "unresolved" : "other";
|
|
41
|
+
return evalInner(resolved, ctx);
|
|
42
|
+
}
|
|
43
|
+
case "MemberOf": {
|
|
44
|
+
const objs = resolveType(ctx.graph, ctx.fileGraph, t.obj, ctx.argMap, ctx.guard);
|
|
45
|
+
const kinds = [];
|
|
46
|
+
for (const { type: obj } of objs) {
|
|
47
|
+
if (obj.kind !== "Object")
|
|
48
|
+
continue;
|
|
49
|
+
// Ruling 16(iii): a dynamic-key access (`BannerComponent[type]`)
|
|
50
|
+
// could select any prop at runtime — merge the shape of every
|
|
51
|
+
// prop the object carries, the same "any branch could be it"
|
|
52
|
+
// treatment Union already gets.
|
|
53
|
+
if (t.member === DYNAMIC_MEMBER_KEY) {
|
|
54
|
+
for (const prop of Object.values(obj.props))
|
|
55
|
+
kinds.push(evalInner(prop, ctx));
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const prop = obj.props[t.member];
|
|
59
|
+
if (prop)
|
|
60
|
+
kinds.push(evalInner(prop, ctx));
|
|
61
|
+
}
|
|
62
|
+
return kinds.length === 0 ? "other" : merge(kinds);
|
|
63
|
+
}
|
|
64
|
+
case "ReturnTypeOf":
|
|
65
|
+
return evalCall(t, ctx);
|
|
66
|
+
case "Str":
|
|
67
|
+
case "Object":
|
|
68
|
+
case "Array":
|
|
69
|
+
case "Unknown":
|
|
70
|
+
case "DynamicImport":
|
|
71
|
+
// A literal array of JSX elements is deliberately "other", the same
|
|
72
|
+
// treatment a Function returning Object-containing-JSX gets ("data
|
|
73
|
+
// factory"): helper-callers.ts's helper/component split (D11) depends
|
|
74
|
+
// on a Function returning Array<JSX> classifying as a helper, not a
|
|
75
|
+
// component, so its callers attribute correctly via helper-call
|
|
76
|
+
// chains instead of it becoming a standalone identity. Ruling 16's
|
|
77
|
+
// ".map(render)" and dynamic-member patterns don't need this arm —
|
|
78
|
+
// both resolve to "jsx" through evalCall's opaque-MemberOf-callee
|
|
79
|
+
// rule and the MemberOf DYNAMIC_MEMBER_KEY merge instead.
|
|
80
|
+
return "other";
|
|
81
|
+
default:
|
|
82
|
+
return assertNever(t);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
ctx.guard.popNode(t);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function evalCall(t, ctx) {
|
|
90
|
+
// `lazy(() => import('./x'))` and friends: the engine's lazy-import rule
|
|
91
|
+
// owns identity; for shape purposes the call is a component.
|
|
92
|
+
if (t.args.some(containsDynamicImport))
|
|
93
|
+
return "component";
|
|
94
|
+
const fns = resolveToFunctions(ctx.graph, ctx.fileGraph, t.callee, ctx.argMap, ctx.guard);
|
|
95
|
+
const resolvable = [];
|
|
96
|
+
for (const f of fns) {
|
|
97
|
+
if (f.fn.kind === "Function")
|
|
98
|
+
resolvable.push(f);
|
|
99
|
+
}
|
|
100
|
+
if (resolvable.length === 0) {
|
|
101
|
+
// Opaque callee (D9 arm 3 / D7): component iff some argument is
|
|
102
|
+
// component-shaped or an import-backed leaf the engine will fold to.
|
|
103
|
+
const carries = t.args.some((a) => evalInner(a, ctx) === "component" || isImportBackedLeaf(a, ctx.graph, ctx.fileGraph, ctx.guard));
|
|
104
|
+
if (!carries)
|
|
105
|
+
return "unresolved";
|
|
106
|
+
// Ruling 16(ii): a method call on non-import-backed data — a parameter,
|
|
107
|
+
// a local array/object literal, a hook result, a global like
|
|
108
|
+
// `Object.keys(x)` — with a component-shaped argument is a *render
|
|
109
|
+
// callback* (`items.map(({...}) => <Button/>)`), not a wrapper that
|
|
110
|
+
// takes a component as a prop: the call's OUTPUT is rendered JSX, not a
|
|
111
|
+
// component. An import-backed callee (the actual unresolvable-HOC case
|
|
112
|
+
// D9 arm 3 exists for) keeps "component". Ruling 19: wrapper-folding.ts's
|
|
113
|
+
// opaque step shares this exact condition (isImportBackedLeaf, exported
|
|
114
|
+
// below) for the parallel identity-folding decision — don't re-derive it.
|
|
115
|
+
if (t.callee.kind === "MemberOf" && !isImportBackedLeaf(t.callee, ctx.graph, ctx.fileGraph, ctx.guard))
|
|
116
|
+
return "jsx";
|
|
117
|
+
return "component";
|
|
118
|
+
}
|
|
119
|
+
const kinds = [];
|
|
120
|
+
for (const { fn, bindingRef } of resolvable) {
|
|
121
|
+
if (fn.kind !== "Function")
|
|
122
|
+
continue;
|
|
123
|
+
if (bindingRef)
|
|
124
|
+
ctx.argMap.bind(bindingRef, t.args);
|
|
125
|
+
try {
|
|
126
|
+
for (const ret of fn.returns)
|
|
127
|
+
kinds.push(evalInner(ret, ctx));
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
if (bindingRef)
|
|
131
|
+
ctx.argMap.unbind(bindingRef);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return merge(kinds);
|
|
135
|
+
}
|
|
136
|
+
function isImportBacked(t, graph, fileGraph) {
|
|
137
|
+
return fileGraphForRef(graph, t.ref, fileGraph).importsByLocal.has(t.ref.symbol);
|
|
138
|
+
}
|
|
139
|
+
/** A TypeOf (possibly under a ReturnTypeOf chain, or a MemberOf access on
|
|
140
|
+
* one — `Sentry.withProfiler`) that names an import the graph cannot
|
|
141
|
+
* resolve — the shape the opaque-HOC fold synthesises identity from (#274).
|
|
142
|
+
* Unwrapping MemberOf.obj is what lets Ruling 16(ii)'s render-callback
|
|
143
|
+
* narrowing correctly except FOR an import-backed namespace member call.
|
|
144
|
+
*
|
|
145
|
+
* Exported (ruling 19): `wrapper-folding.ts`'s opaque-callee identity-fold
|
|
146
|
+
* step shares this EXACT predicate for its parallel "is this a data-method
|
|
147
|
+
* render call, not a wrapper" decision — never re-derive it there. Takes
|
|
148
|
+
* plain params (not this module's private `Ctx`) so a caller outside this
|
|
149
|
+
* file doesn't need to construct one. */
|
|
150
|
+
export function isImportBackedLeaf(t, graph, fileGraph, guard) {
|
|
151
|
+
let cur = t;
|
|
152
|
+
while (cur.kind === "ReturnTypeOf" || cur.kind === "MemberOf") {
|
|
153
|
+
cur = cur.kind === "ReturnTypeOf" ? cur.callee : cur.obj;
|
|
154
|
+
}
|
|
155
|
+
if (cur.kind !== "TypeOf")
|
|
156
|
+
return false;
|
|
157
|
+
if (!isImportBacked(cur, graph, fileGraph))
|
|
158
|
+
return false;
|
|
159
|
+
return resolveReference(graph, fileGraph, cur.ref, guard).kind === "Unknown";
|
|
160
|
+
}
|
|
161
|
+
function containsDynamicImport(t) {
|
|
162
|
+
switch (t.kind) {
|
|
163
|
+
case "DynamicImport":
|
|
164
|
+
return true;
|
|
165
|
+
case "Function":
|
|
166
|
+
return t.returns.some(containsDynamicImport);
|
|
167
|
+
case "ReturnTypeOf":
|
|
168
|
+
return containsDynamicImport(t.callee) || t.args.some(containsDynamicImport);
|
|
169
|
+
case "MemberOf":
|
|
170
|
+
return containsDynamicImport(t.obj);
|
|
171
|
+
case "Union":
|
|
172
|
+
return t.types.some(containsDynamicImport);
|
|
173
|
+
default:
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=component-shape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-shape.js","sourceRoot":"","sources":["../../src/engine/component-shape.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAmB,MAAM,sBAAsB,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC3E,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,kBAAkB,EAAgB,MAAM,mBAAmB,CAAC;AACtG,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AA0BhD,MAAM,UAAU,QAAQ,CACtB,IAAkB,EAClB,KAAY,EACZ,SAAoB,EACpB,SAAsB,iBAAiB,EAAE,EACzC,QAAoB,gBAAgB,EAAE;IAEtC,OAAO,SAAS,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;AAC9D,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAkB,EAAE,KAAY,EAAE,SAAoB;IACtF,OAAO,QAAQ,CAAC,IAAI,EAAE,K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AAqB,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAC/E,KAAK,UAAU;YACb,OAAO,qBAAqB,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACtC,KAAK,OAAO;YACV,OAAO,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QAC7C;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -1,33 +1,34 @@
|
|
|
1
|
-
import type { BindingDecl, Graph,
|
|
2
|
-
import {
|
|
3
|
-
export type Classification = "component" | "helper" | "unknown";
|
|
1
|
+
import type { BindingDecl, FileGraph, Graph, Reference } from "../index.js";
|
|
2
|
+
import type { ComponentRegistry } from "./registry.js";
|
|
4
3
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* caller preserves today's behavior (no helper reassignment).
|
|
10
|
-
*
|
|
11
|
-
* NOTE: an `originFile` argument is required when the decl's value contains
|
|
12
|
-
* cross-module type refs (TypeOf / ReturnTypeOf with refs), so that
|
|
13
|
-
* `resolveReference` knows which FileGraph to look up scope chains against.
|
|
4
|
+
* Walk the scope chain for `ref.symbol` in `fileGraph.declarations` and
|
|
5
|
+
* return the first matching BindingDecl, or null if not found. THE
|
|
6
|
+
* scope-chain walk (I4) — `registry.ts`'s `resolveUsageTarget` calls this
|
|
7
|
+
* seam instead of re-deriving it.
|
|
14
8
|
*/
|
|
15
|
-
export declare function
|
|
9
|
+
export declare function findLocalDeclaration(fileGraph: FileGraph, ref: Reference): BindingDecl | null;
|
|
10
|
+
export type Classification = "component" | "helper" | "unknown";
|
|
16
11
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
12
|
+
* Component-vs-helper classification for owner attribution (#559): owners
|
|
13
|
+
* are registry members, or they fan out. A Function- or call-valued
|
|
14
|
+
* declaration the registry admits is a "component" and owns its JSX; one it
|
|
15
|
+
* does not admit is a "helper", and the JSX inside it belongs to its callers
|
|
16
|
+
* (`resolveOwnerChain`). Plain values stay "unknown" so `resolveOwnerChain`
|
|
17
|
+
* treats them as it always has.
|
|
19
18
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
* Object / Array / Str / Unknown / etc. → false
|
|
19
|
+
* No second shape test and no second naming rule live here: `registry` is
|
|
20
|
+
* the roster view (`excludeHostElementNames` applied), so a lowercase render
|
|
21
|
+
* helper (#540), a capitalised function only ever called (`ActionButtons({…})`),
|
|
22
|
+
* and a dead JSX-returning declaration are all helpers for the same reason —
|
|
23
|
+
* the registry did not admit them.
|
|
26
24
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
25
|
+
* A Vue SFC — the default-exported declaration of a vue-dialect file — is
|
|
26
|
+
* outside the registry by design (it is not typed by this algebra) and the
|
|
27
|
+
* engine admits its identity unconditionally; ownership follows the same
|
|
28
|
+
* rule, so an SFC always owns its template. Any other declaration in a Vue
|
|
29
|
+
* file (a `<script>` helper) is judged like a React one.
|
|
29
30
|
*/
|
|
30
|
-
export declare function
|
|
31
|
+
export declare function classifyDeclaration(decl: BindingDecl, registry: ComponentRegistry, fileGraph: FileGraph): Classification;
|
|
31
32
|
export type SymbolKey = {
|
|
32
33
|
file: string;
|
|
33
34
|
symbol: string;
|
|
@@ -42,8 +43,10 @@ export type ClassifiedHelperIndex = HelperCallerIndex & {
|
|
|
42
43
|
* Three-phase build of the helper → component-callers reverse index plus
|
|
43
44
|
* per-decl classification cache.
|
|
44
45
|
*
|
|
45
|
-
* Phase 1 (collect) walks every module-scope `Function`-
|
|
46
|
-
* across the graph
|
|
46
|
+
* Phase 1 (collect) walks every module-scope `Function`- or
|
|
47
|
+
* `ReturnTypeOf`-valued BindingDecl across the graph (the latter is a
|
|
48
|
+
* factory's product, spec D13), collecting caller-side references from
|
|
49
|
+
* three sources:
|
|
47
50
|
*
|
|
48
51
|
* 1. `TypeOf` refs inside the decl's return-type expressions
|
|
49
52
|
* (`decl.value.returns`) — captures `() => helper()` shapes where the
|
|
@@ -61,7 +64,7 @@ export type ClassifiedHelperIndex = HelperCallerIndex & {
|
|
|
61
64
|
* (the dominant React call shape) never appear as called by anyone.
|
|
62
65
|
*
|
|
63
66
|
* Phase 2 (classify) runs structural classification on every module-scope
|
|
64
|
-
* Function decl, with a reclassification gate: a decl classified as
|
|
67
|
+
* Function- or ReturnTypeOf-valued decl, with a reclassification gate: a decl classified as
|
|
65
68
|
* `"component"` but consumed only as a value (never JSX) is reclassified
|
|
66
69
|
* as `"helper"`.
|
|
67
70
|
*
|
|
@@ -73,4 +76,16 @@ export type ClassifiedHelperIndex = HelperCallerIndex & {
|
|
|
73
76
|
* Cost: O(declarations × refs-per-declaration + jsx-usages). Cross-file
|
|
74
77
|
* resolution uses the existing module resolver — no new IO.
|
|
75
78
|
*/
|
|
76
|
-
export declare function buildHelperCallers(graph: Graph): ClassifiedHelperIndex;
|
|
79
|
+
export declare function buildHelperCallers(graph: Graph, registry: ComponentRegistry): ClassifiedHelperIndex;
|
|
80
|
+
/**
|
|
81
|
+
* Resolve a Reference to the BindingDecl it ultimately points at, crossing
|
|
82
|
+
* files via imports + the module resolver. Returns `{file, decl}` keyed by
|
|
83
|
+
* the target file (not the import-bearing file) so caller-set membership
|
|
84
|
+
* dedupes across multiple import paths.
|
|
85
|
+
*
|
|
86
|
+
* Returns null for unresolved or external refs.
|
|
87
|
+
*/
|
|
88
|
+
export declare function resolveRefToDecl(ref: Reference, callerFile: string, callerGraph: FileGraph, graph: Graph): {
|
|
89
|
+
file: string;
|
|
90
|
+
decl: BindingDecl;
|
|
91
|
+
} | null;
|