dsherret / dsherret/ts-morph

fixUnusedIdentifiers doesn't work on `js` files

Open
#1,376 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
6.2k
Forks
238
Avg merge
2m
Merged PRs (30d)
1

Description

**Describe the bug**

Version: 17.0.1

**To Reproduce**
When using `fixUnusedIdentifiers` on source of a js file, this error occurs `Error: Could not find source file`

To reproduce:
```ts
import { Project } from 'ts-morph';

const project = new Project();
project.addSourceFilesAtPaths([`src/**/*.{ts,js}`]);

const sources = project.getSourceFiles();

sources.forEach(sourceFile => {
sourceFile.fixUnusedIdentifiers();
});
```
i also have `src` folder with `file.js`

```ts
// file.js
const test = 'test'
```

When i run this code i get this error:
```
Error: Could not find source file: '.../test/file.js'.
at getValidSourceFile (.../node_modules/@ts-morph/common/dist/typescript.js:169206:29)
....
```

**Expected behavior**
Should fix unused identifiers or at least not fail

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.