From 0c19dae62cfc724eb020ce7ba087c266d790efda Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Wed, 5 Apr 2023 16:52:39 -0700 Subject: [PATCH] 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 --------- Co-authored-by: Devon Carew --- pkgs/source_span/CHANGELOG.md | 3 ++- pkgs/source_span/lib/src/file.dart | 10 +++++++++- pkgs/source_span/pubspec.yaml | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/pkgs/source_span/CHANGELOG.md b/pkgs/source_span/CHANGELOG.md index f69f0b872..17812f6f6 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 52d1b6cca..74c923459 100644 --- a/pkgs/source_span/lib/src/file.dart +++ b/pkgs/source_span/lib/src/file.dart @@ -32,7 +32,15 @@ class SourceFile { /// the file. final _lineStarts = [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 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 d00730c39..44156ee5a 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