Skip to content
This repository was archived by the owner on Apr 18, 2026. It is now read-only.
This repository was archived by the owner on Apr 18, 2026. It is now read-only.

Optimize output of rest param transformer #2116

Description

@arv

In a strict function if all accesses of the rest param is rest[expr] and rest.length we could generate code that only references arguments.

For example:

'use strict';
function f(x, ...xs) {
  for (let i = 0; i < xs.length; i++) {
    print(xs[i]);
  }
}

Today we compile that into:

'use strict';
function f(x) {
  for (var xs = [],
      $__0 = 1; $__0 < arguments.length; $__0++)
    xs[$__0 - 1] = arguments[$__0];
  for (var i = 0; i < xs.length; i++) {
    print(xs[i]);
  }
}

But we could compile it into:

'use strict';
function f(x) {
  for (var i = 0; i < arguments.length - 1; i++) {
    print(arguments[i + 1]);
  }
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions