fallow-extract 3.34.1

AST extraction engine for fallow codebase intelligence (parser, complexity, SFC / Astro / MDX / CSS)
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
use oxc_ast::ast::{
    Argument, CallExpression, Expression, TSInterfaceDeclaration, TSType, TSTypeAliasDeclaration,
};

use crate::{
    DynamicImportInfo, ImportedName, PlaywrightConditionalFixtureDefinitionFact,
    PlaywrightFixtureAliasFact, PlaywrightFixtureTypeFact, SemanticFact, VitestModuleMockAction,
    VitestModuleMockOperationFact,
};

use super::super::{
    MockObjectProvenance, ModuleInfoExtractor, PendingPlaywrightFactory,
    PendingVitestMockOperation, PendingVitestMockProof,
};
use super::visit_helpers::{
    collect_fixture_type_bindings_from_members, collect_fixture_type_bindings_from_type,
    mock_method_object_span, mock_object_is_literal_global, mock_replacement_candidate,
    mock_static_target_source, playwright_extend_chain, root_manual_mock_source,
    vi_mock_has_factory, vitest_auto_mock_source,
};
use crate::parse::MockApiReferenceSpans;

/// The import sources of the Playwright test runner. The `playwright` package
/// exports the same runner at `playwright/test` that `@playwright/test`
/// re-exports.
const PLAYWRIGHT_TEST_SOURCES: [&str; 2] = ["@playwright/test", "playwright/test"];

/// What the innermost call of an `.extend(...)` chain extends.
enum PlaywrightExtendRoot {
    /// An identifier, for example `base` in `base.extend({})`.
    Name(String),
    /// The base test names of an imported `mergeTests(...)` call.
    Merge(Vec<String>),
}

/// An `.extend(...)` chain such as `base.extend<A>({}).extend<B>({})`.
struct PlaywrightExtendChain<'b, 'a> {
    /// The `.extend(...)` calls, outermost first.
    calls: Vec<&'b CallExpression<'a>>,
    root: PlaywrightExtendRoot,
}

impl ModuleInfoExtractor {
    /// True when `local_name` is the named import `imported_name` from a
    /// Playwright test runner source.
    fn is_playwright_test_import(&self, local_name: &str, imported_name: &str) -> bool {
        PLAYWRIGHT_TEST_SOURCES
            .iter()
            .any(|source| self.is_named_import_from(local_name, source, imported_name))
    }

    fn collect_playwright_fixture_type_bindings(&self, ty: &TSType<'_>) -> Vec<(String, String)> {
        let mut bindings = Vec::new();
        collect_fixture_type_bindings_from_type(
            ty,
            "",
            &self.playwright_fixture_types,
            &mut bindings,
        );
        bindings.sort_unstable();
        bindings.dedup();
        bindings
    }

    pub(super) fn record_playwright_fixture_type_alias(
        &mut self,
        alias: &TSTypeAliasDeclaration<'_>,
    ) {
        let bindings = self.collect_playwright_fixture_type_bindings(&alias.type_annotation);
        self.record_playwright_fixture_type_bindings(alias.id.name.as_str(), bindings);
    }

    /// Record an INTERFACE-declared fixture map (`interface MyFixtures {
    /// loginPage: LoginPage }` consumed by `base.extend<MyFixtures>`) into the
    /// same `playwright_fixture_types` table as the type-alias form, so both
    /// declaration styles resolve identically. `extends` heritage members are
    /// not expanded (the body's own members still resolve). See issue #1785.
    pub(super) fn record_playwright_fixture_interface(
        &mut self,
        iface: &TSInterfaceDeclaration<'_>,
    ) {
        let mut bindings = Vec::new();
        collect_fixture_type_bindings_from_members(
            &iface.body.body,
            "",
            &self.playwright_fixture_types,
            &mut bindings,
        );
        self.record_playwright_fixture_type_bindings(iface.id.name.as_str(), bindings);
    }

