Skip to content

Typescript, deferred imports incorrectly detected as cycles #1241

Description

@bannable

Versions tested: 0.8.35, 0.8.37

// modal.ts
import {hideModal} from './actions';

export function Modal(): void {
  hideModal();
}
// actions.ts
export function showModal(): void {
  void import('./modal').then((m) => m.Modal());
}

export function hideModal(): void {}
from graphify.analyze import find_import_cycles
from graphify.build import build_from_json
from graphify.extract import extract

def test_deferred_import_is_not_a_cycle():
    result = extract(
        ["modal.ts", "actions.ts"]
    )
    graph = build_from_json(result)
    cycles = find_import_cycles(graph)

    assert cycles == [], (
        "deferred import() was counted as a static import edge and reported "
        f"as a circular dependency: {cycles}"
    )

test_deferred_import_is_not_a_cycle()

I suspect this kind of pattern is what led to the cycling in #1196, so it might be worth keeping track of whether the import is deferred while computing cycles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions