feat(bootstrap): remove the need for explicit reflection setup in bootstrap code

BREAKING CHANGES:

Dart applications and TypeScript applications meant to transpile to Dart must now
import `package:angular2/bootstrap.dart` instead of `package:angular2/angular2.dart`
in their bootstrap code. `package:angular2/angular2.dart` no longer export the
bootstrap function. The transformer rewrites imports of `bootstrap.dart` and calls
to `bootstrap` to `bootstrap_static.dart` and `bootstrapStatic` respectively.
This commit is contained in:
yjbanov
2015-07-22 17:02:32 -07:00
parent 55e8dca8de
commit 3531bb7118
119 changed files with 896 additions and 827 deletions
@@ -14,6 +14,7 @@ const INJECTABLES = const [
'Injectable', 'package:angular2/src/di/decorators.dart'),
const ClassDescriptor('Injectable', 'package:angular2/di.dart'),
const ClassDescriptor('Injectable', 'package:angular2/angular2.dart'),
const ClassDescriptor('Injectable', 'package:angular2/bootstrap_static.dart'),
];
const DIRECTIVES = const [
@@ -32,6 +33,8 @@ const DIRECTIVES = const [
superClass: 'Injectable'),
const ClassDescriptor('Directive', 'package:angular2/core.dart',
superClass: 'Injectable'),
const ClassDescriptor('Directive', 'package:angular2/bootstrap_static.dart',
superClass: 'Injectable'),
];
const COMPONENTS = const [
@@ -48,6 +51,8 @@ const COMPONENTS = const [
superClass: 'Directive'),
const ClassDescriptor('Component', 'package:angular2/angular2.dart',
superClass: 'Directive'),
const ClassDescriptor('Component', 'package:angular2/bootstrap_static.dart',
superClass: 'Directive'),
const ClassDescriptor('Component', 'package:angular2/core.dart',
superClass: 'Directive'),
];
@@ -55,6 +60,7 @@ const COMPONENTS = const [
const VIEWS = const [
const ClassDescriptor('View', 'package:angular2/view.dart'),
const ClassDescriptor('View', 'package:angular2/angular2.dart'),
const ClassDescriptor('View', 'package:angular2/bootstrap_static.dart'),
const ClassDescriptor('View', 'package:angular2/core.dart'),
const ClassDescriptor(
'View', 'package:angular2/src/core/annotations/view.dart'),
@@ -75,24 +81,29 @@ class AnnotationMatcher extends ClassMatcherBase {
..addAll(VIEWS));
}
bool _implementsWithWarning(
ClassDescriptor descriptor, List<ClassDescriptor> interfaces) =>
implements(descriptor, interfaces,
bool _implementsWithWarning(Annotation annotation, AssetId assetId,
List<ClassDescriptor> interfaces) {
ClassDescriptor descriptor = firstMatch(annotation.name, assetId);
if (descriptor == null) {
throw 'Unable to locate descriptor for ${annotation.name} in ${assetId}';
}
return implements(descriptor, interfaces,
missingSuperClassWarning: 'Missing `custom_annotation` entry for `${descriptor.superClass}`.');
}
/// Checks if an [Annotation] node implements [Injectable].
bool isInjectable(Annotation annotation, AssetId assetId) =>
_implementsWithWarning(firstMatch(annotation.name, assetId), INJECTABLES);
_implementsWithWarning(annotation, assetId, INJECTABLES);
/// Checks if an [Annotation] node implements [Directive].
bool isDirective(Annotation annotation, AssetId assetId) =>
_implementsWithWarning(firstMatch(annotation.name, assetId), DIRECTIVES);
_implementsWithWarning(annotation, assetId, DIRECTIVES);
/// Checks if an [Annotation] node implements [Component].
bool isComponent(Annotation annotation, AssetId assetId) =>
_implementsWithWarning(firstMatch(annotation.name, assetId), COMPONENTS);
_implementsWithWarning(annotation, assetId, COMPONENTS);
/// Checks if an [Annotation] node implements [View].
bool isView(Annotation annotation, AssetId assetId) =>
_implementsWithWarning(firstMatch(annotation.name, assetId), VIEWS);
_implementsWithWarning(annotation, assetId, VIEWS);
}
@@ -1,5 +1,6 @@
library angular2.transform.common.names;
const BOOTSTRAP_NAME = 'bootstrap';
const SETUP_METHOD_NAME = 'initReflector';
const REFLECTOR_VAR_NAME = 'reflector';
const TRANSFORM_DYNAMIC_MODE = 'transform_dynamic';