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 = 309;
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, 1368);
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 /// Flag-key registries and registry reads.
168 pub flag_registry_facts: Option<Box<fallow_types::extract::FlagRegistryFacts>>,
169 /// Heritage metadata for exported classes.
170 pub class_heritage: Vec<fallow_types::extract::ClassHeritageInfo>,
171 /// Exported free-function factories that provably return one class instance
172 /// (`export function useApi() { return new RESTApi() }`). Compacted to `None`
173 /// when empty so the common no-factory module pays no payload. See #1441 Part A.
174 pub exported_factory_returns: Option<Box<[fallow_types::extract::FactoryReturnExport]>>,
175 /// Object-literal factory-return shapes (`export function createUi() {
176 /// return { orders: factory.ordersPage } }`). Compacted to `None` when empty
177 /// so the common no-object-factory module pays no payload. See issue #1858.
178 pub exported_factory_return_object_shapes:
179 Option<Box<[fallow_types::extract::FactoryReturnObjectShapeExport]>>,
180 /// Named-type property types declared by top-level interfaces and
181 /// type-literal aliases (`interface Opts { c: OptDep }`). Compacted to
182 /// `None` when empty so the common no-interface module pays no payload.
183 /// See issue #1785.
184 pub type_member_types: Option<Box<[fallow_types::extract::TypeMemberTypeEntry]>>,
185 /// Angular `InjectionToken<Interface>` `(token, interface)` pairs (#920).
186 pub injection_tokens: Vec<(String, String)>,
187 /// Local type-capable declarations.
188 pub local_type_declarations: Vec<CachedLocalTypeDeclaration>,
189 /// Type references from exported public signatures.
190 pub public_signature_type_references: Vec<CachedPublicSignatureTypeReference>,
191 /// Namespace-import aliases re-exported through an object literal
192 /// (`export const API = { foo }` where `foo` is `import * as foo from './bar'`).
193 pub namespace_object_aliases: Vec<CachedNamespaceObjectAlias>,
194 /// Iconify collection prefixes found in static icon props (issue #608).
195 pub iconify_prefixes: Vec<String>,
196 /// Nuxt UI icon class suffixes found in static script-side icon properties
197 /// (issue #955).
198 pub iconify_icon_names: Vec<String>,
199 /// Bare identifier names that are candidates for convention auto-import
200 /// resolution (issue #704). Content-local, so they round-trip through the
201 /// cache; resolution against the plugin table happens at graph-build time.
202 pub auto_import_candidates: Vec<String>,
203 /// File-level string directives (`"use client"`, `"use server"`). Content-local,
204 /// round-trips through the cache so the security `client-server-leak` detector
205 /// sees directives on warm-cache loads.
206 pub directives: Vec<String>,
207 /// Byte-offset starts of `next/dynamic(..., { ssr: false })` dynamic imports.
208 /// Content-local, round-trips so the security `client-server-leak` BFS sees
209 /// the ssr:false client-only escape hatch on warm-cache loads.
210 pub client_only_dynamic_import_spans: Vec<u32>,
211 /// Captured security sink sites (category-blind). Round-trips through the
212 /// cache so the catalogue-driven `tainted_sink` detector sees sinks on
213 /// warm-cache loads.
214 pub security_sinks: Vec<fallow_types::extract::SinkSite>,
215 /// Count of sink-shaped nodes whose callee could not be flattened to a
216 /// static path. Round-trips so the in-band blind-spot count is stable.
217 pub security_sinks_skipped: u32,
218 /// Span-level diagnostics for skipped security sink callees.
219 pub security_unresolved_callee_sites: Vec<fallow_types::extract::SkippedSecurityCalleeSite>,
220 /// Local bindings tied to the member-access path they were sourced from.
221 /// Round-trips so the security `tainted_sink` source-to-sink association
222 /// sees source-tainted bindings on warm-cache loads.
223 pub tainted_bindings: Vec<fallow_types::extract::TaintedBinding>,
224 /// Direct sink arguments recognized as sanitizer calls.
225 pub sanitized_sink_args: Vec<fallow_types::extract::SanitizedSinkArg>,
226 /// Defensive control call sites for security surface output.
227 pub security_control_sites: Vec<fallow_types::extract::SecurityControlSite>,
228 /// Deduped statically flattenable callee paths. Round-trips so the
229 /// `boundaries.calls.forbidden` detector sees call sites on warm-cache
230 /// loads.
231 pub callee_uses: Vec<fallow_types::extract::CalleeUse>,
232 /// Misplaced `"use client"` / `"use server"` directive sites.
233 /// Round-trips so the `misplaced-directive` detector sees them on
234 /// warm-cache loads.
235 pub misplaced_directives: Vec<fallow_types::extract::MisplacedDirectiveSite>,
236 /// Export local names of inline `"use server"` body Server Actions.
237 /// Round-trips so the `unused-server-action` reclassifier sees them on
238 /// warm-cache loads.
239 pub inline_server_action_exports: Vec<String>,
240 /// Vue `provide`/`inject` and Svelte `setContext`/`getContext` key sites.
241 /// Round-trips so the `unprovided-inject` detector sees them on warm-cache
242 /// loads.
243 pub di_key_sites: Vec<fallow_types::extract::DiKeySite>,
244 /// Whether the module had an unknowable-key provide. Round-trips so the
245 /// `unprovided-inject` project-wide abstain holds on warm-cache loads.
246 pub has_dynamic_provide: bool,
247 /// Vue `<script setup>` `defineProps` and Svelte 5 `$props()` declared props.
248 /// Round-trips so the `unused-component-prop` detector sees them on
249 /// warm-cache loads.
250 pub component_props: Vec<fallow_types::extract::ComponentProp>,
251 /// Whether the template spreads `$attrs`/`$props`/`props` or the
252 /// `defineProps` return is rest-destructured. Round-trips for the abstain.
253 pub has_props_attrs_fallthrough: bool,
254 /// Whether the SFC calls `defineExpose(...)`. Round-trips for the abstain.
255 pub has_define_expose: bool,
256 /// Whether the SFC calls `defineModel(...)`. Round-trips for the abstain.
257 pub has_define_model: bool,
258 /// Whether `defineProps` had an unharvestable type-reference argument.
259 /// Round-trips for the abstain.
260 pub has_unharvestable_props: bool,
261 /// Vue `<script setup>` `defineEmits` declared events. Round-trips so the
262 /// `unused-component-emit` detector sees them on warm-cache loads.
263 pub component_emits: Vec<fallow_types::extract::ComponentEmit>,
264 /// Angular component/directive inputs (`@Input()` decorators and signal
265 /// `input()` / `model()` initializers). Round-trips so the
266 /// `unused-component-input` detector sees them on warm-cache loads.
267 pub angular_inputs: Vec<fallow_types::extract::AngularInputMember>,
268 /// Angular component/directive outputs (`@Output()` decorators and signal
269 /// `output()` / `outputFromObservable()` initializers). Round-trips so the
270 /// `unused-component-output` detector sees them on warm-cache loads.
271 pub angular_outputs: Vec<fallow_types::extract::AngularOutputMember>,
272 /// Angular `@Component` declarations with their `selector` value(s).
273 /// Round-trips so the Angular `unrendered-component` arm sees them on
274 /// warm-cache loads.
275 pub angular_component_selectors: Vec<fallow_types::extract::AngularComponentSelector>,
276 /// Lit / web-component custom elements registered in this file. Round-trips so
277 /// the Lit `unrendered-component` arm sees them on warm-cache loads.
278 pub registered_custom_elements: Vec<fallow_types::extract::RegisteredCustomElement>,
279 /// Custom-element tag names used (rendered) in this file's `html` templates.
280 /// Round-trips for the Lit `unrendered-component` rendered-tag union.
281 pub used_custom_element_tags: Vec<String>,
282 /// Custom element selector tags referenced in this file's Angular templates.
283 /// Round-trips for the Angular `unrendered-component` used-selector union.
284 pub angular_used_selectors: Vec<String>,
285 /// Angular route / bootstrap component class references. Round-trips for the
286 /// Angular `unrendered-component` entry-point abstain.
287 pub angular_entry_component_refs: Vec<String>,
288 /// Whether this file dynamically renders a component (project-wide abstain
289 /// signal for the Angular `unrendered-component` detector). Round-trips.
290 pub has_dynamic_component_render: bool,
291 /// Whether `defineEmits` had an unharvestable argument. Round-trips for the
292 /// abstain.
293 pub has_unharvestable_emits: bool,
294 /// Whether an `emit(<nonLiteral>)` call was seen. Round-trips for the abstain.
295 pub has_dynamic_emit: bool,
296 /// Whether the emit binding was used as a whole value. Round-trips for the
297 /// abstain.
298 pub has_emit_whole_object_use: bool,
299 /// SvelteKit `load()` return-object keys. Round-trips so the
300 /// `unused-load-data-key` detector sees them on warm-cache loads.
301 pub load_return_keys: Vec<fallow_types::extract::LoadReturnKey>,
302 /// Whether this file's `load()` body could not be harvested safely.
303 /// Round-trips for the abstain.
304 pub has_unharvestable_load: bool,
305 /// Whether this file passes the whole `data` object opaquely. Round-trips
306 /// for the `unused-load-data-key` abstain.
307 pub has_load_data_whole_use: bool,
308 /// React/JSX component definitions. Round-trips so the React-health phases
309 /// see them on warm-cache loads.
310 pub component_functions: Vec<fallow_types::extract::ComponentFunction>,
311 /// React component props. Round-trips so the React `unused-component-prop`
312 /// arm sees them on warm-cache loads.
313 pub react_props: Vec<fallow_types::extract::ComponentProp>,
314 /// React hook call sites. Round-trips for the complexity-fold phase.
315 pub hook_uses: Vec<fallow_types::extract::HookUse>,
316 /// React render edges (child name captured; resolution deferred to graph
317 /// build). Round-trips so the render graph survives a warm cache.
318 pub render_edges: Vec<fallow_types::extract::RenderEdge>,
319 /// Svelte custom events dispatched via `dispatch('<name>')`. Round-trips so
320 /// the `unused-svelte-event` detector sees them on warm-cache loads.
321 pub svelte_dispatched_events: Vec<fallow_types::extract::DispatchedEvent>,
322 /// Svelte template `on:<name>` listener names on component tags. Round-trips
323 /// so the project-wide listened set is correct on warm-cache loads.
324 pub svelte_listened_events: Vec<String>,
325 /// Whether a `dispatch(<nonLiteral>)` call or whole-`dispatch`-value use was
326 /// seen. Round-trips for the `unused-svelte-event` abstain.
327 pub has_dynamic_dispatch: bool,
328}
329
330impl CachedModule {
331 /// Source metadata fingerprint stored with this cache entry.
332 ///
333 #[must_use]
334 pub fn source_fingerprint(&self) -> fallow_types::source_fingerprint::SourceFingerprint {
335 fallow_types::source_fingerprint::SourceFingerprint::with_ctime(
336 self.mtime_ns,
337 self.ctime_ns,
338 self.file_size,
339 )
340 }
341}
342
343/// Cached namespace-object alias.
344#[derive(Debug, Clone, Encode, Decode)]
345pub struct CachedNamespaceObjectAlias {
346 /// Canonical export name on this module.
347 pub via_export_name: String,
348 /// Dotted suffix of the property path relative to the export.
349 pub suffix: String,
350 /// Local name of the namespace import on this module.
351 pub namespace_local: String,
352}
353
354/// Cached local type declaration.
355#[derive(Debug, Clone, Encode, Decode)]
356pub struct CachedLocalTypeDeclaration {
357 /// Local declaration name.
358 pub name: String,
359 /// Byte offset of the declaration span start.
360 pub span_start: u32,
361 /// Byte offset of the declaration span end.
362 pub span_end: u32,
363}
364
365/// Cached public signature type reference.
366#[derive(Debug, Clone, Encode, Decode)]
367pub struct CachedPublicSignatureTypeReference {
368 /// Exported symbol whose signature contains the reference.
369 pub export_name: String,
370 /// Referenced type name.
371 pub type_name: String,
372 /// Byte offset of the reference span start.
373 pub span_start: u32,
374 /// Byte offset of the reference span end.
375 pub span_end: u32,
376}
377
378/// Cached suppression directive.
379#[derive(Debug, Clone, Encode, Decode)]
380pub struct CachedSuppression {
381 /// 1-based line this suppression applies to. 0 = file-wide.
382 pub(crate) line: u32,
383 /// 1-based line where the comment itself appears.
384 pub(crate) comment_line: u32,
385 /// 0 = suppress all, otherwise `IssueKind` discriminant.
386 pub(crate) kind: u8,
387 /// Rule-pack name for scoped policy suppressions. Empty for all other
388 /// suppression targets.
389 pub(crate) policy_pack: String,
390 /// Rule id for scoped policy suppressions. Empty for all other suppression
391 /// targets.
392 pub(crate) policy_rule_id: String,
393 /// Human-authored reason after `--`, when present.
394 pub(crate) reason: Option<String>,
395}
396
397/// Cached unknown suppression kind token (see #449).
398#[derive(Debug, Clone, Encode, Decode)]
399pub struct CachedUnknownSuppressionKind {
400 /// 1-based line where the comment itself appears.
401 pub comment_line: u32,
402 /// True when the marker was `fallow-ignore-file`.
403 pub is_file_level: bool,
404 /// The verbatim token that did not parse.
405 pub token: String,
406 /// Human-authored reason after `--`, when present.
407 pub reason: Option<String>,
408}
409
410/// Cached export data for a single export declaration.
411#[derive(Debug, Clone, Encode, Decode)]
412pub struct CachedExport {
413 /// Export name (or "default" for default exports).
414 pub(crate) name: String,
415 /// Whether this is a default export.
416 pub(crate) is_default: bool,
417 /// Whether this is a type-only export.
418 pub(crate) is_type_only: bool,
419 /// Whether this export is registered through a runtime side effect at
420 /// module load time (Lit `@customElement` decorator or
421 /// `customElements.define` call). Persisted so warm-cache runs continue
422 /// to skip unused-export reporting for these classes.
423 pub(crate) is_side_effect_used: bool,
424 /// Visibility tag discriminant (0=None, 1=Public, 2=Internal, 3=Beta, 4=Alpha).
425 pub(crate) visibility: u8,
426 /// Human-authored reason on `@expected-unused -- <reason>`, when present.
427 pub(crate) expected_unused_reason: Option<String>,
428 /// Whether the leading JSDoc carries a `@deprecated` tag.
429 pub(crate) deprecated: bool,
430 /// Plain-text `@deprecated` message, `None` for a bare tag.
431 pub(crate) deprecated_reason: Option<Box<str>>,
432 /// The local binding name, if different.
433 pub(crate) local_name: Option<String>,
434 /// Byte offset of the export span start.
435 pub(crate) span_start: u32,
436 /// Byte offset of the export span end.
437 pub(crate) span_end: u32,
438 /// Members of this export (for enums and classes).
439 pub(crate) members: Vec<CachedMember>,
440 /// The local name of the parent class from `extends` clause, if any.
441 pub(crate) super_class: Option<String>,
442}
443
444/// Cached import data for a single import declaration.
445#[derive(Debug, Clone, Encode, Decode)]
446pub struct CachedImport {
447 /// The import specifier.
448 pub(crate) source: String,
449 /// For Named imports, the imported symbol name. Empty for other kinds.
450 pub(crate) imported_name: String,
451 /// The local binding name.
452 pub(crate) local_name: String,
453 /// Whether this is a type-only import.
454 pub(crate) is_type_only: bool,
455 /// Whether this whole-module import forwards type meanings only
456 /// (`export type *` inside a `declare module '...'` body).
457 pub(crate) is_type_only_star: bool,
458 /// Whether this import originated from an SFC `<style>` block / `<style src>` (CSS context).
459 pub(crate) from_style: bool,
460 /// Import kind: 0=Named, 1=Default, 2=Namespace, 3=SideEffect.
461 pub(crate) kind: u8,
462 /// Byte offset of the import span start.
463 pub(crate) span_start: u32,
464 /// Byte offset of the import span end.
465 pub(crate) span_end: u32,
466 /// Byte offset of the source string literal span start.
467 pub(crate) source_span_start: u32,
468 /// Byte offset of the source string literal span end.
469 pub(crate) source_span_end: u32,
470}
471
472/// Cached dynamic import data.
473#[derive(Debug, Clone, Encode, Decode)]
474pub struct CachedDynamicImport {
475 /// The import specifier.
476 pub(crate) source: String,
477 /// Byte offset of the span start.
478 pub(crate) span_start: u32,
479 /// Byte offset of the span end.
480 pub(crate) span_end: u32,
481 /// Names destructured from the import result.
482 pub(crate) destructured_names: Vec<String>,
483 /// Local variable name for namespace imports.
484 pub(crate) local_name: Option<String>,
485 /// True when this dynamic import was synthesised by fallow (see
486 /// `DynamicImportInfo::is_speculative`).
487 pub(crate) is_speculative: bool,
488}
489
490/// Cached `require()` call data.
491#[derive(Debug, Clone, Encode, Decode)]
492pub struct CachedRequireCall {
493 /// The require specifier.
494 pub(crate) source: String,
495 /// Byte offset of the span start.
496 pub(crate) span_start: u32,
497 /// Byte offset of the span end.
498 pub(crate) span_end: u32,
499 /// Byte offset of the specifier string-literal span start.
500 pub(crate) source_span_start: u32,
501 /// Byte offset of the specifier string-literal span end.
502 pub(crate) source_span_end: u32,
503 /// Names destructured from the require result.
504 pub(crate) destructured_names: Vec<String>,
505 /// Local variable name for namespace requires.
506 pub(crate) local_name: Option<String>,
507 /// `true` for the type-erased `import type X = require('...')` spelling.
508 pub(crate) is_type_only: bool,
509}
510
511/// Cached re-export data.
512#[derive(Debug, Clone, Encode, Decode)]
513pub struct CachedReExport {
514 /// The module being re-exported from.
515 pub(crate) source: String,
516 /// Name imported from the source.
517 pub(crate) imported_name: String,
518 /// Name exported from this module.
519 pub(crate) exported_name: String,
520 /// Whether this is a type-only re-export.
521 pub(crate) is_type_only: bool,
522 /// Byte offset of the re-export span start (for line-number reporting).
523 pub(crate) span_start: u32,
524 /// Byte offset of the re-export span end.
525 pub(crate) span_end: u32,
526 /// Byte offset of the enclosing statement span start.
527 pub(crate) statement_span_start: u32,
528 /// Byte offset of the enclosing statement span end.
529 pub(crate) statement_span_end: u32,
530 /// Byte offset of the source string-literal span start.
531 pub(crate) source_span_start: u32,
532 /// Byte offset of the source string-literal span end.
533 pub(crate) source_span_end: u32,
534}
535
536/// Cached enum or class member data.
537#[derive(Debug, Clone, Encode, Decode)]
538pub struct CachedMember {
539 /// Member name.
540 pub(crate) name: String,
541 /// Member kind (enum, method, or property).
542 pub(crate) kind: MemberKind,
543 /// Byte offset of the span start.
544 pub(crate) span_start: u32,
545 /// Byte offset of the span end.
546 pub(crate) span_end: u32,
547 /// Whether this member has decorators.
548 pub(crate) has_decorator: bool,
549 /// Full dotted path of each decorator (e.g. `step`, `ns.foo`).
550 /// Empty for undecorated members and decorators with non-identifier
551 /// expressions.
552 pub(crate) decorator_names: Vec<String>,
553 /// True when this is a static method that returns a fresh instance of
554 /// the class: body returns `new this()` / `new <SameClassName>()`, or the
555 /// declared return type matches the class name. Treated as a factory.
556 /// See issues #346, #387.
557 pub(crate) is_instance_returning_static: bool,
558 /// True when this instance method's call result is an instance of the
559 /// same class (declared return type matches the class name, or body's
560 /// last statement is `return this`). Drives fluent-chain credit. See
561 /// issue #387.
562 pub(crate) is_self_returning: bool,
563}
564
565/// Cached dynamic import pattern data (template literals, `import.meta.glob`).
566#[derive(Debug, Clone, Encode, Decode)]
567pub struct CachedDynamicImportPattern {
568 /// Static prefix of the import path.
569 pub(crate) prefix: String,
570 /// Static suffix, if any.
571 pub(crate) suffix: Option<String>,
572 /// Byte offset of the span start.
573 pub(crate) span_start: u32,
574 /// Byte offset of the span end.
575 pub(crate) span_end: u32,
576 /// Runtime mechanism used to load modules matching this pattern.
577 pub(crate) mechanism: crate::ModuleLoadMechanism,
578}