Skip to content
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

Discrepancy with TS compiler in import elision with preserveValueImports:true #2268

Closed
AlexandreBonaventure opened this issue May 26, 2022 · 1 comment

Comments

@AlexandreBonaventure
Copy link

Hello,

I'm copying the comment from @sapphi-red found in this vite issue: vitejs/vite#8339 (comment)


Repro

import { type Map } from 'mapbox-gl';

let MyMap:Map

When preserveValueImports is true, the output behavior differs from TypeScript compiler. I thought a bit strange about the TS compiler's behavior at first, but it seems intended.

Esbuild

import {} from "mapbox-gl";
let MyMap;

TS compiler remove the import line

let MyMap;

"preserveValueImports":true (esbuild repl) "preserveValueImports":true (ts playground)

Expected behaviour

Esbuild should probably behave like TS compiler in this case and remove the whole unused import line, otherwise it is keeping an empty import line which breaks tree-shaking/code-splitting in bundlers using esbuild like vite


When preserveValueImports is false, no discrepancies, it becomes:

let MyMap;

"preserveValueImports":false (esbuild repl) "preserveValueImports":false (ts playground)

@evanw
Copy link
Owner

evanw commented May 26, 2022

Thanks for the report. I can confirm the issue, and will fix this in the next release.

@evanw evanw closed this as completed in 4b34056 May 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants