diff --git a/modules/angular2/src/di/binding.ts b/modules/angular2/src/di/binding.ts index beb4411fe2..ac6e2c3637 100644 --- a/modules/angular2/src/di/binding.ts +++ b/modules/angular2/src/di/binding.ts @@ -450,16 +450,15 @@ function _extractToken(typeOrFunc, annotations /*List | any*/, throw new NoAnnotationError(typeOrFunc, params); } } - function _defaulVisiblity(typeOrFunc) { - try { - if (!(typeOrFunc instanceof Type)) return unbounded; - var f = - ListWrapper.filter(reflector.annotations(typeOrFunc), s => s instanceof InjectableMetadata); - return f.length === 0 ? unbounded : f[0].visibility; - } catch (e) { - return unbounded; - } + if (!(typeOrFunc instanceof Type)) return unbounded; + + // TODO: vsavkin revisit this after clarifying lookup rules + if (!reflector.isReflectionEnabled()) return unbounded; + + var f = + ListWrapper.filter(reflector.annotations(typeOrFunc), s => s instanceof InjectableMetadata); + return f.length === 0 ? unbounded : f[0].visibility; } function _createDependency(token, optional, visibility, depProps): Dependency { diff --git a/modules/angular2/src/reflection/platform_reflection_capabilities.ts b/modules/angular2/src/reflection/platform_reflection_capabilities.ts index 58830d5d8b..25de66fe5b 100644 --- a/modules/angular2/src/reflection/platform_reflection_capabilities.ts +++ b/modules/angular2/src/reflection/platform_reflection_capabilities.ts @@ -3,6 +3,7 @@ import {GetterFn, SetterFn, MethodFn} from './types'; import {List} from 'angular2/src/facade/collection'; export interface PlatformReflectionCapabilities { + isReflectionEnabled(): boolean; factory(type: Type): Function; interfaces(type: Type): List; parameters(type: Type): List>; diff --git a/modules/angular2/src/reflection/reflection.dart b/modules/angular2/src/reflection/reflection.dart index 8c8849b34e..2048b00858 100644 --- a/modules/angular2/src/reflection/reflection.dart +++ b/modules/angular2/src/reflection/reflection.dart @@ -7,6 +7,10 @@ import 'platform_reflection_capabilities.dart'; import 'package:angular2/src/facade/lang.dart'; class NoReflectionCapabilities implements PlatformReflectionCapabilities { + bool isReflectionEnabled() { + return false; + } + Function factory(Type type) { throw "Cannot find reflection information on ${stringify(type)}"; } diff --git a/modules/angular2/src/reflection/reflection_capabilities.dart b/modules/angular2/src/reflection/reflection_capabilities.dart index ab82be182f..a31d187951 100644 --- a/modules/angular2/src/reflection/reflection_capabilities.dart +++ b/modules/angular2/src/reflection/reflection_capabilities.dart @@ -8,6 +8,10 @@ import 'platform_reflection_capabilities.dart'; class ReflectionCapabilities implements PlatformReflectionCapabilities { ReflectionCapabilities([metadataReader]) {} + bool isReflectionEnabled() { + return true; + } + Function factory(Type type) { ClassMirror classMirror = reflectType(type); MethodMirror ctor = classMirror.declarations[classMirror.simpleName]; diff --git a/modules/angular2/src/reflection/reflection_capabilities.ts b/modules/angular2/src/reflection/reflection_capabilities.ts index a80b67a13b..32fe69515a 100644 --- a/modules/angular2/src/reflection/reflection_capabilities.ts +++ b/modules/angular2/src/reflection/reflection_capabilities.ts @@ -15,6 +15,8 @@ export class ReflectionCapabilities implements PlatformReflectionCapabilities { constructor(reflect?: any) { this._reflect = isPresent(reflect) ? reflect : global.Reflect; } + isReflectionEnabled(): boolean { return true; } + factory(t: Type): Function { switch (t.length) { case 0: diff --git a/modules/angular2/src/reflection/reflector.ts b/modules/angular2/src/reflection/reflector.ts index 4ed7431753..c712787462 100644 --- a/modules/angular2/src/reflection/reflector.ts +++ b/modules/angular2/src/reflection/reflector.ts @@ -27,6 +27,8 @@ export class Reflector { this.reflectionCapabilities = reflectionCapabilities; } + isReflectionEnabled(): boolean { return this.reflectionCapabilities.isReflectionEnabled(); } + registerFunction(func: Function, funcInfo: StringMap): void { this._injectableInfo.set(func, funcInfo); } diff --git a/modules/angular2/src/transform/template_compiler/reflection_capabilities.dart b/modules/angular2/src/transform/template_compiler/reflection_capabilities.dart index 90e91cc563..f43613bb7d 100644 --- a/modules/angular2/src/transform/template_compiler/reflection_capabilities.dart +++ b/modules/angular2/src/transform/template_compiler/reflection_capabilities.dart @@ -10,6 +10,8 @@ class NullReflectionCapabilities implements ReflectionCapabilities { _notImplemented(String name) => throw 'Not implemented: $name'; + bool isReflectionEnabled() { return false; } + Function factory(Type type) => _notImplemented('factory'); List parameters(typeOrFunc) => _notImplemented('parameters');