Skip to content

Commit 4665726

Browse files
feat(lang): support const expressions in TS/JS and Dart
Closes angular#1796
1 parent e8ad0d1 commit 4665726

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

modules/angular2/src/facade/lang.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ if (assertionsEnabled_) {
4040
}
4141
export {int};
4242

43+
// This function is needed only to properly support Dart's const expressions
44+
// see https://github.com/angular/ts2dart/pull/151 for more info
45+
export function CONST_EXPR<T>(expr: T): T {
46+
return expr;
47+
};
4348
export function CONST() {
4449
return (target) => target;
4550
};

modules/angular2/test/facade/lang_spec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/test_lib';
22

33
import {ListWrapper} from 'angular2/src/facade/collection';
4-
import {isPresent, RegExpWrapper, RegExpMatcherWrapper} from 'angular2/src/facade/lang';
4+
import {isPresent, RegExpWrapper, RegExpMatcherWrapper, CONST_EXPR} from 'angular2/src/facade/lang';
55

66
export function main() {
77
describe('RegExp', () => {
@@ -21,4 +21,12 @@ export function main() {
2121
expect(indexes).toEqual([1, 4, 8, 9]);
2222
})
2323
});
24+
25+
describe('const', () => {
26+
it('should support const expressions both in TS and Dart', () => {
27+
const numbers = CONST_EXPR([1, 2, 3]);
28+
expect(numbers).toEqual([1, 2, 3]);
29+
})
30+
});
31+
2432
}

0 commit comments

Comments
 (0)