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

Inlined function reassigns const variable #2843

Closed
bhollis opened this issue Jan 23, 2018 · 4 comments
Closed

Inlined function reassigns const variable #2843

bhollis opened this issue Jan 23, 2018 · 4 comments

Comments

@bhollis
Copy link

bhollis commented Jan 23, 2018

Bug report or feature request?

Bug report.

ES5 or ES6+ input?

ES6

Uglify version (uglifyjs -V)
uglify-es 3.3.8

JavaScript input

function makeService() {
  function load() {
    return Promise.resolve(null)
      .then((data) => {
        const version = data;

        return Promise.resolve(null)
          .catch((e) => log(version));
      });
  }

  function log(version) {
    console.log(version);
  }

  return load;
}

The uglifyjs CLI command executed or minify() options used.
uglify-es --ecma 6 -b -c -m --harmony -- uglify-bug.js

JavaScript output or error produced.

function makeService() {
    return function() {
        return Promise.resolve(null).then(e => {
            const n = e;
            return Promise.resolve(null).catch(e => (n = n, void console.log(n)));
        });
        var e;
    };
}

I believe this is the same (or related to) #2842 but I wanted to contribute another test case. This is the smallest test case I could make - it didn't repro without the nested promise, or the function returned from a function.

The error is in the assignment n = n in the inlined catch handler - it fails with "Assignment to constant variable."

@kzc
Copy link
Contributor

kzc commented Jan 23, 2018

This is a dup of #2842 and can be closed.
Just use -c inline=1 as a workaround.

@bhollis
Copy link
Author

bhollis commented Jan 23, 2018

Yup, just hoping to offer a different repro.

@alexlamsl
Copy link
Collaborator

@bhollis thanks for providing the details.

In the future please leave this as a comment on #2842 so it is easier for others to follow, and for me to manage this issue tracker.

@kzc
Copy link
Contributor

kzc commented Jan 23, 2018

An ideal uglify test case is a small standalone program that prints out something with console.log that when minified has different behavior. Rather than reasoning the minified code is correct we'd rather just run it and compare results with the original code run.

Promises/async/await currently don't play well with the uglify test sandbox because their actions run asynchronously in the event loop.

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

3 participants