feat(compiler): Added support for conditional expressions. (#10366)

Expression evaluated by the static reflector can now supports
conditional expressions.

Closes: #10365
This commit is contained in:
Chuck Jazdzewski
2016-07-28 17:32:29 -07:00
committed by GitHub
parent 81d27daf0d
commit 20b03bad11
5 changed files with 116 additions and 23 deletions

View File

@ -411,6 +411,16 @@ describe('StaticReflector', () => {
expect(annotations.length).toBe(1);
expect(annotations[0].providers).toEqual([{provider: 'a', useValue: 'Some string'}]);
});
it('should be able to get the metadata for a class calling a method with a conditional expression',
() => {
const annotations = reflector.annotations(
host.getStaticSymbol('/tmp/src/static-method-call.ts', 'MyCondComponent'));
expect(annotations.length).toBe(1);
expect(annotations[0].providers).toEqual([
[{provider: 'a', useValue: '1'}], [{provider: 'a', useValue: '2'}]
]);
});
});
class MockReflectorHost implements StaticReflectorHost {
@ -960,6 +970,9 @@ class MockReflectorHost implements StaticReflectorHost {
static with(data: any) {
return { provider: 'a', useValue: data }
}
static condMethod(cond: boolean) {
return [{ provider: 'a', useValue: cond ? '1' : '2'}];
}
}
`,
'/tmp/src/static-method-call.ts': `
@ -970,6 +983,11 @@ class MockReflectorHost implements StaticReflectorHost {
providers: MyModule.with(100)
})
export class MyComponent { }
@Component({
providers: [MyModule.condMethod(true), MyModule.condMethod(false)]
})
export class MyCondComponent { }
`,
'/tmp/src/static-field.ts': `
import {Injectable} from 'angular2/core';