macroforge_ts_syn 0.3.0

TypeScript syntax types for compile-time macro code generation
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
//! Macro execution context types.
//!
//! This module provides the context that is passed to macro functions during
//! execution. The [`MacroContextIR`] contains all the information a macro needs
//! to process its input and generate output.
//!
//! ## Context Flow
//!
//! ```text
//! TypeScript Source
//!        │
//!        ▼
//! ┌─────────────────┐
//! │  Parse & Lower  │  (SWC parser → IR types)
//! └────────┬────────┘
//!          │
//!          ▼
//! ┌─────────────────┐
//! │ MacroContextIR  │  (Serialized to macro)
//! └────────┬────────┘
//!          │
//!          ▼
//! ┌─────────────────┐
//! │  Macro Function │  (Your code!)
//! └────────┬────────┘
//!          │
//!          ▼
//! ┌─────────────────┐
//! │   MacroResult   │  (Patches to apply)
//! └─────────────────┘
//! ```
//!
//! ## Example Usage
//!
//! ```rust
//! use macroforge_ts_syn::{MacroContextIR, MacroResult};
//!
//! // This shows the typical signature of a derive macro
//! pub fn my_derive_macro(ctx: MacroContextIR) -> MacroResult {
//!     // Access macro metadata
//!     println!("Macro: {} from {}", ctx.macro_name, ctx.module_path);
//!     println!("File: {}", ctx.file_name);
//!
//!     // Work with the target
//!     if let Some(class) = ctx.as_class() {
//!         println!("Processing class: {}", class.name);
//!     }
//!
//!     MacroResult::default()
//! }
//! ```

use std::collections::HashMap;

use crate::abi::type_registry::{ResolvedTypeRef, TypeRegistry};
use crate::abi::{ClassIR, EnumIR, FunctionIR, InterfaceIR, SpanIR, TypeAliasIR};
use crate::import_registry::ImportRegistry;
use serde::{Deserialize, Serialize};

/// The kind of macro being executed.
///
/// Different macro kinds have different invocation syntax and capabilities:
///
/// - **Derive**: Attached to types, generates additional code alongside the type
/// - **Attribute**: Attached to declarations, can transform the declaration
/// - **Call**: Invoked inline, generates code at the call site
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum MacroKind {
    /// A derive macro attached via JSDoc.
    ///
    /// Example: `/** @derive(Debug, Clone) */`
    ///
    /// Derive macros receive the type definition and generate additional
    /// code (methods, traits, etc.) without modifying the original type.
    Derive,

    /// An attribute macro attached to a declaration.
    ///
    /// Example: `@log`, `@sqlTable("users")`
    ///
    /// Attribute macros can transform or augment the target declaration.
    Attribute,

    /// A call macro invoked inline.
    ///
    /// Example: `sql!("SELECT * FROM users")`, `html!(<div>...</div>)`
    ///
    /// Call macros generate code at the invocation site.
    Call,
}

/// The target declaration of a macro application.
///
/// Wraps the IR type of the declaration that the macro is applied to,
/// allowing macros to handle different target types uniformly.
///
/// # Example
///
/// ```rust,no_run
/// use macroforge_ts_syn::TargetIR;
///
/// fn get_target_name(target: &TargetIR) -> &str {
///     match target {
///         TargetIR::Class(c) => &c.name,
///         TargetIR::Interface(i) => &i.name,
///         TargetIR::Enum(e) => &e.name,
///         TargetIR::TypeAlias(t) => &t.name,
///         TargetIR::Function(f) => &f.name,
///         TargetIR::Other => "<unknown>",
///     }
/// }
/// ```
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum TargetIR {
    /// Macro applied to a class declaration.
    Class(ClassIR),

    /// Macro applied to an enum declaration.
    Enum(EnumIR),

    /// Macro applied to an interface declaration.
    Interface(InterfaceIR),

    /// Macro applied to a type alias declaration.
    TypeAlias(TypeAliasIR),

    /// Macro applied to a function declaration.
    Function(FunctionIR),

    /// Macro applied to an unsupported construct.
    Other,
}

