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
@@ -1,6 +1,5 @@
library angular2.transform.reflection_remover.codegen;
import 'package:analyzer/src/generated/ast.dart';
import 'package:path/path.dart' as path;
import 'package:angular2/src/transform/common/names.dart';
@@ -36,45 +35,10 @@ class Codegen {
/// Generates code to call the method which sets up Angular2 reflection
/// statically.
///
/// If `reflectorAssignment` is provided, it is expected to be the node
/// representing the {@link ReflectionCapabilities} assignment, and we will
/// attempt to parse the access of `reflector` from it so that `reflector` is
/// properly prefixed if necessary.
String codegenSetupReflectionCall(
{AssignmentExpression reflectorAssignment}) {
var reflectorExpression = null;
if (reflectorAssignment != null) {
reflectorExpression = reflectorAssignment.accept(new _ReflectorVisitor());
}
if (reflectorExpression == null) {
reflectorExpression = 'reflector';
}
String codegenSetupReflectionCall() {
var count = 0;
return importUris
.map((_) => '${prefix}${count++}.${SETUP_METHOD_NAME}();')
.join('');
}
}
/// A visitor whose job it is to find the access of `reflector`.
class _ReflectorVisitor extends Object with SimpleAstVisitor<Expression> {
@override
Expression visitAssignmentExpression(AssignmentExpression node) {
if (node == null || node.leftHandSide == null) return null;
return node.leftHandSide.accept(this);
}
@override
Expression visitPropertyAccess(PropertyAccess node) {
if (node == null || node.target == null) return null;
return node.target;
}
@override
Expression visitPrefixedIdentifier(PrefixedIdentifier node) {
if (node == null || node.prefix == null) return null;
return node.prefix;
}
}