aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-08-11 19:43:53 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-08-11 19:43:53 -0700
commitd51d39ef320ed6ca0ba2931dd408323b1a778ca3 (patch)
tree4607654baa6622c0df3e3cea183354d493b59fea
parent70912ec46f4633e474625539c49c19dcfb3d9823 (diff)
downloadbun-d51d39ef320ed6ca0ba2931dd408323b1a778ca3.tar.gz
bun-d51d39ef320ed6ca0ba2931dd408323b1a778ca3.tar.zst
bun-d51d39ef320ed6ca0ba2931dd408323b1a778ca3.zip
Add missing jsonStringify
Former-commit-id: d94dfa2ed1ff26079c091331ebcf7d6bfb68df69
-rw-r--r--src/js_ast.zig109
1 files changed, 79 insertions, 30 deletions
diff --git a/src/js_ast.zig b/src/js_ast.zig
index 3f032e075..8797e4c62 100644
--- a/src/js_ast.zig
+++ b/src/js_ast.zig
@@ -157,12 +157,18 @@ pub const ImportItemStatus = enum(u2) {
// The printer will replace this import with "undefined"
missing,
+ pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
};
pub const AssignTarget = enum(u2) {
none,
replace, // "a = b"
update, // "a += b"
+ pub fn jsonStringify(self: *const @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
};
pub const LocRef = struct { loc: logger.Loc, ref: ?Ref };
@@ -292,6 +298,10 @@ pub const Binding = struct {
b_property,
b_object,
b_missing,
+
+ pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
};
pub var icount: usize = 0;
@@ -456,6 +466,9 @@ pub const G = struct {
get,
set,
spread,
+ pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
};
};
@@ -693,6 +706,10 @@ pub const Symbol = struct {
// This annotates all other symbols that don't have special behavior.
other,
+
+ pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
};
pub const Use = struct {
@@ -778,12 +795,17 @@ pub const Symbol = struct {
pub const OptionalChain = enum(u2) {
-// "a?.b"
-start,
+ // "a?.b"
+ start,
+
+ // "a?.b.c" => ".c" is OptionalChainContinue
+ // "(a?.b).c" => ".c" is OptionalChain null
+ ccontinue,
-// "a?.b.c" => ".c" is OptionalChainContinue
-// "(a?.b).c" => ".c" is OptionalChain null
-ccontinue };
+ pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
+};
pub const E = struct {
pub const Array = struct {
@@ -1578,6 +1600,10 @@ pub const Stmt = struct {
s_while,
s_with,
+ pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
+
pub fn isExportLike(tag: Tag) bool {
return switch (tag) {
.s_export_clause, .s_export_default, .s_export_equals, .s_export_from, .s_export_star, .s_empty => true,
@@ -2462,6 +2488,10 @@ pub const Expr = struct {
e_class,
e_require,
+ pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
+
pub fn isArray(self: Tag) bool {
switch (self) {
.e_array => {
@@ -3257,6 +3287,9 @@ pub const S = struct {
k_var,
k_let,
k_const,
+ pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
};
};
@@ -3350,6 +3383,10 @@ pub const Op = struct {
bin_logical_or_assign,
bin_logical_and_assign,
+ pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
+
pub fn unaryAssignTarget(code: Op.Code) AssignTarget {
if (@enumToInt(code) >= @enumToInt(Op.Code.un_pre_dec) and @enumToInt(code) <= @enumToInt(Op.Code.un_post_inc)) {
return AssignTarget.update;
@@ -3595,31 +3632,36 @@ pub const Span = struct {
};
pub const ExportsKind = enum {
-// This file doesn't have any kind of export, so it's impossible to say what
-// kind of file this is. An empty file is in this category, for example.
-none,
-
-// The exports are stored on "module" and/or "exports". Calling "require()"
-// on this module returns "module.exports". All imports to this module are
-// allowed but may return undefined.
-cjs,
-
-// All export names are known explicitly. Calling "require()" on this module
-// generates an exports object (stored in "exports") with getters for the
-// export names. Named imports to this module are only allowed if they are
-// in the set of export names.
-esm,
-
-// Some export names are known explicitly, but others fall back to a dynamic
-// run-time object. This is necessary when using the "export * from" syntax
-// with either a CommonJS module or an external module (i.e. a module whose
-// export names are not known at compile-time).
-//
-// Calling "require()" on this module generates an exports object (stored in
-// "exports") with getters for the export names. All named imports to this
-// module are allowed. Direct named imports reference the corresponding export
-// directly. Other imports go through property accesses on "exports".
-esm_with_dyn };
+ // This file doesn't have any kind of export, so it's impossible to say what
+ // kind of file this is. An empty file is in this category, for example.
+ none,
+
+ // The exports are stored on "module" and/or "exports". Calling "require()"
+ // on this module returns "module.exports". All imports to this module are
+ // allowed but may return undefined.
+ cjs,
+
+ // All export names are known explicitly. Calling "require()" on this module
+ // generates an exports object (stored in "exports") with getters for the
+ // export names. Named imports to this module are only allowed if they are
+ // in the set of export names.
+ esm,
+
+ // Some export names are known explicitly, but others fall back to a dynamic
+ // run-time object. This is necessary when using the "export * from" syntax
+ // with either a CommonJS module or an external module (i.e. a module whose
+ // export names are not known at compile-time).
+ //
+ // Calling "require()" on this module generates an exports object (stored in
+ // "exports") with getters for the export names. All named imports to this
+ // module are allowed. Direct named imports reference the corresponding export
+ // directly. Other imports go through property accesses on "exports".
+ esm_with_dyn,
+
+ pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
+};
pub fn isDynamicExport(exp: ExportsKind) bool {
return kind == .cjs || kind == .esm_with_dyn;
@@ -3725,6 +3767,9 @@ pub const StrictModeKind = enum(u7) {
implicit_strict_mode_export,
implicit_strict_mode_top_level_await,
implicit_strict_mode_class,
+ pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
};
pub const Scope = struct {
@@ -3772,6 +3817,10 @@ pub const Scope = struct {
entry, // This is a module, TypeScript enum, or TypeScript namespace
function_args,
function_body,
+
+ pub fn jsonStringify(self: @This(), opts: anytype, o: anytype) !void {
+ return try std.json.stringify(@tagName(self), opts, o);
+ }
};
pub fn recursiveSetStrictMode(s: *Scope, kind: StrictModeKind) void {