evanw / esbuild

An extremely fast bundler for the web
https://esbuild.github.io/
MIT License
38.22k stars 1.16k forks source link

Unused code is left when minifying #3899

Open just-boris opened 2 months ago

just-boris commented 2 months ago

When a constant value imported from a different module, it is not inlined properly. Reproducible in the online playground.

import { isDevelopment } from "./is-development";

export function devWarning() {
 if(isDevelopment) {
   console.log('test')
 }
}

export function run() {
  devWarning('dev only');
}

is-development.js contents

export const isDevelopment = false; 
// does not work either 
// export const isDevelopment = process.env.NODE_ENV !== "production";

The output still contains an unused function: function o(){!1}. Expected to eliminate all this code, as it happens in a single file setup