Skip to content

File altered by before transform does not remove new unused imports #17552

Open
@filipesilva

Description

@filipesilva

Description of the bug:

When using a before transform that makes an import unused, the import will not be removed by TypeScript.

So if I have:

import { unused } from 'unused-module';
import { something } from 'some-module';
const value = something;

And replace const value = something with

import { somethingElse } from 'some-other-module';
const value = somethingElse;

The import { unused } from 'unused-module'; statement will be removed, but import { something } from 'some-module'; will remain:

import { something } from 'some-module';
import { somethingElse } from 'some-other-module';
const value = somethingElse;

TypeScript Version: 2.4.2

Code

import { unused } from 'unused-module';
import { something } from 'some-module';
const value = something;

Reproduction of this bug requires using the transforms API.

I have prepared a repository with a simple reproduction that runs this file: https://github.com/filipesilva/ts-transform-import-bug/blob/master/test.ts

git clone https://github.com/filipesilva/ts-transform-import-bug
cd ts-transform-decorator-bug
npm install
npm test

Expected behavior:
All unused imports are removed.

import { somethingElse } from 'some-other-module';
const value = somethingElse;

Actual behavior:
Only imports there were unused before the transformed are removed.

import { something } from 'some-module';
import { somethingElse } from 'some-other-module';
const value = somethingElse;

/cc @rbuckton

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIRelates to the public API for TypeScriptBugA bug in TypeScriptDomain: TransformsRelates to the public transform API

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions