aboutsummaryrefslogtreecommitdiff
path: root/src/ast
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-04-26 19:22:17 -0700
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2021-04-26 19:22:17 -0700
commit70b6f889c7509ae6944469e1c45ed9b755b2ceec (patch)
treee8c7d48c576fbaed33046c557c959d85c5c35c1e /src/ast
parent97ce2513dc71271503ebd746ac5e9e0f57858bb7 (diff)
downloadbun-70b6f889c7509ae6944469e1c45ed9b755b2ceec.tar.gz
bun-70b6f889c7509ae6944469e1c45ed9b755b2ceec.tar.zst
bun-70b6f889c7509ae6944469e1c45ed9b755b2ceec.zip
lots
Diffstat (limited to 'src/ast')
-rw-r--r--src/ast/base.zig50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/ast/base.zig b/src/ast/base.zig
index 744b7e2d9..f941e3745 100644
--- a/src/ast/base.zig
+++ b/src/ast/base.zig
@@ -1,4 +1,5 @@
-const unicode = @import("std").unicode;
+const std = @import("std");
+const unicode = std.unicode;
pub const JavascriptString = []u16;
pub fn newJavascriptString(comptime text: []const u8) JavascriptString {
@@ -7,3 +8,50 @@ pub fn newJavascriptString(comptime text: []const u8) JavascriptString {
pub const NodeIndex = u32;
pub const NodeIndexNone = 4294967293;
+
+// TODO: figure out if we actually need this
+// -- original comment --
+// Files are parsed in parallel for speed. We want to allow each parser to
+// generate symbol IDs that won't conflict with each other. We also want to be
+// able to quickly merge symbol tables from all files into one giant symbol
+// table.
+//
+// We can accomplish both goals by giving each symbol ID two parts: a source
+// index that is unique to the parser goroutine, and an inner index that
+// increments as the parser generates new symbol IDs. Then a symbol map can
+// be an array of arrays indexed first by source index, then by inner index.
+// The maps can be merged quickly by creating a single outer array containing
+// all inner arrays from all parsed files.
+pub const Ref = packed struct {
+ source_index: Int = std.math.maxInt(Ref.Int),
+ inner_index: Int = 0,
+
+ // 2 bits of padding for whatever is the parent
+ pub const Int = u31;
+ pub const None = Ref{ .inner_index = std.math.maxInt(Ref.Int) };
+ pub fn isNull(self: *const Ref) bool {
+ return self.source_index == std.math.maxInt(Ref.Int) and self.inner_index == std.math.maxInt(Ref.Int);
+ }
+
+ pub fn isSourceNull(self: *const Ref) bool {
+ return self.source_index == std.math.maxInt(Ref.Int);
+ }
+
+ pub fn isSourceIndexNull(int: Ref.Int) bool {
+ return int == std.math.maxInt(Ref.Int);
+ }
+
+ pub fn eql(ref: Ref, b: Ref) bool {
+ return ref.inner_index == b.inner_index and ref.source_index == b.source_index;
+ }
+};
+
+// This is kind of the wrong place, but it's shared between files
+pub const RequireOrImportMeta = struct {
+ // CommonJS files will return the "require_*" wrapper function and an invalid
+ // exports object reference. Lazily-initialized ESM files will return the
+ // "init_*" wrapper function and the exports object for that file.
+ wrapper_ref: Ref = Ref.None,
+ exports_ref: Ref = Ref.None,
+ is_wrapper_async: bool = false,
+};