diff --git a/src/babel/transformation/templates/default-parameter.js b/src/babel/transformation/templates/default-parameter.js index 4e77b53153..3107aa385c 100644 --- a/src/babel/transformation/templates/default-parameter.js +++ b/src/babel/transformation/templates/default-parameter.js @@ -1 +1 @@ -let VARIABLE_NAME = ARGUMENTS[ARGUMENT_KEY] === undefined ? DEFAULT_VALUE : ARGUMENTS[ARGUMENT_KEY]; +let VARIABLE_NAME = ARGUMENTS.length >= ARGUMENT_KEY && ARGUMENTS[ARGUMENT_KEY] === undefined ? DEFAULT_VALUE : ARGUMENTS[ARGUMENT_KEY]; diff --git a/test/core/fixtures/transformation/es6.arrow-functions/default-parameters/expected.js b/test/core/fixtures/transformation/es6.arrow-functions/default-parameters/expected.js index 19e5a5638d..f144e932e6 100644 --- a/test/core/fixtures/transformation/es6.arrow-functions/default-parameters/expected.js +++ b/test/core/fixtures/transformation/es6.arrow-functions/default-parameters/expected.js @@ -1,9 +1,9 @@ "use strict"; var some = function some() { - var count = arguments[0] === undefined ? "30" : arguments[0]; + var count = arguments.length >= 0 && arguments[0] === undefined ? "30" : arguments[0]; console.log("count", count); }; -some(); +some(); \ No newline at end of file diff --git a/test/core/fixtures/transformation/es6.parameters/default-eval/expected.js b/test/core/fixtures/transformation/es6.parameters/default-eval/expected.js index 060d7b250e..919885e563 100644 --- a/test/core/fixtures/transformation/es6.parameters/default-eval/expected.js +++ b/test/core/fixtures/transformation/es6.parameters/default-eval/expected.js @@ -2,7 +2,7 @@ var x = "outside"; function outer() { - var a = arguments[0] === undefined ? function () { + var a = arguments.length >= 0 && arguments[0] === undefined ? function () { return eval("x"); } : arguments[0]; return (function () { @@ -10,4 +10,4 @@ function outer() { return a(); })(); } -outer(); +outer(); \ No newline at end of file diff --git a/test/core/fixtures/transformation/es6.parameters/default-multiple/expected.js b/test/core/fixtures/transformation/es6.parameters/default-multiple/expected.js index 60b1aa031e..0816b3537d 100644 --- a/test/core/fixtures/transformation/es6.parameters/default-multiple/expected.js +++ b/test/core/fixtures/transformation/es6.parameters/default-multiple/expected.js @@ -1,14 +1,14 @@ "use strict"; var t = function t() { - var e = arguments[0] === undefined ? "foo" : arguments[0]; - var f = arguments[1] === undefined ? 5 : arguments[1]; + var e = arguments.length >= 0 && arguments[0] === undefined ? "foo" : arguments[0]; + var f = arguments.length >= 1 && arguments[1] === undefined ? 5 : arguments[1]; return e + " bar " + f; }; var a = function a(e) { - var f = arguments[1] === undefined ? 5 : arguments[1]; + var f = arguments.length >= 1 && arguments[1] === undefined ? 5 : arguments[1]; return e + " bar " + f; -}; +}; \ No newline at end of file diff --git a/test/core/fixtures/transformation/es6.parameters/default-single/expected.js b/test/core/fixtures/transformation/es6.parameters/default-single/expected.js index 0657743b0d..da957eb9b1 100644 --- a/test/core/fixtures/transformation/es6.parameters/default-single/expected.js +++ b/test/core/fixtures/transformation/es6.parameters/default-single/expected.js @@ -1,7 +1,7 @@ "use strict"; var t = function t() { - var f = arguments[0] === undefined ? "foo" : arguments[0]; + var f = arguments.length >= 0 && arguments[0] === undefined ? "foo" : arguments[0]; return f + " bar"; -}; +}; \ No newline at end of file diff --git a/test/core/fixtures/transformation/es6.tail-call/default-parameters/expected.js b/test/core/fixtures/transformation/es6.tail-call/default-parameters/expected.js index 1ccb069bfa..95930020d0 100644 --- a/test/core/fixtures/transformation/es6.tail-call/default-parameters/expected.js +++ b/test/core/fixtures/transformation/es6.tail-call/default-parameters/expected.js @@ -6,9 +6,9 @@ function sum() { _function: while (_again) { a = b = undefined; - var a = _arguments[0] === undefined ? 1 : _arguments[0]; + var a = _arguments.length >= 0 && _arguments[0] === undefined ? 1 : _arguments[0]; _again = false; - var b = _arguments[1] === undefined ? 2 : _arguments[1]; + var b = _arguments.length >= 1 && _arguments[1] === undefined ? 2 : _arguments[1]; if (b > 0) { _arguments = [a + 1, b - 1]; @@ -17,4 +17,4 @@ function sum() { } return a; } -} +} \ No newline at end of file diff --git a/test/core/fixtures/transformation/es6.tail-call/factorial/expected.js b/test/core/fixtures/transformation/es6.tail-call/factorial/expected.js index 005b1e39a2..83d3396f8f 100644 --- a/test/core/fixtures/transformation/es6.tail-call/factorial/expected.js +++ b/test/core/fixtures/transformation/es6.tail-call/factorial/expected.js @@ -8,7 +8,7 @@ function fact(_x2) { var n = _x2; acc = undefined; _again = false; - var acc = _arguments[1] === undefined ? 1 : _arguments[1]; + var acc = _arguments.length >= 1 && _arguments[1] === undefined ? 1 : _arguments[1]; if (n > 1) { _arguments = [_x2 = n - 1, acc * n]; _again = true; @@ -17,4 +17,4 @@ function fact(_x2) { return acc; } } -} +} \ No newline at end of file diff --git a/test/core/fixtures/transformation/es6.tail-call/max-args/expected.js b/test/core/fixtures/transformation/es6.tail-call/max-args/expected.js index 2960fa52d1..3cfa256937 100644 --- a/test/core/fixtures/transformation/es6.tail-call/max-args/expected.js +++ b/test/core/fixtures/transformation/es6.tail-call/max-args/expected.js @@ -7,7 +7,7 @@ var count = function count() { _function: while (_again) { i = undefined; _again = false; - var i = _arguments[0] === undefined ? 10 : _arguments[0]; + var i = _arguments.length >= 0 && _arguments[0] === undefined ? 10 : _arguments[0]; if (!i) return; _arguments = [i - 1]; @@ -23,11 +23,11 @@ function count2() { _function2: while (_again2) { i = undefined; _again2 = false; - var i = _arguments2[0] === undefined ? 10 : _arguments2[0]; + var i = _arguments2.length >= 0 && _arguments2[0] === undefined ? 10 : _arguments2[0]; if (!i) return; _arguments2 = [i - 1]; _again2 = true; continue _function2; } -} +} \ No newline at end of file diff --git a/test/core/fixtures/transformation/es6.tail-call/recursion/expected.js b/test/core/fixtures/transformation/es6.tail-call/recursion/expected.js index ca30fc0ec7..db3834538e 100755 --- a/test/core/fixtures/transformation/es6.tail-call/recursion/expected.js +++ b/test/core/fixtures/transformation/es6.tail-call/recursion/expected.js @@ -11,7 +11,7 @@ var g = function g() {}; _again = false; - var m = _arguments[1] === undefined ? getDefaultValue() : _arguments[1]; + var m = _arguments.length >= 1 && _arguments[1] === undefined ? getDefaultValue() : _arguments[1]; // `m` should be `getDefaultValue()` after first pass if (n <= 0) { @@ -27,4 +27,4 @@ _again = true; continue _function; } -})(1e6, true) === "foo"; +})(1e6, true) === "foo"; \ No newline at end of file diff --git a/test/core/fixtures/transformation/misc/regression-1168/expected.js b/test/core/fixtures/transformation/misc/regression-1168/expected.js index 9ac2b1d6f1..b34103489a 100644 --- a/test/core/fixtures/transformation/misc/regression-1168/expected.js +++ b/test/core/fixtures/transformation/misc/regression-1168/expected.js @@ -1,7 +1,7 @@ "use strict"; function test() { - var x = arguments[0] === undefined ? "hi" : arguments[0]; + var x = arguments.length >= 0 && arguments[0] === undefined ? "hi" : arguments[0]; return x; -} +} \ No newline at end of file