feat(Reflection): extract reflection capabilities into a separate module

This commit is contained in:
vsavkin
2014-11-20 12:07:48 -08:00
parent 044625a098
commit 6e8175a816
46 changed files with 637 additions and 416 deletions

View File

@ -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);

View File

@ -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<CompileStep> {
@ -37,16 +34,16 @@ export class Compiler {
var directives = annotation.template.directives;
var annotatedDirectives = ListWrapper.create();
for (var i=0; i<directives.length; i++) {
ListWrapper.push(annotatedDirectives, this._reflector.annotatedType(directives[i]));
ListWrapper.push(annotatedDirectives, this._reader.annotatedType(directives[i]));
}
return createDefaultSteps(this._parser, this._closureMap, annotatedDirectives);
return createDefaultSteps(this._parser, annotatedDirectives);
}
compile(component:Type, templateRoot:Element = null):Promise<ProtoView> {
// 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)
);
}

View File

@ -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<annotations.length; i++) {
var annotation = annotations[i];
if (annotation instanceof Directive) {
@ -21,6 +22,6 @@ export class Reflector {
}
}
}
throw new BaseException('No Directive annotation found on ' + type.name);
throw new BaseException(`No Directive annotation found on ${stringify(type)}`);
}
}

View File

@ -1,5 +1,4 @@
import {Parser} from 'change_detection/parser/parser';
import {ClosureMap} from 'change_detection/parser/closure_map';
import {List} from 'facade/collection';
import {PropertyBindingParser} from './property_binding_parser';
@ -16,10 +15,7 @@ import {ElementBinderBuilder} from './element_binder_builder';
* Takes in an HTMLElement and produces the ProtoViews,
* ProtoElementInjectors and ElementBinders in the end.
*/
export function createDefaultSteps(
parser:Parser, closureMap:ClosureMap,
directives: List<AnnotatedType>
) {
export function createDefaultSteps(parser:Parser, directives: List<AnnotatedType>) {
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()
];
}

View File

@ -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

View File

@ -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)
);
});
});

View File

@ -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);
}
}

View File

@ -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';

View File

@ -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<CompileStep>) {
super(templateLoader, reflector, parser, closureMap);
constructor(templateLoader:TemplateLoader, reader:DirectiveMetadataReader, parser, steps:List<CompileStep>) {
super(templateLoader, reader, parser);
this.steps = steps;
}
createSteps(component):List<CompileStep> {

View File

@ -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');
});

View File

