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

Fix: default rest argument array elements as undefined #14032

Merged
merged 5 commits into from Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/babel-plugin-transform-parameters/src/rest.ts
Expand Up @@ -242,6 +242,8 @@ export default function convertFunctionRest(path) {

let rest = node.params.pop().argument;

if (rest.name === "arguments") scope.rename(rest.name);

const argsId = t.identifier("arguments");

if (t.isPattern(rest)) {
Expand Down
@@ -0,0 +1,4 @@
function func(...arguments) {
The-x-Theorist marked this conversation as resolved.
Show resolved Hide resolved
return arguments;
}
expect(func(1, 2, 3)).toStrictEqual([1, 2, 3])
@@ -0,0 +1,4 @@
function func(...arguments) {
console.log(arguments); // [1, 2, 3]
}
func(1, 2, 3);
@@ -0,0 +1,9 @@
function func() {
for (var _len = arguments.length, _arguments = new Array(_len), _key = 0; _key < _len; _key++) {
_arguments[_key] = arguments[_key];
}

console.log(_arguments); // [1, 2, 3]
}

func(1, 2, 3);
@@ -0,0 +1,5 @@
function func(a, b, ...arguments) {
return [a, b, arguments];
}

expect(func('a', 'b', 1, 2, 3)).toStrictEqual(['a', 'b', [1, 2, 3]])
@@ -0,0 +1,5 @@
function func(a, b, ...arguments) {
return [a, b, arguments];
}

func('a', 'b', 1, 2, 3)
@@ -0,0 +1,9 @@
function func(a, b) {
for (var _len = arguments.length, _arguments = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
_arguments[_key - 2] = arguments[_key];
}

return [a, b, _arguments];
}

func('a', 'b', 1, 2, 3);