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

missing JS minification #3964

Open
Inqnuam opened this issue Nov 5, 2024 · 0 comments
Open

missing JS minification #3964

Inqnuam opened this issue Nov 5, 2024 · 0 comments

Comments

@Inqnuam
Copy link

Inqnuam commented Nov 5, 2024

Original code:

import { DEV } from "./constants";

function reportError() {
  if (DEV) {
    const message = "some useful message"
    throw new Error(message)
  } else {
    throw new Error("ERROR_CODE x2242");
  }
}

export { reportError };

bundled & minified output (--minify --bundle --format=esm):

function E(){if(!1){let r="some useful message";throw new Error(r)}else throw new Error("ERROR_CODE x2242")}export{E as reportError};

expected output:

function E(){throw new Error("ERROR_CODE x2242")}export{E as reportError};

Works perfectly when DEV boolean is defined in the same file

const DEV = false

function reportError() {
  if (DEV) {
    const message = "some useful message"
    throw new Error(message)
  } else {
    throw new Error("ERROR_CODE x2242");
  }
}
export { reportError };

or when there's no variable declaration inside if (DEV) condition

import { DEV } from "./constants";

function reportError() {
  if (DEV) {
    throw new Error("some useful message")
  } else {
    throw new Error("ERROR_CODE x2242");
  }
}

export { reportError };

minimal repro link https://esbuild.github.io/try/#YgAwLjI0LjAALS1taW5pZnkgLS1idW5kbGUgLS1mb3JtYXQ9ZXNtAGUAZW50cnkuanMAaW1wb3J0IHsgREVWIH0gZnJvbSAiLi9jb25zdGFudHMiOwoKZnVuY3Rpb24gcmVwb3J0RXJyb3IoKSB7CiAgaWYgKERFVikgewogICAgIGNvbnN0IG1lc3NhZ2UgPSAic29tZSB1c2VmdWwgbWVzc2FnZSIKICAgICB0aHJvdyBuZXcgRXJyb3IobWVzc2FnZSkKICB9IGVsc2UgewogICAgdGhyb3cgbmV3IEVycm9yKCJFUlJPUl9DT0RFIHgyMjQyIik7CiAgfQp9CgpleHBvcnQgeyByZXBvcnRFcnJvciB9OwoAAGNvbnN0YW50cwBleHBvcnQgY29uc3QgREVWID0gZmFsc2U7

or try to build @sveltejs for browser.

Thanks @evanw 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants