diff options
| author | 2021-05-26 18:13:39 -0700 | |
|---|---|---|
| committer | 2021-05-26 18:13:39 -0700 | |
| commit | 112741dfde4c73a3f3cacd258a05178e6bbab837 (patch) | |
| tree | 80dcbf8865373aef240a86644a532d91ea470190 /src | |
| parent | 8c41ac8b23c5063329772adb1600cb1b312070f4 (diff) | |
| download | bun-112741dfde4c73a3f3cacd258a05178e6bbab837.tar.gz bun-112741dfde4c73a3f3cacd258a05178e6bbab837.tar.zst bun-112741dfde4c73a3f3cacd258a05178e6bbab837.zip | |
Fix base_url always null
Former-commit-id: 831a46191601aad9c8c82ac496955d944cb32f22
Diffstat (limited to 'src')
| -rw-r--r-- | src/resolver/tsconfig_json.zig | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/resolver/tsconfig_json.zig b/src/resolver/tsconfig_json.zig index 52469d6bf..79fb6e677 100644 --- a/src/resolver/tsconfig_json.zig +++ b/src/resolver/tsconfig_json.zig @@ -16,7 +16,7 @@ pub const TSConfigJSON = struct { abs_path: string, // The absolute path of "compilerOptions.baseUrl" - base_url: ?string = null, + base_url: string = "", // This is used if "Paths" is non-nil. It's equal to "BaseURL" except if // "BaseURL" is missing, in which case it is as if "BaseURL" was ".". This @@ -39,6 +39,10 @@ pub const TSConfigJSON = struct { preserve_imports_not_used_as_values: bool = false, + pub fn hasBaseURL(tsconfig: *TSConfigJSON) bool { + return tsconfig.base_url.len > 0; + } + pub const ImportsNotUsedAsValue = enum { preserve, err, @@ -83,13 +87,13 @@ pub const TSConfigJSON = struct { // } // } } + var has_base_url = false; // Parse "compilerOptions" if (json.getProperty("compilerOptions")) |compiler_opts| { - var has_base_url = false; + // Parse "baseUrl" if (compiler_opts.expr.getProperty("baseUrl")) |base_url_prop| { - // maybe we should add a warning when it exists but the value is an array or osmething invalid? if ((base_url_prop.expr.getString(allocator))) |base_url| { result.base_url = base_url; has_base_url = true; @@ -144,7 +148,7 @@ pub const TSConfigJSON = struct { if (compiler_opts.expr.getProperty("paths")) |paths_prop| { switch (paths_prop.expr.data) { .e_object => |paths| { - result.base_url_for_paths = result.base_url orelse "."; + result.base_url_for_paths = result.base_url; result.paths = PathsMap.init(allocator); for (paths.properties) |property| { const key_prop = property.key orelse continue; @@ -230,8 +234,16 @@ pub const TSConfigJSON = struct { } } + if (isDebug and has_base_url) { + std.debug.assert(result.base_url.len > 0); + } + var _result = allocator.create(TSConfigJSON) catch unreachable; _result.* = result; + + if (isDebug and has_base_url) { + std.debug.assert(_result.base_url.len > 0); + } return _result; } |
