From 73a939e76c8182ca73e49bbcb22a73f289f1fda8 Mon Sep 17 00:00:00 2001 From: Jacob MacDonald Date: Tue, 30 Jun 2015 14:13:50 -0700 Subject: [PATCH] fix(change detectors): Fix deduping of protos in transformed dart mode. In non-transformed mode the funcOrValue check was enough, but once transformed these all use the same function for getters, so we need to also check the name. --- modules/angular2/src/change_detection/coalesce.ts | 2 +- .../test/change_detection/coalesce_spec.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/angular2/src/change_detection/coalesce.ts b/modules/angular2/src/change_detection/coalesce.ts index 53d1d24957..300fc3914f 100644 --- a/modules/angular2/src/change_detection/coalesce.ts +++ b/modules/angular2/src/change_detection/coalesce.ts @@ -46,7 +46,7 @@ function _selfRecord(r: ProtoRecord, contextIndex: number, selfIndex: number): P function _findMatching(r: ProtoRecord, rs: List) { return ListWrapper.find(rs, (rr) => rr.mode !== RecordType.DIRECTIVE_LIFECYCLE && rr.mode === r.mode && rr.funcOrValue === r.funcOrValue && - rr.contextIndex === r.contextIndex && + rr.contextIndex === r.contextIndex && rr.name === r.name && ListWrapper.equals(rr.args, r.args)); } diff --git a/modules/angular2/test/change_detection/coalesce_spec.ts b/modules/angular2/test/change_detection/coalesce_spec.ts index bb3a88f7a1..310256a702 100644 --- a/modules/angular2/test/change_detection/coalesce_spec.ts +++ b/modules/angular2/test/change_detection/coalesce_spec.ts @@ -5,9 +5,9 @@ import {RecordType, ProtoRecord} from 'angular2/src/change_detection/proto_recor export function main() { function r(funcOrValue, args, contextIndex, selfIndex, lastInBinding = false, - mode = RecordType.PROPERTY) { - return new ProtoRecord(mode, "name", funcOrValue, args, null, contextIndex, null, selfIndex, - null, null, lastInBinding, false); + mode = RecordType.PROPERTY, name = "name") { + return new ProtoRecord(mode, name, funcOrValue, args, null, contextIndex, null, selfIndex, null, + null, lastInBinding, false); } describe("change detection - coalesce", () => { @@ -60,5 +60,14 @@ export function main() { expect(rs.length).toEqual(2); }); + + it("should not coalesce protos with different names but same value", () => { + var nullFunc = () => {}; + var rs = coalesce([ + r(nullFunc, [], 0, 1, false, RecordType.PROPERTY, "foo"), + r(nullFunc, [], 0, 1, false, RecordType.PROPERTY, "bar"), + ]); + expect(rs.length).toEqual(2); + }); }); }