Skip to content

Commit 2dc0286

Browse files
committed
Use ES2015 syntax for more compact context save/restore.
1 parent fa8544d commit 2dc0286

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

compiler/package.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -823,10 +823,8 @@ func translateFunction(typ *ast.FuncType, recv *ast.Ident, body *ast.BlockStmt,
823823
functionName = " $b"
824824
}
825825
var stores, loads string
826-
for _, v := range c.localVars {
827-
loads += fmt.Sprintf("%s = $f.%s; ", v, v)
828-
stores += fmt.Sprintf("$f.%s = %s; ", v, v)
829-
}
826+
loads = fmt.Sprintf("({%s} = $f); ", strings.Join(c.localVars, ", "))
827+
stores = fmt.Sprintf("$f = {...$f, %s};", strings.Join(c.localVars, ", "))
830828
prefix = prefix + " var $f, $c = false; if (this !== undefined && this.$blk !== undefined) { $f = this; $c = true; " + loads + "}"
831829
suffix = " if ($f === undefined) { $f = { $blk: " + funcRef + " }; } " + stores + "return $f;" + suffix
832830
}

0 commit comments

Comments
 (0)