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

Incorrect compressing of top level objects #1307

Closed
grabofus opened this issue Nov 18, 2022 · 1 comment
Closed

Incorrect compressing of top level objects #1307

grabofus opened this issue Nov 18, 2022 · 1 comment
Labels

Comments

@grabofus
Copy link

grabofus commented Nov 18, 2022

Bug report

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

5.15.1

Complete CLI command or minify() options used

{
  module: true,
  compress: true,
  toplevel: true
}

terser input

const obj = {
    value: 'c'
};

export const compare = (x) => x === obj.value;

terser output or error

export const compare=o=>o===obj.value;

Leading to: Uncaught ReferenceError: obj is not defined

Expected result

const c="c";export const compare=o=>o===c;
@grabofus
Copy link
Author

grabofus commented Nov 18, 2022

For context, both of these work as expected:

const obj = {
    value: 'c'
};

const compare = (x) => x === obj.value;

export { compare }

// Outputs:

const c="c",o=o=>o===c;export{o as compare};
const obj = {
    value: 'c'
};

export default (x) => x === obj.value;

// Outputs:

const t="c";export default c=>c===t;

@grabofus grabofus changed the title Incorrect mangling of top level objects Incorrect compressing of top level objects Nov 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants