From 09b934891818b7a4df6327e3b6712e110d38f75f Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Mon, 17 Oct 2016 10:09:55 -0500 Subject: [PATCH] Avoid unnecessary +0 in transform-es2015-parameters (#4738) --- packages/babel-plugin-transform-es2015-parameters/src/rest.js | 3 +++ .../test/fixtures/parameters/regression-4348/expected.js | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/babel-plugin-transform-es2015-parameters/src/rest.js b/packages/babel-plugin-transform-es2015-parameters/src/rest.js index e1bd77594959a..70b3666770f1d 100644 --- a/packages/babel-plugin-transform-es2015-parameters/src/rest.js +++ b/packages/babel-plugin-transform-es2015-parameters/src/rest.js @@ -161,6 +161,9 @@ function optimiseIndexGetter(path, argsId, offset) { if (t.isNumericLiteral(path.parent.property)) { index = t.numericLiteral(path.parent.property.value + offset); + } else if (offset === 0) { + // Avoid unnecessary '+ 0' + index = path.parent.property; } else { index = t.binaryExpression("+", path.parent.property, t.numericLiteral(offset)); } diff --git a/packages/babel-plugin-transform-es2015-parameters/test/fixtures/parameters/regression-4348/expected.js b/packages/babel-plugin-transform-es2015-parameters/test/fixtures/parameters/regression-4348/expected.js index 2cee31ca38cf3..72353b43e3298 100644 --- a/packages/babel-plugin-transform-es2015-parameters/test/fixtures/parameters/regression-4348/expected.js +++ b/packages/babel-plugin-transform-es2015-parameters/test/fixtures/parameters/regression-4348/expected.js @@ -2,5 +2,5 @@ function first() { var _ref; var index = 0; - return _ref = index++ + 0, arguments.length <= _ref ? undefined : arguments[_ref]; + return _ref = index++, arguments.length <= _ref ? undefined : arguments[_ref]; }