-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flip default parameter template (#4515)
* Flip default parameter template YMMV, I saved ~10b on a 2kb library. Not noticeable at the small scale, by why not do it anyway? I've (unscientifically) found that flipping the default parameter conditional yields better gzip results. I think this is due to the slightly longer string it can now repeatedly match: ```js // old var param = arguments.length <= 0 || void 0 === arguments[0] ? null : arguments[0] --------------------------------------------------------------^ // new var param = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : null ------------------------------------------------------------------------^ ``` Though it's entirely likely gzip will also choose up to the index of the arguments if you many default parameters at different indexes. * Update tests
- Loading branch information
1 parent
08b45ca
commit c2ed9de
Showing
10 changed files
with
31 additions
and
31 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
packages/babel-core/test/fixtures/transformation/misc/regression-1168/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
function test() { | ||
var x = arguments.length <= 0 || arguments[0] === undefined ? "hi" : arguments[0]; | ||
var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "hi"; | ||
|
||
return x; | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...sform-es2015-arrow-functions/test/fixtures/arrow-functions/default-parameters/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
var some = function () { | ||
let count = arguments.length <= 0 || arguments[0] === undefined ? "30" : arguments[0]; | ||
let count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "30"; | ||
|
||
console.log("count", count); | ||
}; | ||
|
||
var collect = function () { | ||
let since = arguments.length <= 0 || arguments[0] === undefined ? 0 : arguments[0]; | ||
let since = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
let userid = arguments[1]; | ||
|
||
console.log(userid); | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...ugin-transform-es2015-parameters/test/fixtures/parameters/default-before-last/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
function foo() { | ||
var a = arguments.length <= 0 || arguments[0] === undefined ? "foo" : arguments[0]; | ||
var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "foo"; | ||
var b = arguments[1]; | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...abel-plugin-transform-es2015-parameters/test/fixtures/parameters/default-eval/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
var x = "outside"; | ||
function outer() { | ||
var a = arguments.length <= 0 || arguments[0] === undefined ? function () { | ||
var a = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () { | ||
return eval("x"); | ||
} : arguments[0]; | ||
}; | ||
return function () { | ||
var x = "inside"; | ||
return a(); | ||
}(); | ||
} | ||
outer(); | ||
outer(); |
8 changes: 4 additions & 4 deletions
8
...-plugin-transform-es2015-parameters/test/fixtures/parameters/default-multiple/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
var t = function () { | ||
var e = arguments.length <= 0 || arguments[0] === undefined ? "foo" : arguments[0]; | ||
var f = arguments.length <= 1 || arguments[1] === undefined ? 5 : arguments[1]; | ||
var e = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "foo"; | ||
var f = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5; | ||
|
||
return e + " bar " + f; | ||
}; | ||
|
||
var a = function (e) { | ||
var f = arguments.length <= 1 || arguments[1] === undefined ? 5 : arguments[1]; | ||
var f = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 5; | ||
|
||
return e + " bar " + f; | ||
}; | ||
}; |
4 changes: 2 additions & 2 deletions
4
...el-plugin-transform-es2015-parameters/test/fixtures/parameters/default-single/expected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
var t = function () { | ||
var f = arguments.length <= 0 || arguments[0] === undefined ? "foo" : arguments[0]; | ||
var f = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "foo"; | ||
|
||
return f + " bar"; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters