diff options
author | 2021-04-29 20:22:25 -0700 | |
---|---|---|
committer | 2021-04-29 20:22:25 -0700 | |
commit | 24d1479ea825cfc6c7ec8f74780bc72b7cd6bc8e (patch) | |
tree | 4606fc2c9bb798717c5e06b5ca825b5f54df9947 /src/defines.zig | |
parent | 3731376943862e17646b477bc98ce3871f064e99 (diff) | |
download | bun-24d1479ea825cfc6c7ec8f74780bc72b7cd6bc8e.tar.gz bun-24d1479ea825cfc6c7ec8f74780bc72b7cd6bc8e.tar.zst bun-24d1479ea825cfc6c7ec8f74780bc72b7cd6bc8e.zip |
hm
Former-commit-id: 2567243c8db7a60a5ba8ca7c662beca080cfa4f4
Diffstat (limited to 'src/defines.zig')
-rw-r--r-- | src/defines.zig | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/defines.zig b/src/defines.zig index 173e5dd0f..740d0d80e 100644 --- a/src/defines.zig +++ b/src/defines.zig @@ -30,6 +30,7 @@ pub const UserDefines = std.StringHashMap(DefineData); pub const DefineData = struct { value: js_ast.Expr.Data, + valueless: bool = false, original_name: ?string = null, // True if accessing this value is known to not have any side effects. For @@ -46,6 +47,10 @@ pub const DefineData = struct { // So we can create just one struct for it. pub const GlobalDefineData = DefineData{}; + pub fn isUndefined(self: *const DefineData) bool { + return self.valueless; + } + pub fn merge(a: DefineData, b: DefineData) DefineData { return DefineData{ .value = b.value, @@ -142,7 +147,7 @@ pub const Define = struct { dots: std.StringHashMap([]DotDefine), allocator: *std.mem.Allocator, - pub fn init(allocator: *std.mem.Allocator, user_defines: UserDefines) !*@This() { + pub fn init(allocator: *std.mem.Allocator, _user_defines: ?UserDefines) !*@This() { var define = try allocator.create(Define); define.allocator = allocator; define.identifiers = std.StringHashMap(IdentifierDefine).init(allocator); @@ -155,7 +160,7 @@ pub const Define = struct { var ident_define = IdentifierDefine{ .value = val, }; - var value_define = DefineData{ .value = val }; + var value_define = DefineData{ .value = val, .valueless = true }; // Step 1. Load the globals into the hash tables for (GlobalDefinesKey) |global| { if (global.len == 1) { @@ -204,7 +209,7 @@ pub const Define = struct { // Step 3. Load user data into hash tables // At this stage, user data has already been validated. - if (user_defines.count() > 0) { + if (_user_defines) |user_defines| { var iter = user_defines.iterator(); while (iter.next()) |user_define| { // If it has a dot, then it's a DotDefine. |