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

Merge non-initialized var declarations more aggessively #1446

Open
nicolo-ribaudo opened this issue Sep 15, 2023 · 1 comment
Open

Merge non-initialized var declarations more aggessively #1446

nicolo-ribaudo opened this issue Sep 15, 2023 · 1 comment

Comments

@nicolo-ribaudo
Copy link

Bug report or Feature request?

Sub-optimal output

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

Whatever is on https://try.terser.org/ as of 2023-09-15

Complete CLI command or minify() options used

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

terser input

export function next() {
  var r;
  while (r = stack.pop()) {
    var p = r.d.call(r.v);
    p(p);
  }
}

terser output or error

(note: run through Prettier to make it more readable)

export function next() {
  for (var a; a = stack.pop(); ) {
    var o = a.d.call(a.v);
    o(o);
  }
}

Expected result

export function next() {
  for (; a = stack.pop(); ) {
    var a, o = a.d.call(a.v);
    o(o);
  }
}
@fabiosantoscode
Copy link
Collaborator

This is interesting. Var can indeed be moved anywhere on a function to improve code size, not just here.

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