aboutsummaryrefslogtreecommitdiff
path: root/src/js_ast.zig
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-05-05 03:09:59 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-05-05 03:09:59 -0700
commit6be0a4653fa62ba8c9ae1c62ba4c56f46f00d7b6 (patch)
tree3d6e882ab97a49333c7df6a7a25085a5aa7361b6 /src/js_ast.zig
parent08961dc3ce04cb615bc81a7ccc62cd53f2d126d1 (diff)
downloadbun-6be0a4653fa62ba8c9ae1c62ba4c56f46f00d7b6.tar.gz
bun-6be0a4653fa62ba8c9ae1c62ba4c56f46f00d7b6.tar.zst
bun-6be0a4653fa62ba8c9ae1c62ba4c56f46f00d7b6.zip
damn tho
Former-commit-id: e1df98878d2dea8530d50d49e8e5b9369931eb43
Diffstat (limited to 'src/js_ast.zig')
-rw-r--r--src/js_ast.zig63
1 files changed, 55 insertions, 8 deletions
diff --git a/src/js_ast.zig b/src/js_ast.zig
index c362e7486..d8b5d6f89 100644
--- a/src/js_ast.zig
+++ b/src/js_ast.zig
@@ -900,10 +900,57 @@ pub const E = struct {
pub const Spread = struct { value: ExprNodeIndex };
pub const String = struct {
- value: JavascriptString,
+ value: JavascriptString = &([_]u16{}),
+ utf8: string = &([_]u8{}),
legacy_octal_loc: ?logger.Loc = null,
prefer_template: bool = false,
+ pub fn isUTF8(s: *const String) bool {
+ return s.utf8.len > 0;
+ }
+
+ pub fn eql(s: *const String, comptime _t: type, other: anytype) bool {
+ if (s.isUTF8()) {
+ switch (_t) {
+ @This() => {
+ if (other.isUTF8()) {
+ return strings.eql(s.utf8, other.utf8);
+ } else {
+ return strings.utf16EqlString(other.value, s.utf8);
+ }
+ },
+ string => {
+ return strings.eql(s.utf8, other);
+ },
+ JavascriptString => {
+ return strings.utf16EqlString(other, s.utf8);
+ },
+ else => {
+ @compileError("Invalid type");
+ },
+ }
+ } else {
+ switch (_t) {
+ @This() => {
+ if (other.isUTF8()) {
+ return strings.utf16EqlString(s.value, other.utf8);
+ } else {
+ return std.mem.eql(u16, other.value, s.value);
+ }
+ },
+ string => {
+ return strings.utf16EqlString(other.utf8, s.value);
+ },
+ JavascriptString => {
+ return std.mem.eql(u16, other.value, s.value);
+ },
+ else => {
+ @compileError("Invalid type");
+ },
+ }
+ }
+ }
+
pub fn string(s: *String, allocator: *std.mem.Allocator) !string {
return try std.unicode.utf16leToUtf8Alloc(allocator, s.value);
}
@@ -2721,27 +2768,27 @@ pub const Op = struct {
new,
call,
member,
- pub fn lt(self: Level, b: Level) callconv(.Inline) bool {
+ pub fn lt(self: Level, b: Level) bool {
return @enumToInt(self) < @enumToInt(b);
}
- pub fn gt(self: Level, b: Level) callconv(.Inline) bool {
+ pub fn gt(self: Level, b: Level) bool {
return @enumToInt(self) > @enumToInt(b);
}
- pub fn gte(self: Level, b: Level) callconv(.Inline) bool {
+ pub fn gte(self: Level, b: Level) bool {
return @enumToInt(self) >= @enumToInt(b);
}
- pub fn lte(self: Level, b: Level) callconv(.Inline) bool {
+ pub fn lte(self: Level, b: Level) bool {
return @enumToInt(self) <= @enumToInt(b);
}
- pub fn eql(self: Level, b: Level) callconv(.Inline) bool {
+ pub fn eql(self: Level, b: Level) bool {
return @enumToInt(self) == @enumToInt(b);
}
- pub fn sub(self: Level, comptime i: anytype) callconv(.Inline) Level {
+ pub fn sub(self: Level, i: anytype) Level {
return @intToEnum(Level, @enumToInt(self) - i);
}
- pub fn add(self: Level, comptime i: anytype) callconv(.Inline) Level {
+ pub fn add(self: Level, i: anytype) Level {
return @intToEnum(Level, @enumToInt(self) + i);
}
};