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