Skip to main content

fallow_extract/cache/
types.rs

1//! Serialization types for the incremental parse cache.
2//!
3//! All types use bitcode `Encode`/`Decode` for fast binary serialization.
4
5use bitcode::{Decode, Encode};
6
7use crate::MemberKind;
8
9/// Cache version. Bump it when the serialized cache shape or the cached
10/// extraction semantics change, and give the reason in the commit message and
11/// the CHANGELOG. A stale version serves old extraction results from a warm
12/// cache. The `assert_cached_type_size!` guards below catch shape changes.
13pub(super) const CACHE_VERSION: u32 = 334;
14
15/// Duplication token cache version. Bump it when duplicate tokenization,
16/// normalization, or the on-disk token cache schema changes, and give the
17/// reason in the commit message and the CHANGELOG.
18pub const DUPES_CACHE_VERSION: u32 = 14;
19
20/// Default maximum cache size (256 MB). Overridable per-project via
21/// `cache.maxSizeMb` in the config file or `FALLOW_CACHE_MAX_SIZE` env var.
22/// Also used as the hard ceiling on load-time deserialization as a defence
23/// against pathological on-disk files.
24pub const DEFAULT_CACHE_MAX_SIZE: usize = 256 * 1024 * 1024;
25
26/// Trigger LRU eviction when the serialized cache exceeds 80% of the cap.
27/// Basis points (1/100 of a percent) for integer arithmetic without floats.
28pub(super) const EVICTION_TRIGGER_BPS: usize = 8000;
29
30/// Evict down to 60% of the cap so subsequent saves leave headroom.
31pub(super) const EVICTION_TARGET_BPS: usize = 6000;
32
33/// Promote the eviction log from `debug!` to `info!` when at least 25% of
34/// entries are removed in a single save. Default-noise concerns mean
35/// small-turnover saves should not be visible without `RUST_LOG=debug`.
36pub(super) const EVICTION_SIGNIFICANT_BPS: usize = 2500;
37
38/// Import kind discriminant for `CachedImport`:
39/// 0 = Named, 1 = Default, 2 = Namespace, 3 = `SideEffect`.
40pub(super) const IMPORT_KIND_NAMED: u8 = 0;
41pub(super) const IMPORT_KIND_DEFAULT: u8 = 1;
42pub(super) const IMPORT_KIND_NAMESPACE: u8 = 2;
43pub(super) const IMPORT_KIND_SIDE_EFFECT: u8 = 3;
44
45macro_rules! assert_cached_type_size {
46    ($ty:ty, $size:expr) => {
47        const _: () = assert!(
48            std::mem::size_of::<$ty>() == $size,
49            concat!(
50                stringify!($ty),
51                " size changed; bump CACHE_VERSION if the cached wire shape or extraction semantics changed, then update this assertion"
52            )
53        );
54    };
55}
56
57assert_cached_type_size!(CachedModule, 1472);
58assert_cached_type_size!(CachedNamespaceObjectAlias, 72);
59assert_cached_type_size!(CachedLocalTypeDeclaration, 32);
60assert_cached_type_size!(CachedPublicSignatureTypeReference, 64);
61assert_cached_type_size!(CachedSuppression, 88);
62assert_cached_type_size!(CachedUnknownSuppressionKind, 56);
63assert_cached_type_size!(CachedExport, 152);
64assert_cached_type_size!(CachedImport, 96);
65assert_cached_type_size!(CachedDynamicImport, 88);
66assert_cached_type_size!(CachedRequireCall, 96);
67assert_cached_type_size!(CachedReExport, 104);
68assert_cached_type_size!(CachedMember, 64);
69assert_cached_type_size!(CachedDynamicImportPattern, 64);
70assert_cached_type_size!(crate::MemberAccess, 48);
71assert_cached_type_size!(fallow_types::extract::SemanticFact, 96);
72assert_cached_type_size!(fallow_types::extract::CalleeUse, 32);
73assert_cached_type_size!(fallow_types::extract::ImportedCallSite, 80);
74assert_cached_type_size!(fallow_types::extract::MisplacedDirectiveSite, 8);
75assert_cached_type_size!(fallow_types::extract::SinkSite, 216);
76assert_cached_type_size!(fallow_types::extract::FunctionComplexity, 96);
77assert_cached_type_size!(fallow_types::extract::ComplexityContribution, 16);
78assert_cached_type_size!(fallow_types::extract::FlagUse, 80);
79assert_cached_type_size!(fallow_types::extract::ClassHeritageInfo, 168);
80assert_cached_type_size!(fallow_types::extract::FactoryReturnExport, 56);
81assert_cached_type_size!(fallow_types::extract::TypeMemberTypeEntry, 72);
82assert_cached_type_size!(fallow_types::extract::LoadReturnKey, 32);
83
84/// Cached data for a single module.
85#[derive(Debug, Clone, Encode, Decode)]
86pub struct CachedModule {
87    /// xxh3 hash of the file content.
88    pub content_hash: u64,
89    /// File modification time in nanoseconds for fast cache validation.
90    /// When mtime+ctime+size match the on-disk file, we skip reading file
91    /// content entirely.
92    pub mtime_ns: u64,
93    /// File inode change time in nanoseconds, or `0` on platforms that do not
94    /// report one. Stored beside `mtime_ns` because mtime is writer-controlled:
95    /// a same-length rewrite with a restored mtime is invisible to
96    /// `(mtime, size)` alone, and the metadata-only fast path would then hand
97    /// back analysis of the previous content.
98    pub ctime_ns: u64,
99    /// File size in bytes for fast cache validation.
100    pub file_size: u64,
101    /// Seconds-since-epoch at the time this entry was last WRITTEN
102    /// (first parse or content-change refresh). NOT updated on cache-hit
103    /// reads: `update_cache` already iterates every in-scope file every run,
104    /// so refreshing on read would collapse the LRU to "last run this file
105    /// was discovered" for every retained entry. With write-only refresh,
106    /// the LRU genuinely targets stale (in-scope-but-unchanged-for-many-runs)
107    /// entries. Used by `CacheStore::save` for write-time eviction ordering.
108    pub last_access_secs: u64,
109    /// Exported symbols.
110    pub exports: Vec<CachedExport>,
111    /// Import specifiers.
112    pub imports: Vec<CachedImport>,
113    /// Re-export specifiers.
114    pub re_exports: Vec<CachedReExport>,
115    /// Dynamic import specifiers.
116    pub dynamic_imports: Vec<CachedDynamicImport>,
117    /// `require()` specifiers.
118    pub require_calls: Vec<CachedRequireCall>,
119    /// Package names statically referenced through package path resolution.
120    pub package_path_references: Box<[String]>,
121    /// Package names that a module augmentation (`declare module 'pkg'` in a
122    /// module file) names. They credit the package as a type-only use.
123    pub type_package_references: Box<[String]>,
124    /// Binary names found in `node_modules/.bin/<name>` paths in string
125    /// literals and template quasis. The analysis maps each name to the
126    /// package that declares the binary.
127    pub bin_path_references: Box<[String]>,
128    /// Package names from direct `require.resolve` calls, with call offsets.
129    pub package_resolve_sites: Box<[(String, u32)]>,
130    /// Static member accesses (e.g., `Status.Active`).
131    pub member_accesses: Vec<crate::MemberAccess>,
132    /// Typed semantic facts produced by extraction for cross-layer analysis.
133    /// `None` means no facts, which keeps the common warm-cache payload lean.
134    pub semantic_facts: Option<Box<[fallow_types::extract::SemanticFact]>>,
135    /// Identifiers used as whole objects (Object.values, for..in, spread, etc.).
136    pub whole_object_uses: Box<[String]>,
137    /// Dynamic import patterns with partial static resolution.
138    pub dynamic_import_patterns: Vec<CachedDynamicImportPattern>,
139    /// Number of parser diagnostics the parse of this file produced.
140    /// Round-trips so a warm load still reports `source-parse-degraded`
141    /// instead of silently inheriting a partial parse.
142    pub parse_error_count: u32,
143    /// Whether the parser abandoned this file instead of recovering.
144    pub parse_panicked: bool,
145    /// Whether this module uses CJS exports.
146    pub has_cjs_exports: bool,
147    /// Whether this module declares at least one Angular `@Component({
148    /// templateUrl: ... })` decorator. Mirrors `ModuleInfo.has_angular_component_template_url`
149    /// so the CRAP-inherit walker's gate survives a warm-cache load.
150    pub has_angular_component_template_url: bool,
151    /// Local names of import bindings that are never referenced in this file.
152    pub unused_import_bindings: Vec<String>,
153    /// Local import bindings referenced from type positions.
154    pub type_referenced_import_bindings: Vec<String>,
155    /// Local import bindings referenced from value positions.
156    pub value_referenced_import_bindings: Vec<String>,
157    /// Inline suppression directives.
158    pub suppressions: Vec<CachedSuppression>,
159    /// Suppression tokens that did not parse to any known `IssueKind`. See #449.
160    pub unknown_suppression_kinds: Vec<CachedUnknownSuppressionKind>,
161    /// Pre-computed line-start byte offsets for O(log N) byte-to-line/col conversion.
162    pub line_offsets: Vec<u32>,
163    /// Per-function complexity metrics.
164    pub complexity: Vec<fallow_types::extract::FunctionComplexity>,
165    /// Whether the run that wrote this entry actually extracted complexity.
166    ///
167    /// An empty `complexity` vector is ambiguous on its own: a `dead-code` run
168    /// passes `need_complexity == false` and produces one, and so does a file
169    /// with no functions at all. Reading emptiness as "not cached" made every
170    /// later `health` run pay a full cold parse for a file that was already
171    /// analyzed. This flag is the honest answer, so a complexity consumer can
172    /// hit on a rich entry and a complexity-blind run can refuse to downgrade
173    /// one.
174    pub complexity_extracted: bool,
175    /// Feature flag use sites.
176    pub flag_uses: Vec<fallow_types::extract::FlagUse>,
177    /// Flag-key registries and registry reads.
178    pub flag_registry_facts: Option<Box<fallow_types::extract::FlagRegistryFacts>>,
179    /// Heritage metadata for exported classes.
180    pub class_heritage: Vec<fallow_types::extract::ClassHeritageInfo>,
181    /// Exported free-function factories that provably return one class instance
182    /// (`export function useApi() { return new RESTApi() }`). Compacted to `None`
183    /// when empty so the common no-factory module pays no payload. See #1441 Part A.
184    pub exported_factory_returns: Option<Box<[fallow_types::extract::FactoryReturnExport]>>,
185    /// Object-literal factory-return shapes (`export function createUi() {
186    /// return { orders: factory.ordersPage } }`). Compacted to `None` when empty
187    /// so the common no-object-factory module pays no payload. See issue #1858.
188    pub exported_factory_return_object_shapes:
189        Option<Box<[fallow_types::extract::FactoryReturnObjectShapeExport]>>,
190    /// Named-type property types declared by top-level interfaces and
191    /// type-literal aliases (`interface Opts { c: OptDep }`). Compacted to
192    /// `None` when empty so the common no-interface module pays no payload.
193    /// See issue #1785.
194    pub type_member_types: Option<Box<[fallow_types::extract::TypeMemberTypeEntry]>>,
195    /// Angular `InjectionToken<Interface>` `(token, interface)` pairs (#920).
196    pub injection_tokens: Vec<(String, String)>,
197    /// Local type-capable declarations.
198    pub local_type_declarations: Vec<CachedLocalTypeDeclaration>,
199    /// Type references from exported public signatures.
200    pub public_signature_type_references: Vec<CachedPublicSignatureTypeReference>,
201    /// Namespace-import aliases re-exported through an object literal
202    /// (`export const API = { foo }` where `foo` is `import * as foo from './bar'`).
203    pub namespace_object_aliases: Vec<CachedNamespaceObjectAlias>,
204    /// Iconify collection prefixes found in static icon props (issue #608).
205    pub iconify_prefixes: Vec<String>,
206    /// Nuxt UI icon class suffixes found in static script-side icon properties
207    /// (issue #955).
208    pub iconify_icon_names: Vec<String>,
209    /// Bare identifier names that are candidates for convention auto-import
210    /// resolution (issue #704). Content-local, so they round-trip through the
211    /// cache; resolution against the plugin table happens at graph-build time.
212    pub auto_import_candidates: Vec<String>,
213    /// File-level string directives (`"use client"`, `"use server"`). Content-local,
214    /// round-trips through the cache so the security `client-server-leak` detector
215    /// sees directives on warm-cache loads.
216    pub directives: Vec<String>,
217    /// Byte-offset starts of `next/dynamic(..., { ssr: false })` dynamic imports.
218    /// Content-local, round-trips so the security `client-server-leak` BFS sees
219    /// the ssr:false client-only escape hatch on warm-cache loads.
220    pub client_only_dynamic_import_spans: Vec<u32>,
221    /// Captured security sink sites (category-blind). Round-trips through the
222    /// cache so the catalogue-driven `tainted_sink` detector sees sinks on
223    /// warm-cache loads.
224    pub security_sinks: Vec<fallow_types::extract::SinkSite>,
225    /// Count of sink-shaped nodes whose callee could not be flattened to a
226    /// static path. Round-trips so the in-band blind-spot count is stable.
227    pub security_sinks_skipped: u32,
228    /// Span-level diagnostics for skipped security sink callees.
229    pub security_unresolved_callee_sites: Vec<fallow_types::extract::SkippedSecurityCalleeSite>,
230    /// Local bindings tied to the member-access path they were sourced from.
231    /// Round-trips so the security `tainted_sink` source-to-sink association
232    /// sees source-tainted bindings on warm-cache loads.
233    pub tainted_bindings: Vec<fallow_types::extract::TaintedBinding>,
234    /// Direct sink arguments recognized as sanitizer calls.
235    pub sanitized_sink_args: Vec<fallow_types::extract::SanitizedSinkArg>,
236    /// Defensive control call sites for security surface output.
237    pub security_control_sites: Vec<fallow_types::extract::SecurityControlSite>,
238    /// Deduped statically flattenable callee paths. Round-trips so the
239    /// `boundaries.calls.forbidden` detector sees call sites on warm-cache
240    /// loads.
241    pub callee_uses: Vec<fallow_types::extract::CalleeUse>,
242    /// Scope-resolved imported calls, preserving each occurrence and argument.
243    pub imported_call_sites: Vec<fallow_types::extract::ImportedCallSite>,
244    /// Misplaced `"use client"` / `"use server"` directive sites.
245    /// Round-trips so the `misplaced-directive` detector sees them on
246    /// warm-cache loads.
247    pub misplaced_directives: Vec<fallow_types::extract::MisplacedDirectiveSite>,
248    /// Export local names of inline `"use server"` body Server Actions.
249    /// Round-trips so the `unused-server-action` reclassifier sees them on
250    /// warm-cache loads.
251    pub inline_server_action_exports: Vec<String>,
252    /// Vue `provide`/`inject` and Svelte `setContext`/`getContext` key sites.
253    /// Round-trips so the `unprovided-inject` detector sees them on warm-cache
254    /// loads.
255    pub di_key_sites: Vec<fallow_types::extract::DiKeySite>,
256    /// Whether the module had an unknowable-key provide. Round-trips so the
257    /// `unprovided-inject` project-wide abstain holds on warm-cache loads.
258    pub has_dynamic_provide: bool,
259    /// All-action `"use server"` module flag. Round-trips so the security
260    /// `client-server-leak` BFS sees the action boundary on warm-cache loads.
261    pub is_server_action_module: bool,
262    /// Global-scope declaration flag. Mirrors `ModuleInfo.has_global_declarations`.
263    pub has_global_declarations: bool,
264    /// `/// <reference path>` values. Mirrors `ModuleInfo.triple_slash_reference_paths`.
265    pub triple_slash_reference_paths: Box<[String]>,
266    /// Vue `<script setup>` `defineProps` and Svelte 5 `$props()` declared props.
267    /// Round-trips so the `unused-component-prop` detector sees them on
268    /// warm-cache loads.
269    pub component_props: Vec<fallow_types::extract::ComponentProp>,
270    /// Framework-neutral input contracts and inspected caller evidence.
271    pub component_contracts: Option<Box<fallow_types::extract::ComponentContractFacts>>,
272    /// Whether the template spreads `$attrs`/`$props`/`props` or the
273    /// `defineProps` return is rest-destructured. Round-trips for the abstain.
274    pub has_props_attrs_fallthrough: bool,
275    /// Whether the SFC calls `defineExpose(...)`. Round-trips for the abstain.
276    pub has_define_expose: bool,
277    /// Whether the SFC calls `defineModel(...)`. Round-trips for the abstain.
278    pub has_define_model: bool,
279    /// Whether `defineProps` had an unharvestable type-reference argument.
280    /// Round-trips for the abstain.
281    pub has_unharvestable_props: bool,
282    /// Vue `<script setup>` `defineEmits` declared events. Round-trips so the
283    /// `unused-component-emit` detector sees them on warm-cache loads.
284    pub component_emits: Vec<fallow_types::extract::ComponentEmit>,
285    /// Angular component/directive inputs (`@Input()` decorators and signal
286    /// `input()` / `model()` initializers). Round-trips so the
287    /// `unused-component-input` detector sees them on warm-cache loads.
288    pub angular_inputs: Vec<fallow_types::extract::AngularInputMember>,
289    /// Angular component/directive outputs (`@Output()` decorators and signal
290    /// `output()` / `outputFromObservable()` initializers). Round-trips so the
291    /// `unused-component-output` detector sees them on warm-cache loads.
292    pub angular_outputs: Vec<fallow_types::extract::AngularOutputMember>,
293    /// Angular `@Component` declarations with their `selector` value(s).
294    /// Round-trips so the Angular `unrendered-component` arm sees them on
295    /// warm-cache loads.
296    pub angular_component_selectors: Vec<fallow_types::extract::AngularComponentSelector>,
297    /// Lit / web-component custom elements registered in this file. Round-trips so
298    /// the Lit `unrendered-component` arm sees them on warm-cache loads.
299    pub registered_custom_elements: Vec<fallow_types::extract::RegisteredCustomElement>,
300    /// Custom-element tag names used (rendered) in this file's `html` templates.
301    /// Round-trips for the Lit `unrendered-component` rendered-tag union.
302    pub used_custom_element_tags: Vec<String>,
303    /// Custom element selector tags referenced in this file's Angular templates.
304    /// Round-trips for the Angular `unrendered-component` used-selector union.
305    pub angular_used_selectors: Vec<String>,
306    /// Angular route / bootstrap component class references. Round-trips for the
307    /// Angular `unrendered-component` entry-point abstain.
308    pub angular_entry_component_refs: Vec<String>,
309    /// Whether this file dynamically renders a component (project-wide abstain
310    /// signal for the Angular `unrendered-component` detector). Round-trips.
311    pub has_dynamic_component_render: bool,
312    /// Whether `defineEmits` had an unharvestable argument. Round-trips for the
313    /// abstain.
314    pub has_unharvestable_emits: bool,
315    /// Whether an `emit(<nonLiteral>)` call was seen. Round-trips for the abstain.
316    pub has_dynamic_emit: bool,
317    /// Whether the emit binding was used as a whole value. Round-trips for the
318    /// abstain.
319    pub has_emit_whole_object_use: bool,
320    /// SvelteKit `load()` return-object keys. Round-trips so the
321    /// `unused-load-data-key` detector sees them on warm-cache loads.
322    pub load_return_keys: Vec<fallow_types::extract::LoadReturnKey>,
323    /// Whether this file's `load()` body could not be harvested safely.
324    /// Round-trips for the abstain.
325    pub has_unharvestable_load: bool,
326    /// Whether this file passes the whole `data` object opaquely. Round-trips
327    /// for the `unused-load-data-key` abstain.
328    pub has_load_data_whole_use: bool,
329    /// React/JSX component definitions. Round-trips so the React-health phases
330    /// see them on warm-cache loads.
331    pub component_functions: Vec<fallow_types::extract::ComponentFunction>,
332    /// React component props. Round-trips so the React `unused-component-prop`
333    /// arm sees them on warm-cache loads.
334    pub react_props: Vec<fallow_types::extract::ComponentProp>,
335    /// React hook call sites. Round-trips for the complexity-fold phase.
336    pub hook_uses: Vec<fallow_types::extract::HookUse>,
337    /// React render edges (child name captured; resolution deferred to graph
338    /// build). Round-trips so the render graph survives a warm cache.
339    pub render_edges: Vec<fallow_types::extract::RenderEdge>,
340    /// Svelte custom events dispatched via `dispatch('<name>')`. Round-trips so
341    /// the `unused-svelte-event` detector sees them on warm-cache loads.
342    pub svelte_dispatched_events: Vec<fallow_types::extract::DispatchedEvent>,
343    /// Svelte template `on:<name>` listener names on component tags. Round-trips
344    /// so the project-wide listened set is correct on warm-cache loads.
345    pub svelte_listened_events: Vec<String>,
346    /// Whether a `dispatch(<nonLiteral>)` call or whole-`dispatch`-value use was
347    /// seen. Round-trips for the `unused-svelte-event` abstain.
348    pub has_dynamic_dispatch: bool,
349}
350
351impl CachedModule {
352    /// Source metadata fingerprint stored with this cache entry.
353    ///
354    #[must_use]
355    pub fn source_fingerprint(&self) -> fallow_types::source_fingerprint::SourceFingerprint {
356        fallow_types::source_fingerprint::SourceFingerprint::with_ctime(
357            self.mtime_ns,
358            self.ctime_ns,
359            self.file_size,
360        )
361    }
362}
363
364/// Cached namespace-object alias.
365#[derive(Debug, Clone, Encode, Decode)]
366pub struct CachedNamespaceObjectAlias {
367    /// Canonical export name on this module.
368    pub via_export_name: String,
369    /// Dotted suffix of the property path relative to the export.
370    pub suffix: String,
371    /// Local name of the namespace import on this module.
372    pub namespace_local: String,
373}
374
375/// Cached local type declaration.
376#[derive(Debug, Clone, Encode, Decode)]
377pub struct CachedLocalTypeDeclaration {
378    /// Local declaration name.
379    pub name: String,
380    /// Byte offset of the declaration span start.
381    pub span_start: u32,
382    /// Byte offset of the declaration span end.
383    pub span_end: u32,
384}
385
386/// Cached public signature type reference.
387#[derive(Debug, Clone, Encode, Decode)]
388pub struct CachedPublicSignatureTypeReference {
389    /// Exported symbol whose signature contains the reference.
390    pub export_name: String,
391    /// Referenced type name.
392    pub type_name: String,
393    /// Byte offset of the reference span start.
394    pub span_start: u32,
395    /// Byte offset of the reference span end.
396    pub span_end: u32,
397    /// True when the reference comes from a `satisfies` clause.
398    pub from_satisfies: bool,
399}
400
401/// Cached suppression directive.
402#[derive(Debug, Clone, Encode, Decode)]
403pub struct CachedSuppression {
404    /// 1-based line this suppression applies to. 0 = file-wide.
405    pub(crate) line: u32,
406    /// 1-based line where the comment itself appears.
407    pub(crate) comment_line: u32,
408    /// 0 = suppress all, otherwise `IssueKind` discriminant.
409    pub(crate) kind: u8,
410    /// Rule-pack name for scoped policy suppressions. Empty for all other
411    /// suppression targets.
412    pub(crate) policy_pack: String,
413    /// Rule id for scoped policy suppressions. Empty for all other suppression
414    /// targets.
415    pub(crate) policy_rule_id: String,
416    /// Human-authored reason after `--`, when present.
417    pub(crate) reason: Option<String>,
418}
419
420/// Cached unknown suppression kind token (see #449).
421#[derive(Debug, Clone, Encode, Decode)]
422pub struct CachedUnknownSuppressionKind {
423    /// 1-based line where the comment itself appears.
424    pub comment_line: u32,
425    /// True when the marker was `fallow-ignore-file`.
426    pub is_file_level: bool,
427    /// The verbatim token that did not parse.
428    pub token: String,
429    /// Human-authored reason after `--`, when present.
430    pub reason: Option<String>,
431}
432
433/// Cached export data for a single export declaration.
434#[derive(Debug, Clone, Encode, Decode)]
435pub struct CachedExport {
436    /// Export name (or "default" for default exports).
437    pub(crate) name: String,
438    /// Whether this is a default export.
439    pub(crate) is_default: bool,
440    /// Whether this is a type-only export.
441    pub(crate) is_type_only: bool,
442    /// Whether this export is registered through a runtime side effect at
443    /// module load time (Lit `@customElement` decorator or
444    /// `customElements.define` call). Persisted so warm-cache runs continue
445    /// to skip unused-export reporting for these classes.
446    pub(crate) is_side_effect_used: bool,
447    /// Visibility tag discriminant (0=None, 1=Public, 2=Internal, 3=Beta, 4=Alpha).
448    pub(crate) visibility: u8,
449    /// Human-authored reason on `@expected-unused -- <reason>`, when present.
450    pub(crate) expected_unused_reason: Option<String>,
451    /// Whether the leading JSDoc carries a `@deprecated` tag.
452    pub(crate) deprecated: bool,
453    /// Plain-text `@deprecated` message, `None` for a bare tag.
454    pub(crate) deprecated_reason: Option<Box<str>>,
455    /// The local binding name, if different.
456    pub(crate) local_name: Option<String>,
457    /// Byte offset of the export span start.
458    pub(crate) span_start: u32,
459    /// Byte offset of the export span end.
460    pub(crate) span_end: u32,
461    /// Members of this export (for enums and classes).
462    pub(crate) members: Vec<CachedMember>,
463    /// The local name of the parent class from `extends` clause, if any.
464    pub(crate) super_class: Option<String>,
465}
466
467/// Cached import data for a single import declaration.
468#[derive(Debug, Clone, Encode, Decode)]
469pub struct CachedImport {
470    /// The import specifier.
471    pub(crate) source: String,
472    /// For Named imports, the imported symbol name. Empty for other kinds.
473    pub(crate) imported_name: String,
474    /// The local binding name.
475    pub(crate) local_name: String,
476    /// Whether this is a type-only import.
477    pub(crate) is_type_only: bool,
478    /// Whether this whole-module import forwards type meanings only
479    /// (`export type *` inside a `declare module '...'` body).
480    pub(crate) is_type_only_star: bool,
481    /// Whether this import originated from an SFC `<style>` block / `<style src>` (CSS context).
482    pub(crate) from_style: bool,
483    /// Import kind: 0=Named, 1=Default, 2=Namespace, 3=SideEffect.
484    pub(crate) kind: u8,
485    /// Byte offset of the import span start.
486    pub(crate) span_start: u32,
487    /// Byte offset of the import span end.
488    pub(crate) span_end: u32,
489    /// Byte offset of the source string literal span start.
490    pub(crate) source_span_start: u32,
491    /// Byte offset of the source string literal span end.
492    pub(crate) source_span_end: u32,
493}
494
495/// Cached dynamic import data.
496#[derive(Debug, Clone, Encode, Decode)]
497pub struct CachedDynamicImport {
498    /// The import specifier.
499    pub(crate) source: String,
500    /// Byte offset of the span start.
501    pub(crate) span_start: u32,
502    /// Byte offset of the span end.
503    pub(crate) span_end: u32,
504    /// Names destructured from the import result.
505    pub(crate) destructured_names: Vec<String>,
506    /// Local variable name for namespace imports.
507    pub(crate) local_name: Option<String>,
508    /// True when this dynamic import was synthesised by fallow (see
509    /// `DynamicImportInfo::is_speculative`).
510    pub(crate) is_speculative: bool,
511}
512
513/// Cached `require()` call data.
514#[derive(Debug, Clone, Encode, Decode)]
515pub struct CachedRequireCall {
516    /// The require specifier.
517    pub(crate) source: String,
518    /// Byte offset of the span start.
519    pub(crate) span_start: u32,
520    /// Byte offset of the span end.
521    pub(crate) span_end: u32,
522    /// Byte offset of the specifier string-literal span start.
523    pub(crate) source_span_start: u32,
524    /// Byte offset of the specifier string-literal span end.
525    pub(crate) source_span_end: u32,
526    /// Names destructured from the require result.
527    pub(crate) destructured_names: Vec<String>,
528    /// Local variable name for namespace requires.
529    pub(crate) local_name: Option<String>,
530    /// `true` for the type-erased `import type X = require('...')` spelling.
531    pub(crate) is_type_only: bool,
532}
533
534/// Cached re-export data.
535#[derive(Debug, Clone, Encode, Decode)]
536pub struct CachedReExport {
537    /// The module being re-exported from.
538    pub(crate) source: String,
539    /// Name imported from the source.
540    pub(crate) imported_name: String,
541    /// Name exported from this module.
542    pub(crate) exported_name: String,
543    /// Whether this is a type-only re-export.
544    pub(crate) is_type_only: bool,
545    /// Byte offset of the re-export span start (for line-number reporting).
546    pub(crate) span_start: u32,
547    /// Byte offset of the re-export span end.
548    pub(crate) span_end: u32,
549    /// Byte offset of the enclosing statement span start.
550    pub(crate) statement_span_start: u32,
551    /// Byte offset of the enclosing statement span end.
552    pub(crate) statement_span_end: u32,
553    /// Byte offset of the source string-literal span start.
554    pub(crate) source_span_start: u32,
555    /// Byte offset of the source string-literal span end.
556    pub(crate) source_span_end: u32,
557}
558
559/// Cached enum or class member data.
560#[derive(Debug, Clone, Encode, Decode)]
561pub struct CachedMember {
562    /// Member name.
563    pub(crate) name: String,
564    /// Member kind (enum, method, or property).
565    pub(crate) kind: MemberKind,
566    /// Byte offset of the span start.
567    pub(crate) span_start: u32,
568    /// Byte offset of the span end.
569    pub(crate) span_end: u32,
570    /// Whether this member has decorators.
571    pub(crate) has_decorator: bool,
572    /// Full dotted path of each decorator (e.g. `step`, `ns.foo`).
573    /// Empty for undecorated members and decorators with non-identifier
574    /// expressions.
575    pub(crate) decorator_names: Vec<String>,
576    /// True when this is a static method that returns a fresh instance of
577    /// the class: body returns `new this()` / `new <SameClassName>()`, or the
578    /// declared return type matches the class name. Treated as a factory.
579    /// See issues #346, #387.
580    pub(crate) is_instance_returning_static: bool,
581    /// True when this instance method's call result is an instance of the
582    /// same class (declared return type matches the class name, or body's
583    /// last statement is `return this`). Drives fluent-chain credit. See
584    /// issue #387.
585    pub(crate) is_self_returning: bool,
586}
587
588/// Cached dynamic import pattern data (template literals, `import.meta.glob`).
589#[derive(Debug, Clone, Encode, Decode)]
590pub struct CachedDynamicImportPattern {
591    /// Static prefix of the import path.
592    pub(crate) prefix: String,
593    /// Static suffix, if any.
594    pub(crate) suffix: Option<String>,
595    /// Byte offset of the span start.
596    pub(crate) span_start: u32,
597    /// Byte offset of the span end.
598    pub(crate) span_end: u32,
599    /// Runtime mechanism used to load modules matching this pattern.
600    pub(crate) mechanism: crate::ModuleLoadMechanism,
601}