    /// Shared sink for alias- and interface-declared fixture maps: normalizes
    /// (sort + dedup), records the binding table, and emits the fixture-type
    /// facts.
    fn record_playwright_fixture_type_bindings(
        &mut self,
        type_name: &str,
        mut bindings: Vec<(String, String)>,
    ) {
        bindings.sort_unstable();
        bindings.dedup();
        if bindings.is_empty() {
            return;
        }
        self.playwright_fixture_types
            .insert(type_name.to_string(), bindings.clone());
        for (fixture_name, fixture_type) in bindings {
            self.semantic_facts
                .push(SemanticFact::PlaywrightFixtureType(
                    PlaywrightFixtureTypeFact {
                        alias_name: type_name.to_string(),
                        fixture_name,
                        type_name: fixture_type,
                    },
                ));
        }
    }

    /// True when `name` holds a Playwright test: the Playwright runner `test`
    /// import or a local const recorded in `playwright_local_tests`.
    pub(crate) fn is_playwright_test_name(&self, name: &str) -> bool {
        self.is_playwright_test_import(name, "test") || self.playwright_local_tests.contains(name)
    }

    /// True when only analysis can prove that `name` holds a Playwright test:
    /// a named or default import, which another file can define, or a local
    /// const that extends such a name.
    pub(crate) fn is_conditional_playwright_base(&self, name: &str) -> bool {
        self.playwright_conditional_tests.contains(name)
            || self.imports.iter().any(|import| {
                import.local_name == name
                    && matches!(
                        import.imported_name,
                        ImportedName::Named(_) | ImportedName::Default
                    )
            })
    }

    /// Record a fixture definition that analysis applies only when the
    /// imported `base_name` resolves to a Playwright test.
    pub(crate) fn record_playwright_conditional_fixture_definition_fact(
        &mut self,
        test_name: String,
        base_name: String,
        fixture_name: String,
        type_name: String,
    ) {
        self.semantic_facts
            .push(SemanticFact::PlaywrightConditionalFixtureDefinition(
                Box::new(PlaywrightConditionalFixtureDefinitionFact {
                    test_name,
                    base_name,
                    fixture_name,
                    type_name,
                }),
            ));
    }

    /// The base test names of a call to the imported `mergeTests`, or `None`
    /// when the call is not one. The import gate (it also accepts
    /// `mergeTests as merge`) keeps a user-local `mergeTests` function inert.
    fn playwright_merge_call_base_names(&self, call: &CallExpression<'_>) -> Option<Vec<String>> {
        let Expression::Identifier(callee) = &call.callee else {
            return None;
        };
        if !self.is_playwright_test_import(callee.name.as_str(), "mergeTests") {
            return None;
        }
        let mut base_names: Vec<String> = call
            .arguments
            .iter()
            .filter_map(playwright_merge_argument_base_name)
            .collect();
        base_names.sort();
        base_names.dedup();
        Some(base_names)
    }

    /// The `.extend(...)` calls of `call` and the root that they extend, or
    /// `None` when `call` is not an `.extend(...)` chain on an identifier or on
    /// an imported `mergeTests(...)` call.
    fn playwright_extend_chain_of<'b, 'a>(
        &self,
        call: &'b CallExpression<'a>,
    ) -> Option<PlaywrightExtendChain<'b, 'a>> {
        let (calls, receiver) = playwright_extend_chain(call)?;
        let root = match receiver {
            Expression::Identifier(ident) => PlaywrightExtendRoot::Name(ident.name.to_string()),
            Expression::CallExpression(inner) => {
                PlaywrightExtendRoot::Merge(self.playwright_merge_call_base_names(inner)?)
            }
            _ => return None,
        };
        Some(PlaywrightExtendChain { calls, root })
    }

