Skip to content

Hoisted constants do not get inlinedΒ #1577

Open
@just-boris

Description

Bug report or Feature request?

Feature request (sub-optimal compression)

Version (complete output of terser -V or specific git commit) 5.37.0

Complete CLI command or minify() options used

{
  module: true,
  compress: {},
  mangle: {},
  output: {},
  parse: {},
  rename: {},
}

terser input

(() => {
  "use strict";
  
  // if the export is here, the constant is not inlined
  window.doSomething = doSomething;

  const isDevelopment = false;

  // if this export is used, the constant will be inlined
  // window.doSomething = doSomething;

  function devWarning(msg) {
    if (isDevelopment) {
      console.warn(msg)
    }
  }

  function doSomething(e) {
    devWarning("for testing");
  }
})();

terser output or error

(()=>{window.doSomething=function(o){t="for testing",n&&console.warn(t);var t};const n=!1})();

Expected result

window.doSomething=function(n){};

P.S. if you are wondering how I got declarations in this order, this is how they were arranged in a bundler output when bundling. I do not have much control on my side how the modules are bundled there, so fixing it here would be nice.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions