From f6065d901f8069b97f8e65b8a316391f2081b2b6 Mon Sep 17 00:00:00 2001 From: "nweiz@google.com" <nweiz@google.com> Date: Wed, 23 Jul 2014 23:44:09 +0000 Subject: [PATCH] Move a number of packages and some of pub over to using source_span. R=efortuna@google.com, rnystrom@google.com, sigmund@google.com BUG=19930 Review URL: https://codereview.chromium.org//401753002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@38526 260f80e4-7a28-3924-810f-c04153c831b5 --- lib/src/barback/transformer_config.dart | 12 ++++++------ lib/src/barback/transformer_id.dart | 10 +++++----- lib/src/barback/transformer_isolate.dart | 7 ++++--- lib/src/pubspec.dart | 21 ++++++++++----------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/src/barback/transformer_config.dart b/lib/src/barback/transformer_config.dart index 42ff5ba5..e6f9912e 100644 --- a/lib/src/barback/transformer_config.dart +++ b/lib/src/barback/transformer_config.dart @@ -5,7 +5,7 @@ library pub.barback.transformer_config; import 'package:path/path.dart' as p; -import 'package:source_maps/source_maps.dart'; +import 'package:source_span/source_span.dart'; import 'package:yaml/yaml.dart'; import 'transformer_id.dart'; @@ -27,7 +27,7 @@ class TransformerConfig { final Map configuration; /// The source span from which this configuration was parsed. - final Span span; + final SourceSpan span; /// The primary input inclusions. /// @@ -65,7 +65,7 @@ class TransformerConfig { /// Parses [identifier] as a [TransformerId] with [configuration]. /// /// [identifierSpan] is the source span for [identifier]. - factory TransformerConfig.parse(String identifier, Span identifierSpan, + factory TransformerConfig.parse(String identifier, SourceSpan identifierSpan, YamlMap configuration) => new TransformerConfig(new TransformerId.parse(identifier, identifierSpan), configuration); @@ -81,13 +81,13 @@ class TransformerConfig { if (field is List) { for (var node in field.nodes) { if (node.value is String) continue; - throw new SpanFormatException( + throw new SourceSpanFormatException( '"$key" field may contain only strings.', node.span); } return new Set.from(field); } else { - throw new SpanFormatException( + throw new SourceSpanFormatException( '"$key" field must be a string or list.', fieldNode.span); } } @@ -114,7 +114,7 @@ class TransformerConfig { // All other keys starting with "$" are unexpected. for (var key in configuration.keys) { if (key is! String || !key.startsWith(r'$')) continue; - throw new SpanFormatException( + throw new SourceSpanFormatException( 'Unknown reserved field.', configurationNode.nodes[key].span); } } diff --git a/lib/src/barback/transformer_id.dart b/lib/src/barback/transformer_id.dart index e793ef32..5d111ab0 100644 --- a/lib/src/barback/transformer_id.dart +++ b/lib/src/barback/transformer_id.dart @@ -8,7 +8,7 @@ import 'dart:async'; import 'package:barback/barback.dart'; import 'package:path/path.dart' as p; -import 'package:source_maps/source_maps.dart'; +import 'package:source_span/source_span.dart'; import '../io.dart'; import '../utils.dart'; @@ -35,7 +35,7 @@ class TransformerId { final String path; /// The source span from which this id was parsed. - final Span span; + final SourceSpan span; /// Whether this ID points to a built-in transformer exposed by pub. bool get isBuiltInTransformer => package.startsWith('\$'); @@ -47,7 +47,7 @@ class TransformerId { /// it just has a package name, it expands to lib/transformer.dart if that /// exists, or lib/${package}.dart otherwise. Otherwise, it expands to /// lib/${path}.dart. In either case it's located in the given package. - factory TransformerId.parse(String identifier, Span span) { + factory TransformerId.parse(String identifier, SourceSpan span) { if (identifier.isEmpty) { throw new FormatException('Invalid library identifier: "".'); } @@ -63,8 +63,8 @@ class TransformerId { TransformerId(this.package, this.path, this.span) { if (!package.startsWith('\$')) return; if (_BUILT_IN_TRANSFORMERS.contains(package)) return; - throw new SpanFormatException('Unsupported built-in transformer $package.', - span); + throw new SourceSpanFormatException( + 'Unsupported built-in transformer $package.', span); } bool operator==(other) => diff --git a/lib/src/barback/transformer_isolate.dart b/lib/src/barback/transformer_isolate.dart index fde48550..9a769e40 100644 --- a/lib/src/barback/transformer_isolate.dart +++ b/lib/src/barback/transformer_isolate.dart @@ -9,7 +9,7 @@ import 'dart:convert'; import 'dart:isolate'; import 'package:barback/barback.dart'; -import 'package:source_maps/source_maps.dart'; +import 'package:source_span/source_span.dart'; import 'package:stack_trace/stack_trace.dart'; import '../../../asset/dart/serialize.dart'; @@ -122,11 +122,12 @@ class TransformerIsolate { } /// An error thrown when a transformer fails to load. -class TransformerLoadError extends SpanException implements WrappedException { +class TransformerLoadError extends SourceSpanException + implements WrappedException { final CrossIsolateException innerError; Chain get innerChain => innerError.stackTrace; - TransformerLoadError(CrossIsolateException error, Span span) + TransformerLoadError(CrossIsolateException error, SourceSpan span) : innerError = error, super("Error loading transformer: ${error.message}", span); } diff --git a/lib/src/pubspec.dart b/lib/src/pubspec.dart index dafb5136..8496063a 100644 --- a/lib/src/pubspec.dart +++ b/lib/src/pubspec.dart @@ -5,7 +5,7 @@ library pub.pubspec; import 'package:path/path.dart' as path; -import 'package:source_maps/source_maps.dart'; +import 'package:source_span/source_span.dart'; import 'package:yaml/yaml.dart'; import 'barback/transformer_config.dart'; @@ -38,8 +38,7 @@ class Pubspec { /// /// This can be null if the pubspec was created in-memory or if its location /// is unknown. - Uri get _location => fields.span.sourceUrl == null ? null : - Uri.parse(fields.span.sourceUrl); + Uri get _location => fields.span.sourceUrl; /// All pubspec fields. /// @@ -257,8 +256,8 @@ class Pubspec { /// [location] is the location from which this pubspec was loaded. Pubspec.fromMap(Map fields, this._sources, {String expectedName, Uri location}) - : fields = fields is YamlMap ? fields : new YamlMap.wrap(fields, - sourceName: location == null ? null : location.toString()) { + : fields = fields is YamlMap ? fields : + new YamlMap.wrap(fields, sourceUrl: location) { // If [expectedName] is passed, ensure that the actual 'name' field exists // and matches the expectation. if (expectedName == null) return; @@ -276,7 +275,7 @@ class Pubspec { {String expectedName, Uri location}) { if (contents.trim() == '') return new Pubspec.empty(); - var pubspecNode = loadYamlNode(contents, sourceName: location.toString()); + var pubspecNode = loadYamlNode(contents, sourceUrl: location); if (pubspecNode is YamlScalar && pubspecNode.value == null) { pubspecNode = new YamlMap(); } else if (pubspecNode is! YamlMap) { @@ -431,7 +430,7 @@ class Pubspec { /// [description] should be a noun phrase that describes whatever's being /// parsed or processed by [fn]. [span] should be the location of whatever's /// being processed within the pubspec. - _wrapFormatException(String description, Span span, fn()) { + _wrapFormatException(String description, SourceSpan span, fn()) { try { return fn(); } on FormatException catch (e) { @@ -442,13 +441,13 @@ class Pubspec { _wrapSpanFormatException(String description, fn()) { try { return fn(); - } on SpanFormatException catch (e) { + } on SourceSpanFormatException catch (e) { _error('Invalid $description: ${e.message}', e.span); } } /// Throws a [PubspecException] with the given message. - void _error(String message, Span span) { + void _error(String message, SourceSpan span) { var name; try { name = this.name; @@ -475,9 +474,9 @@ class PubspecEnvironment { /// An exception thrown when parsing a pubspec. /// /// These exceptions are often thrown lazily while accessing pubspec properties. -class PubspecException extends SpanFormatException +class PubspecException extends SourceSpanFormatException implements ApplicationException { - PubspecException(String message, Span span) + PubspecException(String message, SourceSpan span) : super(message, span); } -- GitLab