/// Context provided to macros during execution.
///
/// This is the primary input to all macro functions. It contains:
/// - Metadata about the macro invocation (name, kind, source location)
/// - The target declaration ([`TargetIR`]) the macro is applied to
/// - Source spans for accurate error reporting
/// - The raw source code of the target for custom parsing
///
/// # ABI Stability
///
/// The `abi_version` field allows for backwards compatibility checking.
/// Macros can verify they're compatible with the runtime version.
///
/// # Error Reporting
///
/// Use [`error_span()`](Self::error_span) to get the best span for error
/// messages. It prefers `macro_name_span` (pointing to the specific macro)
/// over `decorator_span` (pointing to the entire decorator).
///
/// # Example
///
/// ```rust
/// use macroforge_ts_syn::{MacroContextIR, MacroResult, insert_into_class};
///
/// pub fn debug_derive(ctx: MacroContextIR) -> MacroResult {
///     let class = ctx.as_class().expect("Debug requires a class");
///
///     // Generate a debug method
///     let method_code = format!(
///         r#"debug(): string {{
///             return "{}({{}})";
///         }}"#,
///         class.name
///     );
///
///     // Insert at end of class body
///     MacroResult {
///         runtime_patches: vec![insert_into_class(class.body_span, method_code)],
///         ..Default::default()
///     }
/// }
/// ```
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MacroContextIR {
    /// ABI version for compatibility checking
    pub abi_version: u32,

    /// The kind of macro being executed
    pub macro_kind: MacroKind,

    /// The name of the macro (e.g., "Debug")
    pub macro_name: String,

    /// The module path the macro comes from (e.g., "@macro/derive")
    pub module_path: String,

    /// Span of the decorator/macro invocation (entire @derive(...))
    pub decorator_span: SpanIR,

    /// Span of just the macro name within the decorator (e.g., "Debug" in @derive(Debug))
    /// Used for error reporting to point to the specific macro that caused the error
    #[serde(default)]
    pub macro_name_span: Option<SpanIR>,

    /// Span of the target (class, enum, etc.)
    pub target_span: SpanIR,

    /// The file being processed
    pub file_name: String,

    /// The target of the macro application
    pub target: TargetIR,

    /// The source code of the target (class, enum, etc.)
    /// This enables macros to parse the source themselves using TsStream
    pub target_source: String,

    /// The full import registry from the file being processed.
    /// Populated by the host before serializing the context for external macros.
    /// Includes source imports, config imports, and previously generated imports,
    /// giving external macros full parity with builtins.
    #[serde(default)]
    pub import_registry: ImportRegistry,

    /// Macroforge configuration from macroforge.config.ts.
    /// Populated by the host before serializing the context for external macros.
    /// Gives external macros access to foreign type configs, etc.
    #[serde(default)]
    pub config: Option<crate::config::MacroforgeConfig>,

    /// Project-wide type registry, populated during pre-expansion scan.
    /// Gives macros access to all types defined in the project for
    /// Zig-style compile-time type awareness.
    ///
    /// Always present — defaults to an empty `TypeRegistry` when no scan
    /// data is available (e.g. unit-test fixtures that don't exercise
    /// cross-file resolution). Macros must treat this as the source of
    /// truth and call `resolve` rather than ad-hoc lookups.
    #[serde(default)]
    pub type_registry: TypeRegistry,

    /// Resolved type references for the target's fields.
    /// Maps field name -> ResolvedTypeRef for each field in the target.
    /// Only populated when type_registry is available.
    #[serde(default)]
    pub resolved_fields: Option<HashMap<String, ResolvedTypeRef>>,
}

impl MacroContextIR {
    /// Create a new macro context for a derive macro on a class
    pub fn new_derive_class(
        macro_name: String,
        module_path: String,
        decorator_span: SpanIR,
        target_span: SpanIR,
        file_name: String,
        class: ClassIR,
        target_source: String,
    ) -> Self {
        Self {
            abi_version: 1,
            macro_kind: MacroKind::Derive,
            macro_name,
            module_path,
            decorator_span,
            macro_name_span: None,
            target_span,
            file_name,
            target: TargetIR::Class(class),
            target_source,
            import_registry: ImportRegistry::new(),
            config: None,
            type_registry: TypeRegistry::default(),
            resolved_fields: None,
        }
    }

    /// Set the macro name span (builder pattern)
    pub fn with_macro_name_span(mut self, span: SpanIR) -> Self {
        self.macro_name_span = Some(span);
        self
    }

    /// Get the best span for error reporting - prefers macro_name_span if available
    pub fn error_span(&self) -> SpanIR {
        self.macro_name_span.unwrap_or(self.decorator_span)
    }

    /// Get the class IR if the target is a class
    pub fn as_class(&self) -> Option<&ClassIR> {
        match &self.target {
            TargetIR::Class(class) => Some(class),
            _ => None,
        }
    }

