From fd41a41ab929b35ef384f90f3cb24e6c597d6e97 Mon Sep 17 00:00:00 2001 From: Zack Radisic <56137411+zackradisic@users.noreply.github.com> Date: Tue, 9 Sep 2025 20:49:59 -0700 Subject: [PATCH] remove dead code --- src/sourcemap/sourcemap.zig | 183 ------------------------------------ 1 file changed, 183 deletions(-) diff --git a/src/sourcemap/sourcemap.zig b/src/sourcemap/sourcemap.zig index 2335201bd0..4fcbeb1d08 100644 --- a/src/sourcemap/sourcemap.zig +++ b/src/sourcemap/sourcemap.zig @@ -1045,189 +1045,6 @@ fn findSourceMappingURL(comptime T: type, source: []const T, alloc: std.mem.Allo }; } -fn findSourceMappingURLNah(comptime T: type, source: []const T, alloc: std.mem.Allocator) ?bun.jsc.ZigString.Slice { - // According to the spec, we need to find the LAST valid sourceMappingURL - // We need to handle both //# and //@ prefixes, and also /* */ comments - var last_url: ?bun.jsc.ZigString.Slice = null; - var i: usize = 0; - - const solidus = comptime bun.strings.literal(T, "/")[0]; - const asterisk = comptime bun.strings.literal(T, "*")[0]; - const newline = comptime bun.strings.literal(T, "\n")[0]; - const carriage_return = comptime bun.strings.literal(T, "\r")[0]; - - // Line terminators as per ECMAScript spec - // Note: For UTF-8, these would be multi-byte sequences, so we only check them in UTF-16 - const line_separator: T = if (T == u16) 0x2028 else newline; - const paragraph_separator: T = if (T == u16) 0x2029 else newline; - - while (i < source.len) { - // Skip to next potential comment - const slash_pos = std.mem.indexOfScalarPos(T, source, i, solidus) orelse break; - i = slash_pos + 1; - - if (i >= source.len) break; - - const next_char = source[i]; - - // Handle single-line comment // - if (next_char == solidus) { - i += 1; - const comment_start = i; - - // Find end of line - var line_end = source.len; - var j = comment_start; - while (j < source.len) : (j += 1) { - const c = source[j]; - if (c == newline or c == carriage_return or - (T == u16 and (c == line_separator or c == paragraph_separator))) - { - line_end = j; - break; - } - } - - const comment = source[comment_start..line_end]; - if (matchSourceMappingURL(T, comment, alloc)) |url| { - // Free previous URL if any - if (last_url) |prev| prev.deinit(); - last_url = url; - } - - i = line_end; - } - // Handle multi-line comment /* */ - else if (next_char == asterisk) { - i += 1; - const comment_start = i; - - // Find closing */ - var found_end = false; - while (i + 1 < source.len) : (i += 1) { - if (source[i] == asterisk and source[i + 1] == solidus) { - const comment = source[comment_start..i]; - if (matchSourceMappingURL(T, comment, alloc)) |url| { - // Free previous URL if any - if (last_url) |prev| prev.deinit(); - last_url = url; - } - i += 2; - found_end = true; - break; - } - } - - if (!found_end) { - // Unclosed comment - ignore rest of file - break; - } - } - // Not a comment - check if it's whitespace - else { - // Back up to check the character before the slash - const before_slash = slash_pos; - if (before_slash > 0) { - var j = before_slash - 1; - // Check backwards for non-whitespace on this line - while (j > 0) : (j -%= 1) { - const c = source[j]; - if (c == newline or c == carriage_return or - (T == u16 and (c == line_separator or c == paragraph_separator))) - { - // Hit line boundary, this slash starts the line (after whitespace) - break; - } - if (!isWhitespace(T, c)) { - // Non-whitespace found - reset last_url per spec - if (last_url) |prev| { - prev.deinit(); - last_url = null; - } - break; - } - if (j == 0) break; - } - } - } - } - - return last_url; -} - -// Helper function to match sourceMappingURL pattern in a comment -fn matchSourceMappingURL(comptime T: type, comment: []const T, alloc: std.mem.Allocator) ?bun.jsc.ZigString.Slice { - // Pattern: ^[@#]\s*sourceMappingURL=(\S*?)\s*$ - var i: usize = 0; - - // Skip leading whitespace - while (i < comment.len and isWhitespace(T, comment[i])) : (i += 1) {} - - if (i >= comment.len) return null; - - // Check for @ or # prefix - const at_sign = comptime bun.strings.literal(T, "@")[0]; - const hash = comptime bun.strings.literal(T, "#")[0]; - - if (comment[i] != at_sign and comment[i] != hash) return null; - i += 1; - - // Skip whitespace after prefix - while (i < comment.len and isWhitespace(T, comment[i])) : (i += 1) {} - - // Check for "sourceMappingURL=" - const mapping_text = comptime bun.strings.literal(T, "sourceMappingURL="); - if (i + mapping_text.len > comment.len) return null; - - const text_part = comment[i .. i + mapping_text.len]; - if (!std.mem.eql(T, text_part, mapping_text)) return null; - - i += mapping_text.len; - - // Find the URL (non-whitespace characters) - const url_start = i; - while (i < comment.len and !isWhitespace(T, comment[i])) : (i += 1) {} - - if (url_start == i) return null; // Empty URL - - const url = comment[url_start..i]; - - // Verify rest is only whitespace - while (i < comment.len) : (i += 1) { - if (!isWhitespace(T, comment[i])) return null; - } - - // Return the URL as a ZigString.Slice - return switch (T) { - u8 => bun.jsc.ZigString.Slice.fromUTF8NeverFree(url), - u16 => bun.jsc.ZigString.Slice.init( - alloc, - bun.strings.toUTF8Alloc(alloc, url) catch bun.outOfMemory(), - ), - else => @compileError("Not Supported"), - }; -} - -// Helper to check if a character is whitespace -fn isWhitespace(comptime T: type, char: T) bool { - return switch (char) { - '\t', '\n', '\r', ' ', 0x0B, 0x0C => true, - else => { - if (T == u16) { - return switch (char) { - 0xA0, // non-breaking space - 0xFEFF, // BOM - 0x2028, // line separator - 0x2029, // paragraph separator - => true, - else => false, - }; - } - return false; - }, - }; -} - /// The last two arguments to this specify loading hints pub fn getSourceMapImpl( comptime SourceProviderKind: type,