From 0ae89ac096f6e5eaee026b578615c93c3ea2851b Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 19 May 2015 12:02:40 +0200 Subject: [PATCH] feat(CD): add support for === and !== relates to #1500 --- .../src/change_detection/change_detection_util.ts | 4 +++- .../src/change_detection/proto_change_detector.ts | 8 ++++++++ .../test/change_detection/change_detector_spec.js | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/change_detection/change_detection_util.ts b/modules/angular2/src/change_detection/change_detection_util.ts index 71c6508e28..7e1db5ff25 100644 --- a/modules/angular2/src/change_detection/change_detection_util.ts +++ b/modules/angular2/src/change_detection/change_detection_util.ts @@ -67,6 +67,8 @@ export class ChangeDetectionUtil { static operation_remainder(left, right) { return left % right; } static operation_equals(left, right) { return left == right; } static operation_not_equals(left, right) { return left != right; } + static operation_identical(left, right) { return left === right; } + static operation_not_identical(left, right) { return left !== right; } static operation_less_then(left, right) { return left < right; } static operation_greater_then(left, right) { return left > right; } static operation_less_or_equals_then(left, right) { return left <= right; } @@ -140,4 +142,4 @@ export class ChangeDetectionUtil { changes[propertyName] = change; return changes; } -} \ No newline at end of file +} diff --git a/modules/angular2/src/change_detection/proto_change_detector.ts b/modules/angular2/src/change_detection/proto_change_detector.ts index 689bd9b949..0720784ca6 100644 --- a/modules/angular2/src/change_detection/proto_change_detector.ts +++ b/modules/angular2/src/change_detection/proto_change_detector.ts @@ -286,6 +286,10 @@ function _operationToPrimitiveName(operation: string): string { return "operation_equals"; case '!=': return "operation_not_equals"; + case '===': + return "operation_identical"; + case '!==': + return "operation_not_identical"; case '<': return "operation_less_then"; case '>': @@ -319,6 +323,10 @@ function _operationToFunction(operation: string): Function { return ChangeDetectionUtil.operation_equals; case '!=': return ChangeDetectionUtil.operation_not_equals; + case '===': + return ChangeDetectionUtil.operation_identical; + case '!==': + return ChangeDetectionUtil.operation_not_identical; case '<': return ChangeDetectionUtil.operation_less_then; case '>': diff --git a/modules/angular2/test/change_detection/change_detector_spec.js b/modules/angular2/test/change_detection/change_detector_spec.js index 7a30b82832..cddf1d435d 100644 --- a/modules/angular2/test/change_detection/change_detector_spec.js +++ b/modules/angular2/test/change_detection/change_detector_spec.js @@ -168,8 +168,17 @@ export function main() { expect(executeWatch('exp', '11 % 2')).toEqual(['exp=1']); expect(executeWatch('exp', '1 == 1')).toEqual(['exp=true']); + if (IS_DARTIUM) { + expect(executeWatch('exp', '1 == "1"')).toEqual(['exp=false']); + } else { + expect(executeWatch('exp', '1 == "1"')).toEqual(['exp=true']); + } expect(executeWatch('exp', '1 != 1')).toEqual(['exp=false']); + expect(executeWatch('exp', '1 === 1')).toEqual(['exp=true']); + expect(executeWatch('exp', '1 !== 1')).toEqual(['exp=false']); + expect(executeWatch('exp', '1 === "1"')).toEqual(['exp=false']); + expect(executeWatch('exp', '1 < 2')).toEqual(['exp=true']); expect(executeWatch('exp', '2 < 1')).toEqual(['exp=false']);