    /// Get the enum IR if the target is an enum
    pub fn as_enum(&self) -> Option<&EnumIR> {
        match &self.target {
            TargetIR::Enum(enum_ir) => Some(enum_ir),
            _ => None,
        }
    }

    /// Get the interface IR if the target is an interface
    pub fn as_interface(&self) -> Option<&InterfaceIR> {
        match &self.target {
            TargetIR::Interface(interface_ir) => Some(interface_ir),
            _ => None,
        }
    }

    /// Get the type alias IR if the target is a type alias
    pub fn as_type_alias(&self) -> Option<&TypeAliasIR> {
        match &self.target {
            TargetIR::TypeAlias(type_alias_ir) => Some(type_alias_ir),
            _ => None,
        }
    }

    /// Get the function IR if the target is a function
    pub fn as_function(&self) -> Option<&FunctionIR> {
        match &self.target {
            TargetIR::Function(function_ir) => Some(function_ir),
            _ => None,
        }
    }

    /// Create a new macro context for a derive macro on an interface
    pub fn new_derive_interface(
        macro_name: String,
        module_path: String,
        decorator_span: SpanIR,
        target_span: SpanIR,
        file_name: String,
        interface: InterfaceIR,
        target_source: String,
    ) -> Self {
        Self {
            abi_version: 1,
            macro_kind: MacroKind::Derive,
            macro_name,
            module_path,
            decorator_span,
            macro_name_span: None,
            target_span,
            file_name,
            target: TargetIR::Interface(interface),
            target_source,
            import_registry: ImportRegistry::new(),
            config: None,
            type_registry: TypeRegistry::default(),
            resolved_fields: None,
        }
    }

    /// Create a new macro context for a derive macro on a type alias
    pub fn new_derive_type_alias(
        macro_name: String,
        module_path: String,
        decorator_span: SpanIR,
        target_span: SpanIR,
        file_name: String,
        type_alias: TypeAliasIR,
        target_source: String,
    ) -> Self {
        Self {
            abi_version: 1,
            macro_kind: MacroKind::Derive,
            macro_name,
            module_path,
            decorator_span,
            macro_name_span: None,
            target_span,
            file_name,
            target: TargetIR::TypeAlias(type_alias),
            target_source,
            import_registry: ImportRegistry::new(),
            config: None,
            type_registry: TypeRegistry::default(),
            resolved_fields: None,
        }
    }

    /// Create a new macro context for a derive macro on an enum
    pub fn new_derive_enum(
        macro_name: String,
        module_path: String,
        decorator_span: SpanIR,
        target_span: SpanIR,
        file_name: String,
        enum_ir: EnumIR,
        target_source: String,
    ) -> Self {
        Self {
            abi_version: 1,
            macro_kind: MacroKind::Derive,
            macro_name,
            module_path,
            decorator_span,
            macro_name_span: None,
            target_span,
            file_name,
            target: TargetIR::Enum(enum_ir),
            target_source,
            import_registry: ImportRegistry::new(),
            config: None,
            type_registry: TypeRegistry::default(),
            resolved_fields: None,
        }
    }

    /// Create a new macro context for an attribute macro on a function
    pub fn new_attribute_function(
        macro_name: String,
        module_path: String,
        decorator_span: SpanIR,
        target_span: SpanIR,
        file_name: String,
        function_ir: FunctionIR,
        target_source: String,
    ) -> Self {
        Self {
            abi_version: 1,
            macro_kind: MacroKind::Attribute,
            macro_name,
            module_path,
            decorator_span,
            macro_name_span: None,
            target_span,
            file_name,
            target: TargetIR::Function(function_ir),
            target_source,
            import_registry: ImportRegistry::new(),
            config: None,
            type_registry: TypeRegistry::default(),
            resolved_fields: None,
        }
    }

    /// Create a new macro context for an attribute macro on a class
    pub fn new_attribute_class(
        macro_name: String,
        module_path: String,
        decorator_span: SpanIR,
        target_span: SpanIR,
        file_name: String,
        class: ClassIR,
        target_source: String,
    ) -> Self {
        Self {
            abi_version: 1,
            macro_kind: MacroKind::Attribute,
            macro_name,
            module_path,
            decorator_span,
            macro_name_span: None,
            target_span,
            file_name,
            target: TargetIR::Class(class),
            target_source,
            import_registry: ImportRegistry::new(),
            config: None,
            type_registry: TypeRegistry::default(),
            resolved_fields: None,
        }
    }

    /// Create a new macro context for an attribute macro on an interface
    pub fn new_attribute_interface(
        macro_name: String,
        module_path: String,
        decorator_span: SpanIR,
        target_span: SpanIR,
        file_name: String,
        interface: InterfaceIR,
        target_source: String,
    ) -> Self {
        Self {
            abi_version: 1,
            macro_kind: MacroKind::Attribute,
            macro_name,
            module_path,
            decorator_span,
            macro_name_span: None,
            target_span,
            file_name,
            target: TargetIR::Interface(interface),
            target_source,
            import_registry: ImportRegistry::new(),
            config: None,
            type_registry: TypeRegistry::default(),
            resolved_fields: None,
        }
    }

    /// Create a new macro context for an attribute macro on an enum
    pub fn new_attribute_enum(
        macro_name: String,
        module_path: String,
        decorator_span: SpanIR,
        target_span: SpanIR,
        file_name: String,
        enum_ir: EnumIR,
        target_source: String,
    ) -> Self {
        Self {
            abi_version: 1,
            macro_kind: MacroKind::Attribute,
            macro_name,
            module_path,
            decorator_span,
            macro_name_span: None,
            target_span,
            file_name,
            target: TargetIR::Enum(enum_ir),
            target_source,
            import_registry: ImportRegistry::new(),
            config: None,
            type_registry: TypeRegistry::default(),
            resolved_fields: None,
        }
    }

    /// Create a new macro context for an attribute macro on a type alias
    pub fn new_attribute_type_alias(
        macro_name: String,
        module_path: String,
        decorator_span: SpanIR,
        target_span: SpanIR,
        file_name: String,
        type_alias: TypeAliasIR,
        target_source: String,
    ) -> Self {
        Self {
            abi_version: 1,
            macro_kind: MacroKind::Attribute,
            macro_name,
            module_path,
            decorator_span,
            macro_name_span: None,
            target_span,
            file_name,
            target: TargetIR::TypeAlias(type_alias),
            target_source,
            import_registry: ImportRegistry::new(),
            config: None,
            type_registry: TypeRegistry::default(),
            resolved_fields: None,
        }
    }

    /// Returns the module specifier the current file should use to `import`
    /// `type_name`. Returns `None` when the type is co-located, unknown, or
    /// the path arithmetic fails.
    ///
    /// Resolution order:
    /// 1. If the current file already imports `type_name`, return its existing
    ///    specifier (preserves aliases and the user's chosen path style).
    /// 2. Otherwise look up `type_name` in `self.type_registry`.
    /// 3. If the type lives in `self.file_name`, return `None` (no import needed).
    /// 4. Compute the relative path from the current file's directory to
    ///    `entry.file_path`, strip TypeScript file extensions, and prepend
    ///    `./` if needed.
    pub fn import_specifier_for(&self, type_name: &str) -> Option<String> {
        if let Some(existing) = self.import_registry.get_source(type_name)
            && !existing.is_empty()
        {
            return Some(existing.to_string());
        }
        let entry = self.type_registry.types.get(type_name)?;
        if entry.file_path == self.file_name {
            return None;
        }
        relative_module_specifier(&self.file_name, &entry.file_path)
    }
}

/// Computes a TypeScript module specifier for `target_file` relative to the
/// directory containing `current_file`. Strips `.svelte.ts` → `.svelte`,
/// `.tsx` → empty, `.ts` → empty, and prepends `./` for sibling/descendant
/// paths.
fn relative_module_specifier(current_file: &str, target_file: &str) -> Option<String> {
    use std::path::Path;
    let from = Path::new(current_file).parent()?;
    let to = Path::new(target_file);
    let rel = pathdiff::diff_paths(to, from)?;
    let mut s = rel.to_string_lossy().replace('\\', "/");

    if let Some(stripped) = s.strip_suffix(".svelte.ts") {
        s = format!("{stripped}.svelte");
    } else if let Some(stripped) = s.strip_suffix(".tsx") {
        s = stripped.to_string();
    } else if let Some(stripped) = s.strip_suffix(".ts") {
        s = stripped.to_string();
    }

    if !s.starts_with('.') && !s.starts_with('/') {
        s = format!("./{s}");
    }
    Some(s)
}

