Fix: default rest argument array elements as undefined (#14032)
This commit is contained in:
parent
add64e870b
commit
a7acde3885
@ -242,6 +242,8 @@ export default function convertFunctionRest(path) {
|
|||||||
|
|
||||||
let rest = node.params.pop().argument;
|
let rest = node.params.pop().argument;
|
||||||
|
|
||||||
|
if (rest.name === "arguments") scope.rename(rest.name);
|
||||||
|
|
||||||
const argsId = t.identifier("arguments");
|
const argsId = t.identifier("arguments");
|
||||||
|
|
||||||
if (t.isPattern(rest)) {
|
if (t.isPattern(rest)) {
|
||||||
|
|||||||
@ -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);
|
||||||
Loading…
x
Reference in New Issue
Block a user