Skip to content

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

@AlexandreBonaventure

Description

@AlexandreBonaventure

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions