Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(854)

Unified Diff: pkg/compiler/lib/src/io/line_column_provider.dart

Issue 877753008: Fix shift in source map positions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add test. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/io/line_column_provider.dart
diff --git a/pkg/compiler/lib/src/io/line_column_provider.dart b/pkg/compiler/lib/src/io/line_column_provider.dart
index 5aa700cca4a738e5a909b00bf1e7e1c7070a678a..4d17583fb9f5b972cf93b2dbf67c7811e4b4faa9 100644
--- a/pkg/compiler/lib/src/io/line_column_provider.dart
+++ b/pkg/compiler/lib/src/io/line_column_provider.dart
@@ -18,20 +18,19 @@ abstract class LineColumnProvider {
/// [CodeOutputListener] that collects line information.
class LineColumnCollector extends CodeOutputListener
implements LineColumnProvider {
- int lastLineStart = 0;
+ int length = 0;
List<int> lineStarts = <int>[0];
void _collect(String text) {
- int offset = lastLineStart;
int index = 0;
while (index < text.length) {
// Unix uses '\n' and Windows uses '\r\n', so this algorithm works for
// both platforms.
index = text.indexOf('\n', index) + 1;
if (index <= 0) break;
- lastLineStart = offset + index;
- lineStarts.add(lastLineStart);
+ lineStarts.add(length + index);
}
+ length += text.length;
}
@override
@@ -43,7 +42,7 @@ class LineColumnCollector extends CodeOutputListener
int getLine(int offset) {
List<int> starts = lineStarts;
if (offset < 0 || starts.last <= offset) {
- throw 'bad position #$offset in buffer with length ${lineStarts.last}.';
+ throw 'bad position #$offset in buffer with length ${length}.';
}
int first = 0;
int count = starts.length;
@@ -68,6 +67,11 @@ class LineColumnCollector extends CodeOutputListener
@override
void onDone(int length) {
- lineStarts.add(length);
+ lineStarts.add(length + 1);
+ this.length = length;
+ }
+
+ String toString() {
+ return 'lineStarts=$lineStarts,length=$length';
}
}

Powered by Google App Engine
This is Rietveld 408576698