Fix: default rest argument array elements as undefined (#14032)

This commit is contained in:
Sneh Khatri 2021-12-14 02:21:57 +05:30 committed by GitHub
parent add64e870b
commit a7acde3885
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 38 additions and 0 deletions

View File

@ -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)) {

View File

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

View File

@ -0,0 +1,4 @@
function func(...arguments) {
console.log(arguments); // [1, 2, 3]
}
func(1, 2, 3);

View File

@ -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);

View File

@ -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]])

View File

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

View File

@ -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);