-
Notifications
You must be signed in to change notification settings - Fork 12.8k
File altered by before transform does not remove new unused imports #17552
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Currently, whether or not an import is referenced is determined by the checker at check time, prior to emit. We do not re-bind or re-check the AST between transformations, so all check-time state will always be based on the originally parsed AST. The only way to elide an import in this case would be to have the "before" transformer explicitly elide the import. This is currently the intended behavior. We are considering ways of opening up the checker (and our internal |
I'm actually facing the inverse of this problem. Something is being marked as unused (and so the import is elided) but I would like that import to stay. Is there anyway to manage this without checking the entire file and adding the import back in (if it truly is unused) |
Running the `remove-ivy-jit-support-calls` and `remove_decorators` transformers causes the following TS bug microsoft/TypeScript#17552 which is why the `elide-imports` transformer exists in the first place. However, when having a syntax like the below; ```ts import { AccountComponentChild } from '../@types'; export class SignUpComponent implements AccountComponentChild{} ``` The `implements` parts of the class is called a `HeritageClause` with child statements of `ExpressionWithTypeArguments` also the same is for `abstract`. With this change we check the token of the `HeritageClause` and if it's an `ImplementsKeyword` we elide the import. Closes #16907
Running the `remove-ivy-jit-support-calls` and `remove_decorators` transformers causes the following TS bug microsoft/TypeScript#17552 which is why the `elide-imports` transformer exists in the first place. However, when having a syntax like the below; ```ts import { AccountComponentChild } from '../@types'; export class SignUpComponent implements AccountComponentChild{} ``` The `implements` parts of the class is called a `HeritageClause` with child statements of `ExpressionWithTypeArguments` also the same is for `abstract`. With this change we check the token of the `HeritageClause` and if it's an `ImplementsKeyword` we elide the import. Closes #16907
Running the `remove-ivy-jit-support-calls` and `remove_decorators` transformers causes the following TS bug microsoft/TypeScript#17552 which is why the `elide-imports` transformer exists in the first place. However, when having a syntax like the below; ```ts import { AccountComponentChild } from '../@types'; export class SignUpComponent implements AccountComponentChild{} ``` The `implements` parts of the class is called a `HeritageClause` with child statements of `ExpressionWithTypeArguments` also the same is for `abstract`. With this change we check the token of the `HeritageClause` and if it's an `ImplementsKeyword` we elide the import. Closes angular#16907
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:
And replace
const value = something
withThe
import { unused } from 'unused-module';
statement will be removed, butimport { something } from 'some-module';
will remain:TypeScript Version: 2.4.2
Code
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
Expected behavior:
All unused imports are removed.
Actual behavior:
Only imports there were unused before the transformed are removed.
/cc @rbuckton
The text was updated successfully, but these errors were encountered: