Skip to content

Commit

Permalink
Fix: default rest argument array elements as undefined (#14032)
Browse files Browse the repository at this point in the history
  • Loading branch information
The-x-Theorist committed Dec 13, 2021
1 parent add64e8 commit a7acde3
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 0 deletions.
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) {
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);

0 comments on commit a7acde3

Please sign in to comment.