Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ let mime = mime_type::by_extension(b"html"); // MimeType
let mime = mime_type::by_extension_no_default(b"xyz"); // Option<MimeType>

mime.category // Category::Javascript | Css | Html | Json | Image | Text | Wasm | ...
mime.category.is_code()
mime.category.is_text_like()
```

Common constants: `JAVASCRIPT`, `JSON`, `HTML`, `CSS`, `TEXT`, `WASM`, `ICO`, `OTHER`.
Expand Down
21 changes: 0 additions & 21 deletions src/http_types/MimeType.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,6 @@ pub fn create_hash_table() -> Result<Map, bun_alloc::AllocError> {
Ok(map)
}

impl MimeType {
pub fn can_open_in_editor(&self) -> bool {
if self.category == Category::Text || self.category.is_code() {
return true;
}

if self.category == Category::Image {
return self.value.as_ref() == b"image/svg+xml";
}

false
}
}

#[derive(Clone, Copy, PartialEq, Eq, Debug, strum::IntoStaticStr)]
#[strum(serialize_all = "lowercase")]
Comment thread
claude[bot] marked this conversation as resolved.
pub enum Category {
Expand Down Expand Up @@ -305,13 +291,6 @@ impl Category {
Category::Other
}

pub fn is_code(self) -> bool {
matches!(
self,
Category::Wasm | Category::Json | Category::Css | Category::Html | Category::Javascript
)
}

pub fn is_text_like(self) -> bool {
matches!(
self,
Expand Down
30 changes: 0 additions & 30 deletions src/http_types/URLPath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,7 @@
_decoded_storage: Option<Box<[u8]>>,
}

impl URLPath {

Check warning on line 31 in src/http_types/URLPath.rs

View check run for this annotation

Claude / Claude Code Review

Cascade: is_source_map field orphaned by path_without_asset_prefix removal

🟡 Same cascade pattern on the `URLPath` side: deleting `path_without_asset_prefix()` orphans the `pub is_source_map: bool` struct field (line 18) — its sole reader was the deleted `if self.is_source_map && out.ends_with(b".map")`, and the Zig field's only reader is inside `pathWithoutAssetPrefix` (documented dead-in-Zig in this PR's table). The field decl and its struct-literal write at line ~176 could go in the same sweep. Note: the *local* `is_source_map` in `parse()` (lines 146/148/171) is st

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 🟡 Same cascade pattern on the URLPath side: deleting path_without_asset_prefix() orphans the pub is_source_map: bool struct field (line 18) — its sole reader was the deleted if self.is_source_map && out.ends_with(b".map"), and the Zig field's only reader is inside pathWithoutAssetPrefix (documented dead-in-Zig in this PR's table). The field decl and its struct-literal write at line ~176 could go in the same sweep. Note: the local is_source_map in parse() (lines 146/148/171) is still live — only the struct field is dead.

Extended reasoning...

What this is

Not a correctness bug — an incomplete sweep, the same one-hop-downstream cascade already addressed for Category::is_code() in commit f730821. Deleting URLPath::path_without_asset_prefix() removes the only reader of the pub is_source_map: bool struct field, so the field now meets the identical "0 Rust readers / dead in Zig too" criterion this PR uses for the other deletions.

Step-by-step proof that the struct field is now dead

  1. Rust side, before this PR: the only read of self.is_source_map was inside path_without_asset_prefix() at the line being deleted:
    if self.is_source_map && out.ends_with(b".map") {
        return &out[0..out.len() - 4];
    }
  2. Rust side, after this PR: grepping all *.rs for is_source_map yields only URLPath.rs hits — the field declaration at :18, the local variable in parse() at :146/:148/:171, and the struct-literal write at :176. None of the six Rust files that reference URLPath (fetch.rs, filesystem_router.rs, router/lib.rs, http_types/lib.rs, http/lib.rs) touch the field. Zero field readers remain.
  3. Zig side: the field is declared at URLPath.zig:11 and written at :135. Its only read is URLPath.zig:28, inside pathWithoutAssetPrefix — which the PR description's own table documents as having 0 callers (its only caller isRoot is itself dead). So the field is transitively dead in Zig too.
  4. Conclusion: URLPath::is_source_map meets the same "0 Rust readers / dead in Zig too" bar that justified deleting is_root() / path_without_asset_prefix() / can_open_in_editor(), and is the exact analogue of the is_code() cascade already accepted and fixed.

What is not dead

The local let is_source_map = extname == b"map"; at parse():146 is still live — it drives the extname/path recomputation at :148 and :171. Only the struct field (line 18) and its assignment in the struct literal (line 176, plus the doc comment at 16–17) are dead.

Why nothing else flags this

The field is pub, so rustc's dead-code lint won't fire. There's no test or external consumer reading it. It survives only because it's one hop downstream of the function being deleted, and the sweep stopped at the first level — same as is_code() was before the follow-up commit.

Impact

None on runtime behavior — purely about completing the cleanup. Leaving the field in place is harmless; a later sweep would catch it.

Suggested fix

Either:

  • Extend this PR to also delete pub is_source_map: bool (URLPath.rs:16-18) and the is_source_map, line in the struct literal (:176) — the local variable stays, or
  • Intentionally keep it as parser output for Zig-port parity — in which case feel free to disregard.

pub fn is_root(&self, asset_prefix: &[u8]) -> bool {
let without = self.path_without_asset_prefix(asset_prefix);
if without.len() == 1 && without[0] == b'.' {
return true;
}
without == b"index"
}

// TODO: use a real URL parser
// this treats a URL like /_next/ identically to /
pub fn path_without_asset_prefix(&self, asset_prefix: &[u8]) -> &[u8] {
if asset_prefix.is_empty() {
return self.path;
}
let leading_slash_offset: usize = if asset_prefix[0] == b'/' { 1 } else { 0 };
let base = self.path;
let origin = &asset_prefix[leading_slash_offset..];

let out = if base.len() >= origin.len() && &base[0..origin.len()] == origin {
&base[origin.len()..]
} else {
base
};
if self.is_source_map && out.ends_with(b".map") {
return &out[0..out.len() - 4];
}

out
}

/// Take ownership of the percent-decode buffer, if `parse()` had to
/// allocate one. The slice fields of `self` keep pointing into the
/// returned allocation — the caller must keep it alive for as long as any
Expand Down
Loading