aboutsummaryrefslogtreecommitdiff
path: root/src/js_ast.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-04 21:42:49 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-04 21:42:49 -0700
commitd034c004f99cb660b88ed95a851d92291c45b7cb (patch)
tree8b6122581cf859cecf7e303fd9ba2a7c968faa8a /src/js_ast.zig
parent7ba61bc98341c1a357a8b0a9323643d6162976e0 (diff)
downloadbun-d034c004f99cb660b88ed95a851d92291c45b7cb.tar.gz
bun-d034c004f99cb660b88ed95a851d92291c45b7cb.tar.zst
bun-d034c004f99cb660b88ed95a851d92291c45b7cb.zip
Implement `bun init` subcommand
Diffstat (limited to 'src/js_ast.zig')
-rw-r--r--src/js_ast.zig17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/js_ast.zig b/src/js_ast.zig
index eb28091c9..aa53efadd 100644
--- a/src/js_ast.zig
+++ b/src/js_ast.zig
@@ -1335,6 +1335,21 @@ pub const E = struct {
return if (asProperty(self, key)) |query| query.expr else @as(?Expr, null);
}
+ pub fn put(self: *Object, allocator: std.mem.Allocator, key: string, expr: Expr) !void {
+ if (asProperty(self, key)) |query| {
+ self.properties.ptr[query.i].value = expr;
+ } else {
+ try self.properties.push(allocator, .{
+ .key = Expr.init(E.String, E.String.init(key), expr.loc),
+ .value = expr,
+ });
+ }
+ }
+
+ pub fn putString(self: *Object, allocator: std.mem.Allocator, key: string, value: string) !void {
+ return try put(self, allocator, key, Expr.init(E.String, E.String.init(value), logger.Loc.Empty));
+ }
+
pub const SetError = error{ OutOfMemory, Clobber };
pub fn set(self: *const Object, key: Expr, allocator: std.mem.Allocator, value: Expr) SetError!void {
@@ -1502,7 +1517,7 @@ pub const E = struct {
for (obj.properties.slice()) |prop| {
const key = prop.key orelse continue;
if (std.meta.activeTag(key.data) != .e_string) continue;
- if (key.eql(string, name)) return true;
+ if (key.data.e_string.eql(string, name)) return true;
}
return false;
}