Skip to content

Use spread operator to get the arguments more safely #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* will remain to ensure logic does not differ in production.
*/

var invariant = function(condition, format, a, b, c, d, e, f) {
var invariant = function(condition, format, ...args) {
if (process.env.NODE_ENV !== 'production') {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
Expand All @@ -33,7 +33,6 @@ var invariant = function(condition, format, a, b, c, d, e, f) {
'for the full error message and additional helpful warnings.'
);
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(
format.replace(/%s/g, function() { return args[argIndex++]; })
Expand Down
3 changes: 1 addition & 2 deletions invariant.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

var NODE_ENV = process.env.NODE_ENV;

var invariant = function(condition, format, a, b, c, d, e, f) {
var invariant = function(condition, format, ...args) {
if (NODE_ENV !== 'production') {
if (format === undefined) {
throw new Error('invariant requires an error message argument');
Expand All @@ -35,7 +35,6 @@ var invariant = function(condition, format, a, b, c, d, e, f) {
'for the full error message and additional helpful warnings.'
);
} else {
var args = [a, b, c, d, e, f];
var argIndex = 0;
error = new Error(
format.replace(/%s/g, function() { return args[argIndex++]; })
Expand Down
2 changes: 1 addition & 1 deletion invariant.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
declare module.exports: (
condition: any,
format?: string,
...args: Array<any>
args?: Array<any>
) => void;