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

feat: inline var in function body when possible #2621

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

unbyte
Copy link

@unbyte unbyte commented Oct 20, 2022

This PR inlines var declarations like how let/consts are processed.

It's to be applied only when:

  1. the var declaration belongs to a function body, and
  2. the function is an arrow function, or
  3. the arguments is shadowed

This PR significantly reduced the bundle size of our internal large project, because our target is es5 and there are many code structures like prop: function() { var x = value; return x; }

Example

Input

function test() {
  var x = 1;
  return x;
}

Current Output

function test() {
  var x = 1;
  return x;
}

New Output

function test() {
  return 1;
}

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

Successfully merging this pull request may close these issues.

None yet

1 participant