Skip to content

Remove unused pure functions and variables #639

@devongovett

Description

@devongovett

Esbuild doesn't currently seem to remove unused pure functions or variables. For example this input:

(function() {
  var x = 2;

  function foo() {
    console.log('foo');
  }

  function bar() {
    console.log('bar');
  }

  foo();
})();

Currently produces this output:

(function(){var n=2;function o(){console.log("foo")}function c(){console.log("bar")}o()})();

Whereas terser produces:

console.log("foo");

That's obviously even more optimized in this case to get rid of the function declaration entirely, but I'd accept at least just removing the unused vars and functions. We're considering esbuild as an alternative minifier in Parcel, but we don't currently have our own DCE pass and rely on terser for this. This means that the output will typically be much larger than it is currently without either Parcel implementing its own DCE or esbuild doing so.

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