wasm shell + destructuring

This commit is contained in:
agra
2026-03-03 13:21:54 +02:00
parent 6c5672c7df
commit 004aff5f67
18 changed files with 219 additions and 32 deletions

View File

@@ -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();