Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(metadata_extractor): Do not try to guess the selector
Browse files Browse the repository at this point in the history
The dynamic version of angular mandates that the selector is specified.
This commit makes the static vesion consistent with that behavior, the
selector must always be explicitely specified.
  • Loading branch information
vicb authored and jbdeboer committed Aug 25, 2014
1 parent a981feb commit 28f9ee4
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions lib/tools/source_metadata_extractor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import 'package:analyzer/src/generated/ast.dart';
import 'package:angular/tools/source_crawler.dart';
import 'package:angular/tools/common.dart';

const String _COMPONENT = '-component';
const String _DIRECTIVE = '-directive';
String _ATTR_DIRECTIVE = '-attr' + _DIRECTIVE;
RegExp _ATTR_SELECTOR_REGEXP = new RegExp(r'\[([^\]]+)\]');
const List<String> _specs = const ['=>!', '=>', '<=>', '@', '&'];
const Map<String, String> _attrAnnotationsToSpec = const {
Expand Down Expand Up @@ -70,27 +67,9 @@ class SourceMetadataExtractor {

// No explicit selector specified on the directive, compute one.
var className = meta.className;

if (dirInfo.selector == null) {
if (meta.type == COMPONENT) {
if (className.endsWith(_COMPONENT)) {
dirInfo.selector = className.
substring(0, className.length - _COMPONENT.length);
} else {
throw "Directive name '$className' must end with $_DIRECTIVE, "
"$_ATTR_DIRECTIVE, $_COMPONENT or have a \$selector field.";
}
} else {
if (className.endsWith(_ATTR_DIRECTIVE)) {
var attrName = className.
substring(0, className.length - _ATTR_DIRECTIVE.length);
dirInfo.selector = '[$attrName]';
} else if (className.endsWith(_DIRECTIVE)) {
dirInfo.selector = className.
substring(0, className.length - _DIRECTIVE.length);
} else {
throw "Directive name '$className' must have a \$selector field.";
}
}
throw new ArgumentError('Missing selector annotation for $className');
}
var reprocessedAttrs = <String>[];
dirInfo.expressionAttrs.forEach((String attr) {
Expand Down

0 comments on commit 28f9ee4

Please sign in to comment.