Revert "Improve the YamlScalar.span values with trailing whitespace"
This reverts commit aa6b82cb13ade03f55e06b9fbe47f11a0ec92102.
https://github.com/dart-lang/yaml/issues/51 only seems to affect
JSON-encoded source files. Not worth this hack.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c0b3063..143e1c2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,8 +1,3 @@
-## 2.1.16
-
-* Improve the `span` associated with `YamlScalar` values with trailing
- whitespace.
-
## 2.1.15
* Set max SDK version to `<3.0.0`, and adjust other dependencies.
@@ -115,10 +110,12 @@
constructors make it possible to use the same API to access non-YAML data as
YAML data.
-* Make `YamlException` inherit from source_map's `SpanFormatException`. This
+* Make `YamlException` inherit from source_map's [`SpanFormatException`][]. This
improves the error formatting and allows callers access to source range
information.
+[SpanFormatException]: (http://www.dartdocs.org/documentation/source_maps/0.9.2/index.html#source_maps/source_maps.SpanFormatException)
+
## 1.0.0+1
* Fix a variable name typo.
diff --git a/lib/src/parser.dart b/lib/src/parser.dart
index 0971e7f..bffaa17 100644
--- a/lib/src/parser.dart
+++ b/lib/src/parser.dart
@@ -303,22 +303,7 @@
_state = _states.removeLast();
_scanner.scan();
-
- span = span.expand(token.span);
- if (span.text != token.value) {
- // If the only difference between the span and the token is trailing
- // whitespace
- if (span.text.trimRight() == token.value) {
- span = span.file.span(
- span.start.offset,
- // TODO(kevmoo): The length of `token.value` may be incorrect
- // with some UNICODE values. Find a more clean solution.
- span.start.offset + token.value.length,
- );
- }
- }
-
- return ScalarEvent(span, token.value, token.style,
+ return ScalarEvent(span.expand(token.span), token.value, token.style,
anchor: anchor, tag: tag);
}
diff --git a/pubspec.yaml b/pubspec.yaml
index d0fb672..da41f3a 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,5 +1,5 @@
name: yaml
-version: 2.1.16
+version: 2.1.16-dev
description: A parser for YAML.
author: Dart Team <misc@dartlang.org>
diff --git a/test/span_test.dart b/test/span_test.dart
index 09e461c..7ef61d3 100644
--- a/test/span_test.dart
+++ b/test/span_test.dart
@@ -8,6 +8,13 @@
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';
+void _expectSpan(SourceSpan source, String expected) {
+ final result = source.message('message');
+ printOnFailure("r'''\n$result'''");
+
+ expect(result, expected);
+}
+
void main() {
YamlMap yaml;
@@ -26,6 +33,7 @@
_expectSpan(
yaml.nodes['num'].span,
r'''
+line 2, column 9: message
╷
2 │ "num": 42,
│ ^^
@@ -37,6 +45,7 @@
_expectSpan(
yaml.nodes['null'].span,
r'''
+line 7, column 10: message
╷
7 │ "null": null
│ ^^^^
@@ -55,6 +64,7 @@
_expectSpan(
nestedMap.nodes['null'].span,
r'''
+line 4, column 11: message
╷
4 │ "null": null,
│ ^^^^
@@ -66,15 +76,14 @@
_expectSpan(
nestedMap.nodes['num'].span,
r'''
+line 5, column 10: message
╷
-5 │ "num": 42
- │ ^^
+5 │ "num": 42
+ │ ┌──────────^
+6 │ │ },
+ │ └─^
╵''',
);
});
});
}
-
-void _expectSpan(SourceSpan source, String expected) {
- expect(source.highlight(), expected);
-}