Skip to content

Typescript should not be doing code removal for non TS code #30525

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

Closed
hulkish opened this issue Mar 21, 2019 · 6 comments
Closed

Typescript should not be doing code removal for non TS code #30525

hulkish opened this issue Mar 21, 2019 · 6 comments
Labels
Duplicate An existing issue was already created

Comments

@hulkish
Copy link

hulkish commented Mar 21, 2019

Please see babel/babel#9723 (comment)

This code removal is actually unsafe. For example, if foo had side effects - how can typescript know its safe to remove the import, without processing that file first? Aka, this is a task for a bundler/compiler.

Search Terms:
remove import, code remove

Code

import foo from 'foo';
export bar from 'bar';
export * as baz from 'baz';

export default class Foobar {}

Expected behavior:

import foo from 'foo'; // why is this line is removed?
import _bar from 'bar';
export { _bar as bar };
import * as _baz from 'baz';
export { _baz as baz };
var Foobar = function Foobar() {};
export { Foobar as default };

Actual behavior:

import _bar from 'bar';
export { _bar as bar };
import * as _baz from 'baz';
export { _baz as baz };
export default class Foobar {}

Playground Link:
https://www.typescriptlang.org/play/#src=import%20foo%20from%20'foo'%3B%0D%0Aexport%20bar%20from%20'bar'%3B%0D%0Aexport%20*%20as%20baz%20from%20'baz'%3B%0D%0A%0D%0Aexport%20default%20class%20Foobar%20%7B%7D

Related Issues:
babel/babel#9723 (comment)

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 21, 2019
@RyanCavanaugh
Copy link
Member

Duplicate #9191 and dozens of other issues discussing this

@hulkish
Copy link
Author

hulkish commented Mar 21, 2019

@RyanCavanaugh Fair enough, however - I landed here after looking to fix this in @babel/plugin-transform-typescript. And, that issue you've referenced hasn't had activity in months. What do you recommend?

@RyanCavanaugh
Copy link
Member

import "foo"; if you need the side effects

@hulkish
Copy link
Author

hulkish commented Mar 21, 2019

But, this doesn't remove the problem of typescript incorrectly doing code removal.

@RyanCavanaugh
Copy link
Member

You can write

foo;

if you're depending on the specific identifier being in the file

@typescript-bot
Copy link
Collaborator

This issue has been marked as a 'Duplicate' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

3 participants