@ -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() {

View File

@ -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<directives.length; i++) {
ListWrapper.push(annotatedDirectives, reflector.annotatedType(directives[i]));
ListWrapper.push(annotatedDirectives, reader.annotatedType(directives[i]));
}
return new CompilePipeline([new MockStep((parent, current, control) => {
@ -55,7 +53,7 @@ export function main() {
describe('component directives', () => {
it('should detect them in attributes', () => {
var results = createPipeline().process(createElement('<div some-comp></div>'));
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('<div></div>'));
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('<div></div>'));
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('<template some-templ></template>'));
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('<template></template>'));
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('<template></template>'));
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('<div some-decor></div>'));
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('<div></div>'));
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('<div></div>'));
expect(results[0].decoratorDirectives).toEqual([reflector.annotatedType(SomeDecorator)]);
expect(results[0].decoratorDirectives).toEqual([reader.annotatedType(SomeDecorator)]);
});
it('should not allow decorator directives on <template> elements', () => {

View File

@ -14,12 +14,11 @@ import {Template} from 'core/annotations/annotations';
import {Component} from 'core/annotations/annotations';
import {ProtoView, ElementPropertyMemento, DirectivePropertyMemento} from 'core/compiler/view';
import {ProtoElementInjector} from 'core/compiler/element_injector';
import {Reflector} from 'core/compiler/reflector';
import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader';
import {ProtoRecordRange} from 'change_detection/record_range';
import {Parser} from 'change_detection/parser/parser';
import {Lexer} from 'change_detection/parser/lexer';
import {ClosureMap} from 'change_detection/parser/closure_map';
import {ChangeDetector} from 'change_detection/change_detector';
import {Injector} from 'di/di';
@ -29,9 +28,8 @@ export function main() {
function createPipeline({textNodeBindings, propertyBindings, eventBindings, directives, protoElementInjector
}={}) {
var reflector = new Reflector();
var closureMap = new ClosureMap();
var parser = new Parser(new Lexer(), closureMap);
var reflector = new DirectiveMetadataReader();
var parser = new Parser(new Lexer());
return new CompilePipeline([
new MockStep((parent, current, control) => {
if (isPresent(current.element.getAttribute('viewroot'))) {
@ -74,7 +72,7 @@ export function main() {
current.hasBindings = true;
DOM.addClass(current.element, 'ng-binding');
}
}), new ElementBinderBuilder(closureMap)
}), new ElementBinderBuilder()
]);
}

View File

@ -8,16 +8,14 @@ import {CompilePipeline} from 'core/compiler/pipeline/compile_pipeline';
import {CompileElement} from 'core/compiler/pipeline/compile_element';
import {CompileStep} from 'core/compiler/pipeline/compile_step'
import {CompileControl} from 'core/compiler/pipeline/compile_control';
import {Reflector} from 'core/compiler/reflector';
import {Template} from 'core/annotations/annotations';
import {Decorator} from 'core/annotations/annotations';
import {Component} from 'core/annotations/annotations';
import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader';
import {Template, Decorator, Component} from 'core/annotations/annotations';
export function main() {
describe('ElementBindingMarker', () => {
function createPipeline({textNodeBindings, propertyBindings, variableBindings, eventBindings, directives}={}) {
var reflector = new Reflector();
var reader = new DirectiveMetadataReader();
return new CompilePipeline([
new MockStep((parent, current, control) => {
if (isPresent(textNodeBindings)) {
@ -34,7 +32,7 @@ export function main() {
}
if (isPresent(directives)) {
for (var i=0; i<directives.length; i++) {
current.addDirective(reflector.annotatedType(directives[i]));
current.addDirective(reader.annotatedType(directives[i]));
}
}
}), new ElementBindingMarker()

View File

@ -5,13 +5,12 @@ import {DOM} from 'facade/dom';
import {MapWrapper} from 'facade/collection';
import {Parser} from 'change_detection/parser/parser';
import {ClosureMap} from 'change_detection/parser/closure_map';
import {Lexer} from 'change_detection/parser/lexer';
export function main() {
describe('PropertyBindingParser', () => {
function createPipeline() {
return new CompilePipeline([new PropertyBindingParser(new Parser(new Lexer(), new ClosureMap()))]);
return new CompilePipeline([new PropertyBindingParser(new Parser(new Lexer()))]);
}
it('should detect [] syntax', () => {

View File

@ -9,10 +9,8 @@ import {CompileElement} from 'core/compiler/pipeline/compile_element';
import {CompileStep} from 'core/compiler/pipeline/compile_step'
import {CompileControl} from 'core/compiler/pipeline/compile_control';
import {ProtoView} from 'core/compiler/view';
import {Reflector} from 'core/compiler/reflector';
import {Template} from 'core/annotations/annotations';
import {Decorator} from 'core/annotations/annotations';
import {Component} from 'core/annotations/annotations';
import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader';
import {Template, Decorator, Component} from 'core/annotations/annotations';
import {ProtoElementInjector} from 'core/compiler/element_injector';
export function main() {
@ -27,14 +25,14 @@ export function main() {
if (isBlank(directives)) {
directives = [];
}
var reflector = new Reflector();
var reader = new DirectiveMetadataReader();
return new CompilePipeline([new MockStep((parent, current, control) => {
if (isPresent(current.element.getAttribute('viewroot'))) {
current.isViewRoot = true;
}
if (isPresent(current.element.getAttribute('directives'))) {
for (var i=0; i<directives.length; i++) {
current.addDirective(reflector.annotatedType(directives[i]));
current.addDirective(reader.annotatedType(directives[i]));
}
}
current.inheritedProtoView = protoView;

View File

@ -5,13 +5,12 @@ import {DOM} from 'facade/dom';
import {MapWrapper} from 'facade/collection';
import {Parser} from 'change_detection/parser/parser';
import {ClosureMap} from 'change_detection/parser/closure_map';
import {Lexer} from 'change_detection/parser/lexer';
export function main() {
describe('TextInterpolationParser', () => {
function createPipeline() {
return new CompilePipeline([new TextInterpolationParser(new Parser(new Lexer(), new ClosureMap()))]);
return new CompilePipeline([new TextInterpolationParser(new Parser(new Lexer()))]);
}
it('should find text interpolation in normal elements', () => {

View File

@ -7,14 +7,13 @@ import {CompilePipeline} from 'core/compiler/pipeline/compile_pipeline';
import {DOM, TemplateElement} from 'facade/dom';
import {Parser} from 'change_detection/parser/parser';
import {ClosureMap} from 'change_detection/parser/closure_map';
import {Lexer} from 'change_detection/parser/lexer';
export function main() {
describe('ViewSplitter', () => {
function createPipeline() {
return new CompilePipeline([new ViewSplitter(new Parser(new Lexer(), new ClosureMap()))]);
return new CompilePipeline([new ViewSplitter(new Parser(new Lexer()))]);
}
it('should mark root elements as viewRoot', () => {

View File

@ -1,28 +1,26 @@
import {describe, xit, it, expect, beforeEach, ddescribe, iit} from 'test_lib/test_lib';
import {ProtoView, ElementPropertyMemento, DirectivePropertyMemento} from 'core/compiler/view';
import {ProtoElementInjector, ElementInjector} from 'core/compiler/element_injector';
import {Reflector} from 'core/compiler/reflector';
import {Component} from 'core/annotations/annotations';
import {Decorator} from 'core/annotations/annotations';
import {DirectiveMetadataReader} from 'core/compiler/directive_metadata_reader';
import {Component, Decorator} from 'core/annotations/annotations';
import {ProtoRecordRange} from 'change_detection/record_range';
import {ChangeDetector} from 'change_detection/change_detector';
import {TemplateConfig} from 'core/annotations/template_config';
import {Parser} from 'change_detection/parser/parser';
import {ClosureMap} from 'change_detection/parser/closure_map';
import {Lexer} from 'change_detection/parser/lexer';
import {DOM, Element} from 'facade/dom';
import {FIELD} from 'facade/lang';
import {Injector} from 'di/di';
import {View} from 'core/compiler/view';
import {reflector} from 'reflection/reflection';
export function main() {
describe('view', function() {
var parser, closureMap, someComponentDirective;
var parser, someComponentDirective;
beforeEach(() => {
closureMap = new ClosureMap();
parser = new Parser(new Lexer(), closureMap);
someComponentDirective = new Reflector().annotatedType(SomeComponent);
parser = new Parser(new Lexer());
someComponentDirective = new DirectiveMetadataReader().annotatedType(SomeComponent);
});
@ -263,7 +261,7 @@ export function main() {
var pv = new ProtoView(createElement('<div class="ng-binding"></div>'),
new ProtoRecordRange());
pv.bindElement(new ProtoElementInjector(null, 0, [SomeDirective]));
pv.bindDirectiveProperty( 0, parser.parseBinding('foo').ast, 'prop', closureMap.setter('prop'));
pv.bindDirectiveProperty( 0, parser.parseBinding('foo').ast, 'prop', reflector.setter('prop'));
createView(pv);
ctx.foo = 'buz';