diff --git a/karma-dart.conf.js b/karma-dart.conf.js index 43f4ba02d5..d8896537b2 100644 --- a/karma-dart.conf.js +++ b/karma-dart.conf.js @@ -44,6 +44,7 @@ module.exports = function(config) { // Local dependencies, transpiled from the source. '/packages/core': 'http://localhost:9877/base/modules/core/src', '/packages/change_detection': 'http://localhost:9877/base/modules/change_detection/src', + '/packages/reflection': 'http://localhost:9877/base/modules/reflection/src', '/packages/di': 'http://localhost:9877/base/modules/di/src', '/packages/facade': 'http://localhost:9877/base/modules/facade/src', '/packages/test_lib': 'http://localhost:9877/base/modules/test_lib/src', diff --git a/modules/benchmarks/src/compiler/compiler_benchmark.js b/modules/benchmarks/src/compiler/compiler_benchmark.js index 9023155d2f..33340461d3 100644 --- a/modules/benchmarks/src/compiler/compiler_benchmark.js +++ b/modules/benchmarks/src/compiler/compiler_benchmark.js @@ -6,11 +6,10 @@ import {MapWrapper} from 'facade/collection'; import {AnnotatedType} from 'core/compiler/annotated_type'; import {Parser} from 'change_detection/parser/parser'; -import {ClosureMap} from 'change_detection/parser/closure_map'; import {Lexer} from 'change_detection/parser/lexer'; import {Compiler} from 'core/compiler/compiler'; -import {Reflector} from 'core/compiler/reflector'; +import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader'; import {Component} from 'core/annotations/annotations'; import {Decorator} from 'core/annotations/annotations'; @@ -22,10 +21,9 @@ var compiler; var annotatedComponent; function setup() { - var closureMap = new ClosureMap(); - var reflector = new CachingReflector(); - compiler = new Compiler(null, reflector, new Parser(new Lexer(), closureMap), closureMap); - annotatedComponent = reflector.annotatedType(BenchmarkComponent); + var reader = new CachingDirectiveMetadataReader(); + compiler = new Compiler(null, reader, new Parser(new Lexer())); + annotatedComponent = reader.annotatedType(BenchmarkComponent); } export function main() { @@ -63,7 +61,7 @@ function loadTemplate(templateId, repeatCount) { } // Caching reflector as reflection in Dart using Mirrors -class CachingReflector extends Reflector { +class CachingDirectiveMetadataReader extends DirectiveMetadataReader { _cache: Map; constructor() { this._cache = MapWrapper.create(); diff --git a/modules/change_detection/src/parser/ast.js b/modules/change_detection/src/parser/ast.js index 2d30c46138..bbeb606cea 100644 --- a/modules/change_detection/src/parser/ast.js +++ b/modules/change_detection/src/parser/ast.js @@ -1,6 +1,5 @@ import {FIELD, autoConvertAdd, isBlank, isPresent, FunctionWrapper, BaseException} from "facade/lang"; import {List, Map, ListWrapper, MapWrapper} from "facade/collection"; -import {ClosureMap} from "./closure_map"; export class AST { eval(context) { @@ -316,11 +315,9 @@ export class MethodCall extends AST { export class FunctionCall extends AST { target:AST; - closureMap:ClosureMap; args:List; - constructor(target:AST, closureMap:ClosureMap, args:List) { + constructor(target:AST, args:List) { this.target = target; - this.closureMap = closureMap; this.args = args; } diff --git a/modules/change_detection/src/parser/closure_map.dart b/modules/change_detection/src/parser/closure_map.dart deleted file mode 100644 index 5f4ae78d19..0000000000 --- a/modules/change_detection/src/parser/closure_map.dart +++ /dev/null @@ -1,22 +0,0 @@ -library change_detection.parser.closure_map; - -import 'dart:mirrors'; - -typedef SetterFn(Object obj, value); - -class ClosureMap { - Function getter(String name) { - var symbol = new Symbol(name); - return (receiver) => reflect(receiver).getField(symbol).reflectee; - } - - Function setter(String name) { - var symbol = new Symbol(name); - return (receiver, value) => reflect(receiver).setField(symbol, value).reflectee; - } - - Function fn(String name) { - var symbol = new Symbol(name); - return (receiver, posArgs) => reflect(receiver).invoke(symbol, posArgs).reflectee; - } -} diff --git a/modules/change_detection/src/parser/closure_map.es6 b/modules/change_detection/src/parser/closure_map.es6 deleted file mode 100644 index f2ab3ccbae..0000000000 --- a/modules/change_detection/src/parser/closure_map.es6 +++ /dev/null @@ -1,18 +0,0 @@ -export var SetterFn = Function; - -export class ClosureMap { - getter(name:string) { - return new Function('o', 'return o.' + name + ';'); - } - - setter(name:string) { - return new Function('o', 'v', 'return o.' + name + ' = v;'); - } - - fn(name:string) { - var method = `o.${name}`; - return new Function('o', 'args', - `if (!${method}) throw new Error('"${name}" is undefined');` + - `return ${method}.apply(o, args);`); - } -} diff --git a/modules/change_detection/src/parser/parser.js b/modules/change_detection/src/parser/parser.js index e49ffccd11..de07e154ec 100644 --- a/modules/change_detection/src/parser/parser.js +++ b/modules/change_detection/src/parser/parser.js @@ -1,8 +1,8 @@ -import {FIELD, int, isBlank, BaseException, StringWrapper} from 'facade/lang'; +import {FIELD, int, isBlank, isPresent, BaseException, StringWrapper} from 'facade/lang'; import {ListWrapper, List} from 'facade/collection'; import {Lexer, EOF, Token, $PERIOD, $COLON, $SEMICOLON, $LBRACKET, $RBRACKET, $COMMA, $LBRACE, $RBRACE, $LPAREN, $RPAREN} from './lexer'; -import {ClosureMap} from './closure_map'; +import {reflector, Reflector} from 'reflection/reflection'; import { AST, ImplicitReceiver, @@ -29,41 +29,41 @@ var _implicitReceiver = new ImplicitReceiver(); export class Parser { _lexer:Lexer; - _closureMap:ClosureMap; - constructor(lexer:Lexer, closureMap:ClosureMap){ + _reflector:Reflector; + constructor(lexer:Lexer, providedReflector:Reflector = null){ this._lexer = lexer; - this._closureMap = closureMap; + this._reflector = isPresent(providedReflector) ? providedReflector : reflector; } parseAction(input:string):ASTWithSource { var tokens = this._lexer.tokenize(input); - var ast = new _ParseAST(input, tokens, this._closureMap, true).parseChain(); + var ast = new _ParseAST(input, tokens, this._reflector, true).parseChain(); return new ASTWithSource(ast, input); } parseBinding(input:string):ASTWithSource { var tokens = this._lexer.tokenize(input); - var ast = new _ParseAST(input, tokens, this._closureMap, false).parseChain(); + var ast = new _ParseAST(input, tokens, this._reflector, false).parseChain(); return new ASTWithSource(ast, input); } parseTemplateBindings(input:string):List { var tokens = this._lexer.tokenize(input); - return new _ParseAST(input, tokens, this._closureMap, false).parseTemplateBindings(); + return new _ParseAST(input, tokens, this._reflector, false).parseTemplateBindings(); } } class _ParseAST { input:string; tokens:List; - closureMap:ClosureMap; + reflector:Reflector; parseAction:boolean; index:int; - constructor(input:string, tokens:List, closureMap:ClosureMap, parseAction:boolean) { + constructor(input:string, tokens:List, reflector:Reflector, parseAction:boolean) { this.input = input; this.tokens = tokens; this.index = 0; - this.closureMap = closureMap; + this.reflector = reflector; this.parseAction = parseAction; } @@ -311,7 +311,7 @@ class _ParseAST { } else if (this.optionalCharacter($LPAREN)) { var args = this.parseCallArguments(); this.expectCharacter($RPAREN); - result = new FunctionCall(result, this.closureMap, args); + result = new FunctionCall(result, args); } else { return result; @@ -398,12 +398,12 @@ class _ParseAST { if (this.optionalCharacter($LPAREN)) { var args = this.parseCallArguments(); this.expectCharacter($RPAREN); - var fn = this.closureMap.fn(id); + var fn = this.reflector.method(id); return new MethodCall(receiver, fn, args); } else { - var getter = this.closureMap.getter(id); - var setter = this.closureMap.setter(id); + var getter = this.reflector.getter(id); + var setter = this.reflector.setter(id); return new AccessMember(receiver, id, getter, setter); } } diff --git a/modules/change_detection/src/record.js b/modules/change_detection/src/record.js index 9dcb0b0b1e..682df92e08 100644 --- a/modules/change_detection/src/record.js +++ b/modules/change_detection/src/record.js @@ -1,7 +1,6 @@ import {ProtoRecordRange, RecordRange} from './record_range'; import {FIELD, isPresent, isBlank, int, StringWrapper, FunctionWrapper, BaseException} from 'facade/lang'; import {List, Map, ListWrapper, MapWrapper} from 'facade/collection'; -import {ClosureMap} from 'change_detection/parser/closure_map'; var _fresh = new Object(); diff --git a/modules/change_detection/test/change_detector_spec.js b/modules/change_detection/test/change_detector_spec.js index 14f1c3ce09..e91c09788e 100644 --- a/modules/change_detection/test/change_detector_spec.js +++ b/modules/change_detection/test/change_detector_spec.js @@ -4,7 +4,6 @@ import {isPresent} from 'facade/lang'; import {List, ListWrapper, MapWrapper} from 'facade/collection'; import {Parser} from 'change_detection/parser/parser'; import {Lexer} from 'change_detection/parser/lexer'; -import {ClosureMap} from 'change_detection/parser/closure_map'; import { ChangeDetector, @@ -18,7 +17,7 @@ import {Record} from 'change_detection/record'; export function main() { function ast(exp:string) { - var parser = new Parser(new Lexer(), new ClosureMap()); + var parser = new Parser(new Lexer()); return parser.parseBinding(exp).ast; } diff --git a/modules/change_detection/test/parser/parser_spec.js b/modules/change_detection/test/parser/parser_spec.js index fedae075c3..eb0f202505 100644 --- a/modules/change_detection/test/parser/parser_spec.js +++ b/modules/change_detection/test/parser/parser_spec.js @@ -1,10 +1,10 @@ import {ddescribe, describe, it, xit, iit, expect, beforeEach} from 'test_lib/test_lib'; import {BaseException, isBlank, isPresent} from 'facade/lang'; +import {reflector} from 'reflection/reflection'; import {MapWrapper, ListWrapper} from 'facade/collection'; import {Parser} from 'change_detection/parser/parser'; import {Lexer} from 'change_detection/parser/lexer'; import {Formatter, LiteralPrimitive} from 'change_detection/parser/ast'; -import {ClosureMap} from 'change_detection/parser/closure_map'; class TestData { a; @@ -31,7 +31,7 @@ export function main() { } function createParser() { - return new Parser(new Lexer(), new ClosureMap()); + return new Parser(new Lexer(), reflector); } function parseAction(text) { diff --git a/modules/change_detection/test/record_range_spec.js b/modules/change_detection/test/record_range_spec.js index 19a01ee4b7..1cbba70aa3 100644 --- a/modules/change_detection/test/record_range_spec.js +++ b/modules/change_detection/test/record_range_spec.js @@ -4,7 +4,6 @@ import {List, ListWrapper, MapWrapper} from 'facade/collection'; import {isPresent} from 'facade/lang'; import {Parser} from 'change_detection/parser/parser'; import {Lexer} from 'change_detection/parser/lexer'; -import {ClosureMap} from 'change_detection/parser/closure_map'; import { ChangeDetector, diff --git a/modules/core/src/application.js b/modules/core/src/application.js index b652136b65..915bf217e4 100644 --- a/modules/core/src/application.js +++ b/modules/core/src/application.js @@ -3,20 +3,23 @@ import {Type, FIELD, isBlank, isPresent, BaseException} from 'facade/lang'; import {DOM, Element} from 'facade/dom'; import {Compiler} from './compiler/compiler'; import {ProtoView} from './compiler/view'; -import {ClosureMap} from 'change_detection/parser/closure_map'; +import {Reflector, reflector} from 'reflection/reflection'; +import {ReflectionCapabilities} from 'reflection/reflection_capabilities'; import {Parser} from 'change_detection/parser/parser'; import {Lexer} from 'change_detection/parser/lexer'; import {ChangeDetector} from 'change_detection/change_detector'; import {RecordRange} from 'change_detection/record_range'; import {TemplateLoader} from './compiler/template_loader'; -import {Reflector} from './compiler/reflector'; +import {DirectiveMetadataReader} from './compiler/directive_metadata_reader'; import {AnnotatedType} from './compiler/annotated_type'; import {ListWrapper} from 'facade/collection'; var _rootInjector: Injector; // Contains everything that is safe to share between applications. -var _rootBindings = [Compiler, TemplateLoader, Reflector, Parser, Lexer, ClosureMap]; +var _rootBindings = [ + bind(Reflector).toValue(reflector), Compiler, TemplateLoader, DirectiveMetadataReader, Parser, Lexer +]; export var appViewToken = new Object(); export var appWatchGroupToken = new Object(); @@ -27,12 +30,12 @@ export var appDocumentToken = new Object(); // Exported only for tests that need to overwrite default document binding. export function documentDependentBindings(appComponentType) { return [ - bind(appComponentAnnotatedTypeToken).toFactory((reflector) => { + bind(appComponentAnnotatedTypeToken).toFactory((reader) => { // TODO(rado): inspect annotation here and warn if there are bindings, // lightDomServices, and other component annotations that are skipped // for bootstrapping components. - return reflector.annotatedType(appComponentType); - }, [Reflector]), + return reader.annotatedType(appComponentType); + }, [DirectiveMetadataReader]), bind(appElementToken).toFactory((appComponentAnnotatedType, appDocument) => { var selector = appComponentAnnotatedType.annotation.selector; @@ -71,6 +74,8 @@ function _injectorBindings(appComponentType) { // Multiple calls to this method are allowed. Each application would only share // _rootInjector, which is not user-configurable by design, thus safe to share. export function bootstrap(appComponentType: Type, bindings=null) { + reflector.reflectionCapabilities = new ReflectionCapabilities(); + // TODO(rado): prepopulate template cache, so applications with only // index.html and main.js are possible. if (isBlank(_rootInjector)) _rootInjector = new Injector(_rootBindings); diff --git a/modules/core/src/compiler/compiler.js b/modules/core/src/compiler/compiler.js index 0a2490adeb..92f8693ff8 100644 --- a/modules/core/src/compiler/compiler.js +++ b/modules/core/src/compiler/compiler.js @@ -4,9 +4,8 @@ import {List, ListWrapper} from 'facade/collection'; import {DOM, Element} from 'facade/dom'; import {Parser} from 'change_detection/parser/parser'; -import {ClosureMap} from 'change_detection/parser/closure_map'; -import {Reflector} from './reflector'; +import {DirectiveMetadataReader} from './directive_metadata_reader'; import {ProtoView} from './view'; import {CompilePipeline} from './pipeline/compile_pipeline'; import {CompileElement} from './pipeline/compile_element'; @@ -22,14 +21,12 @@ import {Component} from '../annotations/annotations'; */ export class Compiler { _templateLoader:TemplateLoader; - _reflector: Reflector; + _reader: DirectiveMetadataReader; _parser:Parser; - _closureMap:ClosureMap; - constructor(templateLoader:TemplateLoader, reflector: Reflector, parser:Parser, closureMap:ClosureMap) { + constructor(templateLoader:TemplateLoader, reader: DirectiveMetadataReader, parser:Parser) { this._templateLoader = templateLoader; - this._reflector = reflector; + this._reader = reader; this._parser = parser; - this._closureMap = closureMap; } createSteps(component:AnnotatedType):List { @@ -37,16 +34,16 @@ export class Compiler { var directives = annotation.template.directives; var annotatedDirectives = ListWrapper.create(); for (var i=0; i { // TODO load all components transitively from the cache first var cache = null; return PromiseWrapper.resolve(this.compileWithCache( - cache, this._reflector.annotatedType(component), templateRoot) + cache, this._reader.annotatedType(component), templateRoot) ); } diff --git a/modules/core/src/compiler/reflector.es6 b/modules/core/src/compiler/directive_metadata_reader.js similarity index 66% rename from modules/core/src/compiler/reflector.es6 rename to modules/core/src/compiler/directive_metadata_reader.js index b79ee7b930..10fb121782 100644 --- a/modules/core/src/compiler/reflector.es6 +++ b/modules/core/src/compiler/directive_metadata_reader.js @@ -1,6 +1,7 @@ -import {Type, isPresent, BaseException} from 'facade/lang'; +import {Type, isPresent, BaseException, stringify} from 'facade/lang'; import {Directive} from '../annotations/annotations'; import {AnnotatedType} from './annotated_type'; +import {reflector} from 'reflection/reflection'; /** * Interface representing a way of extracting [Directive] annotations from @@ -10,10 +11,10 @@ import {AnnotatedType} from './annotated_type'; * 2) Dart reflective implementation * 3) Dart transformer generated implementation */ -export class Reflector { +export class DirectiveMetadataReader { annotatedType(type:Type):AnnotatedType { - var annotations = type.annotations; - if (annotations) { + var annotations = reflector.annotations(type); + if (isPresent(annotations)) { for (var i=0; i - ) { +export function createDefaultSteps(parser:Parser, directives: List) { return [ new ViewSplitter(parser), new TextInterpolationParser(parser), @@ -28,6 +24,6 @@ export function createDefaultSteps( new ElementBindingMarker(), new ProtoViewBuilder(), new ProtoElementInjectorBuilder(), - new ElementBinderBuilder(closureMap) + new ElementBinderBuilder() ]; } \ No newline at end of file diff --git a/modules/core/src/compiler/pipeline/directive_parser.js b/modules/core/src/compiler/pipeline/directive_parser.js index 5ef67748c7..c51a6b3e75 100644 --- a/modules/core/src/compiler/pipeline/directive_parser.js +++ b/modules/core/src/compiler/pipeline/directive_parser.js @@ -10,7 +10,6 @@ import {Component} from '../../annotations/annotations'; import {CompileStep} from './compile_step'; import {CompileElement} from './compile_element'; import {CompileControl} from './compile_control'; -import {Reflector} from '../reflector'; /** * Parses the directives on a single element. Assumes ViewSplitter has already created diff --git a/modules/core/src/compiler/pipeline/element_binder_builder.js b/modules/core/src/compiler/pipeline/element_binder_builder.js index d12156b7f6..5f90aae25c 100644 --- a/modules/core/src/compiler/pipeline/element_binder_builder.js +++ b/modules/core/src/compiler/pipeline/element_binder_builder.js @@ -2,8 +2,9 @@ import {int, isPresent, isBlank, Type, BaseException, stringify} from 'facade/la import {Element} from 'facade/dom'; import {ListWrapper, List, MapWrapper, StringMapWrapper} from 'facade/collection'; +import {reflector} from 'reflection/reflection'; + import {Parser} from 'change_detection/parser/parser'; -import {ClosureMap} from 'change_detection/parser/closure_map'; import {ProtoRecordRange} from 'change_detection/record_range'; import {Component, Directive} from '../../annotations/annotations'; @@ -11,7 +12,6 @@ import {AnnotatedType} from '../annotated_type'; import {ProtoView, ElementPropertyMemento, DirectivePropertyMemento} from '../view'; import {ProtoElementInjector} from '../element_injector'; import {ElementBinder} from '../element_binder'; -import {Reflector} from '../reflector'; import {CompileStep} from './compile_step'; import {CompileElement} from './compile_element'; @@ -43,11 +43,6 @@ import {CompileControl} from './compile_control'; * with the flag `isViewRoot`. */ export class ElementBinderBuilder extends CompileStep { - _closureMap:ClosureMap; - constructor(closureMap:ClosureMap) { - this._closureMap = closureMap; - } - process(parent:CompileElement, current:CompileElement, control:CompileControl) { var elementBinder = null; if (current.hasBindings) { @@ -125,7 +120,7 @@ export class ElementBinderBuilder extends CompileStep { directiveIndex++, expression.ast, dirProp, - this._closureMap.setter(dirProp) + reflector.setter(dirProp) ); }); }); diff --git a/modules/core/src/compiler/reflector.dart b/modules/core/src/compiler/reflector.dart deleted file mode 100644 index a2b0b556a4..0000000000 --- a/modules/core/src/compiler/reflector.dart +++ /dev/null @@ -1,27 +0,0 @@ -library facade.compiler.reflector; - -import 'dart:mirrors'; -import '../annotations/annotations.dart'; -import './annotated_type.dart'; -import 'package:facade/lang.dart'; - -/** - * Interface representing a way of extracting [Directive] annotations from - * [Type]. This interface has three native implementations: - * - * 1) JavaScript native implementation - * 2) Dart reflective implementation - * 3) Dart transformer generated implementation - */ -class Reflector { - AnnotatedType annotatedType(Type type) { - var directiveAnnotations = reflectType(type).metadata - .map( (im) => im.reflectee) - .where( (annotation) => annotation is Directive); - if (directiveAnnotations.isEmpty) { - throw new BaseException('No Directive annotation found on '+stringify(type)); - } - return new AnnotatedType(type, directiveAnnotations.first); - } - -} diff --git a/modules/core/src/compiler/view.js b/modules/core/src/compiler/view.js index 458fce22ab..0d3ac6c200 100644 --- a/modules/core/src/compiler/view.js +++ b/modules/core/src/compiler/view.js @@ -7,7 +7,7 @@ import {AST} from 'change_detection/parser/ast'; import {ProtoElementInjector, ElementInjector, PreBuiltObjects} from './element_injector'; import {ElementBinder} from './element_binder'; import {AnnotatedType} from './annotated_type'; -import {SetterFn} from 'change_detection/parser/closure_map'; +import {SetterFn} from 'reflection/types'; import {FIELD, IMPLEMENTS, int, isPresent, isBlank} from 'facade/lang'; import {Injector} from 'di/di'; import {NgElement} from 'core/dom/element'; diff --git a/modules/core/test/compiler/compiler_spec.js b/modules/core/test/compiler/compiler_spec.js index 14af477b63..02b078d70b 100644 --- a/modules/core/test/compiler/compiler_spec.js +++ b/modules/core/test/compiler/compiler_spec.js @@ -4,7 +4,7 @@ import {List} from 'facade/collection'; import {Compiler} from 'core/compiler/compiler'; import {ProtoView} from 'core/compiler/view'; -import {Reflector} from 'core/compiler/reflector'; +import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader'; import {TemplateLoader} from 'core/compiler/template_loader'; import {Component} from 'core/annotations/annotations'; import {TemplateConfig} from 'core/annotations/template_config'; @@ -14,20 +14,18 @@ import {CompileControl} from 'core/compiler/pipeline/compile_control'; import {Parser} from 'change_detection/parser/parser'; import {Lexer} from 'change_detection/parser/lexer'; -import {ClosureMap} from 'change_detection/parser/closure_map'; export function main() { describe('compiler', function() { - var compiler, reflector; + var compiler, reader; beforeEach( () => { - reflector = new Reflector(); + reader = new DirectiveMetadataReader(); }); function createCompiler(processClosure) { - var closureMap = new ClosureMap(); var steps = [new MockStep(processClosure)]; - return new TestableCompiler(null, reflector, new Parser(new Lexer(), closureMap), closureMap, steps); + return new TestableCompiler(null, reader, new Parser(new Lexer()), steps); } it('should run the steps and return the ProtoView of the root element', (done) => { @@ -68,7 +66,7 @@ export function main() { current.inheritedProtoView = new ProtoView(current.element, null); current.inheritedElementBinder = current.inheritedProtoView.bindElement(null); if (current.element === mainEl) { - current.componentDirective = reflector.annotatedType(NestedComponent); + current.componentDirective = reader.annotatedType(NestedComponent); } }); compiler.compile(MainComponent, mainEl).then( (protoView) => { @@ -99,8 +97,8 @@ class NestedComponent {} class TestableCompiler extends Compiler { steps:List; - constructor(templateLoader:TemplateLoader, reflector:Reflector, parser, closureMap, steps:List) { - super(templateLoader, reflector, parser, closureMap); + constructor(templateLoader:TemplateLoader, reader:DirectiveMetadataReader, parser, steps:List) { + super(templateLoader, reader, parser); this.steps = steps; } createSteps(component):List { diff --git a/modules/core/test/compiler/reflector_spec.js b/modules/core/test/compiler/directive_metadata_reader_spec.js similarity index 70% rename from modules/core/test/compiler/reflector_spec.js rename to modules/core/test/compiler/directive_metadata_reader_spec.js index 93d38738d6..1adc2f16a0 100644 --- a/modules/core/test/compiler/reflector_spec.js +++ b/modules/core/test/compiler/directive_metadata_reader_spec.js @@ -1,5 +1,5 @@ import {ddescribe, describe, it, iit, expect, beforeEach} from 'test_lib/test_lib'; -import {Reflector} from 'core/compiler/reflector'; +import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader'; import {Decorator} from 'core/annotations/annotations'; import {AnnotatedType} from 'core/compiler/annotated_type'; @@ -13,22 +13,22 @@ class SomeDirectiveWithoutAnnotation { } export function main() { - describe("reflector", () => { - var reflector; + describe("DirectiveMetadataReader", () => { + var rader; beforeEach( () => { - reflector = new Reflector(); + rader = new DirectiveMetadataReader(); }); it('should read out the annotation', () => { - var annoatedDirective = reflector.annotatedType(SomeDirective); + var annoatedDirective = rader.annotatedType(SomeDirective); expect(annoatedDirective).toEqual( new AnnotatedType(SomeDirective, new Decorator({selector: 'someSelector'}))); }); it('should throw if not matching annotation is found', () => { expect(() => { - reflector.annotatedType(SomeDirectiveWithoutAnnotation); + rader.annotatedType(SomeDirectiveWithoutAnnotation); }).toThrowError('No Directive annotation found on SomeDirectiveWithoutAnnotation'); }); diff --git a/modules/core/test/compiler/integration_spec.js b/modules/core/test/compiler/integration_spec.js index 4fa35d0d8e..c637d7d17a 100644 --- a/modules/core/test/compiler/integration_spec.js +++ b/modules/core/test/compiler/integration_spec.js @@ -5,11 +5,10 @@ import {DOM} from 'facade/dom'; import {Injector} from 'di/di'; import {ChangeDetector} from 'change_detection/change_detector'; import {Parser} from 'change_detection/parser/parser'; -import {ClosureMap} from 'change_detection/parser/closure_map'; import {Lexer} from 'change_detection/parser/lexer'; import {Compiler} from 'core/compiler/compiler'; -import {Reflector} from 'core/compiler/reflector'; +import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader'; import {Component} from 'core/annotations/annotations'; import {Decorator} from 'core/annotations/annotations'; @@ -20,8 +19,7 @@ export function main() { var compiler; beforeEach( () => { - var closureMap = new ClosureMap(); - compiler = new Compiler(null, new Reflector(), new Parser(new Lexer(), closureMap), closureMap); + compiler = new Compiler(null, new DirectiveMetadataReader(), new Parser(new Lexer())); }); describe('react to record changes', function() { diff --git a/modules/core/test/compiler/pipeline/directive_parser_spec.js b/modules/core/test/compiler/pipeline/directive_parser_spec.js index d04f127a89..528a087869 100644 --- a/modules/core/test/compiler/pipeline/directive_parser_spec.js +++ b/modules/core/test/compiler/pipeline/directive_parser_spec.js @@ -11,26 +11,24 @@ import {Component} from 'core/annotations/annotations'; import {Decorator} from 'core/annotations/annotations'; import {Template} from 'core/annotations/annotations'; import {TemplateConfig} from 'core/annotations/template_config'; -import {Reflector} from 'core/compiler/reflector'; +import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader'; import {Parser} from 'change_detection/parser/parser'; import {Lexer} from 'change_detection/parser/lexer'; -import {ClosureMap} from 'change_detection/parser/closure_map'; export function main() { describe('DirectiveParser', () => { - var reflector, directives; + var reader, directives; beforeEach( () => { - reflector = new Reflector(); + reader = new DirectiveMetadataReader(); directives = [SomeDecorator, SomeTemplate, SomeTemplate2, SomeComponent, SomeComponent2]; }); function createPipeline({propertyBindings, variableBindings}={}) { - var closureMap = new ClosureMap(); - var parser = new Parser(new Lexer(), closureMap); + var parser = new Parser(new Lexer()); var annotatedDirectives = ListWrapper.create(); for (var i=0; i { @@ -55,7 +53,7 @@ export function main() { describe('component directives', () => { it('should detect them in attributes', () => { var results = createPipeline().process(createElement('
')); - expect(results[0].componentDirective).toEqual(reflector.annotatedType(SomeComponent)); + expect(results[0].componentDirective).toEqual(reader.annotatedType(SomeComponent)); }); it('should detect them in property bindings', () => { @@ -63,7 +61,7 @@ export function main() { 'some-comp': 'someExpr' }}); var results = pipeline.process(createElement('
')); - expect(results[0].componentDirective).toEqual(reflector.annotatedType(SomeComponent)); + expect(results[0].componentDirective).toEqual(reader.annotatedType(SomeComponent)); }); it('should detect them in variable bindings', () => { @@ -71,7 +69,7 @@ export function main() { 'some-comp': 'someExpr' }}); var results = pipeline.process(createElement('
')); - expect(results[0].componentDirective).toEqual(reflector.annotatedType(SomeComponent)); + expect(results[0].componentDirective).toEqual(reader.annotatedType(SomeComponent)); }); it('should not allow multiple component directives on the same element', () => { @@ -94,7 +92,7 @@ export function main() { describe('template directives', () => { it('should detect them in attributes', () => { var results = createPipeline().process(createElement('')); - expect(results[0].templateDirective).toEqual(reflector.annotatedType(SomeTemplate)); + expect(results[0].templateDirective).toEqual(reader.annotatedType(SomeTemplate)); }); it('should detect them in property bindings', () => { @@ -102,7 +100,7 @@ export function main() { 'some-templ': 'someExpr' }}); var results = pipeline.process(createElement('')); - expect(results[0].templateDirective).toEqual(reflector.annotatedType(SomeTemplate)); + expect(results[0].templateDirective).toEqual(reader.annotatedType(SomeTemplate)); }); it('should detect them in variable bindings', () => { @@ -110,7 +108,7 @@ export function main() { 'some-templ': 'someExpr' }}); var results = pipeline.process(createElement('')); - expect(results[0].templateDirective).toEqual(reflector.annotatedType(SomeTemplate)); + expect(results[0].templateDirective).toEqual(reader.annotatedType(SomeTemplate)); }); it('should not allow multiple template directives on the same element', () => { @@ -133,7 +131,7 @@ export function main() { describe('decorator directives', () => { it('should detect them in attributes', () => { var results = createPipeline().process(createElement('
')); - expect(results[0].decoratorDirectives).toEqual([reflector.annotatedType(SomeDecorator)]); + expect(results[0].decoratorDirectives).toEqual([reader.annotatedType(SomeDecorator)]); }); it('should detect them in property bindings', () => { @@ -141,7 +139,7 @@ export function main() { 'some-decor': 'someExpr' }}); var results = pipeline.process(createElement('
')); - expect(results[0].decoratorDirectives).toEqual([reflector.annotatedType(SomeDecorator)]); + expect(results[0].decoratorDirectives).toEqual([reader.annotatedType(SomeDecorator)]); }); it('should detect them in variable bindings', () => { @@ -149,7 +147,7 @@ export function main() { 'some-decor': 'someExpr' }}); var results = pipeline.process(createElement('
')); - expect(results[0].decoratorDirectives).toEqual([reflector.annotatedType(SomeDecorator)]); + expect(results[0].decoratorDirectives).toEqual([reader.annotatedType(SomeDecorator)]); }); it('should not allow decorator directives on