Skip to content

Codegen: Avoid useless zero subtraction in rest arguments #12188

Closed
@subzey

Description

@subzey

Currenty the function like this:

const foo = (...args: any[]): void => {
}

is transpiled into

var foo = function () {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i - 0] = arguments[_i];
    }
};

You may notice that zero subtraction in the args[_i-0] part is useless.

My proposal is to drop it and use just args[_i] in cases when the function signature consists only of spread.
This small change won't affect the generated code behavior, but would make it slightly more readable and compact.

You can preview the results here, and here's the proposed change

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedA PR has been merged for this issueHelp WantedYou can do thisSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions