Skip to content

Commit

Permalink
Revert "Improve the YamlScalar.span values with trailing whitespace"
Browse files Browse the repository at this point in the history
This reverts commit cb3cf76.

https://github.com/dart-lang/yaml/issues/51 only seems to affect
JSON-encoded source files. Not worth this hack.
  • Loading branch information
kevmoo committed Apr 9, 2019
1 parent cb3cf76 commit aa6f6a3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 29 deletions.
9 changes: 3 additions & 6 deletions pkgs/yaml/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down
17 changes: 1 addition & 16 deletions pkgs/yaml/lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -303,22 +303,7 @@ class Parser {

_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);
}

Expand Down
2 changes: 1 addition & 1 deletion pkgs/yaml/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: yaml
version: 2.1.16
version: 2.1.16-dev

description: A parser for YAML.
author: Dart Team <[email protected]>
Expand Down
21 changes: 15 additions & 6 deletions pkgs/yaml/test/span_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import 'package:source_span/source_span.dart';
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;

Expand All @@ -26,6 +33,7 @@ void main() {
_expectSpan(
yaml.nodes['num'].span,
r'''
line 2, column 9: message
2 │ "num": 42,
│ ^^
Expand All @@ -37,6 +45,7 @@ void main() {
_expectSpan(
yaml.nodes['null'].span,
r'''
line 7, column 10: message
7 │ "null": null
│ ^^^^
Expand All @@ -55,6 +64,7 @@ void main() {
_expectSpan(
nestedMap.nodes['null'].span,
r'''
line 4, column 11: message
4 │ "null": null,
│ ^^^^
Expand All @@ -66,15 +76,14 @@ void main() {
_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);
}

0 comments on commit aa6f6a3

Please sign in to comment.