Skip to content

Commit c74f4ef

Browse files
committed
Use rest arguments where possible
> lebab --replace . --transform arg-rest
1 parent c409cd9 commit c74f4ef

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

compiler/prelude/prelude.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ var $flushConsole = function () { };
6161
var $throwRuntimeError; /* set by package "runtime" */
6262
var $throwNilPointerError = function () { $throwRuntimeError("invalid memory address or nil pointer dereference"); };
6363
var $call = function (fn, rcvr, args) { return fn.apply(rcvr, args); };
64-
var $makeFunc = function (fn) { return function () { return $externalize(fn(this, new ($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments, []))), $emptyInterface); }; };
64+
var $makeFunc = function (fn) { return function(...args) { return $externalize(fn(this, new ($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(args, []))), $emptyInterface); }; };
6565
var $unused = function (v) { };
6666
var $print = console.log;
6767
// Under Node we can emulate print() more closely by avoiding a newline.
6868
if (($global.process !== undefined) && $global.require) {
6969
try {
7070
var util = $global.require('util');
71-
$print = function () { $global.process.stderr.write(util.format.apply(this, arguments)); };
71+
$print = function(...args) { $global.process.stderr.write(util.format.apply(this, args)); };
7272
} catch (e) {
7373
// Failed to require util module, keep using console.log().
7474
}
@@ -119,13 +119,13 @@ var $methodVal = function (recv, name) {
119119
var $methodExpr = function (typ, name) {
120120
var method = typ.prototype[name];
121121
if (method.$expr === undefined) {
122-
method.$expr = function () {
122+
method.$expr = function(...args) {
123123
$stackDepthOffset--;
124124
try {
125125
if (typ.wrapped) {
126-
arguments[0] = new typ(arguments[0]);
126+
args[0] = new typ(args[0]);
127127
}
128-
return Function.call.apply(method, arguments);
128+
return Function.call.apply(method, args);
129129
} finally {
130130
$stackDepthOffset++;
131131
}
@@ -138,10 +138,10 @@ var $ifaceMethodExprs = {};
138138
var $ifaceMethodExpr = function (name) {
139139
var expr = $ifaceMethodExprs["$" + name];
140140
if (expr === undefined) {
141-
expr = $ifaceMethodExprs["$" + name] = function () {
141+
expr = $ifaceMethodExprs["$" + name] = function(...args) {
142142
$stackDepthOffset--;
143143
try {
144-
return Function.call.apply(arguments[0][name], arguments);
144+
return Function.call.apply(args[0][name], args);
145145
} finally {
146146
$stackDepthOffset++;
147147
}

compiler/prelude/types.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,15 @@ var $newType = function (size, kind, string, named, pkg, exported, constructor)
280280
$addMethodSynthesizer(function () {
281281
var synthesizeMethod = function (target, m, f) {
282282
if (target.prototype[m.prop] !== undefined) { return; }
283-
target.prototype[m.prop] = function () {
283+
target.prototype[m.prop] = function(...args) {
284284
var v = this.$val[f.prop];
285285
if (f.typ === $jsObjectPtr) {
286286
v = new $jsObjectPtr(v);
287287
}
288288
if (v.$val === undefined) {
289289
v = new f.typ(v);
290290
}
291-
return v[m.prop].apply(v, arguments);
291+
return v[m.prop].apply(v, args);
292292
};
293293
};
294294
fields.forEach(function (f) {
@@ -696,14 +696,14 @@ var $structType = function (pkgPath, fields) {
696696
if (fields.length === 0) {
697697
string = "struct {}";
698698
}
699-
typ = $newType(0, $kindStruct, string, false, "", false, function () {
699+
typ = $newType(0, $kindStruct, string, false, "", false, function(...args) {
700700
this.$val = this;
701701
for (var i = 0; i < fields.length; i++) {
702702
var f = fields[i];
703703
if (f.name == '_') {
704704
continue;
705705
}
706-
var arg = arguments[i];
706+
var arg = args[i];
707707
this[f.prop] = arg !== undefined ? arg : f.typ.zero();
708708
}
709709
});

0 commit comments

Comments
 (0)