aboutsummaryrefslogtreecommitdiff
path: root/src/js_ast.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/js_ast.zig')
-rw-r--r--src/js_ast.zig19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/js_ast.zig b/src/js_ast.zig
index 6e017849e..f3a10b683 100644
--- a/src/js_ast.zig
+++ b/src/js_ast.zig
@@ -2948,6 +2948,14 @@ pub const Expr = struct {
// This should never make it to the printer
inline_identifier,
+ // object, regex and array may have had side effects
+ pub fn isPrimitiveLiteral(tag: Tag) bool {
+ return switch (tag) {
+ .e_null, .e_undefined, .e_string, .e_boolean, .e_number, .e_big_int => true,
+ else => false,
+ };
+ }
+
pub fn typeof(tag: Tag) ?string {
return switch (tag) {
.e_array, .e_object, .e_null, .e_reg_exp => "object",
@@ -3745,6 +3753,17 @@ pub const Expr = struct {
};
}
+ pub fn toFiniteNumber(data: Expr.Data) ?f64 {
+ return switch (data) {
+ .e_boolean => @as(f64, if (data.e_boolean.value) 1.0 else 0.0),
+ .e_number => if (std.math.isFinite(data.e_number.value))
+ data.e_number.value
+ else
+ null,
+ else => null,
+ };
+ }
+
pub const Equality = struct { equal: bool = false, ok: bool = false };
// Returns "equal, ok". If "ok" is false, then nothing is known about the two