Skip to content

Commit a2ad0b8

Browse files
authored
Deprecate the use of runes in SourceFile. (flutter#16)
This behavior runs contrary to the rest of Dart's string handling, and in particular breaks string_scanner. See dart-lang/string_scanner#4.
1 parent 581faf5 commit a2ad0b8

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
# 1.4.0
2+
3+
* The `new SourceFile()` constructor is deprecated. This constructed a source
4+
file from a string's runes, rather than its code units, which runs counter to
5+
the way Dart handles strings otherwise. The `new StringFile.fromString()`
6+
constructor (see below) should be used instead.
7+
8+
* The `new SourceFile.fromString()` constructor was added. This works like `new
9+
SourceFile()`, except it uses code units rather than runes.
10+
11+
* The current behavior when characters larger than `0xFFFF` are passed to `new
12+
SourceFile.decoded()` is now considered deprecated.
13+
114
# 1.3.1
215

316
* Properly highlight spans for lines that include tabs with

lib/src/file.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,28 @@ class SourceFile {
4949
/// previous result.
5050
int _cachedLine;
5151

52-
/// Creates a new source file from [text].
52+
/// This constructor is deprecated.
5353
///
54-
/// [url] may be either a [String], a [Uri], or `null`.
54+
/// Use [new SourceFile.fromString] instead.
55+
@Deprecated("Will be removed in 2.0.0")
5556
SourceFile(String text, {url})
5657
: this.decoded(text.runes, url: url);
5758

58-
/// Creates a new source file from a list of decoded characters.
59+
/// Creates a new source file from [text].
5960
///
6061
/// [url] may be either a [String], a [Uri], or `null`.
62+
SourceFile.fromString(String text, {url})
63+
: this.decoded(text.codeUnits, url: url);
64+
65+
/// Creates a new source file from a list of decoded code units.
66+
///
67+
/// [url] may be either a [String], a [Uri], or `null`.
68+
///
69+
/// Currently, if [decodedChars] contains characters larger than `0xFFFF`,
70+
/// they'll be treated as single characters rather than being split into
71+
/// surrogate pairs. **This behavior is deprecated**. For
72+
/// forwards-compatibility, callers should only pass in characters less than
73+
/// or equal to `0xFFFF`.
6174
SourceFile.decoded(Iterable<int> decodedChars, {url})
6275
: url = url is String ? Uri.parse(url) : url,
6376
_decodedChars = new Uint32List.fromList(decodedChars.toList()) {

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: source_span
2-
version: 1.3.1
2+
version: 1.4.0
33
author: Dart Team <[email protected]>
44
description: A library for identifying source spans and locations.
55
homepage: https://github.com/dart-lang/source_span

0 commit comments

Comments
 (0)