Skip to main content

fallow_types/
extract_member_facts.rs

1//! The member access facts, the fixture, binding and mock facts, and the
2//! `this` spread, dynamic custom element and misplaced directive facts that
3//! the extractor records for the analysis.
4
5/// A member name referenced from an Angular template surface.
6#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
7#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
8pub struct AngularTemplateMemberAccessFact {
9    /// Referenced class member name.
10    pub member: String,
11}
12
13/// A typed Angular component field that exposes array elements to templates.
14#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
15#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
16pub struct AngularComponentFieldArrayTypeFact {
17    /// Component field name used as the template iterable.
18    pub field: String,
19    /// Array element class name.
20    pub element_class: String,
21}
22
23/// Opaque Angular `{ ...this }` forwarding marker.
24#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
25#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
26pub struct AngularThisSpreadFact;
27
28/// A member access on a static factory call result.
29#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
30#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
31pub struct FactoryCallMemberAccessFact {
32    /// Local imported class or namespace object used as the factory callee.
33    pub callee_object: String,
34    /// Static factory method invoked on the callee object.
35    pub callee_method: String,
36    /// Member accessed on the returned instance-like object.
37    pub member: String,
38}
39
40/// A factory-returned value consumed opaquely, so every member of the class it
41/// returns must be treated as used.
42#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
43#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
44pub struct FactoryFnWholeObjectFact {
45    /// Local imported function used as the factory callee.
46    pub callee_name: String,
47}
48
49/// A member access reached through a property of a value returned by an imported
50/// factory that returns an object literal.
51///
52/// `const ui = createUi(); ui.orders.member` emits one fact per member read on a
53/// factory-result property. The analyze layer resolves `callee_name` through the
54/// consumer's imports to the factory's origin module, reads that module's
55/// `exported_factory_return_object_shapes` to find the property whose path equals
56/// `property_path` and its class local name, resolves THAT through the factory
57/// module's own imports to the class export, and credits `member` on the class
58/// (gated on the export actually being a class with members). See issue #1858.
59#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
60#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
61pub struct FactoryReturnObjectPropertyAccessFact {
62    /// Local imported function used as the factory callee.
63    pub callee_name: String,
64    /// Dotted property path between the factory-result local and the final member
65    /// (e.g. `"orders"` for `ui.orders.member`, `"invoke.orders"` for `ui.invoke.orders.member`).
66    pub property_path: String,
67    /// Member accessed on the terminal property's instance.
68    pub member: String,
69}
70
71/// A member access reached through a typed property hop that the extraction
72/// layer could not resolve locally.
73///
74/// `constructor(private opts: Opts) { ... this.opts.c.optM() }` where `Opts`
75/// is NOT declared in this file emits
76/// `TypedPropertyMemberAccessFact { type_name: "Opts", property_path: "c", member: "optM" }`.
77/// The analyze layer resolves `type_name` through the consumer's imports to the
78/// declaring module, walks `property_path` through that module's
79/// `type_member_types`, resolves the terminal type name through the declaring
80/// module's own imports, and credits `member` on the resolved class (gated on
81/// the export actually being a class with members). See issue #1785.
82#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
83#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
84pub struct TypedPropertyMemberAccessFact {
85    /// Local (usually imported) named-type symbol the receiver is typed by.
86    pub type_name: String,
87    /// Remaining dotted property segments between the typed binding and the
88    /// final member (e.g. `"c"` for `this.opts.c.optM()`).
89    pub property_path: String,
90    /// Member accessed on the terminal property's instance.
91    pub member: String,
92}
93
94/// A class member directly required by a named structural type.
95///
96/// Optional properties and methods are excluded: removing an optional
97/// implementation can preserve assignability, while removing a required one
98/// from an explicit `implements` contract cannot.
99#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
100#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
101pub struct RequiredTypeMemberFact {
102    /// Module-local interface or object-type alias name.
103    pub type_name: String,
104    /// Static required property or method name.
105    pub member: String,
106}
107
108/// A named interface that a module-local interface extends.
109///
110/// Analysis follows these edges to give an `implements` contract the required
111/// members of each parent interface, also across modules.
112#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
113#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
114pub struct InterfaceExtendsFact {
115    /// Module-local interface declaration name.
116    pub interface_name: String,
117    /// Module-local or imported name of the parent interface.
118    pub parent_name: String,
119}
120
121/// One direct contributor to a named type alias's receiver surface.
122///
123/// Nested property types are deliberately excluded: in
124/// `{ nested: Nested }`, `Alias.member` does not access `Nested.member`.
125#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
126#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
127pub struct TypeAliasSurfaceTargetFact {
128    /// Module-local alias declaration name.
129    pub alias_name: String,
130    /// Module-local or imported named type contributing the direct surface.
131    pub target_name: String,
132}
133
134/// A statically known string value of a TypeScript enum member.
135#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
136#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
137pub struct StringEnumMemberValueFact {
138    /// Module-local enum declaration name.
139    pub enum_name: String,
140    /// Static enum member name.
141    pub member_name: String,
142    /// Exact string initializer value.
143    pub value: String,
144}
145
146/// A computed property access whose key is a static enum member.
147#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
148#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
149pub struct ComputedEnumKeyUseFact {
150    /// Local enum object used as the key source.
151    pub key_object: String,
152    /// Static member selected from the enum object.
153    pub key_member: String,
154}
155
156/// A fluent chain rooted at a static factory call, one fact per chain. A step is
157/// used when the root method is a factory and each earlier step returns `this`.
158#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
159#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
160pub struct FluentChainMemberAccessFact {
161    /// Local imported class or namespace object used as the chain root.
162    pub root_object: String,
163    /// Static factory method that starts the fluent chain.
164    pub root_method: String,
165    /// The methods called after the root method, each once, in first-call order.
166    pub steps: Vec<String>,
167}
168
169/// A fluent chain rooted at a `new` expression, one fact per chain. A step is
170/// used when the first method and each earlier step return `this`.
171#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
172#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
173pub struct FluentChainNewMemberAccessFact {
174    /// Local imported class constructed by the `new` expression.
175    pub class_name: String,
176    /// The method called on the new instance.
177    pub first_method: String,
178    /// The methods called after the first method, each once, in first-call order.
179    pub steps: Vec<String>,
180}
181
182/// A member access on a Playwright fixture object inside a test callback.
183#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
184#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
185pub struct PlaywrightFixtureUseFact {
186    /// Local test function or wrapper used as the callback callee.
187    pub test_name: String,
188    /// Fixture name or dotted fixture path referenced in the callback.
189    pub fixture_name: String,
190    /// Member accessed on the fixture target.
191    pub member: String,
192}
193
194/// A Playwright fixture definition declared by a typed `test.extend<T>()`.
195#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
196#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
197pub struct PlaywrightFixtureDefinitionFact {
198    /// Local test function or wrapper receiving the fixture definition.
199    pub test_name: String,
200    /// Fixture name or dotted fixture path declared by the fixture type.
201    pub fixture_name: String,
202    /// Local type symbol used as the fixture target.
203    pub type_name: String,
204}
205
206/// A Playwright fixture definition from `<base>.extend<T>()` where `base` is
207/// an imported name. The extractor cannot prove that `base` holds a Playwright
208/// test, so analysis applies the definition only when `base` resolves to one.
209#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
210#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
211pub struct PlaywrightConditionalFixtureDefinitionFact {
212    /// Local test function or wrapper receiving the fixture definition.
213    pub test_name: String,
214    /// Imported local name that `.extend<T>()` is called on.
215    pub base_name: String,
216    /// Fixture name or dotted fixture path declared by the fixture type.
217    pub fixture_name: String,
218    /// Local type symbol used as the fixture target.
219    pub type_name: String,
220}
221
222/// A local name that holds a Playwright test: the result of an `.extend()` on
223/// the `@playwright/test` `test` import or of a `mergeTests(...)` call.
224#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
225#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
226pub struct PlaywrightTestBindingFact {
227    /// Local name of the Playwright test.
228    pub test_name: String,
229}
230
231/// A Playwright fixture wrapper alias declared by `mergeTests` or `.extend`.
232#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
233#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
234pub struct PlaywrightFixtureAliasFact {
235    /// Local test function or wrapper that inherits fixture definitions.
236    pub test_name: String,
237    /// Local test function or wrapper inherited by `test_name`.
238    pub base_name: String,
239}
240
241/// A nested Playwright fixture binding declared by a fixture type alias.
242#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
243#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
244pub struct PlaywrightFixtureTypeFact {
245    /// Local type alias containing the nested fixture binding.
246    pub alias_name: String,
247    /// Fixture name or dotted fixture path declared inside the type alias.
248    pub fixture_name: String,
249    /// Local type symbol used as the nested fixture target.
250    pub type_name: String,
251}
252
253/// An exported value whose runtime instance targets a local class or interface.
254#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
255#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
256pub struct InstanceExportBindingFact {
257    /// Exported binding name.
258    pub export_name: String,
259    /// Local class or interface symbol used as the instance target.
260    pub target_name: String,
261    /// The static method of `target_name` whose call result the export
262    /// holds (`export const sm = Cls.getInstance()`). `None` when the export
263    /// is a direct instance. The class can be imported, so the analyze layer
264    /// checks that the method returns an instance.
265    #[serde(default, skip_serializing_if = "Option::is_none")]
266    pub factory_method: Option<String>,
267}
268
269/// A property of an exported object whose value is an instance of a local class.
270#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
271#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
272pub struct ExportedObjectInstancePropertyFact {
273    /// Public export name of the containing object.
274    pub export_name: String,
275    /// Dotted path from the exported object to the instance property.
276    pub property_path: String,
277    /// Local class symbol instantiated at that property.
278    pub class_local_name: String,
279}
280
281/// A proven class member read through a namespace-qualified constructor or local subclass.
282#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
283#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
284pub struct QualifiedClassMemberAccessFact {
285    /// Local namespace-import binding.
286    pub namespace_local: String,
287    /// Class export selected from that namespace.
288    pub class_export_name: String,
289    /// Member accessed through the proven class or instance binding.
290    pub member: String,
291}
292
293/// Opaque marker for a dynamic custom-element render site.
294#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
295#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
296pub struct DynamicCustomElementRenderFact;
297
298/// The action performed by a Vitest module-mock operation.
299#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
300#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
301#[serde(rename_all = "snake_case")]
302pub enum VitestModuleMockAction {
303    /// Register a mock. `factory_replaces_original` is true only when the
304    /// factory is structurally closed and cannot load the original module.
305    ///
306    /// Automock (`vi.mock` / `jest.mock` without a factory) is always
307    /// `factory_replaces_original: false` by decision (issue #2082). For
308    /// Vitest, the runner derives the mocked shape by importing the original
309    /// module, so its top-level code executes at collection time, and
310    /// file-level masking cannot express "module evaluated but exports
311    /// stubbed". For Jest, a `__mocks__` sibling takes precedence and the
312    /// original is genuinely not required, but the manual mock itself may
313    /// load the original (`jest.requireActual`), and proving it never does
314    /// would need a cross-file factory proof. Both runners therefore keep
315    /// coverage credit for the automock form.
316    Mock {
317        /// Whether the factory provably replaces the original module.
318        factory_replaces_original: bool,
319    },
320    /// Remove a registered mock and restore the original module.
321    Unmock,
322}
323
324impl VitestModuleMockAction {
325    /// Whether this operation registers a proven complete replacement.
326    #[must_use]
327    pub const fn replaces_original(self) -> bool {
328        matches!(
329            self,
330            Self::Mock {
331                factory_replaces_original: true
332            }
333        )
334    }
335}
336
337/// Ordered Vitest module-mock operation with a static source target.
338///
339/// The declaring [`ModuleInfo::file_id`](crate::extract::ModuleInfo::file_id) owns the test-root provenance. The
340/// resolver consumes `source` through its canonical specifier pipeline; this
341/// fact deliberately carries no resolved path or duplicate diagnostic span.
342#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
343#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
344pub struct VitestModuleMockOperationFact {
345    /// Static module specifier passed to `vi.mock` or `vi.unmock`.
346    pub source: String,
347    /// Source-order position of the call within the declaring module.
348    pub call_start: u32,
349    /// Typed mock or unmock action.
350    pub action: VitestModuleMockAction,
351}
352
353/// A `this`-rooted member access with exact enclosing-class provenance.
354#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
355#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
356pub struct ClassThisMemberAccessFact {
357    /// Enclosing class local name, or `default` for an anonymous default class.
358    pub class_local_name: String,
359    /// Dotted receiver spelling beginning with `this.`.
360    pub object: String,
361    /// Terminal member being accessed.
362    pub member: String,
363}
364
365/// A whole-object use of a `this`-rooted chain with enclosing-class provenance.
366#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, bitcode::Encode, bitcode::Decode)]
367#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
368pub struct ClassThisWholeObjectUseFact {
369    /// Enclosing class local name, or `default` for an anonymous default class.
370    pub class_local_name: String,
371    /// Dotted receiver spelling beginning with `this.`.
372    pub object: String,
373}
374
375/// A `"use client"` / `"use server"` directive string written as an expression
376/// statement in `program.body` (NOT the leading prologue), so the RSC bundler
377/// silently ignores it. One entry per offending occurrence. Consumed by the
378/// `misplaced-directive` detector.
379#[derive(Debug, Clone, PartialEq, Eq, bitcode::Encode, bitcode::Decode)]
380pub struct MisplacedDirectiveSite {
381    /// `true` for `"use server"`, `false` for `"use client"`.
382    pub is_server: bool,
383    /// Start byte offset of the misplaced directive statement.
384    pub span_start: u32,
385}