diff --git a/modules/angular2/test/render/dom/compiler/compiler_browser_spec.js b/modules/angular2/test/render/dom/compiler/compiler_browser_spec.ts similarity index 66% rename from modules/angular2/test/render/dom/compiler/compiler_browser_spec.js rename to modules/angular2/test/render/dom/compiler/compiler_browser_spec.ts index aedb546227..b8c35ff7dc 100644 --- a/modules/angular2/test/render/dom/compiler/compiler_browser_spec.js +++ b/modules/angular2/test/render/dom/compiler/compiler_browser_spec.ts @@ -1,6 +1,6 @@ - /* - * Runs compiler tests using in-browser DOM adapter. - */ +/* +* Runs compiler tests using in-browser DOM adapter. +*/ import {runCompilerCommonTests} from './compiler_common_tests'; diff --git a/modules/angular2/test/render/dom/compiler/compiler_common_tests.js b/modules/angular2/test/render/dom/compiler/compiler_common_tests.js deleted file mode 100644 index d71a8d3d1d..0000000000 --- a/modules/angular2/test/render/dom/compiler/compiler_common_tests.js +++ /dev/null @@ -1,229 +0,0 @@ -import { - AsyncTestCompleter, - beforeEach, - ddescribe, - describe, - el, - expect, - iit, - inject, - IS_DARTIUM, - it, -} from 'angular2/test_lib'; - -import {DOM} from 'angular2/src/dom/dom_adapter'; -import {List, ListWrapper, Map, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection'; -import {Type, isBlank, stringify, isPresent} from 'angular2/src/facade/lang'; -import {PromiseWrapper, Promise} from 'angular2/src/facade/async'; - -import {DomCompiler} from 'angular2/src/render/dom/compiler/compiler'; -import {ProtoViewDto, ViewDefinition, DirectiveMetadata} from 'angular2/src/render/api'; -import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element'; -import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step' -import {CompileStepFactory} from 'angular2/src/render/dom/compiler/compile_step_factory'; -import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control'; -import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader'; - -import {UrlResolver} from 'angular2/src/services/url_resolver'; - -import {resolveInternalDomProtoView} from 'angular2/src/render/dom/view/proto_view'; - -export function runCompilerCommonTests() { - describe('DomCompiler', function() { - var mockStepFactory; - - function createCompiler(processClosure, urlData = null) { - if (isBlank(urlData)) { - urlData = MapWrapper.create(); - } - var tplLoader = new FakeTemplateLoader(urlData); - mockStepFactory = new MockStepFactory([new MockStep(processClosure)]); - return new DomCompiler(mockStepFactory, tplLoader); - } - - describe('compile', () => { - - it('should run the steps and build the AppProtoView of the root element', inject([AsyncTestCompleter], (async) => { - var compiler = createCompiler((parent, current, control) => { - current.inheritedProtoView.bindVariable('b', 'a'); - }); - compiler.compile(new ViewDefinition({ - componentId: 'someComponent', - template: '
' - })).then( (protoView) => { - expect(protoView.variableBindings).toEqual(MapWrapper.createFromStringMap({ - 'a': 'b' - })); - async.done(); - }); - })); - - it('should run the steps and build the proto view', inject([AsyncTestCompleter], (async) => { - var compiler = createCompiler((parent, current, control) => { - current.inheritedProtoView.bindVariable('b', 'a'); - }); - - var dirMetadata = new DirectiveMetadata({id: 'id', selector: 'CUSTOM', type: DirectiveMetadata.COMPONENT_TYPE}); - compiler.compileHost(dirMetadata).then( (protoView) => { - expect(DOM.tagName(resolveInternalDomProtoView(protoView.render).element)).toEqual('CUSTOM') - expect(mockStepFactory.viewDef.directives).toEqual([dirMetadata]); - expect(protoView.variableBindings).toEqual(MapWrapper.createFromStringMap({ - 'a': 'b' - })); - async.done(); - }); - })); - - it('should use the inline template and compile in sync', inject([AsyncTestCompleter], (async) => { - var compiler = createCompiler(EMPTY_STEP); - compiler.compile(new ViewDefinition({ - componentId: 'someId', - template: 'inline component' - })).then( (protoView) => { - expect(DOM.getInnerHTML(resolveInternalDomProtoView(protoView.render).element)).toEqual('inline component'); - async.done(); - }); - })); - - it('should load url templates', inject([AsyncTestCompleter], (async) => { - var urlData = MapWrapper.createFromStringMap({ - 'someUrl': 'url component' - }); - var compiler = createCompiler(EMPTY_STEP, urlData); - compiler.compile(new ViewDefinition({ - componentId: 'someId', - absUrl: 'someUrl' - })).then( (protoView) => { - expect(DOM.getInnerHTML(resolveInternalDomProtoView(protoView.render).element)).toEqual('url component'); - async.done(); - }); - })); - - it('should report loading errors', inject([AsyncTestCompleter], (async) => { - var compiler = createCompiler(EMPTY_STEP, MapWrapper.create()); - PromiseWrapper.catchError(compiler.compile(new ViewDefinition({ - componentId: 'someId', - absUrl: 'someUrl' - })), (e) => { - expect(e.message).toContain(`Failed to load the template "someId"`); - async.done(); - }); - })); - - it('should wait for async subtasks to be resolved', inject([AsyncTestCompleter], (async) => { - var subTasksCompleted = false; - - var completer = PromiseWrapper.completer(); - - var compiler = createCompiler( (parent, current, control) => { - ListWrapper.push(mockStepFactory.subTaskPromises, completer.promise.then((_) => { - subTasksCompleted = true; - })); - }); - - // It should always return a Promise because the subtask is async - var pvPromise = compiler.compile(new ViewDefinition({ - componentId: 'someId', - template: 'some component' - })); - expect(pvPromise).toBePromise(); - expect(subTasksCompleted).toEqual(false); - - // The Promise should resolve after the subtask is ready - completer.resolve(null); - pvPromise.then((protoView) => { - expect(subTasksCompleted).toEqual(true); - async.done(); - }); - })); - - it('should return ProtoViews of type COMPONENT_VIEW_TYPE', inject([AsyncTestCompleter], (async) => { - var compiler = createCompiler(EMPTY_STEP); - compiler.compile(new ViewDefinition({ - componentId: 'someId', - template: 'inline component' - })).then( (protoView) => { - expect(protoView.type).toEqual(ProtoViewDto.COMPONENT_VIEW_TYPE); - async.done(); - }); - })); - - }); - - describe('compileHost', () => { - - it('should return ProtoViews of type HOST_VIEW_TYPE', inject([AsyncTestCompleter], (async) => { - var compiler = createCompiler(EMPTY_STEP); - compiler.compileHost(someComponent).then( (protoView) => { - expect(protoView.type).toEqual(ProtoViewDto.HOST_VIEW_TYPE); - async.done(); - }); - })); - - }); - - }); - -} - -class MockStepFactory extends CompileStepFactory { - steps:List; - subTaskPromises:List; - viewDef:ViewDefinition; - - constructor(steps) { - super(); - this.steps = steps; - } - createSteps(viewDef, subTaskPromises) { - this.viewDef = viewDef; - this.subTaskPromises = subTaskPromises; - ListWrapper.forEach(this.subTaskPromises, (p) => ListWrapper.push(subTaskPromises, p) ); - return this.steps; - } -} - -class MockStep /*implements CompileStep*/ { - processClosure:Function; - constructor(process) { - this.processClosure = process; - } - process(parent:CompileElement, current:CompileElement, control:CompileControl) { - this.processClosure(parent, current, control); - } -} - -var EMPTY_STEP = (parent, current, control) => { - if (isPresent(parent)) { - current.inheritedProtoView = parent.inheritedProtoView; - } -}; - -class FakeTemplateLoader extends TemplateLoader { - _urlData: Map; - constructor(urlData) { - super(null, new UrlResolver()); - this._urlData = urlData; - } - - load(template: ViewDefinition) { - if (isPresent(template.template)) { - return PromiseWrapper.resolve(DOM.createTemplate(template.template)); - } - - if (isPresent(template.absUrl)) { - var content = MapWrapper.get(this._urlData, template.absUrl); - if (isPresent(content)) { - return PromiseWrapper.resolve(DOM.createTemplate(content)); - } - } - - return PromiseWrapper.reject('Load failed', null); - } -} - -var someComponent = new DirectiveMetadata({ - selector: 'some-comp', - id: 'someComponent', - type: DirectiveMetadata.COMPONENT_TYPE -}); diff --git a/modules/angular2/test/render/dom/compiler/compiler_common_tests.ts b/modules/angular2/test/render/dom/compiler/compiler_common_tests.ts new file mode 100644 index 0000000000..eeca0a8966 --- /dev/null +++ b/modules/angular2/test/render/dom/compiler/compiler_common_tests.ts @@ -0,0 +1,221 @@ +import { + AsyncTestCompleter, + beforeEach, + ddescribe, + describe, + el, + expect, + iit, + inject, + IS_DARTIUM, + it, +} from 'angular2/test_lib'; + +import {DOM} from 'angular2/src/dom/dom_adapter'; +import {List, ListWrapper, Map, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection'; +import {Type, isBlank, stringify, isPresent} from 'angular2/src/facade/lang'; +import {PromiseWrapper, Promise} from 'angular2/src/facade/async'; + +import {DomCompiler} from 'angular2/src/render/dom/compiler/compiler'; +import {ProtoViewDto, ViewDefinition, DirectiveMetadata} from 'angular2/src/render/api'; +import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element'; +import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step'; +import {CompileStepFactory} from 'angular2/src/render/dom/compiler/compile_step_factory'; +import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control'; +import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader'; + +import {UrlResolver} from 'angular2/src/services/url_resolver'; + +import {resolveInternalDomProtoView} from 'angular2/src/render/dom/view/proto_view'; + +export function runCompilerCommonTests() { + describe('DomCompiler', function() { + var mockStepFactory; + + function createCompiler(processClosure, urlData = null) { + if (isBlank(urlData)) { + urlData = MapWrapper.create(); + } + var tplLoader = new FakeTemplateLoader(urlData); + mockStepFactory = new MockStepFactory([new MockStep(processClosure)]); + return new DomCompiler(mockStepFactory, tplLoader); + } + + describe('compile', () => { + + it('should run the steps and build the AppProtoView of the root element', + inject([AsyncTestCompleter], (async) => { + var compiler = createCompiler((parent, current, control) => { + current.inheritedProtoView.bindVariable('b', 'a'); + }); + compiler.compile( + new ViewDefinition({componentId: 'someComponent', template: '
'})) + .then((protoView) => { + expect(protoView.variableBindings) + .toEqual(MapWrapper.createFromStringMap({'a': 'b'})); + async.done(); + }); + })); + + it('should run the steps and build the proto view', inject([AsyncTestCompleter], (async) => { + var compiler = createCompiler((parent, current, control) => { + current.inheritedProtoView.bindVariable('b', 'a'); + }); + + var dirMetadata = new DirectiveMetadata( + {id: 'id', selector: 'CUSTOM', type: DirectiveMetadata.COMPONENT_TYPE}); + compiler.compileHost(dirMetadata) + .then((protoView) => { + expect(DOM.tagName(resolveInternalDomProtoView(protoView.render).element)) + .toEqual('CUSTOM'); + expect(mockStepFactory.viewDef.directives).toEqual([dirMetadata]); + expect(protoView.variableBindings) + .toEqual(MapWrapper.createFromStringMap({'a': 'b'})); + async.done(); + }); + })); + + it('should use the inline template and compile in sync', + inject([AsyncTestCompleter], (async) => { + var compiler = createCompiler(EMPTY_STEP); + compiler.compile( + new ViewDefinition({componentId: 'someId', template: 'inline component'})) + .then((protoView) => { + expect(DOM.getInnerHTML(resolveInternalDomProtoView(protoView.render).element)) + .toEqual('inline component'); + async.done(); + }); + })); + + it('should load url templates', inject([AsyncTestCompleter], (async) => { + var urlData = MapWrapper.createFromStringMap({'someUrl': 'url component'}); + var compiler = createCompiler(EMPTY_STEP, urlData); + compiler.compile(new ViewDefinition({componentId: 'someId', absUrl: 'someUrl'})) + .then((protoView) => { + expect(DOM.getInnerHTML(resolveInternalDomProtoView(protoView.render).element)) + .toEqual('url component'); + async.done(); + }); + })); + + it('should report loading errors', inject([AsyncTestCompleter], (async) => { + var compiler = createCompiler(EMPTY_STEP, MapWrapper.create()); + PromiseWrapper.catchError( + compiler.compile(new ViewDefinition({componentId: 'someId', absUrl: 'someUrl'})), + (e) => { + expect(e.message).toContain(`Failed to load the template "someId"`); + async.done(); + return null; + }); + })); + + it('should wait for async subtasks to be resolved', inject([AsyncTestCompleter], (async) => { + var subTasksCompleted = false; + + var completer = PromiseWrapper.completer(); + + var compiler = createCompiler((parent, current, control) => { + ListWrapper.push(mockStepFactory.subTaskPromises, + completer.promise.then((_) => { subTasksCompleted = true; })); + }); + + // It should always return a Promise because the subtask is async + var pvPromise = compiler.compile( + new ViewDefinition({componentId: 'someId', template: 'some component'})); + expect(pvPromise).toBePromise(); + expect(subTasksCompleted).toEqual(false); + + // The Promise should resolve after the subtask is ready + completer.resolve(null); + pvPromise.then((protoView) => { + expect(subTasksCompleted).toEqual(true); + async.done(); + }); + })); + + it('should return ProtoViews of type COMPONENT_VIEW_TYPE', + inject([AsyncTestCompleter], (async) => { + var compiler = createCompiler(EMPTY_STEP); + compiler.compile( + new ViewDefinition({componentId: 'someId', template: 'inline component'})) + .then((protoView) => { + expect(protoView.type).toEqual(ProtoViewDto.COMPONENT_VIEW_TYPE); + async.done(); + }); + })); + + }); + + describe('compileHost', () => { + + it('should return ProtoViews of type HOST_VIEW_TYPE', + inject([AsyncTestCompleter], (async) => { + var compiler = createCompiler(EMPTY_STEP); + compiler.compileHost(someComponent) + .then((protoView) => { + expect(protoView.type).toEqual(ProtoViewDto.HOST_VIEW_TYPE); + async.done(); + }); + })); + + }); + + }); +} + +class MockStepFactory extends CompileStepFactory { + steps: List; + subTaskPromises: List>; + viewDef: ViewDefinition; + + constructor(steps) { + super(); + this.steps = steps; + } + createSteps(viewDef, subTaskPromises) { + this.viewDef = viewDef; + this.subTaskPromises = subTaskPromises; + ListWrapper.forEach(this.subTaskPromises, (p) => ListWrapper.push(subTaskPromises, p)); + return this.steps; + } +} + +class MockStep implements CompileStep { + processClosure: Function; + constructor(process) { this.processClosure = process; } + process(parent: CompileElement, current: CompileElement, control: CompileControl) { + this.processClosure(parent, current, control); + } +} + +var EMPTY_STEP = (parent, current, control) => { + if (isPresent(parent)) { + current.inheritedProtoView = parent.inheritedProtoView; + } +}; + +class FakeTemplateLoader extends TemplateLoader { + _urlData: Map; + constructor(urlData) { + super(null, new UrlResolver()); + this._urlData = urlData; + } + + load(template: ViewDefinition) { + if (isPresent(template.template)) { + return PromiseWrapper.resolve(DOM.createTemplate(template.template)); + } + + if (isPresent(template.absUrl)) { + var content = MapWrapper.get(this._urlData, template.absUrl); + if (isPresent(content)) { + return PromiseWrapper.resolve(DOM.createTemplate(content)); + } + } + + return PromiseWrapper.reject('Load failed', null); + } +} + +var someComponent = new DirectiveMetadata( + {selector: 'some-comp', id: 'someComponent', type: DirectiveMetadata.COMPONENT_TYPE}); diff --git a/modules/angular2/test/render/dom/compiler/directive_parser_spec.js b/modules/angular2/test/render/dom/compiler/directive_parser_spec.ts similarity index 68% rename from modules/angular2/test/render/dom/compiler/directive_parser_spec.js rename to modules/angular2/test/render/dom/compiler/directive_parser_spec.ts index 0cd68caf27..f1ea8096e6 100644 --- a/modules/angular2/test/render/dom/compiler/directive_parser_spec.js +++ b/modules/angular2/test/render/dom/compiler/directive_parser_spec.ts @@ -9,12 +9,13 @@ import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element'; import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control'; import {ViewDefinition, DirectiveMetadata} from 'angular2/src/render/api'; import {Lexer, Parser} from 'angular2/change_detection'; +import {ElementBinderBuilder} from 'angular2/src/render/dom/view/proto_view_builder'; export function main() { describe('DirectiveParser', () => { var parser, annotatedDirectives; - beforeEach( () => { + beforeEach(() => { annotatedDirectives = [ someComponent, someComponent2, @@ -35,20 +36,21 @@ export function main() { if (isBlank(directives)) directives = annotatedDirectives; return new CompilePipeline([ - new MockStep( (parent, current, control) => { - if (isPresent(propertyBindings)) { - StringMapWrapper.forEach(propertyBindings, (ast, name) => { - current.bindElement().bindProperty(name, ast); - }); - } - }), + new MockStep((parent, current, control) => + { + if (isPresent(propertyBindings)) { + StringMapWrapper.forEach(propertyBindings, (ast, name) => { + current.bindElement().bindProperty(name, ast); + }); + } + }), new DirectiveParser(parser, directives) ]); } - function process(el, propertyBindings = null, directives = null) { + function process(el, propertyBindings = null, directives = null): List { var pipeline = createPipeline(propertyBindings, directives); - return ListWrapper.map(pipeline.process(el), (ce) => ce.inheritedElementBinder ); + return ListWrapper.map(pipeline.process(el), (ce) => ce.inheritedElementBinder); } it('should not add directives if they are not used', () => { @@ -58,16 +60,14 @@ export function main() { it('should detect directives in attributes', () => { var results = process(el('
')); - expect(results[0].directives[0].directiveIndex).toBe( - annotatedDirectives.indexOf(someDirective) - ); + expect(results[0].directives[0].directiveIndex) + .toBe(annotatedDirectives.indexOf(someDirective)); }); it('should detect directives with multiple attributes', () => { var results = process(el('')); - expect(results[0].directives[0].directiveIndex).toBe( - annotatedDirectives.indexOf(decoratorWithMultipleAttrs) - ); + expect(results[0].directives[0].directiveIndex) + .toBe(annotatedDirectives.indexOf(decoratorWithMultipleAttrs)); }); it('should compile children by default', () => { @@ -81,36 +81,26 @@ export function main() { }); it('should bind directive properties from bound properties', () => { - var results = process( - el('
'), - { - 'elProp': parser.parseBinding('someExpr', '') - } - ); + var results = process(el('
'), + {'elProp': parser.parseBinding('someExpr', '')}); var directiveBinding = results[0].directives[0]; expect(MapWrapper.get(directiveBinding.propertyBindings, 'dirProp').source) - .toEqual('someExpr'); + .toEqual('someExpr'); }); it('should bind directive properties with pipes', () => { - var results = process( - el('
'), - { - 'elProp': parser.parseBinding('someExpr', '') - } - ); + var results = process(el('
'), + {'elProp': parser.parseBinding('someExpr', '')}); var directiveBinding = results[0].directives[0]; - var pipedProp = MapWrapper.get(directiveBinding.propertyBindings, 'doubleProp'); - var simpleProp = MapWrapper.get(directiveBinding.propertyBindings, 'dirProp'); + var pipedProp = MapWrapper.get(directiveBinding.propertyBindings, 'doubleProp'); + var simpleProp = MapWrapper.get(directiveBinding.propertyBindings, 'dirProp'); expect(pipedProp.ast.name).toEqual('double'); expect(pipedProp.ast.exp).toEqual(simpleProp.ast); expect(simpleProp.source).toEqual('someExpr'); }); it('should bind directive properties from attribute values', () => { - var results = process( - el('
') - ); + var results = process(el('
')); var directiveBinding = results[0].directives[0]; var simpleProp = MapWrapper.get(directiveBinding.propertyBindings, 'dirProp'); expect(simpleProp.source).toEqual('someValue'); @@ -160,9 +150,7 @@ export function main() { }); it('should bind directive events', () => { - var results = process( - el('
') - ); + var results = process(el('
')); var directiveBinding = results[0].directives[0]; expect(directiveBinding.eventBindings.length).toEqual(1); var eventBinding = directiveBinding.eventBindings[0]; @@ -171,9 +159,7 @@ export function main() { }); it('should bind directive global events', () => { - var results = process( - el('
') - ); + var results = process(el('
')); var directiveBinding = results[0].directives[0]; expect(directiveBinding.eventBindings.length).toEqual(1); var eventBinding = directiveBinding.eventBindings[0]; @@ -182,83 +168,61 @@ export function main() { }); it('should bind directive host actions', () => { - var results = process( - el('
') - ); + var results = process(el('
')); var directiveBinding = results[0].directives[0]; expect(directiveBinding.hostActions[0].actionName).toEqual('focus'); }); - //TODO: assertions should be enabled when running tests: https://github.com/angular/angular/issues/1340 + // TODO: assertions should be enabled when running tests: + // https://github.com/angular/angular/issues/1340 describe('component directives', () => { it('should save the component id', () => { - var results = process( - el('') - ); + var results = process(el('')); expect(results[0].componentId).toEqual('someComponent'); }); it('should throw when the provided selector is not an element selector', () => { - expect( () => { - createPipeline(null, [componentWithNonElementSelector]); - }).toThrowError(`Component 'componentWithNonElementSelector' can only have an element selector, but had '[attr]'`); + expect(() => { createPipeline(null, [componentWithNonElementSelector]); }) + .toThrowError( + `Component 'componentWithNonElementSelector' can only have an element selector, but had '[attr]'`); }); it('should not allow multiple component directives on the same element', () => { - expect( () => { - process( - el(''), - null, - [someComponent, someComponentDup] - ); - }).toThrowError(new RegExp('Only one component directive is allowed per element' )); + expect(() => { + process(el(''), null, [someComponent, someComponentDup]); + }).toThrowError(new RegExp('Only one component directive is allowed per element')); }); it('should sort the directives and store the component as the first directive', () => { - var results = process( - el('') - ); - expect(annotatedDirectives[results[0].directives[0].directiveIndex].id).toEqual('someComponent'); - expect(annotatedDirectives[results[0].directives[1].directiveIndex].id).toEqual('someDirective'); + var results = process(el('')); + expect(annotatedDirectives[results[0].directives[0].directiveIndex].id) + .toEqual('someComponent'); + expect(annotatedDirectives[results[0].directives[1].directiveIndex].id) + .toEqual('someDirective'); }); }); }); } -@IMPLEMENTS(CompileStep) -class MockStep { - processClosure:Function; - constructor(process) { - this.processClosure = process; - } - process(parent:CompileElement, current:CompileElement, control:CompileControl) { +class MockStep implements CompileStep { + processClosure: Function; + constructor(process) { this.processClosure = process; } + process(parent: CompileElement, current: CompileElement, control: CompileControl) { this.processClosure(parent, current, control); } } -var someComponent = new DirectiveMetadata({ - selector: 'some-comp', - id: 'someComponent', - type: DirectiveMetadata.COMPONENT_TYPE -}); +var someComponent = new DirectiveMetadata( + {selector: 'some-comp', id: 'someComponent', type: DirectiveMetadata.COMPONENT_TYPE}); -var someComponentDup = new DirectiveMetadata({ - selector: 'some-comp', - id: 'someComponentDup', - type: DirectiveMetadata.COMPONENT_TYPE -}); +var someComponentDup = new DirectiveMetadata( + {selector: 'some-comp', id: 'someComponentDup', type: DirectiveMetadata.COMPONENT_TYPE}); -var someComponent2 = new DirectiveMetadata({ - selector: 'some-comp2', - id: 'someComponent2', - type: DirectiveMetadata.COMPONENT_TYPE -}); +var someComponent2 = new DirectiveMetadata( + {selector: 'some-comp2', id: 'someComponent2', type: DirectiveMetadata.COMPONENT_TYPE}); -var someDirective = new DirectiveMetadata({ - selector: '[some-decor]', - id: 'someDirective', - type: DirectiveMetadata.DIRECTIVE_TYPE -}); +var someDirective = new DirectiveMetadata( + {selector: '[some-decor]', id: 'someDirective', type: DirectiveMetadata.DIRECTIVE_TYPE}); var someDirectiveIgnoringChildren = new DirectiveMetadata({ selector: '[some-decor-ignoring-children]', @@ -275,47 +239,34 @@ var decoratorWithMultipleAttrs = new DirectiveMetadata({ var someDirectiveWithProps = new DirectiveMetadata({ selector: '[some-decor-props]', - properties: MapWrapper.createFromStringMap({ - 'dirProp': 'elProp', - 'doubleProp': 'elProp | double' - }), + properties: + MapWrapper.createFromStringMap({'dirProp': 'elProp', 'doubleProp': 'elProp | double'}), readAttributes: ['some-attr'] }); var someDirectiveWithHostProperties = new DirectiveMetadata({ selector: '[some-decor-with-host-props]', - hostProperties: MapWrapper.createFromStringMap({ - 'dirProp': 'hostProperty' - }) + hostProperties: MapWrapper.createFromStringMap({'dirProp': 'hostProperty'}) }); var someDirectiveWithHostAttributes = new DirectiveMetadata({ selector: '[some-decor-with-host-attrs]', - hostAttributes: MapWrapper.createFromStringMap({ - 'attr_name': 'attr_val', - 'class': 'foo bar' - }) + hostAttributes: MapWrapper.createFromStringMap({'attr_name': 'attr_val', 'class': 'foo bar'}) }); var someDirectiveWithEvents = new DirectiveMetadata({ selector: '[some-decor-events]', - hostListeners: MapWrapper.createFromStringMap({ - 'click': 'doIt()' - }) + hostListeners: MapWrapper.createFromStringMap({'click': 'doIt()'}) }); var someDirectiveWithHostActions = new DirectiveMetadata({ selector: '[some-decor-host-actions]', - hostActions: MapWrapper.createFromStringMap({ - 'focus': 'focus()' - }) + hostActions: MapWrapper.createFromStringMap({'focus': 'focus()'}) }); var someDirectiveWithGlobalEvents = new DirectiveMetadata({ selector: '[some-decor-globalevents]', - hostListeners: MapWrapper.createFromStringMap({ - 'window:resize': 'doItGlobal()' - }) + hostListeners: MapWrapper.createFromStringMap({'window:resize': 'doItGlobal()'}) }); var componentWithNonElementSelector = new DirectiveMetadata({ diff --git a/modules/angular2/test/render/dom/compiler/pipeline_spec.js b/modules/angular2/test/render/dom/compiler/pipeline_spec.ts similarity index 83% rename from modules/angular2/test/render/dom/compiler/pipeline_spec.js rename to modules/angular2/test/render/dom/compiler/pipeline_spec.ts index 4577407123..839ba75881 100644 --- a/modules/angular2/test/render/dom/compiler/pipeline_spec.js +++ b/modules/angular2/test/render/dom/compiler/pipeline_spec.ts @@ -5,7 +5,7 @@ import {isPresent, NumberWrapper, StringWrapper, IMPLEMENTS} from 'angular2/src/ import {CompilePipeline} from 'angular2/src/render/dom/compiler/compile_pipeline'; import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element'; -import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step' +import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step'; import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control'; import {ProtoViewBuilder} from 'angular2/src/render/dom/view/proto_view_builder'; @@ -25,7 +25,8 @@ export function main() { }); it('should stop walking the tree when compileChildren is false', () => { - var element = el('
'); + var element = el( + '
'); var step0Log = []; var pipeline = new CompilePipeline([new IgnoreChildrenStep(), createLoggerStep(step0Log)]); @@ -40,7 +41,8 @@ export function main() { var element = el('
'); var pipeline = new CompilePipeline([new MockStep((parent, current, control) => { if (isPresent(DOM.getAttribute(current.element, 'viewroot'))) { - current.inheritedProtoView = new ProtoViewBuilder(current.element, ProtoViewDto.EMBEDDED_VIEW_TYPE); + current.inheritedProtoView = + new ProtoViewBuilder(current.element, ProtoViewDto.EMBEDDED_VIEW_TYPE); } })]); var results = pipeline.process(element); @@ -99,10 +101,8 @@ export function main() { var element = el('
'); var step0Log = []; var step1Log = []; - var pipeline = new CompilePipeline([ - createWrapperStep('wrap0', step0Log), - createLoggerStep(step1Log) - ]); + var pipeline = new CompilePipeline( + [createWrapperStep('wrap0', step0Log), createLoggerStep(step1Log)]); var result = pipeline.process(element); expect(step0Log).toEqual(['1', '1<2', '2<3']); expect(step1Log).toEqual(['1', '1 { - var element = el('
'); + var element = + el('
'); var step0Log = []; var step1Log = []; var step2Log = []; @@ -127,7 +128,8 @@ export function main() { }); it('should allow to add a parent by multiple processors to different elements', () => { - var element = el('
'); + var element = + el('
'); var step0Log = []; var step1Log = []; var step2Log = []; @@ -147,10 +149,8 @@ export function main() { var element = el('
'); var step0Log = []; var step1Log = []; - var pipeline = new CompilePipeline([ - createWrapperStep('wrap0', step0Log), - createLoggerStep(step1Log) - ]); + var pipeline = new CompilePipeline( + [createWrapperStep('wrap0', step0Log), createLoggerStep(step1Log)]); var result = pipeline.process(element); expect(step0Log).toEqual(['1', '1<2', '2<3']); expect(step1Log).toEqual(['1', '1')); var pipeline = new CompilePipeline([ - new MockStep((parent, current, control) => { - if (StringWrapper.equals(DOM.getAttribute(current.element, 'id'), '1')) { - control.addChild(newChild); - } - }), + new MockStep((parent, current, control) => + { + if (StringWrapper.equals(DOM.getAttribute(current.element, 'id'), '1')) { + control.addChild(newChild); + } + }), createLoggerStep(resultLog) ]); var result = pipeline.process(element); @@ -182,20 +183,16 @@ export function main() { }); } -@IMPLEMENTS(CompileStep) -class MockStep { - processClosure:Function; - constructor(process) { - this.processClosure = process; - } - process(parent:CompileElement, current:CompileElement, control:CompileControl) { +class MockStep implements CompileStep { + processClosure: Function; + constructor(process) { this.processClosure = process; } + process(parent: CompileElement, current: CompileElement, control: CompileControl) { this.processClosure(parent, current, control); } } -@IMPLEMENTS(CompileStep) -export class IgnoreChildrenStep { - process(parent:CompileElement, current:CompileElement, control:CompileControl) { +export class IgnoreChildrenStep implements CompileStep { + process(parent: CompileElement, current: CompileElement, control: CompileControl) { var attributeMap = DOM.attributeMap(current.element); if (MapWrapper.contains(attributeMap, 'ignore-children')) { current.compileChildren = false; @@ -203,9 +200,8 @@ export class IgnoreChildrenStep { } } -@IMPLEMENTS(CompileStep) -class IgnoreCurrentElementStep { - process(parent:CompileElement, current:CompileElement, control:CompileControl) { +class IgnoreCurrentElementStep implements CompileStep { + process(parent: CompileElement, current: CompileElement, control: CompileControl) { var attributeMap = DOM.attributeMap(current.element); if (MapWrapper.contains(attributeMap, 'ignore-current')) { control.ignoreCurrentElement(); @@ -222,9 +218,7 @@ function logEntry(log, parent, current) { } function createLoggerStep(log) { - return new MockStep((parent, current, control) => { - logEntry(log, parent, current); - }); + return new MockStep((parent, current, control) => { logEntry(log, parent, current); }); } function createWrapperStep(wrapperId, log) { @@ -244,8 +238,6 @@ function createWrapperStep(wrapperId, log) { function resultIdLog(result) { var idLog = []; - ListWrapper.forEach(result, (current) => { - logEntry(idLog, null, current); - }); + ListWrapper.forEach(result, (current) => { logEntry(idLog, null, current); }); return idLog; } diff --git a/modules/angular2/test/render/dom/compiler/property_binding_parser_spec.js b/modules/angular2/test/render/dom/compiler/property_binding_parser_spec.ts similarity index 82% rename from modules/angular2/test/render/dom/compiler/property_binding_parser_spec.js rename to modules/angular2/test/render/dom/compiler/property_binding_parser_spec.ts index 54762c0791..4d882e8e17 100644 --- a/modules/angular2/test/render/dom/compiler/property_binding_parser_spec.js +++ b/modules/angular2/test/render/dom/compiler/property_binding_parser_spec.ts @@ -7,6 +7,7 @@ import {CompileElement} from 'angular2/src/render/dom/compiler/compile_element'; import {CompileStep} from 'angular2/src/render/dom/compiler/compile_step'; import {CompileControl} from 'angular2/src/render/dom/compiler/compile_control'; import {Lexer, Parser} from 'angular2/change_detection'; +import {ElementBinderBuilder} from 'angular2/src/render/dom/view/proto_view_builder'; var EMPTY_MAP = MapWrapper.create(); @@ -14,19 +15,19 @@ export function main() { describe('PropertyBindingParser', () => { function createPipeline(hasNestedProtoView = false) { return new CompilePipeline([ - new MockStep((parent, current, control) => { - if (hasNestedProtoView) { - current.bindElement().bindNestedProtoView(el('')); - } - }), - new PropertyBindingParser(new Parser(new Lexer()))]); + new MockStep((parent, current, control) => + { + if (hasNestedProtoView) { + current.bindElement().bindNestedProtoView(el('')); + } + }), + new PropertyBindingParser(new Parser(new Lexer())) + ]); } - function process(element, hasNestedProtoView = false) { - return ListWrapper.map( - createPipeline(hasNestedProtoView).process(element), - (compileElement) => compileElement.inheritedElementBinder - ); + function process(element, hasNestedProtoView = false): List { + return ListWrapper.map(createPipeline(hasNestedProtoView).process(element), + (compileElement) => compileElement.inheritedElementBinder); } it('should detect [] syntax', () => { @@ -44,9 +45,8 @@ export function main() { expect(MapWrapper.get(results[0].propertyBindings, 'a').source).toEqual('b'); }); - it('should detect bind- syntax only if an attribute name starts with bind', () => { - expect(process(el('
'))[0]).toEqual(null); - }); + it('should detect bind- syntax only if an attribute name starts with bind', + () => { expect(process(el('
'))[0]).toEqual(null); }); it('should detect interpolation syntax', () => { var results = process(el('
')); @@ -67,14 +67,17 @@ export function main() { it('should store variable binding for a template element on the nestedProtoView', () => { var results = process(el('