wasm shell + destructuring
This commit is contained in:
@@ -2405,9 +2405,28 @@ pub const Parser = struct {
|
||||
try targets.append(self.allocator, target);
|
||||
}
|
||||
|
||||
// Only plain '=' is allowed
|
||||
// Destructuring declaration: a, b := expr;
|
||||
if (self.current.tag == .colon_equal) {
|
||||
self.advance();
|
||||
// All targets must be plain identifiers
|
||||
var names = std.ArrayList([]const u8).empty;
|
||||
for (targets.items) |target| {
|
||||
if (target.data != .identifier) {
|
||||
return self.fail("destructuring targets must be identifiers");
|
||||
}
|
||||
try names.append(self.allocator, target.data.identifier.name);
|
||||
}
|
||||
const value = try self.parseExpr();
|
||||
try self.expectSemicolonAfter(value);
|
||||
return try self.createNode(start, .{ .destructure_decl = .{
|
||||
.names = try names.toOwnedSlice(self.allocator),
|
||||
.value = value,
|
||||
} });
|
||||
}
|
||||
|
||||
// Multi-target assignment: only plain '=' is allowed
|
||||
if (self.current.tag != .equal) {
|
||||
return self.fail("multi-target assignment requires '='");
|
||||
return self.fail("multi-target assignment requires '=' or ':='");
|
||||
}
|
||||
self.advance();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user