Skip to content

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

Closed
@hulkish

Description

@hulkish

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions