JavaScript: moving an import joins it into one under `// @ts-ignore`

Open
#9,791 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Domain
devtools

Research direction

The join logic is in rewrite-javascript/rewrite/src/javascript/recipes/change-import.ts, where ChangeImport merges a moved member into an existing import from the target module. Start there and check whether the comment directly above that import is considered. Reproduce with oldModule ./old.ts, oldMember a, newModule ./m.ts on the before example. Done when the moved member gets its own statement under the ts-ignore comment and merging into unrelated imports still works as before.

Written by the indexing model from the issue text.

Description

bug javascript

Potentially related:

  • #9789: the same join ignores import attributes

ChangeImport (org.openrewrite.javascript.change-import) joins a moved member into an existing import of the target module even when a // @ts-ignore sits above that import. The directive then also hides errors for the moved member, such as the target module not exporting it, which is the error a move most needs to surface.

Verified on 8d2c9b668a with new ChangeImport({oldModule: "./old.ts", oldMember: "a", newModule: "./m.ts"}).

1. Moved member joined under // @ts-ignore

Before

import {a} from "./old.ts";
// @ts-ignore
import {b} from "./m.ts";

a(b);

After (problem)

// @ts-ignore
import {a, b} from "./m.ts";

a(b);

After (expected)

import {a} from "./m.ts";
// @ts-ignore
import {b} from "./m.ts";

a(b);

Expected rule: don't join a moved or added member into an import directly below // @ts-ignore or // @ts-expect-error; keep or add a statement of its own.

Dominant language
Java
Stars
3.9k
Forks
599
Avg merge
9h 38m
Merged PRs (30d)
557

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openrewrite/rewrite

All issues in openrewrite/rewrite

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.