    /// The fixture bindings that the type arguments of each `.extend<T>(...)`
    /// call in a chain declare, sorted and without duplicates.
    fn collect_playwright_extend_type_bindings(
        &self,
        calls: &[&CallExpression<'_>],
    ) -> Vec<(String, String)> {
        let mut bindings = Vec::new();
        for call in calls {
            let Some(type_arguments) = call.type_arguments.as_deref() else {
                continue;
            };
            for type_arg in &type_arguments.params {
                bindings.extend(self.collect_playwright_fixture_type_bindings(type_arg));
            }
        }
        bindings.sort_unstable();
        bindings.dedup();
        bindings
    }

    pub(super) fn record_playwright_fixture_definitions(
        &mut self,
        test_name: &str,
        call: &CallExpression<'_>,
    ) {
        let Some(chain) = self.playwright_extend_chain_of(call) else {
            return;
        };
        let receiver_is_test = match &chain.root {
            PlaywrightExtendRoot::Name(base_name) => self.is_playwright_test_name(base_name),
            PlaywrightExtendRoot::Merge(_) => true,
        };
        if !receiver_is_test {
            // `appTest.extend<T>()` on an imported `appTest` defines the
            // fixtures of `T` only when analysis resolves `appTest` to a
            // Playwright test. An unrelated imported `extend` stays inert.
            if let PlaywrightExtendRoot::Name(base_name) = &chain.root
                && self.is_conditional_playwright_base(base_name)
            {
                self.playwright_conditional_tests
                    .insert(test_name.to_string());
                for (fixture_name, type_name) in
                    self.collect_playwright_extend_type_bindings(&chain.calls)
                {
                    self.record_playwright_conditional_fixture_definition_fact(
                        test_name.to_string(),
                        base_name.clone(),
                        fixture_name,
                        type_name,
                    );
                }
            }
            return;
        }
        self.playwright_local_tests.insert(test_name.to_string());
        let bindings = self.collect_playwright_extend_type_bindings(&chain.calls);
        // Remember this local `const X = base.extend<T>({...})` fixture definition
        // so a helper wrapping `<X>.extend(...)` can inherit the bindings under its
        // own name (issue #1791). Stored whether or not the const is exported.
        if !bindings.is_empty() {
            self.playwright_local_fixture_defs
                .insert(test_name.to_string(), bindings.clone());
        }
        for (fixture_name, type_name) in bindings {
            self.record_playwright_fixture_definition_fact(
                test_name.to_string(),
                fixture_name.clone(),
                type_name,
            );
        }
    }

    fn record_playwright_fixture_alias(&mut self, test_name: &str, base_name: &str) {
        self.semantic_facts
            .push(SemanticFact::PlaywrightFixtureAlias(
                PlaywrightFixtureAliasFact {
                    test_name: test_name.to_string(),
                    base_name: base_name.to_string(),
                },
            ));
    }

    pub(super) fn record_playwright_wrapper_aliases(
        &mut self,
        test_name: &str,
        call: &CallExpression<'_>,
    ) {
        // `mergeTests(a, b)` and the chained `mergeTests(a, b).extend(...)`
        // (issue #3462) both inherit the fixtures of each merged test.
        let base_names = match self
            .playwright_extend_chain_of(call)
            .map(|chain| chain.root)
        {
            Some(PlaywrightExtendRoot::Name(base_name)) => {
                if !self.is_playwright_test_import(base_name.as_str(), "test") {
                    self.record_playwright_fixture_alias(test_name, &base_name);
                }
                return;
            }
            Some(PlaywrightExtendRoot::Merge(base_names)) => base_names,
            None => match self.playwright_merge_call_base_names(call) {
                Some(base_names) => base_names,
                None => return,
            },
        };
        self.playwright_local_tests.insert(test_name.to_string());
        for base_name in base_names {
            self.record_playwright_fixture_alias(test_name, &base_name);
        }
    }

    /// Alias a helper to each test that its returned `mergeTests(...)` call
    /// merges (issue #1795). The analyze-time alias fact lets each merged
    /// fixture resolve cross-file through the #1210 expansion. The pending pair
    /// serves same-file helper inheritance.
    fn record_playwright_merge_helper_aliases(&mut self, test_name: &str, base_names: Vec<String>) {
        for base_name in base_names {
            self.record_playwright_fixture_alias(test_name, &base_name);
            self.pending_playwright_factory_aliases
                .push((test_name.to_string(), base_name));
        }
    }

    /// Queue the fixture bindings of a helper that returns `<base>.extend<T>(...)`.
    /// `base_name` is `None` when the root of the chain is a `mergeTests(...)` call.
    fn push_playwright_factory_type_bindings(
        &mut self,
        test_name: &str,
        base_name: Option<String>,
        calls: &[&CallExpression<'_>],
    ) {
        let type_bindings = self.collect_playwright_extend_type_bindings(calls);
        if type_bindings.is_empty() {
            return;
        }
        self.pending_playwright_factory_calls
            .push(PendingPlaywrightFactory {
                test_name: test_name.to_string(),
                base_name,
                type_bindings,
            });
    }

    /// Capture helper-function Playwright fixtures or aliases from returns.
    pub(super) fn try_capture_playwright_factory_helper(
        &mut self,
        test_name: &str,
        call: &CallExpression<'_>,
    ) {
        let chain = self.playwright_extend_chain_of(call);
        if let Some(PlaywrightExtendChain {
            calls,
            root: PlaywrightExtendRoot::Name(base_name),
        }) = chain
        {
            // A helper returning `<base>.extend(...)`. `<base>` is either the
            // `@playwright/test` `test` import (its own fixtures come from the
            // type argument via the PendingPlaywrightFactory below) OR a local
            // fixture const / another helper. Record an alias unconditionally so
            // the helper inherits the base's fixture bindings even when the
            // wrapping `.extend({})` carries no type argument of its own (issue
            // #1791). The alias no-ops when `base` is the raw `test` import, since
            // no captured factory is keyed on it. The alias is name-based, so a
            // non-Playwright `<x>.extend(...)` helper whose `<x>` collides with a
            // same-file genuine fixture const could over-credit that fixture's
            // class; this only ever over-credits (false-negative direction),
            // matching the documented `mergeTests` name-collision tolerance.
            self.pending_playwright_factory_aliases
                .push((test_name.to_string(), base_name.clone()));

            // An IMPORTED base const (`billingBaseFixture.extend({})` where
            // `billingBaseFixture` comes from a sibling file) cannot resolve
            // through the same-module `resolve_playwright_factory_call_definitions`
            // pass, so ALSO emit an analyze-time alias fact for any base that is
            // not the raw `@playwright/test` `test` import (mirror the gate in
            // `record_playwright_wrapper_aliases`); the #1210 cross-file
            // expansion then resolves the imported base to its fixture
            // definitions. The raw `test` base no-ops. Issue #1795.
            if !self.is_playwright_test_import(base_name.as_str(), "test") {
                self.record_playwright_fixture_alias(test_name, &base_name);
            }
            self.push_playwright_factory_type_bindings(test_name, Some(base_name), &calls);
        } else if let Some(PlaywrightExtendChain {
            calls,
            root: PlaywrightExtendRoot::Merge(base_names),
        }) = chain
        {
            // A helper returning `mergeTests(a, b).extend<T>(...)` (issue #3462)
            // inherits the merged tests and defines the fixtures of `T`.
            self.record_playwright_merge_helper_aliases(test_name, base_names);
            self.push_playwright_factory_type_bindings(test_name, None, &calls);
        } else if let Some(base_names) = self.playwright_merge_call_base_names(call) {
            // A helper returning `mergeTests(billingTest(), ordersUiTest())`
            // (issue #1795).
            self.record_playwright_merge_helper_aliases(test_name, base_names);
        } else if let Expression::Identifier(ident) = &call.callee {
            self.pending_playwright_factory_aliases
                .push((test_name.to_string(), ident.name.to_string()));
        }
    }

    pub(super) fn record_vitest_mock_imports(&mut self, expr: &CallExpression<'_>) {
        let Some((object_span, provenance)) = mock_method_object_span(expr, "mock") else {
            return;
        };
        let Some(target_source) = mock_static_target_source(expr) else {
            return;
        };

        let has_factory = vi_mock_has_factory(expr);
        // Literal `vi`/`jest` objects may be injected globals with no import to
        // prove provenance against, so their credit edges are pushed eagerly.
        // Aliased and namespace forms always come from an import; their edges
        // wait for the span-provenance check in
        // `resolve_vitest_mock_operations` so an unrelated `x.mock("./y")`
        // never credits a file.
        let literal_global = mock_object_is_literal_global(expr);
        if literal_global {
            self.push_mock_credit_edges(&target_source, expr.span, has_factory);
        }

        let proof = mock_replacement_candidate(expr).map_or(
            PendingVitestMockProof::UnprovenMock,
            |candidate| PendingVitestMockProof::ClosedFactory {
                binding_requirement_spans: candidate.binding_requirement_spans,
                namespace_requirement_spans: candidate.namespace_requirement_spans,
            },
        );
        self.pending_vitest_mock_operations
            .push(PendingVitestMockOperation {
                source: target_source,
                object_span,
                provenance,
                call_span: expr.span,
                has_factory,
                needs_deferred_edges: !literal_global,
                proof,
            });
    }

    /// Record `X.doMock(...)` / `ns.vi.doMock(...)` for coverage credit only.
    ///
    /// Decision for issue #2082: `doMock` never masks. Unlike `vi.mock` it is
    /// not hoisted, affects only module requests evaluated after the call, and
    /// usually sits inside a test callback whose execution (and order relative
    /// to the file's dynamic imports) is a runtime scheduling question, so a
    /// mask derived from it could produce false uncovered findings. The safe,
    /// useful part is the credit side: the target and its speculative
    /// `__mocks__` sibling become dynamic-import edges, so a manual mock
    /// registered only through `doMock` stops looking like an unused file.
    /// `doUnmock` is ignored entirely: it only affects later dynamic imports,
    /// so letting it clear a sound hoisted `vi.mock` mask would lose
    /// precision for nothing.
    pub(super) fn record_vitest_do_mock(&mut self, expr: &CallExpression<'_>) {
        let Some((object_span, provenance)) = mock_method_object_span(expr, "doMock") else {
            return;
        };
        let Some(target_source) = mock_static_target_source(expr) else {
            return;
        };

        let has_factory = vi_mock_has_factory(expr);
        if mock_object_is_literal_global(expr) {
            self.push_mock_credit_edges(&target_source, expr.span, has_factory);
            return;
        }
        self.pending_vitest_mock_operations
            .push(PendingVitestMockOperation {
                source: target_source,
                object_span,
                provenance,
                call_span: expr.span,
                has_factory,
                needs_deferred_edges: true,
                proof: PendingVitestMockProof::CreditOnly,
            });
    }

    fn push_mock_credit_edges(
        &mut self,
        target_source: &str,
        span: oxc_span::Span,
        has_factory: bool,
    ) {
        self.dynamic_imports.push(DynamicImportInfo {
            source: target_source.to_string(),
            span,
            destructured_names: Vec::new(),
            local_name: None,
            is_speculative: false,
            value_escapes: false,
        });

        if has_factory {
            return;
        }
        // Two candidate conventions: the `__mocks__` sibling next to the
        // mocked module (relative and alias-shaped specifiers, issue #251) and
        // the root-level `__mocks__/<specifier>` manual mock for bare package
        // specifiers (issue #2225). A slash-bearing bare source gets both: for
        // an aliased user module the sibling resolves internally and the root
        // candidate misses, while for a real package the sibling is dropped in
        // package space and the root candidate probes the runner convention.
        for mock_source in [
            vitest_auto_mock_source(target_source),
            root_manual_mock_source(target_source),
        ]
        .into_iter()
        .flatten()
        {
            self.dynamic_imports.push(DynamicImportInfo {
                source: mock_source,
                span,
                destructured_names: Vec::new(),
                local_name: Some(String::new()),
                is_speculative: true,
                value_escapes: false,
            });
        }
    }

    pub(super) fn record_vitest_unmock(&mut self, expr: &CallExpression<'_>) {
        if let Some((object_span, provenance)) = mock_method_object_span(expr, "unmock")
            && let Some(source) = mock_static_target_source(expr)
        {
            self.pending_vitest_mock_operations
                .push(PendingVitestMockOperation {
                    source,
                    object_span,
                    provenance,
                    call_span: expr.span,
                    has_factory: false,
                    needs_deferred_edges: false,
                    proof: PendingVitestMockProof::Unmock,
                });
        }
    }

    pub(crate) fn resolve_vitest_mock_operations(&mut self, spans: &MockApiReferenceSpans) {
        let mut operations: Vec<_> = self
            .pending_vitest_mock_operations
            .drain(..)
            .filter(|operation| match operation.provenance {
                MockObjectProvenance::Binding => {
                    spans.mock_bindings.contains(&operation.object_span)
                }
                MockObjectProvenance::VitestNamespace => {
                    spans.vitest_namespaces.contains(&operation.object_span)
                }
            })
            .collect();
        operations.sort_unstable_by_key(|operation| operation.call_span.start);

        // Provenance is proven now, so push the deferred credit edges for
        // aliased and namespace mock registrations (the literal `vi`/`jest`
        // forms already pushed theirs at record time).
        let deferred_edges: Vec<(String, oxc_span::Span, bool)> = operations
            .iter()
            .filter(|operation| {
                operation.needs_deferred_edges
                    && !matches!(operation.proof, PendingVitestMockProof::Unmock)
            })
            .map(|operation| {
                (
                    operation.source.clone(),
                    operation.call_span,
                    operation.has_factory,
                )
            })
            .collect();
        for (source, span, has_factory) in deferred_edges {
            self.push_mock_credit_edges(&source, span, has_factory);
        }

        self.semantic_facts
            .extend(operations.into_iter().filter_map(|operation| {
                let action = match operation.proof {
                    PendingVitestMockProof::ClosedFactory {
                        binding_requirement_spans,
                        namespace_requirement_spans,
                    } => VitestModuleMockAction::Mock {
                        factory_replaces_original: binding_requirement_spans
                            .iter()
                            .all(|span| spans.mock_bindings.contains(span))
                            && namespace_requirement_spans
                                .iter()
                                .all(|span| spans.vitest_namespaces.contains(span)),
                    },
                    PendingVitestMockProof::UnprovenMock => VitestModuleMockAction::Mock {
                        factory_replaces_original: false,
                    },
                    PendingVitestMockProof::Unmock => VitestModuleMockAction::Unmock,
                    // `doMock` contributes credit edges only; it must never
                    // enter the ordered mask fact stream (issue #2082).
                    PendingVitestMockProof::CreditOnly => return None,
                };
                Some(SemanticFact::VitestModuleMockOperation(
                    VitestModuleMockOperationFact {
                        source: operation.source,
                        call_start: operation.call_span.start,
                        action,
                    },
                ))
            }));
    }
}

/// The base test name a `mergeTests(...)` argument contributes: a bare fixture
/// identifier (`mergeTests(testA, testB)`, issue #1210) or a factory call with a
/// bare identifier callee (`mergeTests(billingTest(), ordersUiTest())`, issue
/// #1795). Other argument shapes (spreads, member-expression callees) abstain.
fn playwright_merge_argument_base_name(argument: &Argument<'_>) -> Option<String> {
    match argument {
        Argument::Identifier(ident) => Some(ident.name.to_string()),
        Argument::CallExpression(call) => match &call.callee {
            Expression::Identifier(callee) => Some(callee.name.to_string()),
            _ => None,
        },
        _ => None,
    }
}