From d22e103618ed62d4754359e0db474d9cfe378e7f Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Mon, 14 Dec 2015 20:02:40 -0800 Subject: [PATCH] fix(ChangeDetection): chain expressions evaluate to the last expression (codegen) fixes #4782 --- .../src/core/change_detection/codegen_logic_util.ts | 2 +- .../core/change_detection/change_detector_config.ts | 1 + .../core/change_detection/change_detector_spec.ts | 12 ++++++++---- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/angular2/src/core/change_detection/codegen_logic_util.ts b/modules/angular2/src/core/change_detection/codegen_logic_util.ts index 2c2e2ab741a0..d1d27a6c7332 100644 --- a/modules/angular2/src/core/change_detection/codegen_logic_util.ts +++ b/modules/angular2/src/core/change_detection/codegen_logic_util.ts @@ -103,7 +103,7 @@ export class CodegenLogicUtil { break; case RecordType.Chain: - rhs = 'null'; + rhs = `${getLocalName(protoRec.args[protoRec.args.length - 1])}`; break; default: diff --git a/modules/angular2/test/core/change_detection/change_detector_config.ts b/modules/angular2/test/core/change_detection/change_detector_config.ts index ed7493306433..c770c004972f 100644 --- a/modules/angular2/test/core/change_detection/change_detector_config.ts +++ b/modules/angular2/test/core/change_detection/change_detector_config.ts @@ -433,6 +433,7 @@ var _availableEventDefinitions = [ '(event)="a[0]=\$event"', // '(event)="\$event=1"', '(event)="a=a+1; a=a+1;"', + '(event)="true; false"', '(event)="false"', '(event)="true"', '(event)="true ? a = a + 1 : a = a + 1"', diff --git a/modules/angular2/test/core/change_detection/change_detector_spec.ts b/modules/angular2/test/core/change_detection/change_detector_spec.ts index 5128cfd2bfb5..c7015d7c50a1 100644 --- a/modules/angular2/test/core/change_detection/change_detector_spec.ts +++ b/modules/angular2/test/core/change_detection/change_detector_spec.ts @@ -1341,12 +1341,16 @@ export function main() { it('should return the prevent default value', () => { var val = _createChangeDetector('(event)="false"', d, null); - var res = val.changeDetector.handleEvent("event", 0, locals); - expect(res).toBe(true); + var preventDefault = val.changeDetector.handleEvent("event", 0, locals); + expect(preventDefault).toBe(true); val = _createChangeDetector('(event)="true"', d, null); - res = val.changeDetector.handleEvent("event", 0, locals); - expect(res).toBe(false); + preventDefault = val.changeDetector.handleEvent("event", 0, locals); + expect(preventDefault).toBe(false); + + val = _createChangeDetector('(event)="true; false"', d, null); + preventDefault = val.changeDetector.handleEvent("event", 0, locals); + expect(preventDefault).toEqual(true); }); it('should support short-circuiting', () => {