refactor(dart/transform): Avoid using package:code_transformers

Replace uses of `package:code_transformers`, which is only used to
convert from uri to `AssetId`, with calls to the utility methods in
`src/transform/common/url_resolver.dart`.

Closes #5931
This commit is contained in:
Tim Blasi 2015-12-15 16:42:21 -08:00 committed by Timothy Blasi
parent 6b73d09ba1
commit c1c54ed0f2
3 changed files with 17 additions and 12 deletions

View File

@ -11,7 +11,6 @@ environment:
dependencies: dependencies:
analyzer: '>=0.24.4 <0.27.0' analyzer: '>=0.24.4 <0.27.0'
barback: '^0.15.2+2' barback: '^0.15.2+2'
code_transformers: '0.2.9+4'
dart_style: '>=0.1.8 <0.3.0' dart_style: '>=0.1.8 <0.3.0'
glob: '^1.0.0' glob: '^1.0.0'
html: '^0.12.0' html: '^0.12.0'
@ -23,6 +22,7 @@ dependencies:
source_span: '^1.0.0' source_span: '^1.0.0'
stack_trace: '^1.1.1' stack_trace: '^1.1.1'
dev_dependencies: dev_dependencies:
code_transformers: '0.2.9+4'
guinness: '^0.1.18' guinness: '^0.1.18'
transformers: transformers:
- angular2 - angular2

View File

@ -2,9 +2,10 @@ library angular2.transform.common.class_matcher_base;
import 'package:analyzer/src/generated/ast.dart'; import 'package:analyzer/src/generated/ast.dart';
import 'package:barback/barback.dart' show AssetId; import 'package:barback/barback.dart' show AssetId;
import 'package:code_transformers/assets.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'logging.dart' show log; import 'logging.dart' show log;
import 'url_resolver.dart';
/// Checks if a given [Identifier] matches any of the given [ClassDescriptor]s. /// Checks if a given [Identifier] matches any of the given [ClassDescriptor]s.
abstract class ClassMatcherBase { abstract class ClassMatcherBase {
@ -74,6 +75,7 @@ ImportDirective _getMatchingImport(
name = className.name; name = className.name;
} }
if (name != descriptor.name) return null; if (name != descriptor.name) return null;
final assetUri = toAssetUri(assetId);
return (className.root as CompilationUnit) return (className.root as CompilationUnit)
.directives .directives
.where((d) => d is ImportDirective) .where((d) => d is ImportDirective)
@ -82,12 +84,13 @@ ImportDirective _getMatchingImport(
var uriString = i.uri.stringValue; var uriString = i.uri.stringValue;
if (uriString == descriptor.import) { if (uriString == descriptor.import) {
importMatch = true; importMatch = true;
} else if (uriString.startsWith('package:') || } else if (uriString.startsWith('package:') || isDartCoreUri(uriString)) {
uriString.startsWith('dart:')) {
return false; return false;
} else { } else {
importMatch = final candidateAssetId =
descriptor.assetId == uriToAssetId(assetId, uriString, log, null); fromUri(const TransformerUrlResolver().resolve(assetUri, uriString));
importMatch = descriptor.assetId == candidateAssetId;
} }
if (!importMatch) return false; if (!importMatch) return false;

View File

@ -4,14 +4,15 @@ import 'dart:async';
import 'package:analyzer/analyzer.dart'; import 'package:analyzer/analyzer.dart';
import 'package:analyzer/src/generated/ast.dart'; import 'package:analyzer/src/generated/ast.dart';
import 'package:angular2/src/transform/common/async_string_writer.dart';
import 'package:angular2/src/transform/common/logging.dart';
import 'package:code_transformers/assets.dart';
import 'package:angular2/src/transform/common/asset_reader.dart';
import 'package:barback/barback.dart' show AssetId; import 'package:barback/barback.dart' show AssetId;
import 'package:source_span/source_span.dart'; import 'package:source_span/source_span.dart';
import 'package:path/path.dart' as path; import 'package:path/path.dart' as path;
import 'package:angular2/src/transform/common/asset_reader.dart';
import 'package:angular2/src/transform/common/async_string_writer.dart';
import 'package:angular2/src/transform/common/logging.dart';
import 'package:angular2/src/transform/common/url_resolver.dart';
/// Reads the code at `assetId`, inlining any `part` directives in that code. /// Reads the code at `assetId`, inlining any `part` directives in that code.
/// ///
/// Returns `null` if the code represented by `assetId` is a `part`. /// Returns `null` if the code represented by `assetId` is a `part`.
@ -50,12 +51,13 @@ Future<String> _getAllDeclarations(AssetReader reader, AssetId assetId,
var partsStart = visitor.parts.first.offset, var partsStart = visitor.parts.first.offset,
partsEnd = visitor.parts.last.end; partsEnd = visitor.parts.last.end;
final assetUri = toAssetUri(assetId);
var asyncWriter = new AsyncStringWriter(code.substring(0, partsStart)); var asyncWriter = new AsyncStringWriter(code.substring(0, partsStart));
visitor.parts.forEach((partDirective) { visitor.parts.forEach((partDirective) {
var uri = stringLiteralToString(partDirective.uri); var uri = stringLiteralToString(partDirective.uri);
var partAssetId = uriToAssetId(assetId, uri, log, null /* span */, var partAssetId =
errorOnAbsolute: false); fromUri(const TransformerUrlResolver().resolve(assetUri, uri));
asyncWriter.asyncPrint(reader.readAsString(partAssetId).then((partCode) { asyncWriter.asyncPrint(reader.readAsString(partAssetId).then((partCode) {
if (partCode == null || partCode.isEmpty) { if (partCode == null || partCode.isEmpty) {
log.warning('Empty part at "${partDirective.uri}. Ignoring.', log.warning('Empty part at "${partDirective.uri}. Ignoring.',