support default values (#4442)

This commit is contained in:
Alex Lam S.L
2020-12-23 22:22:55 +00:00
committed by GitHub
parent 56fce2131c
commit 2390fae5c4
10 changed files with 1430 additions and 208 deletions

View File

@@ -702,6 +702,8 @@ function OutputStream(options) {
// (false, true) ? (a = 10, b = 20) : (c = 30)
// ==> 20 (side effect, set a := 10 and b := 20)
|| p instanceof AST_Conditional
// [ a = (1, 2) ] = [] ==> a == 2
|| p instanceof AST_DefaultValue
// { [(1, 2)]: 3 }[2] ==> 3
// { foo: (1, 2) }.foo ==> 2
|| p instanceof AST_DestructuredKeyVal
@@ -1218,6 +1220,15 @@ function OutputStream(options) {
}
});
DEFPRINT(AST_DefaultValue, function(output) {
var self = this;
self.name.print(output);
output.space();
output.print("=");
output.space();
self.value.print(output);
});
/* -----[ other expressions ]----- */
function print_call_args(self, output) {
if (self.expression instanceof AST_Call || self.expression instanceof AST_Lambda) {