From 8a52375fb87f77279ff3546506fb898318f6da1a Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Fri, 5 Jun 2015 11:10:54 -0700 Subject: [PATCH] chore(transformer): add tests for property bindings and multiple executions --- .../angular2/src/render/dom/compiler/compiler.ts | 16 +++++++--------- .../render/dom/view/property_setter_factory.ts | 4 ++-- .../transform/template_compiler/all_tests.dart | 12 ++++++++++++ .../expected/hello.ng_deps.dart | 10 +++++++--- .../inline_expression_files/hello.ng_deps.dart | 2 +- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/modules/angular2/src/render/dom/compiler/compiler.ts b/modules/angular2/src/render/dom/compiler/compiler.ts index d26fd4a281..1648197029 100644 --- a/modules/angular2/src/render/dom/compiler/compiler.ts +++ b/modules/angular2/src/render/dom/compiler/compiler.ts @@ -16,16 +16,14 @@ import {TemplateLoader} from 'angular2/src/render/dom/compiler/template_loader'; import {CompileStepFactory, DefaultStepFactory} from './compile_step_factory'; import {Parser} from 'angular2/change_detection'; import {ShadowDomStrategy} from '../shadow_dom/shadow_dom_strategy'; -import { - PropertySetterFactory -} from '../view/property_setter_factory' +import {PropertySetterFactory} from '../view/property_setter_factory'; - /** - * The compiler loads and translates the html templates of components into - * nested ProtoViews. To decompose its functionality it uses - * the CompilePipeline and the CompileSteps. - */ - export class DomCompiler extends RenderCompiler { +/** + * The compiler loads and translates the html templates of components into + * nested ProtoViews. To decompose its functionality it uses + * the CompilePipeline and the CompileSteps. + */ +export class DomCompiler extends RenderCompiler { _templateLoader: TemplateLoader; _stepFactory: CompileStepFactory; _propertySetterFactory: PropertySetterFactory; diff --git a/modules/angular2/src/render/dom/view/property_setter_factory.ts b/modules/angular2/src/render/dom/view/property_setter_factory.ts index be359c3af9..6f13174ab2 100644 --- a/modules/angular2/src/render/dom/view/property_setter_factory.ts +++ b/modules/angular2/src/render/dom/view/property_setter_factory.ts @@ -93,8 +93,8 @@ export class PropertySetterFactory { var dashCasedClassName; if (isBlank(setterFn)) { dashCasedClassName = camelCaseToDashCase(className); - setterFn = (element, value) => { - if (value) { + setterFn = (element, isAdd) => { + if (isAdd) { DOM.addClass(element, dashCasedClassName); } else { DOM.removeClass(element, dashCasedClassName); diff --git a/modules/angular2/test/transform/template_compiler/all_tests.dart b/modules/angular2/test/transform/template_compiler/all_tests.dart index de69ac94e5..fe01d1c922 100644 --- a/modules/angular2/test/transform/template_compiler/all_tests.dart +++ b/modules/angular2/test/transform/template_compiler/all_tests.dart @@ -92,6 +92,18 @@ void allTests() { output = await process(new AssetId('a', inputPath)); _formatThenExpectEquals(output, expected); }); + + it('should create the same output for multiple calls.', () async { + var inputPath = + 'template_compiler/inline_expression_files/hello.ng_deps.dart'; + var expected = readFile( + 'template_compiler/inline_expression_files/expected/hello.ng_deps.dart'); + var output = await process(new AssetId('a', inputPath)); + _formatThenExpectEquals(output, expected); + output = await process(new AssetId('a', inputPath)); + _formatThenExpectEquals(output, expected); + }); + }); } diff --git a/modules/angular2/test/transform/template_compiler/inline_expression_files/expected/hello.ng_deps.dart b/modules/angular2/test/transform/template_compiler/inline_expression_files/expected/hello.ng_deps.dart index cc2c7b5d0d..e9faabb671 100644 --- a/modules/angular2/test/transform/template_compiler/inline_expression_files/expected/hello.ng_deps.dart +++ b/modules/angular2/test/transform/template_compiler/inline_expression_files/expected/hello.ng_deps.dart @@ -14,9 +14,13 @@ void initReflector(reflector) { 'parameters': const [const []], 'annotations': const [ const Component(selector: 'hello-app'), - const View(template: '{{greeting}}') + const View(template: '
{{greeting}}
') ] }) - ..registerGetters({'greeting': (o) => o.greeting}) - ..registerSetters({'greeting': (o, v) => o.greeting = v}); + ..registerGetters({'b': (o) => o.b, 'greeting': (o) => o.greeting}) + ..registerSetters({ + 'b': (o, v) => o.b = v, + 'greeting': (o, v) => o.greeting = v, + 'a': (o, v) => o.a = v + }); } diff --git a/modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_deps.dart b/modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_deps.dart index bd23fa6e55..d87b0ac7db 100644 --- a/modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_deps.dart +++ b/modules/angular2/test/transform/template_compiler/inline_expression_files/hello.ng_deps.dart @@ -14,7 +14,7 @@ void initReflector(reflector) { 'parameters': const [const []], 'annotations': const [ const Component(selector: 'hello-app'), - const View(template: '{{greeting}}') + const View(template: '
{{greeting}}
') ] }); }