diff options
author | 2021-10-16 21:33:09 -0700 | |
---|---|---|
committer | 2021-10-16 21:33:09 -0700 | |
commit | be66c01829200113c138a04468d6fc3d8c9eb277 (patch) | |
tree | 4780ddd81a576b7af0852ece3a1dc2fb422a7f0b | |
parent | 21b9884606970efa0992d69e1b489c862e4e48f0 (diff) | |
download | bun-be66c01829200113c138a04468d6fc3d8c9eb277.tar.gz bun-be66c01829200113c138a04468d6fc3d8c9eb277.tar.zst bun-be66c01829200113c138a04468d6fc3d8c9eb277.zip |
Update js_ast.zig
-rw-r--r-- | src/js_ast.zig | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/js_ast.zig b/src/js_ast.zig index 91698d344..885366b6d 100644 --- a/src/js_ast.zig +++ b/src/js_ast.zig @@ -2033,6 +2033,23 @@ pub const Expr = struct { return exp.data.e_import; } + pub fn hasAnyPropertyNamed(expr: *const Expr, comptime names: []const string) bool { + if (std.meta.activeTag(expr.data) != .e_object) return false; + const obj = expr.data.e_object; + if (@ptrToInt(obj.properties.ptr) == 0) return false; + + for (obj.properties) |prop| { + const value = prop.value orelse continue; + const key = prop.key orelse continue; + if (std.meta.activeTag(key.data) != .e_string) continue; + const key_str = key.data.e_string; + if (strings.eqlAnyComptime(key_str.utf8, names)) return true; + } + + return false; + } + + // Making this comptime bloats the binary and doesn't seem to impact runtime performance. pub fn asProperty(expr: *const Expr, name: string) ?Query { if (std.meta.activeTag(expr.data) != .e_object) return null; const obj = expr.data.e_object; |