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:
parent
6b73d09ba1
commit
c1c54ed0f2
|
@ -11,7 +11,6 @@ environment:
|
|||
dependencies:
|
||||
analyzer: '>=0.24.4 <0.27.0'
|
||||
barback: '^0.15.2+2'
|
||||
code_transformers: '0.2.9+4'
|
||||
dart_style: '>=0.1.8 <0.3.0'
|
||||
glob: '^1.0.0'
|
||||
html: '^0.12.0'
|
||||
|
@ -23,6 +22,7 @@ dependencies:
|
|||
source_span: '^1.0.0'
|
||||
stack_trace: '^1.1.1'
|
||||
dev_dependencies:
|
||||
code_transformers: '0.2.9+4'
|
||||
guinness: '^0.1.18'
|
||||
transformers:
|
||||
- angular2
|
||||
|
|
|
@ -2,9 +2,10 @@ library angular2.transform.common.class_matcher_base;
|
|||
|
||||
import 'package:analyzer/src/generated/ast.dart';
|
||||
import 'package:barback/barback.dart' show AssetId;
|
||||
import 'package:code_transformers/assets.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'logging.dart' show log;
|
||||
import 'url_resolver.dart';
|
||||
|
||||
/// Checks if a given [Identifier] matches any of the given [ClassDescriptor]s.
|
||||
abstract class ClassMatcherBase {
|
||||
|
@ -74,6 +75,7 @@ ImportDirective _getMatchingImport(
|
|||
name = className.name;
|
||||
}
|
||||
if (name != descriptor.name) return null;
|
||||
final assetUri = toAssetUri(assetId);
|
||||
return (className.root as CompilationUnit)
|
||||
.directives
|
||||
.where((d) => d is ImportDirective)
|
||||
|
@ -82,12 +84,13 @@ ImportDirective _getMatchingImport(
|
|||
var uriString = i.uri.stringValue;
|
||||
if (uriString == descriptor.import) {
|
||||
importMatch = true;
|
||||
} else if (uriString.startsWith('package:') ||
|
||||
uriString.startsWith('dart:')) {
|
||||
} else if (uriString.startsWith('package:') || isDartCoreUri(uriString)) {
|
||||
return false;
|
||||
} else {
|
||||
importMatch =
|
||||
descriptor.assetId == uriToAssetId(assetId, uriString, log, null);
|
||||
final candidateAssetId =
|
||||
fromUri(const TransformerUrlResolver().resolve(assetUri, uriString));
|
||||
|
||||
importMatch = descriptor.assetId == candidateAssetId;
|
||||
}
|
||||
|
||||
if (!importMatch) return false;
|
||||
|
|
|
@ -4,14 +4,15 @@ import 'dart:async';
|
|||
|
||||
import 'package:analyzer/analyzer.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:source_span/source_span.dart';
|
||||
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.
|
||||
///
|
||||
/// 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,
|
||||
partsEnd = visitor.parts.last.end;
|
||||
final assetUri = toAssetUri(assetId);
|
||||
|
||||
var asyncWriter = new AsyncStringWriter(code.substring(0, partsStart));
|
||||
visitor.parts.forEach((partDirective) {
|
||||
var uri = stringLiteralToString(partDirective.uri);
|
||||
var partAssetId = uriToAssetId(assetId, uri, log, null /* span */,
|
||||
errorOnAbsolute: false);
|
||||
var partAssetId =
|
||||
fromUri(const TransformerUrlResolver().resolve(assetUri, uri));
|
||||
asyncWriter.asyncPrint(reader.readAsString(partAssetId).then((partCode) {
|
||||
if (partCode == null || partCode.isEmpty) {
|
||||
log.warning('Empty part at "${partDirective.uri}. Ignoring.',
|
||||
|
|
Loading…
Reference in New Issue