You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
File altered by before transform does not remove new unused imports #17552
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 EmitResolver) to custom transformations to allow more control, but that likely won't be ready in the 2.5 release timeframe.
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)
This is not a compiler bug. In TypeScript 2.4.2, import usage is determined during checking, before before transformers run. A transformer can replace something with somethingElse, but that does not cause the checker to re-bind or re-check the transformed tree, so the original something import remains classified as used for emit.
A before transformer that makes an import unused must explicitly remove that import as part of its transformation. Automatically rechecking arbitrary transformed ASTs during emit is not supported.
Activity
rbuckton commentedon Aug 23, 2017
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
EmitResolver) to custom transformations to allow more control, but that likely won't be ready in the 2.5 release timeframe.arciisine commentedon Aug 26, 2017
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)
fix(@ngtools/webpack): elide imports for `implements` keywords
fix(@ngtools/webpack): elide imports for `implements` keywords
fix(@ngtools/webpack): elide imports for `implements` keywords
fix(@ngtools/webpack): elide imports for `implements` keywords
RyanCavanaugh commentedon Aug 26, 2026
This is not a compiler bug. In TypeScript 2.4.2, import usage is determined during checking, before
beforetransformers run. A transformer can replacesomethingwithsomethingElse, but that does not cause the checker to re-bind or re-check the transformed tree, so the originalsomethingimport remains classified as used for emit.A
beforetransformer that makes an import unused must explicitly remove that import as part of its transformation. Automatically rechecking arbitrary transformed ASTs during emit is not supported.