diff options
author | 2023-04-17 17:13:01 -0700 | |
---|---|---|
committer | 2023-04-17 17:13:01 -0700 | |
commit | 4505be7ff9bf66f8fa38c0aaa26a1fb76048bb6d (patch) | |
tree | 8b4bf174e04247849a4f475c2a5edb4a3d6b2a46 | |
parent | a17624942e834875287c2b8b35b45954e91a67c3 (diff) | |
download | bun-dylan/change-pathname-assert.tar.gz bun-dylan/change-pathname-assert.tar.zst bun-dylan/change-pathname-assert.zip |
only if dir existsdylan/change-pathname-assert
-rw-r--r-- | src/fs.zig | 2 | ||||
-rw-r--r-- | src/string_immutable.zig | 10 | ||||
-rw-r--r-- | test/bundler/esbuild/default.test.ts | 4 |
3 files changed, 13 insertions, 3 deletions
diff --git a/src/fs.zig b/src/fs.zig index db0685936..0da1ed184 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -1100,7 +1100,7 @@ pub const PathName = struct { } if (comptime Environment.allow_assert) { - std.debug.assert(!strings.includes(self.base, "/")); + if (self.dir.len > 0) std.debug.assert(!strings.includes(self.base, "/")); } // /bar/foo.js -> foo diff --git a/src/string_immutable.zig b/src/string_immutable.zig index bc0b59ea0..f44afdce6 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -224,6 +224,16 @@ pub fn indexOfSigned(self: string, str: string) i32 { } pub inline fn lastIndexOfChar(self: string, char: u8) ?usize { + if (comptime Environment.isLinux) { + const memrchr = struct { + pub extern fn memrchr(ptr: [*]const u8, val: c_int, len: usize) ?[*]const u8; + }.memrchr; + const start = memrchr(self.ptr, char, self.len) orelse return null; + const i = @ptrToInt(start) - @ptrToInt(self.ptr); + std.debug.assert(i < self.len); + return @intCast(usize, i); + } + return std.mem.lastIndexOfScalar(u8, self, char); } diff --git a/test/bundler/esbuild/default.test.ts b/test/bundler/esbuild/default.test.ts index d504bd4da..c3421224d 100644 --- a/test/bundler/esbuild/default.test.ts +++ b/test/bundler/esbuild/default.test.ts @@ -5953,9 +5953,9 @@ describe("bundler", () => { 'Could not resolve: "@scope/pkg4". Maybe you need to "bun install"?', 'Could not resolve: "@scope/pkg5/foo". Maybe you need to "bun install"?', 'Could not resolve: "@abs-path/pkg6". Maybe you need to "bun install"?', - 'Could not resolve: "@abs-path/pkg6/foo". Maybe you need to "bun install"?', + 'Could not resolve: "@abs-path/pkg7/foo". Maybe you need to "bun install"?', 'Could not resolve: "@scope-only/pkg8". Maybe you need to "bun install"?', - 'Could not resolve: "slash/" Maybe. you need to "bun install"?', + 'Could not resolve: "slash/". Maybe you need to "bun install"?', 'Could not resolve: "pkg3". Maybe you need to "bun install"?', ], }, |