#[cfg(test)]
mod import_specifier_tests {
    use super::*;
    use crate::SpanIR;
    use crate::abi::ir::interface::InterfaceIR;
    use crate::abi::ir::type_registry::{TypeDefinitionIR, TypeRegistry, TypeRegistryEntry};

    fn empty_interface(name: &str) -> InterfaceIR {
        InterfaceIR {
            name: name.to_string(),
            span: SpanIR::new(0, 0),
            body_span: SpanIR::new(0, 0),
            type_params: vec![],
            heritage: vec![],
            fields: vec![],
            methods: vec![],
            decorators: vec![],
        }
    }

    fn make_ctx(file_name: &str) -> MacroContextIR {
        MacroContextIR {
            abi_version: 1,
            macro_kind: MacroKind::Derive,
            macro_name: "Test".to_string(),
            module_path: "@test".to_string(),
            decorator_span: SpanIR::new(0, 0),
            macro_name_span: None,
            target_span: SpanIR::new(0, 0),
            file_name: file_name.to_string(),
            target: TargetIR::Interface(empty_interface("Probe")),
            target_source: String::new(),
            import_registry: ImportRegistry::new(),
            config: None,
            type_registry: TypeRegistry::default(),
            resolved_fields: None,
        }
    }

    fn registry_with(name: &str, file_path: &str) -> TypeRegistry {
        let mut reg = TypeRegistry {
            types: HashMap::new(),
            qualified_types: HashMap::new(),
            ambiguous_names: vec![],
        };
        reg.types.insert(
            name.to_string(),
            TypeRegistryEntry {
                name: name.to_string(),
                file_path: file_path.to_string(),
                is_exported: true,
                definition: TypeDefinitionIR::Interface(empty_interface(name)),
                file_imports: vec![],
            },
        );
        reg
    }

    #[test]
    fn existing_import_takes_priority() {
        let mut ctx = make_ctx("/foo/order.svelte.ts");
        ctx.import_registry.install_source_imports(vec![
            crate::import_registry::SourceImportEntry {
                local_name: "Customer".to_string(),
                source_module: "./customer.svelte".to_string(),
                original_name: None,
                is_type_only: true,
            },
        ]);
        ctx.type_registry = registry_with("Customer", "/totally/different/path.svelte.ts");
        assert_eq!(
            ctx.import_specifier_for("Customer"),
            Some("./customer.svelte".to_string())
        );
    }

    #[test]
    fn co_located_returns_none() {
        let mut ctx = make_ctx("/foo/bar.svelte.ts");
        ctx.type_registry = registry_with("Bar", "/foo/bar.svelte.ts");
        assert_eq!(ctx.import_specifier_for("Bar"), None);
    }

    #[test]
    fn sibling_file() {
        let mut ctx = make_ctx("/foo/order.svelte.ts");
        ctx.type_registry = registry_with("Customer", "/foo/customer.svelte.ts");
        assert_eq!(
            ctx.import_specifier_for("Customer"),
            Some("./customer.svelte".to_string())
        );
    }

    #[test]
    fn nested_subdir() {
        let mut ctx = make_ctx("/foo/order.svelte.ts");
        ctx.type_registry = registry_with("Customer", "/foo/sub/customer.svelte.ts");
        assert_eq!(
            ctx.import_specifier_for("Customer"),
            Some("./sub/customer.svelte".to_string())
        );
    }

    #[test]
    fn parent_dir() {
        let mut ctx = make_ctx("/foo/sub/order.svelte.ts");
        ctx.type_registry = registry_with("Customer", "/foo/customer.svelte.ts");
        assert_eq!(
            ctx.import_specifier_for("Customer"),
            Some("../customer.svelte".to_string())
        );
    }

    #[test]
    fn unknown_type() {
        let ctx = make_ctx("/foo/order.svelte.ts");
        assert_eq!(ctx.import_specifier_for("Customer"), None);
    }

    #[test]
    fn plain_ts_file() {
        let mut ctx = make_ctx("/foo/order.svelte.ts");
        ctx.type_registry = registry_with("Util", "/foo/util.ts");
        assert_eq!(ctx.import_specifier_for("Util"), Some("./util".to_string()));
    }

    #[test]
    fn tsx_file() {
        let mut ctx = make_ctx("/foo/order.svelte.ts");
        ctx.type_registry = registry_with("Component", "/foo/component.tsx");
        assert_eq!(
            ctx.import_specifier_for("Component"),
            Some("./component".to_string())
        );
    }
}