Skip to content

formatter: leading JSDoc block before grouped imports panics ("ImportDeclaration must have a source") #22486

@infinity-atom42

Description

@infinity-atom42

Summary

oxfmt panics in sort_imports when a file contains a floating /** … */ JSDoc block (separated from the first import by a blank line) followed by two or more import statements.

Same panic site as #22354, but a distinct trigger that isn't covered by the fix in #22369 (which is shipped in 0.50.0).

Versions / env

  • oxfmt 0.50.0 (released 2026-05-15)
  • macOS 25.4.0, arm64, Node 24.15.0

Minimal repro

repro.ts — four lines is enough:

/** jsdoc */

import * as React from "react";
import { foo } from "bar";
$ oxfmt --threads 1 repro.ts
thread '<unnamed>' panicked at crates/oxc_formatter/src/ir_transform/sort_imports/source_line.rs:139:32:
`ImportDeclaration` must have a source

Bisected trigger

The panic requires all three:

Condition Panics?
/** jsdoc */ + blank + import a + import b yes
/* jsdoc */ (single *) + blank + import a + import b no
// jsdoc line comment + blank + import a + import b no
/** jsdoc */ + import a (attached, no blank) + blank + import b no
/** jsdoc */ + blank + single import a only no

So: JSDoc-style block comment + detached from the first import by a blank line + ≥ 2 imports.

The JSDoc body content doesn't matter (single-line /** x */ is enough). Multiline JSDoc with @see etc. behaves the same — that's just how I originally hit it in a real file.

Expected

Format without panicking — concretely, every ImportDeclaration reaching sort_imports/source_line.rs:139 should have its source set.

Related

Metadata

Metadata

Assignees

Labels

Type

Priority

None yet

Effort

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions