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