fix(build): MetadataCollector correctly collects property metadata
Fixes #7772 Closes #7773
This commit is contained in:
parent
85f3dc2fb5
commit
111afcdff1
|
@ -148,6 +148,8 @@ export class MetadataCollector {
|
|||
}
|
||||
break;
|
||||
case ts.SyntaxKind.PropertyDeclaration:
|
||||
case ts.SyntaxKind.GetAccessor:
|
||||
case ts.SyntaxKind.SetAccessor:
|
||||
const property = <ts.PropertyDeclaration>member;
|
||||
const propertyDecorators = getDecorators(property.decorators);
|
||||
if (propertyDecorators) {
|
||||
|
|
|
@ -172,15 +172,43 @@ describe('Collector', () => {
|
|||
expect(metadata).toBeFalsy();
|
||||
});
|
||||
|
||||
let casesFile;
|
||||
let casesMetadata;
|
||||
|
||||
beforeEach(() => {
|
||||
casesFile = program.getSourceFile('/app/cases-data.ts');
|
||||
casesMetadata = collector.getMetadata(casesFile, typeChecker);
|
||||
});
|
||||
|
||||
it('should provide null for an any ctor pameter type', () => {
|
||||
const sourceFile = program.getSourceFile('/app/cases-data.ts');
|
||||
const metadata = collector.getMetadata(sourceFile, typeChecker);
|
||||
expect(metadata).toBeTruthy();
|
||||
const casesAny = <ClassMetadata>metadata.metadata['CaseAny'];
|
||||
const casesAny = <ClassMetadata>casesMetadata.metadata['CaseAny'];
|
||||
expect(casesAny).toBeTruthy();
|
||||
const ctorData = casesAny.members['__ctor__'];
|
||||
expect(ctorData).toEqual([{__symbolic: 'constructor', parameters: [null]}]);
|
||||
});
|
||||
|
||||
it('should record annotations on set and get declartions', () => {
|
||||
const propertyData = {
|
||||
name: [
|
||||
{
|
||||
__symbolic: 'property',
|
||||
decorators: [
|
||||
{
|
||||
__symbolic: 'call',
|
||||
expression: {__symbolic: 'reference', module: 'angular2/core', name: 'Input'},
|
||||
arguments: ['firstName']
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
};
|
||||
const caseGetProp = <ClassMetadata>casesMetadata.metadata['GetProp'];
|
||||
expect(caseGetProp.members).toEqual(propertyData);
|
||||
const caseSetProp = <ClassMetadata>casesMetadata.metadata['SetProp'];
|
||||
expect(caseSetProp.members).toEqual(propertyData);
|
||||
const caseFullProp = <ClassMetadata>casesMetadata.metadata['FullProp'];
|
||||
expect(caseFullProp.members).toEqual(propertyData);
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: Do not use \` in a template literal as it confuses clang-format
|
||||
|
@ -285,12 +313,39 @@ const FILES: Directory = {
|
|||
}
|
||||
}`,
|
||||
'cases-data.ts': `
|
||||
import {Injectable} from 'angular2/core';
|
||||
import {Injectable, Input} from 'angular2/core';
|
||||
|
||||
@Injectable()
|
||||
export class CaseAny {
|
||||
constructor(param: any) {}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class GetProp {
|
||||
private _name: string;
|
||||
@Input('firstName') get name(): string {
|
||||
return this._name;
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class SetProp {
|
||||
private _name: string;
|
||||
@Input('firstName') set name(value: string) {
|
||||
this._name = value;
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class FullProp {
|
||||
private _name: string;
|
||||
@Input('firstName') get name(): string {
|
||||
return this._name;
|
||||
}
|
||||
set name(value: string) {
|
||||
this._name = value;
|
||||
}
|
||||
}
|
||||
`,
|
||||
'cases-no-data.ts': `
|
||||
import {HeroService} from './hero.service';
|
||||
|
|
Loading…
Reference in New Issue