diff options
| author | 2023-05-04 22:44:02 -0700 | |
|---|---|---|
| committer | 2023-05-04 22:44:02 -0700 | |
| commit | d9386a68a4316052f355235a7ff4f4b5eb0a2722 (patch) | |
| tree | 183845717e420645e2ab3b5705dc87b393b726b9 /src/sourcemap/sourcemap.zig | |
| parent | 945d069290fcf0ce852120b809ed8aa6cdd1e245 (diff) | |
| download | bun-d9386a68a4316052f355235a7ff4f4b5eb0a2722.tar.gz bun-d9386a68a4316052f355235a7ff4f4b5eb0a2722.tar.zst bun-d9386a68a4316052f355235a7ff4f4b5eb0a2722.zip | |
fix source map line offsets (#2791)
* find codepoint at `i`
* fix allocator usage
* missing comment
* switch to `Cursor` iterator
Diffstat (limited to 'src/sourcemap/sourcemap.zig')
| -rw-r--r-- | src/sourcemap/sourcemap.zig | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/sourcemap/sourcemap.zig b/src/sourcemap/sourcemap.zig index b7441ccc9..cc557caf1 100644 --- a/src/sourcemap/sourcemap.zig +++ b/src/sourcemap/sourcemap.zig @@ -356,17 +356,16 @@ pub const LineColumnOffset = struct { std.debug.assert(i >= offset); std.debug.assert(i < input.len); - offset = i + 1; + var iter = strings.CodepointIterator.initOffset(input, i); + var cursor = strings.CodepointIterator.Cursor{ .i = @truncate(u32, iter.i) }; + _ = iter.next(&cursor); + offset = i + cursor.width; - var cp = strings.CodepointIterator.initOffset(input, offset); - var cursor = strings.CodepointIterator.Cursor{}; - _ = cp.next(&cursor); switch (cursor.c) { '\r', '\n', 0x2028, 0x2029 => { // Handle Windows-specific "\r\n" newlines - if (cp.c == '\r' and input.len > offset + 1 and input[offset + 1] == '\n') { + if (cursor.c == '\r' and input.len > i + 1 and input[i + 1] == '\n') { columns += 1; - offset += 1; continue; } |
