fix(transformer): Support prefixed annotations in the transformer.
closes https://github.com/angular/angular/issues/2754
This commit is contained in:
@ -127,17 +127,37 @@ class AnnotationMatcher {
|
||||
// Checks if an [Annotation] matches an [AnnotationDescriptor].
|
||||
static bool _matchAnnotation(
|
||||
Annotation annotation, AnnotationDescriptor descriptor, AssetId assetId) {
|
||||
if (annotation.name.name != descriptor.name) return false;
|
||||
String name;
|
||||
Identifier prefix;
|
||||
if (annotation.name is PrefixedIdentifier) {
|
||||
// TODO(jakemac): Shouldn't really need a cast here, remove once
|
||||
// https://github.com/dart-lang/sdk/issues/23798 is fixed.
|
||||
var prefixedName = annotation.name as PrefixedIdentifier;
|
||||
name = prefixedName.identifier.name;
|
||||
prefix = prefixedName.prefix;
|
||||
} else {
|
||||
name = annotation.name.name;
|
||||
}
|
||||
if (name != descriptor.name) return false;
|
||||
return (annotation.root as CompilationUnit).directives
|
||||
.where((d) => d is ImportDirective)
|
||||
.any((ImportDirective i) {
|
||||
var importMatch = false;
|
||||
var uriString = i.uri.stringValue;
|
||||
if (uriString == descriptor.import) return true;
|
||||
if (uriString.startsWith('package:') || uriString.startsWith('dart:')) {
|
||||
if (uriString == descriptor.import) {
|
||||
importMatch = true;
|
||||
} else if (uriString.startsWith('package:') ||
|
||||
uriString.startsWith('dart:')) {
|
||||
return false;
|
||||
} else {
|
||||
importMatch = descriptor.assetId ==
|
||||
uriToAssetId(assetId, uriString, logger, null);
|
||||
}
|
||||
return descriptor.assetId ==
|
||||
uriToAssetId(assetId, uriString, logger, null);
|
||||
|
||||
if (!importMatch) return false;
|
||||
if (prefix == null) return i.prefix == null;
|
||||
if (i.prefix == null) return false;
|
||||
return prefix.name == i.prefix.name;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -36,8 +36,13 @@ class ViewDefinitionEntry {
|
||||
String _getComponentId(AssetId assetId, String className) => '$className';
|
||||
|
||||
// TODO(kegluenq): Improve this test.
|
||||
bool _isViewAnnotation(InstanceCreationExpression node) =>
|
||||
'${node.constructorName.type}' == 'View';
|
||||
bool _isViewAnnotation(InstanceCreationExpression node) {
|
||||
var constructorName = node.constructorName.type.name;
|
||||
if (constructorName is PrefixedIdentifier) {
|
||||
constructorName = constructorName.identifier;
|
||||
}
|
||||
return constructorName.name == 'View';
|
||||
}
|
||||
|
||||
/// Creates [ViewDefinition] objects for all `View` `Directive`s defined in
|
||||
/// `entryPoint`.
|
||||
|
Reference in New Issue
Block a user