From 4665726f48bc6a9054838d05e4a554c5e3ca7939 Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Sun, 10 May 2015 13:26:33 +0200 Subject: [PATCH] feat(lang): support const expressions in TS/JS and Dart Closes #1796 --- modules/angular2/src/facade/lang.ts | 5 +++++ modules/angular2/test/facade/lang_spec.js | 10 +++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/angular2/src/facade/lang.ts b/modules/angular2/src/facade/lang.ts index d8b2b4ace4..ad57de55c6 100644 --- a/modules/angular2/src/facade/lang.ts +++ b/modules/angular2/src/facade/lang.ts @@ -40,6 +40,11 @@ if (assertionsEnabled_) { } export {int}; +// This function is needed only to properly support Dart's const expressions +// see https://github.com/angular/ts2dart/pull/151 for more info +export function CONST_EXPR(expr: T): T { + return expr; +}; export function CONST() { return (target) => target; }; diff --git a/modules/angular2/test/facade/lang_spec.js b/modules/angular2/test/facade/lang_spec.js index 3e6929d05c..29ab544032 100644 --- a/modules/angular2/test/facade/lang_spec.js +++ b/modules/angular2/test/facade/lang_spec.js @@ -1,7 +1,7 @@ import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/test_lib'; import {ListWrapper} from 'angular2/src/facade/collection'; -import {isPresent, RegExpWrapper, RegExpMatcherWrapper} from 'angular2/src/facade/lang'; +import {isPresent, RegExpWrapper, RegExpMatcherWrapper, CONST_EXPR} from 'angular2/src/facade/lang'; export function main() { describe('RegExp', () => { @@ -21,4 +21,12 @@ export function main() { expect(indexes).toEqual([1, 4, 8, 9]); }) }); + + describe('const', () => { + it('should support const expressions both in TS and Dart', () => { + const numbers = CONST_EXPR([1, 2, 3]); + expect(numbers).toEqual([1, 2, 3]); + }) + }); + }