Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Use rest arguments where possible
> lebab --replace . --transform arg-rest
  • Loading branch information
flimzy committed Jun 26, 2023
commit c74f4efb41224aaa8969856412ed7a63c75534e3
14 changes: 7 additions & 7 deletions compiler/prelude/prelude.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ var $flushConsole = function () { };
var $throwRuntimeError; /* set by package "runtime" */
var $throwNilPointerError = function () { $throwRuntimeError("invalid memory address or nil pointer dereference"); };
var $call = function (fn, rcvr, args) { return fn.apply(rcvr, args); };
var $makeFunc = function (fn) { return function () { return $externalize(fn(this, new ($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(arguments, []))), $emptyInterface); }; };
var $makeFunc = function (fn) { return function(...args) { return $externalize(fn(this, new ($sliceType($jsObjectPtr))($global.Array.prototype.slice.call(args, []))), $emptyInterface); }; };
var $unused = function (v) { };
var $print = console.log;
// Under Node we can emulate print() more closely by avoiding a newline.
if (($global.process !== undefined) && $global.require) {
try {
var util = $global.require('util');
$print = function () { $global.process.stderr.write(util.format.apply(this, arguments)); };
$print = function(...args) { $global.process.stderr.write(util.format.apply(this, args)); };
} catch (e) {
// Failed to require util module, keep using console.log().
}
Expand Down Expand Up @@ -119,13 +119,13 @@ var $methodVal = function (recv, name) {
var $methodExpr = function (typ, name) {
var method = typ.prototype[name];
if (method.$expr === undefined) {
method.$expr = function () {
method.$expr = function(...args) {
$stackDepthOffset--;
try {
if (typ.wrapped) {
arguments[0] = new typ(arguments[0]);
args[0] = new typ(args[0]);
}
return Function.call.apply(method, arguments);
return Function.call.apply(method, args);
} finally {
$stackDepthOffset++;
}
Expand All @@ -138,10 +138,10 @@ var $ifaceMethodExprs = {};
var $ifaceMethodExpr = function (name) {
var expr = $ifaceMethodExprs["$" + name];
if (expr === undefined) {
expr = $ifaceMethodExprs["$" + name] = function () {
expr = $ifaceMethodExprs["$" + name] = function(...args) {
$stackDepthOffset--;
try {
return Function.call.apply(arguments[0][name], arguments);
return Function.call.apply(args[0][name], args);
} finally {
$stackDepthOffset++;
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/prelude/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,15 @@ var $newType = function (size, kind, string, named, pkg, exported, constructor)
$addMethodSynthesizer(function () {
var synthesizeMethod = function (target, m, f) {
if (target.prototype[m.prop] !== undefined) { return; }
target.prototype[m.prop] = function () {
target.prototype[m.prop] = function(...args) {
var v = this.$val[f.prop];
if (f.typ === $jsObjectPtr) {
v = new $jsObjectPtr(v);
}
if (v.$val === undefined) {
v = new f.typ(v);
}
return v[m.prop].apply(v, arguments);
return v[m.prop].apply(v, args);
};
};
fields.forEach(function (f) {
Expand Down Expand Up @@ -696,14 +696,14 @@ var $structType = function (pkgPath, fields) {
if (fields.length === 0) {
string = "struct {}";
}
typ = $newType(0, $kindStruct, string, false, "", false, function () {
typ = $newType(0, $kindStruct, string, false, "", false, function(...args) {
this.$val = this;
for (var i = 0; i < fields.length; i++) {
var f = fields[i];
if (f.name == '_') {
continue;
}
var arg = arguments[i];
var arg = args[i];
this[f.prop] = arg !== undefined ? arg : f.typ.zero();
}
});
Expand Down