Add public access to a SourceFile's code units (dart-lang/source_span#93)
* Add public access to a SourceFile's code units
This makes it possible to efficiently reparse information from around
a `FileSpan`, such as to expand it through surrounding whitespace
characters. Otherwise, a caller would have to call `getText()` which
can be very expensive in a tight loop.
* Fix lints
* Update CHANGELOG.md
Co-authored-by: Devon Carew <devoncarew@google.com>
---------
Co-authored-by: Devon Carew <devoncarew@google.com>
diff --git a/pkgs/source_span/CHANGELOG.md b/pkgs/source_span/CHANGELOG.md
index f69f0b8..17812f6 100644
--- a/pkgs/source_span/CHANGELOG.md
+++ b/pkgs/source_span/CHANGELOG.md
@@ -1,5 +1,6 @@
-## 1.9.2-dev
+## 1.10.0
+* Add a `SourceFile.codeUnits` property.
* Require Dart 2.18
* Add an API usage example in `example/`.
diff --git a/pkgs/source_span/lib/src/file.dart b/pkgs/source_span/lib/src/file.dart
index 52d1b6c..74c9234 100644
--- a/pkgs/source_span/lib/src/file.dart
+++ b/pkgs/source_span/lib/src/file.dart
@@ -32,7 +32,15 @@
/// the file.
final _lineStarts = <int>[0];
- /// The code points of the characters in the file.
+ /// The code units of the characters in the file.
+ ///
+ /// If this was constructed with the deprecated `SourceFile()` constructor,
+ /// this will instead contain the code _points_ of the characters in the file
+ /// (so characters above 2^16 are represented as individual integers rather
+ /// than surrogate pairs).
+ List<int> get codeUnits => _decodedChars;
+
+ /// The code units of the characters in this file.
final Uint32List _decodedChars;
/// The length of the file in characters.
diff --git a/pkgs/source_span/pubspec.yaml b/pkgs/source_span/pubspec.yaml
index d00730c..44156ee 100644
--- a/pkgs/source_span/pubspec.yaml
+++ b/pkgs/source_span/pubspec.yaml
@@ -1,5 +1,5 @@
name: source_span
-version: 1.9.2-dev
+version: 1.10.0
description: >-
Provides a standard representation for source code locations and spans.
repository: https://github.com/dart-lang/source_span